porffor 0.18.22 → 0.18.24
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 +226 -1
- package/compiler/builtins/dataview.ts +261 -0
- package/compiler/builtins/porffor.d.ts +2 -0
- package/compiler/builtins/typedarray.js +58 -9
- package/compiler/builtins.js +6 -0
- package/compiler/codegen.js +3 -3
- package/compiler/generated_builtins.js +594 -231
- package/compiler/types.js +2 -0
- package/compiler/wasmSpec.js +1 -0
- package/compiler/wrap.js +33 -8
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/types.js
CHANGED
@@ -55,6 +55,8 @@ registerInternalType('Date');
|
|
55
55
|
registerInternalType('Set', ['iterable']);
|
56
56
|
|
57
57
|
registerInternalType('ArrayBuffer');
|
58
|
+
registerInternalType('SharedArrayBuffer');
|
59
|
+
registerInternalType('DataView');
|
58
60
|
registerInternalType('Uint8Array', ['iterable', 'length']);
|
59
61
|
registerInternalType('Int8Array', ['iterable', 'length']);
|
60
62
|
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,32 @@ 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
|
+
|
137
|
+
case TYPES.dataview: {
|
138
|
+
const [ length, ptr, byteOffset ] = (new Uint32Array(memory.buffer.slice(value, value + 12), 0, 3));
|
139
|
+
const bufferPtr = ptr - byteOffset;
|
140
|
+
const bufferLen = (new Uint32Array(memory.buffer.slice(bufferPtr, bufferPtr + 4), 0, 1))[0];
|
141
|
+
const buffer = memory.buffer.slice(bufferPtr + 4, bufferPtr + 4 + bufferLen);
|
142
|
+
return new DataView(buffer, byteOffset, length);
|
143
|
+
}
|
144
|
+
|
123
145
|
case TYPES.uint8array:
|
124
146
|
case TYPES.int8array:
|
125
147
|
case TYPES.uint8clampedarray:
|
@@ -129,7 +151,7 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
|
|
129
151
|
case TYPES.int32array:
|
130
152
|
case TYPES.float32array:
|
131
153
|
case TYPES.float64array: {
|
132
|
-
const [ length, ptr ] = (new
|
154
|
+
const [ length, ptr ] = (new Uint32Array(memory.buffer.slice(value, value + 8), 0, 2));
|
133
155
|
return new globalThis[TYPE_NAMES[type]](memory.buffer, ptr + 4, length);
|
134
156
|
}
|
135
157
|
|
@@ -289,6 +311,9 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
289
311
|
return -1;
|
290
312
|
}
|
291
313
|
},
|
314
|
+
b: () => {
|
315
|
+
debugger;
|
316
|
+
},
|
292
317
|
...customImports
|
293
318
|
}
|
294
319
|
});
|
package/package.json
CHANGED