Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler refactor: store called function signature to AstCall #685

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/ast.jou
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ class AstCall:
uses_arrow_operator: bool # distinguishes foo->bar() and foo.bar()
nargs: int
args: AstExpression*
called_signature: Signature* # populated in typecheck, NULL before typecheck runs, not owned

def print(self) -> None:
self->print_with_tree_printer(TreePrinter{})
Expand Down
13 changes: 1 addition & 12 deletions compiler/build_cf_graph.jou
Original file line number Diff line number Diff line change
Expand Up @@ -483,18 +483,7 @@ class CfBuilder:
location: Location,
call: AstCall*,
) -> LocalVariable*:
sig: Signature* = NULL

if call->method_call_self != NULL:
selfclass = call->method_call_self->types.orig_type
if call->uses_arrow_operator:
assert selfclass->kind == TypeKind.Pointer
selfclass = selfclass->value_type
assert selfclass->kind == TypeKind.Class
sig = selfclass->find_method(call->name)
else:
sig = self->filetypes->find_function(call->name)

sig = call->called_signature
assert sig != NULL

ins = CfInstruction{
Expand Down
2 changes: 2 additions & 0 deletions compiler/typecheck/step3_function_and_method_bodies.jou
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@ def typecheck_function_or_method_call(state: State*, call: AstCall*, self_type:
"class %s does not have a method named '%s'", self_type->name, call->name)
fail(location, msg)

call->called_signature = sig

if self_type == NULL:
function_or_method = "function"
else:
Expand Down
Loading