Skip to content

Commit

Permalink
scope: Set owner for instance or class' static scope
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Oct 30, 2024
1 parent d277342 commit 616caa8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions flamingo/call.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ static int call(
(*rv)->inst.data = NULL;
(*rv)->inst.free_data = NULL;

inner_scope->owner = *rv;

// XXX A small quirk to note regarding this: an instance won't be created if it isn't assigned to anything.
// That means that the class instantiation callback will never be called either, even if the constructor code itself is.

Expand Down
4 changes: 4 additions & 0 deletions flamingo/flamingo.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ struct flamingo_scope_t {
size_t vars_size;
flamingo_var_t* vars;

// If scope is an instance's scope or a class' static scope, this will be set to that instance or class.

flamingo_val_t* owner;

// Used for return to know what it can and can't return.

bool class_scope;
Expand Down
2 changes: 2 additions & 0 deletions flamingo/grammar/function_declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ static int parse_function_declaration(flamingo_t* flamingo, TSNode node, flaming

if (kind == FLAMINGO_FN_KIND_CLASS) {
flamingo_scope_t* const scope = scope_alloc();

var->val->fn.scope = scope;
scope->owner = var->val;

if (find_static_members_in_class(flamingo, scope, body) < 0) {
return -1;
Expand Down
3 changes: 3 additions & 0 deletions flamingo/scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ static flamingo_scope_t* scope_alloc(void) {
scope->vars_size = 0;
scope->vars = NULL;

scope->owner = NULL;
scope->class_scope = false;

return scope;
}

Expand Down

0 comments on commit 616caa8

Please sign in to comment.