Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/compiler/iroptimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,12 @@ class IROptimizer {
break;
case StackOpcode.CONTROL_WHILE:
case StackOpcode.CONTROL_FOR:
modified = this.analyzeInputs(inputs, state) || modified;
modified = this.analyzeLoopedStack(inputs.do, state, stackBlock, true) || modified;
break;
case StackOpcode.CONTROL_REPEAT:
modified = this.analyzeInputs(inputs, state) || modified;
modified = this.analyzeLoopedStack(inputs.do, state, stackBlock) || modified;
modified = this.analyzeLoopedStack(inputs.do, state, stackBlock, false) || modified;
break;
case StackOpcode.CONTROL_IF_ELSE: {
modified = this.analyzeInputs(inputs, state) || modified;
Expand Down Expand Up @@ -642,20 +645,24 @@ class IROptimizer {
* @param {IntermediateStack} stack
* @param {TypeState} state
* @param {IntermediateStackBlock} block
* @param {boolean} willReevaluateInputs
* @returns {boolean}
* @private
*/
analyzeLoopedStack (stack, state, block) {
analyzeLoopedStack (stack, state, block, willReevaluateInputs) {
let modified = false;

if (block.yields && !this.ignoreYields) {
let modified = state.clear();
modified = state.clear();
if (willReevaluateInputs) {
modified = this.analyzeInputs(block.inputs, state) || modified;
}
block.entryState = state.clone();
block.exitState = state.clone();
modified = this.analyzeInputs(block.inputs, state) || modified;
return this.analyzeStack(stack, state) || modified;
}

let iterations = 0;
let modified = false;
let keepLooping;
do {
// If we are stuck in an apparent infinite loop, give up and assume the worst.
Expand All @@ -672,7 +679,10 @@ class IROptimizer {
const newState = state.clone();
modified = this.analyzeStack(stack, newState) || modified;
modified = (keepLooping = state.or(newState)) || modified;
modified = this.analyzeInputs(block.inputs, state) || modified;

if (willReevaluateInputs) {
modified = this.analyzeInputs(block.inputs, state) || modified;
}
} while (keepLooping);
block.entryState = state.clone();
return modified;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// TW Snapshot
// Input SHA-256: 38075839898d1ba3d2556f350ff18438a205c5b6b3cb809d07d3f738bd37dad9

// Sprite1 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
const b1 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"];
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "d", null);
thread.procedures["Wa"]();
if ((("" + b1.value).toLowerCase() === "bwah".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "l", null);
}
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "k", null);
retire(); return;
}; })

// Sprite1 Wa
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"];
const b1 = stage.variables["6h7bpiz0`;;x^G1B3(%["];
return function funXYZ_a () {
b0.value = b1.value.length;
for (var a0 = b0.value; a0 > 0; a0--) {
b0.value = "bwah";
}
return "";
}; })
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// TW Snapshot
// Input SHA-256: 38075839898d1ba3d2556f350ff18438a205c5b6b3cb809d07d3f738bd37dad9

// Sprite1 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
const b1 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"];
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "d", null);
yield* thread.procedures["Wa"]();
if ((("" + b1.value).toLowerCase() === "bwah".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "l", null);
}
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "k", null);
retire(); return;
}; })

// Sprite1 Wa
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"];
const b1 = stage.variables["6h7bpiz0`;;x^G1B3(%["];
return function* genXYZ_a () {
b0.value = b1.value.length;
for (var a0 = b0.value; a0 > 0; a0--) {
b0.value = "bwah";
if (isStuck()) yield;
}
return "";
}; })