porffor 0.16.0-60619b22e → 0.16.0-61ae4fd8d

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.
@@ -0,0 +1,10 @@
1
+ // todo: support non-bytestring properly
2
+ export const String = (value: any): bytestring => {
3
+ if (Porffor.rawType(value) == Porffor.TYPES.symbol) return __Symbol_prototype_toString(value);
4
+ return __ecma262_ToString(value);
5
+ };
6
+
7
+ // todo: support constructor/string objects properly
8
+ export const String$constructor = (value: any): bytestring => {
9
+ return __ecma262_ToString(value);
10
+ };
@@ -1933,15 +1933,15 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
1933
1933
  }
1934
1934
 
1935
1935
  if (valtypeBinary !== Valtype.i32 &&
1936
- (builtinFuncs[name] && builtinFuncs[name].params[i * (typedParams ? 2 : 1)] === Valtype.i32)
1936
+ (func && func.params[i * (typedParams ? 2 : 1)] === Valtype.i32)
1937
1937
  ) {
1938
1938
  out.push(Opcodes.i32_to);
1939
1939
  }
1940
1940
 
1941
1941
  if (valtypeBinary === Valtype.i32 &&
1942
- (builtinFuncs[name] && builtinFuncs[name].params[i * (typedParams ? 2 : 1)] === Valtype.f64)
1942
+ (func && func.params[i * (typedParams ? 2 : 1)] === Valtype.f64)
1943
1943
  ) {
1944
- out.push(Opcodes.f64_convert_i32_s);
1944
+ out.push([ Opcodes.f64_convert_i32_s ]);
1945
1945
  }
1946
1946
 
1947
1947
  if (typedParams) out = out.concat(getNodeType(scope, arg));
@@ -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
 
@@ -2092,6 +2092,24 @@ export const BuiltinFuncs = function() {
2092
2092
  locals: [],
2093
2093
  localNames: ["_this","_this#type"],
2094
2094
  };
2095
+ this.String = {
2096
+ wasm: (scope, {builtin,}) => [[32,0],[32,1],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,24,64],[97],[4,64],[32,0],[32,1],[16, builtin('__Symbol_prototype_toString')],[26],[15],[11],[32,0],[32,1],[16, builtin('__ecma262_ToString')],[15]],
2097
+ params: [124,127],
2098
+ typedParams: true,
2099
+ returns: [124],
2100
+ returnType: 18,
2101
+ locals: [127],
2102
+ localNames: ["value","value#type","#last_type"],
2103
+ };
2104
+ this.String$constructor = {
2105
+ wasm: (scope, {builtin,}) => [[32,0],[32,1],[16, builtin('__ecma262_ToString')],[15]],
2106
+ params: [124,127],
2107
+ typedParams: true,
2108
+ returns: [124],
2109
+ returnType: 18,
2110
+ locals: [],
2111
+ localNames: ["value","value#type"],
2112
+ };
2095
2113
  this.__Porffor_symbol_descStore = {
2096
2114
  wasm: (scope, {allocPage,builtin,}) => [...number(allocPage(scope, 'bytestring: __Porffor_symbol_descStore/ptr', 'i8') * pageSize, 124),[33,4],[32,0],[252,3],[4,64],[32,4],[252,2],[40,0,0],[183],[33,5],[32,4],[252,2],[32,5],[68,0,0,0,0,0,0,240,63],[160],[252,2],[54,0,0],[32,4],[65,18],[32,5],[65,0],[32,2],[32,3],[16, builtin('__Porffor_set_write')],[26],[32,5],[65,0],[15],[5],[32,4],[65,18],[32,2],[32,3],[16, builtin('__Porffor_set_read')],[34,6],[15],[11],[68,0,0,0,0,0,0,0,0],[65,3],[15]],
2097
2115
  params: [124,127,124,127],
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-60619b22e",
4
+ "version": "0.16.0-61ae4fd8d",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},