porffor 0.16.0-fa3914030 → 0.17.0-9c7bd8098
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.js +1 -1
- package/compiler/codegen.js +35 -7
- package/package.json +1 -1
package/compiler/builtins.js
CHANGED
@@ -150,7 +150,7 @@ export const BuiltinVars = function() {
|
|
150
150
|
this.Math = number(1);
|
151
151
|
|
152
152
|
// wintercg(tm)
|
153
|
-
this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor/0.
|
153
|
+
this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor/0.17.0`, false, '__navigator_userAgent');
|
154
154
|
this.__navigator_userAgent.type = Prefs.bytestring ? TYPES.bytestring : TYPES.string;
|
155
155
|
|
156
156
|
for (const x in TYPES) {
|
package/compiler/codegen.js
CHANGED
@@ -1826,7 +1826,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
1826
1826
|
if (indirectMode === 'strict') {
|
1827
1827
|
return typeSwitch(scope, getNodeType(scope, decl.callee), {
|
1828
1828
|
[TYPES.function]: [
|
1829
|
-
...
|
1829
|
+
...out,
|
1830
1830
|
[ global ? Opcodes.global_get : Opcodes.local_get, local.idx ],
|
1831
1831
|
Opcodes.i32_to_u,
|
1832
1832
|
[ Opcodes.call_indirect, args.length, 0 ],
|
@@ -3665,6 +3665,9 @@ const generateFunc = (scope, decl) => {
|
|
3665
3665
|
index: currentFuncIndex++
|
3666
3666
|
};
|
3667
3667
|
|
3668
|
+
funcIndex[name] = func.index;
|
3669
|
+
funcs.push(func);
|
3670
|
+
|
3668
3671
|
if (typedInput && decl.returnType) {
|
3669
3672
|
const { type } = extractTypeAnnotation(decl.returnType);
|
3670
3673
|
// if (type != null && !Prefs.indirectCalls) {
|
@@ -3674,12 +3677,26 @@ const generateFunc = (scope, decl) => {
|
|
3674
3677
|
}
|
3675
3678
|
}
|
3676
3679
|
|
3680
|
+
const defaultValues = {};
|
3677
3681
|
for (let i = 0; i < params.length; i++) {
|
3678
|
-
|
3682
|
+
let name;
|
3683
|
+
const x = params[i];
|
3684
|
+
switch (x.type) {
|
3685
|
+
case 'Identifier': {
|
3686
|
+
name = x.name;
|
3687
|
+
break;
|
3688
|
+
}
|
3689
|
+
|
3690
|
+
case 'AssignmentPattern': {
|
3691
|
+
name = x.left.name;
|
3692
|
+
defaultValues[name] = x.right;
|
3693
|
+
break;
|
3694
|
+
}
|
3695
|
+
}
|
3696
|
+
|
3679
3697
|
// if (name == null) return todo('non-identifier args are not supported');
|
3680
3698
|
|
3681
3699
|
allocVar(func, name, false);
|
3682
|
-
|
3683
3700
|
if (typedInput && params[i].typeAnnotation) {
|
3684
3701
|
addVarMetadata(func, name, false, extractTypeAnnotation(params[i]));
|
3685
3702
|
}
|
@@ -3696,11 +3713,22 @@ const generateFunc = (scope, decl) => {
|
|
3696
3713
|
};
|
3697
3714
|
}
|
3698
3715
|
|
3699
|
-
|
3700
|
-
|
3716
|
+
const prelude = [];
|
3717
|
+
for (const x in defaultValues) {
|
3718
|
+
prelude.push(
|
3719
|
+
...getType(func, x),
|
3720
|
+
...number(TYPES.undefined, Valtype.i32),
|
3721
|
+
[ Opcodes.i32_eq ],
|
3722
|
+
[ Opcodes.if, Blocktype.void ],
|
3723
|
+
...generate(func, defaultValues[x], false, x),
|
3724
|
+
[ Opcodes.local_set, func.locals[x].idx ],
|
3701
3725
|
|
3702
|
-
|
3703
|
-
|
3726
|
+
...setType(func, x, getNodeType(scope, defaultValues[x])),
|
3727
|
+
[ Opcodes.end ]
|
3728
|
+
);
|
3729
|
+
}
|
3730
|
+
|
3731
|
+
const wasm = func.wasm = prelude.concat(generate(func, body));
|
3704
3732
|
|
3705
3733
|
if (name === 'main') func.gotLastType = true;
|
3706
3734
|
|
package/package.json
CHANGED