porffor 0.18.28 → 0.18.29

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,30 @@
1
+ import type {} from './porffor.d.ts';
2
+
3
+ export const WeakRef = function (target: any): WeakRef {
4
+ if (!new.target) throw new TypeError("Constructor WeakRef requires 'new'");
5
+
6
+ const out: WeakRef = Porffor.allocateBytes(9);
7
+
8
+ Porffor.wasm`local.get ${out}
9
+ i32.to_u
10
+ local.get ${target}
11
+ f64.store 0 0
12
+
13
+ local.get ${out}
14
+ i32.to_u
15
+ local.get ${target+1}
16
+ i32.store8 0 8`;
17
+
18
+ return out;
19
+ };
20
+
21
+ export const __WeakRef_prototype_deref = (_this: WeakRef) => {
22
+ Porffor.wasm`local.get ${_this}
23
+ i32.to_u
24
+ f64.load 0 0
25
+
26
+ local.get ${_this}
27
+ i32.to_u
28
+ i32.load8_u 0 8
29
+ return`;
30
+ };
@@ -3737,6 +3737,19 @@ export const BuiltinFuncs = function() {
3737
3737
  returns: [124,127], typedReturns: 1,
3738
3738
  locals: [124,127], localNames: ["_this","_this#type","callbackFn","callbackFn#type","out","#last_type"],
3739
3739
  };
3740
+ this.WeakRef = {
3741
+ wasm: (scope, {builtin,internalThrow}) => [[32,-1],[184],[65,1],[33,2],[33,3],[32,2],[33,4],[2,124],[32,4],[65,194,0],[70],[4,64,"TYPESWITCH|String"],[32,3],[252,3],[40,1,0],[69],[184],[12,1],[11],[32,4],[65,194,1],[70],[4,64,"TYPESWITCH|ByteString"],[32,3],[252,3],[40,1,0],[69],[184],[12,1],[11],[32,3],[68,0,0,0,0,0,0,0,0],[97],[184],[11,"TYPESWITCH_end"],[252,3],[4,64],...internalThrow(scope, 'TypeError', `Constructor WeakRef requires 'new'`),[11],[65,9],[16, builtin('__Porffor_allocateBytes')],[183],[34,5],[252,3],[32,0],[57,0,0],[32,5],[252,3],[32,1],[58,0,8],[32,5],[65,32],[15]],
3742
+ params: [124,127], typedParams: 1,
3743
+ returns: [124,127], typedReturns: 1,
3744
+ locals: [127,124,127,124], localNames: ["target","target#type","#last_type","#logicinner_tmp","#typeswitch_tmp","out"],
3745
+ constr: 1,
3746
+ };
3747
+ this.__WeakRef_prototype_deref = {
3748
+ wasm: (scope, {}) => [[32,0],[252,3],[43,0,0],[32,0],[252,3],[45,0,8],[15]],
3749
+ params: [124,127], typedParams: 1,
3750
+ returns: [124,127], typedReturns: 1,
3751
+ locals: [], localNames: ["_this","_this#type"],
3752
+ };
3740
3753
  this.__ecma262_ToIntegerOrInfinity = {
3741
3754
  wasm: (scope, {builtin}) => [[65,0],[32,0],[16, builtin('Number')],[34,2],[16, builtin('__Number_isNaN')],[252,3],[4,64],[68,0,0,0,0,0,0,0,0],[65,0],[15],[11],[32,2],[16, builtin('__Number_isFinite')],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,2],[65,0],[15],[11],[32,2],[16, builtin('__Math_trunc')],[34,2],[68,0,0,0,0,0,0,0,0],[97],[4,64],[68,0,0,0,0,0,0,0,0],[65,0],[15],[11],[32,2],[65,0],[15]],
3742
3755
  params: [124,127], typedParams: 1,
package/compiler/types.js CHANGED
@@ -65,4 +65,6 @@ registerInternalType('Int16Array', ['iterable', 'length']);
65
65
  registerInternalType('Uint32Array', ['iterable', 'length']);
66
66
  registerInternalType('Int32Array', ['iterable', 'length']);
67
67
  registerInternalType('Float32Array', ['iterable', 'length']);
68
- registerInternalType('Float64Array', ['iterable', 'length']);
68
+ registerInternalType('Float64Array', ['iterable', 'length']);
69
+
70
+ registerInternalType('WeakRef');
package/compiler/wrap.js CHANGED
@@ -155,6 +155,13 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
155
155
  return new globalThis[TYPE_NAMES[type]](memory.buffer, ptr + 4, length);
156
156
  }
157
157
 
158
+ case TYPES.weakref: {
159
+ const v = (new Float64Array(memory.buffer.slice(value, value + 8), 0, 1))[0];
160
+ const t = (new Uint8Array(memory.buffer, value + 8, 1))[0];
161
+
162
+ return new WeakRef(porfToJSValue({ memory, funcs, pages }, v, t));
163
+ }
164
+
158
165
  default: return value;
159
166
  }
160
167
  };
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.28+66d3e519a",
4
+ "version": "0.18.29+791cf81b6",
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.28+66d3e519a';
3
+ globalThis.version = '0.18.29+791cf81b6';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {