Skip to content

Commit

Permalink
Revert
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Jul 19, 2023
1 parent f31c391 commit 38bb0c7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/llex.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ struct LexState {
std::vector<EnumDesc> enums{};
std::vector<TString*> export_symbols{};
std::vector<void*> parse_time_allocations{};
bool should_have_extends = false;

LexState()
: lines{ std::string{} }, warnconfs{ WarningConfig(0) }
Expand Down
12 changes: 2 additions & 10 deletions src/lparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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?");
}
}


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
25 changes: 25 additions & 0 deletions tests/basic.pluto
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,31 @@ do
class Human end
end

print "Testing compile-time conditionals."
do
local debug_bytecode = string.dump(load([[
local DEBUG <constexpr> = 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 <constexpr> = 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"
Expand Down

0 comments on commit 38bb0c7

Please sign in to comment.