porffor 0.16.0-fe07da0f4 → 0.17.0-05070e1f0
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/CONTRIBUTING.md +2 -2
- package/README.md +5 -17
- package/compiler/2c.js +146 -81
- package/compiler/allocators.js +128 -0
- package/compiler/assemble.js +12 -5
- package/compiler/builtins/array.ts +94 -5
- package/compiler/builtins/base64.ts +28 -24
- package/compiler/builtins/date.ts +3 -30
- package/compiler/builtins/math.ts +6 -2
- package/compiler/builtins/number.ts +10 -21
- package/compiler/builtins/porffor.d.ts +10 -0
- package/compiler/builtins/set.ts +9 -14
- package/compiler/builtins/string_f64.ts +10 -0
- package/compiler/builtins/typedarray.js +42 -0
- package/compiler/builtins/z_ecma262.ts +62 -0
- package/compiler/builtins.js +51 -6
- package/compiler/codegen.js +824 -409
- package/compiler/cyclone.js +535 -0
- package/compiler/decompile.js +3 -1
- package/compiler/generated_builtins.js +420 -162
- package/compiler/havoc.js +93 -0
- package/compiler/index.js +104 -7
- package/compiler/opt.js +10 -44
- package/compiler/parse.js +2 -8
- package/compiler/pgo.js +220 -0
- package/compiler/precompile.js +12 -7
- package/compiler/prefs.js +8 -4
- package/compiler/prototype.js +34 -43
- package/compiler/types.js +31 -5
- package/compiler/wasmSpec.js +4 -2
- package/compiler/wrap.js +120 -21
- package/package.json +3 -5
- package/rhemyn/README.md +7 -4
- package/rhemyn/compile.js +138 -66
- package/runner/debug.js +1 -1
- package/runner/index.js +31 -14
- package/runner/{profiler.js → profile.js} +1 -1
- package/runner/repl.js +16 -11
package/compiler/builtins.js
CHANGED
@@ -32,26 +32,26 @@ export const importedFuncs = [
|
|
32
32
|
{
|
33
33
|
name: 'profile1',
|
34
34
|
import: 'y',
|
35
|
-
params:
|
35
|
+
params: [ Valtype.i32 ],
|
36
36
|
returns: 0
|
37
37
|
},
|
38
38
|
{
|
39
39
|
name: 'profile2',
|
40
40
|
import: 'z',
|
41
|
-
params:
|
41
|
+
params: [ Valtype.i32 ],
|
42
42
|
returns: 0
|
43
43
|
},
|
44
44
|
{
|
45
45
|
name: '__Porffor_readArgv',
|
46
46
|
import: 'w',
|
47
47
|
params: 2,
|
48
|
-
returns:
|
48
|
+
returns: 1
|
49
49
|
},
|
50
50
|
{
|
51
51
|
name: '__Porffor_readFile',
|
52
52
|
import: 'q',
|
53
53
|
params: 2,
|
54
|
-
returns:
|
54
|
+
returns: 1
|
55
55
|
}
|
56
56
|
];
|
57
57
|
|
@@ -150,7 +150,7 @@ export const BuiltinVars = function() {
|
|
150
150
|
this.Math = number(1);
|
151
151
|
|
152
152
|
// wintercg(tm)
|
153
|
-
this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor/0.
|
153
|
+
this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor/0.17.0`, false, '__navigator_userAgent');
|
154
154
|
this.__navigator_userAgent.type = Prefs.bytestring ? TYPES.bytestring : TYPES.string;
|
155
155
|
|
156
156
|
for (const x in TYPES) {
|
@@ -160,6 +160,17 @@ export const BuiltinVars = function() {
|
|
160
160
|
this.__performance_timeOrigin = [
|
161
161
|
[ Opcodes.call, importedFuncs.timeOrigin ]
|
162
162
|
];
|
163
|
+
|
164
|
+
|
165
|
+
this.__Uint8Array_BYTES_PER_ELEMENT = number(1);
|
166
|
+
this.__Int8Array_BYTES_PER_ELEMENT = number(1);
|
167
|
+
this.__Uint8ClampedArray_BYTES_PER_ELEMENT = number(1);
|
168
|
+
this.__Uint16Array_BYTES_PER_ELEMENT = number(2);
|
169
|
+
this.__Int16Array_BYTES_PER_ELEMENT = number(2);
|
170
|
+
this.__Uint32Array_BYTES_PER_ELEMENT = number(4);
|
171
|
+
this.__Int32Array_BYTES_PER_ELEMENT = number(4);
|
172
|
+
this.__Float32Array_BYTES_PER_ELEMENT = number(4);
|
173
|
+
this.__Float64Array_BYTES_PER_ELEMENT = number(8);
|
163
174
|
};
|
164
175
|
|
165
176
|
export const BuiltinFuncs = function() {
|
@@ -167,6 +178,7 @@ export const BuiltinFuncs = function() {
|
|
167
178
|
params: [ valtypeBinary, valtypeBinary ],
|
168
179
|
locals: [],
|
169
180
|
returns: [ valtypeBinary ],
|
181
|
+
returnType: TYPES.number,
|
170
182
|
wasm: [ // x - truncf(x / y) * y
|
171
183
|
[ Opcodes.local_get, 0 ], // x
|
172
184
|
|
@@ -183,12 +195,27 @@ export const BuiltinFuncs = function() {
|
|
183
195
|
]
|
184
196
|
};
|
185
197
|
|
198
|
+
this['f64_**'] = this['i32_**'] = {
|
199
|
+
params: [ valtypeBinary, valtypeBinary ],
|
200
|
+
locals: [],
|
201
|
+
returns: [ valtypeBinary ],
|
202
|
+
returnType: TYPES.number,
|
203
|
+
wasm: (scope, { builtin }) => [
|
204
|
+
[ Opcodes.local_get, 0 ],
|
205
|
+
...number(TYPES.number, Valtype.i32),
|
206
|
+
[ Opcodes.local_get, 1 ],
|
207
|
+
...number(TYPES.number, Valtype.i32),
|
208
|
+
[ Opcodes.call, builtin('__Math_pow') ]
|
209
|
+
]
|
210
|
+
};
|
211
|
+
|
186
212
|
// add bitwise ops by converting operands to i32 first
|
187
213
|
for (const [ char, op ] of [ ['&', Opcodes.i32_and], ['|', Opcodes.i32_or], ['^', Opcodes.i32_xor], ['<<', Opcodes.i32_shl], ['>>', Opcodes.i32_shr_s], ['>>>', Opcodes.i32_shr_u] ]) {
|
188
214
|
this[`f64_${char}`] = {
|
189
215
|
params: [ valtypeBinary, valtypeBinary ],
|
190
216
|
locals: [],
|
191
217
|
returns: [ valtypeBinary ],
|
218
|
+
returnType: TYPES.number,
|
192
219
|
wasm: [
|
193
220
|
[ Opcodes.local_get, 0 ],
|
194
221
|
Opcodes.i32_to,
|
@@ -208,6 +235,7 @@ export const BuiltinFuncs = function() {
|
|
208
235
|
params: [ valtypeBinary ],
|
209
236
|
locals: [],
|
210
237
|
returns: [ valtypeBinary ],
|
238
|
+
returnType: TYPES.number,
|
211
239
|
wasm: [
|
212
240
|
[ Opcodes.local_get, 0 ]
|
213
241
|
],
|
@@ -469,6 +497,7 @@ export const BuiltinFuncs = function() {
|
|
469
497
|
params: [ valtypeBinary ],
|
470
498
|
locals: [],
|
471
499
|
returns: [ valtypeBinary ],
|
500
|
+
returnType: TYPES.number,
|
472
501
|
wasm: [
|
473
502
|
[ Opcodes.local_get, 0 ],
|
474
503
|
[ Opcodes.f64_sqrt ]
|
@@ -480,6 +509,7 @@ export const BuiltinFuncs = function() {
|
|
480
509
|
params: [ valtypeBinary ],
|
481
510
|
locals: [],
|
482
511
|
returns: [ valtypeBinary ],
|
512
|
+
returnType: TYPES.number,
|
483
513
|
wasm: [
|
484
514
|
[ Opcodes.local_get, 0 ],
|
485
515
|
[ Opcodes.f64_abs ]
|
@@ -491,6 +521,7 @@ export const BuiltinFuncs = function() {
|
|
491
521
|
params: [ valtypeBinary ],
|
492
522
|
locals: [],
|
493
523
|
returns: [ valtypeBinary ],
|
524
|
+
returnType: TYPES.number,
|
494
525
|
wasm: [
|
495
526
|
...number(1),
|
496
527
|
[ Opcodes.local_get, 0 ],
|
@@ -503,6 +534,7 @@ export const BuiltinFuncs = function() {
|
|
503
534
|
params: [ valtypeBinary ],
|
504
535
|
locals: [],
|
505
536
|
returns: [ valtypeBinary ],
|
537
|
+
returnType: TYPES.number,
|
506
538
|
wasm: [
|
507
539
|
[ Opcodes.local_get, 0 ],
|
508
540
|
[ Opcodes.f64_floor ]
|
@@ -514,6 +546,7 @@ export const BuiltinFuncs = function() {
|
|
514
546
|
params: [ valtypeBinary ],
|
515
547
|
locals: [],
|
516
548
|
returns: [ valtypeBinary ],
|
549
|
+
returnType: TYPES.number,
|
517
550
|
wasm: [
|
518
551
|
[ Opcodes.local_get, 0 ],
|
519
552
|
[ Opcodes.f64_ceil ]
|
@@ -525,6 +558,7 @@ export const BuiltinFuncs = function() {
|
|
525
558
|
params: [ valtypeBinary ],
|
526
559
|
locals: [],
|
527
560
|
returns: [ valtypeBinary ],
|
561
|
+
returnType: TYPES.number,
|
528
562
|
wasm: [
|
529
563
|
[ Opcodes.local_get, 0 ],
|
530
564
|
[ Opcodes.f64_nearest ]
|
@@ -536,6 +570,7 @@ export const BuiltinFuncs = function() {
|
|
536
570
|
params: [ valtypeBinary ],
|
537
571
|
locals: [],
|
538
572
|
returns: [ valtypeBinary ],
|
573
|
+
returnType: TYPES.number,
|
539
574
|
wasm: [
|
540
575
|
[ Opcodes.local_get, 0 ],
|
541
576
|
[ Opcodes.f64_trunc ]
|
@@ -547,6 +582,7 @@ export const BuiltinFuncs = function() {
|
|
547
582
|
params: [ valtypeBinary ],
|
548
583
|
locals: [],
|
549
584
|
returns: [ valtypeBinary ],
|
585
|
+
returnType: TYPES.number,
|
550
586
|
wasm: [
|
551
587
|
[ Opcodes.local_get, 0 ],
|
552
588
|
Opcodes.i32_trunc_sat_f64_u,
|
@@ -560,6 +596,7 @@ export const BuiltinFuncs = function() {
|
|
560
596
|
params: [ valtypeBinary ],
|
561
597
|
locals: [],
|
562
598
|
returns: [ valtypeBinary ],
|
599
|
+
returnType: TYPES.number,
|
563
600
|
wasm: [
|
564
601
|
[ Opcodes.local_get, 0 ],
|
565
602
|
[ Opcodes.f32_demote_f64 ],
|
@@ -573,6 +610,7 @@ export const BuiltinFuncs = function() {
|
|
573
610
|
params: [ valtypeBinary, valtypeBinary ],
|
574
611
|
locals: [],
|
575
612
|
returns: [ valtypeBinary ],
|
613
|
+
returnType: TYPES.number,
|
576
614
|
wasm: [
|
577
615
|
[ Opcodes.local_get, 0 ],
|
578
616
|
Opcodes.i32_trunc_sat_f64_s,
|
@@ -887,6 +925,7 @@ export const BuiltinFuncs = function() {
|
|
887
925
|
globalNames: [ 'state0', 'state1' ],
|
888
926
|
globalInits: [ prngSeed0, prngSeed1 ],
|
889
927
|
returns: [ Valtype.f64 ],
|
928
|
+
returnType: TYPES.number,
|
890
929
|
wasm: [
|
891
930
|
...prng.wasm,
|
892
931
|
|
@@ -938,6 +977,7 @@ export const BuiltinFuncs = function() {
|
|
938
977
|
globalNames: [ 'state0', 'state1' ],
|
939
978
|
globalInits: [ prngSeed0, prngSeed1 ],
|
940
979
|
returns: [ Valtype.i32 ],
|
980
|
+
returnType: TYPES.number,
|
941
981
|
wasm: [
|
942
982
|
...prng.wasm,
|
943
983
|
|
@@ -959,6 +999,7 @@ export const BuiltinFuncs = function() {
|
|
959
999
|
params: [ valtypeBinary ],
|
960
1000
|
locals: [],
|
961
1001
|
returns: [ valtypeBinary ],
|
1002
|
+
returnType: TYPES.number,
|
962
1003
|
wasm: [
|
963
1004
|
[ Opcodes.local_get, 0 ],
|
964
1005
|
...number(Math.PI / 180),
|
@@ -971,6 +1012,7 @@ export const BuiltinFuncs = function() {
|
|
971
1012
|
params: [ valtypeBinary ],
|
972
1013
|
locals: [],
|
973
1014
|
returns: [ valtypeBinary ],
|
1015
|
+
returnType: TYPES.number,
|
974
1016
|
wasm: [
|
975
1017
|
[ Opcodes.local_get, 0 ],
|
976
1018
|
...number(180 / Math.PI),
|
@@ -984,6 +1026,7 @@ export const BuiltinFuncs = function() {
|
|
984
1026
|
locals: [],
|
985
1027
|
localNames: [ 'x', 'lower', 'upper' ],
|
986
1028
|
returns: [ valtypeBinary ],
|
1029
|
+
returnType: TYPES.number,
|
987
1030
|
wasm: [
|
988
1031
|
[ Opcodes.local_get, 0 ],
|
989
1032
|
[ Opcodes.local_get, 1 ],
|
@@ -999,9 +1042,9 @@ export const BuiltinFuncs = function() {
|
|
999
1042
|
locals: [],
|
1000
1043
|
localNames: [ 'x', 'inLow', 'inHigh', 'outLow', 'outHigh' ],
|
1001
1044
|
returns: [ valtypeBinary ],
|
1045
|
+
returnType: TYPES.number,
|
1002
1046
|
wasm: [
|
1003
1047
|
// (x − inLow) * (outHigh − outLow) / (inHigh - inLow) + outLow
|
1004
|
-
|
1005
1048
|
[ Opcodes.local_get, 0 ],
|
1006
1049
|
[ Opcodes.local_get, 1 ],
|
1007
1050
|
[ Opcodes.f64_sub ],
|
@@ -1043,6 +1086,7 @@ export const BuiltinFuncs = function() {
|
|
1043
1086
|
params: [],
|
1044
1087
|
locals: [],
|
1045
1088
|
returns: [ valtypeBinary ],
|
1089
|
+
returnType: TYPES.number,
|
1046
1090
|
wasm: [
|
1047
1091
|
[ Opcodes.call, importedFuncs.time ]
|
1048
1092
|
]
|
@@ -1070,6 +1114,7 @@ export const BuiltinFuncs = function() {
|
|
1070
1114
|
typedParams: true,
|
1071
1115
|
locals: [],
|
1072
1116
|
returns: [ valtypeBinary ],
|
1117
|
+
returnType: TYPES.number,
|
1073
1118
|
wasm: [
|
1074
1119
|
[ Opcodes.local_get, 1 ],
|
1075
1120
|
Opcodes.i32_from_u
|