harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit f85f1f7cdcfccb683497172a70bfc687a0595680
parent 81b7d9444390fe15a66b2883effb2b9adb0eebc9
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Thu, 18 Mar 2021 20:02:01 -0400

Update for prototype grammar changes

Diffstat:
Mrt/+linux/syscalls.ha | 14+++++++-------
Msrc/parse.c | 30+++++++-----------------------
Msrc/typedef.c | 2++
Mtests/07-aliases.ha | 2+-
4 files changed, 17 insertions(+), 31 deletions(-)

diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -1,10 +1,10 @@ -fn syscall0(u64) u64; -fn syscall1(u64, u64) u64; -fn syscall2(u64, u64, u64) u64; -fn syscall3(u64, u64, u64, u64) u64; -fn syscall4(u64, u64, u64, u64, u64) u64; -fn syscall5(u64, u64, u64, u64, u64, u64) u64; -fn syscall6(u64, u64, u64, u64, u64, u64, u64) u64; +fn syscall0(_: u64) u64; +fn syscall1(_: u64, _: u64) u64; +fn syscall2(_: u64, _: u64, _: u64) u64; +fn syscall3(_: u64, _: u64, _: u64, _: u64) u64; +fn syscall4(_: u64, _: u64, _: u64, _: u64, _: u64) u64; +fn syscall5(_: u64, _: u64, _: u64, _: u64, _: u64, _: u64) u64; +fn syscall6(_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64) u64; export fn write(fd: int, buf: *const void, count: size) size = syscall3(SYS_write, fd: u64, buf: uintptr: u64, count: u64): size; diff --git a/src/parse.c b/src/parse.c @@ -262,38 +262,22 @@ static void parse_parameter_list(struct lexer *lexer, struct ast_function_type *type) { trenter(TR_PARSE, "parameter-list"); - struct token tok = {0}, tok2 = {0}; + struct token tok = {0}; bool more = true; type->params = mkfuncparams(&lexer->loc); struct ast_function_parameters *next = type->params; while (more) { switch (lex(lexer, &tok)) { + case T_UNDERSCORE: + break; case T_NAME: - switch (lex(lexer, &tok2)) { - case T_COLON: - next->name = tok.name; // Assumes ownership - next->type = parse_type(lexer); - break; - case T_DOUBLE_COLON: - next->type = parse_type(lexer); - synassert(next->type->storage == STORAGE_ALIAS, - &tok, T_NAME, T_EOF); - struct identifier *ident = - xcalloc(1, sizeof(struct identifier)); - struct identifier *ns; - ident->name = tok.name; // Assumes ownership - for (ns = &next->type->alias; ns->ns; ns = ns->ns); - ns->ns = ident; - break; - default: - synassert(false, &tok2, T_COLON, T_DOUBLE_COLON, T_EOF); - } + next->name = tok.name; // Assumes ownership break; default: - unlex(lexer, &tok); - next->type = parse_type(lexer); - break; + synassert(false, &tok, T_UNDERSCORE, T_NAME, T_EOF); } + want(lexer, T_COLON, NULL); + next->type = parse_type(lexer); trace(TR_PARSE, "%s: [type]", next->name); switch (lex(lexer, &tok)) { diff --git a/src/typedef.c b/src/typedef.c @@ -238,6 +238,7 @@ emit_type(const struct type *type, FILE *out) fprintf(out, "fn("); for (const struct type_func_param *param = type->func.params; param; param = param->next) { + fprintf(out, "_: "); if (param->next) { emit_type(param->type, out); fprintf(out, ", "); @@ -320,6 +321,7 @@ emit_decl_func(struct declaration *decl, FILE *out) for (struct type_func_param *param = fntype->func.params; param; param = param->next) { + fprintf(out, "_: "); if (param->next) { emit_type(param->type, out); fprintf(out, ", "); diff --git a/tests/07-aliases.ha b/tests/07-aliases.ha @@ -30,7 +30,7 @@ fn alias_array() void = { assert(c[2] == 3, "array ptr ptr alias"); }; -type my_fn = *const fn(int) int; +type my_fn = *const fn(_: int) int; type my_fn_ptr = *my_fn; type my_fn_ptr_ptr = *my_fn_ptr;