Revert "Update behavior of non-existant procedures in compiler to match interpreter"

This reverts commit b04df3eda7.

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.
This commit is contained in:
Muffin committed 2023-07-23 15:06:29 -05:00
1 parent f42b260cc0
commit f0bb852f10
2 files changed
+34 -48

No files matched your search

+34 -29
View File
@@ -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
};
}
-19
View File
@@ -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;