#import "Extensions/Wasi_Runtime";
What a wasm64 program needs to run as a WASI command (node, wasmtime and the
like). jaic adds it to jaic -os wasm programs and to workspaces whose LLVM triple
names WASI; a program that brings its own host bindings leaves it out. This module is a jaic
extension, not official Jai. See docs/native/wasm-target.md.
It supplies, in Jai, the C library entry points the stdlib reaches for under OS == .WASM
(the same ones the interpreter's sandbox host implements): a heap, memmove/memcmp,
read/write, clock_gettime, exit, files and directories (files.jai), process calls that
fail the way a sandbox without processes would, green threads for the pthread calls
(threads.jai), a libm (math.jai, elementary.jai), the compiler-rt binary128 helpers
Long_Double needs (quad.jai), plus Runtime_Support's
wasm_write_string and wasm_debug_break, and _start, which collects the WASI arguments and
calls main. Every definition is a #program_export under its C name; jaic's LLVM backend
binds the program's #foreign references to them without exporting them from the module, so
the linker drops the ones a program never calls and the module imports nothing but the
wasi_snapshot_preview1 calls it uses.
Show moreShow less
Under the interpreter (compile-time code, jaic -interp -os wasm) none of this runs: the
sandbox host answers those #foreign calls itself.
Procedures#
The next thread to run, after the one that just ran. With none ready, it sleeps until the first timed wait runs out. When every thread waits for something only another waiting thread could do, they are deadlocked: the one that blocked last gets EDEADLK.
Blocks the running thread until another wakes it or deadline passes, and says why it woke:
0, ETIMEDOUT or EDEADLK. Only for programs jaic made able to unwind (green.enabled).
Wakes the thread that has waited longest for object.
Sleeps the whole interval: a host may wake a poll slightly early (Node's can).
A sleep is a timed wait for nothing, so other threads run meanwhile.
Releases the mutex for the length of the wait, however deeply the thread holds it.
Types#
The compiler reads these by offset: state at 0, top at 8, limit at 16, enabled at 24.
Constants#
Just under 1 MiB, so the heap's power-of-two classes fit it with its tag.