porffor 0.57.1 → 0.57.3
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/string.ts +97 -8
- package/compiler/builtins_precompiled.js +105 -105
- 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 +1 -1
- 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 +2 -1
- /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';
|
@@ -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
|
}
|