diff options
| author | Ginger Bill <bill@gingerbill.org> | 2016-09-03 12:41:03 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2016-09-03 12:41:03 +0100 |
| commit | 11205f968ad2bf4893fa75df3fc3331f960039d1 (patch) | |
| tree | 9f6504a674e1fc59346b98df961c20c773db2227 /src/checker/type.cpp | |
| parent | e1a6775661d1ef57b84effa9b4c567c030b87556 (diff) | |
Typesafe variadic procedures
Diffstat (limited to 'src/checker/type.cpp')
| -rw-r--r-- | src/checker/type.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/checker/type.cpp b/src/checker/type.cpp index 2ff004636..16453b4dc 100644 --- a/src/checker/type.cpp +++ b/src/checker/type.cpp @@ -149,6 +149,7 @@ struct Type { Type * results; // Type_Tuple isize param_count; isize result_count; + b32 variadic; } Proc; }; }; @@ -240,13 +241,27 @@ Type *make_type_tuple(gbAllocator a) { return t; } -Type *make_type_proc(gbAllocator a, Scope *scope, Type *params, isize param_count, Type *results, isize result_count) { +Type *make_type_proc(gbAllocator a, Scope *scope, Type *params, isize param_count, Type *results, isize result_count, b32 variadic) { Type *t = alloc_type(a, Type_Proc); - t->Proc.scope = scope; - t->Proc.params = params; - t->Proc.param_count = param_count; - t->Proc.results = results; + + if (variadic) { + if (param_count == 0) { + GB_PANIC("variadic procedure must have at least one parameter"); + } + GB_ASSERT(params != NULL && params->kind == Type_Tuple); + Entity *e = params->Tuple.variables[param_count-1]; + if (get_base_type(e->type)->kind != Type_Slice) { + // NOTE(bill): For custom calling convention + GB_PANIC("variadic parameter must be of type slice"); + } + } + + t->Proc.scope = scope; + t->Proc.params = params; + t->Proc.param_count = param_count; + t->Proc.results = results; t->Proc.result_count = result_count; + t->Proc.variadic = variadic; return t; } |