Skip to content

Commit

Permalink
Improve self printing (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli authored Mar 26, 2023
1 parent e838dd6 commit 7233ba9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion self_hosted/ast.jou
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,10 @@ class AstSignature:
for i = 0; i < self->nargs; i++:
if i != 0:
printf(", ")
self->args[i].print(NULL)
if strcmp(self->args[i].name, "self") == 0:
printf("self")
else:
self->args[i].print(NULL)

if self->takes_varargs:
if self->nargs != 0:
Expand Down
8 changes: 6 additions & 2 deletions src/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,12 @@ static void print_ast_function_signature(const AstSignature *sig)
printf("%s(", sig->name);
for (const AstNameTypeValue *ntv = sig->args.ptr; ntv < End(sig->args); ntv++) {
if (ntv > sig->args.ptr) printf(", ");
printf("%s: ", ntv->name);
print_ast_type(&ntv->type);
if (!strcmp(ntv->name, "self"))
printf("self");
else{
printf("%s: ", ntv->name);
print_ast_type(&ntv->type);
}
assert(!ntv->value);
}
if (sig->takes_varargs) {
Expand Down

0 comments on commit 7233ba9

Please sign in to comment.