porffor 0.61.1 → 0.61.4
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/2c.js +6 -68
- package/compiler/assemble.js +2 -4
- package/compiler/builtins/_internal_object.ts +1 -1
- package/compiler/builtins/annexb_string.js +5 -4
- package/compiler/builtins/array.ts +25 -17
- package/compiler/builtins/arraybuffer.ts +4 -4
- package/compiler/builtins/base64.ts +2 -2
- package/compiler/builtins/bigint.ts +5 -5
- package/compiler/builtins/console.ts +1 -0
- package/compiler/builtins/crypto.ts +1 -1
- package/compiler/builtins/dataview.ts +1 -1
- package/compiler/builtins/date.ts +9 -9
- package/compiler/builtins/error.js +1 -1
- package/compiler/builtins/function.ts +2 -3
- package/compiler/builtins/json.ts +12 -5
- package/compiler/builtins/map.ts +9 -7
- package/compiler/builtins/math.ts +49 -13
- package/compiler/builtins/number.ts +26 -7
- package/compiler/builtins/object.ts +13 -9
- package/compiler/builtins/porffor.d.ts +3 -6
- package/compiler/builtins/promise.ts +9 -9
- package/compiler/builtins/reflect.ts +1 -1
- package/compiler/builtins/regexp.ts +372 -465
- package/compiler/builtins/set.ts +6 -4
- package/compiler/builtins/string.ts +104 -116
- package/compiler/builtins/string_f64.ts +6 -5
- package/compiler/builtins/stringtonumber.ts +4 -3
- package/compiler/builtins/symbol.ts +2 -2
- package/compiler/builtins/typedarray.js +16 -15
- package/compiler/builtins/uint8array_base64.ts +2 -2
- package/compiler/builtins/uri.ts +145 -145
- package/compiler/builtins/weakmap.ts +3 -3
- package/compiler/builtins/weakref.ts +1 -1
- package/compiler/builtins/weakset.ts +1 -1
- package/compiler/builtins/z_ecma262.ts +9 -0
- package/compiler/builtins.js +57 -81
- package/compiler/builtins_precompiled.js +799 -788
- package/compiler/codegen.js +112 -40
- package/compiler/opt.js +2 -2
- package/compiler/precompile.js +4 -2
- package/compiler/semantic.js +1 -5
- package/compiler/wasmSpec.js +1 -0
- package/compiler/wrap.js +19 -26
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/runtime/index.js +1 -1
- package/bun.lock +0 -84
- package/deno.lock +0 -18
package/compiler/2c.js
CHANGED
|
@@ -2,7 +2,6 @@ import { read_unsignedLEB128 } from './encoding.js';
|
|
|
2
2
|
import { Blocktype, Opcodes, Valtype, PageSize } from './wasmSpec.js';
|
|
3
3
|
import { operatorOpcode } from './expression.js';
|
|
4
4
|
import { log } from './log.js';
|
|
5
|
-
import './prefs.js';
|
|
6
5
|
|
|
7
6
|
const CValtype = {
|
|
8
7
|
i8: 'u8',
|
|
@@ -209,7 +208,7 @@ export default ({ funcs, globals, data, pages }) => {
|
|
|
209
208
|
|
|
210
209
|
includes.set('stdint.h', true);
|
|
211
210
|
|
|
212
|
-
|
|
211
|
+
let out = '';
|
|
213
212
|
|
|
214
213
|
for (const x in globals) {
|
|
215
214
|
const g = globals[x];
|
|
@@ -281,6 +280,7 @@ export default ({ funcs, globals, data, pages }) => {
|
|
|
281
280
|
if (cified.has(f.name)) return '';
|
|
282
281
|
cified.add(f.name);
|
|
283
282
|
|
|
283
|
+
let topOfOut = '';
|
|
284
284
|
let out = '';
|
|
285
285
|
|
|
286
286
|
let depth = 1;
|
|
@@ -358,8 +358,7 @@ export default ({ funcs, globals, data, pages }) => {
|
|
|
358
358
|
|
|
359
359
|
if (f.name === '__Porffor_promise_runJobs') {
|
|
360
360
|
out += '}';
|
|
361
|
-
|
|
362
|
-
return;
|
|
361
|
+
return topOfOut + out;
|
|
363
362
|
}
|
|
364
363
|
|
|
365
364
|
if (f.name === '#main') {
|
|
@@ -661,66 +660,6 @@ f64 _time_out${id} = (f64)_ts${id}.tv_sec * 1000.0 + (f64)_ts${id}.tv_nsec / 1.0
|
|
|
661
660
|
break;
|
|
662
661
|
}
|
|
663
662
|
|
|
664
|
-
case '__Porffor_readArgv': {
|
|
665
|
-
prepend.set('__Porffor_readArgv',
|
|
666
|
-
`i32 __Porffor_readArgv(u32 index, u32 outPtr) {
|
|
667
|
-
if (index >= _argc) {
|
|
668
|
-
return -1;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
char* arg = _argv[index];
|
|
672
|
-
|
|
673
|
-
u32 read = 0;
|
|
674
|
-
char* out = _memory + outPtr + 4;
|
|
675
|
-
char ch;
|
|
676
|
-
while ((ch = *(arg++)) != 0) {
|
|
677
|
-
out[read++] = ch;
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
*((i32*)(_memory + outPtr)) = (i32)read;
|
|
681
|
-
return read;
|
|
682
|
-
}`);
|
|
683
|
-
|
|
684
|
-
const outPtr = vals.pop();
|
|
685
|
-
const index = vals.pop();
|
|
686
|
-
vals.push(`(f64)__Porffor_readArgv((u32)(${index}), (u32)(${outPtr}))`);
|
|
687
|
-
break;
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
case '__Porffor_readFile': {
|
|
691
|
-
includes.set('stdio.h', true);
|
|
692
|
-
|
|
693
|
-
prepend.set('__Porffor_readFile',
|
|
694
|
-
`i32 __Porffor_readFile(u32 pathPtr, u32 outPtr) {
|
|
695
|
-
FILE* fp;
|
|
696
|
-
if (pathPtr == 0) {
|
|
697
|
-
fp = stdin;
|
|
698
|
-
} else {
|
|
699
|
-
char* path = _memory + pathPtr + 4;
|
|
700
|
-
fp = fopen(path, "r");
|
|
701
|
-
if (fp == NULL) {
|
|
702
|
-
return -1;
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
u32 read = 0;
|
|
707
|
-
char* out = _memory + outPtr + 4;
|
|
708
|
-
char ch;
|
|
709
|
-
while ((ch = fgetc(fp)) != EOF) {
|
|
710
|
-
out[read++] = ch;
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
fclose(fp);
|
|
714
|
-
|
|
715
|
-
*((i32*)(_memory + outPtr)) = (i32)read;
|
|
716
|
-
return read;
|
|
717
|
-
}`);
|
|
718
|
-
const outPtr = vals.pop();
|
|
719
|
-
const pathPtr = vals.pop();
|
|
720
|
-
vals.push(`(f64)__Porffor_readFile((u32)(${pathPtr}), (u32)(${outPtr}))`);
|
|
721
|
-
break;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
663
|
default:
|
|
725
664
|
log.warning('2c', `unimplemented import: ${importFunc.name}`);
|
|
726
665
|
break;
|
|
@@ -730,7 +669,7 @@ f64 _time_out${id} = (f64)_ts${id}.tv_sec * 1000.0 + (f64)_ts${id}.tv_nsec / 1.0
|
|
|
730
669
|
}
|
|
731
670
|
|
|
732
671
|
if (!cified.has(func.name) && !ffiFuncs[func.name]) {
|
|
733
|
-
cify(func);
|
|
672
|
+
topOfOut += cify(func);
|
|
734
673
|
}
|
|
735
674
|
|
|
736
675
|
let args = [];
|
|
@@ -951,12 +890,11 @@ f64 _time_out${id} = (f64)_ts${id}.tv_sec * 1000.0 + (f64)_ts${id}.tv_nsec / 1.0
|
|
|
951
890
|
}
|
|
952
891
|
|
|
953
892
|
out += '}\n\n';
|
|
954
|
-
|
|
955
|
-
globalThis.out = globalThis.out + out;
|
|
893
|
+
return topOfOut + out;
|
|
956
894
|
};
|
|
957
895
|
|
|
958
896
|
for (const x of funcs) {
|
|
959
|
-
if (x.export || x.name === '#main') cify(x);
|
|
897
|
+
if (x.export || x.name === '#main') out += cify(x);
|
|
960
898
|
}
|
|
961
899
|
|
|
962
900
|
const rawParams = f => {
|
package/compiler/assemble.js
CHANGED
|
@@ -25,14 +25,12 @@ export default (funcs, globals, tags, pages, data, noTreeshake = false) => {
|
|
|
25
25
|
if (f.usesImports) for (let j = 0; j < f.wasm.length; j++) {
|
|
26
26
|
const x = f.wasm[j];
|
|
27
27
|
if (x[0] === Opcodes.call && x[1] < importedFuncs.length) {
|
|
28
|
-
const
|
|
29
|
-
const func = importedFuncs[idx];
|
|
30
|
-
|
|
28
|
+
const func = importedFuncs[x[1]];
|
|
31
29
|
if (!remap.has(func)) {
|
|
32
30
|
remap.set(func, importFuncs.length);
|
|
33
31
|
importFuncs.push(func);
|
|
34
32
|
}
|
|
35
|
-
|
|
33
|
+
f.wasm[j] = [ x[0], remap.get(func) ];
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
36
|
}
|
|
@@ -153,7 +153,7 @@ return`;
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
if (Porffor.type(_obj) > 0x05) {
|
|
156
|
-
if (underlyingStore == 0) underlyingStore = Porffor.
|
|
156
|
+
if (underlyingStore == 0) underlyingStore = Porffor.malloc();
|
|
157
157
|
|
|
158
158
|
// check if underlying object already exists for obj
|
|
159
159
|
const underlyingLength: i32 = Porffor.wasm.i32.load(underlyingStore, 0, 0);
|
|
@@ -21,16 +21,17 @@ export const __ByteString_prototype_${a0} = (_this: bytestring) =>
|
|
|
21
21
|
const arg = (name, s1, s2) => out += `
|
|
22
22
|
export const __String_prototype_${name} = (_this: string, arg: any) => {
|
|
23
23
|
arg = ecma262.ToString(arg);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const len: i32 = arg.length;
|
|
25
|
+
const escaped: bytestring = Porffor.malloc(6 + len * 6); // overallocate in case of "s
|
|
26
|
+
for (let i: i32 = 0; i < len; i++) {
|
|
27
|
+
const c: i32 = arg.charCodeAt(i);
|
|
27
28
|
if (c != 34) {
|
|
28
29
|
__Porffor_bytestring_appendChar(escaped, c);
|
|
29
30
|
} else {
|
|
30
31
|
__Porffor_bytestring_appendStr(escaped, '"');
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
+
|
|
34
35
|
return Porffor.concatStrings(
|
|
35
36
|
Porffor.concatStrings(
|
|
36
37
|
Porffor.concatStrings(
|
|
@@ -4,7 +4,7 @@ export const Array = function (...args: any[]): any[] {
|
|
|
4
4
|
const argsLen: number = args.length;
|
|
5
5
|
if (argsLen == 0) {
|
|
6
6
|
// 0 args, new 0 length array
|
|
7
|
-
const out: any[] = Porffor.
|
|
7
|
+
const out: any[] = Porffor.malloc();
|
|
8
8
|
return out;
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -20,7 +20,7 @@ export const Array = function (...args: any[]): any[] {
|
|
|
20
20
|
!Number.isInteger(n) // non-integer/non-finite
|
|
21
21
|
)) throw new RangeError('Invalid array length');
|
|
22
22
|
|
|
23
|
-
const out: any[] = Porffor.
|
|
23
|
+
const out: any[] = Porffor.malloc();
|
|
24
24
|
out.length = n;
|
|
25
25
|
return out;
|
|
26
26
|
}
|
|
@@ -38,7 +38,7 @@ export const __Array_isArray = (x: unknown): boolean =>
|
|
|
38
38
|
export const __Array_from = (arg: any, mapFn: any): any[] => {
|
|
39
39
|
if (arg == null) throw new TypeError('Argument cannot be nullish');
|
|
40
40
|
|
|
41
|
-
let out: any[] = Porffor.
|
|
41
|
+
let out: any[] = Porffor.malloc();
|
|
42
42
|
|
|
43
43
|
if (Porffor.fastOr(
|
|
44
44
|
Porffor.type(arg) == Porffor.TYPES.array,
|
|
@@ -220,7 +220,7 @@ export const __Array_prototype_slice = (_this: any[], _start: any, _end: any) =>
|
|
|
220
220
|
}
|
|
221
221
|
if (end > len) end = len;
|
|
222
222
|
|
|
223
|
-
let out: any[] = Porffor.
|
|
223
|
+
let out: any[] = Porffor.malloc();
|
|
224
224
|
|
|
225
225
|
if (start > end) return out;
|
|
226
226
|
|
|
@@ -260,7 +260,7 @@ export const __Array_prototype_splice = (_this: any[], _start: any, _deleteCount
|
|
|
260
260
|
if (deleteCount > len - start) deleteCount = len - start;
|
|
261
261
|
|
|
262
262
|
// read values to be deleted into out
|
|
263
|
-
let out: any[] = Porffor.
|
|
263
|
+
let out: any[] = Porffor.malloc();
|
|
264
264
|
out.length = deleteCount;
|
|
265
265
|
|
|
266
266
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
|
@@ -371,6 +371,8 @@ export const __Array_prototype_fill = (_this: any[], value: any, _start: any, _e
|
|
|
371
371
|
// @porf-typed-array
|
|
372
372
|
export const __Array_prototype_indexOf = (_this: any[], searchElement: any, _position: any) => {
|
|
373
373
|
const len: i32 = _this.length;
|
|
374
|
+
if (len == 0) return -1;
|
|
375
|
+
|
|
374
376
|
let position: i32 = ecma262.ToIntegerOrInfinity(_position);
|
|
375
377
|
if (position >= 0) {
|
|
376
378
|
if (position > len) position = len;
|
|
@@ -389,6 +391,8 @@ export const __Array_prototype_indexOf = (_this: any[], searchElement: any, _pos
|
|
|
389
391
|
// @porf-typed-array
|
|
390
392
|
export const __Array_prototype_lastIndexOf = (_this: any[], searchElement: any, _position: any) => {
|
|
391
393
|
const len: i32 = _this.length;
|
|
394
|
+
if (len == 0) return -1;
|
|
395
|
+
|
|
392
396
|
let position: i32 = _position == null ? len - 1 : ecma262.ToIntegerOrInfinity(_position);
|
|
393
397
|
if (position >= 0) {
|
|
394
398
|
if (position > len - 1) position = len - 1;
|
|
@@ -406,6 +410,8 @@ export const __Array_prototype_lastIndexOf = (_this: any[], searchElement: any,
|
|
|
406
410
|
// @porf-typed-array
|
|
407
411
|
export const __Array_prototype_includes = (_this: any[], searchElement: any, _position: any) => {
|
|
408
412
|
const len: i32 = _this.length;
|
|
413
|
+
if (len == 0) return false;
|
|
414
|
+
|
|
409
415
|
let position: i32 = ecma262.ToIntegerOrInfinity(_position);
|
|
410
416
|
if (position >= 0) {
|
|
411
417
|
if (position > len) position = len;
|
|
@@ -415,7 +421,7 @@ export const __Array_prototype_includes = (_this: any[], searchElement: any, _po
|
|
|
415
421
|
}
|
|
416
422
|
|
|
417
423
|
for (let i: i32 = position; i < len; i++) {
|
|
418
|
-
if (_this[i]
|
|
424
|
+
if (__ecma262_SameValueZero(_this[i], searchElement)) return true;
|
|
419
425
|
}
|
|
420
426
|
|
|
421
427
|
return false;
|
|
@@ -437,7 +443,7 @@ export const __Array_prototype_with = (_this: any[], _index: any, value: any) =>
|
|
|
437
443
|
throw new RangeError('Invalid index');
|
|
438
444
|
}
|
|
439
445
|
|
|
440
|
-
let out: any[] = Porffor.
|
|
446
|
+
let out: any[] = Porffor.malloc();
|
|
441
447
|
Porffor.clone(_this, out);
|
|
442
448
|
|
|
443
449
|
out[index] = value;
|
|
@@ -485,7 +491,7 @@ export const __Array_prototype_copyWithin = (_this: any[], _target: any, _start:
|
|
|
485
491
|
// @porf-typed-array
|
|
486
492
|
export const __Array_prototype_concat = (_this: any[], ...vals: any[]) => {
|
|
487
493
|
// todo/perf: rewrite to use memory.copy (via some Porffor.array.append thing?)
|
|
488
|
-
let out: any[] = Porffor.
|
|
494
|
+
let out: any[] = Porffor.malloc();
|
|
489
495
|
Porffor.clone(_this, out);
|
|
490
496
|
|
|
491
497
|
let len: i32 = _this.length;
|
|
@@ -536,7 +542,7 @@ export const __Array_prototype_forEach = (_this: any[], callbackFn: any, thisArg
|
|
|
536
542
|
// @porf-typed-array
|
|
537
543
|
export const __Array_prototype_filter = (_this: any[], callbackFn: any, thisArg: any) => {
|
|
538
544
|
if (Porffor.type(callbackFn) != Porffor.TYPES.function) throw new TypeError('Callback must be a function');
|
|
539
|
-
const out: any[] = Porffor.
|
|
545
|
+
const out: any[] = Porffor.malloc();
|
|
540
546
|
|
|
541
547
|
const len: i32 = _this.length;
|
|
542
548
|
let i: i32 = 0;
|
|
@@ -554,7 +560,7 @@ export const __Array_prototype_filter = (_this: any[], callbackFn: any, thisArg:
|
|
|
554
560
|
export const __Array_prototype_map = (_this: any[], callbackFn: any, thisArg: any) => {
|
|
555
561
|
if (Porffor.type(callbackFn) != Porffor.TYPES.function) throw new TypeError('Callback must be a function');
|
|
556
562
|
const len: i32 = _this.length;
|
|
557
|
-
const out: any[] = Porffor.
|
|
563
|
+
const out: any[] = Porffor.malloc();
|
|
558
564
|
out.length = len;
|
|
559
565
|
|
|
560
566
|
let i: i32 = 0;
|
|
@@ -568,7 +574,7 @@ export const __Array_prototype_map = (_this: any[], callbackFn: any, thisArg: an
|
|
|
568
574
|
export const __Array_prototype_flatMap = (_this: any[], callbackFn: any, thisArg: any) => {
|
|
569
575
|
if (Porffor.type(callbackFn) != Porffor.TYPES.function) throw new TypeError('Callback must be a function');
|
|
570
576
|
const len: i32 = _this.length;
|
|
571
|
-
const out: any[] = Porffor.
|
|
577
|
+
const out: any[] = Porffor.malloc();
|
|
572
578
|
|
|
573
579
|
let i: i32 = 0, j: i32 = 0;
|
|
574
580
|
while (i < len) {
|
|
@@ -612,6 +618,7 @@ export const __Array_prototype_findIndex = (_this: any[], callbackFn: any, thisA
|
|
|
612
618
|
if (!!callbackFn.call(thisArg, _this[i], i, _this)) return i;
|
|
613
619
|
i++;
|
|
614
620
|
}
|
|
621
|
+
return -1;
|
|
615
622
|
};
|
|
616
623
|
|
|
617
624
|
// @porf-typed-array
|
|
@@ -621,6 +628,7 @@ export const __Array_prototype_findLastIndex = (_this: any[], callbackFn: any, t
|
|
|
621
628
|
while (i > 0) {
|
|
622
629
|
if (!!callbackFn.call(thisArg, _this[--i], i, _this)) return i;
|
|
623
630
|
}
|
|
631
|
+
return -1;
|
|
624
632
|
};
|
|
625
633
|
|
|
626
634
|
// @porf-typed-array
|
|
@@ -768,7 +776,7 @@ export const __Array_prototype_sort = (_this: any[], callbackFn: any) => {
|
|
|
768
776
|
export const __Array_prototype_toString = (_this: any[]) => {
|
|
769
777
|
// todo: this is bytestring only!
|
|
770
778
|
|
|
771
|
-
let out: bytestring = Porffor.
|
|
779
|
+
let out: bytestring = Porffor.malloc();
|
|
772
780
|
const len: i32 = _this.length;
|
|
773
781
|
let i: i32 = 0;
|
|
774
782
|
while (i < len) {
|
|
@@ -799,7 +807,7 @@ export const __Array_prototype_join = (_this: any[], _separator: any) => {
|
|
|
799
807
|
if (Porffor.type(_separator) != Porffor.TYPES.undefined)
|
|
800
808
|
separator = ecma262.ToString(_separator);
|
|
801
809
|
|
|
802
|
-
let out: bytestring = Porffor.
|
|
810
|
+
let out: bytestring = Porffor.malloc();
|
|
803
811
|
const len: i32 = _this.length;
|
|
804
812
|
let i: i32 = 0;
|
|
805
813
|
while (i < len) {
|
|
@@ -829,7 +837,7 @@ export const __Array_prototype_toReversed = (_this: any[]) => {
|
|
|
829
837
|
let start: i32 = 0;
|
|
830
838
|
let end: i32 = len - 1;
|
|
831
839
|
|
|
832
|
-
let out: any[] = Porffor.
|
|
840
|
+
let out: any[] = Porffor.malloc();
|
|
833
841
|
out.length = len;
|
|
834
842
|
|
|
835
843
|
while (true) {
|
|
@@ -847,14 +855,14 @@ export const __Array_prototype_toReversed = (_this: any[]) => {
|
|
|
847
855
|
export const __Array_prototype_toSorted = (_this: any[], callbackFn: any) => {
|
|
848
856
|
// todo/perf: could be rewritten to be its own instead of cloning and using normal sort()
|
|
849
857
|
|
|
850
|
-
let out: any[] = Porffor.
|
|
858
|
+
let out: any[] = Porffor.malloc();
|
|
851
859
|
Porffor.clone(_this, out);
|
|
852
860
|
|
|
853
861
|
return __Array_prototype_sort(out, callbackFn);
|
|
854
862
|
};
|
|
855
863
|
|
|
856
864
|
export const __Array_prototype_toSpliced = (_this: any[], _start: any, _deleteCount: any, ...items: any[]) => {
|
|
857
|
-
let out: any[] = Porffor.
|
|
865
|
+
let out: any[] = Porffor.malloc();
|
|
858
866
|
Porffor.clone(_this, out);
|
|
859
867
|
|
|
860
868
|
const len: i32 = _this.length;
|
|
@@ -942,7 +950,7 @@ export const __Array_prototype_flat = (_this: any[], _depth: any) => {
|
|
|
942
950
|
if (Porffor.type(_depth) == Porffor.TYPES.undefined) _depth = 1;
|
|
943
951
|
let depth: i32 = ecma262.ToIntegerOrInfinity(_depth);
|
|
944
952
|
|
|
945
|
-
let out: any[] = Porffor.
|
|
953
|
+
let out: any[] = Porffor.malloc();
|
|
946
954
|
if (depth <= 0) {
|
|
947
955
|
Porffor.clone(_this, out);
|
|
948
956
|
return out;
|
|
@@ -22,7 +22,7 @@ export const ArrayBuffer = function (length: any): ArrayBuffer {
|
|
|
22
22
|
if (byteLength < 0) throw new RangeError('Invalid ArrayBuffer length (negative)');
|
|
23
23
|
if (byteLength > 4294967295) throw new RangeError('Invalid ArrayBuffer length (over 32 bit address space)');
|
|
24
24
|
|
|
25
|
-
const out: ArrayBuffer = Porffor.
|
|
25
|
+
const out: ArrayBuffer = Porffor.malloc(byteLength + 4);
|
|
26
26
|
Porffor.wasm.i32.store(out, byteLength, 0, 0);
|
|
27
27
|
|
|
28
28
|
return out;
|
|
@@ -98,7 +98,7 @@ export const __ArrayBuffer_prototype_slice = (_this: ArrayBuffer, start: any, en
|
|
|
98
98
|
}
|
|
99
99
|
if (end > len) end = len;
|
|
100
100
|
|
|
101
|
-
const out: ArrayBuffer = Porffor.
|
|
101
|
+
const out: ArrayBuffer = Porffor.malloc(4 + (end - start));
|
|
102
102
|
Porffor.wasm.i32.store(out, end - start, 0, 0);
|
|
103
103
|
|
|
104
104
|
Porffor.wasm`
|
|
@@ -185,7 +185,7 @@ export const SharedArrayBuffer = function (length: any): SharedArrayBuffer {
|
|
|
185
185
|
if (byteLength < 0) throw new RangeError('Invalid SharedArrayBuffer length (negative)');
|
|
186
186
|
if (byteLength > 4294967295) throw new RangeError('Invalid SharedArrayBuffer length (over 32 bit address space)');
|
|
187
187
|
|
|
188
|
-
const out: SharedArrayBuffer = Porffor.
|
|
188
|
+
const out: SharedArrayBuffer = Porffor.malloc(byteLength + 4);
|
|
189
189
|
Porffor.wasm.i32.store(out, byteLength, 0, 0);
|
|
190
190
|
|
|
191
191
|
return out;
|
|
@@ -222,7 +222,7 @@ export const __SharedArrayBuffer_prototype_slice = (_this: SharedArrayBuffer, st
|
|
|
222
222
|
}
|
|
223
223
|
if (end > len) end = len;
|
|
224
224
|
|
|
225
|
-
const out: SharedArrayBuffer = Porffor.
|
|
225
|
+
const out: SharedArrayBuffer = Porffor.malloc(4 + (end - start));
|
|
226
226
|
Porffor.wasm.i32.store(out, end - start, 0, 0);
|
|
227
227
|
|
|
228
228
|
Porffor.wasm`
|
|
@@ -8,7 +8,7 @@ export const btoa = (input: bytestring): bytestring => {
|
|
|
8
8
|
const keyStrPtr: i32 = Porffor.wasm`local.get ${keyStr}`;
|
|
9
9
|
|
|
10
10
|
let len: i32 = input.length;
|
|
11
|
-
let output: bytestring = Porffor.
|
|
11
|
+
let output: bytestring = Porffor.malloc();
|
|
12
12
|
|
|
13
13
|
let i: i32 = Porffor.wasm`local.get ${input}`,
|
|
14
14
|
j: i32 = Porffor.wasm`local.get ${output}`;
|
|
@@ -49,7 +49,7 @@ export const atob = (input: bytestring): bytestring => {
|
|
|
49
49
|
const lut: bytestring = '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@>@@@?456789:;<=@@@@@@@\x00\x01\x02\x03\x04\x05\x06\x07\b\t\n\x0B\f\r\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19@@@@@@\x1A\x1B\x1C\x1D\x1E\x1F !"#$%&\'()*+,-./0123';
|
|
50
50
|
const lutPtr: i32 = Porffor.wasm`local.get ${lut}`;
|
|
51
51
|
|
|
52
|
-
let output: bytestring = Porffor.
|
|
52
|
+
let output: bytestring = Porffor.malloc();
|
|
53
53
|
|
|
54
54
|
let i: i32 = Porffor.wasm`local.get ${input}`,
|
|
55
55
|
j: i32 = Porffor.wasm`local.get ${output}`;
|
|
@@ -30,7 +30,7 @@ export const __Porffor_bigint_fromDigits = (negative: boolean, digits: i32[]): b
|
|
|
30
30
|
// store small (abs(n) < 2^51 (0x8000000000000)) values inline (no allocation)
|
|
31
31
|
// like a ~s52 (s53 exc 2^51+(0-2^32) for u32 as pointer) inside a f64
|
|
32
32
|
export const __Porffor_bigint_inlineToDigitForm = (n: number): number => {
|
|
33
|
-
const ptr: i32 = Porffor.
|
|
33
|
+
const ptr: i32 = Porffor.malloc(4); // 4 meta + 1 digit
|
|
34
34
|
Porffor.wasm.i32.store8(ptr, n < 0, 0, 0);
|
|
35
35
|
Porffor.wasm.i32.store16(ptr, 1, 0, 2);
|
|
36
36
|
Porffor.wasm.i32.store(ptr, Math.abs(n), 0, 4);
|
|
@@ -46,7 +46,7 @@ export const __Porffor_bigint_fromNumber = (n: number): bigint => {
|
|
|
46
46
|
const negative: boolean = n < 0;
|
|
47
47
|
n = Math.abs(n);
|
|
48
48
|
|
|
49
|
-
const digits: i32[] = Porffor.
|
|
49
|
+
const digits: i32[] = Porffor.malloc();
|
|
50
50
|
while (n > 0) {
|
|
51
51
|
digits.unshift(n % 0x100000000);
|
|
52
52
|
n = Math.trunc(n / 0x100000000);
|
|
@@ -90,7 +90,7 @@ export const __Porffor_bigint_fromString = (n: string|bytestring): bigint => {
|
|
|
90
90
|
// 4294967297 -> [ 1, 1 ]
|
|
91
91
|
|
|
92
92
|
const BASE: i32 = 0x100000000; // 2^32
|
|
93
|
-
const digits: i32[] = Porffor.
|
|
93
|
+
const digits: i32[] = Porffor.malloc(); // todo: free later
|
|
94
94
|
digits.length = len - offset;
|
|
95
95
|
|
|
96
96
|
let i: i32 = 0;
|
|
@@ -109,7 +109,7 @@ export const __Porffor_bigint_fromString = (n: string|bytestring): bigint => {
|
|
|
109
109
|
return acc as bigint;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
const result: i32[] = Porffor.
|
|
112
|
+
const result: i32[] = Porffor.malloc();
|
|
113
113
|
while (digits.length > 0) {
|
|
114
114
|
let carry: i32 = 0;
|
|
115
115
|
for (let j: i32 = 0; j < digits.length; j++) {
|
|
@@ -156,7 +156,7 @@ export const __Porffor_bigint_add = (a: number, b: number, sub: boolean): bigint
|
|
|
156
156
|
const bLen: i32 = Porffor.wasm.i32.load16_u(b, 0, 2);
|
|
157
157
|
|
|
158
158
|
const maxLen: i32 = Math.max(aLen, bLen);
|
|
159
|
-
const digits: i32[] = Porffor.
|
|
159
|
+
const digits: i32[] = Porffor.malloc();
|
|
160
160
|
|
|
161
161
|
// fast path: same sign
|
|
162
162
|
let negative: boolean = false;
|
|
@@ -59,6 +59,7 @@ export const __Porffor_print = (arg: any, colors: boolean = true, depth: number
|
|
|
59
59
|
return;
|
|
60
60
|
|
|
61
61
|
case Porffor.TYPES.boolean:
|
|
62
|
+
case Porffor.TYPES.booleanobject:
|
|
62
63
|
if (colors) Porffor.printStatic('\x1b[33m'); // yellow
|
|
63
64
|
if (arg) {
|
|
64
65
|
Porffor.printStatic('true');
|
|
@@ -22,7 +22,7 @@ export const DataView = function (arg: any, byteOffset: any, length: any): DataV
|
|
|
22
22
|
if (len < 0) throw new RangeError('Invalid DataView length (negative)');
|
|
23
23
|
if (len > 4294967295) throw new RangeError('Invalid DataView length (over 32 bit address space)');
|
|
24
24
|
|
|
25
|
-
const out: DataView = Porffor.
|
|
25
|
+
const out: DataView = Porffor.malloc(12);
|
|
26
26
|
Porffor.wasm.i32.store(out, Porffor.wasm`local.get ${arg}` + offset, 0, 4);
|
|
27
27
|
Porffor.wasm.i32.store(out, offset, 0, 8);
|
|
28
28
|
Porffor.wasm.i32.store(out, len, 0, 0);
|
|
@@ -347,7 +347,7 @@ export const __ecma262_WeekDayName = (tv: number): bytestring => {
|
|
|
347
347
|
const lut: bytestring = 'SunMonTueWedThuFriSat';
|
|
348
348
|
const weekday: number = __ecma262_WeekDay(tv);
|
|
349
349
|
|
|
350
|
-
let out: bytestring = Porffor.
|
|
350
|
+
let out: bytestring = Porffor.malloc(8);
|
|
351
351
|
out.length = 3;
|
|
352
352
|
|
|
353
353
|
let outPtr: number = Porffor.wasm`local.get ${out}`;
|
|
@@ -365,7 +365,7 @@ export const __ecma262_MonthName = (tv: number): bytestring => {
|
|
|
365
365
|
const lut: bytestring = 'JanFebMarAprMayJunJulAugSepOctNovDec';
|
|
366
366
|
const month: number = __ecma262_MonthFromTime(tv);
|
|
367
367
|
|
|
368
|
-
let out: bytestring = Porffor.
|
|
368
|
+
let out: bytestring = Porffor.malloc(8);
|
|
369
369
|
out.length = 3;
|
|
370
370
|
|
|
371
371
|
let outPtr: number = Porffor.wasm`local.get ${out}`;
|
|
@@ -1472,7 +1472,7 @@ export const __Porffor_bytestring_appendPadNum = (str: bytestring, num: number,
|
|
|
1472
1472
|
export const __ecma262_ToUTCDTSF = (t: number): bytestring => {
|
|
1473
1473
|
const year: number = __ecma262_YearFromTime(t);
|
|
1474
1474
|
|
|
1475
|
-
let out: bytestring = Porffor.
|
|
1475
|
+
let out: bytestring = Porffor.malloc(64);
|
|
1476
1476
|
if (Porffor.fastOr(year < 0, year >= 10000)) {
|
|
1477
1477
|
// extended year format
|
|
1478
1478
|
// sign
|
|
@@ -1565,7 +1565,7 @@ export const __ecma262_TimeString = (tv: number): bytestring => {
|
|
|
1565
1565
|
const second: number = __ecma262_SecFromTime(tv);
|
|
1566
1566
|
|
|
1567
1567
|
// 4. Return the string-concatenation of hour, ":", minute, ":", second, the code unit 0x0020 (SPACE), and "GMT".
|
|
1568
|
-
let out: bytestring = Porffor.
|
|
1568
|
+
let out: bytestring = Porffor.malloc(64);
|
|
1569
1569
|
__Porffor_bytestring_appendPadNum(out, hour, 2);
|
|
1570
1570
|
__Porffor_bytestring_appendChar(out, 58); // ':'
|
|
1571
1571
|
|
|
@@ -1601,7 +1601,7 @@ export const __ecma262_DateString = (tv: number): bytestring => {
|
|
|
1601
1601
|
// 5. If yv is +0𝔽 or yv > +0𝔽, let yearSign be the empty String; otherwise, let yearSign be "-".
|
|
1602
1602
|
// 6. Let paddedYear be ToZeroPaddedDecimalString(abs(ℝ(yv)), 4).
|
|
1603
1603
|
// 7. Return the string-concatenation of weekday, the code unit 0x0020 (SPACE), month, the code unit 0x0020 (SPACE), day, the code unit 0x0020 (SPACE), yearSign, and paddedYear.
|
|
1604
|
-
let out: bytestring = Porffor.
|
|
1604
|
+
let out: bytestring = Porffor.malloc(64);
|
|
1605
1605
|
|
|
1606
1606
|
// weekday
|
|
1607
1607
|
__Porffor_bytestring_appendStr(out, weekday);
|
|
@@ -1638,7 +1638,7 @@ export const __ecma262_ToDateString = (tv: number) => {
|
|
|
1638
1638
|
const t: number = __ecma262_LocalTime(tv);
|
|
1639
1639
|
|
|
1640
1640
|
// 3. Return the string-concatenation of DateString(t), the code unit 0x0020 (SPACE), TimeString(t), and TimeZoneString(tv).
|
|
1641
|
-
const out: bytestring = Porffor.
|
|
1641
|
+
const out: bytestring = Porffor.malloc(64);
|
|
1642
1642
|
__Porffor_bytestring_appendStr(out, __ecma262_DateString(t));
|
|
1643
1643
|
__Porffor_bytestring_appendChar(out, 32);
|
|
1644
1644
|
|
|
@@ -1675,7 +1675,7 @@ export const __Date_prototype_toTimeString = (_this: any) => {
|
|
|
1675
1675
|
const t: number = __ecma262_LocalTime(tv);
|
|
1676
1676
|
|
|
1677
1677
|
// 6. Return the string-concatenation of TimeString(t) and TimeZoneString(tv).
|
|
1678
|
-
const out: bytestring = Porffor.
|
|
1678
|
+
const out: bytestring = Porffor.malloc(64);
|
|
1679
1679
|
__Porffor_bytestring_appendStr(out, __ecma262_TimeString(t));
|
|
1680
1680
|
__Porffor_bytestring_appendStr(out, __ecma262_TimeZoneString(tv));
|
|
1681
1681
|
return out;
|
|
@@ -1728,7 +1728,7 @@ export const __Date_prototype_toUTCString = (_this: any) => {
|
|
|
1728
1728
|
// 11. Return the string-concatenation of weekday, ",", the code unit 0x0020 (SPACE),
|
|
1729
1729
|
// day, the code unit 0x0020 (SPACE), month, the code unit 0x0020 (SPACE),
|
|
1730
1730
|
// yearSign, paddedYear, the code unit 0x0020 (SPACE), and TimeString(tv).
|
|
1731
|
-
const out: bytestring = Porffor.
|
|
1731
|
+
const out: bytestring = Porffor.malloc(64);
|
|
1732
1732
|
|
|
1733
1733
|
// weekday
|
|
1734
1734
|
__Porffor_bytestring_appendStr(out, weekday);
|
|
@@ -1867,7 +1867,7 @@ export const Date = function (...values: any[]): bytestring|Date {
|
|
|
1867
1867
|
}
|
|
1868
1868
|
|
|
1869
1869
|
// 6. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Date.prototype%", « [[DateValue]] »).
|
|
1870
|
-
const O: Date = Porffor.
|
|
1870
|
+
const O: Date = Porffor.malloc(8);
|
|
1871
1871
|
|
|
1872
1872
|
// 7. Set O.[[DateValue]] to dv.
|
|
1873
1873
|
__Porffor_date_write(O, dv);
|
|
@@ -8,7 +8,7 @@ export default () => {
|
|
|
8
8
|
if (message === undefined) message = '';
|
|
9
9
|
else message = ecma262.ToString(message);
|
|
10
10
|
|
|
11
|
-
const obj: ${name} = Porffor.
|
|
11
|
+
const obj: ${name} = Porffor.malloc(8);
|
|
12
12
|
Porffor.wasm.i32.store(obj, message, 0, 0);
|
|
13
13
|
Porffor.wasm.i32.store8(obj, Porffor.type(message), 0, 4);
|
|
14
14
|
|
|
@@ -10,7 +10,7 @@ export const Function = function (source: string) {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export const __Function_prototype_toString = (_this: Function) => {
|
|
13
|
-
const out: bytestring = Porffor.
|
|
13
|
+
const out: bytestring = Porffor.malloc(256);
|
|
14
14
|
|
|
15
15
|
Porffor.bytestring.appendStr(out, 'function ');
|
|
16
16
|
Porffor.bytestring.appendStr(out, __Porffor_funcLut_name(_this));
|
|
@@ -21,8 +21,7 @@ export const __Function_prototype_toString = (_this: Function) => {
|
|
|
21
21
|
export const __Function_prototype_toLocaleString = (_this: Function) => __Function_prototype_toString(_this);
|
|
22
22
|
|
|
23
23
|
export const __Function_prototype_apply = (_this: Function, thisArg: any, argsArray: any) => {
|
|
24
|
-
|
|
25
|
-
return Porffor.call(_this, argsArray, thisArg, null);
|
|
24
|
+
return Porffor.call(_this, Array.from(argsArray ?? []) as any[], thisArg, null);
|
|
26
25
|
};
|
|
27
26
|
|
|
28
27
|
export const __Function_prototype_bind = (_this: Function, thisArg: any, argsArray: any) => {
|
|
@@ -39,6 +39,7 @@ export const __Porffor_json_canSerialize = (value: any): boolean => {
|
|
|
39
39
|
Porffor.type(value) == Porffor.TYPES.stringobject,
|
|
40
40
|
Porffor.type(value) == Porffor.TYPES.number,
|
|
41
41
|
Porffor.type(value) == Porffor.TYPES.numberobject,
|
|
42
|
+
Porffor.type(value) == Porffor.TYPES.booleanobject,
|
|
42
43
|
Porffor.type(value) == Porffor.TYPES.array,
|
|
43
44
|
Porffor.type(value) > Porffor.TYPES.function
|
|
44
45
|
)) return true;
|
|
@@ -57,6 +58,12 @@ export const __Porffor_json_serialize = (_buffer: i32, value: any, depth: i32, s
|
|
|
57
58
|
if (value === true) return __Porffor_bytestring_bufferStr(buffer, 'true');
|
|
58
59
|
if (value === false) return __Porffor_bytestring_bufferStr(buffer, 'false');
|
|
59
60
|
|
|
61
|
+
// Handle Boolean objects by extracting [[BooleanData]]
|
|
62
|
+
if (Porffor.type(value) == Porffor.TYPES.booleanobject) {
|
|
63
|
+
if (value.valueOf()) return __Porffor_bytestring_bufferStr(buffer, 'true');
|
|
64
|
+
return __Porffor_bytestring_bufferStr(buffer, 'false');
|
|
65
|
+
}
|
|
66
|
+
|
|
60
67
|
if (Porffor.fastOr(
|
|
61
68
|
(Porffor.type(value) | 0b10000000) == Porffor.TYPES.bytestring,
|
|
62
69
|
Porffor.type(value) == Porffor.TYPES.stringobject
|
|
@@ -240,7 +247,7 @@ export const __JSON_stringify = (value: any, replacer: any, space: any) => {
|
|
|
240
247
|
if (space < 1) {
|
|
241
248
|
space = undefined;
|
|
242
249
|
} else {
|
|
243
|
-
const spaceStr: bytestring = Porffor.
|
|
250
|
+
const spaceStr: bytestring = Porffor.malloc(6 + space);
|
|
244
251
|
for (let i: i32 = 0; i < space; i++) Porffor.bytestring.appendChar(spaceStr, 32);
|
|
245
252
|
|
|
246
253
|
space = spaceStr;
|
|
@@ -262,8 +269,8 @@ export const __JSON_stringify = (value: any, replacer: any, space: any) => {
|
|
|
262
269
|
}
|
|
263
270
|
}
|
|
264
271
|
|
|
265
|
-
const buffer: bytestring = Porffor.
|
|
266
|
-
const out = __Porffor_json_serialize(buffer, value, 0, space);
|
|
272
|
+
const buffer: bytestring = Porffor.malloc(4096);
|
|
273
|
+
const out: i32 = __Porffor_json_serialize(buffer, value, 0, space);
|
|
267
274
|
if (out == -1) return undefined;
|
|
268
275
|
|
|
269
276
|
buffer.length = out - (buffer as i32);
|
|
@@ -329,7 +336,7 @@ export const __JSON_parse = (_: bytestring) => {
|
|
|
329
336
|
|
|
330
337
|
if (c == 34) { // '"' - string
|
|
331
338
|
pos++;
|
|
332
|
-
const out: bytestring = Porffor.
|
|
339
|
+
const out: bytestring = Porffor.malloc();
|
|
333
340
|
|
|
334
341
|
while (pos < len) {
|
|
335
342
|
const ch: i32 = text.charCodeAt(pos);
|
|
@@ -375,7 +382,7 @@ export const __JSON_parse = (_: bytestring) => {
|
|
|
375
382
|
|
|
376
383
|
if (c == 91) { // '[' - array
|
|
377
384
|
pos++;
|
|
378
|
-
const arr: any[] = Porffor.
|
|
385
|
+
const arr: any[] = Porffor.malloc();
|
|
379
386
|
skipWhitespace();
|
|
380
387
|
|
|
381
388
|
if (pos < len && text.charCodeAt(pos) == 93) { // empty array
|