porffor 0.48.0 → 0.48.2
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.
- package/compiler/builtins_precompiled.js +56 -56
- package/compiler/codegen.js +23 -4
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -1608,6 +1608,10 @@ const getNodeType = (scope, node) => {
|
|
1608
1608
|
}
|
1609
1609
|
}
|
1610
1610
|
|
1611
|
+
if (node.type === 'SequenceExpression') {
|
1612
|
+
return getNodeType(scope, node.expressions.at(-1));
|
1613
|
+
}
|
1614
|
+
|
1611
1615
|
return getLastType(scope);
|
1612
1616
|
})();
|
1613
1617
|
|
@@ -2961,6 +2965,19 @@ const setLocalWithType = (scope, name, isGlobal, decl, tee = false, overrideType
|
|
2961
2965
|
return out;
|
2962
2966
|
};
|
2963
2967
|
|
2968
|
+
const setDefaultFuncName = (decl, name) => {
|
2969
|
+
if (decl.id) return;
|
2970
|
+
|
2971
|
+
if (decl.type === 'ClassExpression') {
|
2972
|
+
// check if it has a name definition
|
2973
|
+
for (const x of decl.body.body) {
|
2974
|
+
if (x.key.name === 'name') return;
|
2975
|
+
}
|
2976
|
+
}
|
2977
|
+
|
2978
|
+
decl.id = { name };
|
2979
|
+
};
|
2980
|
+
|
2964
2981
|
const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
2965
2982
|
// statically analyzed ffi dlopen hack to let 2c handle it
|
2966
2983
|
if (init && init.type === 'CallExpression' && init.callee.name === '__Porffor_dlopen') {
|
@@ -3029,7 +3046,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3029
3046
|
if (init && isFuncType(init.type)) {
|
3030
3047
|
// hack for let a = function () { ... }
|
3031
3048
|
if (!init.id) {
|
3032
|
-
init
|
3049
|
+
setDefaultFuncName(init, name);
|
3033
3050
|
generateFunc(scope, init, true);
|
3034
3051
|
return out;
|
3035
3052
|
}
|
@@ -3037,7 +3054,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3037
3054
|
|
3038
3055
|
if (defaultValue && isFuncType(defaultValue.type)) {
|
3039
3056
|
// set id as name, but do not use it as it is only default value
|
3040
|
-
|
3057
|
+
setDefaultFuncName(defaultValue, name);
|
3041
3058
|
}
|
3042
3059
|
|
3043
3060
|
if (topLevel && Object.hasOwn(builtinVars, name)) {
|
@@ -3165,7 +3182,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3165
3182
|
out = out.concat([
|
3166
3183
|
// check tmp is iterable
|
3167
3184
|
// array or string or bytestring
|
3168
|
-
...typeIsOneOf(getType(scope, tmpName), [ TYPES.array, TYPES.string, TYPES.bytestring ]),
|
3185
|
+
...typeIsOneOf(getType(scope, tmpName), [ TYPES.array, TYPES.string, TYPES.bytestring, TYPES.__porffor_generator ]),
|
3169
3186
|
// typed array
|
3170
3187
|
...getType(scope, tmpName),
|
3171
3188
|
...number(TYPES.uint8array, Valtype.i32),
|
@@ -4103,7 +4120,7 @@ const generateForOf = (scope, decl) => {
|
|
4103
4120
|
|
4104
4121
|
// check tmp is iterable
|
4105
4122
|
// array or string or bytestring
|
4106
|
-
...typeIsOneOf(iterType, [ TYPES.array, TYPES.set, TYPES.string, TYPES.bytestring ]),
|
4123
|
+
...typeIsOneOf(iterType, [ TYPES.array, TYPES.set, TYPES.string, TYPES.bytestring, TYPES.__porffor_generator ]),
|
4107
4124
|
// typed array
|
4108
4125
|
...iterType,
|
4109
4126
|
...number(TYPES.uint8array, Valtype.i32),
|
@@ -4443,6 +4460,8 @@ const generateForOf = (scope, decl) => {
|
|
4443
4460
|
]
|
4444
4461
|
}),
|
4445
4462
|
|
4463
|
+
[TYPES.__porffor_generator]: () => [],
|
4464
|
+
|
4446
4465
|
// note: should be impossible to reach?
|
4447
4466
|
default: internalThrow(scope, 'TypeError', `Tried for..of on non-iterable type`)
|
4448
4467
|
}, Blocktype.void));
|
package/package.json
CHANGED