porffor 0.18.22 → 0.18.23

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/types.js CHANGED
@@ -55,6 +55,7 @@ registerInternalType('Date');
55
55
  registerInternalType('Set', ['iterable']);
56
56
 
57
57
  registerInternalType('ArrayBuffer');
58
+ registerInternalType('SharedArrayBuffer');
58
59
  registerInternalType('Uint8Array', ['iterable', 'length']);
59
60
  registerInternalType('Int8Array', ['iterable', 'length']);
60
61
  registerInternalType('Uint8ClampedArray', ['iterable', 'length']);
@@ -38,6 +38,7 @@ export const Opcodes = {
38
38
  loop: 0x03,
39
39
  if: 0x04,
40
40
  else: 0x05,
41
+ select: 0x1b,
41
42
 
42
43
  try: 0x06,
43
44
  catch: 0x07,
package/compiler/wrap.js CHANGED
@@ -11,13 +11,13 @@ const fs = (typeof process?.version !== 'undefined' ? (await import('node:fs'))
11
11
  const bold = x => `\u001b[1m${x}\u001b[0m`;
12
12
 
13
13
  export const readByteStr = (memory, ptr) => {
14
- const length = (new Int32Array(memory.buffer, ptr, 1))[0];
14
+ const length = (new Uint32Array(memory.buffer, ptr, 1))[0];
15
15
  return Array.from(new Uint8Array(memory.buffer, ptr + 4, length)).map(x => String.fromCharCode(x)).join('');
16
16
  };
17
17
 
18
18
  export const writeByteStr = (memory, ptr, str) => {
19
19
  const length = str.length;
20
- (new Int32Array(memory.buffer, ptr, 1))[0] = length;
20
+ (new Uint32Array(memory.buffer, ptr, 1))[0] = length;
21
21
 
22
22
  const arr = new Uint8Array(memory.buffer, ptr + 4, length);
23
23
  for (let i = 0; i < length; i++) {
@@ -46,17 +46,17 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
46
46
  }
47
47
 
48
48
  case TYPES.string: {
49
- const length = (new Int32Array(memory.buffer, value, 1))[0];
49
+ const length = (new Uint32Array(memory.buffer, value, 1))[0];
50
50
  return Array.from(new Uint16Array(memory.buffer, value + 4, length)).map(x => String.fromCharCode(x)).join('');
51
51
  }
52
52
 
53
53
  case TYPES.bytestring: {
54
- const length = (new Int32Array(memory.buffer, value, 1))[0];
54
+ const length = (new Uint32Array(memory.buffer, value, 1))[0];
55
55
  return Array.from(new Uint8Array(memory.buffer, value + 4, length)).map(x => String.fromCharCode(x)).join('');
56
56
  }
57
57
 
58
58
  case TYPES.array: {
59
- const length = (new Int32Array(memory.buffer, value, 1))[0];
59
+ const length = (new Uint32Array(memory.buffer, value, 1))[0];
60
60
 
61
61
  const out = [];
62
62
  for (let i = 0; i < length; i++) {
@@ -82,7 +82,7 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
82
82
  }
83
83
 
84
84
  case TYPES.set: {
85
- const size = (new Int32Array(memory.buffer, value, 1))[0];
85
+ const size = (new Uint32Array(memory.buffer, value, 1))[0];
86
86
 
87
87
  const out = new Set();
88
88
  for (let i = 0; i < size; i++) {
@@ -116,10 +116,24 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
116
116
  }
117
117
 
118
118
  case TYPES.arraybuffer: {
119
- const length = (new Int32Array(memory.buffer.slice(value, value + 4), 0, 1))[0];
119
+ const length = (new Uint32Array(memory.buffer.slice(value, value + 4), 0, 1))[0];
120
+ if (length === 4294967295) {
121
+ // mock detached
122
+ const buf = new ArrayBuffer(0);
123
+ if (buf.detached != null) buf.transfer();
124
+ else buf.detached = true;
125
+ return buf;
126
+ }
120
127
  return memory.buffer.slice(value + 4, value + 4 + length);
121
128
  }
122
129
 
130
+ case TYPES.sharedarraybuffer: {
131
+ const length = (new Uint32Array(memory.buffer.slice(value, value + 4), 0, 1))[0];
132
+ const buf = memory.buffer.slice(value + 4, value + 4 + length);
133
+ buf.shared = true;
134
+ return buf;
135
+ }
136
+
123
137
  case TYPES.uint8array:
124
138
  case TYPES.int8array:
125
139
  case TYPES.uint8clampedarray:
@@ -129,7 +143,7 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
129
143
  case TYPES.int32array:
130
144
  case TYPES.float32array:
131
145
  case TYPES.float64array: {
132
- const [ length, ptr ] = (new Int32Array(memory.buffer.slice(value, value + 8), 0, 2));
146
+ const [ length, ptr ] = (new Uint32Array(memory.buffer.slice(value, value + 8), 0, 2));
133
147
  return new globalThis[TYPE_NAMES[type]](memory.buffer, ptr + 4, length);
134
148
  }
135
149
 
@@ -289,6 +303,9 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
289
303
  return -1;
290
304
  }
291
305
  },
306
+ b: () => {
307
+ debugger;
308
+ },
292
309
  ...customImports
293
310
  }
294
311
  });
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.22+b1a191357",
4
+ "version": "0.18.23+8066aaac0",
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.22+b1a191357';
3
+ globalThis.version = '0.18.23+8066aaac0';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {