Skip to content

Commit 6596206

Browse files
committed
Revert "Check old compiler stub after main switch statement"
This reverts commit c553490. My Blocks Plus needs this
1 parent 35ed95c commit 6596206

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

src/compiler/irgen.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ class ScriptTreeGenerator {
9898
}
9999
}
100100

101-
this.oldCompilerStub = new oldCompilerCompatiblity.ScriptTreeGeneratorStub(this);
101+
this.oldCompilerStub = (
102+
oldCompilerCompatiblity.enabled ?
103+
new oldCompilerCompatiblity.ScriptTreeGeneratorStub(this) :
104+
null
105+
);
102106
}
103107

104108
setProcedureVariant (procedureVariant) {
@@ -202,6 +206,13 @@ class ScriptTreeGenerator {
202206
* @returns {IntermediateInput} Compiled input node for this input.
203207
*/
204208
descendInput (block, preserveStrings = false) {
209+
if (this.oldCompilerStub) {
210+
const oldCompilerResult = this.oldCompilerStub.descendInputFromNewCompiler(block);
211+
if (oldCompilerResult) {
212+
return oldCompilerResult;
213+
}
214+
}
215+
205216
switch (block.opcode) {
206217
case 'colour_picker':
207218
return this.createConstantInput(block.fields.COLOUR.value, true);
@@ -566,14 +577,7 @@ class ScriptTreeGenerator {
566577
if (compatBlocks.inputs.includes(block.opcode)) {
567578
return this.descendCompatLayerInput(block);
568579
}
569-
570-
// It might be an extension block using patches for the old compiler.
571-
const oldCompilerResult = this.oldCompilerStub.descendInputFromNewCompiler(block);
572-
if (oldCompilerResult) {
573-
return oldCompilerResult;
574-
}
575-
576-
// It might be an extension block using the default compatibility layer.
580+
// It might be an extension block.
577581
const blockInfo = this.getBlockInfo(block.opcode);
578582
if (blockInfo) {
579583
const type = blockInfo.info.blockType;
@@ -603,6 +607,13 @@ class ScriptTreeGenerator {
603607
* @returns {IntermediateStackBlock} Compiled node for this block.
604608
*/
605609
descendStackedBlock (block) {
610+
if (this.oldCompilerStub) {
611+
const oldCompilerResult = this.oldCompilerStub.descendStackedBlockFromNewCompiler(block);
612+
if (oldCompilerResult) {
613+
return oldCompilerResult;
614+
}
615+
}
616+
606617
switch (block.opcode) {
607618
case 'control_all_at_once':
608619
// In Scratch 3, this block behaves like "if 1 = 1"
@@ -944,14 +955,7 @@ class ScriptTreeGenerator {
944955
if (compatBlocks.stacked.includes(block.opcode)) {
945956
return this.descendCompatLayerStack(block);
946957
}
947-
948-
// It might be an extension block using patches for the old compiler.
949-
const oldCompilerResult = this.oldCompilerStub.descendStackedBlockFromNewCompiler(block);
950-
if (oldCompilerResult) {
951-
return oldCompilerResult;
952-
}
953-
954-
// It might be an extension block using the default compatibility layer.
958+
// It might be an extension block.
955959
const blockInfo = this.getBlockInfo(block.opcode);
956960
if (blockInfo) {
957961
const type = blockInfo.info.blockType;

src/compiler/old-compiler-compatibility.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* opaque objects.
1616
* - Extensions need to implement the JS generators for all AST node kinds
1717
* they use. Can not rely on the defualt JS generator.
18-
* - Extensions do not try to override the behavior of native blocks.
1918
*/
2019

2120
const {InputOpcode, InputType} = require('./enums');
@@ -347,6 +346,7 @@ JSGeneratorStub.unstable_exports = {
347346
};
348347

349348
const oldCompilerCompatibility = {
349+
enabled: false,
350350
IRGeneratorStub,
351351
ScriptTreeGeneratorStub,
352352
TypedInput,

src/virtual-machine.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ class VirtualMachine extends EventEmitter {
244244

245245
i_will_not_ask_for_help_when_these_break: () => {
246246
this.emit('LEGACY_EXTENSION_API', 'i_will_not_ask_for_help_when_these_break');
247+
247248
const oldCompilerCompatibility = require('./compiler/old-compiler-compatibility.js');
249+
oldCompilerCompatibility.enabled = true;
250+
248251
return {
249252
IRGenerator: oldCompilerCompatibility.IRGeneratorStub,
250253
ScriptTreeGenerator: oldCompilerCompatibility.ScriptTreeGeneratorStub,

0 commit comments

Comments
 (0)