From 49c5c6fedee7c10dd4f485ff60bc39c703febe98 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Fri, 15 Jan 2021 16:55:22 -0600 Subject: [PATCH] Support compiling threads where top block is an input --- src/compiler/irgen.js | 29 ++++++++++++++++------------- src/compiler/jsgen.js | 4 ++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/compiler/irgen.js b/src/compiler/irgen.js index 86cdb7de..f5a564e5 100644 --- a/src/compiler/irgen.js +++ b/src/compiler/irgen.js @@ -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}`); } } diff --git a/src/compiler/jsgen.js b/src/compiler/jsgen.js index f443cce9..6836ed87 100644 --- a/src/compiler/jsgen.js +++ b/src/compiler/jsgen.js @@ -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}`);