diff --git a/components/compiler/generator.cpp b/components/compiler/generator.cpp index 3d3b21d65..ee9876a14 100644 --- a/components/compiler/generator.cpp +++ b/components/compiler/generator.cpp @@ -125,6 +125,11 @@ namespace code.push_back (Compiler::Generator::segment3 (0, buttons)); } + void opReport (Compiler::Generator::CodeContainer& code) + { + code.push_back (Compiler::Generator::segment5 (58)); + } + void opFetchLocalShort (Compiler::Generator::CodeContainer& code) { code.push_back (Compiler::Generator::segment5 (21)); @@ -516,6 +521,14 @@ namespace Compiler opMessageBox (code, buttons); } + void report (CodeContainer& code, Literals& literals, const std::string& message) + { + int index = literals.addString (message); + + opPushInt (code, index); + opReport (code); + } + void fetchLocal (CodeContainer& code, char localType, int localIndex) { opPushInt (code, localIndex); diff --git a/components/compiler/generator.hpp b/components/compiler/generator.hpp index 5671949f2..fd1f954ca 100644 --- a/components/compiler/generator.hpp +++ b/components/compiler/generator.hpp @@ -81,6 +81,8 @@ namespace Compiler void message (CodeContainer& code, Literals& literals, const std::string& message, int buttons); + void report (CodeContainer& code, Literals& literals, const std::string& message); + void fetchLocal (CodeContainer& code, char localType, int localIndex); void jump (CodeContainer& code, int offset); diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp index 5462f7788..834cd27b4 100644 --- a/components/compiler/lineparser.cpp +++ b/components/compiler/lineparser.cpp @@ -30,12 +30,12 @@ namespace Compiler { case 'l': - Generator::message (mCode, mLiterals, "%g", 0); + Generator::report (mCode, mLiterals, "%g"); break; case 'f': - Generator::message (mCode, mLiterals, "%f", 0); + Generator::report (mCode, mLiterals, "%f"); break; default: diff --git a/components/interpreter/docs/vmformat.txt b/components/interpreter/docs/vmformat.txt index 6619fc30a..3e513aa44 100644 --- a/components/interpreter/docs/vmformat.txt +++ b/components/interpreter/docs/vmformat.txt @@ -117,5 +117,9 @@ op 55: explicit reference = stack[0]; pop; disable explicit reference op 56: explicit reference = stack[0]; pop; push 1, if explicit reference is disabled, 0 else op 57: explicit reference = stack[0]; pop; replace stack[0] with distance between explicit reference and a reference of ID stack[0] -opcodes 58-33554431 unused +op 58: report string literal index in stack[0]; + additional arguments (if any) in stack[n]..stack[1]; + n is determined according to the message string + all arguments are removed from stack +opcodes 59-33554431 unused opcodes 33554432-67108863 reserved for extensions diff --git a/components/interpreter/installopcodes.cpp b/components/interpreter/installopcodes.cpp index f383ff47c..556477af2 100644 --- a/components/interpreter/installopcodes.cpp +++ b/components/interpreter/installopcodes.cpp @@ -95,6 +95,7 @@ namespace Interpreter interpreter.installSegment5 (54, new OpEnableExplicit); interpreter.installSegment5 (55, new OpDisableExplicit); interpreter.installSegment5 (56, new OpGetDisabledExplicit); + interpreter.installSegment5 (58, new OpReport); // script control interpreter.installSegment5 (46, new OpScriptRunning); @@ -106,4 +107,3 @@ namespace Interpreter interpreter.installSegment5 (57, new OpGetDistanceExplicit); } } - diff --git a/components/interpreter/miscopcodes.hpp b/components/interpreter/miscopcodes.hpp index fbee0aa26..37c38fc30 100644 --- a/components/interpreter/miscopcodes.hpp +++ b/components/interpreter/miscopcodes.hpp @@ -13,6 +13,66 @@ namespace Interpreter { + inline std::string formatMessage (const std::string& message, Runtime& runtime) + { + std::string formattedMessage; + + for (std::size_t i=0; i