Skip to content

Commit

Permalink
issue #26 Simple escape analysis - mark locals that have up-values as…
Browse files Browse the repository at this point in the history
… escaped
  • Loading branch information
dibyendumajumdar committed Jul 9, 2020
1 parent 52e27ec commit 276e03d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct lua_variable_symbol {
struct var_type value_type;
const struct string_object *var_name; /* name of the variable */
struct block_scope *block; /* NULL if global symbol, as globals are never added to a scope */
bool escaped; /* Has one or more up-value references */
struct pseudo *pseudo; /* backend data for the symbol */
};
struct lua_label_symbol {
Expand Down
2 changes: 2 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ static struct lua_symbol *new_local_symbol(struct parser_state *parser, const st
symbol->variable.block = scope;
symbol->variable.var_name = name;
symbol->variable.pseudo = NULL;
symbol->variable.escaped = false;
return symbol;
}

Expand Down Expand Up @@ -247,6 +248,7 @@ static bool add_upvalue_in_function(struct parser_state *parser, struct ast_node
(const struct ptr_list *)function->function_expr.upvalues); /* position of upvalue in function */
copy_type(&upvalue->upvalue.value_type, &sym->variable.value_type);
add_symbol(parser->container, &function->function_expr.upvalues, upvalue);
sym->variable.escaped = true; /* mark original variable as having escaped */
return true;
}

Expand Down

0 comments on commit 276e03d

Please sign in to comment.