From beee7d5d34d6d37649b544de33db36f389648897 Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Tue, 5 Aug 2025 01:35:21 -0400 Subject: allow `proc main(a, b, c i64)` and such --- main.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 3ce67dc..6c2c072 100644 --- a/main.c +++ b/main.c @@ -120,18 +120,32 @@ Type parse_type(Lexer *l, Proc *proc) { void parse_args_list(Lexer *l, Proc *proc) { Node *start = proc->start; int i = 0; + struct { + Str name; + LexSpan pos; + } idbuf[32]; + int id = 0; while (l->tok != TOK_RPAREN && l->tok != TOK_EOF) { lex_expect(l, TM_IDENT); - Str name = l->ident; - LexSpan pos = l->pos; - lex_expect(l, TM_IDENT); + if (id == sizeof idbuf / sizeof *idbuf) { + lex_error(l, LE_ERROR, S("too many arguments without specifying a type")); + return; + } + idbuf[id].name = l->ident; + idbuf[id].pos = l->pos; + id++; + lex_expect(l, TM_IDENT | TM_COMMA); + if (l->tok == TOK_COMMA) continue; Value v = (Value) { .type = parse_type(l, proc) }; ZDA_PUSH(&start->val.tuple, v, &proc->arena); lex_expected(l, TM_RPAREN | TM_COMMA); - Node *proj = node_new(proc, N_PROJ, proc->start); - proj->val.type = v.type; - proj->val.i = i++; - scope_bind(&proc->scope, name, proj, pos, proc); + while (id > 0) { + id--; + Node *proj = node_new(proc, N_PROJ, proc->start); + proj->val.type = v.type; + proj->val.i = i++; + scope_bind(&proc->scope, idbuf[id].name, proj, idbuf[id].pos, proc); + } } lex_expected(l, TM_RPAREN); lex_next(l); -- cgit v1.2.3