Skip to content

Commit

Permalink
Unbreak HATs
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Aug 22, 2023
1 parent e19c766 commit a1416da
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/compiler/jsgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,9 +762,10 @@ class JSGenerator {
// If you don't do this, the loop effectively yields twice per iteration and will run at half-speed.
const isLastInLoop = this.isLastBlockInLoop();

if (node.blockType === BlockType.COMMAND) {
const blockType = node.blockType;
if (blockType === BlockType.COMMAND || blockType === BlockType.HAT) {
this.source += `${this.generateCompatibilityLayerCall(node, isLastInLoop)};\n`;
} else if (node.blockType === BlockType.CONDITIONAL) {
} else if (blockType === BlockType.CONDITIONAL) {
this.source += `switch (Math.round(${this.generateCompatibilityLayerCall(node, isLastInLoop)})) {\n`;
for (let i = 0; i < node.substacks.length; i++) {
this.source += `case ${i + 1}: {\n`;
Expand All @@ -773,12 +774,14 @@ class JSGenerator {
this.source += `}\n`;
}
this.source += `}\n`;
} else if (node.blockType === BlockType.LOOP) {
} else if (blockType === BlockType.LOOP) {
const stackFrameName = this.localVariables.next();
this.source += `const ${stackFrameName} = persistentStackFrame();\n`;
this.source += `while (toBoolean(${this.generateCompatibilityLayerCall(node, isLastInLoop, stackFrameName)})) {\n`;
this.descendStack(node.substacks[0], new Frame(true));
this.source += '}\n';
} else {
throw new Error(`Unknown block type: ${blockType}`);
}

if (isLastInLoop) {
Expand Down

0 comments on commit a1416da

Please sign in to comment.