From df66ab0339f2dac08f76094f91efbbbb157a7bfa Mon Sep 17 00:00:00 2001 From: smallmodel <15067410+smallmodel@users.noreply.github.com> Date: Sun, 13 Aug 2023 21:55:22 +0200 Subject: [PATCH] Fixed EmitField bug Clear the previous opcode when a new label is emitted --- code/script/scriptcompiler.cpp | 39 ++++++++++++++++++++++++++++------ code/script/scriptcompiler.h | 5 +++-- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/code/script/scriptcompiler.cpp b/code/script/scriptcompiler.cpp index a9ef6b27..674e455b 100644 --- a/code/script/scriptcompiler.cpp +++ b/code/script/scriptcompiler.cpp @@ -481,6 +481,7 @@ void ScriptCompiler::EmitField(sval_t listener_val, sval_t field_val, unsigned i unsigned int index = -1; unsigned int prev_index; + /* if (field_val.node[0].stringValue) { str name = field_val.stringValue; str name2 = field_val.stringValue; @@ -493,6 +494,10 @@ void ScriptCompiler::EmitField(sval_t listener_val, sval_t field_val, unsigned i index = Director.GetString(name2); } } + */ + + index = Director.AddString(field_val.stringValue); + eventnum = Event::FindGetterEventNum(field_val.stringValue); prev_index = GetOpcodeValue(sizeof(unsigned int), sizeof(unsigned int)); @@ -668,15 +673,32 @@ void ScriptCompiler::EmitJumpBack(unsigned char *pos, unsigned int sourcePos) AddJumpBackLocation(pos); } -void ScriptCompiler::EmitLabel(str name, unsigned int sourcePos) +void ScriptCompiler::EmitLabel(const char* name, unsigned int sourcePos) { if (showopcodes->integer) { - glbs.DPrintf("<%s>:\n", name.c_str()); + glbs.DPrintf("<%s>:\n", name); } if (!stateScript->AddLabel(name, code_pos)) { - CompileError(sourcePos, "Duplicate label '%s'", name.c_str()); + CompileError(sourcePos, "Duplicate label '%s'", name); } + + // Make sure to clear the previous opcode since it's a new context + ClearPrevOpcode(); +} + +void ScriptCompiler::EmitLabel(int name, unsigned int sourcePos) +{ + if (showopcodes->integer) { + glbs.DPrintf("<%d>:\n", name); + } + + if (!stateScript->AddLabel(str(name), code_pos)) { + CompileError(sourcePos, "Duplicate label '%d'", name); + } + + // Make sure to clear the previous opcode since it's a new context + ClearPrevOpcode(); } void ScriptCompiler::EmitLabelParameterList(sval_t parameter_list, unsigned int sourcePos) @@ -692,15 +714,18 @@ void ScriptCompiler::EmitLabelParameterList(sval_t parameter_list, unsigned int } } -void ScriptCompiler::EmitLabelPrivate(str name, unsigned int sourcePos) +void ScriptCompiler::EmitLabelPrivate(const char* name, unsigned int sourcePos) { if (showopcodes->integer) { - glbs.DPrintf("<%s>:\n", name.c_str()); + glbs.DPrintf("<%s>:\n", name); } if (!stateScript->AddLabel(name, code_pos, true)) { - CompileError(sourcePos, "Duplicate label '%s'", name.c_str()); - } + CompileError(sourcePos, "Duplicate label '%s'", name); + } + + // Make sure to clear the previous opcode since it's a new context + ClearPrevOpcode(); } void ScriptCompiler::EmitAndJump(sval_t logic_stmt, unsigned int sourcePos) diff --git a/code/script/scriptcompiler.h b/code/script/scriptcompiler.h index f683a115..41896f9b 100644 --- a/code/script/scriptcompiler.h +++ b/code/script/scriptcompiler.h @@ -127,9 +127,10 @@ public: void EmitInteger(unsigned int value, unsigned int sourcePos); void EmitJump(unsigned char *pos, unsigned int sourcePos); void EmitJumpBack(unsigned char *pos, unsigned int sourcePos); - void EmitLabel(str name, unsigned int sourcePos); + void EmitLabel(const char* name, unsigned int sourcePos); + void EmitLabel(int name, unsigned int sourcePos); void EmitLabelParameterList(sval_t parameter_list, unsigned int sourcePos); - void EmitLabelPrivate(str name, unsigned int sourcePos); + void EmitLabelPrivate(const char* name, unsigned int sourcePos); void EmitAndJump(sval_t logic_stmt, unsigned int sourcePos); void EmitOrJump(sval_t logic_stmt, unsigned int sourcePos); void EmitMakeArray(sval_t val);