porffor 0.18.32 → 0.18.33

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.
@@ -1042,6 +1042,75 @@ export const __ByteString_prototype_trim = (_this: bytestring) => {
1042
1042
  };
1043
1043
 
1044
1044
 
1045
+ export const __String_prototype_concat = (_this: string, ...vals: any[]) => {
1046
+ // todo/perf: rewrite to use memory.copy?
1047
+ let out: string = Porffor.allocate();
1048
+ out += _this;
1049
+
1050
+ const valsLen: i32 = vals.length;
1051
+ for (let i: i32 = 0; i < valsLen; i++) {
1052
+ let x: any;
1053
+ Porffor.wasm`
1054
+ local.get ${vals}
1055
+ local.get ${i}
1056
+ i32.const 9
1057
+ i32.mul
1058
+ i32.add
1059
+ f64.load 0 4
1060
+
1061
+ local.get ${vals}
1062
+ local.get ${i}
1063
+ i32.const 9
1064
+ i32.mul
1065
+ i32.add
1066
+ i32.load8_u 0 12
1067
+
1068
+ call __ecma262_ToString
1069
+ local.set ${x+1}
1070
+ i32.trunc_sat_f64_u
1071
+ local.set ${x}`;
1072
+
1073
+ out += x;
1074
+ }
1075
+
1076
+ return out;
1077
+ };
1078
+
1079
+ export const __ByteString_prototype_concat = (_this: bytestring, ...vals: any[]) => {
1080
+ // todo/perf: rewrite to use memory.copy?
1081
+ let out: string = Porffor.allocate();
1082
+ out += _this;
1083
+
1084
+ const valsLen: i32 = vals.length;
1085
+ for (let i: i32 = 0; i < valsLen; i++) {
1086
+ let x: any;
1087
+ Porffor.wasm`
1088
+ local.get ${vals}
1089
+ local.get ${i}
1090
+ i32.const 9
1091
+ i32.mul
1092
+ i32.add
1093
+ f64.load 0 4
1094
+
1095
+ local.get ${vals}
1096
+ local.get ${i}
1097
+ i32.const 9
1098
+ i32.mul
1099
+ i32.add
1100
+ i32.load8_u 0 12
1101
+
1102
+ call __ecma262_ToString
1103
+ local.set ${x+1}
1104
+ i32.trunc_sat_f64_u
1105
+ local.set ${x}`;
1106
+
1107
+ out += x;
1108
+ }
1109
+
1110
+ return out;
1111
+ };
1112
+
1113
+
1045
1114
  // 22.1.3.29 String.prototype.toString ()
1046
1115
  // https://tc39.es/ecma262/#sec-string.prototype.tostring
1047
1116
  export const __String_prototype_toString = (_this: string) => {
@@ -263,7 +263,7 @@ export const BuiltinFuncs = function() {
263
263
 
264
264
 
265
265
  this.__Porffor_print = {
266
- params: [ valtypeBinary, Valtype.i32 ],
266
+ params: [ globalThis.precompile ? Valtype.f64 : valtypeBinary, Valtype.i32 ],
267
267
  typedParams: true,
268
268
  locals: [ Valtype.i32, Valtype.i32 ],
269
269
  returns: [],
@@ -189,7 +189,14 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
189
189
  if (!Array.isArray(inst)) inst = [ inst ];
190
190
  const immediates = asm.slice(1).map(x => {
191
191
  const int = parseInt(x);
192
- if (Number.isNaN(int)) return scope.locals[x]?.idx ?? globals[x].idx;
192
+ if (Number.isNaN(int)) {
193
+ if (builtinFuncs[x]) {
194
+ if (funcIndex[x] == null) includeBuiltin(scope, x);
195
+ return funcIndex[x];
196
+ }
197
+
198
+ return scope.locals[x]?.idx ?? globals[x].idx;
199
+ }
193
200
  return int;
194
201
  });
195
202
 
@@ -4737,7 +4744,7 @@ const internalConstrs = {
4737
4744
 
4738
4745
  // print space
4739
4746
  ...(i !== decl.arguments.length - 1 ? [
4740
- ...number(32),
4747
+ ...number(32, globalThis.precompile ? Valtype.f64 : valtypeBinary),
4741
4748
  [ Opcodes.call, importedFuncs.printChar ]
4742
4749
  ] : [])
4743
4750
  );
@@ -4745,7 +4752,7 @@ const internalConstrs = {
4745
4752
 
4746
4753
  // print newline
4747
4754
  out.push(
4748
- ...number(10),
4755
+ ...number(10, globalThis.precompile ? Valtype.f64 : valtypeBinary),
4749
4756
  [ Opcodes.call, importedFuncs.printChar ]
4750
4757
  );
4751
4758
 
@@ -1662,6 +1662,20 @@ export const BuiltinFuncs = function() {
1662
1662
  returns: [127,127], typedReturns: 1,
1663
1663
  locals: [127], localNames: ["_this","_this#type","#last_type"],
1664
1664
  };
1665
+ this.__String_prototype_concat = {
1666
+ wasm: (scope, {builtin}) => [[16, builtin('__Porffor_allocate')],[33,5],[252,2],[34,4],[32,0],[33,6],[33,9],[65,1],[64,0],[65,128,128,4],[108],[34,10],[32,9],[40,0,0],[34,8],[32,6],[40,0,0],[34,7],[106],[54,1,0],[32,10],[65,4],[106],[32,9],[65,4],[106],[65,252,255,3],[252,10,0,0],[32,10],[65,4],[106],[32,8],[65,2],[108],[106],[32,6],[65,4],[106],[32,7],[65,2],[108],[252,10,0,0],[65,194,0],[33,5],[32,10],[33,4],[32,2],[40,1,0],[33,11],[65,0],[33,12],[3,64],[32,12],[32,11],[72],[4,64],[32,2],[32,12],[65,9],[108],[106],[43,0,4],[32,2],[32,12],[65,9],[108],[106],[45,0,12],[16, builtin('__ecma262_ToString')],[33,14],[252,3],[33,13],[32,4],[32,13],[33,6],[33,9],[65,1],[64,0],[65,128,128,4],[108],[34,10],[32,9],[40,0,0],[34,8],[32,6],[40,0,0],[34,7],[106],[54,1,0],[65,194,0],[65,194,1],[70],[4,64],[32,9],[32,8],[16, builtin('__Porffor_bytestringToString')],[33,9],[11],[32,14],[65,194,1],[70],[4,64],[32,6],[32,7],[16, builtin('__Porffor_bytestringToString')],[33,6],[11],[32,10],[65,4],[106],[32,9],[65,4],[106],[65,252,255,3],[252,10,0,0],[32,10],[65,4],[106],[32,8],[65,2],[108],[106],[32,6],[65,4],[106],[32,7],[65,2],[108],[252,10,0,0],[65,194,0],[33,5],[32,10],[33,4],[32,12],[65,1],[106],[33,12],[12,1],[11],[11],[32,4],[65,194,0],[15]],
1667
+ params: [127,127,127,127], typedParams: 1,
1668
+ returns: [127,127], typedReturns: 1,
1669
+ locals: [127,127,127,127,127,127,127,127,127,127,127], localNames: ["_this","_this#type","vals","vals#type","out","#last_type","concat_right_pointer","concat_right_length","concat_left_length","concat_left_pointer","concat_out_pointer","valsLen","i","x","x#type"],
1670
+ hasRestArgument: 1,
1671
+ };
1672
+ this.__ByteString_prototype_concat = {
1673
+ wasm: (scope, {builtin}) => [[16, builtin('__Porffor_allocate')],[33,5],[252,2],[34,4],[32,0],[33,6],[33,9],[65,1],[64,0],[65,128,128,4],[108],[34,10],[32,9],[40,0,0],[34,8],[32,6],[40,0,0],[34,7],[106],[54,1,0],[65,194,0],[65,194,1],[70],[4,64],[32,9],[32,8],[16, builtin('__Porffor_bytestringToString')],[33,9],[11],[65,194,1],[65,194,1],[70],[4,64],[32,6],[32,7],[16, builtin('__Porffor_bytestringToString')],[33,6],[11],[32,10],[65,4],[106],[32,9],[65,4],[106],[65,252,255,3],[252,10,0,0],[32,10],[65,4],[106],[32,8],[65,2],[108],[106],[32,6],[65,4],[106],[32,7],[65,2],[108],[252,10,0,0],[65,194,0],[33,5],[32,10],[33,4],[32,2],[40,1,0],[33,11],[65,0],[33,12],[3,64],[32,12],[32,11],[72],[4,64],[32,2],[32,12],[65,9],[108],[106],[43,0,4],[32,2],[32,12],[65,9],[108],[106],[45,0,12],[16, builtin('__ecma262_ToString')],[33,14],[252,3],[33,13],[32,4],[32,13],[33,6],[33,9],[65,1],[64,0],[65,128,128,4],[108],[34,10],[32,9],[40,0,0],[34,8],[32,6],[40,0,0],[34,7],[106],[54,1,0],[65,194,0],[65,194,1],[70],[4,64],[32,9],[32,8],[16, builtin('__Porffor_bytestringToString')],[33,9],[11],[32,14],[65,194,1],[70],[4,64],[32,6],[32,7],[16, builtin('__Porffor_bytestringToString')],[33,6],[11],[32,10],[65,4],[106],[32,9],[65,4],[106],[65,252,255,3],[252,10,0,0],[32,10],[65,4],[106],[32,8],[65,2],[108],[106],[32,6],[65,4],[106],[32,7],[65,2],[108],[252,10,0,0],[65,194,0],[33,5],[32,10],[33,4],[32,12],[65,1],[106],[33,12],[12,1],[11],[11],[32,4],[65,194,0],[15]],
1674
+ params: [127,127,127,127], typedParams: 1,
1675
+ returns: [127,127], typedReturns: 1,
1676
+ locals: [127,127,127,127,127,127,127,127,127,127,127], localNames: ["_this","_this#type","vals","vals#type","out","#last_type","concat_right_pointer","concat_right_length","concat_left_length","concat_left_pointer","concat_out_pointer","valsLen","i","x","x#type"],
1677
+ hasRestArgument: 1,
1678
+ };
1665
1679
  this.__String_prototype_toString = {
1666
1680
  wasm: (scope, {}) => [[32,0],[65,194,0],[15]],
1667
1681
  params: [127,127], typedParams: 1,
@@ -3808,7 +3822,7 @@ export const BuiltinFuncs = function() {
3808
3822
  locals: [124], localNames: ["argument","argument#type","number"],
3809
3823
  };
3810
3824
  this.__ecma262_ToString = {
3811
- wasm: (scope, {allocPage,builtin,internalThrow}) => [[16, builtin('__Porffor_allocate')],[33,3],[33,2],[32,0],[32,1],[16, builtin('__Porffor_rawType')],[34,4],[68,0,0,0,0,0,128,80,64],[97],[32,4],[68,0,0,0,0,0,64,104,64],[97],[114],[4,64],[32,0],[32,1],[15],[11],[32,4],[68,0,0,0,0,0,0,24,64],[97],[4,64],...internalThrow(scope, 'TypeError', `Cannot convert a Symbol value to a string`),[11],[32,4],[68,0,0,0,0,0,0,8,64],[97],[4,64],...number(allocPage(scope, 'bytestring: __ecma262_ToString/out', 'i8') * pageSize, 124),[34,2],[65,194,1],[15],[11],[32,4],[68,0,0,0,0,0,0,16,64],[97],[32,0],[68,0,0,0,0,0,0,0,0],[97],[113],[4,64],[32,2],[252,3],[34,5],[65,4],[54,1,0],[32,5],[65,238,0],[58,0,4],[32,5],[65,245,0],[58,0,5],[32,5],[65,236,0],[58,0,6],[32,5],[65,236,0],[58,0,7],[32,5],[184],[34,2],[65,194,1],[15],[11],[32,4],[68,0,0,0,0,0,0,240,63],[97],[4,64],[32,0],[68,0,0,0,0,0,0,240,63],[97],[4,64],[32,2],[252,3],[34,5],[65,4],[54,1,0],[32,5],[65,244,0],[58,0,4],[32,5],[65,242,0],[58,0,5],[32,5],[65,245,0],[58,0,6],[32,5],[65,229,0],[58,0,7],[32,5],[184],[34,2],[65,194,1],[15],[11],[32,2],[252,3],[34,5],[65,5],[54,1,0],[32,5],[65,230,0],[58,0,4],[32,5],[65,225,0],[58,0,5],[32,5],[65,236,0],[58,0,6],[32,5],[65,243,0],[58,0,7],[32,5],[65,229,0],[58,0,8],[32,5],[184],[34,2],[65,194,1],[15],[11],[32,0],[33,6],[32,1],[34,7],[33,8],[2,124],[32,8],[65,0],[70],[4,64,"TYPESWITCH|Number"],[32,6],[32,7],[68,0,0,0,0,0,0,0,0],[65,3],[16, builtin('__Number_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,1],[70],[4,64,"TYPESWITCH|Boolean"],[32,6],[32,7],[16, builtin('__Boolean_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,4],[70],[4,64,"TYPESWITCH|Object"],[32,6],[32,7],[16, builtin('__Object_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,5],[70],[4,64,"TYPESWITCH|Function"],[32,6],[32,7],[16, builtin('__Function_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,6],[70],[4,64,"TYPESWITCH|Symbol"],[32,6],[32,7],[16, builtin('__Symbol_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,18],[70],[4,64,"TYPESWITCH|Date"],[32,6],[32,7],[16, builtin('__Date_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,19],[70],[4,64,"TYPESWITCH|Set"],[32,6],[32,7],[16, builtin('__Set_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,33],[70],[4,64,"TYPESWITCH|WeakSet"],[32,6],[32,7],[16, builtin('__WeakSet_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,194,0],[70],[4,64,"TYPESWITCH|String"],[32,6],[252,2],[32,7],[16, builtin('__String_prototype_toString')],[33,3],[183],[12,1],[11],[32,8],[65,208,0],[70],[4,64,"TYPESWITCH|Array"],[32,6],[32,7],[16, builtin('__Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,215,0],[70],[4,64,"TYPESWITCH|Uint8Array"],[32,6],[32,7],[16, builtin('__Uint8Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,216,0],[70],[4,64,"TYPESWITCH|Int8Array"],[32,6],[32,7],[16, builtin('__Int8Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,217,0],[70],[4,64,"TYPESWITCH|Uint8ClampedArray"],[32,6],[32,7],[16, builtin('__Uint8ClampedArray_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,218,0],[70],[4,64,"TYPESWITCH|Uint16Array"],[32,6],[32,7],[16, builtin('__Uint16Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,219,0],[70],[4,64,"TYPESWITCH|Int16Array"],[32,6],[32,7],[16, builtin('__Int16Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,220,0],[70],[4,64,"TYPESWITCH|Uint32Array"],[32,6],[32,7],[16, builtin('__Uint32Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,221,0],[70],[4,64,"TYPESWITCH|Int32Array"],[32,6],[32,7],[16, builtin('__Int32Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,222,0],[70],[4,64,"TYPESWITCH|Float32Array"],[32,6],[32,7],[16, builtin('__Float32Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,223,0],[70],[4,64,"TYPESWITCH|Float64Array"],[32,6],[32,7],[16, builtin('__Float64Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,194,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,6],[252,2],[32,7],[16, builtin('__ByteString_prototype_toString')],[33,3],[183],[12,1],[11],...internalThrow(scope, 'TypeError', `'toString' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[32,3],[15]],
3825
+ wasm: (scope, {allocPage,builtin,internalThrow}) => [[16, builtin('__Porffor_allocate')],[33,3],[33,2],[32,0],[32,1],[16, builtin('__Porffor_rawType')],[34,4],[68,0,0,0,0,0,128,80,64],[97],[32,4],[68,0,0,0,0,0,64,104,64],[97],[114],[4,64],[32,0],[32,1],[15],[11],[32,4],[68,0,0,0,0,0,0,24,64],[97],[4,64],...internalThrow(scope, 'TypeError', `Cannot convert a Symbol value to a string`),[11],[32,4],[68,0,0,0,0,0,0,8,64],[97],[4,64],...number(allocPage(scope, 'bytestring: __ecma262_ToString/out', 'i8') * pageSize, 124),[34,2],[65,194,1],[15],[11],[32,4],[68,0,0,0,0,0,0,16,64],[97],[32,0],[68,0,0,0,0,0,0,0,0],[97],[113],[4,64],[32,2],[252,3],[34,5],[65,4],[54,1,0],[32,5],[65,238,0],[58,0,4],[32,5],[65,245,0],[58,0,5],[32,5],[65,236,0],[58,0,6],[32,5],[65,236,0],[58,0,7],[32,5],[184],[34,2],[65,194,1],[15],[11],[32,4],[68,0,0,0,0,0,0,240,63],[97],[4,64],[32,0],[68,0,0,0,0,0,0,240,63],[97],[4,64],[32,2],[252,3],[34,5],[65,4],[54,1,0],[32,5],[65,244,0],[58,0,4],[32,5],[65,242,0],[58,0,5],[32,5],[65,245,0],[58,0,6],[32,5],[65,229,0],[58,0,7],[32,5],[184],[34,2],[65,194,1],[15],[11],[32,2],[252,3],[34,5],[65,5],[54,1,0],[32,5],[65,230,0],[58,0,4],[32,5],[65,225,0],[58,0,5],[32,5],[65,236,0],[58,0,6],[32,5],[65,243,0],[58,0,7],[32,5],[65,229,0],[58,0,8],[32,5],[184],[34,2],[65,194,1],[15],[11],[32,0],[33,6],[32,1],[34,7],[33,8],[2,124],[32,8],[65,0],[70],[4,64,"TYPESWITCH|Number"],[32,6],[32,7],[68,0,0,0,0,0,0,0,0],[65,3],[16, builtin('__Number_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,1],[70],[4,64,"TYPESWITCH|Boolean"],[32,6],[32,7],[16, builtin('__Boolean_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,4],[70],[4,64,"TYPESWITCH|Object"],[32,6],[32,7],[16, builtin('__Object_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,5],[70],[4,64,"TYPESWITCH|Function"],[32,6],[32,7],[16, builtin('__Function_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,6],[70],[4,64,"TYPESWITCH|Symbol"],[32,6],[32,7],[16, builtin('__Symbol_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,18],[70],[4,64,"TYPESWITCH|Date"],[32,6],[32,7],[16, builtin('__Date_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,19],[70],[4,64,"TYPESWITCH|Set"],[32,6],[32,7],[16, builtin('__Set_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,32],[70],[4,64,"TYPESWITCH|WeakRef"],[32,6],[32,7],[16, builtin('__WeakRef_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,33],[70],[4,64,"TYPESWITCH|WeakSet"],[32,6],[32,7],[16, builtin('__WeakSet_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,194,0],[70],[4,64,"TYPESWITCH|String"],[32,6],[252,2],[32,7],[16, builtin('__String_prototype_toString')],[33,3],[183],[12,1],[11],[32,8],[65,208,0],[70],[4,64,"TYPESWITCH|Array"],[32,6],[32,7],[16, builtin('__Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,215,0],[70],[4,64,"TYPESWITCH|Uint8Array"],[32,6],[32,7],[16, builtin('__Uint8Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,216,0],[70],[4,64,"TYPESWITCH|Int8Array"],[32,6],[32,7],[16, builtin('__Int8Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,217,0],[70],[4,64,"TYPESWITCH|Uint8ClampedArray"],[32,6],[32,7],[16, builtin('__Uint8ClampedArray_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,218,0],[70],[4,64,"TYPESWITCH|Uint16Array"],[32,6],[32,7],[16, builtin('__Uint16Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,219,0],[70],[4,64,"TYPESWITCH|Int16Array"],[32,6],[32,7],[16, builtin('__Int16Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,220,0],[70],[4,64,"TYPESWITCH|Uint32Array"],[32,6],[32,7],[16, builtin('__Uint32Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,221,0],[70],[4,64,"TYPESWITCH|Int32Array"],[32,6],[32,7],[16, builtin('__Int32Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,222,0],[70],[4,64,"TYPESWITCH|Float32Array"],[32,6],[32,7],[16, builtin('__Float32Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,223,0],[70],[4,64,"TYPESWITCH|Float64Array"],[32,6],[32,7],[16, builtin('__Float64Array_prototype_toString')],[33,3],[12,1],[11],[32,8],[65,194,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,6],[252,2],[32,7],[16, builtin('__ByteString_prototype_toString')],[33,3],[183],[12,1],[11],...internalThrow(scope, 'TypeError', `'toString' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[32,3],[15]],
3812
3826
  params: [124,127], typedParams: 1,
3813
3827
  returns: [124,127], typedReturns: 1,
3814
3828
  locals: [124,127,124,127,124,127,127], localNames: ["argument","argument#type","out","#last_type","type","#makearray_pointer_tmp","#proto_target","#proto_target#type","#typeswitch_tmp"],
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.18.32+da1ae5c67",
4
+ "version": "0.18.33+823ef76d5",
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.18.32+da1ae5c67';
3
+ globalThis.version = '0.18.33+823ef76d5';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {