porffor 0.28.5 → 0.28.6

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/2c.js CHANGED
@@ -335,10 +335,15 @@ export default ({ funcs, globals, tags, data, exceptions, pages }) => {
335
335
  // this just does local.get via the variable name
336
336
  // nice but does not get the value at this moment
337
337
  // so breaks some wasm principles :(
338
- vals.push(`${invLocals[i[1]]}`);
338
+ vals.push(`${invLocals[idx]}`);
339
339
  } else {
340
340
  const id = localTmpId++;
341
- line(`const ${invLocalTypes[idx]} _get${id} = ${invLocals[idx]}`);
341
+
342
+ const line2 = out.indexOf('{\n') + 2;
343
+ out = out.slice(0, line2) + ` ${invLocalTypes[idx]} _get${id};\n` + out.slice(line2);
344
+ // line(`const ${invLocalTypes[idx]} _get${id} = ${invLocals[idx]}`);
345
+
346
+ line(`_get${id} = ${invLocals[idx]}`);
342
347
  vals.push(`_get${id}`);
343
348
  }
344
349
  };
@@ -823,7 +828,7 @@ _time_out = _time.tv_nsec / 1000000. + _time.tv_sec * 1000.;`);
823
828
  lastCond = false;
824
829
  }
825
830
 
826
- if (vals.length === 1 && returns) {
831
+ if (vals.length === 1 && f.returns.length === 1) {
827
832
  line(`return ${vals.pop()}`);
828
833
  }
829
834
 
@@ -1,10 +1,32 @@
1
1
  import type {} from './porffor.d.ts';
2
2
 
3
- export const Number = function (argument: any): any {
4
- // todo: actually do prim objects
5
- new.target; // trick compiler into allowing as constructor
3
+ // 21.1.1.1 Number (value)
4
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number-constructor-number-value
5
+ export const Number = function (value: any): any {
6
+ let n: number = 0;
7
+
8
+ // 1. If value is present, then
9
+ // todo: handle undefined (NaN) and not present (0) args differently
10
+ if (Porffor.rawType(value) != Porffor.TYPES.undefined) {
11
+ // a. Let prim be ? ToNumeric(value).
12
+ // b. If prim is a BigInt, let n be 𝔽(ℝ(prim)).
13
+ // todo: handle when bigints exist
14
+ // c. Otherwise, let n be prim.
15
+ n = ecma262.ToNumeric(value);
16
+ }
17
+
18
+ // 2. Else,
19
+ // a. Let n be +0𝔽.
20
+ // n is already 0 (from init value)
6
21
 
7
- return ecma262.ToNumeric(argument);
22
+ // 3. If NewTarget is undefined, return n.
23
+ if (!new.target) return n;
24
+
25
+ // 4. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Number.prototype%", « [[NumberData]] »).
26
+ // 5. Set O.[[NumberData]] to n.
27
+ // 6. Return O.
28
+ // todo: actual prim objects
29
+ return n;
8
30
  };
9
31
 
10
32
  // radix: number|any for rawType check
@@ -60,6 +60,8 @@ export const __ecma262_StringToNumber = (str: unknown): number => {
60
60
  // trim whitespace
61
61
  str = str.trim();
62
62
 
63
+ if (str.length == 0) return 0;
64
+
63
65
  // check 0x, 0o, 0b prefixes
64
66
  const first: i32 = str.charCodeAt(0);
65
67
  const second: i32 = str.charCodeAt(1);
@@ -1678,10 +1678,10 @@ export const BuiltinFuncs = function() {
1678
1678
  locals: [124,127,127], localNames: ["y","y#type","x","x#type","ratio","ratio#type","#last_type"],
1679
1679
  };
1680
1680
  this.Number = {
1681
- wasm: (scope, {builtin}) => [[32,4],[32,5],[16, builtin('__ecma262_ToNumeric')],[34,6],[15]],
1681
+ wasm: (scope, {builtin}) => [[68,0,0,0,0,0,0,0,0],[33,6],[32,5],[184],[68,0,0,0,0,0,0,96,64],[98],[4,64],[32,4],[32,5],[16, builtin('__ecma262_ToNumeric')],[26],[33,6],[11],[32,0],[33,8],[32,1],[33,9],[2,124],[32,9],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,8],[252,3],[40,1,0],[69],[184],[12,1],[11],[32,9],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,8],[252,3],[40,1,0],[69],[184],[12,1],[11],[32,8],[68,0,0,0,0,0,0,0,0],[97],[184],[11,"TYPESWITCH_end"],[252,3],[4,64],[32,6],[65,1],[15],[11],[32,6],[65,1],[15]],
1682
1682
  params: [124,127,124,127,124,127], typedParams: 1,
1683
1683
  returns: [124,127], typedReturns: 1,
1684
- locals: [127], localNames: ["#newtarget","#newtarget#type","#this","#this#type","argument","argument#type","#last_type"],
1684
+ locals: [124,127,124,127], localNames: ["#newtarget","#newtarget#type","#this","#this#type","value","value#type","n","#last_type","#logicinner_tmp","#typeswitch_tmp1"],
1685
1685
  constr: 1,
1686
1686
  };
1687
1687
  this.__Number_prototype_toString = {
@@ -2649,7 +2649,7 @@ export const BuiltinFuncs = function() {
2649
2649
  locals: [124,124,124,124,127,127,127,127,127,127], localNames: ["str","str#type","i","i#type","n","dec","len","chr","__proto_length_cache","__proto_pointer_cache","__charCodeAt_tmp","#last_type","#typeswitch_tmp1","logictmpi"],
2650
2650
  };
2651
2651
  this.__ecma262_StringToNumber = {
2652
- wasm: (scope, {builtin,internalThrow}) => [[32,0],[33,2],[32,1],[34,3],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,2],[252,2],[32,3],[16, builtin('__String_prototype_trim')],[33,4],[183],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,2],[252,2],[32,3],[16, builtin('__ByteString_prototype_trim')],[33,4],[183],[12,1],[11],...internalThrow(scope, 'TypeError', `'trim' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[34,0],[32,4],[33,1],[26],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[65,0],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[65,0],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[33,6],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[65,1],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[65,1],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[33,10],[32,6],[68,0,0,0,0,0,0,72,64],[97],[4,64],[32,10],[68,0,0,0,0,0,0,94,64],[97],[34,11],[69],[4,127],[32,10],[68,0,0,0,0,0,0,86,64],[97],[65,2],[33,4],[5],[32,11],[65,2],[33,4],[11],[4,64],[32,0],[32,1],[68,0,0,0,0,0,0,48,64],[65,1],[68,0,0,0,0,0,0,0,64],[65,1],[16, builtin('__Porffor_stn_int')],[34,4],[15],[11],[32,10],[68,0,0,0,0,0,192,91,64],[97],[34,11],[69],[4,127],[32,10],[68,0,0,0,0,0,192,83,64],[97],[65,2],[33,4],[5],[32,11],[65,2],[33,4],[11],[4,64],[32,0],[32,1],[68,0,0,0,0,0,0,32,64],[65,1],[68,0,0,0,0,0,0,0,64],[65,1],[16, builtin('__Porffor_stn_int')],[34,4],[15],[11],[32,10],[68,0,0,0,0,0,128,88,64],[97],[34,11],[69],[4,127],[32,10],[68,0,0,0,0,0,128,80,64],[97],[65,2],[33,4],[5],[32,11],[65,2],[33,4],[11],[4,64],[32,0],[32,1],[68,0,0,0,0,0,0,0,64],[65,1],[68,0,0,0,0,0,0,0,64],[65,1],[16, builtin('__Porffor_stn_int')],[34,4],[15],[11],[11],[68,0,0,0,0,0,0,0,0],[33,12],[68,0,0,0,0,0,0,0,0],[33,13],[32,6],[68,0,0,0,0,0,128,69,64],[97],[4,64],[68,0,0,0,0,0,0,240,63],[33,12],[11],[32,6],[68,0,0,0,0,0,128,70,64],[97],[4,64],[68,0,0,0,0,0,0,240,63],[33,13],[68,0,0,0,0,0,0,240,63],[33,12],[11],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,64,82,64],[97],[4,64],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[68,0,0,0,0,0,0,240,63],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[68,0,0,0,0,0,0,240,63],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,128,91,64],[97],[34,11],[4,127],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[68,0,0,0,0,0,0,0,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[68,0,0,0,0,0,0,0,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,128,89,64],[97],[65,2],[33,4],[5],[32,11],[65,2],[33,4],[11],[34,11],[33,14],[32,4],[33,5],[2,127],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,14],[40,1,0],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,14],[40,1,0],[12,1],[11],[32,14],[11,"TYPESWITCH_end"],[4,127],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[68,0,0,0,0,0,0,8,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[68,0,0,0,0,0,0,8,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,64,90,64],[97],[65,2],[33,4],[5],[32,11],[32,4],[33,4],[11],[34,11],[33,14],[32,4],[33,5],[2,127],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,14],[40,1,0],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,14],[40,1,0],[12,1],[11],[32,14],[11,"TYPESWITCH_end"],[4,127],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[68,0,0,0,0,0,0,16,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[68,0,0,0,0,0,0,16,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,128,91,64],[97],[65,2],[33,4],[5],[32,11],[32,4],[33,4],[11],[34,11],[33,14],[32,4],[33,5],[2,127],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,14],[40,1,0],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,14],[40,1,0],[12,1],[11],[32,14],[11,"TYPESWITCH_end"],[4,127],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[68,0,0,0,0,0,0,20,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[68,0,0,0,0,0,0,20,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,64,90,64],[97],[65,2],[33,4],[5],[32,11],[32,4],[33,4],[11],[34,11],[33,14],[32,4],[33,5],[2,127],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,14],[40,1,0],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,14],[40,1,0],[12,1],[11],[32,14],[11,"TYPESWITCH_end"],[4,127],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[68,0,0,0,0,0,0,24,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[68,0,0,0,0,0,0,24,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,0,93,64],[97],[65,2],[33,4],[5],[32,11],[32,4],[33,4],[11],[34,11],[33,14],[32,4],[33,5],[2,127],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,14],[40,1,0],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,14],[40,1,0],[12,1],[11],[32,14],[11,"TYPESWITCH_end"],[4,127],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[68,0,0,0,0,0,0,28,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[68,0,0,0,0,0,0,28,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,64,94,64],[97],[65,2],[33,4],[5],[32,11],[32,4],[33,4],[11],[4,64],[68,0,0,0,0,0,0,240,127],[33,15],[32,13],[252,3],[4,124],[32,15],[154],[65,1],[33,4],[5],[32,15],[65,1],[33,4],[11],[32,4],[15],[11],[68,0,0,0,0,0,0,248,127],[65,1],[15],[11],[32,0],[32,1],[32,12],[65,1],[16, builtin('__Porffor_stn_float')],[26],[33,15],[32,13],[252,3],[4,64],[32,15],[154],[65,1],[15],[11],[32,15],[65,1],[15]],
2652
+ wasm: (scope, {builtin,internalThrow}) => [[32,0],[33,2],[32,1],[34,3],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,2],[252,2],[32,3],[16, builtin('__String_prototype_trim')],[33,4],[183],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,2],[252,2],[32,3],[16, builtin('__ByteString_prototype_trim')],[33,4],[183],[12,1],[11],...internalThrow(scope, 'TypeError', `'trim' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[34,0],[32,4],[33,1],[26],[32,0],[252,3],[40,1,0],[184],[68,0,0,0,0,0,0,0,0],[97],[4,64],[68,0,0,0,0,0,0,0,0],[65,1],[15],[11],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[65,0],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[65,0],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[33,6],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[65,1],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[65,1],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[33,10],[32,6],[68,0,0,0,0,0,0,72,64],[97],[4,64],[32,10],[68,0,0,0,0,0,0,94,64],[97],[34,11],[69],[4,127],[32,10],[68,0,0,0,0,0,0,86,64],[97],[65,2],[33,4],[5],[32,11],[65,2],[33,4],[11],[4,64],[32,0],[32,1],[68,0,0,0,0,0,0,48,64],[65,1],[68,0,0,0,0,0,0,0,64],[65,1],[16, builtin('__Porffor_stn_int')],[34,4],[15],[11],[32,10],[68,0,0,0,0,0,192,91,64],[97],[34,11],[69],[4,127],[32,10],[68,0,0,0,0,0,192,83,64],[97],[65,2],[33,4],[5],[32,11],[65,2],[33,4],[11],[4,64],[32,0],[32,1],[68,0,0,0,0,0,0,32,64],[65,1],[68,0,0,0,0,0,0,0,64],[65,1],[16, builtin('__Porffor_stn_int')],[34,4],[15],[11],[32,10],[68,0,0,0,0,0,128,88,64],[97],[34,11],[69],[4,127],[32,10],[68,0,0,0,0,0,128,80,64],[97],[65,2],[33,4],[5],[32,11],[65,2],[33,4],[11],[4,64],[32,0],[32,1],[68,0,0,0,0,0,0,0,64],[65,1],[68,0,0,0,0,0,0,0,64],[65,1],[16, builtin('__Porffor_stn_int')],[34,4],[15],[11],[11],[68,0,0,0,0,0,0,0,0],[33,12],[68,0,0,0,0,0,0,0,0],[33,13],[32,6],[68,0,0,0,0,0,128,69,64],[97],[4,64],[68,0,0,0,0,0,0,240,63],[33,12],[11],[32,6],[68,0,0,0,0,0,128,70,64],[97],[4,64],[68,0,0,0,0,0,0,240,63],[33,13],[68,0,0,0,0,0,0,240,63],[33,12],[11],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,64,82,64],[97],[4,64],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[68,0,0,0,0,0,0,240,63],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[68,0,0,0,0,0,0,240,63],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,128,91,64],[97],[34,11],[4,127],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[68,0,0,0,0,0,0,0,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[68,0,0,0,0,0,0,0,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,128,89,64],[97],[65,2],[33,4],[5],[32,11],[65,2],[33,4],[11],[34,11],[33,14],[32,4],[33,5],[2,127],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,14],[40,1,0],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,14],[40,1,0],[12,1],[11],[32,14],[11,"TYPESWITCH_end"],[4,127],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[68,0,0,0,0,0,0,8,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[68,0,0,0,0,0,0,8,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,64,90,64],[97],[65,2],[33,4],[5],[32,11],[32,4],[33,4],[11],[34,11],[33,14],[32,4],[33,5],[2,127],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,14],[40,1,0],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,14],[40,1,0],[12,1],[11],[32,14],[11,"TYPESWITCH_end"],[4,127],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[68,0,0,0,0,0,0,16,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[68,0,0,0,0,0,0,16,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,128,91,64],[97],[65,2],[33,4],[5],[32,11],[32,4],[33,4],[11],[34,11],[33,14],[32,4],[33,5],[2,127],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,14],[40,1,0],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,14],[40,1,0],[12,1],[11],[32,14],[11,"TYPESWITCH_end"],[4,127],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[68,0,0,0,0,0,0,20,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[68,0,0,0,0,0,0,20,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,64,90,64],[97],[65,2],[33,4],[5],[32,11],[32,4],[33,4],[11],[34,11],[33,14],[32,4],[33,5],[2,127],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,14],[40,1,0],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,14],[40,1,0],[12,1],[11],[32,14],[11,"TYPESWITCH_end"],[4,127],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[68,0,0,0,0,0,0,24,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[68,0,0,0,0,0,0,24,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,0,93,64],[97],[65,2],[33,4],[5],[32,11],[32,4],[33,4],[11],[34,11],[33,14],[32,4],[33,5],[2,127],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[32,14],[40,1,0],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,14],[40,1,0],[12,1],[11],[32,14],[11,"TYPESWITCH_end"],[4,127],[32,0],[252,3],[34,8],[40,1,0],[33,7],[32,1],[33,5],[2,124],[32,5],[65,195,0],[70],[4,64,"TYPESWITCH|String"],[2,124],[32,12],[68,0,0,0,0,0,0,28,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[65,2],[108],[32,8],[106],[47,0,4],[184],[65,1],[33,4],[11],[12,1],[11],[32,5],[65,195,1],[70],[4,64,"TYPESWITCH|ByteString"],[2,124],[32,12],[68,0,0,0,0,0,0,28,64],[160],[252,2],[34,9],[32,7],[78],[4,64],[68,0,0,0,0,0,0,248,127],[12,1],[11],[32,9],[32,8],[106],[45,0,4],[184],[65,1],[33,4],[11],[12,1],[11],...internalThrow(scope, 'TypeError', `'charCodeAt' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[68,0,0,0,0,0,64,94,64],[97],[65,2],[33,4],[5],[32,11],[32,4],[33,4],[11],[4,64],[68,0,0,0,0,0,0,240,127],[33,15],[32,13],[252,3],[4,124],[32,15],[154],[65,1],[33,4],[5],[32,15],[65,1],[33,4],[11],[32,4],[15],[11],[68,0,0,0,0,0,0,248,127],[65,1],[15],[11],[32,0],[32,1],[32,12],[65,1],[16, builtin('__Porffor_stn_float')],[26],[33,15],[32,13],[252,3],[4,64],[32,15],[154],[65,1],[15],[11],[32,15],[65,1],[15]],
2653
2653
  params: [124,127], typedParams: 1,
