Skip to content

Commit bf7ae82

Browse files
authored
Merge pull request #290 from Tacodiva/compiler-int-type-fix
Make types for blocks which return ints more specific
2 parents 7051b87 + 8fe321c commit bf7ae82

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

src/compiler/irgen.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class ScriptTreeGenerator {
262262
index: this.descendInputOfBlock(block, 'INDEX')
263263
});
264264
case 'data_lengthoflist':
265-
return new IntermediateInput(InputOpcode.LIST_LENGTH, InputType.NUMBER_POS_REAL | InputType.NUMBER_ZERO, {
265+
return new IntermediateInput(InputOpcode.LIST_LENGTH, InputType.NUMBER_POS_INT | InputType.NUMBER_ZERO, {
266266
list: this.descendVariable(block, 'LIST', LIST_TYPE)
267267
});
268268
case 'data_listcontainsitem':
@@ -271,7 +271,7 @@ class ScriptTreeGenerator {
271271
item: this.descendInputOfBlock(block, 'ITEM')
272272
});
273273
case 'data_itemnumoflist':
274-
return new IntermediateInput(InputOpcode.LIST_INDEX_OF, InputType.NUMBER_POS_REAL | InputType.NUMBER_ZERO, {
274+
return new IntermediateInput(InputOpcode.LIST_INDEX_OF, InputType.NUMBER_POS_INT | InputType.NUMBER_ZERO, {
275275
list: this.descendVariable(block, 'LIST', LIST_TYPE),
276276
item: this.descendInputOfBlock(block, 'ITEM')
277277
});
@@ -290,12 +290,12 @@ class ScriptTreeGenerator {
290290

291291
case 'looks_backdropnumbername':
292292
if (block.fields.NUMBER_NAME.value === 'number') {
293-
return new IntermediateInput(InputOpcode.LOOKS_BACKDROP_NUMBER, InputType.NUMBER_POS_REAL);
293+
return new IntermediateInput(InputOpcode.LOOKS_BACKDROP_NUMBER, InputType.NUMBER_POS_INT);
294294
}
295295
return new IntermediateInput(InputOpcode.LOOKS_BACKDROP_NAME, InputType.STRING);
296296
case 'looks_costumenumbername':
297297
if (block.fields.NUMBER_NAME.value === 'number') {
298-
return new IntermediateInput(InputOpcode.LOOKS_COSTUME_NUMBER, InputType.NUMBER_POS_REAL);
298+
return new IntermediateInput(InputOpcode.LOOKS_COSTUME_NUMBER, InputType.NUMBER_POS_INT);
299299
}
300300
return new IntermediateInput(InputOpcode.LOOKS_COSTUME_NAME, InputType.STRING);
301301
case 'looks_size':
@@ -482,13 +482,13 @@ class ScriptTreeGenerator {
482482
});
483483
case 'sensing_current':
484484
switch (block.fields.CURRENTMENU.value.toLowerCase()) {
485-
case 'year': return new IntermediateInput(InputOpcode.SENSING_TIME_YEAR, InputType.NUMBER_POS_REAL | InputType.NUMBER_ZERO);
486-
case 'month': return new IntermediateInput(InputOpcode.SENSING_TIME_MONTH, InputType.NUMBER_POS_REAL);
487-
case 'date': return new IntermediateInput(InputOpcode.SENSING_TIME_DATE, InputType.NUMBER_POS_REAL);
488-
case 'dayofweek': return new IntermediateInput(InputOpcode.SENSING_TIME_WEEKDAY, InputType.NUMBER_POS_REAL);
489-
case 'hour': return new IntermediateInput(InputOpcode.SENSING_TIME_HOUR, InputType.NUMBER_POS_REAL | InputType.NUMBER_ZERO);
490-
case 'minute': return new IntermediateInput(InputOpcode.SENSING_TIME_MINUTE, InputType.NUMBER_POS_REAL | InputType.NUMBER_ZERO);
491-
case 'second': return new IntermediateInput(InputOpcode.SENSING_TIME_SECOND, InputType.NUMBER_POS_REAL | InputType.NUMBER_ZERO);
485+
case 'year': return new IntermediateInput(InputOpcode.SENSING_TIME_YEAR, InputType.NUMBER_POS_INT | InputType.NUMBER_ZERO);
486+
case 'month': return new IntermediateInput(InputOpcode.SENSING_TIME_MONTH, InputType.NUMBER_POS_INT);
487+
case 'date': return new IntermediateInput(InputOpcode.SENSING_TIME_DATE, InputType.NUMBER_POS_INT);
488+
case 'dayofweek': return new IntermediateInput(InputOpcode.SENSING_TIME_WEEKDAY, InputType.NUMBER_POS_INT);
489+
case 'hour': return new IntermediateInput(InputOpcode.SENSING_TIME_HOUR, InputType.NUMBER_POS_INT | InputType.NUMBER_ZERO);
490+
case 'minute': return new IntermediateInput(InputOpcode.SENSING_TIME_MINUTE, InputType.NUMBER_POS_INT | InputType.NUMBER_ZERO);
491+
case 'second': return new IntermediateInput(InputOpcode.SENSING_TIME_SECOND, InputType.NUMBER_POS_INT | InputType.NUMBER_ZERO);
492492
default: return this.createConstantInput(0);
493493
}
494494
case 'sensing_dayssince2000':
@@ -523,7 +523,7 @@ class ScriptTreeGenerator {
523523
switch (property) {
524524
case 'background #': // fallthrough for scratch 1.0 compatibility
525525
case 'backdrop #':
526-
return new IntermediateInput(InputOpcode.SENSING_OF_BACKDROP_NUMBER, InputType.NUMBER_POS_REAL);
526+
return new IntermediateInput(InputOpcode.SENSING_OF_BACKDROP_NUMBER, InputType.NUMBER_POS_INT);
527527
case 'backdrop name':
528528
return new IntermediateInput(InputOpcode.SENSING_OF_BACKDROP_NAME, InputType.STRING);
529529
}
@@ -536,7 +536,7 @@ class ScriptTreeGenerator {
536536
case 'direction':
537537
return new IntermediateInput(InputOpcode.SENSING_OF_DIRECTION, InputType.NUMBER_REAL, {object});
538538
case 'costume #':
539-
return new IntermediateInput(InputOpcode.SENSING_OF_COSTUME_NUMBER, InputType.NUMBER_POS_REAL, {object});
539+
return new IntermediateInput(InputOpcode.SENSING_OF_COSTUME_NUMBER, InputType.NUMBER_POS_INT, {object});
540540
case 'costume name':
541541
return new IntermediateInput(InputOpcode.SENSING_OF_COSTUME_NAME, InputType.STRING, {object});
542542
case 'size':

test/snapshot/__snapshots__/tw-gh-249-quicksort.sb3.tw-snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const b1 = stage.variables["rQq!wAuU2T9DV9,S[/s."];
1919
return function funXYZ_run () {
2020
b0.value = [];
2121
for (var a0 = 100; a0 >= 0.5; a0--) {
22-
b0.value.push((b1.value[((b0.value.length + 1) | 0) - 1] ?? ""));
22+
b0.value.push((b1.value[(b0.value.length + 1) - 1] ?? ""));
2323
b0._monitorUpToDate = false;
2424
}
2525
thread.procedures["Wqsort %s %s"](1,b0.value.length);

test/snapshot/__snapshots__/warp-timer/tw-gh-249-quicksort.sb3.tw-snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const b1 = stage.variables["rQq!wAuU2T9DV9,S[/s."];
1919
return function* genXYZ_run () {
2020
b0.value = [];
2121
for (var a0 = 100; a0 >= 0.5; a0--) {
22-
b0.value.push((b1.value[((b0.value.length + 1) | 0) - 1] ?? ""));
22+
b0.value.push((b1.value[(b0.value.length + 1) - 1] ?? ""));
2323
b0._monitorUpToDate = false;
2424
if (isStuck()) yield;
2525
}

0 commit comments

Comments
 (0)