porffor 0.56.5 → 0.56.6

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.
@@ -1530,8 +1530,8 @@ const getLastType = scope => {
1530
1530
  ];
1531
1531
  };
1532
1532
 
1533
- const setLastType = (scope, type = []) => {
1534
- typeUsed(scope, knownType(scope, type));
1533
+ const setLastType = (scope, type = [], doNotMarkAsUsed = false) => {
1534
+ if (!doNotMarkAsUsed) typeUsed(scope, knownType(scope, type));
1535
1535
  return [
1536
1536
  ...(typeof type === 'number' ? [ number(type, Valtype.i32) ] : type),
1537
1537
  [ Opcodes.local_set, localTmp(scope, '#last_type', Valtype.i32) ]
@@ -1659,7 +1659,7 @@ const getNodeType = (scope, node) => {
1659
1659
  if (node.operator === 'delete') return TYPES.boolean;
1660
1660
  if (node.operator === 'typeof') return TYPES.bytestring;
1661
1661
 
1662
- // todo: proper bigint support
1662
+ // todo: non-static bigint support
1663
1663
  const type = getNodeType(scope, node.argument);
1664
1664
  const known = knownType(scope, type);
1665
1665
  if (known === TYPES.bigint) return TYPES.bigint;
@@ -1668,6 +1668,7 @@ const getNodeType = (scope, node) => {
1668
1668
  }
1669
1669
 
1670
1670
  if (node.type === 'UpdateExpression') {
1671
+ // todo: bigint support
1671
1672
  return TYPES.number;
1672
1673
  }
1673
1674
 
@@ -1932,7 +1933,7 @@ const typeIsIterable = wasm => [
1932
1933
  number(TYPES.uint8array, Valtype.i32),
1933
1934
  [ Opcodes.i32_ge_s ],
1934
1935
  ...wasm,
1935
- number(TYPES.float64array, Valtype.i32),
1936
+ number(TYPES.biguint64array, Valtype.i32),
1936
1937
  [ Opcodes.i32_le_s ],
1937
1938
  [ Opcodes.i32_and ],
1938
1939
  [ Opcodes.i32_or ],
@@ -3898,6 +3899,56 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3898
3899
 
3899
3900
  [ Opcodes.f64_store, 0, 4 ]
3900
3901
  ],
3902
+ [TYPES.bigint64array]: () => [
3903
+ number(8, Valtype.i32),
3904
+ [ Opcodes.i32_mul ],
3905
+ [ Opcodes.i32_add ],
3906
+ ...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
3907
+
3908
+ ...(op === '=' ? [
3909
+ ...generate(scope, decl.right),
3910
+ ...getNodeType(scope, decl.right),
3911
+ [ Opcodes.call, includeBuiltin(scope, '__ecma262_ToBigInt').index ]
3912
+ ] : performOp(scope, op, [
3913
+ [ Opcodes.local_get, pointerTmp ],
3914
+ [ Opcodes.i64_load, 0, 4 ],
3915
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_bigint_fromS64').index ]
3916
+ ], [
3917
+ ...generate(scope, decl.right),
3918
+ ...getNodeType(scope, decl.right),
3919
+ [ Opcodes.call, includeBuiltin(scope, '__ecma262_ToBigInt').index ]
3920
+ ], [ number(TYPES.bigint, Valtype.i32) ], [ number(TYPES.bigint, Valtype.i32) ])),
3921
+ ...optional([ Opcodes.local_tee, newValueTmp ]),
3922
+
3923
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_bigint_toI64').index ],
3924
+ [ Opcodes.i64_store, 0, 4 ],
3925
+ setLastType(scope, TYPES.bigint, true)
3926
+ ],
3927
+ [TYPES.biguint64array]: () => [
3928
+ number(8, Valtype.i32),
3929
+ [ Opcodes.i32_mul ],
3930
+ [ Opcodes.i32_add ],
3931
+ ...(op === '=' ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
3932
+
3933
+ ...(op === '=' ? [
3934
+ ...generate(scope, decl.right),
3935
+ ...getNodeType(scope, decl.right),
3936
+ [ Opcodes.call, includeBuiltin(scope, '__ecma262_ToBigInt').index ]
3937
+ ] : performOp(scope, op, [
3938
+ [ Opcodes.local_get, pointerTmp ],
3939
+ [ Opcodes.i64_load, 0, 4 ],
3940
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_bigint_fromS64').index ]
3941
+ ], [
3942
+ ...generate(scope, decl.right),
3943
+ ...getNodeType(scope, decl.right),
3944
+ [ Opcodes.call, includeBuiltin(scope, '__ecma262_ToBigInt').index ]
3945
+ ], [ number(TYPES.bigint, Valtype.i32) ], [ number(TYPES.bigint, Valtype.i32) ])),
3946
+ ...optional([ Opcodes.local_tee, newValueTmp ]),
3947
+
3948
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_bigint_toI64').index ],
3949
+ [ Opcodes.i64_store, 0, 4 ],
3950
+ setLastType(scope, TYPES.bigint, true)
3951
+ ]
3901
3952
  }, {
3902
3953
  prelude: [
3903
3954
  objectGet,
@@ -4552,7 +4603,7 @@ const generateForOf = (scope, decl) => {
4552
4603
 
4553
4604
  const prevDepth = depth.length;
4554
4605
 
4555
- const makeTypedArrayNext = (getOp, elementSize) => [
4606
+ const makeTypedArrayNext = (getOp, elementSize, type = TYPES.number) => [
4556
4607
  // if counter == length then break
4557
4608
  [ Opcodes.local_get, counter ],
4558
4609
  [ Opcodes.local_get, length ],
@@ -4580,8 +4631,8 @@ const generateForOf = (scope, decl) => {
4580
4631
  [ Opcodes.i32_add ],
4581
4632
  [ Opcodes.local_set, counter ],
4582
4633
 
4583
- // set last type to number
4584
- ...setLastType(scope, TYPES.number)
4634
+ // set last type to number or specified
4635
+ ...setLastType(scope, type, true)
4585
4636
  ];
4586
4637
 
4587
4638
  // Wasm to get next element
@@ -4737,7 +4788,14 @@ const generateForOf = (scope, decl) => {
4737
4788
  [ TYPES.float64array, () => makeTypedArrayNext([
4738
4789
  [ Opcodes.f64_load, 0, 4 ]
4739
4790
  ], 8) ],
4740
-
4791
+ [ TYPES.bigint64array, () => makeTypedArrayNext([
4792
+ [ Opcodes.i64_load, 0, 4 ],
4793
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_bigint_fromS64').index ]
4794
+ ], 8, TYPES.bigint) ],
4795
+ [ TYPES.biguint64array, () => makeTypedArrayNext([
4796
+ [ Opcodes.i64_load, 0, 4 ],
4797
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_bigint_fromU64').index ]
4798
+ ], 8, TYPES.bigint) ],
4741
4799
  [ TYPES.__porffor_generator, () => [
4742
4800
  // just break?! TODO: actually implement this
4743
4801
  [ Opcodes.br, depth.length - prevDepth ]
@@ -5927,7 +5985,7 @@ const generateMember = (scope, decl, _global, _name) => {
5927
5985
  [ Opcodes.i32_add ],
5928
5986
 
5929
5987
  [ Opcodes.f64_load, 0, 4 ]
5930
- ],
5988
+ ]
5931
5989
  }, {
5932
5990
  prelude: [
5933
5991
  objectGet,
@@ -5939,6 +5997,31 @@ const generateMember = (scope, decl, _global, _name) => {
5939
5997
  ],
5940
5998
  postlude: setLastType(scope, TYPES.number)
5941
5999
  }),
6000
+
6001
+ ...wrapBC({
6002
+ [TYPES.bigint64array]: () => [
6003
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_bigint_fromS64').index ]
6004
+ ],
6005
+ [TYPES.biguint64array]: () => [
6006
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_bigint_fromU64').index ]
6007
+ ]
6008
+ }, {
6009
+ prelude: [
6010
+ objectGet,
6011
+ Opcodes.i32_to_u,
6012
+ [ Opcodes.i32_load, 0, 4 ],
6013
+
6014
+ propertyGet,
6015
+ Opcodes.i32_to_u,
6016
+
6017
+ number(8, Valtype.i32),
6018
+ [ Opcodes.i32_mul ],
6019
+ [ Opcodes.i32_add ],
6020
+
6021
+ [ Opcodes.i64_load, 0, 4 ]
6022
+ ],
6023
+ postlude: setLastType(scope, TYPES.bigint, true)
6024
+ })
5942
6025
  } : {}),
5943
6026
 
5944
6027
  [TYPES.undefined]: internalThrow(scope, 'TypeError', `Cannot read property of undefined`, true),
@@ -96,7 +96,7 @@ export const big_signedLEB128 = n => {
96
96
  buffer.push(byte);
97
97
  break;
98
98
  } else {
99
- byte |= 0x80n;
99
+ byte |= 0x80;
100
100
  }
101
101
 
102
102
  buffer.push(byte);
package/compiler/index.js CHANGED
@@ -36,7 +36,7 @@ const progressStart = msg => {
36
36
 
37
37
  const log = (extra, after) => {
38
38
  const pre = extra ? `${extra}` : spinner[spin++ % 4];
39
- process.stdout.write(`\r\u001b[2m${' '.repeat(120)}\r${' '.repeat(12 - pre.length)}${pre} ${msg}${after ?? ''}\u001b[0m`);
39
+ process.stdout.write(`\r\u001b[2m${' '.repeat(60)}\r${' '.repeat(12 - pre.length)}${pre} ${msg}${after ?? ''}\u001b[0m`);
40
40
  };
41
41
  log();
42
42
 
@@ -49,7 +49,7 @@ const progressDone = (msg, start) => {
49
49
  clearInterval(progressInterval);
50
50
 
51
51
  const timeStr = (performance.now() - start).toFixed(0);
52
- console.log(`\r${' '.repeat(120)}\r\u001b[2m${' '.repeat(10 - timeStr.length)}${timeStr}ms\u001b[0m \u001b[92m${msg}\u001b[0m`);
52
+ console.log(`\r${' '.repeat(60)}\r\u001b[2m${' '.repeat(10 - timeStr.length)}${timeStr}ms\u001b[0m \u001b[92m${msg}\u001b[0m`);
53
53
  progressLines++;
54
54
  };
55
55
  const progressClear = () => {
package/compiler/types.js CHANGED
@@ -56,7 +56,7 @@ registerInternalType('ArrayBuffer');
56
56
  registerInternalType('SharedArrayBuffer');
57
57
  registerInternalType('DataView');
58
58
 
59
- for (const x of [ 'Uint8', 'Int8', 'Uint8Clamped', 'Uint16', 'Int16', 'Uint32', 'Int32', 'Float32', 'Float64' ])
59
+ for (const x of [ 'Uint8', 'Int8', 'Uint8Clamped', 'Uint16', 'Int16', 'Uint32', 'Int32', 'Float32', 'Float64', 'BigInt64', 'BigUint64' ])
60
60
  registerInternalType(`${x}Array`, ['iterable', 'length']);
61
61
 
62
62
  registerInternalType('WeakRef');
@@ -131,9 +131,13 @@ export const Opcodes = {
131
131
  i32_ne: 0x47,
132
132
 
133
133
  i32_lt_s: 0x48,
134
- i32_le_s: 0x4c,
134
+ i32_lt_u: 0x49,
135
135
  i32_gt_s: 0x4a,
136
+ i32_gt_u: 0x4b,
137
+ i32_le_s: 0x4c,
138
+ i32_le_u: 0x4d,
136
139
  i32_ge_s: 0x4e,
140
+ i32_ge_u: 0x4f,
137
141
 
138
142
  i32_clz: 0x67,
139
143
  i32_ctz: 0x68,
@@ -222,6 +226,8 @@ export const Opcodes = {
222
226
 
223
227
  i32_trunc_sat_f64_s: [ 0xfc, 0x02 ],
224
228
  i32_trunc_sat_f64_u: [ 0xfc, 0x03 ],
229
+ i64_trunc_sat_f64_s: [ 0xfc, 0x06 ],
230
+ i64_trunc_sat_f64_u: [ 0xfc, 0x07 ],
225
231
 
226
232
  memory_init: [ 0xfc, 0x08 ],
227
233
  data_drop: [ 0xfc, 0x09 ],
package/compiler/wrap.js CHANGED
@@ -228,7 +228,9 @@ ${flags & 0b0001 ? ` get func idx: ${get}
228
228
  case TYPES.uint32array:
229
229
  case TYPES.int32array:
230
230
  case TYPES.float32array:
231
- case TYPES.float64array: {
231
+ case TYPES.float64array:
232
+ case TYPES.bigint64array:
233
+ case TYPES.biguint64array: {
232
234
  const [ length, ptr ] = read(Uint32Array, memory, value, 2);
233
235
  return read(globalThis[TYPE_NAMES[type]], memory, ptr + 4, length);
234
236
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "An ahead-of-time JavaScript compiler",
4
- "version": "0.56.5",
4
+ "version": "0.56.6",
5
5
  "author": "Oliver Medhurst <honk@goose.icu>",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/r.cjs CHANGED
@@ -1,95 +1,3 @@
1
- var assert = mustBeTrue => {
2
- if (mustBeTrue === true) {
3
- return;
4
- }
5
-
6
- throw new Test262Error('assert failed');
7
- };
8
- assert; // idk why exactly but this fixes many tests by forcing indirect ref
9
-
10
- var __assert_throws = (expectedErrorConstructor, func) => {
11
- if (typeof func !== 'function') {
12
- throw new Test262Error('assert.throws invoked with a non-function value');
13
- }
14
-
15
- try {
16
- func();
17
- } catch {
18
- return;
19
- }
20
-
21
- throw new Test262Error('assert.throws failed');
22
- };
23
-
24
- var __assert__isSameValue = (a, b) => {
25
- if (a === b) {
26
- // Handle +/-0 vs. -/+0
27
- return a !== 0 || 1 / a === 1 / b;
28
- }
29
-
30
- // Handle NaN vs. NaN
31
- return a !== a && b !== b;
32
- };
33
-
34
- var __assert_sameValue = (actual, expected) => {
35
- if (assert._isSameValue(actual, expected)) {
36
- return;
37
- }
38
-
39
- throw new Test262Error('assert.sameValue failed');
40
- };
41
-
42
- var __assert_notSameValue = (actual, unexpected) => {
43
- if (!assert._isSameValue(actual, unexpected)) {
44
- return;
45
- }
46
-
47
- throw new Test262Error('assert.notSameValue failed');
48
- };
49
-
50
- var typedArrayConstructors = [
51
- Float64Array,
52
- Float32Array,
53
- Int32Array,
54
- Int16Array,
55
- Int8Array,
56
- Uint32Array,
57
- Uint16Array,
58
- Uint8Array,
59
- Uint8ClampedArray
60
- ];
61
-
62
- function testWithTypedArrayConstructors(f, selected) {
63
- var constructors = selected || typedArrayConstructors;
64
- for (var i = 0; i < constructors.length; ++i) {
65
- f(constructors[i]);
66
- }
67
- }
68
-
69
- testWithTypedArrayConstructors(function(TA) {
70
- var sample = new TA([40, 41, 42, 43]);
71
-
72
- function testRes(result, msg) {
73
- assert.sameValue(result.length, 4, msg);
74
- assert.sameValue(result[0], 40, msg + " & result[0] === 40");
75
- assert.sameValue(result[1], 41, msg + " & result[1] === 41");
76
- assert.sameValue(result[2], 42, msg + " & result[2] === 42");
77
- assert.sameValue(result[3], 43, msg + " & result[3] === 43");
78
- }
79
-
80
- testRes(sample.subarray(0), "begin == 0");
81
- testRes(sample.subarray(-4), "begin == -srcLength");
82
- testRes(sample.subarray(-5), "begin < -srcLength");
83
-
84
- testRes(sample.subarray(0, 4), "begin == 0, end == srcLength");
85
- testRes(sample.subarray(-4, 4), "begin == -srcLength, end == srcLength");
86
- testRes(sample.subarray(-5, 4), "begin < -srcLength, end == srcLength");
87
-
88
- testRes(sample.subarray(0, 5), "begin == 0, end > srcLength");
89
- testRes(sample.subarray(-4, 5), "begin == -srcLength, end > srcLength");
90
- testRes(sample.subarray(-5, 5), "begin < -srcLength, end > srcLength");
91
- });
92
-
93
1
 
94
2
  // class C {
95
3
  // // static #method = () => 1;
package/runner/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.56.5';
3
+ globalThis.version = '0.56.6';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {