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 +++++++++++++++++++++------- test.lang | 6 ++++-- 2 files changed, 25 insertions(+), 9 deletions(-) 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); diff --git a/test.lang b/test.lang index 1eee23a..2654990 100644 --- a/test.lang +++ b/test.lang @@ -8,8 +8,10 @@ // also single-line now -proc main(a i64) { +proc main(a, b i64, c, d, e bool) { let x = (a + -a) = (a xor a) let y = (a + a) = (a * 2) - return (x & y & (a = a) & (a = ~a)) | ((a + 2) <> a) + //return (x & y & (a = a) & (a = ~a)) | ((a - a) = (a + a)) + //return (a - a) = (a + a) + return c = d = e } -- cgit v1.2.3