From 38bb0c74ae1527a7eb8ebb8980e2aca0c22576b8 Mon Sep 17 00:00:00 2001 From: Sainan Date: Wed, 19 Jul 2023 22:47:14 +0200 Subject: [PATCH] Revert --- src/llex.h | 1 - src/lparser.cpp | 12 ++---------- tests/basic.pluto | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/llex.h b/src/llex.h index ce3aed7ea1..cbb0515ca3 100644 --- a/src/llex.h +++ b/src/llex.h @@ -319,7 +319,6 @@ struct LexState { std::vector enums{}; std::vector export_symbols{}; std::vector parse_time_allocations{}; - bool should_have_extends = false; LexState() : lines{ std::string{} }, warnconfs{ WarningConfig(0) } diff --git a/src/lparser.cpp b/src/lparser.cpp index df633c0d8b..124c6949d4 100644 --- a/src/lparser.cpp +++ b/src/lparser.cpp @@ -1018,13 +1018,6 @@ static void leaveblock (FuncState *fs) { } luaK_patchtohere(fs, bl->breaklist); ls->laststat.token = TK_EOS; /* Prevent unreachable code warnings on blocks that don't explicitly check for TK_END. */ - - if (ls->should_have_extends && bl->nactvar != 0) { - expdesc f; - singlevaraux(fs, luaS_newliteral(ls->L, "Pluto_operator_extends"), &f, 1); - if (f.k == VVOID) - luaX_syntaxerror(ls, "what the fuck?"); - } } @@ -1528,7 +1521,8 @@ static void applyextends (LexState *ls, expdesc *v, TString *parent, int line) { expdesc f; singlevaraux(fs, luaS_newliteral(ls->L, "Pluto_operator_extends"), &f, 1); - lua_assert(f.k != VVOID); + if (f.k == VVOID) + luaX_syntaxerror(ls, "what the fuck?"); luaK_exp2nextreg(fs, &f); expdesc args = *v; @@ -4631,9 +4625,7 @@ static void mainfunc (LexState *ls, FuncState *fs) { luaC_objbarrier(ls->L, fs->f, env->name); builtinoperators(ls); luaX_next(ls); /* read first token */ - ls->should_have_extends = true; const bool ret = statlist(ls); /* parse main body */ - ls->should_have_extends = false; check(ls, TK_EOS); if (!ls->export_symbols.empty()) { if (ret) { diff --git a/tests/basic.pluto b/tests/basic.pluto index 3e0e7f8c17..1e92be6f28 100644 --- a/tests/basic.pluto +++ b/tests/basic.pluto @@ -1260,6 +1260,31 @@ do class Human end end +print "Testing compile-time conditionals." +do + local debug_bytecode = string.dump(load([[ + local DEBUG = true + $if DEBUG then + print("Script running in debug mode") + $else + print("Script running in release mode") + $end + ]], "")) + local release_bytecode = string.dump(load([[ + local DEBUG = false + $if DEBUG then + print("Script running in debug mode") + $else + print("Script running in release mode") + $end + ]], "")) + + assert(debug_bytecode:find("Script running in debug mode") ~= nil) + assert(debug_bytecode:find("Script running in release mode") == nil) + assert(release_bytecode:find("Script running in debug mode") == nil) + assert(release_bytecode:find("Script running in release mode") ~= nil) +end + print "Testing compatibility." do local a = "Hi"