2654
2654
  returns: [124,127], typedReturns: 1,
2655
2655
  locals: [124,127,127,127,124,127,127,127,124,127,124,124,127,124], localNames: ["str","str#type","#proto_target","#proto_target#type","#last_type","#typeswitch_tmp1","first","__proto_length_cache","__proto_pointer_cache","__charCodeAt_tmp","second","logictmpi","i","negative","#logicinner_tmp_int","n"],
@@ -1848,12 +1848,33 @@ const createThisArg = (scope, decl, knownThis = undefined) => {
1848
1848
  ...number(TYPES.object, Valtype.i32)
1849
1849
  ];
1850
1850
  } else {
1851
+ const name = mapName(decl.callee?.name);
1852
+ if (name && name.startsWith('__') && name.includes('_prototype_')) {
1853
+ // todo: this should just be same as decl._new
1854
+ // but we do not support prototype, constructor, etc yet
1855
+ // so do `this` as `new Type()` instead
1856
+ const node = {
1857
+ type: 'NewExpression',
1858
+ callee: {
1859
+ type: 'Identifier',
1860
+ name: name.slice(2, name.indexOf('_', 2))
1861
+ },
1862
+ arguments: [],
1863
+ _new: true
1864
+ };
1865
+
1866
+ return [
1867
+ ...generateCall(scope, node),
1868
+ ...getNodeType(scope, node)
1869
+ ];
1870
+ }
1871
+
1851
1872
  return [
1852
1873
  ...generate(scope, { type: 'Identifier', name: 'globalThis' }),
1853
1874
  ...getType(scope, 'globalThis')
1854
1875
  ];
1855
1876
  }
1856
- }
1877
+ };
1857
1878
 
1858
1879
  const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
1859
1880
  let name = mapName(decl.callee.name);
@@ -2454,13 +2475,19 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2454
2475
  return internalThrow(scope, 'TypeError', `${unhackName(name)} is not a constructor`, true);
2455
2476
  }
2456
2477
 
2478
+ let args = [...decl.arguments];
2479
+ const internalProtoFunc = func && func.internal && func.name.includes('_prototype_');
2480
+ if (!globalThis.precompile && internalProtoFunc && !decl._protoInternalCall) {
2481
+ // just function called, not as prototype, add this to start
2482
+ args.unshift(decl._thisWasm ?? createThisArg(scope, decl));
2483
+ }
2484
+
2457
2485
  if (func && func.constr) {
2458
2486
  out.push(...(decl._newTargetWasm ?? createNewTarget(scope, decl, idx - importedFuncs.length)));
2459
2487
  out.push(...(decl._thisWasm ?? createThisArg(scope, decl)));
2460
2488
  paramOffset += 4;
2461
2489
  }
2462
2490
 
2463
- let args = [...decl.arguments];
2464
2491
  if (func && !func.hasRestArgument && args.length < paramCount) {
2465
2492
  // too little args, push undefineds
2466
2493
  args = args.concat(new Array(paramCount - args.length).fill(DEFAULT_VALUE()));
@@ -2488,6 +2515,12 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2488
2515
 
2489
2516
  for (let i = 0; i < args.length; i++) {
2490
2517
  const arg = args[i];
2518
+ if (Array.isArray(arg)) {
2519
+ // if wasm, just append it
2520
+ out = out.concat(arg);
2521
+ continue;
2522
+ }
2523
+
2491
2524
  out = out.concat(generate(scope, arg));
2492
2525
 
2493
2526
  // todo: this should be used instead of the too many args thing above (by removing that)
@@ -2929,7 +2962,8 @@ const generateVar = (scope, decl) => {
2929
2962
  object: { type: 'Identifier', name: tmpName, },
2930
2963
  property: { type: 'Identifier', name: 'length', }
2931
2964
  }
2932
- ]
2965
+ ],
2966
+ _protoInternalCall: true
2933
2967
  }
2934
2968
  });
2935
2969
  }
@@ -5539,7 +5573,7 @@ const generateFunc = (scope, decl) => {
5539
5573
 
5540
5574
  if (lastInst[0] === Opcodes.end || lastInst[0] === Opcodes.local_set || lastInst[0] === Opcodes.global_set) {
5541
5575
  if (lastInst[0] === Opcodes.local_set && lastInst[1] === func.locals['#last_type'].idx) {
5542
- func.wasm.splice(main.wasm.length - 1, 1);
5576
+ func.wasm.splice(func.wasm.length - 1, 1);
5543
5577
  } else {
5544
5578
  func.returns = [];
5545
5579
  }
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.28.5+4f843e06e",
4
+ "version": "0.28.6+56105b926",
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.28.5+4f843e06e';
3
+ globalThis.version = '0.28.6+56105b926';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {