porffor 0.50.14 → 0.50.16
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.js +55 -55
- package/compiler/builtins_objects.js +6 -6
- package/compiler/builtins_precompiled.js +30 -30
- package/compiler/codegen.js +192 -190
- package/compiler/cyclone.js +3 -3
- package/compiler/embedding.js +7 -6
- package/compiler/opt.js +2 -2
- package/compiler/pgo.js +4 -4
- package/compiler/precompile.js +1 -1
- package/compiler/prototype.js +34 -34
- package/compiler/wrap.js +6 -6
- package/package.json +1 -1
- package/rhemyn/compile.js +20 -18
- package/runner/flamegraph.js +2 -2
- package/runner/index.js +1 -1
package/compiler/builtins.js
CHANGED
@@ -72,20 +72,20 @@ export const UNDEFINED = 0;
|
|
72
72
|
export const NULL = 0;
|
73
73
|
|
74
74
|
export const BuiltinVars = function(ctx) {
|
75
|
-
this.undefined = number(UNDEFINED);
|
75
|
+
this.undefined = [ number(UNDEFINED) ];
|
76
76
|
this.undefined.type = TYPES.undefined;
|
77
77
|
|
78
|
-
this.null = number(NULL);
|
78
|
+
this.null = [ number(NULL) ];
|
79
79
|
this.null.type = TYPES.object;
|
80
80
|
|
81
|
-
this.NaN = number(NaN);
|
81
|
+
this.NaN = [ number(NaN) ];
|
82
82
|
this.NaN.floatOnly = true;
|
83
83
|
|
84
|
-
this.Infinity = number(Infinity);
|
84
|
+
this.Infinity = [ number(Infinity) ];
|
85
85
|
this.Infinity.floatOnly = true;
|
86
86
|
|
87
87
|
for (const x in TYPES) {
|
88
|
-
this['__Porffor_TYPES_' + x] = () => number(TYPES[x]);
|
88
|
+
this['__Porffor_TYPES_' + x] = () => [ number(TYPES[x]) ];
|
89
89
|
}
|
90
90
|
|
91
91
|
this.__performance_timeOrigin = [
|
@@ -93,15 +93,15 @@ export const BuiltinVars = function(ctx) {
|
|
93
93
|
];
|
94
94
|
this.__performance_timeOrigin.usesImports = true;
|
95
95
|
|
96
|
-
this.__Uint8Array_BYTES_PER_ELEMENT = number(1);
|
97
|
-
this.__Int8Array_BYTES_PER_ELEMENT = number(1);
|
98
|
-
this.__Uint8ClampedArray_BYTES_PER_ELEMENT = number(1);
|
99
|
-
this.__Uint16Array_BYTES_PER_ELEMENT = number(2);
|
100
|
-
this.__Int16Array_BYTES_PER_ELEMENT = number(2);
|
101
|
-
this.__Uint32Array_BYTES_PER_ELEMENT = number(4);
|
102
|
-
this.__Int32Array_BYTES_PER_ELEMENT = number(4);
|
103
|
-
this.__Float32Array_BYTES_PER_ELEMENT = number(4);
|
104
|
-
this.__Float64Array_BYTES_PER_ELEMENT = number(8);
|
96
|
+
this.__Uint8Array_BYTES_PER_ELEMENT = [ number(1) ];
|
97
|
+
this.__Int8Array_BYTES_PER_ELEMENT = [ number(1) ];
|
98
|
+
this.__Uint8ClampedArray_BYTES_PER_ELEMENT = [ number(1) ];
|
99
|
+
this.__Uint16Array_BYTES_PER_ELEMENT = [ number(2) ];
|
100
|
+
this.__Int16Array_BYTES_PER_ELEMENT = [ number(2) ];
|
101
|
+
this.__Uint32Array_BYTES_PER_ELEMENT = [ number(4) ];
|
102
|
+
this.__Int32Array_BYTES_PER_ELEMENT = [ number(4) ];
|
103
|
+
this.__Float32Array_BYTES_PER_ELEMENT = [ number(4) ];
|
104
|
+
this.__Float64Array_BYTES_PER_ELEMENT = [ number(8) ];
|
105
105
|
|
106
106
|
ObjectBuiltins.call(this, ctx, Prefs);
|
107
107
|
};
|
@@ -135,9 +135,9 @@ export const BuiltinFuncs = function() {
|
|
135
135
|
returnType: TYPES.number,
|
136
136
|
wasm: (scope, { builtin }) => [
|
137
137
|
[ Opcodes.local_get, 0 ],
|
138
|
-
|
138
|
+
number(TYPES.number, Valtype.i32),
|
139
139
|
[ Opcodes.local_get, 1 ],
|
140
|
-
|
140
|
+
number(TYPES.number, Valtype.i32),
|
141
141
|
[ Opcodes.call, builtin('__Math_pow') ],
|
142
142
|
[ Opcodes.drop ],
|
143
143
|
]
|
@@ -224,12 +224,12 @@ export const BuiltinFuncs = function() {
|
|
224
224
|
[ Opcodes.f64_trunc ],
|
225
225
|
[ Opcodes.f64_ne ],
|
226
226
|
[ Opcodes.if, Blocktype.void ],
|
227
|
-
|
227
|
+
number(0),
|
228
228
|
[ Opcodes.return ],
|
229
229
|
[ Opcodes.end ],
|
230
230
|
[ Opcodes.local_get, 0 ],
|
231
231
|
[ Opcodes.f64_abs ],
|
232
|
-
|
232
|
+
number(9007199254740991),
|
233
233
|
[ Opcodes.f64_le ],
|
234
234
|
Opcodes.i32_from
|
235
235
|
]
|
@@ -267,7 +267,7 @@ export const BuiltinFuncs = function() {
|
|
267
267
|
returns: [ valtypeBinary ],
|
268
268
|
returnType: TYPES.number,
|
269
269
|
wasm: [
|
270
|
-
|
270
|
+
number(1),
|
271
271
|
[ Opcodes.local_get, 0 ],
|
272
272
|
[ Opcodes.f64_copysign ]
|
273
273
|
]
|
@@ -378,15 +378,15 @@ export const BuiltinFuncs = function() {
|
|
378
378
|
// seed = (MULTIPLIER * seed + INCREMENT) % MODULUS
|
379
379
|
// MULTIPLIER * state0
|
380
380
|
[ Opcodes.global_get, 0 ],
|
381
|
-
|
381
|
+
number(1103515245, Valtype.i32),
|
382
382
|
[ Opcodes.i32_mul ],
|
383
383
|
|
384
384
|
// + INCREMENT
|
385
|
-
|
385
|
+
number(12345, Valtype.i32),
|
386
386
|
[ Opcodes.i32_add ],
|
387
387
|
|
388
388
|
// % MODULUS
|
389
|
-
|
389
|
+
number(2 ** 31, Valtype.i32),
|
390
390
|
[ Opcodes.i32_rem_s ],
|
391
391
|
|
392
392
|
// state0 =
|
@@ -404,11 +404,11 @@ export const BuiltinFuncs = function() {
|
|
404
404
|
// seed = (MULTIPLIER * seed + INCREMENT) % MODULUS
|
405
405
|
// MULTIPLIER * state0
|
406
406
|
[ Opcodes.global_get, 0 ],
|
407
|
-
|
407
|
+
number(48271, Valtype.i32),
|
408
408
|
[ Opcodes.i32_mul ],
|
409
409
|
|
410
410
|
// % MODULUS
|
411
|
-
|
411
|
+
number((2 ** 31) - 1, Valtype.i32),
|
412
412
|
[ Opcodes.i32_rem_s ],
|
413
413
|
|
414
414
|
// state0 =
|
@@ -574,14 +574,14 @@ export const BuiltinFuncs = function() {
|
|
574
574
|
|
575
575
|
// rotl(s0, 24) ^ s1
|
576
576
|
[ Opcodes.local_get, 1 ], // s0
|
577
|
-
|
577
|
+
number(24, Valtype.i64),
|
578
578
|
[ Opcodes.i64_rotl ],
|
579
579
|
[ Opcodes.local_get, 0 ], // s1
|
580
580
|
[ Opcodes.i64_xor ],
|
581
581
|
|
582
582
|
// ^ (s1 << 16)
|
583
583
|
[ Opcodes.local_get, 0 ], // s1
|
584
|
-
|
584
|
+
number(16, Valtype.i64),
|
585
585
|
[ Opcodes.i64_shl ],
|
586
586
|
[ Opcodes.i64_xor ],
|
587
587
|
|
@@ -590,7 +590,7 @@ export const BuiltinFuncs = function() {
|
|
590
590
|
|
591
591
|
// state1 = rotl(s1, 37)
|
592
592
|
[ Opcodes.local_get, 0 ], // s1
|
593
|
-
|
593
|
+
number(37, Valtype.i64),
|
594
594
|
[ Opcodes.i64_rotl ],
|
595
595
|
[ Opcodes.global_set, 1 ], // state1
|
596
596
|
|
@@ -612,7 +612,7 @@ export const BuiltinFuncs = function() {
|
|
612
612
|
|
613
613
|
// t = state1 << 9
|
614
614
|
[ Opcodes.global_get, 1 ], // state1
|
615
|
-
|
615
|
+
number(9, Valtype.i32),
|
616
616
|
[ Opcodes.i32_shl ],
|
617
617
|
[ Opcodes.local_set, 1 ], // t
|
618
618
|
|
@@ -648,7 +648,7 @@ export const BuiltinFuncs = function() {
|
|
648
648
|
|
649
649
|
// state3 = rotl(state3, 11)
|
650
650
|
[ Opcodes.global_get, 3 ], // state3
|
651
|
-
|
651
|
+
number(11, Valtype.i32),
|
652
652
|
[ Opcodes.i32_rotl ],
|
653
653
|
[ Opcodes.global_set, 3 ], // state3
|
654
654
|
|
@@ -686,28 +686,28 @@ export const BuiltinFuncs = function() {
|
|
686
686
|
// [ Opcodes.f64_reinterpret_i64 ],
|
687
687
|
|
688
688
|
// - 1
|
689
|
-
//
|
689
|
+
// number(1),
|
690
690
|
// [ Opcodes.f64_sub ],
|
691
691
|
|
692
692
|
...(prng.returns === Valtype.i64 ? [
|
693
|
-
|
693
|
+
number((1 << 53) - 1, Valtype.i64),
|
694
694
|
[ Opcodes.i64_and ],
|
695
695
|
|
696
696
|
// double(mantissa)
|
697
697
|
[ Opcodes.f64_convert_i64_u ],
|
698
698
|
|
699
699
|
// / (1 << 53)
|
700
|
-
|
700
|
+
number(1 << 53),
|
701
701
|
[ Opcodes.f64_div ]
|
702
702
|
] : [
|
703
|
-
|
703
|
+
number((1 << 21) - 1, Valtype.i32),
|
704
704
|
[ Opcodes.i32_and ],
|
705
705
|
|
706
706
|
// double(mantissa)
|
707
707
|
[ Opcodes.f64_convert_i32_u ],
|
708
708
|
|
709
709
|
// / (1 << 21)
|
710
|
-
|
710
|
+
number(1 << 21),
|
711
711
|
[ Opcodes.f64_div ]
|
712
712
|
])
|
713
713
|
]
|
@@ -727,13 +727,13 @@ export const BuiltinFuncs = function() {
|
|
727
727
|
|
728
728
|
...(prng.returns === Valtype.i64 ? [
|
729
729
|
// the lowest bits of the output generated by xorshift128+ have low quality
|
730
|
-
|
730
|
+
number(56, Valtype.i64),
|
731
731
|
[ Opcodes.i64_shr_u ],
|
732
732
|
|
733
733
|
[ Opcodes.i32_wrap_i64 ],
|
734
734
|
] : []),
|
735
735
|
|
736
|
-
|
736
|
+
number(0xff, Valtype.i32),
|
737
737
|
[ Opcodes.i32_and ],
|
738
738
|
]
|
739
739
|
};
|
@@ -746,7 +746,7 @@ export const BuiltinFuncs = function() {
|
|
746
746
|
returnType: TYPES.number,
|
747
747
|
wasm: [
|
748
748
|
[ Opcodes.local_get, 0 ],
|
749
|
-
|
749
|
+
number(Math.PI / 180),
|
750
750
|
[ Opcodes.f64_mul ]
|
751
751
|
]
|
752
752
|
};
|
@@ -759,7 +759,7 @@ export const BuiltinFuncs = function() {
|
|
759
759
|
returnType: TYPES.number,
|
760
760
|
wasm: [
|
761
761
|
[ Opcodes.local_get, 0 ],
|
762
|
-
|
762
|
+
number(180 / Math.PI),
|
763
763
|
[ Opcodes.f64_mul ]
|
764
764
|
]
|
765
765
|
};
|
@@ -819,7 +819,7 @@ export const BuiltinFuncs = function() {
|
|
819
819
|
returnType: TYPES.boolean,
|
820
820
|
wasm: [
|
821
821
|
[ Opcodes.local_get, 0 ],
|
822
|
-
|
822
|
+
number(0),
|
823
823
|
[ Opcodes.f64_le ],
|
824
824
|
Opcodes.i32_from
|
825
825
|
]
|
@@ -866,7 +866,7 @@ export const BuiltinFuncs = function() {
|
|
866
866
|
[ Opcodes.local_get, 0 ],
|
867
867
|
|
868
868
|
// size = pageSize
|
869
|
-
|
869
|
+
number(pageSize, Valtype.i32),
|
870
870
|
[ ...Opcodes.memory_copy, 0x00, 0x00 ],
|
871
871
|
]
|
872
872
|
};
|
@@ -878,9 +878,9 @@ export const BuiltinFuncs = function() {
|
|
878
878
|
returns: [ Valtype.i32 ],
|
879
879
|
returnType: TYPES.number,
|
880
880
|
wasm: [
|
881
|
-
|
881
|
+
number(1, Valtype.i32),
|
882
882
|
[ Opcodes.memory_grow, 0 ],
|
883
|
-
|
883
|
+
number(pageSize, Valtype.i32),
|
884
884
|
[ Opcodes.i32_mul ]
|
885
885
|
]
|
886
886
|
},
|
@@ -895,17 +895,17 @@ export const BuiltinFuncs = function() {
|
|
895
895
|
wasm: [
|
896
896
|
// if chunkOffset >= chunks:
|
897
897
|
[ Opcodes.global_get, 1 ],
|
898
|
-
|
898
|
+
number(pageSize * (Prefs.allocatorChunks ?? 16), Valtype.i32),
|
899
899
|
[ Opcodes.i32_ge_s ],
|
900
900
|
[ Opcodes.if, Valtype.i32 ],
|
901
901
|
// chunkOffset = 1 page
|
902
|
-
|
902
|
+
number(1 * pageSize, Valtype.i32),
|
903
903
|
[ Opcodes.global_set, 1 ],
|
904
904
|
|
905
905
|
// return chunkPtr = allocated
|
906
|
-
|
906
|
+
number(Prefs.allocatorChunks ?? 16, Valtype.i32),
|
907
907
|
[ Opcodes.memory_grow, 0 ],
|
908
|
-
|
908
|
+
number(pageSize, Valtype.i32),
|
909
909
|
[ Opcodes.i32_mul ],
|
910
910
|
[ Opcodes.global_set, 0 ],
|
911
911
|
[ Opcodes.global_get, 0 ],
|
@@ -916,7 +916,7 @@ export const BuiltinFuncs = function() {
|
|
916
916
|
[ Opcodes.i32_add ],
|
917
917
|
|
918
918
|
// chunkOffset += 1 page
|
919
|
-
|
919
|
+
number(pageSize, Valtype.i32),
|
920
920
|
[ Opcodes.global_get, 1 ],
|
921
921
|
[ Opcodes.i32_add ],
|
922
922
|
[ Opcodes.global_set, 1 ],
|
@@ -936,7 +936,7 @@ export const BuiltinFuncs = function() {
|
|
936
936
|
wasm: (scope, { builtin }) => [
|
937
937
|
// if bytesWritten >= pageSize:
|
938
938
|
[ Opcodes.global_get, 1 ],
|
939
|
-
|
939
|
+
number(pageSize, Valtype.i32),
|
940
940
|
[ Opcodes.i32_ge_s ],
|
941
941
|
[ Opcodes.if, Valtype.i32 ],
|
942
942
|
// bytesWritten = bytesToAllocate
|
@@ -972,7 +972,7 @@ export const BuiltinFuncs = function() {
|
|
972
972
|
// dst = grow memory by 1 page
|
973
973
|
[ Opcodes.i32_const, 1 ],
|
974
974
|
[ Opcodes.memory_grow, 0 ],
|
975
|
-
|
975
|
+
number(65536, Valtype.i32),
|
976
976
|
[ Opcodes.i32_mul ],
|
977
977
|
[ Opcodes.local_tee, 3 ],
|
978
978
|
|
@@ -1021,7 +1021,7 @@ export const BuiltinFuncs = function() {
|
|
1021
1021
|
returnType: TYPES.number,
|
1022
1022
|
wasm: (scope, { allocPage }) => [
|
1023
1023
|
[ Opcodes.local_get, 0 ],
|
1024
|
-
|
1024
|
+
number(48, Valtype.i32),
|
1025
1025
|
[ Opcodes.i32_mul ],
|
1026
1026
|
[ Opcodes.i32_load16_u, 0, ...unsignedLEB128(allocPage(scope, 'func lut')) ]
|
1027
1027
|
],
|
@@ -1034,9 +1034,9 @@ export const BuiltinFuncs = function() {
|
|
1034
1034
|
returnType: TYPES.number,
|
1035
1035
|
wasm: (scope, { allocPage }) => [
|
1036
1036
|
[ Opcodes.local_get, 0 ],
|
1037
|
-
|
1037
|
+
number(48, Valtype.i32),
|
1038
1038
|
[ Opcodes.i32_mul ],
|
1039
|
-
|
1039
|
+
number(2, Valtype.i32),
|
1040
1040
|
[ Opcodes.i32_add ],
|
1041
1041
|
[ Opcodes.i32_load8_u, 0, ...unsignedLEB128(allocPage(scope, 'func lut')) ]
|
1042
1042
|
],
|
@@ -1049,11 +1049,11 @@ export const BuiltinFuncs = function() {
|
|
1049
1049
|
returnType: TYPES.bytestring,
|
1050
1050
|
wasm: (scope, { allocPage }) => [
|
1051
1051
|
[ Opcodes.local_get, 0 ],
|
1052
|
-
|
1052
|
+
number(48, Valtype.i32),
|
1053
1053
|
[ Opcodes.i32_mul ],
|
1054
|
-
|
1054
|
+
number(3, Valtype.i32),
|
1055
1055
|
[ Opcodes.i32_add ],
|
1056
|
-
|
1056
|
+
number(allocPage(scope, 'func lut'), Valtype.i32),
|
1057
1057
|
[ Opcodes.i32_add ]
|
1058
1058
|
],
|
1059
1059
|
table: true
|
@@ -40,7 +40,7 @@ export default function({ builtinFuncs }, Prefs) {
|
|
40
40
|
[ Opcodes.end ],
|
41
41
|
|
42
42
|
// set cache & ptr for use
|
43
|
-
|
43
|
+
number(ptr, Valtype.i32),
|
44
44
|
glbl(Opcodes.global_set, `getptr_${name}`, Valtype.i32)[0]
|
45
45
|
];
|
46
46
|
|
@@ -62,17 +62,17 @@ export default function({ builtinFuncs }, Prefs) {
|
|
62
62
|
|
63
63
|
out.push(
|
64
64
|
getPtr,
|
65
|
-
|
65
|
+
number(existingFunc ? TYPES.function : TYPES.object, Valtype.i32),
|
66
66
|
|
67
67
|
...makeString(scope, x),
|
68
68
|
Opcodes.i32_to_u,
|
69
|
-
|
69
|
+
number(TYPES.bytestring, Valtype.i32),
|
70
70
|
|
71
71
|
...generate(scope, value),
|
72
72
|
...getNodeType(scope, value),
|
73
73
|
|
74
|
-
|
75
|
-
|
74
|
+
number(flags, Valtype.i32),
|
75
|
+
number(TYPES.number, Valtype.i32),
|
76
76
|
|
77
77
|
[ Opcodes.call, builtin('__Porffor_object_expr_initWithFlags') ],
|
78
78
|
[ Opcodes.drop ],
|
@@ -103,7 +103,7 @@ export default function({ builtinFuncs }, Prefs) {
|
|
103
103
|
}
|
104
104
|
|
105
105
|
if (typeof d.value === 'number') {
|
106
|
-
this[k] = number(d.value);
|
106
|
+
this[k] = [ number(d.value) ];
|
107
107
|
this[k].type = TYPES.number;
|
108
108
|
continue;
|
109
109
|
}
|