porffor 0.58.12 → 0.58.14

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.
@@ -1370,7 +1370,7 @@ const generateBinaryExp = (scope, decl) => {
1370
1370
  };
1371
1371
 
1372
1372
  const asmFuncToAsm = (scope, func, extra) => func(scope, {
1373
- Valtype, Opcodes, TYPES, TYPE_NAMES, usedTypes, typeSwitch, makeString, internalThrow,
1373
+ Valtype, Opcodes, TYPES, TYPE_NAMES, usedTypes, typeSwitch, makeString, internalThrow, funcs,
1374
1374
  getNodeType, generate, generateIdent,
1375
1375
  builtin: (name, offset = false) => {
1376
1376
  let idx = importedFuncs[name] ?? includeBuiltin(scope, name)?.index;
@@ -1442,7 +1442,13 @@ const asmFuncToAsm = (scope, func, extra) => func(scope, {
1442
1442
  wasm.push(Opcodes.i32_to_u);
1443
1443
  return wasm;
1444
1444
  },
1445
- allocPage: (scope, name) => allocPage({ scope, pages }, name)
1445
+ allocPage: (scope, name) => allocPage({ scope, pages }, name),
1446
+ allocLargePage: (scope, name) => {
1447
+ const _ = allocPage({ scope, pages }, name);
1448
+ allocPage({ scope, pages }, name + '#2');
1449
+
1450
+ return _;
1451
+ }
1446
1452
  }, extra);
1447
1453
 
1448
1454
  const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTypes = [], globalInits = {}, returns = [], returnType, localNames = [], globalNames = [], table = false, constr = false, hasRestArgument = false, usesTag = false, usesImports = false, returnTypes } = {}) => {
@@ -2495,6 +2501,8 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2495
2501
  i32_store8: { imms: 2, args: [ true, true ], returns: 0, addValue: true },
2496
2502
  // pointer, align, offset
2497
2503
  i32_load16_u: { imms: 2, args: [ true ], returns: 1 },
2504
+ // pointer, align, offset
2505
+ i32_load16_s: { imms: 2, args: [ true ], returns: 1 },
2498
2506
  // pointer, value, align, offset
2499
2507
  i32_store16: { imms: 2, args: [ true, true ], returns: 0, addValue: true },
2500
2508
 
@@ -2514,35 +2522,34 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2514
2522
  };
2515
2523
 
2516
2524
  const opName = name.slice('__Porffor_wasm_'.length);
2525
+ if (!wasmOps[opName]) throw new Error('Unimplemented Porffor.wasm op: ' + opName);
2517
2526
 
2518
- if (wasmOps[opName]) {
2519
- const op = wasmOps[opName];
2527
+ const op = wasmOps[opName];
2520
2528
 
2521
- const argOut = [];
2522
- for (let i = 0; i < op.args.length; i++) {
2523
- if (!op.args[i]) globalThis.noi32F64CallConv = true;
2529
+ const argOut = [];
2530
+ for (let i = 0; i < op.args.length; i++) {
2531
+ if (!op.args[i]) globalThis.noi32F64CallConv = true;
2524
2532
 
2525
- argOut.push(
2526
- ...generate(scope, decl.arguments[i]),
2527
- ...(op.args[i] ? [ Opcodes.i32_to ] : [])
2528
- );
2533
+ argOut.push(
2534
+ ...generate(scope, decl.arguments[i]),
2535
+ ...(op.args[i] ? [ Opcodes.i32_to ] : [])
2536
+ );
2529
2537
 
2530
- globalThis.noi32F64CallConv = false;
2531
- }
2538
+ globalThis.noi32F64CallConv = false;
2539
+ }
2532
2540
 
2533
- // literals only
2534
- const imms = decl.arguments.slice(op.args.length).map(x => x.value);
2541
+ // literals only
2542
+ const imms = decl.arguments.slice(op.args.length).map(x => x.value);
2535
2543
 
2536
- let opcode = Opcodes[opName];
2537
- if (!Array.isArray(opcode)) opcode = [ opcode ];
2544
+ let opcode = Opcodes[opName];
2545
+ if (!Array.isArray(opcode)) opcode = [ opcode ];
2538
2546
 
2539
- return [
2540
- ...argOut,
2541
- [ ...opcode, ...imms ],
2542
- ...(new Array(op.returns).fill(Opcodes.i32_from)),
2543
- ...(op.addValue ? [ number(UNDEFINED) ] : [])
2544
- ];
2545
- }
2547
+ return [
2548
+ ...argOut,
2549
+ [ ...opcode, ...imms ],
2550
+ ...(new Array(op.returns).fill(Opcodes.i32_from)),
2551
+ ...(op.addValue ? [ number(UNDEFINED) ] : [])
2552
+ ];
2546
2553
  } else {
2547
2554
  if (!Prefs.indirectCalls) return internalThrow(scope, 'TypeError', `${unhackName(name)} is not a function`, true);
2548
2555
 
@@ -4145,6 +4152,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
4145
4152
  ]),
4146
4153
  ...setLastType(scope)
4147
4154
  ], generate(scope, decl.right), getLastType(scope), getNodeType(scope, decl.right))),
4155
+ ...(valtypeBinary === Valtype.i32 ? [ [ Opcodes.f64_convert_i32_s ] ] : []),
4148
4156
  ...getNodeType(scope, decl),
4149
4157
 
4150
4158
  ...(hash != null ? [
@@ -6195,8 +6203,8 @@ const generateMember = (scope, decl, _global, _name) => {
6195
6203
  ] : [
6196
6204
  [ Opcodes.call, includeBuiltin(scope, '__Porffor_object_get').index ]
6197
6205
  ]),
6198
-
6199
- ...setLastType(scope)
6206
+ ...setLastType(scope),
6207
+ ...(valtypeBinary === Valtype.i32 ? [ Opcodes.i32_trunc_sat_f64_s ] : [])
6200
6208
  ],
6201
6209
 
6202
6210
  ...extraBC
@@ -7282,6 +7290,10 @@ export default program => {
7282
7290
  tags = [];
7283
7291
  exceptions = [];
7284
7292
  funcs = []; indirectFuncs = [];
7293
+ funcs.bytesPerFuncLut = () => {
7294
+ return indirectFuncs._bytesPerFuncLut ??=
7295
+ Math.min(Math.floor((pageSize * 2) / indirectFuncs.length), indirectFuncs.reduce((acc, x) => x.name.length > acc ? x.name.length : acc, 0) + 8);
7296
+ };
7285
7297
  funcIndex = {};
7286
7298
  depth = [];
7287
7299
  pages = new Map();
package/compiler/wrap.js CHANGED
@@ -351,7 +351,7 @@ ${flags & 0b0001 ? ` get func idx: ${get}
351
351
  const [ flags ] = read(Uint16Array, memory, value + 4, 1);
352
352
 
353
353
  if (Prefs.d) {
354
- const bc = new Uint8Array(memory.buffer.slice(value + 6));
354
+ const bc = new Uint8Array(memory.buffer.slice(value + 10));
355
355
  let i = 0;
356
356
  while (true) {
357
357
  const opcode = bc[i++];
@@ -449,7 +449,7 @@ ${flags & 0b0001 ? ` get func idx: ${get}
449
449
  case 0x30:
450
450
  case 0x31: {
451
451
  const index = bc[i++];
452
- console.log(`${opcode === 0x30 ? 'start' : 'end'} capture`, index);
452
+ console.log(`\x1b[2m${opcode === 0x30 ? 'start' : 'end'} capture ${index}\x1b[0m`);
453
453
  break;
454
454
  }
455
455
  }
package/foo.js ADDED
@@ -0,0 +1,4 @@
1
+ console.log(/a(?=b)/.test('ab'));
2
+ console.log(/a(?=b)/.test('ac'));
3
+ console.log(/a(?!b)/.test('ab'));
4
+ console.log(/a(?!b)/.test('ac'));
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.58.12",
4
+ "version": "0.58.14",
5
5
  "author": "Oliver Medhurst <honk@goose.icu>",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runtime/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.58.12';
3
+ globalThis.version = '0.58.14';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {