porffor 0.57.0 → 0.57.2
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 +1 -1
- package/README.md +1 -1
- package/compiler/2c.js +1 -1
- package/compiler/builtins/array.ts +1 -1
- package/compiler/builtins/base64.ts +2 -2
- package/compiler/builtins/console.ts +20 -20
- package/compiler/builtins/date.ts +1 -1
- package/compiler/builtins/number.ts +1 -1
- package/compiler/builtins/object.ts +4 -4
- package/compiler/builtins/promise.ts +3 -3
- package/compiler/builtins/string.ts +97 -8
- package/compiler/builtins_precompiled.js +153 -882
- package/compiler/codegen.js +39 -12
- package/compiler/cyclone.js +1 -1
- package/compiler/encoding.js +1 -0
- package/compiler/log.js +0 -2
- package/compiler/opt.js +1 -1
- package/compiler/precompile.js +3 -5
- package/compiler/wrap.js +0 -1
- package/foo.ts +5 -0
- package/package.json +2 -2
- package/porf +3 -3
- package/porf.cmd +1 -1
- package/{runner → runtime}/index.js +8 -6
- package/optional-chaining-tests.js +0 -335
- package/r.cjs +0 -71
- /package/{runner → runtime}/debug.js +0 -0
- /package/{runner → runtime}/flamegraph.js +0 -0
- /package/{runner → runtime}/hotlines.js +0 -0
- /package/{runner → runtime}/repl.js +0 -0
package/CONTRIBUTING.md
CHANGED
@@ -21,7 +21,7 @@ The repo comes with easy alias scripts for Unix and Windows, which you can use l
|
|
21
21
|
- Unix: `./porf path/to/script.js`
|
22
22
|
- Windows: `.\porf path/to/script.js`
|
23
23
|
|
24
|
-
You can also swap out `node` in the alias to use another runtime like Deno (`deno run -A ...`) or Bun (`bun ...`), or just use it yourself (eg `node
|
24
|
+
You can also swap out `node` in the alias to use another runtime like Deno (`deno run -A ...`) or Bun (`bun ...`), or just use it yourself (eg `node runtime/index.js ...`, `bun runtime/index.js ...`). Node, Deno, Bun should work.
|
25
25
|
|
26
26
|
### Precompile
|
27
27
|
|
package/README.md
CHANGED
@@ -122,7 +122,7 @@ Porffor can run Test262 via some hacks/transforms which remove unsupported featu
|
|
122
122
|
- `wasmSpec.js`: "enums"/info from wasm spec
|
123
123
|
- `wrap.js`: wrapper for compiler which instantiates and produces nice exports
|
124
124
|
|
125
|
-
- `
|
125
|
+
- `runtime`: contains utils for running JS with the compiler
|
126
126
|
- `index.js`: the main file, you probably want to use this
|
127
127
|
- `repl.js`: basic repl (uses `node:repl`)
|
128
128
|
|
package/compiler/2c.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { read_signedLEB128, 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';
|
@@ -65,7 +65,7 @@ export const __Array_from = (arg: any, mapFn: any): any[] => {
|
|
65
65
|
}
|
66
66
|
|
67
67
|
if (Porffor.type(arg) == Porffor.TYPES.object) {
|
68
|
-
let len = ecma262.ToIntegerOrInfinity((arg as object)['length']);
|
68
|
+
let len: i32 = ecma262.ToIntegerOrInfinity((arg as object)['length']);
|
69
69
|
if (len > 4294967295) throw new RangeError('Invalid array length');
|
70
70
|
if (len < 0) len = 0;
|
71
71
|
|
@@ -15,7 +15,7 @@ export const btoa = (input: bytestring): bytestring => {
|
|
15
15
|
|
16
16
|
// todo/perf: add some per 6 char variant using bitwise magic?
|
17
17
|
|
18
|
-
const endPtr = i + len;
|
18
|
+
const endPtr: i32 = i + len;
|
19
19
|
while (i < endPtr) {
|
20
20
|
const chr1: i32 = Porffor.wasm.i32.load8_u(i++, 0, 4);
|
21
21
|
const chr2: i32 = i < endPtr ? Porffor.wasm.i32.load8_u(i++, 0, 4) : -1;
|
@@ -54,7 +54,7 @@ export const atob = (input: bytestring): bytestring => {
|
|
54
54
|
let i: i32 = Porffor.wasm`local.get ${input}`,
|
55
55
|
j: i32 = Porffor.wasm`local.get ${output}`;
|
56
56
|
|
57
|
-
const endPtr = i + input.length;
|
57
|
+
const endPtr: i32 = i + input.length;
|
58
58
|
while (i < endPtr) {
|
59
59
|
const enc1: i32 = Porffor.wasm.i32.load8_u(lutPtr + Porffor.wasm.i32.load8_u(i++, 0, 4), 0, 4);
|
60
60
|
const enc2: i32 = i < endPtr ? Porffor.wasm.i32.load8_u(lutPtr + Porffor.wasm.i32.load8_u(i++, 0, 4), 0, 4) : -1;
|
@@ -86,27 +86,27 @@ export const __Porffor_miniLog = (arg: any) => {
|
|
86
86
|
Porffor.printStatic('\n');
|
87
87
|
};
|
88
88
|
|
89
|
-
export const
|
90
|
-
const
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
89
|
+
export const __Porffor_print = (arg: any, colors: boolean = true, depth: number = 0) => {
|
90
|
+
const __Porffor_printArray = (arg: any[]|Uint8Array|Int8Array|Uint8ClampedArray|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array|Float64Array, colors: boolean, length: boolean = false) => {
|
91
|
+
const arrLen: i32 = arg.length;
|
92
|
+
if (length) {
|
93
|
+
Porffor.printStatic('(');
|
94
|
+
print(arrLen);
|
95
|
+
Porffor.printStatic(') ');
|
96
|
+
}
|
96
97
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
98
|
+
if (arrLen == 0) {
|
99
|
+
Porffor.printStatic('[]');
|
100
|
+
} else {
|
101
|
+
Porffor.printStatic('[ ');
|
102
|
+
for (let i: i32 = 0; i < arrLen; i++) {
|
103
|
+
__Porffor_print(arg[i], colors);
|
104
|
+
if (i != arrLen - 1) Porffor.printStatic(', ');
|
105
|
+
}
|
106
|
+
Porffor.printStatic(' ]');
|
104
107
|
}
|
105
|
-
|
106
|
-
}
|
107
|
-
};
|
108
|
+
};
|
108
109
|
|
109
|
-
export const __Porffor_print = (arg: any, colors: boolean = true, depth: number = 0) => {
|
110
110
|
// todo: Symbol.toStringTag could reduce duplication here
|
111
111
|
switch (Porffor.type(arg)) {
|
112
112
|
case Porffor.TYPES.number:
|
@@ -335,7 +335,7 @@ export const __Porffor_print = (arg: any, colors: boolean = true, depth: number
|
|
335
335
|
}
|
336
336
|
};
|
337
337
|
|
338
|
-
let tabLevel = 0;
|
338
|
+
let tabLevel: i32 = 0;
|
339
339
|
export const __Porffor_consoleIndent = () => {
|
340
340
|
for (let i: i32 = 0; i < tabLevel; i++) {
|
341
341
|
Porffor.printStatic('\t');
|
@@ -459,7 +459,7 @@ export const __Porffor_dirObject = (obj: any, colors: boolean, depth: i32, showH
|
|
459
459
|
|
460
460
|
const keys = __Object_keys(obj);
|
461
461
|
const keysLen = keys.length - 1;
|
462
|
-
for (let i = 0; i <= keysLen; i++) {
|
462
|
+
for (let i: i32 = 0; i <= keysLen; i++) {
|
463
463
|
const key = keys[i];
|
464
464
|
__Porffor_consolePrint(key);
|
465
465
|
Porffor.printStatic(': ');
|
@@ -147,7 +147,7 @@ export const __ecma262_DateFromTime = (t: number): number => {
|
|
147
147
|
const dayWithinYear: number = __ecma262_DayWithinYear(t);
|
148
148
|
|
149
149
|
// 3. Let month be MonthFromTime(t).
|
150
|
-
const month = __ecma262_MonthFromTime(t);
|
150
|
+
const month: number = __ecma262_MonthFromTime(t);
|
151
151
|
|
152
152
|
// 4. If month is +0𝔽, return dayWithinYear + 1𝔽.
|
153
153
|
if (month == 0) return dayWithinYear + 1;
|
@@ -168,7 +168,7 @@ export const __Porffor_object_in = (obj: any, prop: any): boolean => {
|
|
168
168
|
return true;
|
169
169
|
}
|
170
170
|
|
171
|
-
let lastProto = obj;
|
171
|
+
let lastProto: any = obj;
|
172
172
|
while (true) {
|
173
173
|
obj = Porffor.object.getPrototypeWithHidden(obj, Porffor.type(obj));
|
174
174
|
if (Porffor.fastOr(obj == null, Porffor.wasm`local.get ${obj}` == Porffor.wasm`local.get ${lastProto}`)) break;
|
@@ -189,7 +189,7 @@ export const __Porffor_object_instanceof = (obj: any, constr: any, checkProto: a
|
|
189
189
|
return false;
|
190
190
|
}
|
191
191
|
|
192
|
-
let lastProto = obj;
|
192
|
+
let lastProto: any = obj;
|
193
193
|
while (true) {
|
194
194
|
obj = Porffor.object.getPrototypeWithHidden(obj, Porffor.type(obj));
|
195
195
|
if (Porffor.fastOr(obj == null, Porffor.wasm`local.get ${obj}` == Porffor.wasm`local.get ${lastProto}`)) break;
|
@@ -347,7 +347,7 @@ export const __Object_getOwnPropertyDescriptor = (obj: any, prop: any): object|u
|
|
347
347
|
if (entryPtr == -1) {
|
348
348
|
if (Porffor.type(obj) == Porffor.TYPES.function) {
|
349
349
|
// hack: function .name and .length
|
350
|
-
const v = obj[p];
|
350
|
+
const v: any = obj[p];
|
351
351
|
if (v != null) {
|
352
352
|
const out: object = {};
|
353
353
|
out.writable = false;
|
@@ -619,7 +619,7 @@ export const __Object_create = (proto: any, props: any): object => {
|
|
619
619
|
export const __Object_groupBy = (items: any, callbackFn: any): object => {
|
620
620
|
const out: object = {};
|
621
621
|
|
622
|
-
let i = 0;
|
622
|
+
let i: i32 = 0;
|
623
623
|
for (const x of items) {
|
624
624
|
const k: any = callbackFn(x, i++);
|
625
625
|
if (!__Object_hasOwn(out, k)) {
|
@@ -383,18 +383,18 @@ export const __Promise_allSettled = (promises: any): Promise => {
|
|
383
383
|
_allLen++;
|
384
384
|
if (__ecma262_IsPromise(x)) {
|
385
385
|
x.then(r => {
|
386
|
-
const o = {};
|
386
|
+
const o: object = {};
|
387
387
|
o.status = 'fulfilled';
|
388
388
|
o.value = r;
|
389
389
|
if (Porffor.array.fastPush(_allOut, o) == _allLen) _allRes(_allOut);
|
390
390
|
}, r => {
|
391
|
-
const o = {};
|
391
|
+
const o: object = {};
|
392
392
|
o.status = 'rejected';
|
393
393
|
o.reason = r;
|
394
394
|
if (Porffor.array.fastPush(_allOut, o) == _allLen) _allRes(_allOut);
|
395
395
|
});
|
396
396
|
} else {
|
397
|
-
const o = {};
|
397
|
+
const o: object = {};
|
398
398
|
o.status = 'fulfilled';
|
399
399
|
o.value = x;
|
400
400
|
Porffor.array.fastPush(_allOut, o);
|
@@ -1227,12 +1227,26 @@ memory.copy 0 0`;
|
|
1227
1227
|
|
1228
1228
|
export const __String_prototype_split = (_this: string, separator: any, limit: any) => {
|
1229
1229
|
let out: any[] = Porffor.allocate(), outLen: i32 = 0;
|
1230
|
-
const sType: i32 = Porffor.TYPES.string;
|
1231
1230
|
|
1232
1231
|
if (Porffor.wasm`local.get ${limit+1}` == Porffor.TYPES.undefined) limit = Number.MAX_SAFE_INTEGER;
|
1233
1232
|
limit |= 0;
|
1234
1233
|
if (limit < 0) limit = Number.MAX_SAFE_INTEGER;
|
1235
1234
|
|
1235
|
+
if (separator == null) {
|
1236
|
+
out.length = 1;
|
1237
|
+
// out[0] = _this; (but in wasm as it is a f64 array and we are in i32 space)
|
1238
|
+
Porffor.wasm`
|
1239
|
+
local.get ${out}
|
1240
|
+
local.get ${_this}
|
1241
|
+
f64.convert_i32_u
|
1242
|
+
f64.store 0 4
|
1243
|
+
|
1244
|
+
local.get ${out}
|
1245
|
+
i32.const 67
|
1246
|
+
i32.store8 0 12`;
|
1247
|
+
return out;
|
1248
|
+
}
|
1249
|
+
|
1236
1250
|
let tmp: string = Porffor.allocate(), tmpLen: i32 = 0;
|
1237
1251
|
const thisLen: i32 = _this.length * 2, sepLen: i32 = separator.length;
|
1238
1252
|
if (sepLen == 1) {
|
@@ -1263,7 +1277,7 @@ local.get ${outLen}
|
|
1263
1277
|
i32.const 9
|
1264
1278
|
i32.mul
|
1265
1279
|
i32.add
|
1266
|
-
|
1280
|
+
i32.const 67
|
1267
1281
|
i32.store8 0 12`;
|
1268
1282
|
outLen++;
|
1269
1283
|
|
@@ -1275,6 +1289,36 @@ i32.store8 0 12`;
|
|
1275
1289
|
Porffor.wasm.i32.store16(Porffor.wasm`local.get ${tmp}` + tmpLen * 2, x, 0, 4);
|
1276
1290
|
tmpLen++;
|
1277
1291
|
}
|
1292
|
+
} else if (sepLen == 0) {
|
1293
|
+
const clammedLimit: i32 = limit > thisLen ? thisLen : limit;
|
1294
|
+
tmpLen = 1;
|
1295
|
+
for (let i = 0; i <= clammedLimit; i+=2) {
|
1296
|
+
tmp = Porffor.allocateBytes(8);
|
1297
|
+
const x: i32 = Porffor.wasm.i32.load16_u(Porffor.wasm`local.get ${_this}` + i, 0, 4);
|
1298
|
+
|
1299
|
+
Porffor.wasm.i32.store16(Porffor.wasm`local.get ${tmp}`, x, 0, 4);
|
1300
|
+
tmp.length = tmpLen;
|
1301
|
+
out.length = outLen;
|
1302
|
+
|
1303
|
+
Porffor.wasm`
|
1304
|
+
local.get ${out}
|
1305
|
+
local.get ${outLen}
|
1306
|
+
i32.const 9
|
1307
|
+
i32.mul
|
1308
|
+
i32.add
|
1309
|
+
local.get ${tmp}
|
1310
|
+
f64.convert_i32_u
|
1311
|
+
f64.store 0 4
|
1312
|
+
local.get ${out}
|
1313
|
+
local.get ${outLen}
|
1314
|
+
i32.const 9
|
1315
|
+
i32.mul
|
1316
|
+
i32.add
|
1317
|
+
i32.const 67
|
1318
|
+
i32.store8 0 12`;
|
1319
|
+
outLen++;
|
1320
|
+
}
|
1321
|
+
return out;
|
1278
1322
|
} else {
|
1279
1323
|
let sepInd: i32 = 0;
|
1280
1324
|
for (let i: i32 = 0; i < thisLen; i += 2) {
|
@@ -1303,7 +1347,7 @@ local.get ${outLen}
|
|
1303
1347
|
i32.const 9
|
1304
1348
|
i32.mul
|
1305
1349
|
i32.add
|
1306
|
-
|
1350
|
+
i32.const 67
|
1307
1351
|
i32.store8 0 12`;
|
1308
1352
|
outLen++;
|
1309
1353
|
|
@@ -1335,7 +1379,7 @@ local.get ${outLen}
|
|
1335
1379
|
i32.const 9
|
1336
1380
|
i32.mul
|
1337
1381
|
i32.add
|
1338
|
-
|
1382
|
+
i32.const 67
|
1339
1383
|
i32.store8 0 12`;
|
1340
1384
|
outLen++;
|
1341
1385
|
}
|
@@ -1346,7 +1390,21 @@ i32.store8 0 12`;
|
|
1346
1390
|
|
1347
1391
|
export const __ByteString_prototype_split = (_this: bytestring, separator: any, limit: any) => {
|
1348
1392
|
let out: any[] = Porffor.allocate(), outLen: i32 = 0;
|
1349
|
-
|
1393
|
+
|
1394
|
+
if (separator == null) {
|
1395
|
+
out.length = 1;
|
1396
|
+
// out[0] = _this; (but in wasm as it is a f64 array and we are in i32 space)
|
1397
|
+
Porffor.wasm`
|
1398
|
+
local.get ${out}
|
1399
|
+
local.get ${_this}
|
1400
|
+
f64.convert_i32_u
|
1401
|
+
f64.store 0 4
|
1402
|
+
|
1403
|
+
local.get ${out}
|
1404
|
+
i32.const 195
|
1405
|
+
i32.store8 0 12`;
|
1406
|
+
return out;
|
1407
|
+
}
|
1350
1408
|
|
1351
1409
|
if (Porffor.wasm`local.get ${limit+1}` == Porffor.TYPES.undefined) limit = Number.MAX_SAFE_INTEGER;
|
1352
1410
|
limit |= 0;
|
@@ -1382,7 +1440,7 @@ local.get ${outLen}
|
|
1382
1440
|
i32.const 9
|
1383
1441
|
i32.mul
|
1384
1442
|
i32.add
|
1385
|
-
|
1443
|
+
i32.const 195
|
1386
1444
|
i32.store8 0 12`;
|
1387
1445
|
outLen++;
|
1388
1446
|
|
@@ -1394,6 +1452,37 @@ i32.store8 0 12`;
|
|
1394
1452
|
Porffor.wasm.i32.store8(Porffor.wasm`local.get ${tmp}` + tmpLen, x, 0, 4);
|
1395
1453
|
tmpLen++;
|
1396
1454
|
}
|
1455
|
+
} else if (sepLen == 0) {
|
1456
|
+
const clammedLimit: i32 = limit > thisLen ? thisLen : limit;
|
1457
|
+
tmpLen = 1;
|
1458
|
+
for (let i = 0; i <= clammedLimit; i++) {
|
1459
|
+
tmp = Porffor.allocateBytes(8);
|
1460
|
+
const x: i32 = Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${_this}` + i, 0, 4);
|
1461
|
+
|
1462
|
+
Porffor.wasm.i32.store8(Porffor.wasm`local.get ${tmp}`, x, 0, 4);
|
1463
|
+
tmp.length = tmpLen;
|
1464
|
+
out.length = outLen;
|
1465
|
+
|
1466
|
+
Porffor.wasm`
|
1467
|
+
local.get ${out}
|
1468
|
+
local.get ${outLen}
|
1469
|
+
i32.const 9
|
1470
|
+
i32.mul
|
1471
|
+
i32.add
|
1472
|
+
local.get ${tmp}
|
1473
|
+
f64.convert_i32_u
|
1474
|
+
f64.store 0 4
|
1475
|
+
|
1476
|
+
local.get ${out}
|
1477
|
+
local.get ${outLen}
|
1478
|
+
i32.const 9
|
1479
|
+
i32.mul
|
1480
|
+
i32.add
|
1481
|
+
i32.const 195
|
1482
|
+
i32.store8 0 12`;
|
1483
|
+
outLen++;
|
1484
|
+
}
|
1485
|
+
return out;
|
1397
1486
|
} else {
|
1398
1487
|
let sepInd: i32 = 0;
|
1399
1488
|
for (let i: i32 = 0; i < thisLen; i++) {
|
@@ -1422,7 +1511,7 @@ local.get ${outLen}
|
|
1422
1511
|
i32.const 9
|
1423
1512
|
i32.mul
|
1424
1513
|
i32.add
|
1425
|
-
|
1514
|
+
i32.const 195
|
1426
1515
|
i32.store8 0 12`;
|
1427
1516
|
outLen++;
|
1428
1517
|
|
@@ -1454,7 +1543,7 @@ local.get ${outLen}
|
|
1454
1543
|
i32.const 9
|
1455
1544
|
i32.mul
|
1456
1545
|
i32.add
|
1457
|
-
|
1546
|
+
i32.const 195
|
1458
1547
|
i32.store8 0 12`;
|
1459
1548
|
outLen++;
|
1460
1549
|
}
|