jz 0.1.0 → 0.2.0
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/README.md +221 -62
- package/cli.js +34 -8
- package/index.js +133 -14
- package/module/array.js +399 -131
- package/module/collection.js +457 -212
- package/module/console.js +170 -87
- package/module/core.js +247 -143
- package/module/date.js +691 -0
- package/module/function.js +84 -23
- package/module/index.js +2 -1
- package/module/json.js +485 -138
- package/module/math.js +81 -40
- package/module/number.js +189 -83
- package/module/object.js +228 -46
- package/module/regex.js +34 -30
- package/module/schema.js +17 -18
- package/module/string.js +483 -227
- package/module/symbol.js +6 -4
- package/module/timer.js +90 -32
- package/module/typedarray.js +176 -44
- package/package.json +5 -10
- package/src/analyze.js +639 -124
- package/src/autoload.js +183 -0
- package/src/compile.js +448 -1083
- package/src/ctx.js +42 -12
- package/src/emit.js +646 -147
- package/src/host.js +273 -68
- package/src/ir.js +81 -31
- package/src/jzify.js +220 -36
- package/src/narrow.js +956 -0
- package/src/optimize.js +628 -42
- package/src/plan.js +1233 -0
- package/src/prepare.js +438 -256
- package/src/vectorize.js +1016 -0
- package/wasi.js +23 -4
package/wasi.js
CHANGED
|
@@ -17,16 +17,35 @@
|
|
|
17
17
|
* Create WASI import object for WebAssembly instantiation.
|
|
18
18
|
* @param {object} [opts]
|
|
19
19
|
* @param {function} [opts.write] - Custom write: (fd, text) => void
|
|
20
|
+
* @param {function} [opts.read] - Custom read: (fd, buf: Uint8Array) => bytesRead
|
|
20
21
|
*/
|
|
21
22
|
export function wasi(opts = {}) {
|
|
22
23
|
let mem = null
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const fallbackWrite = (fd, text) => {
|
|
25
|
+
const stream = fd === 1 ? globalThis.process?.stdout : globalThis.process?.stderr
|
|
26
|
+
if (stream && typeof stream.write === 'function') {
|
|
27
|
+
try { stream.write(text); return }
|
|
28
|
+
catch {}
|
|
29
|
+
}
|
|
30
|
+
const msg = text.replace(/\n$/, '')
|
|
31
|
+
;(fd === 1 ? console.log : console.warn)(msg)
|
|
32
|
+
}
|
|
33
|
+
const write = opts.write || fallbackWrite
|
|
27
34
|
|
|
28
35
|
return {
|
|
29
36
|
wasi_snapshot_preview1: {
|
|
37
|
+
fd_read(fd, iovs, iovs_len, nread) {
|
|
38
|
+
const dv = new DataView(mem.buffer)
|
|
39
|
+
let total = 0
|
|
40
|
+
for (let i = 0; i < iovs_len; i++) {
|
|
41
|
+
const ptr = dv.getUint32(iovs + i * 8, true)
|
|
42
|
+
const len = dv.getUint32(iovs + i * 8 + 4, true)
|
|
43
|
+
const buf = new Uint8Array(mem.buffer, ptr, len)
|
|
44
|
+
total += opts.read ? (opts.read(fd, buf) || 0) : 0
|
|
45
|
+
}
|
|
46
|
+
dv.setUint32(nread, total, true)
|
|
47
|
+
return 0
|
|
48
|
+
},
|
|
30
49
|
fd_write(fd, iovs, iovs_len, nwritten) {
|
|
31
50
|
const dv = new DataView(mem.buffer)
|
|
32
51
|
let written = 0
|