From f0bb852f10ddfa4f7ecc70b67208aa92bbd4ed70 Mon Sep 17 00:00:00 2001 From: Muffin Date: Sun, 23 Jul 2023 15:06:29 -0500 Subject: [PATCH] Revert "Update behavior of non-existant procedures in compiler to match interpreter" This reverts commit b04df3eda76e179aac2ef2c74cffa9e16ae4e17e. There are still subtle issues related to execution order (JS is left-to-right while Scratch is depth-first). As there will inherently be some issues, we may as well do what runs faster. --- src/compiler/irgen.js | 63 +++++++++++++++++++++++-------------------- src/compiler/jsgen.js | 19 ------------- 2 files changed, 34 insertions(+), 48 deletions(-) diff --git a/src/compiler/irgen.js b/src/compiler/irgen.js index 9d47740ec5..45f3735111 100644 --- a/src/compiler/irgen.js +++ b/src/compiler/irgen.js @@ -1291,43 +1291,33 @@ class ScriptTreeGenerator { const procedureCode = block.mutation.proccode; const paramNamesIdsAndDefaults = this.blocks.getProcedureParamNamesIdsAndDefaults(procedureCode); if (paramNamesIdsAndDefaults === null) { - // Still need to evaluate arguments in case of side effects - const argumentList = []; - for (const inputName of Object.keys(block.inputs)) { - argumentList.push(this.descendInputOfBlock(block, inputName)); - } return { - kind: 'procedures.discard', - values: argumentList + kind: 'noop' }; } const [paramNames, paramIds, paramDefaults] = paramNamesIdsAndDefaults; - const argumentList = []; - for (let i = 0; i < paramIds.length; i++) { - let value; - if (block.inputs[paramIds[i]] && block.inputs[paramIds[i]].block) { - value = this.descendInputOfBlock(block, paramIds[i]); - } else { - value = { - kind: 'constant', - value: paramDefaults[i] - }; - } - argumentList.push(value); - } const addonBlock = this.runtime.getAddonBlock(procedureCode); if (addonBlock) { this.script.yields = true; - const argumentNameMap = {}; - for (let i = 0; i < argumentList.length; i++) { - argumentNameMap[paramNames[i]] = argumentList[i]; + const args = {}; + for (let i = 0; i < paramIds.length; i++) { + let value; + if (block.inputs[paramIds[i]] && block.inputs[paramIds[i]].block) { + value = this.descendInputOfBlock(block, paramIds[i]); + } else { + value = { + kind: 'constant', + value: paramDefaults[i] + }; + } + args[paramNames[i]] = value; } return { kind: 'addons.call', code: procedureCode, - arguments: argumentNameMap, + arguments: args, blockId: block.id }; } @@ -1336,8 +1326,7 @@ class ScriptTreeGenerator { const definitionBlock = this.blocks.getBlock(definitionId); if (!definitionBlock) { return { - kind: 'procedures.discard', - values: argumentList + kind: 'noop' }; } const innerDefinition = this.blocks.getBlock(definitionBlock.inputs.custom_block.block); @@ -1361,15 +1350,31 @@ class ScriptTreeGenerator { } // Non-warp direct recursion yields. - if (!this.script.isWarp && procedureCode === this.script.procedureCode) { - this.script.yields = true; + if (!this.script.isWarp) { + if (procedureCode === this.script.procedureCode) { + this.script.yields = true; + } + } + + const args = []; + for (let i = 0; i < paramIds.length; i++) { + let value; + if (block.inputs[paramIds[i]] && block.inputs[paramIds[i]].block) { + value = this.descendInputOfBlock(block, paramIds[i]); + } else { + value = { + kind: 'constant', + value: paramDefaults[i] + }; + } + args.push(value); } return { kind: 'procedures.call', code: procedureCode, variant, - arguments: argumentList + arguments: args }; } diff --git a/src/compiler/jsgen.js b/src/compiler/jsgen.js index c56b4ca292..f20b460cdb 100644 --- a/src/compiler/jsgen.js +++ b/src/compiler/jsgen.js @@ -653,17 +653,6 @@ class JSGenerator { } return new TypedInput(`${procedureReference}(${joinedArgs})`, TYPE_UNKNOWN); } - case 'procedures.discard': { - const args = []; - for (const value of node.values) { - args.push(this.descendInput(value).asUnknown()); - } - if (args.length > 0) { - // We can use the comma operator to discard the values. - return new TypedInput(`(${args.join(',')},"")`, TYPE_STRING); - } - return new TypedInput('""', TYPE_STRING); - } case 'sensing.answer': return new TypedInput(`runtime.ext_scratch3_sensing._answer`, TYPE_STRING); @@ -1079,14 +1068,6 @@ class JSGenerator { this.resetVariableInputs(); break; } - case 'procedures.discard': { - for (const value of node.values) { - const input = this.descendInput(value).asUnknown(); - // Don't need to use void, but it makes it explicit that we do not care about the result. - this.source += `void ${input};\n`; - } - break; - } case 'procedures.return': this.stopScriptAndReturn(this.descendInput(node.value).asSafe()); break;