Skip to content

Commit 179030a

Browse files
authored
Don't eagerly cast boolean arguments to boolean (#223)
Fixes #222
1 parent 99ff662 commit 179030a

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

src/compiler/irgen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class ScriptTreeGenerator {
202202
};
203203
}
204204
return {
205-
kind: 'args.stringNumber',
205+
kind: 'procedures.argument',
206206
index: index
207207
};
208208
}
@@ -223,7 +223,7 @@ class ScriptTreeGenerator {
223223
};
224224
}
225225
return {
226-
kind: 'args.boolean',
226+
kind: 'procedures.argument',
227227
index: index
228228
};
229229
}

src/compiler/jsgen.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,6 @@ class JSGenerator {
433433
case 'addons.call':
434434
return new TypedInput(`(${this.descendAddonCall(node)})`, TYPE_UNKNOWN);
435435

436-
case 'args.boolean':
437-
return new TypedInput(`toBoolean(p${node.index})`, TYPE_BOOLEAN);
438-
case 'args.stringNumber':
439-
return new TypedInput(`p${node.index}`, TYPE_UNKNOWN);
440-
441436
case 'compat':
442437
// Compatibility layer inputs never use flags.
443438
return new TypedInput(`(${this.generateCompatibilityLayerCall(node, false)})`, TYPE_UNKNOWN);
@@ -665,6 +660,8 @@ class JSGenerator {
665660
}
666661
return new TypedInput(`${procedureReference}(${joinedArgs})`, TYPE_UNKNOWN);
667662
}
663+
case 'procedures.argument':
664+
return new TypedInput(`p${node.index}`, TYPE_UNKNOWN);
668665

669666
case 'sensing.answer':
670667
return new TypedInput(`runtime.ext_scratch3_sensing._answer`, TYPE_STRING);
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// TW Snapshot
2+
// Input SHA-256: 9ecff9e3c4b1dcdf3e23d0e49c0a2da3de446b6d626a2b5ee39d761be20344ca
3+
4+
// Sprite1 script
5+
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
6+
const b0 = runtime.getOpcodeFunction("looks_say");
7+
return function* genXYZ () {
8+
yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "f", null);
9+
yield* thread.procedures["ZBlock A %s"]("Hai!!!");
10+
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "k", null);
11+
retire(); return;
12+
}; })
13+
14+
// Sprite1 ZBlock A %s
15+
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
16+
const b0 = runtime.getOpcodeFunction("looks_say");
17+
return function* genXYZ_Block_A_ (p0) {
18+
if ((("" + p0).toLowerCase() === "Hai!!!".toLowerCase())) {
19+
yield* executeInCompatibilityLayer({"MESSAGE":"pass did not cast",}, b0, false, false, "m", null);
20+
} else {
21+
yield* executeInCompatibilityLayer({"MESSAGE":"fail was casted",}, b0, false, false, "n", null);
22+
}
23+
return "";
24+
}; })
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// TW Snapshot
2+
// Input SHA-256: 9ecff9e3c4b1dcdf3e23d0e49c0a2da3de446b6d626a2b5ee39d761be20344ca
3+
4+
// Sprite1 script
5+
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
6+
const b0 = runtime.getOpcodeFunction("looks_say");
7+
return function* genXYZ () {
8+
yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "f", null);
9+
yield* thread.procedures["ZBlock A %s"]("Hai!!!");
10+
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "k", null);
11+
retire(); return;
12+
}; })
13+
14+
// Sprite1 ZBlock A %s
15+
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
16+
const b0 = runtime.getOpcodeFunction("looks_say");
17+
return function* genXYZ_Block_A_ (p0) {
18+
if ((("" + p0).toLowerCase() === "Hai!!!".toLowerCase())) {
19+
yield* executeInCompatibilityLayer({"MESSAGE":"pass did not cast",}, b0, false, false, "m", null);
20+
} else {
21+
yield* executeInCompatibilityLayer({"MESSAGE":"fail was casted",}, b0, false, false, "n", null);
22+
}
23+
return "";
24+
}; })

0 commit comments

Comments
 (0)