porffor 0.55.4 → 0.55.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.
@@ -2134,12 +2134,13 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2134
2134
  funcs.push(func);
2135
2135
  }
2136
2136
 
2137
+ const arg = decl.arguments[0] ?? DEFAULT_VALUE();
2137
2138
  const idx = funcIndex[rhemynName];
2138
2139
  return [
2139
2140
  // make string arg
2140
- ...generate(scope, decl.arguments[0]),
2141
+ ...generate(scope, arg),
2141
2142
  Opcodes.i32_to_u,
2142
- ...getNodeType(scope, decl.arguments[0]),
2143
+ ...getNodeType(scope, arg),
2143
2144
 
2144
2145
  // call regex func
2145
2146
  [ Opcodes.call, idx ],
@@ -2150,7 +2151,6 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2150
2151
  }
2151
2152
 
2152
2153
  protoName = decl.callee.property.name;
2153
-
2154
2154
  target = decl.callee.object;
2155
2155
  }
2156
2156
 
@@ -2163,6 +2163,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2163
2163
  type: 'CallExpression',
2164
2164
  callee: target,
2165
2165
  arguments: decl.arguments.slice(1),
2166
+ optional: decl.optional,
2166
2167
  _thisWasm: [
2167
2168
  ...generate(scope, decl.arguments[0] ?? DEFAULT_VALUE()),
2168
2169
  [ Opcodes.local_tee, valTmp ],
@@ -2269,6 +2270,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2269
2270
 
2270
2271
  protoBC[type] = () => generate(scope, {
2271
2272
  type: 'CallExpression',
2273
+ optional: decl.optional,
2272
2274
  callee: {
2273
2275
  type: 'Identifier',
2274
2276
  name: x
@@ -2370,7 +2372,8 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2370
2372
  ...protoBC,
2371
2373
 
2372
2374
  // TODO: error better
2373
- default: internalThrow(scope, 'TypeError', `'${protoName}' proto func tried to be called on a type without an impl`, !unusedValue)
2375
+ default: decl.optional ? withType(scope, [ number(UNDEFINED) ], TYPES.undefined)
2376
+ : internalThrow(scope, 'TypeError', `'${protoName}' proto func tried to be called on a type without an impl`, !unusedValue)
2374
2377
  }, unusedValue ? Blocktype.void : valtypeBinary),
2375
2378
  ...(unusedValue ? [ number(UNDEFINED) ] : [])
2376
2379
  ];
@@ -2392,7 +2395,8 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2392
2395
  ...protoBC,
2393
2396
 
2394
2397
  // TODO: error better
2395
- default: def
2398
+ default: decl.optional ? withType(scope, [ number(UNDEFINED) ], TYPES.undefined)
2399
+ : def
2396
2400
  }, valtypeBinary)
2397
2401
  ];
2398
2402
  }
@@ -2580,7 +2584,8 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2580
2584
  ...setLastType(scope)
2581
2585
  ],
2582
2586
 
2583
- default: internalThrow(scope, 'TypeError', `${unhackName(name)} is not a function`, Valtype.f64)
2587
+ default: decl.optional ? withType(scope, [ number(UNDEFINED) ], TYPES.undefined)
2588
+ : internalThrow(scope, 'TypeError', `${unhackName(name)} is not a function`, Valtype.f64)
2584
2589
  }, Valtype.f64),
2585
2590
  ...(valtypeBinary === Valtype.i32 && scope.returns[0] !== Valtype.f64 ? [ [ Opcodes.f64_convert_i32_s ] ] : [])
2586
2591
  ];
@@ -3180,7 +3185,7 @@ const setDefaultFuncName = (decl, name) => {
3180
3185
  if (decl.type === 'ClassExpression') {
3181
3186
  // check if it has a name definition
3182
3187
  for (const x of decl.body.body) {
3183
- if (x.key.name === 'name') return;
3188
+ if (x.static && x.key.name === 'name') return;
3184
3189
  }
3185
3190
  }
3186
3191
 
@@ -3258,7 +3263,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
3258
3263
  const [ _func, out ] = generateFunc(scope, init, true);
3259
3264
 
3260
3265
  const funcName = init.id?.name;
3261
- if (name !== funcName) {
3266
+ if (name !== funcName && funcIndex[funcName]) {
3262
3267
  funcIndex[name] = funcIndex[funcName];
3263
3268
  delete funcIndex[funcName];
3264
3269
  }
package/compiler/wrap.js CHANGED
@@ -537,7 +537,7 @@ export default (source, module = undefined, customImports = {}, print = str => p
537
537
  }
538
538
 
539
539
  if (Prefs.disassemble) {
540
- return { exports, wasm, times, disams: funcs.map(x => disassemble(x.wasm, x.name, x.index, x.locals, x.params, x.returns, funcs, globals, exceptions)), c };
540
+ return { exports, wasm, times, disasms: funcs.map(x => disassemble(x.wasm, x.name, x.index, x.locals, x.params, x.returns, funcs, globals, exceptions)), c };
541
541
  }
542
542
 
543
543
  return { exports, wasm, times, pages, c };
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.55.4",
4
+ "version": "0.55.6",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/r.js CHANGED
@@ -1,2 +1,6 @@
1
- function print() {}
2
- print();
1
+ const a = {
2
+ b() { return this._b; },
3
+ _b: { c: 42 }
4
+ };
5
+
6
+ console.log((a?.b)())
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.55.4';
3
+ globalThis.version = '0.55.6';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {