porffor 0.14.0-eca486960 → 0.16.0-053a03e10
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 +15 -9
- package/README.md +9 -13
- package/asur/index.js +1 -1
- package/compiler/2c.js +104 -51
- package/compiler/assemble.js +18 -3
- package/compiler/builtins/annexb_string.ts +1 -0
- package/compiler/builtins/array.ts +84 -4
- package/compiler/builtins/base64.ts +1 -0
- package/compiler/builtins/boolean.ts +2 -0
- package/compiler/builtins/console.ts +6 -0
- package/compiler/builtins/crypto.ts +1 -0
- package/compiler/builtins/date.ts +2 -0
- package/compiler/builtins/error.js +22 -0
- package/compiler/builtins/escape.ts +1 -2
- package/compiler/builtins/function.ts +2 -0
- package/compiler/builtins/int.ts +2 -0
- package/compiler/builtins/math.ts +410 -0
- package/compiler/builtins/number.ts +2 -0
- package/compiler/builtins/object.ts +2 -0
- package/compiler/builtins/porffor.d.ts +11 -0
- package/compiler/builtins/set.ts +15 -1
- package/compiler/builtins/string.ts +1 -0
- package/compiler/builtins/symbol.ts +8 -7
- package/compiler/builtins.js +46 -10
- package/compiler/codegen.js +384 -192
- package/compiler/cyclone.js +535 -0
- package/compiler/decompile.js +6 -0
- package/compiler/generated_builtins.js +503 -53
- package/compiler/havoc.js +93 -0
- package/compiler/index.js +78 -7
- package/compiler/opt.js +3 -39
- package/compiler/parse.js +2 -2
- package/compiler/pgo.js +206 -0
- package/compiler/precompile.js +5 -4
- package/compiler/prefs.js +7 -2
- package/compiler/prototype.js +180 -157
- package/compiler/wrap.js +71 -16
- package/no_pgo.txt +923 -0
- package/package.json +1 -1
- package/pgo.txt +916 -0
- package/runner/index.js +18 -12
- package/runner/repl.js +18 -2
- /package/runner/{profiler.js → profile.js} +0 -0
package/compiler/builtins.js
CHANGED
@@ -32,14 +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
|
+
},
|
44
|
+
{
|
45
|
+
name: '__Porffor_readArgv',
|
46
|
+
import: 'w',
|
47
|
+
params: 2,
|
48
|
+
returns: 1
|
49
|
+
},
|
50
|
+
{
|
51
|
+
name: '__Porffor_readFile',
|
52
|
+
import: 'q',
|
53
|
+
params: 2,
|
54
|
+
returns: 1
|
43
55
|
}
|
44
56
|
];
|
45
57
|
|
@@ -138,7 +150,7 @@ export const BuiltinVars = function() {
|
|
138
150
|
this.Math = number(1);
|
139
151
|
|
140
152
|
// wintercg(tm)
|
141
|
-
this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor/0.
|
153
|
+
this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor/0.16.0`, false, '__navigator_userAgent');
|
142
154
|
this.__navigator_userAgent.type = Prefs.bytestring ? TYPES.bytestring : TYPES.string;
|
143
155
|
|
144
156
|
for (const x in TYPES) {
|
@@ -155,6 +167,7 @@ export const BuiltinFuncs = function() {
|
|
155
167
|
params: [ valtypeBinary, valtypeBinary ],
|
156
168
|
locals: [],
|
157
169
|
returns: [ valtypeBinary ],
|
170
|
+
returnType: TYPES.number,
|
158
171
|
wasm: [ // x - truncf(x / y) * y
|
159
172
|
[ Opcodes.local_get, 0 ], // x
|
160
173
|
|
@@ -177,6 +190,7 @@ export const BuiltinFuncs = function() {
|
|
177
190
|
params: [ valtypeBinary, valtypeBinary ],
|
178
191
|
locals: [],
|
179
192
|
returns: [ valtypeBinary ],
|
193
|
+
returnType: TYPES.number,
|
180
194
|
wasm: [
|
181
195
|
[ Opcodes.local_get, 0 ],
|
182
196
|
Opcodes.i32_to,
|
@@ -196,6 +210,7 @@ export const BuiltinFuncs = function() {
|
|
196
210
|
params: [ valtypeBinary ],
|
197
211
|
locals: [],
|
198
212
|
returns: [ valtypeBinary ],
|
213
|
+
returnType: TYPES.number,
|
199
214
|
wasm: [
|
200
215
|
[ Opcodes.local_get, 0 ]
|
201
216
|
],
|
@@ -221,7 +236,7 @@ export const BuiltinFuncs = function() {
|
|
221
236
|
typedParams: true,
|
222
237
|
locals: [ Valtype.i32, Valtype.i32 ],
|
223
238
|
returns: [],
|
224
|
-
wasm: (scope, { typeSwitch }) => [
|
239
|
+
wasm: (scope, { typeSwitch, builtin }) => [
|
225
240
|
...typeSwitch(scope, [ [ Opcodes.local_get, 1 ] ], {
|
226
241
|
[TYPES.number]: [
|
227
242
|
[ Opcodes.local_get, 0 ],
|
@@ -317,7 +332,7 @@ export const BuiltinFuncs = function() {
|
|
317
332
|
|
318
333
|
// make end pointer
|
319
334
|
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 0 ],
|
320
|
-
...number(ValtypeSize[valtype], Valtype.i32),
|
335
|
+
...number(ValtypeSize[valtype] + 1, Valtype.i32),
|
321
336
|
[ Opcodes.i32_mul ],
|
322
337
|
|
323
338
|
[ Opcodes.local_get, 2 ],
|
@@ -326,14 +341,18 @@ export const BuiltinFuncs = function() {
|
|
326
341
|
|
327
342
|
[ Opcodes.loop, Blocktype.void ],
|
328
343
|
|
329
|
-
// print current
|
344
|
+
// print current array element
|
330
345
|
[ Opcodes.local_get, 2 ],
|
331
|
-
[ Opcodes.load,
|
332
|
-
|
346
|
+
[ Opcodes.load, 0, ValtypeSize.i32 ],
|
347
|
+
|
348
|
+
[ Opcodes.local_get, 2 ],
|
349
|
+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
|
350
|
+
|
351
|
+
[ Opcodes.call, builtin('__Porffor_print') ],
|
333
352
|
|
334
353
|
// increment pointer by sizeof valtype
|
335
354
|
[ Opcodes.local_get, 2 ],
|
336
|
-
...number(ValtypeSize[valtype], Valtype.i32),
|
355
|
+
...number(ValtypeSize[valtype] + 1, Valtype.i32),
|
337
356
|
[ Opcodes.i32_add ],
|
338
357
|
[ Opcodes.local_tee, 2 ],
|
339
358
|
|
@@ -453,6 +472,7 @@ export const BuiltinFuncs = function() {
|
|
453
472
|
params: [ valtypeBinary ],
|
454
473
|
locals: [],
|
455
474
|
returns: [ valtypeBinary ],
|
475
|
+
returnType: TYPES.number,
|
456
476
|
wasm: [
|
457
477
|
[ Opcodes.local_get, 0 ],
|
458
478
|
[ Opcodes.f64_sqrt ]
|
@@ -464,6 +484,7 @@ export const BuiltinFuncs = function() {
|
|
464
484
|
params: [ valtypeBinary ],
|
465
485
|
locals: [],
|
466
486
|
returns: [ valtypeBinary ],
|
487
|
+
returnType: TYPES.number,
|
467
488
|
wasm: [
|
468
489
|
[ Opcodes.local_get, 0 ],
|
469
490
|
[ Opcodes.f64_abs ]
|
@@ -475,6 +496,7 @@ export const BuiltinFuncs = function() {
|
|
475
496
|
params: [ valtypeBinary ],
|
476
497
|
locals: [],
|
477
498
|
returns: [ valtypeBinary ],
|
499
|
+
returnType: TYPES.number,
|
478
500
|
wasm: [
|
479
501
|
...number(1),
|
480
502
|
[ Opcodes.local_get, 0 ],
|
@@ -487,6 +509,7 @@ export const BuiltinFuncs = function() {
|
|
487
509
|
params: [ valtypeBinary ],
|
488
510
|
locals: [],
|
489
511
|
returns: [ valtypeBinary ],
|
512
|
+
returnType: TYPES.number,
|
490
513
|
wasm: [
|
491
514
|
[ Opcodes.local_get, 0 ],
|
492
515
|
[ Opcodes.f64_floor ]
|
@@ -498,6 +521,7 @@ export const BuiltinFuncs = function() {
|
|
498
521
|
params: [ valtypeBinary ],
|
499
522
|
locals: [],
|
500
523
|
returns: [ valtypeBinary ],
|
524
|
+
returnType: TYPES.number,
|
501
525
|
wasm: [
|
502
526
|
[ Opcodes.local_get, 0 ],
|
503
527
|
[ Opcodes.f64_ceil ]
|
@@ -509,6 +533,7 @@ export const BuiltinFuncs = function() {
|
|
509
533
|
params: [ valtypeBinary ],
|
510
534
|
locals: [],
|
511
535
|
returns: [ valtypeBinary ],
|
536
|
+
returnType: TYPES.number,
|
512
537
|
wasm: [
|
513
538
|
[ Opcodes.local_get, 0 ],
|
514
539
|
[ Opcodes.f64_nearest ]
|
@@ -520,6 +545,7 @@ export const BuiltinFuncs = function() {
|
|
520
545
|
params: [ valtypeBinary ],
|
521
546
|
locals: [],
|
522
547
|
returns: [ valtypeBinary ],
|
548
|
+
returnType: TYPES.number,
|
523
549
|
wasm: [
|
524
550
|
[ Opcodes.local_get, 0 ],
|
525
551
|
[ Opcodes.f64_trunc ]
|
@@ -531,6 +557,7 @@ export const BuiltinFuncs = function() {
|
|
531
557
|
params: [ valtypeBinary ],
|
532
558
|
locals: [],
|
533
559
|
returns: [ valtypeBinary ],
|
560
|
+
returnType: TYPES.number,
|
534
561
|
wasm: [
|
535
562
|
[ Opcodes.local_get, 0 ],
|
536
563
|
Opcodes.i32_trunc_sat_f64_u,
|
@@ -544,6 +571,7 @@ export const BuiltinFuncs = function() {
|
|
544
571
|
params: [ valtypeBinary ],
|
545
572
|
locals: [],
|
546
573
|
returns: [ valtypeBinary ],
|
574
|
+
returnType: TYPES.number,
|
547
575
|
wasm: [
|
548
576
|
[ Opcodes.local_get, 0 ],
|
549
577
|
[ Opcodes.f32_demote_f64 ],
|
@@ -557,6 +585,7 @@ export const BuiltinFuncs = function() {
|
|
557
585
|
params: [ valtypeBinary, valtypeBinary ],
|
558
586
|
locals: [],
|
559
587
|
returns: [ valtypeBinary ],
|
588
|
+
returnType: TYPES.number,
|
560
589
|
wasm: [
|
561
590
|
[ Opcodes.local_get, 0 ],
|
562
591
|
Opcodes.i32_trunc_sat_f64_s,
|
@@ -871,6 +900,7 @@ export const BuiltinFuncs = function() {
|
|
871
900
|
globalNames: [ 'state0', 'state1' ],
|
872
901
|
globalInits: [ prngSeed0, prngSeed1 ],
|
873
902
|
returns: [ Valtype.f64 ],
|
903
|
+
returnType: TYPES.number,
|
874
904
|
wasm: [
|
875
905
|
...prng.wasm,
|
876
906
|
|
@@ -922,6 +952,7 @@ export const BuiltinFuncs = function() {
|
|
922
952
|
globalNames: [ 'state0', 'state1' ],
|
923
953
|
globalInits: [ prngSeed0, prngSeed1 ],
|
924
954
|
returns: [ Valtype.i32 ],
|
955
|
+
returnType: TYPES.number,
|
925
956
|
wasm: [
|
926
957
|
...prng.wasm,
|
927
958
|
|
@@ -943,6 +974,7 @@ export const BuiltinFuncs = function() {
|
|
943
974
|
params: [ valtypeBinary ],
|
944
975
|
locals: [],
|
945
976
|
returns: [ valtypeBinary ],
|
977
|
+
returnType: TYPES.number,
|
946
978
|
wasm: [
|
947
979
|
[ Opcodes.local_get, 0 ],
|
948
980
|
...number(Math.PI / 180),
|
@@ -955,6 +987,7 @@ export const BuiltinFuncs = function() {
|
|
955
987
|
params: [ valtypeBinary ],
|
956
988
|
locals: [],
|
957
989
|
returns: [ valtypeBinary ],
|
990
|
+
returnType: TYPES.number,
|
958
991
|
wasm: [
|
959
992
|
[ Opcodes.local_get, 0 ],
|
960
993
|
...number(180 / Math.PI),
|
@@ -968,6 +1001,7 @@ export const BuiltinFuncs = function() {
|
|
968
1001
|
locals: [],
|
969
1002
|
localNames: [ 'x', 'lower', 'upper' ],
|
970
1003
|
returns: [ valtypeBinary ],
|
1004
|
+
returnType: TYPES.number,
|
971
1005
|
wasm: [
|
972
1006
|
[ Opcodes.local_get, 0 ],
|
973
1007
|
[ Opcodes.local_get, 1 ],
|
@@ -983,9 +1017,9 @@ export const BuiltinFuncs = function() {
|
|
983
1017
|
locals: [],
|
984
1018
|
localNames: [ 'x', 'inLow', 'inHigh', 'outLow', 'outHigh' ],
|
985
1019
|
returns: [ valtypeBinary ],
|
1020
|
+
returnType: TYPES.number,
|
986
1021
|
wasm: [
|
987
1022
|
// (x − inLow) * (outHigh − outLow) / (inHigh - inLow) + outLow
|
988
|
-
|
989
1023
|
[ Opcodes.local_get, 0 ],
|
990
1024
|
[ Opcodes.local_get, 1 ],
|
991
1025
|
[ Opcodes.f64_sub ],
|
@@ -1027,6 +1061,7 @@ export const BuiltinFuncs = function() {
|
|
1027
1061
|
params: [],
|
1028
1062
|
locals: [],
|
1029
1063
|
returns: [ valtypeBinary ],
|
1064
|
+
returnType: TYPES.number,
|
1030
1065
|
wasm: [
|
1031
1066
|
[ Opcodes.call, importedFuncs.time ]
|
1032
1067
|
]
|
@@ -1054,6 +1089,7 @@ export const BuiltinFuncs = function() {
|
|
1054
1089
|
typedParams: true,
|
1055
1090
|
locals: [],
|
1056
1091
|
returns: [ valtypeBinary ],
|
1092
|
+
returnType: TYPES.number,
|
1057
1093
|
wasm: [
|
1058
1094
|
[ Opcodes.local_get, 1 ],
|
1059
1095
|
Opcodes.i32_from_u
|