porffor 0.47.8 → 0.48.1

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.
@@ -2961,6 +2961,19 @@ const setLocalWithType = (scope, name, isGlobal, decl, tee = false, overrideType
2961
2961
  return out;
2962
2962
  };
2963
2963
 
2964
+ const setDefaultFuncName = (decl, name) => {
2965
+ if (decl.id) return;
2966
+
2967
+ if (decl.type === 'ClassExpression') {
2968
+ // check if it has a name definition
2969
+ for (const x of decl.body.body) {
2970
+ if (x.key.name === 'name') return;
2971
+ }
2972
+ }
2973
+
2974
+ decl.id = { name };
2975
+ };
2976
+
2964
2977
  const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
2965
2978
  // statically analyzed ffi dlopen hack to let 2c handle it
2966
2979
  if (init && init.type === 'CallExpression' && init.callee.name === '__Porffor_dlopen') {
@@ -3014,7 +3027,6 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
3014
3027
  }
3015
3028
  }
3016
3029
 
3017
-
3018
3030
  const topLevel = scope.name === 'main';
3019
3031
 
3020
3032
  if (typeof pattern === 'string') {
@@ -3030,12 +3042,17 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
3030
3042
  if (init && isFuncType(init.type)) {
3031
3043
  // hack for let a = function () { ... }
3032
3044
  if (!init.id) {
3033
- init.id = { name };
3045
+ setDefaultFuncName(init, name);
3034
3046
  generateFunc(scope, init, true);
3035
3047
  return out;
3036
3048
  }
3037
3049
  }
3038
3050
 
3051
+ if (defaultValue && isFuncType(defaultValue.type)) {
3052
+ // set id as name, but do not use it as it is only default value
3053
+ if (!defaultValue.id) setDefaultFuncName(defaultValue, name);
3054
+ }
3055
+
3039
3056
  if (topLevel && Object.hasOwn(builtinVars, name)) {
3040
3057
  // cannot redeclare
3041
3058
  if (kind !== 'var') return internalThrow(scope, 'SyntaxError', `Identifier '${unhackName(name)}' has already been declared`);
@@ -3161,7 +3178,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
3161
3178
  out = out.concat([
3162
3179
  // check tmp is iterable
3163
3180
  // array or string or bytestring
3164
- ...typeIsOneOf(getType(scope, tmpName), [ TYPES.array, TYPES.string, TYPES.bytestring ]),
3181
+ ...typeIsOneOf(getType(scope, tmpName), [ TYPES.array, TYPES.string, TYPES.bytestring, TYPES.__porffor_generator ]),
3165
3182
  // typed array
3166
3183
  ...getType(scope, tmpName),
3167
3184
  ...number(TYPES.uint8array, Valtype.i32),
@@ -4099,7 +4116,7 @@ const generateForOf = (scope, decl) => {
4099
4116
 
4100
4117
  // check tmp is iterable
4101
4118
  // array or string or bytestring
4102
- ...typeIsOneOf(iterType, [ TYPES.array, TYPES.set, TYPES.string, TYPES.bytestring ]),
4119
+ ...typeIsOneOf(iterType, [ TYPES.array, TYPES.set, TYPES.string, TYPES.bytestring, TYPES.__porffor_generator ]),
4103
4120
  // typed array
4104
4121
  ...iterType,
4105
4122
  ...number(TYPES.uint8array, Valtype.i32),
@@ -4439,6 +4456,8 @@ const generateForOf = (scope, decl) => {
4439
4456
  ]
4440
4457
  }),
4441
4458
 
4459
+ [TYPES.__porffor_generator]: () => [],
4460
+
4442
4461
  // note: should be impossible to reach?
4443
4462
  default: internalThrow(scope, 'TypeError', `Tried for..of on non-iterable type`)
4444
4463
  }, Blocktype.void));
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.47.8",
4
+ "version": "0.48.1",
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.47.8';
3
+ globalThis.version = '0.48.1';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {