porffor 0.60.9 → 0.60.10
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 +79 -69
- package/compiler/builtins_precompiled.js +1072 -1072
- package/compiler/codegen.js +45 -42
- package/compiler/precompile.js +2 -2
- package/foo.js +34 -0
- package/package.json +1 -1
- package/runtime/index.js +1 -1
package/compiler/builtins.js
CHANGED
@@ -6,7 +6,12 @@ import './prefs.js';
|
|
6
6
|
|
7
7
|
export let importedFuncs;
|
8
8
|
export const setImports = (v = null) => {
|
9
|
-
|
9
|
+
if (v == null) {
|
10
|
+
v = Object.create(null);
|
11
|
+
v.length = 0;
|
12
|
+
}
|
13
|
+
|
14
|
+
importedFuncs = v;
|
10
15
|
};
|
11
16
|
setImports();
|
12
17
|
|
@@ -61,36 +66,37 @@ export const createImport = (name, params, returns, js = null, c = null) => {
|
|
61
66
|
export const UNDEFINED = 0;
|
62
67
|
export const NULL = 0;
|
63
68
|
|
64
|
-
export const BuiltinVars =
|
65
|
-
|
66
|
-
|
69
|
+
export const BuiltinVars = ({ builtinFuncs }) => {
|
70
|
+
const _ = Object.create(null);
|
71
|
+
_.undefined = () => [ number(UNDEFINED) ];
|
72
|
+
_.undefined.type = TYPES.undefined;
|
67
73
|
|
68
|
-
|
69
|
-
|
74
|
+
_.null = () => [ number(NULL) ];
|
75
|
+
_.null.type = TYPES.object;
|
70
76
|
|
71
|
-
|
72
|
-
|
77
|
+
_.NaN = () => [ number(NaN) ];
|
78
|
+
_.Infinity = () => [ number(Infinity) ];
|
73
79
|
|
74
80
|
for (const x in TYPES) {
|
75
|
-
|
81
|
+
_['__Porffor_TYPES_' + x] = () => [ number(TYPES[x]) ];
|
76
82
|
}
|
77
83
|
|
78
|
-
|
84
|
+
_.__performance_timeOrigin = [
|
79
85
|
[ Opcodes.call, importedFuncs.timeOrigin ]
|
80
86
|
];
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
87
|
+
_.__performance_timeOrigin.usesImports = true;
|
88
|
+
|
89
|
+
_.__Uint8Array_BYTES_PER_ELEMENT = () => [ number(1) ];
|
90
|
+
_.__Int8Array_BYTES_PER_ELEMENT = () => [ number(1) ];
|
91
|
+
_.__Uint8ClampedArray_BYTES_PER_ELEMENT = () => [ number(1) ];
|
92
|
+
_.__Uint16Array_BYTES_PER_ELEMENT = () => [ number(2) ];
|
93
|
+
_.__Int16Array_BYTES_PER_ELEMENT = () => [ number(2) ];
|
94
|
+
_.__Uint32Array_BYTES_PER_ELEMENT = () => [ number(4) ];
|
95
|
+
_.__Int32Array_BYTES_PER_ELEMENT = () => [ number(4) ];
|
96
|
+
_.__Float32Array_BYTES_PER_ELEMENT = () => [ number(4) ];
|
97
|
+
_.__Float64Array_BYTES_PER_ELEMENT = () => [ number(8) ];
|
98
|
+
_.__BigInt64Array_BYTES_PER_ELEMENT = () => [ number(8) ];
|
99
|
+
_.__BigUint64Array_BYTES_PER_ELEMENT = () => [ number(8) ];
|
94
100
|
|
95
101
|
// well-known symbols
|
96
102
|
for (const x of [
|
@@ -101,7 +107,7 @@ export const BuiltinVars = function({ builtinFuncs }) {
|
|
101
107
|
'toPrimitive', 'toStringTag', 'unscopables',
|
102
108
|
'dispose', 'asyncDispose'
|
103
109
|
]) {
|
104
|
-
|
110
|
+
_[`__Symbol_${x}`] = (scope, { glbl, builtin, makeString }) => [
|
105
111
|
[ Opcodes.block, Valtype.f64 ],
|
106
112
|
...glbl(Opcodes.global_get, `#wellknown_${x}`, Valtype.f64),
|
107
113
|
Opcodes.i32_to_u,
|
@@ -117,7 +123,7 @@ export const BuiltinVars = function({ builtinFuncs }) {
|
|
117
123
|
...glbl(Opcodes.global_get, `#wellknown_${x}`, Valtype.f64),
|
118
124
|
[ Opcodes.end ]
|
119
125
|
];
|
120
|
-
|
126
|
+
_[`__Symbol_${x}`].type = TYPES.symbol;
|
121
127
|
}
|
122
128
|
|
123
129
|
// builtin objects
|
@@ -223,36 +229,36 @@ export const BuiltinVars = function({ builtinFuncs }) {
|
|
223
229
|
}
|
224
230
|
};
|
225
231
|
|
226
|
-
|
232
|
+
_[name] = (scope, { builtin }) => [
|
227
233
|
[ Opcodes.call, builtin('#get_' + name) ],
|
228
234
|
Opcodes.i32_from_u
|
229
235
|
];
|
230
|
-
|
236
|
+
_[name].type = existingFunc ? TYPES.function : TYPES.object;
|
231
237
|
|
232
238
|
for (const x in props) {
|
233
239
|
const d = props[x];
|
234
240
|
const k = prefix + x;
|
235
241
|
|
236
|
-
if (
|
242
|
+
if ('value' in d && !(k in builtinFuncs) && !(k in _)) {
|
237
243
|
if (Array.isArray(d.value) || typeof d.value === 'function') {
|
238
|
-
|
244
|
+
_[k] = d.value;
|
239
245
|
continue;
|
240
246
|
}
|
241
247
|
|
242
248
|
if (typeof d.value === 'number') {
|
243
|
-
|
244
|
-
|
249
|
+
_[k] = [ number(d.value) ];
|
250
|
+
_[k].type = TYPES.number;
|
245
251
|
continue;
|
246
252
|
}
|
247
253
|
|
248
254
|
if (typeof d.value === 'string') {
|
249
|
-
|
250
|
-
|
255
|
+
_[k] = (scope, { makeString }) => makeString(scope, d.value);
|
256
|
+
_[k].type = TYPES.bytestring;
|
251
257
|
continue;
|
252
258
|
}
|
253
259
|
|
254
260
|
if (d.value === null) {
|
255
|
-
|
261
|
+
_[k] = _.null;
|
256
262
|
continue;
|
257
263
|
}
|
258
264
|
|
@@ -293,7 +299,7 @@ export const BuiltinVars = function({ builtinFuncs }) {
|
|
293
299
|
enumerable: false,
|
294
300
|
configurable: true
|
295
301
|
}, autoFuncKeys(name)),
|
296
|
-
...(
|
302
|
+
...(_[`__${name}_prototype`] ? {
|
297
303
|
prototype: {
|
298
304
|
writable: false,
|
299
305
|
enumerable: false,
|
@@ -448,7 +454,7 @@ export const BuiltinVars = function({ builtinFuncs }) {
|
|
448
454
|
}, enumerableGlobals)
|
449
455
|
});
|
450
456
|
|
451
|
-
if (Prefs.logMissingObjects) for (const x of Object.keys(builtinFuncs).concat(Object.keys(
|
457
|
+
if (Prefs.logMissingObjects) for (const x of Object.keys(builtinFuncs).concat(Object.keys(_))) {
|
452
458
|
if (!x.startsWith('__')) continue;
|
453
459
|
const name = x.split('_').slice(2, -1).join('_');
|
454
460
|
|
@@ -464,10 +470,13 @@ export const BuiltinVars = function({ builtinFuncs }) {
|
|
464
470
|
done.add(name);
|
465
471
|
}
|
466
472
|
}
|
473
|
+
|
474
|
+
return _;
|
467
475
|
};
|
468
476
|
|
469
|
-
export const BuiltinFuncs =
|
470
|
-
|
477
|
+
export const BuiltinFuncs = () => {
|
478
|
+
const _ = Object.create(null);
|
479
|
+
_.isNaN = {
|
471
480
|
params: [ valtypeBinary ],
|
472
481
|
locals: [],
|
473
482
|
returns: [ valtypeBinary ],
|
@@ -479,9 +488,9 @@ export const BuiltinFuncs = function() {
|
|
479
488
|
Opcodes.i32_from
|
480
489
|
]
|
481
490
|
};
|
482
|
-
|
491
|
+
_.__Number_isNaN = _.isNaN;
|
483
492
|
|
484
|
-
|
493
|
+
_.isFinite = {
|
485
494
|
params: [ valtypeBinary ],
|
486
495
|
locals: [ valtypeBinary ],
|
487
496
|
returns: [ valtypeBinary ],
|
@@ -496,10 +505,10 @@ export const BuiltinFuncs = function() {
|
|
496
505
|
Opcodes.i32_from
|
497
506
|
]
|
498
507
|
};
|
499
|
-
|
508
|
+
_.__Number_isFinite = _.isFinite;
|
500
509
|
|
501
510
|
// todo: should be false for +-Infinity
|
502
|
-
|
511
|
+
_.__Number_isInteger = {
|
503
512
|
params: [ valtypeBinary ],
|
504
513
|
locals: [],
|
505
514
|
returns: [ valtypeBinary ],
|
@@ -513,7 +522,7 @@ export const BuiltinFuncs = function() {
|
|
513
522
|
]
|
514
523
|
};
|
515
524
|
|
516
|
-
|
525
|
+
_.__Number_isSafeInteger = {
|
517
526
|
params: [ valtypeBinary ],
|
518
527
|
locals: [],
|
519
528
|
returns: [ valtypeBinary ],
|
@@ -545,7 +554,7 @@ export const BuiltinFuncs = function() {
|
|
545
554
|
[ 'round', Opcodes.f64_nearest ],
|
546
555
|
[ 'trunc', Opcodes.f64_trunc ]
|
547
556
|
]) {
|
548
|
-
|
557
|
+
_[`__Math_${name}`] = {
|
549
558
|
params: [ Valtype.f64 ],
|
550
559
|
locals: [],
|
551
560
|
returns: [ Valtype.f64 ],
|
@@ -558,7 +567,7 @@ export const BuiltinFuncs = function() {
|
|
558
567
|
}
|
559
568
|
|
560
569
|
// todo: does not follow spec with +-Infinity and values >2**32
|
561
|
-
|
570
|
+
_.__Math_clz32 = {
|
562
571
|
params: [ valtypeBinary ],
|
563
572
|
locals: [],
|
564
573
|
returns: [ valtypeBinary ],
|
@@ -571,7 +580,7 @@ export const BuiltinFuncs = function() {
|
|
571
580
|
]
|
572
581
|
};
|
573
582
|
|
574
|
-
|
583
|
+
_.__Math_fround = {
|
575
584
|
params: [ valtypeBinary ],
|
576
585
|
locals: [],
|
577
586
|
returns: [ valtypeBinary ],
|
@@ -584,7 +593,7 @@ export const BuiltinFuncs = function() {
|
|
584
593
|
};
|
585
594
|
|
586
595
|
// todo: this does not overflow correctly
|
587
|
-
|
596
|
+
_.__Math_imul = {
|
588
597
|
params: [ valtypeBinary, valtypeBinary ],
|
589
598
|
locals: [],
|
590
599
|
returns: [ valtypeBinary ],
|
@@ -839,7 +848,7 @@ export const BuiltinFuncs = function() {
|
|
839
848
|
|
840
849
|
if (!prng) throw new Error(`unknown prng algo: ${Prefs.prng}`);
|
841
850
|
|
842
|
-
|
851
|
+
_.__Math_random = {
|
843
852
|
...prng,
|
844
853
|
params: [],
|
845
854
|
returns: [ Valtype.f64 ],
|
@@ -870,7 +879,7 @@ export const BuiltinFuncs = function() {
|
|
870
879
|
]
|
871
880
|
};
|
872
881
|
|
873
|
-
|
882
|
+
_.__Porffor_randomByte = {
|
874
883
|
...prng,
|
875
884
|
params: [],
|
876
885
|
returns: [ Valtype.i32 ],
|
@@ -890,7 +899,7 @@ export const BuiltinFuncs = function() {
|
|
890
899
|
]
|
891
900
|
};
|
892
901
|
|
893
|
-
|
902
|
+
_.__Math_radians = {
|
894
903
|
params: [ valtypeBinary ],
|
895
904
|
locals: [],
|
896
905
|
returns: [ valtypeBinary ],
|
@@ -902,7 +911,7 @@ export const BuiltinFuncs = function() {
|
|
902
911
|
]
|
903
912
|
};
|
904
913
|
|
905
|
-
|
914
|
+
_.__Math_degrees = {
|
906
915
|
params: [ valtypeBinary ],
|
907
916
|
locals: [],
|
908
917
|
returns: [ valtypeBinary ],
|
@@ -914,7 +923,7 @@ export const BuiltinFuncs = function() {
|
|
914
923
|
]
|
915
924
|
};
|
916
925
|
|
917
|
-
|
926
|
+
_.__Math_clamp = {
|
918
927
|
params: [ valtypeBinary, valtypeBinary, valtypeBinary ],
|
919
928
|
locals: [],
|
920
929
|
localNames: [ 'x', 'lower', 'upper' ],
|
@@ -929,7 +938,7 @@ export const BuiltinFuncs = function() {
|
|
929
938
|
]
|
930
939
|
};
|
931
940
|
|
932
|
-
|
941
|
+
_.__Math_scale = {
|
933
942
|
params: [ valtypeBinary, valtypeBinary, valtypeBinary, valtypeBinary, valtypeBinary ],
|
934
943
|
locals: [],
|
935
944
|
localNames: [ 'x', 'inLow', 'inHigh', 'outLow', 'outHigh' ],
|
@@ -959,7 +968,7 @@ export const BuiltinFuncs = function() {
|
|
959
968
|
};
|
960
969
|
|
961
970
|
// todo: fix for -0
|
962
|
-
|
971
|
+
_.__Math_signbit = {
|
963
972
|
params: [ valtypeBinary ],
|
964
973
|
locals: [],
|
965
974
|
returns: [ valtypeBinary ],
|
@@ -973,7 +982,7 @@ export const BuiltinFuncs = function() {
|
|
973
982
|
};
|
974
983
|
|
975
984
|
|
976
|
-
|
985
|
+
_.__performance_now = {
|
977
986
|
params: [],
|
978
987
|
locals: [],
|
979
988
|
returns: [ valtypeBinary ],
|
@@ -982,10 +991,10 @@ export const BuiltinFuncs = function() {
|
|
982
991
|
[ Opcodes.call, importedFuncs.time ]
|
983
992
|
]
|
984
993
|
};
|
985
|
-
|
994
|
+
_.__performance_now.usesImports = true;
|
986
995
|
|
987
996
|
|
988
|
-
|
997
|
+
_.__Porffor_typeName = {
|
989
998
|
params: [ Valtype.i32 ],
|
990
999
|
locals: [],
|
991
1000
|
returns: [ valtypeBinary ],
|
@@ -1000,7 +1009,7 @@ export const BuiltinFuncs = function() {
|
|
1000
1009
|
}
|
1001
1010
|
};
|
1002
1011
|
|
1003
|
-
|
1012
|
+
_.__Porffor_clone = {
|
1004
1013
|
params: [ Valtype.i32, Valtype.i32 ],
|
1005
1014
|
locals: [],
|
1006
1015
|
returns: [],
|
@@ -1013,7 +1022,7 @@ export const BuiltinFuncs = function() {
|
|
1013
1022
|
]
|
1014
1023
|
};
|
1015
1024
|
|
1016
|
-
|
1025
|
+
_.__Porffor_allocate = ({
|
1017
1026
|
oneshot: {
|
1018
1027
|
params: [],
|
1019
1028
|
locals: [],
|
@@ -1065,7 +1074,7 @@ export const BuiltinFuncs = function() {
|
|
1065
1074
|
}
|
1066
1075
|
})[Prefs.allocator ?? 'chunk'];
|
1067
1076
|
|
1068
|
-
|
1077
|
+
_.__Porffor_allocateBytes = {
|
1069
1078
|
params: [ Valtype.i32 ],
|
1070
1079
|
locals: [],
|
1071
1080
|
globalInits: { currentPtr: 0, bytesWritten: pageSize }, // init to pageSize so we always allocate on first call
|
@@ -1100,7 +1109,7 @@ export const BuiltinFuncs = function() {
|
|
1100
1109
|
]
|
1101
1110
|
};
|
1102
1111
|
|
1103
|
-
|
1112
|
+
_.__Porffor_bytestringToString = {
|
1104
1113
|
params: [ Valtype.i32 ],
|
1105
1114
|
locals: [ Valtype.i32, Valtype.i32, Valtype.i32 ],
|
1106
1115
|
localNames: [ 'src', 'len', 'counter', 'dst' ],
|
@@ -1152,7 +1161,7 @@ export const BuiltinFuncs = function() {
|
|
1152
1161
|
]
|
1153
1162
|
};
|
1154
1163
|
|
1155
|
-
|
1164
|
+
_.__Porffor_funcLut_length = {
|
1156
1165
|
params: [ Valtype.i32 ],
|
1157
1166
|
returns: [ Valtype.i32 ],
|
1158
1167
|
returnType: TYPES.number,
|
@@ -1167,7 +1176,7 @@ export const BuiltinFuncs = function() {
|
|
1167
1176
|
table: true
|
1168
1177
|
};
|
1169
1178
|
|
1170
|
-
|
1179
|
+
_.__Porffor_funcLut_flags = {
|
1171
1180
|
params: [ Valtype.i32 ],
|
1172
1181
|
returns: [ Valtype.i32 ],
|
1173
1182
|
returnType: TYPES.number,
|
@@ -1184,7 +1193,7 @@ export const BuiltinFuncs = function() {
|
|
1184
1193
|
table: true
|
1185
1194
|
};
|
1186
1195
|
|
1187
|
-
|
1196
|
+
_.__Porffor_funcLut_name = {
|
1188
1197
|
params: [ Valtype.i32 ],
|
1189
1198
|
returns: [ Valtype.i32 ],
|
1190
1199
|
returnType: TYPES.bytestring,
|
@@ -1202,7 +1211,7 @@ export const BuiltinFuncs = function() {
|
|
1202
1211
|
table: true
|
1203
1212
|
};
|
1204
1213
|
|
1205
|
-
|
1214
|
+
_.__Porffor_number_getExponent = {
|
1206
1215
|
params: [ Valtype.f64 ],
|
1207
1216
|
returns: [ Valtype.i32 ],
|
1208
1217
|
returnType: TYPES.number,
|
@@ -1220,7 +1229,7 @@ export const BuiltinFuncs = function() {
|
|
1220
1229
|
]
|
1221
1230
|
};
|
1222
1231
|
|
1223
|
-
|
1232
|
+
_.__Porffor_bigint_fromU64 = {
|
1224
1233
|
params: [ Valtype.i64 ],
|
1225
1234
|
locals: [ Valtype.i32, Valtype.i32, Valtype.i32 ],
|
1226
1235
|
localNames: [ 'x', 'hi', 'lo', 'ptr' ],
|
@@ -1272,7 +1281,7 @@ export const BuiltinFuncs = function() {
|
|
1272
1281
|
]
|
1273
1282
|
};
|
1274
1283
|
|
1275
|
-
|
1284
|
+
_.__Porffor_bigint_fromS64 = {
|
1276
1285
|
params: [ Valtype.i64 ],
|
1277
1286
|
locals: [ Valtype.i32, Valtype.i32, Valtype.i32, Valtype.i64 ],
|
1278
1287
|
localNames: [ 'x', 'hi', 'lo', 'ptr', 'abs' ],
|
@@ -1340,7 +1349,7 @@ export const BuiltinFuncs = function() {
|
|
1340
1349
|
]
|
1341
1350
|
};
|
1342
1351
|
|
1343
|
-
|
1352
|
+
_.__Porffor_bigint_toI64 = {
|
1344
1353
|
params: [ Valtype.f64 ],
|
1345
1354
|
locals: [ Valtype.i32, Valtype.i32 ],
|
1346
1355
|
localNames: [ 'x', 'ptr', 'digits' ],
|
@@ -1402,5 +1411,6 @@ export const BuiltinFuncs = function() {
|
|
1402
1411
|
]
|
1403
1412
|
};
|
1404
1413
|
|
1405
|
-
PrecompiledBuiltins.BuiltinFuncs
|
1414
|
+
PrecompiledBuiltins.BuiltinFuncs(_);
|
1415
|
+
return _;
|
1406
1416
|
};
|