mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Simplified script VM:
- removed I_RET instruction, return is now implicit at end of script - I_POP is not a binary instruction. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@963 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+15
-16
@@ -140,7 +140,6 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
|
||||
|
||||
// Loop until we are done
|
||||
while (true) {
|
||||
assert(instr < &*script.instructions.end());
|
||||
// Is there a jump going here?
|
||||
// If so, unify with current execution path
|
||||
while (!jumps.empty() && jumps.top()->target == instr) {
|
||||
@@ -158,6 +157,8 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
|
||||
delete j;
|
||||
}
|
||||
|
||||
if (instr >= &*script.instructions.end()) break; // end of script
|
||||
|
||||
// Analyze the current instruction
|
||||
Instruction i = *instr++;
|
||||
switch (i.instr) {
|
||||
@@ -167,11 +168,6 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
|
||||
stack.push_back(script.constants[i.data]);
|
||||
break;
|
||||
}
|
||||
// Pop top value (as normal)
|
||||
case I_POP: {
|
||||
stack.pop_back();
|
||||
break;
|
||||
}
|
||||
// Jump
|
||||
case I_JUMP: {
|
||||
if (&script.instructions[i.data] >= instr) {
|
||||
@@ -253,16 +249,6 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
|
||||
closeScope(scope);
|
||||
break;
|
||||
}
|
||||
// Function return (as normal)
|
||||
case I_RET: {
|
||||
closeScope(scope);
|
||||
// return top of stack
|
||||
ScriptValueP result = stack.back();
|
||||
stack.pop_back();
|
||||
assert(stack.size() == stack_size); // we end up with the same stack
|
||||
assert(jumps.empty()); // no open jump records
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get a variable (almost as normal)
|
||||
case I_GET_VAR: {
|
||||
@@ -293,6 +279,10 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
|
||||
}
|
||||
// Simple instruction: binary
|
||||
case I_BINARY: {
|
||||
if (i.instr2 == I_POP) {
|
||||
stack.pop_back();
|
||||
continue;
|
||||
}
|
||||
ScriptValueP b = stack.back(); stack.pop_back();
|
||||
ScriptValueP& a = stack.back();
|
||||
switch (i.instr2) {
|
||||
@@ -330,6 +320,15 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Function return (as normal)
|
||||
closeScope(scope);
|
||||
ScriptValueP result = stack.back();
|
||||
stack.pop_back();
|
||||
assert(stack.size() == stack_size); // we end up with the same stack
|
||||
assert(jumps.empty()); // no open jump records
|
||||
return result;
|
||||
|
||||
} catch (...) {
|
||||
// cleanup after an exception
|
||||
// the only place where exceptions should be possible is in someValue->getMember
|
||||
|
||||
Reference in New Issue
Block a user