porffor 0.18.21 → 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/assemble.js +34 -1
- package/compiler/builtins/array.ts +32 -1
- package/compiler/builtins/arraybuffer.ts +249 -0
- package/compiler/builtins/porffor.d.ts +2 -0
- package/compiler/builtins/typedarray.js +65 -5
- package/compiler/builtins.js +6 -0
- package/compiler/codegen.js +3 -3
- package/compiler/generated_builtins.js +496 -224
- package/compiler/types.js +1 -0
- package/compiler/wasmSpec.js +1 -0
- package/compiler/wrap.js +25 -8
- package/package.json +1 -1
- package/runner/index.js +1 -1
- package/compiler/builtins/typedarray.ts +0 -19
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']);
|
package/compiler/wasmSpec.js
CHANGED
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
package/runner/index.js
CHANGED
@@ -1,19 +0,0 @@
|
|
1
|
-
import type {} from './porffor.d.ts';
|
2
|
-
|
3
|
-
export const ArrayBuffer = function (length: number): ArrayBuffer {
|
4
|
-
if (!new.target) throw new TypeError("Constructor ArrayBuffer requires 'new'");
|
5
|
-
|
6
|
-
if (length < 0) throw new RangeError('Invalid ArrayBuffer length (negative)');
|
7
|
-
if (length > 34359738368) throw new RangeError('Invalid ArrayBuffer length (>32GiB)');
|
8
|
-
|
9
|
-
length |= 0;
|
10
|
-
|
11
|
-
const out: ArrayBuffer = Porffor.allocateBytes(length + 4);
|
12
|
-
Porffor.wasm.i32.store(out, length, 0, 0);
|
13
|
-
|
14
|
-
return out;
|
15
|
-
};
|
16
|
-
|
17
|
-
export const __ArrayBuffer_prototype_byteLength$get = (_this: ArrayBuffer) => {
|
18
|
-
return Porffor.wasm.i32.load(_this, 0, 0);
|
19
|
-
};
|