porffor 0.37.15 → 0.37.17

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.
@@ -1015,7 +1015,7 @@ const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTy
1015
1015
  const existing = funcByName(name);
1016
1016
  if (existing) return existing;
1017
1017
 
1018
- const nameParam = i => localNames[i] ?? (i >= params.length ? ['a', 'b', 'c'][i - params.length] : ['x', 'y', 'z'][i]);
1018
+ const nameParam = i => localNames[i] ?? `l${i}`;
1019
1019
 
1020
1020
  const allLocals = params.concat(localTypes);
1021
1021
  const locals = {};
@@ -1398,6 +1398,11 @@ const getNodeType = (scope, node) => {
1398
1398
  return TYPES.number;
1399
1399
  }
1400
1400
 
1401
+ if (node.type === 'TemplateLiteral') {
1402
+ // could be normal string but shrug
1403
+ return TYPES.bytestring;
1404
+ }
1405
+
1401
1406
  if (node.type === 'TaggedTemplateExpression') {
1402
1407
  // hack
1403
1408
  switch (node.tag.name) {
@@ -2932,6 +2937,59 @@ const setLocalWithType = (scope, name, isGlobal, decl, tee = false, overrideType
2932
2937
  };
2933
2938
 
2934
2939
  const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
2940
+ // statically analyzed ffi dlopen hack to let 2c handle it
2941
+ if (init && init.type === 'CallExpression' && init.callee.name === '__Porffor_dlopen') {
2942
+ if (Prefs.target !== 'native' && !Prefs.native) throw new Error('Porffor.dlopen is only supported for native target (use --native)');
2943
+
2944
+ // disable pgo if using ffi (lol)
2945
+ Prefs.pgo = false;
2946
+
2947
+ try {
2948
+ let usedNames = [];
2949
+ for (const x of pattern.properties) {
2950
+ const name = x.key.name;
2951
+ usedNames.push(name);
2952
+ }
2953
+
2954
+ let path = init.arguments[0].value;
2955
+ let symbols = {};
2956
+
2957
+ for (const x of init.arguments[1].properties) {
2958
+ const name = x.key.name;
2959
+ if (!usedNames.includes(name)) continue;
2960
+
2961
+ let parameters, result;
2962
+ for (const y of x.value.properties) {
2963
+ switch (y.key.name) {
2964
+ case 'parameters':
2965
+ parameters = y.value.elements.map(z => z.value);
2966
+ break;
2967
+
2968
+ case 'result':
2969
+ result = y.value.value;
2970
+ break;
2971
+ }
2972
+ }
2973
+
2974
+ symbols[name] = { parameters, result };
2975
+
2976
+ // mock ffi function
2977
+ asmFunc(name, {
2978
+ wasm: [],
2979
+ params: parameters.map(x => Valtype.i32),
2980
+ returns: result ? [ Valtype.i32 ] : [],
2981
+ returnType: TYPES.number
2982
+ })
2983
+ }
2984
+
2985
+ return [ [ null, 'dlopen', path, symbols ] ];
2986
+ } catch (e) {
2987
+ console.error('bad Porffor.dlopen syntax');
2988
+ throw e;
2989
+ }
2990
+ }
2991
+
2992
+
2935
2993
  const topLevel = scope.name === 'main';
2936
2994
 
2937
2995
  if (typeof pattern === 'string') {
@@ -3502,7 +3560,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3502
3560
  [TYPES.undefined]: internalThrow(scope, 'TypeError', 'Cannot set property of undefined', true),
3503
3561
 
3504
3562
  // default: internalThrow(scope, 'TypeError', `Cannot assign member with this type`)
3505
- default: [
3563
+ default: () => [
3506
3564
  ...objectWasm,
3507
3565
  Opcodes.i32_to_u,
3508
3566
  ...(op === '=' ? [] : [ [ Opcodes.local_tee, localTmp(scope, '#objset_object', Valtype.i32) ] ]),
@@ -5185,7 +5243,7 @@ const countParams = (func, name = undefined) => {
5185
5243
  name ??= func.name;
5186
5244
  let params = func.params.length;
5187
5245
  if (func.constr) params -= 4;
5188
- if (!builtinFuncs[name] || builtinFuncs[name]?.typedParams) params = Math.floor(params / 2);
5246
+ if (!func.internal || builtinFuncs[name]?.typedParams) params = Math.floor(params / 2);
5189
5247
 
5190
5248
  return func.argc = params;
5191
5249
  };
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.37.15+ef676dd35",
4
+ "version": "0.37.17+5b3ce1ba8",
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.37.15+ef676dd35';
3
+ globalThis.version = '0.37.17+5b3ce1ba8';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {