Skip to content

Commit

Permalink
Don't eagerly cast boolean arguments to boolean
Browse files Browse the repository at this point in the history
Fixes #222
  • Loading branch information
GarboMuffin committed Sep 8, 2024
1 parent 99ff662 commit fcee94f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/compiler/irgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class ScriptTreeGenerator {
};
}
return {
kind: 'args.stringNumber',
kind: 'procedures.argument',
index: index
};
}
Expand All @@ -223,7 +223,7 @@ class ScriptTreeGenerator {
};
}
return {
kind: 'args.boolean',
kind: 'procedures.argument',
index: index
};
}
Expand Down
7 changes: 2 additions & 5 deletions src/compiler/jsgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,6 @@ class JSGenerator {
case 'addons.call':
return new TypedInput(`(${this.descendAddonCall(node)})`, TYPE_UNKNOWN);

case 'args.boolean':
return new TypedInput(`toBoolean(p${node.index})`, TYPE_BOOLEAN);
case 'args.stringNumber':
return new TypedInput(`p${node.index}`, TYPE_UNKNOWN);

case 'compat':
// Compatibility layer inputs never use flags.
return new TypedInput(`(${this.generateCompatibilityLayerCall(node, false)})`, TYPE_UNKNOWN);
Expand Down Expand Up @@ -665,6 +660,8 @@ class JSGenerator {
}
return new TypedInput(`${procedureReference}(${joinedArgs})`, TYPE_UNKNOWN);
}
case 'procedures.argument':
return new TypedInput(`p${node.index}`, TYPE_UNKNOWN);

case 'sensing.answer':
return new TypedInput(`runtime.ext_scratch3_sensing._answer`, TYPE_STRING);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// TW Snapshot
// Input SHA-256: b157139c7d41cd5d9bc1829c714121545a8e42ea64c094db8081d9741b032be0

// Sprite1 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "f", null);
yield* thread.procedures["ZBlock A %s"]("Hai!!!");
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "k", null);
retire(); return;
}; })

// Sprite1 ZBlock A %s
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ_Block_A_ (p0) {
if ((("" + p0).toLowerCase() === "Hai!!!".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass did not cast",}, b0, false, false, "m", null);
} else {
yield* executeInCompatibilityLayer({"MESSAGE":"fail was casted",}, b0, false, false, "n", null);
}
return "";
}; })
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// TW Snapshot
// Input SHA-256: b157139c7d41cd5d9bc1829c714121545a8e42ea64c094db8081d9741b032be0

// Sprite1 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "f", null);
yield* thread.procedures["ZBlock A %s"]("Hai!!!");
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "k", null);
retire(); return;
}; })

// Sprite1 ZBlock A %s
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ_Block_A_ (p0) {
if ((("" + p0).toLowerCase() === "Hai!!!".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass did not cast",}, b0, false, false, "m", null);
} else {
yield* executeInCompatibilityLayer({"MESSAGE":"fail was casted",}, b0, false, false, "n", null);
}
return "";
}; })

0 comments on commit fcee94f

Please sign in to comment.