void fetchMember (CodeContainer& code, Literals& literals, char localType, const std::string& name, const std::string& id, bool global) { int index = literals.addString (name); opPushInt (code, index); index = literals.addString (id); opPushInt (code, index); switch (localType) { case 'f': opFetchMemberFloat (code, global); break; case 's': opFetchMemberShort (code, global); break; case 'l': opFetchMemberLong (code, global); break; default: assert (0); } }
void assignToMember (CodeContainer& code, Literals& literals, char localType, const std::string& name, const std::string& id, const CodeContainer& value, char valueType, bool global) { int index = literals.addString (name); opPushInt (code, index); index = literals.addString (id); opPushInt (code, index); std::copy (value.begin(), value.end(), std::back_inserter (code)); if (localType!=valueType) { if (localType=='f' && (valueType=='l' || valueType=='s')) { opIntToFloat (code); } else if ((localType=='l' || localType=='s') && valueType=='f') { opFloatToInt (code); } } switch (localType) { case 'f': opStoreMemberFloat (code, global); break; case 's': opStoreMemberShort (code, global); break; case 'l': opStoreMemberLong (code, global); break; default: assert (0); } }
void fetchGlobal (CodeContainer& code, Literals& literals, char localType, const std::string& name) { int index = literals.addString (name); opPushInt (code, index); switch (localType) { case 'f': opFetchGlobalFloat (code); break; case 's': opFetchGlobalShort (code); break; case 'l': opFetchGlobalLong (code); break; default: assert (0); } }
void report (CodeContainer& code, Literals& literals, const std::string& message) { int index = literals.addString (message); opPushInt (code, index); opReport (code); }
void message (CodeContainer& code, Literals& literals, const std::string& message, int buttons) { assert (buttons==0); int index = literals.addString (message); opPushInt (code, index); opMessageBox (code, buttons); }
void disable (CodeContainer& code, Literals& literals, const std::string& id) { if (id.empty()) { opDisable (code); } else { int index = literals.addString (id); opPushInt (code, index); opDisableExplicit (code); } }
void message (CodeContainer& code, Literals& literals, const std::string& message, int buttons) { assert (buttons>=0); if (buttons>=256) throw std::runtime_error ("A message box can't have more than 255 buttons"); int index = literals.addString (message); opPushInt (code, index); opMessageBox (code, buttons); }
void Extensions::generateInstructionCode (int keyword, std::vector<Interpreter::Type_Code>& code, Literals& literals, const std::string& id, int optionalArguments) const { assert (optionalArguments>=0); std::map<int, Instruction>::const_iterator iter = mInstructions.find (keyword); if (iter==mInstructions.end()) throw std::logic_error ("unknown custom instruction keyword"); if (optionalArguments && iter->second.mSegment!=3) throw std::logic_error ("instructions with optional arguments must be placed into segment 3"); if (!id.empty()) { if (iter->second.mCodeExplicit==-1) throw std::logic_error ("explicit references not supported"); int index = literals.addString (id); Generator::pushInt (code, literals, index); } switch (iter->second.mSegment) { case 3: if (optionalArguments>=256) throw std::logic_error ("number of optional arguments is too large for segment 3"); code.push_back (Generator::segment3 ( id.empty() ? iter->second.mCode : iter->second.mCodeExplicit, optionalArguments)); break; case 5: code.push_back (Generator::segment5 ( id.empty() ? iter->second.mCode : iter->second.mCodeExplicit)); break; default: throw std::logic_error ("unsupported code segment"); } }
void pushString (CodeContainer& code, Literals& literals, const std::string& value) { int index = literals.addString (value); opPushInt (code, index); }