From 3f47036ce321369d0e1c9ea0acef0968f53b238e Mon Sep 17 00:00:00 2001 From: dibyendumajumdar Date: Sun, 20 Mar 2022 16:45:30 +0000 Subject: [PATCH] #77 simple optimization phase to replace upvalues that reference literals with those literals --- src/parser.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/parser.c b/src/parser.c index 278738b..7b59d41 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1253,8 +1253,10 @@ static AstNode *parse_embedded_C(ParserState *parser, bool is_decl) { const StringObject *varname = ls->t.seminfo.ts; bool is_local = 0; LuaSymbol *symbol = search_for_variable(parser, varname, &is_local); - if (symbol && is_local) + if (symbol && is_local) { raviX_add_symbol(parser->compiler_state, &node->embedded_C_stmt.symbols, symbol); + symbol->variable.modified = 1; // assume local will be modified + } else { raviX_syntaxerror(ls, "Argument to C__unsafe() must be a local variable"); } @@ -1262,8 +1264,11 @@ static AstNode *parse_embedded_C(ParserState *parser, bool is_decl) { while (testnext(ls, ',')) { varname = check_name_and_next(ls); symbol = search_for_variable(parser, varname, &is_local); - if (symbol && is_local) - raviX_add_symbol(parser->compiler_state, &node->embedded_C_stmt.symbols, symbol); + if (symbol && is_local) { + raviX_add_symbol(parser->compiler_state, &node->embedded_C_stmt.symbols, + symbol); + symbol->variable.modified = 1; // assume local will be modified + } else { raviX_syntaxerror(ls, "Argument to C__unsafe() must be a local variable"); }