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.
@@ -6,7 +6,12 @@ import './prefs.js';
6
6
 
7
7
  export let importedFuncs;
8
8
  export const setImports = (v = null) => {
9
- importedFuncs = v ?? { length: 0 };
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 = function({ builtinFuncs }) {
65
- this.undefined = () => [ number(UNDEFINED) ];
66
- this.undefined.type = TYPES.undefined;
69
+ export const BuiltinVars = ({ builtinFuncs }) => {
70
+ const _ = Object.create(null);
71
+ _.undefined = () => [ number(UNDEFINED) ];
72
+ _.undefined.type = TYPES.undefined;
67
73
 
68
- this.null = () => [ number(NULL) ];
69
- this.null.type = TYPES.object;
74
+ _.null = () => [ number(NULL) ];
75
+ _.null.type = TYPES.object;
70
76
 
71
- this.NaN = () => [ number(NaN) ];
72
- this.Infinity = () => [ number(Infinity) ];
77
+ _.NaN = () => [ number(NaN) ];
78
+ _.Infinity = () => [ number(Infinity) ];
73
79
 
74
80
  for (const x in TYPES) {
75
- this['__Porffor_TYPES_' + x] = () => [ number(TYPES[x]) ];
81
+ _['__Porffor_TYPES_' + x] = () => [ number(TYPES[x]) ];
76
82
  }
77
83
 
78
- this.__performance_timeOrigin = [
84
+ _.__performance_timeOrigin = [
79
85
  [ Opcodes.call, importedFuncs.timeOrigin ]
80
86
  ];
81
- this.__performance_timeOrigin.usesImports = true;
82
-
83
- this.__Uint8Array_BYTES_PER_ELEMENT = () => [ number(1) ];
84
- this.__Int8Array_BYTES_PER_ELEMENT = () => [ number(1) ];
85
- this.__Uint8ClampedArray_BYTES_PER_ELEMENT = () => [ number(1) ];
86
- this.__Uint16Array_BYTES_PER_ELEMENT = () => [ number(2) ];
87
- this.__Int16Array_BYTES_PER_ELEMENT = () => [ number(2) ];
88
- this.__Uint32Array_BYTES_PER_ELEMENT = () => [ number(4) ];
89
- this.__Int32Array_BYTES_PER_ELEMENT = () => [ number(4) ];
90
- this.__Float32Array_BYTES_PER_ELEMENT = () => [ number(4) ];
91
- this.__Float64Array_BYTES_PER_ELEMENT = () => [ number(8) ];
92
- this.__BigInt64Array_BYTES_PER_ELEMENT = () => [ number(8) ];
93
- this.__BigUint64Array_BYTES_PER_ELEMENT = () => [ number(8) ];
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
- this[`__Symbol_${x}`] = (scope, { glbl, builtin, makeString }) => [
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
- this[`__Symbol_${x}`].type = TYPES.symbol;
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
- this[name] = (scope, { builtin }) => [
232
+ _[name] = (scope, { builtin }) => [
227
233
  [ Opcodes.call, builtin('#get_' + name) ],
228
234
  Opcodes.i32_from_u
229
235
  ];
230
- this[name].type = existingFunc ? TYPES.function : TYPES.object;
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 (Object.hasOwn(d, 'value') && !Object.hasOwn(builtinFuncs, k) && !Object.hasOwn(this, k)) {
242
+ if ('value' in d && !(k in builtinFuncs) && !(k in _)) {
237
243
  if (Array.isArray(d.value) || typeof d.value === 'function') {
238
- this[k] = d.value;
244
+ _[k] = d.value;
239
245
  continue;
240
246
  }
241
247
 
242
248
  if (typeof d.value === 'number') {
243
- this[k] = [ number(d.value) ];
244
- this[k].type = TYPES.number;
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
- this[k] = (scope, { makeString }) => makeString(scope, d.value);
250
- this[k].type = TYPES.bytestring;
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
- this[k] = this.null;
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
- ...(this[`__${name}_prototype`] ? {
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(this))) {
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 = function() {
470
- this.isNaN = {
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
- this.__Number_isNaN = this.isNaN;
491
+ _.__Number_isNaN = _.isNaN;
483
492
 
484
- this.isFinite = {
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
- this.__Number_isFinite = this.isFinite;
508
+ _.__Number_isFinite = _.isFinite;
500
509
 
501
510
  // todo: should be false for +-Infinity
502
- this.__Number_isInteger = {
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
- this.__Number_isSafeInteger = {
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
- this[`__Math_${name}`] = {
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
- this.__Math_clz32 = {
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
- this.__Math_fround = {
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
- this.__Math_imul = {
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
- this.__Math_random = {
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
- this.__Porffor_randomByte = {
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
- this.__Math_radians = {
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
- this.__Math_degrees = {
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
- this.__Math_clamp = {
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
- this.__Math_scale = {
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
- this.__Math_signbit = {
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
- this.__performance_now = {
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
- this.__performance_now.usesImports = true;
994
+ _.__performance_now.usesImports = true;
986
995
 
987
996
 
988
- this.__Porffor_typeName = {
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
- this.__Porffor_clone = {
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
- this.__Porffor_allocate = ({
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
- this.__Porffor_allocateBytes = {
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
- this.__Porffor_bytestringToString = {
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
- this.__Porffor_funcLut_length = {
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
- this.__Porffor_funcLut_flags = {
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
- this.__Porffor_funcLut_name = {
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
- this.__Porffor_number_getExponent = {
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
- this.__Porffor_bigint_fromU64 = {
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
- this.__Porffor_bigint_fromS64 = {
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
- this.__Porffor_bigint_toI64 = {
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.call(this);
1414
+ PrecompiledBuiltins.BuiltinFuncs(_);
1415
+ return _;
1406
1416
  };