porffor 0.37.4 → 0.37.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/builtins_precompiled.js +205 -205
- package/compiler/codegen.js +71 -72
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -588,8 +588,8 @@ const truthy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMod
|
|
588
588
|
...wasm,
|
589
589
|
...(!useTmp ? [] : [ [ Opcodes.local_set, tmp ] ]),
|
590
590
|
|
591
|
-
...typeSwitch(scope, type,
|
592
|
-
[TYPES.string]
|
591
|
+
...typeSwitch(scope, type, [
|
592
|
+
[ [ TYPES.string, TYPES.bytestring ], [
|
593
593
|
...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
|
594
594
|
...(intIn ? [] : [ Opcodes.i32_to_u ]),
|
595
595
|
|
@@ -600,18 +600,9 @@ const truthy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMod
|
|
600
600
|
/* [ Opcodes.i32_eqz ],
|
601
601
|
[ Opcodes.i32_eqz ], */
|
602
602
|
...(intOut ? [] : [ Opcodes.i32_from_u ])
|
603
|
-
],
|
604
|
-
[
|
605
|
-
|
606
|
-
...(intIn ? [] : [ Opcodes.i32_to_u ]),
|
607
|
-
|
608
|
-
// get length
|
609
|
-
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 0 ],
|
610
|
-
|
611
|
-
...(intOut ? [] : [ Opcodes.i32_from_u ])
|
612
|
-
],
|
613
|
-
default: def
|
614
|
-
}, intOut ? Valtype.i32 : valtypeBinary)
|
603
|
+
] ],
|
604
|
+
[ 'default', def ]
|
605
|
+
], intOut ? Valtype.i32 : valtypeBinary)
|
615
606
|
];
|
616
607
|
};
|
617
608
|
|
@@ -651,8 +642,8 @@ const falsy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMode
|
|
651
642
|
...wasm,
|
652
643
|
...(!useTmp ? [] : [ [ Opcodes.local_set, tmp ] ]),
|
653
644
|
|
654
|
-
...typeSwitch(scope, type,
|
655
|
-
[TYPES.string]
|
645
|
+
...typeSwitch(scope, type, [
|
646
|
+
[ [ TYPES.string, TYPES.bytestring ], [
|
656
647
|
...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
|
657
648
|
...(intIn ? [] : [ Opcodes.i32_to_u ]),
|
658
649
|
|
@@ -662,20 +653,9 @@ const falsy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMode
|
|
662
653
|
// if length == 0
|
663
654
|
[ Opcodes.i32_eqz ],
|
664
655
|
...(intOut ? [] : [ Opcodes.i32_from_u ])
|
665
|
-
],
|
666
|
-
[
|
667
|
-
|
668
|
-
...(intIn ? [] : [ Opcodes.i32_to_u ]),
|
669
|
-
|
670
|
-
// get length
|
671
|
-
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 0 ],
|
672
|
-
|
673
|
-
// if length == 0
|
674
|
-
[ Opcodes.i32_eqz ],
|
675
|
-
...(intOut ? [] : [ Opcodes.i32_from_u ])
|
676
|
-
],
|
677
|
-
default: def
|
678
|
-
}, intOut ? Valtype.i32 : valtypeBinary)
|
656
|
+
] ],
|
657
|
+
[ 'default', def ]
|
658
|
+
], intOut ? Valtype.i32 : valtypeBinary)
|
679
659
|
];
|
680
660
|
};
|
681
661
|
|
@@ -687,30 +667,25 @@ const nullish = (scope, wasm, type, intIn = false, intOut = false) => {
|
|
687
667
|
...wasm,
|
688
668
|
...(!useTmp ? [] : [ [ Opcodes.local_set, tmp ] ]),
|
689
669
|
|
690
|
-
...typeSwitch(scope, type,
|
691
|
-
[TYPES.empty]
|
670
|
+
...typeSwitch(scope, type, [
|
671
|
+
[ [ TYPES.empty, TYPES.undefined ], [
|
692
672
|
// empty
|
693
673
|
...(!useTmp ? [ [ Opcodes.drop ] ] : []),
|
694
674
|
...number(1, intOut ? Valtype.i32 : valtypeBinary)
|
695
|
-
],
|
696
|
-
[TYPES.
|
697
|
-
// undefined
|
698
|
-
...(!useTmp ? [ [ Opcodes.drop ] ] : []),
|
699
|
-
...number(1, intOut ? Valtype.i32 : valtypeBinary)
|
700
|
-
],
|
701
|
-
[TYPES.object]: [
|
675
|
+
] ],
|
676
|
+
[ TYPES.object, [
|
702
677
|
// object, null if == 0
|
703
678
|
...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
|
704
679
|
|
705
680
|
...(intIn ? [ [ Opcodes.i32_eqz ] ] : [ ...Opcodes.eqz ]),
|
706
681
|
...(intOut ? [] : [ Opcodes.i32_from_u ])
|
707
|
-
],
|
708
|
-
default
|
682
|
+
] ],
|
683
|
+
[ 'default', [
|
709
684
|
// not
|
710
685
|
...(!useTmp ? [ [ Opcodes.drop ] ] : []),
|
711
686
|
...number(0, intOut ? Valtype.i32 : valtypeBinary)
|
712
|
-
]
|
713
|
-
|
687
|
+
] ]
|
688
|
+
], intOut ? Valtype.i32 : valtypeBinary)
|
714
689
|
];
|
715
690
|
};
|
716
691
|
|
@@ -2720,7 +2695,23 @@ let typeswitchDepth = 0;
|
|
2720
2695
|
const typeSwitch = (scope, type, bc, returns = valtypeBinary, fallthrough = false) => {
|
2721
2696
|
const known = knownType(scope, type);
|
2722
2697
|
if (known != null) {
|
2723
|
-
|
2698
|
+
if (Array.isArray(bc)) {
|
2699
|
+
let def;
|
2700
|
+
for (const [ type, wasm ] of bc) {
|
2701
|
+
if (type === 'default') {
|
2702
|
+
def = wasm;
|
2703
|
+
continue;
|
2704
|
+
}
|
2705
|
+
|
2706
|
+
if (Array.isArray(type)) {
|
2707
|
+
if (type.includes(known)) return wasm;
|
2708
|
+
} else if (type === known) return wasm;
|
2709
|
+
}
|
2710
|
+
|
2711
|
+
return def;
|
2712
|
+
} else {
|
2713
|
+
return bc[known] ?? bc.default;
|
2714
|
+
}
|
2724
2715
|
}
|
2725
2716
|
|
2726
2717
|
if (Prefs.typeswitchBrtable) {
|
@@ -2728,9 +2719,7 @@ const typeSwitch = (scope, type, bc, returns = valtypeBinary, fallthrough = fals
|
|
2728
2719
|
return brTable(type, bc, returns);
|
2729
2720
|
}
|
2730
2721
|
|
2731
|
-
typeswitchDepth
|
2732
|
-
|
2733
|
-
const tmp = localTmp(scope, `#typeswitch_tmp${typeswitchDepth}${Prefs.typeswitchUniqueTmp ? uniqId() : ''}`, Valtype.i32);
|
2722
|
+
const tmp = localTmp(scope, `#typeswitch_tmp${++typeswitchDepth}${Prefs.typeswitchUniqueTmp ? uniqId() : ''}`, Valtype.i32);
|
2734
2723
|
const out = [
|
2735
2724
|
...type,
|
2736
2725
|
[ Opcodes.local_set, tmp ],
|
@@ -2739,28 +2728,39 @@ const typeSwitch = (scope, type, bc, returns = valtypeBinary, fallthrough = fals
|
|
2739
2728
|
|
2740
2729
|
if (typeof bc === 'function') bc = bc();
|
2741
2730
|
|
2742
|
-
let
|
2743
|
-
if (!Array.isArray(
|
2744
|
-
|
2731
|
+
let def;
|
2732
|
+
if (!Array.isArray(bc)) {
|
2733
|
+
def = bc.default;
|
2734
|
+
bc = Object.entries(bc);
|
2745
2735
|
}
|
2746
2736
|
|
2747
|
-
for (let i = 0; i <
|
2748
|
-
let [
|
2749
|
-
if (
|
2750
|
-
|
2737
|
+
for (let i = 0; i < bc.length; i++) {
|
2738
|
+
let [ type, wasm ] = bc[i];
|
2739
|
+
if (type === 'default') {
|
2740
|
+
def = wasm;
|
2741
|
+
continue;
|
2742
|
+
}
|
2743
|
+
|
2744
|
+
if (Array.isArray(type)) {
|
2745
|
+
for (let j = 0; j < type.length; j++) {
|
2746
|
+
out.push(
|
2747
|
+
[ Opcodes.local_get, tmp ],
|
2748
|
+
...number(type[j], Valtype.i32),
|
2749
|
+
[ Opcodes.i32_eq ]
|
2750
|
+
);
|
2751
2751
|
|
2752
|
-
|
2752
|
+
if (j > 0) out.push([ Opcodes.i32_or ]);
|
2753
|
+
}
|
2754
|
+
} else {
|
2753
2755
|
out.push(
|
2754
2756
|
[ Opcodes.local_get, tmp ],
|
2755
|
-
...number(
|
2757
|
+
...number(type, Valtype.i32),
|
2756
2758
|
[ Opcodes.i32_eq ]
|
2757
2759
|
);
|
2758
|
-
|
2759
|
-
if (j > 0) out.push([ Opcodes.i32_or ]);
|
2760
2760
|
}
|
2761
2761
|
|
2762
2762
|
out.push(
|
2763
|
-
[ Opcodes.if, Blocktype.void, `TYPESWITCH|${
|
2763
|
+
[ Opcodes.if, Blocktype.void, `TYPESWITCH|${Array.isArray(type) ? type.map(t => TYPE_NAMES[t]).join(',') : TYPE_NAMES[type]}` ],
|
2764
2764
|
...wasm,
|
2765
2765
|
...(fallthrough ? [] : [ [ Opcodes.br, 1 ] ]),
|
2766
2766
|
[ Opcodes.end ]
|
@@ -2768,7 +2768,7 @@ const typeSwitch = (scope, type, bc, returns = valtypeBinary, fallthrough = fals
|
|
2768
2768
|
}
|
2769
2769
|
|
2770
2770
|
// default
|
2771
|
-
if (
|
2771
|
+
if (def) out.push(...def);
|
2772
2772
|
else if (returns !== Blocktype.void) out.push(...number(0, returns));
|
2773
2773
|
|
2774
2774
|
out.push([ Opcodes.end, 'TYPESWITCH_end' ]);
|
@@ -3661,19 +3661,18 @@ const generateUnary = (scope, decl) => {
|
|
3661
3661
|
const out = toGenerate ? generate(scope, decl.argument) : [];
|
3662
3662
|
disposeLeftover(out);
|
3663
3663
|
|
3664
|
-
out.push(...typeSwitch(scope, overrideType ?? getNodeType(scope, decl.argument),
|
3665
|
-
[TYPES.number
|
3666
|
-
[TYPES.boolean
|
3667
|
-
[TYPES.string
|
3668
|
-
[TYPES.undefined]
|
3669
|
-
[TYPES.function
|
3670
|
-
[TYPES.symbol
|
3671
|
-
[TYPES.bytestring
|
3672
|
-
[TYPES.empty]: makeString(scope, 'undefined', false, '#typeof_result'),
|
3664
|
+
out.push(...typeSwitch(scope, overrideType ?? getNodeType(scope, decl.argument), [
|
3665
|
+
[ TYPES.number, makeString(scope, 'number', false, '#typeof_result') ],
|
3666
|
+
[ TYPES.boolean, makeString(scope, 'boolean', false, '#typeof_result') ],
|
3667
|
+
[ TYPES.string, makeString(scope, 'string', false, '#typeof_result') ],
|
3668
|
+
[ [ TYPES.undefined, TYPES.empty ], makeString(scope, 'undefined', false, '#typeof_result') ],
|
3669
|
+
[ TYPES.function, makeString(scope, 'function', false, '#typeof_result') ],
|
3670
|
+
[ TYPES.symbol, makeString(scope, 'symbol', false, '#typeof_result') ],
|
3671
|
+
[ TYPES.bytestring, makeString(scope, 'string', false, '#typeof_result') ],
|
3673
3672
|
|
3674
3673
|
// object and internal types
|
3675
|
-
default
|
3676
|
-
|
3674
|
+
[ 'default', makeString(scope, 'object', false, '#typeof_result') ],
|
3675
|
+
]));
|
3677
3676
|
|
3678
3677
|
return out;
|
3679
3678
|
}
|
@@ -3991,7 +3990,7 @@ const generateForOf = (scope, decl) => {
|
|
3991
3990
|
Opcodes.i32_from_u,
|
3992
3991
|
[ Opcodes.local_set, tmp ],
|
3993
3992
|
|
3994
|
-
|
3993
|
+
...setVar,
|
3995
3994
|
|
3996
3995
|
[ Opcodes.block, Blocktype.void ],
|
3997
3996
|
[ Opcodes.block, Blocktype.void ],
|
package/package.json
CHANGED