From 276e03d6857d80f951c0c38cffa7479c0403ebcf Mon Sep 17 00:00:00 2001 From: Dibyendu Majumdar Date: Thu, 9 Jul 2020 22:17:56 +0100 Subject: [PATCH] issue #26 Simple escape analysis - mark locals that have up-values as escaped --- src/implementation.h | 1 + src/parser.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/implementation.h b/src/implementation.h index fe484a7..356e472 100644 --- a/src/implementation.h +++ b/src/implementation.h @@ -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 { diff --git a/src/parser.c b/src/parser.c index 3c4b113..76641b3 100644 --- a/src/parser.c +++ b/src/parser.c @@ -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; } @@ -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; }