Skip to content

Commit 1999555

Browse files
committed
Fixed variable assignment resulting in wrong assembly
1 parent a6f8826 commit 1999555

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/optimizer/optimizerModuleBase.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,20 @@ OptimizerModuleBase::Node OptimizerModuleBase::nodeFromAST(const astnode& input)
9999
auto nodeType = input.kind;
100100
switch (nodeType) {
101101

102-
case sqf::parser::sqf::bison::astkind::ASSIGNMENT:
102+
case sqf::parser::sqf::bison::astkind::ASSIGNMENT: {
103+
Node newNode;
104+
105+
newNode.type = nodeType == sqf::parser::sqf::bison::astkind::ASSIGNMENT ? InstructionType::assignTo : InstructionType::assignToLocal;
106+
newNode.file = *input.token.path;
107+
newNode.line = input.token.line;
108+
newNode.offset = input.token.offset;
109+
auto varname = std::string(input.children[0].token.contents);
110+
std::transform(varname.begin(), varname.end(), varname.begin(), ::tolower);
111+
newNode.value = std::string(varname);
112+
113+
newNode.children.emplace_back(nodeFromAST(input.children[1]));
114+
return newNode;
115+
}
103116
case sqf::parser::sqf::bison::astkind::ASSIGNMENT_LOCAL: {
104117
Node newNode;
105118

src/scriptCompiler.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,18 @@ void ScriptCompiler::ASTToInstructions(CompiledCodeData& output, CompileTempData
186186
auto nodeType = node.kind;
187187
switch (nodeType) {
188188

189-
case sqf::parser::sqf::bison::astkind::ASSIGNMENT:
189+
case sqf::parser::sqf::bison::astkind::ASSIGNMENT: {
190+
auto varname = std::string(node.children[0].token.contents);
191+
//need value on stack first
192+
ASTToInstructions(output, temp, instructions, node.children[1]);
193+
std::transform(varname.begin(), varname.end(), varname.begin(), ::tolower);
194+
instructions.emplace_back(ScriptInstruction{
195+
nodeType == sqf::parser::sqf::bison::astkind::ASSIGNMENT ?
196+
InstructionType::assignTo
197+
:
198+
InstructionType::assignToLocal
199+
, node.token.offset, getFileIndex(*node.token.path), node.token.line, varname });
200+
} break;
190201
case sqf::parser::sqf::bison::astkind::ASSIGNMENT_LOCAL: {
191202
auto varname = std::string(node.token.contents);
192203
//need value on stack first
@@ -198,8 +209,7 @@ void ScriptCompiler::ASTToInstructions(CompiledCodeData& output, CompileTempData
198209
:
199210
InstructionType::assignToLocal
200211
, node.token.offset, getFileIndex(*node.token.path), node.token.line, varname });
201-
}
202-
break;
212+
} break;
203213
case sqf::parser::sqf::bison::astkind::EXP0:
204214
case sqf::parser::sqf::bison::astkind::EXP1:
205215
case sqf::parser::sqf::bison::astkind::EXP2:

0 commit comments

Comments
 (0)