porffor 0.55.6 → 0.55.8

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.
@@ -2119,15 +2119,17 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2119
2119
  }
2120
2120
 
2121
2121
  // literal.func()
2122
- if (!decl._new && !name && decl.callee.type === 'MemberExpression') {
2122
+ if (!decl._new && !name && (decl.callee.type === 'MemberExpression' || decl.callee.type === 'ChainExpression')) {
2123
+ const prop = (decl.callee.expression ?? decl.callee).property;
2124
+ const object = (decl.callee.expression ?? decl.callee).object;
2125
+
2123
2126
  // megahack for /regex/.func()
2124
- const funcName = decl.callee.property.name;
2125
- if (decl.callee.object.regex && ['test'].includes(funcName)) {
2126
- const regex = decl.callee.object.regex.pattern;
2127
- const rhemynName = `regex_${funcName}_${sanitize(regex)}`;
2127
+ if (object?.regex && ['test'].includes(prop.name)) {
2128
+ const regex = object.regex.pattern;
2129
+ const rhemynName = `regex_${prop.name}_${sanitize(regex)}`;
2128
2130
 
2129
2131
  if (!funcIndex[rhemynName]) {
2130
- const func = Rhemyn[funcName](regex, currentFuncIndex++, rhemynName);
2132
+ const func = Rhemyn[prop.name](regex, currentFuncIndex++, rhemynName);
2131
2133
  func.internal = true;
2132
2134
 
2133
2135
  funcIndex[func.name] = func.index;
@@ -2146,15 +2148,15 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2146
2148
  [ Opcodes.call, idx ],
2147
2149
  Opcodes.i32_from_u,
2148
2150
 
2149
- ...setLastType(scope, Rhemyn.types[funcName])
2151
+ ...setLastType(scope, Rhemyn.types[prop.name])
2150
2152
  ];
2151
2153
  }
2152
2154
 
2153
- protoName = decl.callee.property.name;
2154
- target = decl.callee.object;
2155
+ protoName = prop?.name;
2156
+ target = object;
2155
2157
  }
2156
2158
 
2157
- if (protoName) {
2159
+ if (protoName && target) {
2158
2160
  if (protoName === 'call') {
2159
2161
  const valTmp = localTmp(scope, '#call_val');
2160
2162
  const typeTmp = localTmp(scope, '#call_type', Valtype.i32);
@@ -2528,28 +2530,31 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2528
2530
  const calleeLocal = localTmp(scope, tmpName + 'callee');
2529
2531
 
2530
2532
  // hack: this should be more thorough, Function.bind, etc
2531
- if (decl.callee.type === 'MemberExpression' && !decl._new) {
2532
- const thisLocal = localTmp(scope, tmpName + 'caller');
2533
- const thisLocalType = localTmp(scope, tmpName + 'caller#type', Valtype.i32);
2534
-
2535
- knownThis = [
2536
- [ Opcodes.local_get, thisLocal ],
2537
- [ Opcodes.local_get, thisLocalType ]
2538
- ];
2539
- getCallee = [
2540
- ...generate(scope, decl.callee.object),
2541
- [ Opcodes.local_set, thisLocal ],
2542
- ...getNodeType(scope, decl.callee.object),
2543
- [ Opcodes.local_set, thisLocalType ],
2533
+ if (!decl._new && (decl.callee.type === 'MemberExpression' || decl.callee.type === 'ChainExpression')) {
2534
+ const { property, object, computed, optional } = decl.callee.expression ?? decl.callee;
2535
+ if (object && property) {
2536
+ const thisLocal = localTmp(scope, tmpName + 'caller');
2537
+ const thisLocalType = localTmp(scope, tmpName + 'caller#type', Valtype.i32);
2538
+
2539
+ knownThis = [
2540
+ [ Opcodes.local_get, thisLocal ],
2541
+ [ Opcodes.local_get, thisLocalType ]
2542
+ ];
2543
+ getCallee = [
2544
+ ...generate(scope, object),
2545
+ [ Opcodes.local_set, thisLocal ],
2546
+ ...getNodeType(scope, object),
2547
+ [ Opcodes.local_set, thisLocalType ],
2544
2548
 
2545
- ...generate(scope, {
2546
- type: 'MemberExpression',
2547
- object: { type: 'Identifier', name: tmpName + 'caller' },
2548
- property: decl.callee.property,
2549
- computed: decl.callee.computed,
2550
- optional: decl.callee.optional
2551
- })
2552
- ];
2549
+ ...generate(scope, {
2550
+ type: 'MemberExpression',
2551
+ object: { type: 'Identifier', name: tmpName + 'caller' },
2552
+ property,
2553
+ computed,
2554
+ optional
2555
+ })
2556
+ ];
2557
+ }
2553
2558
  }
2554
2559
 
2555
2560
  let callee = decl.callee, callAsNew = decl._new;
package/compiler/index.js CHANGED
@@ -67,7 +67,7 @@ export default (code, module = undefined) => {
67
67
  let target = Prefs.target ?? 'wasm';
68
68
  if (Prefs.native) target = 'native';
69
69
 
70
- const outFile = Prefs.o;
70
+ let outFile = Prefs.o;
71
71
  const logProgress = Prefs.profileCompiler || (Prefs.target && outFile && !Prefs.native && globalThis.file);
72
72
 
73
73
  globalThis.valtype = Prefs.valtype ?? 'f64';
@@ -243,14 +243,15 @@ export default (code, module = undefined) => {
243
243
  outFile ??= Prefs.native ? './porffor_tmp' : file.split('/').at(-1).split('.')[0];
244
244
 
245
245
  let compiler = Prefs.compiler ?? 'clang';
246
- const cO = Prefs._cO ?? 'Ofast';
246
+ const cO = Prefs._cO ?? 'O3';
247
247
 
248
248
  if (compiler === 'zig') compiler = [ 'zig', 'cc' ];
249
249
  else compiler = [ compiler ];
250
250
 
251
251
  const tmpfile = 'porffor_tmp.c';
252
252
  const args = [ ...compiler, tmpfile, '-o', outFile ?? (process.platform === 'win32' ? 'out.exe' : 'out'), '-' + cO ];
253
- if (!Prefs.compiler) args.push('-flto=thin', '-march=native', '-s', '-ffast-math', '-fno-exceptions', '-fno-ident', '-fno-asynchronous-unwind-tables', '-ffunction-sections', '-fdata-sections');
253
+ if (compiler.includes('clang')) args.push('-flto=thin', '-march=native', '-ffast-math', '-fno-exceptions', '-fno-ident', '-fno-asynchronous-unwind-tables', '-ffunction-sections', '-fdata-sections');
254
+ if (Prefs.s) args.push('-s');
254
255
 
255
256
  if (logProgress) progressStart('compiling Wasm to C...');
256
257
  const t4 = performance.now();
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.6",
4
+ "version": "0.55.8",
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.55.6';
3
+ globalThis.version = '0.55.8';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
package/r.js DELETED
@@ -1,6 +0,0 @@
1
- const a = {
2
- b() { return this._b; },
3
- _b: { c: 42 }
4
- };
5
-
6
- console.log((a?.b)())