From aa2a2d36d90d3c7f7cd96fc7e15b5dcf91e495c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xenxo=20Espasand=C3=ADn?= Date: Sun, 24 Sep 2023 14:36:08 +0200 Subject: [PATCH] feat(arc): waittill undefined param (#149) --- src/arc/compiler.cpp | 14 ++++++++++---- src/arc/decompiler.cpp | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/arc/compiler.cpp b/src/arc/compiler.cpp index 14b726b5..8e1b4e92 100644 --- a/src/arc/compiler.cpp +++ b/src/arc/compiler.cpp @@ -302,7 +302,10 @@ auto compiler::emit_stmt_waittill(stmt_waittill const& stm) -> void for (auto const& entry : stm.args->list) { - emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, fmt::format("{}", variable_access(entry->as()))); + if (entry->is()) + emit_opcode(opcode::OP_SafeDecTop); + else + emit_opcode(opcode::OP_SafeSetWaittillVariableFieldCached, fmt::format("{}", variable_access(entry->as()))); } emit_opcode(opcode::OP_ClearParams); @@ -2003,12 +2006,15 @@ auto compiler::process_stmt_waittill(stmt_waittill const& stm) -> void { for (auto const& entry : stm.args->list) { - if (!entry->is()) + if (!entry->is() && !entry->is()) { - throw comp_error(entry->loc(), "illegal waittill param, must be a local variable"); + throw comp_error(entry->loc(), "illegal waittill param, must be a local variable or undefined"); } - variable_register(entry->as()); + if (entry->is()) + { + variable_register(entry->as()); + } } } diff --git a/src/arc/decompiler.cpp b/src/arc/decompiler.cpp index 5d92e7e1..b4ed35fa 100644 --- a/src/arc/decompiler.cpp +++ b/src/arc/decompiler.cpp @@ -192,6 +192,7 @@ auto decompiler::decompile_instruction(instruction const& inst, bool last) -> vo break; } case opcode::OP_GetUndefined: + case opcode::OP_SafeDecTop: { stack_.push(expr_undefined::make(loc)); break; @@ -1118,7 +1119,6 @@ auto decompiler::decompile_instruction(instruction const& inst, bool last) -> vo case opcode::OP_CheckClearParams: case opcode::OP_CastFieldObject: case opcode::OP_CastBool: - case opcode::OP_SafeDecTop: break; case opcode::OP_CreateLocalVariable: case opcode::OP_RemoveLocalVariables: