From c2ea3f4efb3205e1a3aa882ff5f10df49116f0c0 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Fri, 28 Aug 2020 23:35:44 -0500 Subject: [PATCH] ast+js: Allow scripts to opt into stuck checking (#10) --- src/compiler/astgen.js | 8 +++++++- src/compiler/jsgen.js | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/compiler/astgen.js b/src/compiler/astgen.js index 4a87b038..c35a1e5d 100644 --- a/src/compiler/astgen.js +++ b/src/compiler/astgen.js @@ -15,6 +15,7 @@ const compatBlocks = require('./compat-blocks'); * @property {boolean} hasArguments * @property {boolean} isWarp * @property {boolean} yields + * @property {boolean} loopStuckChecking * @property {Array} dependedProcedures The list of procedure codes that this tree directly depends on. Does not include dependencies of dependencies, etc. * @property {*} cachedCompileResult */ @@ -70,6 +71,8 @@ class ScriptTreeGenerator { this.isWarp = false; /** @private */ this.yields = true; + /** @private */ + this.loopStuckChecking = this.target.runtime.compilerOptions.loopStuckChecking; /** * The names of the arguments accepted by this script, in order. @@ -1272,7 +1275,7 @@ class ScriptTreeGenerator { } analyzeLoop () { - if (!this.isWarp || this.target.runtime.compilerOptions.loopStuckChecking) { + if (!this.isWarp || this.loopStuckChecking) { this.yields = true; } } @@ -1296,6 +1299,9 @@ class ScriptTreeGenerator { switch (flag) { case 'nocompile': throw new Error('Script explicitly disables compilation'); + case 'stuck': + this.loopStuckChecking = true; + break; } } } diff --git a/src/compiler/jsgen.js b/src/compiler/jsgen.js index 2bc314d4..6207d8f7 100644 --- a/src/compiler/jsgen.js +++ b/src/compiler/jsgen.js @@ -141,7 +141,7 @@ class ScriptCompiler { this.isWarp = script.isWarp; this.isProcedure = script.isProcedure; - this.loopStuckChecking = this.target.runtime.compilerOptions.loopStuckChecking; + this.loopStuckChecking = script.loopStuckChecking; this.localVariables = new VariablePool('a'); this._setupVariablesPool = new VariablePool('b');