Skip to content

Commit

Permalink
Alternative observation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Jul 19, 2023
1 parent ee2b2ef commit 849ea7c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/llex.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ 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: 10 additions & 2 deletions src/lparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,13 @@ 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 @@ -1521,8 +1528,7 @@ static void applyextends (LexState *ls, expdesc *v, TString *parent, int line) {

expdesc f;
singlevaraux(fs, luaS_newliteral(ls->L, "Pluto_operator_extends"), &f, 1);
if (f.k == VVOID)
luaX_syntaxerror(ls, "what the fuck?");
lua_assert(f.k != VVOID);
luaK_exp2nextreg(fs, &f);

expdesc args = *v;
Expand Down Expand Up @@ -4625,7 +4631,9 @@ 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: 0 additions & 25 deletions tests/basic.pluto
Original file line number Diff line number Diff line change
Expand Up @@ -1260,31 +1260,6 @@ 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 849ea7c

Please sign in to comment.