Skip to content

Commit

Permalink
val: Set owner scope for declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Oct 30, 2024
1 parent 616caa8 commit f482ca2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions flamingo/flamingo.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ struct flamingo_val_t {
flamingo_val_kind_t kind;
size_t ref_count;

// The scope this value was created in.

flamingo_scope_t* owner;

// All the type-specific data.

union {
Expand Down
1 change: 1 addition & 0 deletions flamingo/grammar/function_declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static int parse_function_declaration(flamingo_t* flamingo, TSNode node, flaming
var_set_val(var, val_alloc());

var->val->kind = FLAMINGO_VAL_KIND_FN;
var->val->owner = cur_scope;

var->val->fn.kind = kind;
var->val->fn.env = env_close_over(flamingo->env);
Expand Down
2 changes: 2 additions & 0 deletions flamingo/grammar/var_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,7 @@ static int parse_var_decl(flamingo_t* flamingo, TSNode node) {
var->val->kind = FLAMINGO_VAL_KIND_NONE;
}

var->val->owner = cur_scope;

return 0;
}
2 changes: 2 additions & 0 deletions flamingo/val.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ static flamingo_val_t* val_init(flamingo_val_t* val) {
val->kind = FLAMINGO_VAL_KIND_NONE;
val->ref_count = 1;

val->owner = NULL;

return val;
}

Expand Down

0 comments on commit f482ca2

Please sign in to comment.