summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorWormHeamer2025-08-05 01:35:21 -0400
committerWormHeamer2025-08-05 01:35:21 -0400
commitbeee7d5d34d6d37649b544de33db36f389648897 (patch)
treef697611f882477ee1bb0112d44f1928f49e9df0c /main.c
parent6ab9f2fb0e3d7a6e6db182d5e4eec10c42bf5372 (diff)
allow `proc main(a, b, c i64)` and such
Diffstat (limited to 'main.c')
-rw-r--r--main.c28
1 files changed, 21 insertions, 7 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);