Last active
April 29, 2023 09:21
-
-
Save ericoporto/3ad4ba3cd1abc1446d6302e45aa4f36a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline bool FixupArgument(char fixup, ScriptOperation& codeOp, int argIndex, ccInstance* codeInst, ccInstance& c_this, int pc_at) { | |
using FixupFunc = std::function<bool(ScriptOperation&, int, ccInstance*, ccInstance&, int)>; | |
// #define FIXUP_GLOBALDATA 1 // code[fixup] += &globaldata[0] | |
// #define FIXUP_FUNCTION 2 // code[fixup] += &code[0] | |
// #define FIXUP_STRING 3 // code[fixup] += &strings[0] | |
// #define FIXUP_IMPORT 4 // code[fixup] = &imported_thing[code[fixup]] | |
// #define FIXUP_DATADATA 5 // globaldata[fixup] += &globaldata[0] | |
// #define FIXUP_STACK 6 // code[fixup] += &stack[0] | |
static const std::array<FixupFunc, 7> fixupFuncs{ { | |
[](ScriptOperation&, int, ccInstance*, ccInstance&, int) { return false; }, // Placeholder for index 0 | |
[](ScriptOperation& op, int idx, ccInstance* inst, ccInstance&, int pc) { // FIXUP_GLOBALDATA | |
ScriptVariable* gl_var = (ScriptVariable*)inst->code[pc]; | |
op.Args[idx].SetGlobalVar(&gl_var->RValue); | |
return false; | |
}, | |
[](ScriptOperation& op, int idx, ccInstance* inst, ccInstance&, int pc) { // FIXUP_FUNCTION | |
op.Args[idx].SetInt32((int32_t)inst->code[pc]); | |
return false; | |
}, | |
[](ScriptOperation& op, int idx, ccInstance* inst, ccInstance&, int pc) { // FIXUP_STRING | |
op.Args[idx].SetStringLiteral(&inst->strings[0] + inst->code[pc]); | |
return false; | |
}, | |
[](ScriptOperation& op, int idx, ccInstance* inst, ccInstance&, int pc) { // FIXUP_IMPORT | |
const ScriptImport* import = simp.getByIndex(static_cast<uint32_t>(inst->code[pc])); | |
if (import) { | |
op.Args[idx] = import->Value; | |
} else { | |
cc_error("cannot resolve import, key = %ld", inst->code[pc]); | |
return true; | |
} | |
return false; | |
}, | |
[](ScriptOperation&, int, ccInstance*, ccInstance&, int) { return false; }, // Placeholder for FIXUP_DATADATA | |
[](ScriptOperation& op, int idx, ccInstance* inst, ccInstance& c_this, int pc) { // FIXUP_STACK | |
op.Args[idx] = c_this.GetStackPtrOffsetFw((int32_t)inst->code[pc]); | |
return false; | |
} | |
} }; | |
if (fixup < fixupFuncs.size()) { | |
return fixupFuncs[fixup](codeOp, argIndex, codeInst, c_this, pc_at); | |
} | |
else { | |
cc_error("internal fixup type error: %d", fixup); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment