From d9248dc8f135a1e83d8148d5c6a9234c64539d42 Mon Sep 17 00:00:00 2001 From: jwklong <72522395+jwklong@users.noreply.github.com> Date: Tue, 28 Oct 2025 17:05:41 +0000 Subject: [PATCH 1/5] generate input first --- src/compiler/irgen.js | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/compiler/irgen.js b/src/compiler/irgen.js index bc7871de8a0..7feadde8e6b 100644 --- a/src/compiler/irgen.js +++ b/src/compiler/irgen.js @@ -2063,20 +2063,6 @@ class ScriptTreeGenerator { } } - // 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', - input: inputNode - }; - } catch (e) { - // Ignore - } - } - log.warn(`IR: Unknown stacked block: ${block.opcode}`, block); throw new Error(`IR: Unknown stacked block: ${block.opcode}`); } @@ -2373,23 +2359,36 @@ class ScriptTreeGenerator { // We do need to evaluate empty hats const hatInfo = this.runtime._hats[topBlock.opcode]; const isHat = !!hatInfo; + const isProcHat = topBlock.opcode === 'procedures_definition' || topBlock.opcode === 'procedures_definition_return'; if (isHat) { this.script.stack = this.walkHat(topBlock); } else { // We don't evaluate the procedures_definition top block as it never does anything // We also don't want it to be treated like a hat block let entryBlock; - if ( - topBlock.opcode === 'procedures_definition' - || topBlock.opcode === 'procedures_definition_return' - ) { + if (isProcHat) { entryBlock = topBlock.next; } else { entryBlock = topBlockId; } if (entryBlock) { - this.script.stack = this.walkStack(entryBlock); + const entryBlockObj = this.getBlockById(entryBlock); + + // When this thread was triggered by a stack click, attempt to compile as an input. + if (this.thread.stackClick && !isProcHat && !entryBlockObj.next) { + try { + const inputNode = this.descendInput(entryBlockObj); + this.script.stack = { + kind: 'visualReport', + input: inputNode + }; + doneAsInput = true; + } catch (e) { + // Ignore + } + } + this.script.stack ??= this.walkStack(entryBlock); } } From 95e1eff78d2fc125819877de9ab5a993ee9997ac Mon Sep 17 00:00:00 2001 From: jwklong <72522395+jwklong@users.noreply.github.com> Date: Tue, 28 Oct 2025 17:10:54 +0000 Subject: [PATCH 2/5] fix --- src/compiler/irgen.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/irgen.js b/src/compiler/irgen.js index 7feadde8e6b..fb3b30547c5 100644 --- a/src/compiler/irgen.js +++ b/src/compiler/irgen.js @@ -2379,10 +2379,10 @@ class ScriptTreeGenerator { if (this.thread.stackClick && !isProcHat && !entryBlockObj.next) { try { const inputNode = this.descendInput(entryBlockObj); - this.script.stack = { + this.script.stack = [{ kind: 'visualReport', input: inputNode - }; + }]; doneAsInput = true; } catch (e) { // Ignore From 5a71f7e66d9abe0d84c08960851858b5e02c619a Mon Sep 17 00:00:00 2001 From: jwklong <72522395+jwklong@users.noreply.github.com> Date: Tue, 28 Oct 2025 17:18:04 +0000 Subject: [PATCH 3/5] remove unnecessary warns when it already throws errors --- src/compiler/irgen.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/compiler/irgen.js b/src/compiler/irgen.js index fb3b30547c5..9b47627f113 100644 --- a/src/compiler/irgen.js +++ b/src/compiler/irgen.js @@ -1016,7 +1016,6 @@ class ScriptTreeGenerator { }; } - log.warn(`IR: Unknown input: ${block.opcode}`, block); throw new Error(`IR: Unknown input: ${block.opcode}`); } } @@ -2063,7 +2062,6 @@ class ScriptTreeGenerator { } } - log.warn(`IR: Unknown stacked block: ${block.opcode}`, block); throw new Error(`IR: Unknown stacked block: ${block.opcode}`); } } From a63c907bea57997387bb04da4a7d3e4ee1dcf196 Mon Sep 17 00:00:00 2001 From: jwklong <72522395+jwklong@users.noreply.github.com> Date: Tue, 28 Oct 2025 17:48:34 +0000 Subject: [PATCH 4/5] add silly warns --- src/compiler/irgen.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/compiler/irgen.js b/src/compiler/irgen.js index 9b47627f113..4aeac5ff0fe 100644 --- a/src/compiler/irgen.js +++ b/src/compiler/irgen.js @@ -1016,6 +1016,7 @@ class ScriptTreeGenerator { }; } + if (this.debug) log.warn(`IR: Unknown input: ${block.opcode}`, block); throw new Error(`IR: Unknown input: ${block.opcode}`); } } @@ -2062,6 +2063,7 @@ class ScriptTreeGenerator { } } + if (this.debug) log.warn(`IR: Unknown stacked block: ${block.opcode}`, block); throw new Error(`IR: Unknown stacked block: ${block.opcode}`); } } From 8dbb80861627cf3fda381a51359c9230bb55c6f2 Mon Sep 17 00:00:00 2001 From: jwklong <72522395+jwklong@users.noreply.github.com> Date: Tue, 28 Oct 2025 17:52:29 +0000 Subject: [PATCH 5/5] cleanup --- src/compiler/irgen.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compiler/irgen.js b/src/compiler/irgen.js index 4aeac5ff0fe..21be9f49ed0 100644 --- a/src/compiler/irgen.js +++ b/src/compiler/irgen.js @@ -2383,7 +2383,6 @@ class ScriptTreeGenerator { kind: 'visualReport', input: inputNode }]; - doneAsInput = true; } catch (e) { // Ignore }