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.
@@ -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.16.0`, false, '__navigator_userAgent');
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) {
@@ -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
- ...argWasm,
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
- const name = params[i].name;
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
- funcIndex[name] = func.index;
3700
- funcs.push(func);
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
- const wasm = generate(func, body);
3703
- func.wasm = wasm;
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
@@ -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.16.0-fa3914030",
4
+ "version": "0.17.0-9c7bd8098",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},