Support compiling threads where top block is an input

This commit is contained in:
Thomas Weber committed 2021-01-15 16:55:22 -06:00
1 parent 128caac782
commit 49c5c6fede
2 files changed
+20 -13

No files matched your search

+16 -13
View File
@@ -1084,20 +1084,23 @@ class ScriptTreeGenerator {
if (compatBlocks.stacked.includes(block.opcode)) {
return this.descendCompatLayer(block);
}
// When this thread was triggered by a stack click, attempt to compile as an input.
// TODO: perhaps this should be moved to generate()?
if (this.thread.stackClick) {
try {
const inputNode = this.descendInput(block);
return {
kind: 'visualReport',
id: this.thread.topBlock,
input: inputNode
};
} catch (e) {
// Ignore
}
}
log.warn(`IR: Unknown stacked block: ${block.opcode}`, block);
// Try to compile as an input.
let isValidInput;
try {
this.descendInput(block);
isValidInput = true;
} catch (e) {
isValidInput = false;
}
if (isValidInput) {
throw new Error(`IR: This block is an input, not a stacked block: ${block.opcode}`);
}
throw new Error(`IR: Unknown stacked block: ${block.opcode}`);
}
}
+4
View File
@@ -865,6 +865,10 @@ class JSGenerator {
this.source += `runtime.monitorBlocks.changeBlock({ id: "${sanitize(node.variable.id)}", element: "checkbox", value: true }, runtime);\n`;
break;
case 'visualReport':
this.source += `runtime.visualReport("${sanitize(node.id)}", ${this.descendInput(node.input).asUnknown()});\n`;
break;
default:
log.warn(`JS: Unknown stacked block: ${node.kind}`, node);
throw new Error(`JS: Unknown stacked block: ${node.kind}`);