Skip to content

Commit 3752219

Browse files
committed
Compile looks_say and looks_think without compatibility layer
1 parent 36d4d82 commit 3752219

File tree

131 files changed

+2387
-2560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+2387
-2560
lines changed

src/blocks/scratch3_looks.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,10 @@ class Scratch3LooksBlocks {
352352
}
353353

354354
think (args, util) {
355-
this.runtime.emit(Scratch3LooksBlocks.SAY_OR_THINK, util.target, 'think', args.MESSAGE);
355+
this._think(args.MESSAGE, util.target);
356+
}
357+
_think (message, target) { // used by compiler
358+
this.runtime.emit(Scratch3LooksBlocks.SAY_OR_THINK, target, 'think', message);
356359
}
357360

358361
thinkforsecs (args, util) {

src/compiler/compat-blocks.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
const stacked = [
1111
'looks_changestretchby',
1212
'looks_hideallsprites',
13-
'looks_say',
1413
'looks_sayforsecs',
1514
'looks_setstretchto',
1615
'looks_switchbackdroptoandwait',
17-
'looks_think',
1816
'looks_thinkforsecs',
1917
'motion_align_scene',
2018
'motion_glidesecstoxy',

src/compiler/enums.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ const StackOpcode = {
152152
LOOKS_BACKDROP_SET: 'looks.switchBackdrop',
153153
LOOKS_COSTUME_NEXT: 'looks.nextCostume',
154154
LOOKS_COSTUME_SET: 'looks.switchCostume',
155+
LOOKS_SAY: 'looks.say',
156+
LOOKS_THINK: 'looks.think',
155157

156158
MOTION_X_SET: 'motion.setX',
157159
MOTION_X_CHANGE: 'motion.changeX',

src/compiler/irgen.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,10 @@ class ScriptTreeGenerator {
806806
return new IntermediateStackBlock(StackOpcode.LOOKS_BACKDROP_NEXT);
807807
case 'looks_nextcostume':
808808
return new IntermediateStackBlock(StackOpcode.LOOKS_COSTUME_NEXT);
809+
case 'looks_say':
810+
return new IntermediateStackBlock(StackOpcode.LOOKS_SAY, {
811+
message: this.descendInputOfBlock(block, 'MESSAGE')
812+
});
809813
case 'looks_seteffectto':
810814
return new IntermediateStackBlock(StackOpcode.LOOKS_EFFECT_SET, {
811815
effect: block.fields.EFFECT.value.toLowerCase(),
@@ -825,6 +829,10 @@ class ScriptTreeGenerator {
825829
return new IntermediateStackBlock(StackOpcode.LOOKS_COSTUME_SET, {
826830
costume: this.descendInputOfBlock(block, 'COSTUME', true)
827831
});
832+
case 'looks_think':
833+
return new IntermediateStackBlock(StackOpcode.LOOKS_THINK, {
834+
message: this.descendInputOfBlock(block, 'MESSAGE')
835+
});
828836

829837
case 'motion_changexby':
830838
return new IntermediateStackBlock(StackOpcode.MOTION_X_CHANGE, {

src/compiler/jsgen.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,12 @@ class JSGenerator {
779779
case StackOpcode.LOOKS_COSTUME_SET:
780780
this.source += `runtime.ext_scratch3_looks._setCostume(target, ${this.descendInput(node.costume)});\n`;
781781
break;
782+
case StackOpcode.LOOKS_SAY:
783+
this.source += `runtime.ext_scratch3_looks._say(${this.descendInput(node.message)}, target);\n`;
784+
break;
785+
case StackOpcode.LOOKS_THINK:
786+
this.source += `runtime.ext_scratch3_looks._think(${this.descendInput(node.message)}, target);\n`;
787+
break;
782788

783789
case StackOpcode.MOTION_X_CHANGE:
784790
this.source += `target.setXY(target.x + ${this.descendInput(node.dx)}, target.y);\n`;

test/snapshot/__snapshots__/order-library-reverse.sb3.tw-snapshot

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
66
const b0 = stage.variables["p]KODv+)+:l=%NT~j3/d-order"];
77
const b1 = stage.variables["p]KODv+)+:l=%NT~j3/d-wait"];
8-
const b2 = runtime.getOpcodeFunction("looks_say");
98
return function* genXYZ () {
109
b0.value = 0;
1110
thread.timer = timer();
@@ -18,52 +17,50 @@ yield;
1817
thread.timer = null;
1918
b0.value = ((+b0.value || 0) + 1);
2019
if ((b0.value === 1)) {
21-
yield* executeInCompatibilityLayer({"MESSAGE":"pass order is correct (1)",}, b2, false, false, "]4hbk*5ix]V00h|!x1oy", null);
20+
runtime.ext_scratch3_looks._say("pass order is correct (1)", target);
2221
} else {
23-
yield* executeInCompatibilityLayer({"MESSAGE":("fail order is incorrect 1 != " + ("" + b0.value)),}, b2, false, false, "H=x@7SpNJeX|!}8x5y4,", null);
22+
runtime.ext_scratch3_looks._say(("fail order is incorrect 1 != " + ("" + b0.value)), target);
2423
}
2524
retire(); return;
2625
}; })
2726

2827
// Sprite3 script
2928
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
30-
const b0 = runtime.getOpcodeFunction("looks_say");
31-
const b1 = stage.variables["p]KODv+)+:l=%NT~j3/d-wait"];
29+
const b0 = stage.variables["p]KODv+)+:l=%NT~j3/d-wait"];
3230
return function* genXYZ () {
33-
yield* executeInCompatibilityLayer({"MESSAGE":"plan 2",}, b0, false, false, "1Ba%a0GIK#hwJ46y=WVt", null);
31+
runtime.ext_scratch3_looks._say("plan 2", target);
3432
thread.timer = timer();
35-
var a0 = Math.max(0, 1000 * (+b1.value || 0));
33+
var a0 = Math.max(0, 1000 * (+b0.value || 0));
3634
runtime.requestRedraw();
3735
yield;
3836
while (thread.timer.timeElapsed() < a0) {
3937
yield;
4038
}
4139
thread.timer = null;
4240
thread.timer = timer();
43-
var a1 = Math.max(0, 1000 * (+b1.value || 0));
41+
var a1 = Math.max(0, 1000 * (+b0.value || 0));
4442
runtime.requestRedraw();
4543
yield;
4644
while (thread.timer.timeElapsed() < a1) {
4745
yield;
4846
}
4947
thread.timer = null;
5048
thread.timer = timer();
51-
var a2 = Math.max(0, 1000 * (+b1.value || 0));
49+
var a2 = Math.max(0, 1000 * (+b0.value || 0));
5250
runtime.requestRedraw();
5351
yield;
5452
while (thread.timer.timeElapsed() < a2) {
5553
yield;
5654
}
5755
thread.timer = null;
58-
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "}-I/zE+.RSi`:h[RxMvQ", null);
56+
runtime.ext_scratch3_looks._say("end", target);
5957
retire(); return;
6058
}; })
6159

6260
// Sprite1 script
6361
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
6462
const b0 = stage.variables["p]KODv+)+:l=%NT~j3/d-order"];
6563
const b1 = stage.variables["p]KODv+)+:l=%NT~j3/d-wait"];
66-
const b2 = runtime.getOpcodeFunction("looks_say");
6764
return function* genXYZ () {
6865
b0.value = 0;
6966
thread.timer = timer();
@@ -76,9 +73,9 @@ yield;
7673
thread.timer = null;
7774
b0.value = ((+b0.value || 0) + 1);
7875
if ((b0.value === 2)) {
79-
yield* executeInCompatibilityLayer({"MESSAGE":"pass order is correct (2)",}, b2, false, false, "0i[-T:vYTt=bi47@byUE", null);
76+
runtime.ext_scratch3_looks._say("pass order is correct (2)", target);
8077
} else {
81-
yield* executeInCompatibilityLayer({"MESSAGE":("fail order is incorrect 2 != " + ("" + b0.value)),}, b2, false, false, "Coc1aZ;L9M-RyEt`syps", null);
78+
runtime.ext_scratch3_looks._say(("fail order is incorrect 2 != " + ("" + b0.value)), target);
8279
}
8380
retire(); return;
8481
}; })

test/snapshot/__snapshots__/order-library.sb3.tw-snapshot

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,41 @@
33

44
// Sprite3 script
55
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
6-
const b0 = runtime.getOpcodeFunction("looks_say");
7-
const b1 = stage.variables["):/PVGTvoVRvq(ikGwRE-wait"];
6+
const b0 = stage.variables["):/PVGTvoVRvq(ikGwRE-wait"];
87
return function* genXYZ () {
9-
yield* executeInCompatibilityLayer({"MESSAGE":"plan 2",}, b0, false, false, "s+@:|^WPr8]N1Y9Hk2f5", null);
8+
runtime.ext_scratch3_looks._say("plan 2", target);
109
thread.timer = timer();
11-
var a0 = Math.max(0, 1000 * (+b1.value || 0));
10+
var a0 = Math.max(0, 1000 * (+b0.value || 0));
1211
runtime.requestRedraw();
1312
yield;
1413
while (thread.timer.timeElapsed() < a0) {
1514
yield;
1615
}
1716
thread.timer = null;
1817
thread.timer = timer();
19-
var a1 = Math.max(0, 1000 * (+b1.value || 0));
18+
var a1 = Math.max(0, 1000 * (+b0.value || 0));
2019
runtime.requestRedraw();
2120
yield;
2221
while (thread.timer.timeElapsed() < a1) {
2322
yield;
2423
}
2524
thread.timer = null;
2625
thread.timer = timer();
27-
var a2 = Math.max(0, 1000 * (+b1.value || 0));
26+
var a2 = Math.max(0, 1000 * (+b0.value || 0));
2827
runtime.requestRedraw();
2928
yield;
3029
while (thread.timer.timeElapsed() < a2) {
3130
yield;
3231
}
3332
thread.timer = null;
34-
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "7e7aA!PF-sxf1uka+sh2", null);
33+
runtime.ext_scratch3_looks._say("end", target);
3534
retire(); return;
3635
}; })
3736

3837
// Sprite1 script
3938
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
4039
const b0 = stage.variables["):/PVGTvoVRvq(ikGwRE-order"];
4140
const b1 = stage.variables["):/PVGTvoVRvq(ikGwRE-wait"];
42-
const b2 = runtime.getOpcodeFunction("looks_say");
4341
return function* genXYZ () {
4442
b0.value = 0;
4543
thread.timer = timer();
@@ -52,9 +50,9 @@ yield;
5250
thread.timer = null;
5351
b0.value = ((+b0.value || 0) + 1);
5452
if ((b0.value === 1)) {
55-
yield* executeInCompatibilityLayer({"MESSAGE":"pass order is correct (1)",}, b2, false, false, "RSQ{nVCc)6E)(`KlnFCF", null);
53+
runtime.ext_scratch3_looks._say("pass order is correct (1)", target);
5654
} else {
57-
yield* executeInCompatibilityLayer({"MESSAGE":("fail order is incorrect 1 != " + ("" + b0.value)),}, b2, false, false, "8k^j~`c^|YO@hkFd?~2d", null);
55+
runtime.ext_scratch3_looks._say(("fail order is incorrect 1 != " + ("" + b0.value)), target);
5856
}
5957
retire(); return;
6058
}; })
@@ -63,7 +61,6 @@ retire(); return;
6361
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
6462
const b0 = stage.variables["):/PVGTvoVRvq(ikGwRE-order"];
6563
const b1 = stage.variables["):/PVGTvoVRvq(ikGwRE-wait"];
66-
const b2 = runtime.getOpcodeFunction("looks_say");
6764
return function* genXYZ () {
6865
b0.value = 0;
6966
thread.timer = timer();
@@ -76,9 +73,9 @@ yield;
7673
thread.timer = null;
7774
b0.value = ((+b0.value || 0) + 1);
7875
if ((b0.value === 2)) {
79-
yield* executeInCompatibilityLayer({"MESSAGE":"pass order is correct (2)",}, b2, false, false, "KP?op(=Vg2#;@]!,C#.~", null);
76+
runtime.ext_scratch3_looks._say("pass order is correct (2)", target);
8077
} else {
81-
yield* executeInCompatibilityLayer({"MESSAGE":("fail order is incorrect 2 != " + ("" + b0.value)),}, b2, false, false, "=]|}L~4uQXTNtwJKw_;R", null);
78+
runtime.ext_scratch3_looks._say(("fail order is incorrect 2 != " + ("" + b0.value)), target);
8279
}
8380
retire(); return;
8481
}; })

test/snapshot/__snapshots__/tw-NaN.sb3.tw-snapshot

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,71 @@
33

44
// Sprite1 script
55
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
6-
const b0 = runtime.getOpcodeFunction("looks_say");
76
return function* genXYZ () {
8-
yield* executeInCompatibilityLayer({"MESSAGE":"plan 21",}, b0, false, false, "B", null);
7+
runtime.ext_scratch3_looks._say("plan 21", target);
98
if (!(("" + (0 / 0)).toLowerCase() === "0".toLowerCase())) {
10-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aA", null);
9+
runtime.ext_scratch3_looks._say("pass", target);
1110
}
1211
if ((("" + (0 * Infinity)).toLowerCase() === "NaN".toLowerCase())) {
13-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "/", null);
12+
runtime.ext_scratch3_looks._say("pass", target);
1413
}
1514
if (((((0 * Infinity) || 0) * 1) === 0)) {
16-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "?", null);
15+
runtime.ext_scratch3_looks._say("pass", target);
1716
}
1817
if ((("" + ((Math.acos(1.01) * 180) / Math.PI)).toLowerCase() === "NaN".toLowerCase())) {
19-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "=", null);
18+
runtime.ext_scratch3_looks._say("pass", target);
2019
}
2120
if ((((((Math.acos(1.01) * 180) / Math.PI) || 0) * 1) === 0)) {
22-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "]", null);
21+
runtime.ext_scratch3_looks._say("pass", target);
2322
}
2423
if ((("" + ((Math.asin(1.01) * 180) / Math.PI)).toLowerCase() === "NaN".toLowerCase())) {
25-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "_", null);
24+
runtime.ext_scratch3_looks._say("pass", target);
2625
}
2726
if ((((((Math.asin(1.01) * 180) / Math.PI) || 0) * 1) === 0)) {
28-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "{", null);
27+
runtime.ext_scratch3_looks._say("pass", target);
2928
}
3029
if ((("" + (0 / 0)).toLowerCase() === "NaN".toLowerCase())) {
31-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "}", null);
30+
runtime.ext_scratch3_looks._say("pass", target);
3231
}
3332
if (((((0 / 0) || 0) * 1) === 0)) {
34-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aa", null);
33+
runtime.ext_scratch3_looks._say("pass", target);
3534
}
3635
if ((("" + Math.sqrt(-1)).toLowerCase() === "NaN".toLowerCase())) {
37-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ac", null);
36+
runtime.ext_scratch3_looks._say("pass", target);
3837
}
3938
if ((((Math.sqrt(-1) || 0) * 1) === 0)) {
40-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ae", null);
39+
runtime.ext_scratch3_looks._say("pass", target);
4140
}
4241
if ((("" + mod(0, 0)).toLowerCase() === "NaN".toLowerCase())) {
43-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ag", null);
42+
runtime.ext_scratch3_looks._say("pass", target);
4443
}
4544
if ((((mod(0, 0) || 0) * 1) === 0)) {
46-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ai", null);
45+
runtime.ext_scratch3_looks._say("pass", target);
4746
}
4847
if ((("" + Math.log(-1)).toLowerCase() === "NaN".toLowerCase())) {
49-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ak", null);
48+
runtime.ext_scratch3_looks._say("pass", target);
5049
}
5150
if ((((Math.log(-1) || 0) * 1) === 0)) {
52-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "am", null);
51+
runtime.ext_scratch3_looks._say("pass", target);
5352
}
5453
if ((("" + (Math.log(-1) / Math.LN10)).toLowerCase() === "NaN".toLowerCase())) {
55-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ao", null);
54+
runtime.ext_scratch3_looks._say("pass", target);
5655
}
5756
if (((((Math.log(-1) / Math.LN10) || 0) * 1) === 0)) {
58-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aq", null);
57+
runtime.ext_scratch3_looks._say("pass", target);
5958
}
6059
if (((((Math.round(Math.sin((Math.PI * (1 / 0)) / 180) * 1e10) / 1e10) || 0) * 1) === 0)) {
61-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "as", null);
60+
runtime.ext_scratch3_looks._say("pass", target);
6261
}
6362
if (((((Math.round(Math.cos((Math.PI * (1 / 0)) / 180) * 1e10) / 1e10) || 0) * 1) === 0)) {
64-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "au", null);
63+
runtime.ext_scratch3_looks._say("pass", target);
6564
}
6665
if ((((tan((1 / 0)) || 0) * 1) === 0)) {
67-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aw", null);
66+
runtime.ext_scratch3_looks._say("pass", target);
6867
}
6968
if ((((runtime.ext_scratch3_operators._random((-1 / 0), (1 / 0)) || 0) * 1) === 0)) {
70-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ax", null);
69+
runtime.ext_scratch3_looks._say("pass", target);
7170
}
72-
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, ":", null);
71+
runtime.ext_scratch3_looks._say("end", target);
7372
retire(); return;
7473
}; })

test/snapshot/__snapshots__/tw-add-can-return-nan.sb3.tw-snapshot

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33

44
// Sprite1 script
55
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
6-
const b0 = runtime.getOpcodeFunction("looks_say");
76
return function* genXYZ () {
8-
yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "6_?4sPB-|g:DtjdOm5Q-", null);
7+
runtime.ext_scratch3_looks._say("plan 1", target);
98
if (!((Infinity + -Infinity) <= 0)) {
10-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, ")-u2YbbMb;gXMPOidjPj", null);
9+
runtime.ext_scratch3_looks._say("pass", target);
1110
}
12-
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "zqE}hdaes.b)@mO1{R;X", null);
11+
runtime.ext_scratch3_looks._say("end", target);
1312
retire(); return;
1413
}; })

test/snapshot/__snapshots__/tw-all-at-once.sb3.tw-snapshot

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33

44
// Sprite1 script
55
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
6-
const b0 = runtime.getOpcodeFunction("looks_say");
76
return function* genXYZ () {
8-
yield* executeInCompatibilityLayer({"MESSAGE":"plan 1",}, b0, false, false, "1TRvh{mBarwY!BX8`o$R", null);
7+
runtime.ext_scratch3_looks._say("plan 1", target);
98
if (true) {
10-
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "K|r`QjC126S.93lMawiD", null);
9+
runtime.ext_scratch3_looks._say("pass", target);
1110
}
12-
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "QaZ%(g:;bB~D+24z:U?l", null);
11+
runtime.ext_scratch3_looks._say("end", target);
1312
retire(); return;
1413
}; })

0 commit comments

Comments
 (0)