porffor 0.37.14 → 0.37.16

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.
@@ -17,8 +17,10 @@ export const __Porffor_strcmp = (a: any, b: any): boolean => {
17
17
  // bytestring, bytestring
18
18
  // this path is hyper-optimized as it is by far the most common and (perf) important
19
19
 
20
- let ap: i32 = a - 28;
21
- let bp: i32 = b - 28;
20
+ let ap32: i32 = a - 28;
21
+ let bp32: i32 = b - 28;
22
+ let ap8: i32 = a - 4;
23
+ let bp8: i32 = b - 4;
22
24
  Porffor.wasm`
23
25
  ;; load in 2 i64x2 chunks while length >= 32
24
26
  local.get ${al}
@@ -26,29 +28,28 @@ i32.const 32
26
28
  i32.ge_s
27
29
  if 64
28
30
  loop 64
29
- local.get ${ap}
31
+ local.get ${ap32}
30
32
  local.get ${al}
31
33
  i32.add
32
34
  v128.load 0 0
33
35
 
34
- local.get ${bp}
36
+ local.get ${bp32}
35
37
  local.get ${al}
36
38
  i32.add
37
39
  v128.load 0 0
38
-
39
40
  v128.xor
40
41
 
41
- local.get ${ap}
42
+ local.get ${ap32}
42
43
  local.get ${al}
43
44
  i32.add
44
45
  v128.load 0 16
45
46
 
46
- local.get ${bp}
47
+ local.get ${bp32}
47
48
  local.get ${al}
48
49
  i32.add
49
50
  v128.load 0 16
50
-
51
51
  v128.xor
52
+
52
53
  v128.or
53
54
  v128.any_true
54
55
  if 64
@@ -73,15 +74,15 @@ i32.const 8
73
74
  i32.ge_s
74
75
  if 64
75
76
  loop 64
76
- local.get ${ap}
77
+ local.get ${ap8}
77
78
  local.get ${al}
78
79
  i32.add
79
- i64.load 0 24
80
+ i64.load 0 0
80
81
 
81
- local.get ${bp}
82
+ local.get ${bp8}
82
83
  local.get ${al}
83
84
  i32.add
84
- i64.load 0 24
85
+ i64.load 0 0
85
86
 
86
87
  i64.ne
87
88
  if 64
@@ -17,9 +17,9 @@ usedTypes:[80,7,195],
17
17
  globalInits:{underlyingKeys:(_,{allocPage,glbl,loc})=>[...number(allocPage(_,'array: __internal_object.ts/underlyingKeys','f64'),124),...glbl(36,'underlyingKeys',124),...glbl(35,'underlyingKeys',124),[252,3],[33,loc('#makearray_pointer_tmp',127)],[32,loc('#makearray_pointer_tmp',127)],[65,0],[54,1,0],[32,loc('#makearray_pointer_tmp',127)],[68,0],[252,3],[54,1,0],[32,loc('#makearray_pointer_tmp',127)],[26]],underlyingVals:(_,{allocPage,glbl,loc})=>[...number(allocPage(_,'array: __internal_object.ts/underlyingVals','f64'),124),...glbl(36,'underlyingVals',124),...glbl(35,'underlyingVals',124),[252,3],[33,loc('#makearray_pointer_tmp',127)],[32,loc('#makearray_pointer_tmp',127)],[65,0],[54,1,0],[32,loc('#makearray_pointer_tmp',127)],[68,0],[252,3],[54,1,0],[32,loc('#makearray_pointer_tmp',127)],[26]]},data:{"bytestring: __Porffor_object_makeObject/key1":[9,0,0,0,112,114,111,116,111,116,121,112,101],"bytestring: __Porffor_object_makeObject/key2":[11,0,0,0,99,111,110,115,116,114,117,99,116,111,114]},
18
18
  };
19
19
  this.__Porffor_strcmp = {
20
- wasm:()=>[[32,0],[32,2],[70],[4,64],[65,1],[65,2],[15],[11],[32,0],[40,0,0],[33,4],[32,2],[40,0,0],[33,5],[32,4],[32,5],[71],[4,64],[65,0],[65,2],[15],[11],[32,1],[65,195,1],[70],[4,64],[32,3],[65,195,1],[70],[4,64],[32,0],[65,28],[107],[33,6],[32,2],[65,28],[107],[33,7],[32,4],[65,32],[78],[4,64],[3,64],[32,6],[32,4],[106],[253,0,0,0],[32,7],[32,4],[106],[253,0,0,0],[253,81],[32,6],[32,4],[106],[253,0,0,16],[32,7],[32,4],[106],[253,0,0,16],[253,81],[253,80],[253,83],[4,64],[65,0],[65,2],[15],[11],[32,4],[65,32],[107],[34,4],[65,32],[78],[13,0],[11],[11],[32,4],[65,8],[78],[4,64],[3,64],[32,6],[32,4],[106],[41,0,24],[32,7],[32,4],[106],[41,0,24],[82],[4,64],[65,0],[65,2],[15],[11],[32,4],[65,8],[107],[34,4],[65,8],[78],[13,0],[11],[11],[32,4],[65,2],[78],[4,64],[3,64],[32,0],[32,4],[106],[47,0,2],[32,2],[32,4],[106],[47,0,2],[71],[4,64],[65,0],[65,2],[15],[11],[32,4],[65,2],[107],[34,4],[65,2],[78],[13,0],[11],[11],[32,4],[65,1],[70],[4,64],[32,0],[45,0,4],[32,2],[45,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[11],[65,1],[65,2],[15],[5],[65,0],[33,8],[3,64],[32,8],[32,4],[72],[4,64],[32,0],[32,8],[106],[45,0,4],[32,2],[32,8],[65,2],[108],[106],[47,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,8],[65,1],[106],[33,8],[12,1],[11],[11],[65,1],[65,2],[15],[11],[5],[32,3],[65,195,1],[70],[4,64],[65,0],[33,8],[3,64],[32,8],[32,4],[72],[4,64],[32,0],[32,8],[65,2],[108],[106],[47,0,4],[32,2],[32,8],[106],[45,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,8],[65,1],[106],[33,8],[12,1],[11],[11],[65,1],[65,2],[15],[5],[32,0],[65,4],[107],[33,6],[32,2],[65,4],[107],[33,7],[3,64],[32,6],[32,4],[65,2],[108],[106],[41,0,0],[32,7],[32,4],[65,2],[108],[106],[41,0,0],[82],[4,64],[65,0],[65,2],[15],[11],[32,4],[65,4],[107],[34,4],[65,4],[78],[13,0],[11],[65,0],[33,8],[3,64],[32,8],[32,4],[72],[4,64],[32,0],[32,8],[65,2],[108],[106],[47,0,4],[32,2],[32,8],[65,2],[108],[106],[47,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,8],[65,1],[106],[33,8],[12,1],[11],[11],[65,1],[65,2],[15],[11],[11],[65,0],[65,128,1],[15]],
20
+ wasm:()=>[[32,0],[32,2],[70],[4,64],[65,1],[65,2],[15],[11],[32,0],[40,0,0],[33,4],[32,2],[40,0,0],[33,5],[32,4],[32,5],[71],[4,64],[65,0],[65,2],[15],[11],[32,1],[65,195,1],[70],[4,64],[32,3],[65,195,1],[70],[4,64],[32,0],[65,28],[107],[33,6],[32,2],[65,28],[107],[33,7],[32,0],[65,4],[107],[33,8],[32,2],[65,4],[107],[33,9],[32,4],[65,32],[78],[4,64],[3,64],[32,6],[32,4],[106],[253,0,0,0],[32,7],[32,4],[106],[253,0,0,0],[253,81],[32,6],[32,4],[106],[253,0,0,16],[32,7],[32,4],[106],[253,0,0,16],[253,81],[253,80],[253,83],[4,64],[65,0],[65,2],[15],[11],[32,4],[65,32],[107],[34,4],[65,32],[78],[13,0],[11],[11],[32,4],[65,8],[78],[4,64],[3,64],[32,8],[32,4],[106],[41,0,0],[32,9],[32,4],[106],[41,0,0],[82],[4,64],[65,0],[65,2],[15],[11],[32,4],[65,8],[107],[34,4],[65,8],[78],[13,0],[11],[11],[32,4],[65,2],[78],[4,64],[3,64],[32,0],[32,4],[106],[47,0,2],[32,2],[32,4],[106],[47,0,2],[71],[4,64],[65,0],[65,2],[15],[11],[32,4],[65,2],[107],[34,4],[65,2],[78],[13,0],[11],[11],[32,4],[65,1],[70],[4,64],[32,0],[45,0,4],[32,2],[45,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[11],[65,1],[65,2],[15],[5],[65,0],[33,10],[3,64],[32,10],[32,4],[72],[4,64],[32,0],[32,10],[106],[45,0,4],[32,2],[32,10],[65,2],[108],[106],[47,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,10],[65,1],[106],[33,10],[12,1],[11],[11],[65,1],[65,2],[15],[11],[5],[32,3],[65,195,1],[70],[4,64],[65,0],[33,10],[3,64],[32,10],[32,4],[72],[4,64],[32,0],[32,10],[65,2],[108],[106],[47,0,4],[32,2],[32,10],[106],[45,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,10],[65,1],[106],[33,10],[12,1],[11],[11],[65,1],[65,2],[15],[5],[32,0],[65,4],[107],[33,11],[32,2],[65,4],[107],[33,12],[3,64],[32,11],[32,4],[65,2],[108],[106],[41,0,0],[32,12],[32,4],[65,2],[108],[106],[41,0,0],[82],[4,64],[65,0],[65,2],[15],[11],[32,4],[65,4],[107],[34,4],[65,4],[78],[13,0],[11],[65,0],[33,10],[3,64],[32,10],[32,4],[72],[4,64],[32,0],[32,10],[65,2],[108],[106],[47,0,4],[32,2],[32,10],[65,2],[108],[106],[47,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,10],[65,1],[106],[33,10],[12,1],[11],[11],[65,1],[65,2],[15],[11],[11],[65,0],[65,128,1],[15]],
21
21
  params:[127,127,127,127],typedParams:1,returns:[127,127],typedReturns:1,
22
- locals:[127,127,127,127,127],localNames:["a","a#type","b","b#type","al","bl","ap","bp","i"],
22
+ locals:[127,127,127,127,127,127,127,127,127],localNames:["a","a#type","b","b#type","al","bl","ap32","bp32","ap8","bp8","i","ap","bp"],
23
23
  };
24
24
  this.__Porffor_strcat = {
25
25
  wasm:(_,{builtin})=>[[32,0],[40,0,0],[33,4],[32,2],[40,0,0],[33,5],[32,1],[65,195,1],[70],[4,64],[32,3],[65,195,1],[70],[4,64],[65,4],[32,4],[106],[32,5],[106],[16,builtin('__Porffor_allocateBytes')],[34,6],[32,4],[32,5],[106],[54,0,0],[32,6],[65,4],[106],[32,0],[65,4],[106],[32,4],[252,10,0,0],[32,6],[65,4],[106],[32,4],[106],[32,2],[65,4],[106],[32,5],[252,10,0,0],[32,6],[65,195,1],[15],[5],[65,4],[32,4],[32,5],[106],[65,2],[108],[106],[16,builtin('__Porffor_allocateBytes')],[34,6],[32,4],[32,5],[106],[54,0,0],[65,0],[33,7],[3,64],[32,7],[32,4],[72],[4,64],[32,6],[32,7],[65,2],[108],[106],[32,0],[32,7],[106],[45,0,4],[59,0,4],[32,7],[65,1],[106],[33,7],[12,1],[11],[11],[32,6],[65,4],[106],[32,4],[65,2],[108],[106],[32,2],[65,4],[106],[32,5],[65,2],[108],[252,10,0,0],[32,6],[65,195,0],[15],[11],[5],[32,3],[65,195,1],[70],[4,64],[65,4],[32,4],[32,5],[106],[65,2],[108],[106],[16,builtin('__Porffor_allocateBytes')],[34,6],[32,4],[32,5],[106],[54,0,0],[32,6],[65,4],[106],[32,0],[65,4],[106],[32,4],[65,2],[108],[252,10,0,0],[32,6],[32,4],[65,2],[108],[106],[33,8],[65,0],[33,7],[3,64],[32,7],[32,5],[72],[4,64],[32,8],[32,7],[65,2],[108],[106],[32,2],[32,7],[106],[45,0,4],[59,0,4],[32,7],[65,1],[106],[33,7],[12,1],[11],[11],[32,6],[65,195,0],[15],[5],[65,4],[32,4],[32,5],[106],[65,2],[108],[106],[16,builtin('__Porffor_allocateBytes')],[34,6],[32,4],[32,5],[106],[54,0,0],[32,6],[65,4],[106],[32,0],[65,4],[106],[32,4],[65,2],[108],[252,10,0,0],[32,6],[65,4],[106],[32,4],[65,2],[108],[106],[32,2],[65,4],[106],[32,5],[65,2],[108],[252,10,0,0],[32,6],[65,195,0],[15],[11],[11],[65,0],[65,128,1],[15]],
@@ -1170,7 +1170,15 @@ const setType = (scope, _name, type) => {
1170
1170
  const out = typeof type === 'number' ? number(type, Valtype.i32) : type;
1171
1171
 
1172
1172
  if (Object.hasOwn(scope.locals, name)) {
1173
- if (scope.locals[name]?.metadata?.type != null) return [];
1173
+ if (scope.locals[name]?.metadata?.type != null) {
1174
+ const metadata = scope.locals[name].metadata;
1175
+ if (metadata.inferredType && knownType(scope, type) !== metadata.type) {
1176
+ delete metadata.type;
1177
+ delete metadata.inferredType;
1178
+ }
1179
+
1180
+ return [];
1181
+ }
1174
1182
 
1175
1183
  const typeLocal = scope.locals[name + '#type'];
1176
1184
  if (typeLocal) return [
@@ -1183,7 +1191,15 @@ const setType = (scope, _name, type) => {
1183
1191
  }
1184
1192
 
1185
1193
  if (Object.hasOwn(globals, name)) {
1186
- if (globals[name]?.metadata?.type != null) return [];
1194
+ if (globals[name]?.metadata?.type != null) {
1195
+ const metadata = globals[name].metadata;
1196
+ if (metadata.inferredType && knownType(scope, type) !== metadata.type) {
1197
+ delete metadata.type;
1198
+ delete metadata.inferredType;
1199
+ }
1200
+
1201
+ return [];
1202
+ }
1187
1203
 
1188
1204
  const typeLocal = globals[name + '#type'];
1189
1205
  if (typeLocal) return [
@@ -2599,15 +2615,12 @@ const knownType = (scope, type) => {
2599
2615
  return read_signedLEB128(type[0].slice(1));
2600
2616
  }
2601
2617
 
2602
- if (typedInput && type.length === 1 && type[0][0] === Opcodes.local_get) {
2618
+ if (type.length === 1 && type[0][0] === Opcodes.local_get) {
2603
2619
  const idx = type[0][1];
2604
2620
 
2605
2621
  // type idx = var idx + 1
2606
2622
  const name = Object.values(scope.locals).find(x => x.idx === idx)?.name;
2607
- if (name) {
2608
- const local = scope.locals[name];
2609
- if (local.metadata?.type != null) return v.metadata.type;
2610
- }
2623
+ if (scope.locals[name]?.metadata?.type != null) return v.metadata.type;
2611
2624
  }
2612
2625
 
2613
2626
  return null;
@@ -2962,14 +2975,25 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
2962
2975
  // let generated;
2963
2976
  // if (init) generated = generate(scope, init, global, name);
2964
2977
 
2965
- const typed = typedInput && pattern.typeAnnotation;
2966
- let idx = allocVar(scope, name, global, !(typed && extractTypeAnnotation(pattern).type != null));
2967
- addVarMetadata(scope, name, global, { kind });
2978
+ const typed = typedInput && pattern.typeAnnotation && extractTypeAnnotation(pattern);
2979
+ let idx = allocVar(scope, name, global, !(typed && typed.type != null));
2968
2980
 
2981
+ let metadata = { kind };
2969
2982
  if (typed) {
2970
- addVarMetadata(scope, name, global, extractTypeAnnotation(pattern));
2983
+ metadata = {
2984
+ ...metadata,
2985
+ ...typed
2986
+ };
2987
+ } else if (init) {
2988
+ const knownInit = knownType(scope, getNodeType(scope, init));
2989
+ if (knownInit != null) {
2990
+ metadata.type = knownInit;
2991
+ metadata.inferredType = true;
2992
+ }
2971
2993
  }
2972
2994
 
2995
+ addVarMetadata(scope, name, global, metadata);
2996
+
2973
2997
  if (init) {
2974
2998
  const alreadyArray = scope.arrays?.get(name) != null;
2975
2999
 
@@ -3502,7 +3526,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3502
3526
  [TYPES.undefined]: internalThrow(scope, 'TypeError', 'Cannot set property of undefined', true),
3503
3527
 
3504
3528
  // default: internalThrow(scope, 'TypeError', `Cannot assign member with this type`)
3505
- default: [
3529
+ default: () => [
3506
3530
  ...objectWasm,
3507
3531
  Opcodes.i32_to_u,
3508
3532
  ...(op === '=' ? [] : [ [ Opcodes.local_tee, localTmp(scope, '#objset_object', Valtype.i32) ] ]),
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.37.14+ebe5bcdbc",
4
+ "version": "0.37.16+2b7968825",
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.37.14+ebe5bcdbc';
3
+ globalThis.version = '0.37.16+2b7968825';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {