porffor 0.25.9 → 0.27.0

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.
@@ -376,7 +376,7 @@ const generateReturn = (scope, decl) => {
376
376
  ...generate(scope, arg),
377
377
  ...(scope.returnType != null ? [] : getNodeType(scope, arg)),
378
378
 
379
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_promise_resolve').index) ],
379
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_promise_resolve').index ],
380
380
  [ Opcodes.drop ],
381
381
  [ Opcodes.drop ],
382
382
 
@@ -546,7 +546,7 @@ const concatStrings = (scope, left, right, leftType, rightType, allBytestrings =
546
546
  [ Opcodes.if, Blocktype.void ],
547
547
  [ Opcodes.local_get, leftPointer ],
548
548
  [ Opcodes.local_get, leftLength ],
549
- [ Opcodes.call, ...unsignedLEB128(funcIndex.__Porffor_bytestringToString) ],
549
+ [ Opcodes.call, funcIndex.__Porffor_bytestringToString ],
550
550
  [ Opcodes.local_set, leftPointer ],
551
551
  [ Opcodes.end ],
552
552
 
@@ -556,7 +556,7 @@ const concatStrings = (scope, left, right, leftType, rightType, allBytestrings =
556
556
  [ Opcodes.if, Blocktype.void ],
557
557
  [ Opcodes.local_get, rightPointer ],
558
558
  [ Opcodes.local_get, rightLength ],
559
- [ Opcodes.call, ...unsignedLEB128(funcIndex.__Porffor_bytestringToString) ],
559
+ [ Opcodes.call, funcIndex.__Porffor_bytestringToString ],
560
560
  [ Opcodes.local_set, rightPointer ],
561
561
  [ Opcodes.end ]
562
562
  ]),
@@ -662,7 +662,7 @@ const compareStrings = (scope, left, right, leftType, rightType, allBytestrings
662
662
  [ Opcodes.if, Blocktype.void ],
663
663
  [ Opcodes.local_get, leftPointer ],
664
664
  [ Opcodes.local_get, leftLength ],
665
- [ Opcodes.call, ...unsignedLEB128(funcIndex.__Porffor_bytestringToString) ],
665
+ [ Opcodes.call, funcIndex.__Porffor_bytestringToString ],
666
666
  [ Opcodes.local_set, leftPointer ],
667
667
  [ Opcodes.end ],
668
668
 
@@ -673,7 +673,7 @@ const compareStrings = (scope, left, right, leftType, rightType, allBytestrings
673
673
  [ Opcodes.local_get, rightPointer ],
674
674
  [ Opcodes.local_get, rightPointer ],
675
675
  [ Opcodes.i32_load, 0, 0 ],
676
- [ Opcodes.call, ...unsignedLEB128(funcIndex.__Porffor_bytestringToString) ],
676
+ [ Opcodes.call, funcIndex.__Porffor_bytestringToString ],
677
677
  [ Opcodes.local_set, rightPointer ],
678
678
  [ Opcodes.end ]
679
679
  ]),
@@ -1016,7 +1016,7 @@ const performOp = (scope, op, left, right, leftType, rightType, _global = false,
1016
1016
  return finalize([
1017
1017
  ...left,
1018
1018
  ...right,
1019
- [ Opcodes.call, ...unsignedLEB128(idx) ]
1019
+ [ Opcodes.call, idx ]
1020
1020
  ]);
1021
1021
  }
1022
1022
 
@@ -1239,7 +1239,7 @@ const asmFuncToAsm = (scope, func) => {
1239
1239
  if (idx == null) throw new Error(`builtin('${n}') failed: could not find func (from ${scope.name})`);
1240
1240
  if (offset) idx -= importedFuncs.length;
1241
1241
 
1242
- return float ? ieee754_binary64(idx) : unsignedLEB128(idx);
1242
+ return float ? ieee754_binary64(idx) : idx;
1243
1243
  },
1244
1244
  glbl: (opcode, name, type) => {
1245
1245
  const globalName = '#porf#' + name; // avoid potential name clashing with user js
@@ -1940,7 +1940,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
1940
1940
  ...getNodeType(scope, decl.arguments[0]),
1941
1941
 
1942
1942
  // call regex func
1943
- [ Opcodes.call, ...unsignedLEB128(idx) ],
1943
+ [ Opcodes.call, idx ],
1944
1944
  Opcodes.i32_from_u,
1945
1945
 
1946
1946
  ...setLastType(scope, Rhemyn.types[funcName])
@@ -1983,7 +1983,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
1983
1983
  ...getNodeType(scope, target),
1984
1984
 
1985
1985
  // call regex func
1986
- [ Opcodes.call, ...unsignedLEB128(idx) ],
1986
+ [ Opcodes.call, idx ],
1987
1987
  Opcodes.i32_from,
1988
1988
 
1989
1989
  ...setLastType(scope, Rhemyn.types[protoName])
@@ -2503,7 +2503,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2503
2503
  if (typedParams) out = out.concat(getNodeType(scope, arg));
2504
2504
  }
2505
2505
 
2506
- out.push([ Opcodes.call, ...unsignedLEB128(idx) ]);
2506
+ out.push([ Opcodes.call, idx ]);
2507
2507
 
2508
2508
  if (!typedReturns) {
2509
2509
  // let type;
@@ -3133,12 +3133,12 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3133
3133
  [ Opcodes.local_get, localTmp(scope, '#objset_property', Valtype.i32) ],
3134
3134
  [ Opcodes.local_get, localTmp(scope, '#objset_property_type', Valtype.i32) ],
3135
3135
 
3136
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_object_get').index) ],
3136
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_object_get').index ],
3137
3137
  ...setLastType(scope)
3138
3138
  ], generate(scope, decl.right), getLastType(scope), getNodeType(scope, decl.right), false, name, true)),
3139
3139
  ...getNodeType(scope, decl),
3140
3140
 
3141
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_object_set').index) ],
3141
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_object_set').index ],
3142
3142
  [ Opcodes.drop ],
3143
3143
  // ...setLastType(scope, getNodeType(scope, decl)),
3144
3144
  ],
@@ -3437,7 +3437,7 @@ const generateUnary = (scope, decl) => {
3437
3437
  ...getNodeType(scope, property),
3438
3438
  ...toPropertyKey(scope, true),
3439
3439
 
3440
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_object_delete').index) ],
3440
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_object_delete').index ],
3441
3441
  [ Opcodes.drop ],
3442
3442
  Opcodes.i32_from_u
3443
3443
  ];
@@ -3750,7 +3750,7 @@ const generateForOf = (scope, decl) => {
3750
3750
  ...setType(scope, leftName, TYPES.string),
3751
3751
 
3752
3752
  // allocate out string
3753
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_allocate').index) ],
3753
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ],
3754
3754
  [ Opcodes.local_tee, localTmp(scope, '#forof_allocd', Valtype.i32) ],
3755
3755
 
3756
3756
  // set length to 1
@@ -3804,7 +3804,7 @@ const generateForOf = (scope, decl) => {
3804
3804
  ...setType(scope, leftName, TYPES.bytestring),
3805
3805
 
3806
3806
  // allocate out string
3807
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_allocate').index) ],
3807
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ],
3808
3808
  [ Opcodes.local_tee, localTmp(scope, '#forof_allocd', Valtype.i32) ],
3809
3809
 
3810
3810
  // set length to 1
@@ -4594,7 +4594,7 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
4594
4594
 
4595
4595
  if (name === '#member_prop_assign') {
4596
4596
  out.push(
4597
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_allocate').index) ]
4597
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ]
4598
4598
  );
4599
4599
  shouldGet = false;
4600
4600
  }
@@ -4734,7 +4734,7 @@ const generateArray = (scope, decl, global = false, name = '$undeclared', initEm
4734
4734
  };
4735
4735
 
4736
4736
  const toPropertyKey = (scope, i32Conv = false) => [
4737
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__ecma262_ToPropertyKey').index) ],
4737
+ [ Opcodes.call, includeBuiltin(scope, '__ecma262_ToPropertyKey').index ],
4738
4738
  ...(i32Conv ? [
4739
4739
  [ Opcodes.local_set, localTmp(scope, '#swap', Valtype.i32) ],
4740
4740
  Opcodes.i32_to_u,
@@ -4744,7 +4744,7 @@ const toPropertyKey = (scope, i32Conv = false) => [
4744
4744
 
4745
4745
  const generateObject = (scope, decl, global = false, name = '$undeclared') => {
4746
4746
  const out = [
4747
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_allocate').index) ]
4747
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ]
4748
4748
  ];
4749
4749
 
4750
4750
  if (decl.properties.length > 0) {
@@ -4773,7 +4773,7 @@ const generateObject = (scope, decl, global = false, name = '$undeclared') => {
4773
4773
  ...(kind !== 'init' ? [ Opcodes.i32_to_u ] : []),
4774
4774
  ...getNodeType(scope, value),
4775
4775
 
4776
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, `__Porffor_object_expr_${kind}`).index) ],
4776
+ [ Opcodes.call, includeBuiltin(scope, `__Porffor_object_expr_${kind}`).index ],
4777
4777
 
4778
4778
  [ Opcodes.drop ],
4779
4779
  [ Opcodes.drop ]
@@ -4894,7 +4894,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
4894
4894
  [ Opcodes.i32_eq ],
4895
4895
  [ Opcodes.if, Blocktype.void ],
4896
4896
  [ Opcodes.local_get, tmp ],
4897
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_funcLut_length').index) ],
4897
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_funcLut_length').index ],
4898
4898
  Opcodes.i32_from_u,
4899
4899
 
4900
4900
  ...setLastType(scope, TYPES.number),
@@ -4953,7 +4953,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
4953
4953
 
4954
4954
  [TYPES.string]: [
4955
4955
  // allocate out string
4956
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_allocate').index) ],
4956
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ],
4957
4957
  [ Opcodes.local_tee, localTmp(scope, '#member_allocd', Valtype.i32) ],
4958
4958
 
4959
4959
  // set length to 1
@@ -4987,7 +4987,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
4987
4987
 
4988
4988
  [TYPES.bytestring]: [
4989
4989
  // allocate out string
4990
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_allocate').index) ],
4990
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ],
4991
4991
  [ Opcodes.local_tee, localTmp(scope, '#member_allocd', Valtype.i32) ],
4992
4992
 
4993
4993
  // set length to 1
@@ -5025,7 +5025,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
5025
5025
  ...getNodeType(scope, property),
5026
5026
  ...toPropertyKey(scope, true),
5027
5027
 
5028
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_object_get').index) ],
5028
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_object_get').index ],
5029
5029
  ...setLastType(scope)
5030
5030
  ],
5031
5031
 
@@ -5038,7 +5038,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
5038
5038
  ...getNodeType(scope, property),
5039
5039
  ...toPropertyKey(scope, true),
5040
5040
 
5041
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_object_get').index) ],
5041
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_object_get').index ],
5042
5042
  ...setLastType(scope)
5043
5043
  ],
5044
5044
 
@@ -5309,7 +5309,7 @@ const generateFunc = (scope, decl) => {
5309
5309
  if (decl.async) {
5310
5310
  // make promise at the start
5311
5311
  wasm.unshift(
5312
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(func, '__Porffor_promise_create').index) ],
5312
+ [ Opcodes.call, includeBuiltin(func, '__Porffor_promise_create').index ],
5313
5313
  [ Opcodes.drop ],
5314
5314
  [ Opcodes.local_set, func.locals['#async_out_promise'].idx ]
5315
5315
  );
@@ -5348,7 +5348,7 @@ const generateFunc = (scope, decl) => {
5348
5348
  // inject promise job runner func at the end of main if used
5349
5349
  if (Object.hasOwn(funcIndex, '__ecma262_HostEnqueuePromiseJob')) {
5350
5350
  wasm.push(
5351
- [ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_promise_runJobs').index) ],
5351
+ [ Opcodes.call, includeBuiltin(scope, '__Porffor_promise_runJobs').index ],
5352
5352
  [ Opcodes.drop ],
5353
5353
  [ Opcodes.drop ]
5354
5354
  );
@@ -98,7 +98,7 @@ export default (wasm, name = '', ind = 0, locals = {}, params = [], returns = []
98
98
  }
99
99
 
100
100
  if (inst[0] === Opcodes.call || inst[0] === Opcodes.return_call) {
101
- const idx = read_unsignedLEB128(inst.slice(1));
101
+ const idx = inst[1];
102
102
  const callFunc = funcs.find(x => x.index === idx);
103
103
  if (callFunc) out += ` ;; $${callFunc.name} ${makeSignature(callFunc.params, callFunc.returns)}`;
104
104
  if (globalThis.importFuncs && idx < importFuncs.length) {
@@ -92,7 +92,7 @@ const compile = async (file, _funcs) => {
92
92
  const y = wasm[i];
93
93
  const n = wasm[i + 1];
94
94
  if (y[0] === Opcodes.call) {
95
- const idx = read_unsignedLEB128(y.slice(1));
95
+ const idx = y[1];
96
96
  const f = funcs.find(x => x.index === idx);
97
97
  if (!f) continue;
98
98
 
@@ -204,8 +204,8 @@ ${funcs.map(x => {
204
204
  .replace(/\["alloc","(.*?)","(.*?)",(.*?)\]/g, (_, reason, type, valtype) => `...number(allocPage(scope, '${reason}', '${type}') * pageSize, ${valtype})`)
205
205
  .replace(/\["global",(.*?),"(.*?)",(.*?)\]/g, (_, opcode, name, valtype) => `...glbl(${opcode}, '${name}', ${valtype})`)
206
206
  .replace(/\"local","(.*?)",(.*?)\]/g, (_, name, valtype) => `loc('${name}', ${valtype})]`)
207
- .replace(/\[16,"(.*?)"]/g, (_, name) => `[16, ...builtin('${name}')]`)
208
- .replace(/\[68,"funcref","(.*?)"]/g, (_, name, offset) => `[68,...builtin('${name}', true, true)]`)
207
+ .replace(/\[16,"(.*?)"]/g, (_, name) => `[16, builtin('${name}')]`)
208
+ .replace(/\[68,"funcref","(.*?)"]/g, (_, name, offset) => `[68, ...builtin('${name}', true, true)]`)
209
209
  .replace(/\["throw","(.*?)","(.*?)"\]/g, (_, constructor, message) => `...internalThrow(scope, '${constructor}', \`${message}\`)`)
210
210
  .replace(/\["get object","(.*?)"\]/g, (_, objName) => `...generateIdent(scope, { name: '${objName}' })`);
211
211
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
4
- "version": "0.25.9+5c6c180c0",
4
+ "version": "0.27.0+acf68b3a9",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
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.25.9+5c6c180c0';
3
+ globalThis.version = '0.27.0+acf68b3a9';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {