From e8322da6631ecf49a6761210df1e9f89ac26725a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 17 Jul 2014 08:35:28 +0200 Subject: [PATCH] added support for targeted scripts to script compiler --- components/compiler/generator.cpp | 15 +++++++++++---- components/compiler/generator.hpp | 2 +- components/compiler/lineparser.cpp | 14 +++++++------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/components/compiler/generator.cpp b/components/compiler/generator.cpp index c67e51e57..235b163ad 100644 --- a/components/compiler/generator.cpp +++ b/components/compiler/generator.cpp @@ -300,9 +300,9 @@ namespace code.push_back (Compiler::Generator::segment5 (46)); } - void opStartScript (Compiler::Generator::CodeContainer& code) + void opStartScript (Compiler::Generator::CodeContainer& code, bool targeted) { - code.push_back (Compiler::Generator::segment5 (47)); + code.push_back (Compiler::Generator::segment5 (targeted ? 71 : 47)); } void opStopScript (Compiler::Generator::CodeContainer& code) @@ -830,9 +830,16 @@ namespace Compiler opScriptRunning (code); } - void startScript (CodeContainer& code) + void startScript (CodeContainer& code, Literals& literals, const std::string& id) { - opStartScript (code); + if (id.empty()) + opStartScript (code, false); + else + { + int index = literals.addString (id); + opPushInt (code, index); + opStartScript (code, true); + } } void stopScript (CodeContainer& code) diff --git a/components/compiler/generator.hpp b/components/compiler/generator.hpp index b51116122..2619033c8 100644 --- a/components/compiler/generator.hpp +++ b/components/compiler/generator.hpp @@ -113,7 +113,7 @@ namespace Compiler void scriptRunning (CodeContainer& code); - void startScript (CodeContainer& code); + void startScript (CodeContainer& code, Literals& literals, const std::string& id); void stopScript (CodeContainer& code); diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp index f7d2726e3..b1b831bc2 100644 --- a/components/compiler/lineparser.cpp +++ b/components/compiler/lineparser.cpp @@ -262,6 +262,13 @@ namespace Compiler Generator::disable (mCode, mLiterals, mExplicit); mState = PotentialEndState; return true; + + case Scanner::K_startscript: + + mExprParser.parseArguments ("c", scanner, mCode); + Generator::startScript (mCode, mLiterals, mExplicit); + mState = EndState; + return true; } // check for custom extensions @@ -361,13 +368,6 @@ namespace Compiler mState = EndState; return true; - case Scanner::K_startscript: - - mExprParser.parseArguments ("c", scanner, mCode); - Generator::startScript (mCode); - mState = EndState; - return true; - case Scanner::K_stopscript: mExprParser.parseArguments ("c", scanner, mCode);