Skip to content
Draft
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
50 changes: 48 additions & 2 deletions src/compiler/iroptimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,36 @@ class IROptimizer {
case InputOpcode.ADDON_CALL:
break;

case InputOpcode.CAST_BOOLEAN: {
const innerType = inputs.target.type;
if (innerType & InputType.BOOLEAN) return innerType;
return InputType.BOOLEAN;
}

case InputOpcode.CAST_NUMBER: {
const innerType = inputs.target.type;
if (innerType & InputType.NUMBER) return innerType;
return InputType.NUMBER;
} case InputOpcode.CAST_NUMBER_OR_NAN: {
}

case InputOpcode.CAST_NUMBER_INDEX: {
const innerType = inputs.target.type;
if (innerType & InputType.NUMBER_INDEX) return innerType;
return InputType.NUMBER_INDEX;
}

case InputOpcode.CAST_NUMBER_OR_NAN: {
const innerType = inputs.target.type;
if (innerType & InputType.NUMBER_OR_NAN) return innerType;
return InputType.NUMBER_OR_NAN;
}

case InputOpcode.CAST_STRING: {
const innerType = inputs.target.type;
if (innerType & InputType.STRING) return innerType;
return InputType.STRING;
}

case InputOpcode.OP_ADD: {
const leftType = inputs.left.type;
const rightType = inputs.right.type;
Expand Down Expand Up @@ -693,19 +713,45 @@ class IROptimizer {
}

switch (input.opcode) {
case InputOpcode.CAST_BOOLEAN: {
const targetType = input.inputs.target.type;
if ((targetType & InputType.BOOLEAN) === targetType) {
return input.inputs.target;
}
return input;
}

case InputOpcode.CAST_NUMBER: {
const targetType = input.inputs.target.type;
if ((targetType & InputType.NUMBER) === targetType) {
return input.inputs.target;
}
return input;
} case InputOpcode.CAST_NUMBER_OR_NAN: {
}

case InputOpcode.CAST_NUMBER_INDEX: {
const targetType = input.inputs.target.type;
if ((targetType & InputType.NUMBER_INDEX) === targetType) {
return input.inputs.target;
}
return input;
}

case InputOpcode.CAST_NUMBER_OR_NAN: {
const targetType = input.inputs.target.type;
if ((targetType & InputType.NUMBER_OR_NAN) === targetType) {
return input.inputs.target;
}
return input;
}

case InputOpcode.CAST_STRING: {
const targetType = input.inputs.target.type;
if ((targetType & InputType.STRING) === targetType) {
return input.inputs.target;
}
return input;
}
}

return input;
Expand Down
2 changes: 1 addition & 1 deletion test/snapshot/__snapshots__/tw-sensing-of.sb3.tw-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ if (compareEqual((b4 ? b4.value : 0), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass non existent variable",}, b0, false, false, ")nnN?*l+E)dC(fT5(_@q", null);
}
b5.value = (("" + randomInt(1, 9)) + ("" + randomInt(1, 9)));
if (compareEqual(runtime.ext_scratch3_sensing.getAttributeOf({OBJECT: ("" + b5.value), PROPERTY: "backdrop #" }), 0)) {
if (compareEqual(runtime.ext_scratch3_sensing.getAttributeOf({OBJECT: b5.value, PROPERTY: "backdrop #" }), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass NE backdrop #",}, b0, false, false, "UFr{[email protected]_paq:r]F", null);
}
if (compareEqual(runtime.ext_scratch3_sensing.getAttributeOf({OBJECT: ("" + b5.value), PROPERTY: "backdrop name" }), 0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ return function funXYZ_a () {
b0.value = "ababa";
b1.value = "";
b2.value = 1;
for (var a0 = ("" + b0.value).length; a0 > 0; a0--) {
if ((((("" + b0.value))[(b2.value | 0) - 1] || "").toLowerCase() === "a".toLowerCase())) {
b1.value = (("" + b1.value) + "b");
for (var a0 = b0.value.length; a0 > 0; a0--) {
if ((((b0.value)[b2.value - 1] || "").toLowerCase() === "a".toLowerCase())) {
b1.value = (b1.value + "b");
} else {
b1.value = (("" + b1.value) + "a");
b1.value = (b1.value + "a");
}
b2.value = (b2.value + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ if (compareEqual((b4 ? b4.value : 0), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass non existent variable",}, b0, false, false, ")nnN?*l+E)dC(fT5(_@q", null);
}
b5.value = (("" + randomInt(1, 9)) + ("" + randomInt(1, 9)));
if (compareEqual(runtime.ext_scratch3_sensing.getAttributeOf({OBJECT: ("" + b5.value), PROPERTY: "backdrop #" }), 0)) {
if (compareEqual(runtime.ext_scratch3_sensing.getAttributeOf({OBJECT: b5.value, PROPERTY: "backdrop #" }), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass NE backdrop #",}, b0, false, false, "UFr{[email protected]_paq:r]F", null);
}
if (compareEqual(runtime.ext_scratch3_sensing.getAttributeOf({OBJECT: ("" + b5.value), PROPERTY: "backdrop name" }), 0)) {
Expand Down