Expand description
L0’s ABI over handles: step 2 of
todo/l0-interface.md.
The functions a compiled program imports from fjs:l0, with the WASM
types of the summary,
over super, the typed L0. It is still native Rust: step 3 exports it
from a .wasm.
- A value is an
i64handle, an index into a table ofnaivevalues, with the slot’s generation in the high 32 bits, so a handle used after itsdroptraps even when its slot holds a new value. The four constants are the handles0to3, whichdupanswers as they are anddropleaves alone, and everyundefined,nullor boolean an L0 function answers is one of them. Every other handle is one owned reference:dupmakes a new handle anddropfrees one. - A builder is an
i32handle, an index into a table of open builders, with a generation the same way. - Bytes cross through
with_memory, which stands in for the memory the loader makes. - Code is a
Codein a table,add_code, which stands in for the shared WASM table. A function L0 makes keeps its code index as the item0of its NaNVM frame, before the frame the program gave, so one RustStaticCoderuns every code index. - A throw traps
(
l0-throw-trap.md).throwkeeps the value and traps: in WASM it reachesunreachable, and here it panics withThrown. A throw from NaNVM’s own Rust code is anErr, turned into athrowonly at the export, incall, so nothing is borrowed or half made when it traps. The host reads it throughhas_thrown,thrownandrecover, withenterandleavearound each call, which are not L0 imports.catchis a native host’s whole sequence.
A misuse traps as super does, with the text l0.<name>: <reason>,
including a handle that names no value, not a value, and bytes out of
the memory, out of bounds.
Structs§
- Thrown
- The payload of the panic
throwcauses in native code. The value is kept apart, in the runtime, forthrown.
Constants§
- FALSE
- The constant
false. - NULL
- The constant
null. - TRUE
- The constant
true. - UNDEFINED
- The constant
undefined.
Functions§
- add_
code - The loader’s step that puts a code in the table, answering its index.
- begin_
array - L0
begin_array. - begin_
object - L0
begin_object. - call
- L0
call. A throw, from the code or from NaNVM’s own, becomesthrowhere. - catch
- A native host’s call into the program:
Okwith the result, orErrwith the thrown value, afterrecover. A misuse panics on. It needspanic = "unwind": withabort, every trap ends the process, and a WASM host catches the trap itself. - concat
- L0
concat. - drop
- L0
drop. It takesv. - dup
- L0
dup. - enter
- Marks the start of a call of the host into the program, for
recover. Calls may nest, as when the host answers an effect. - find
- L0
find. - frame
- L0
frame: the itemiof the frame the program gavemake_function, read through the running function,self_. - from_
bool - L0
from_bool: the constanttruefor anybbut0. - from_
f64 - L0
from_f64. - from_
unit - L0
from_unit. A number that is not a UTF-16 unit traps. - has_
thrown 1when athrowcaused the last trap, else0: the trap was a misuse.- item
- L0
item. - join
- L0
join. - key
- L0
key. - kind
- L0
kind. - leave
- Ends the call
entermarked, after it returned. - length
- L0
length. - live
- The number of handles in use, besides the constants: for tests of ownership.
- make_
bigint - L0
make_bigint: a sign andlenu64words atptr. - make_
function - L0
make_function. It takesframeandtext, a string orundefined. - make_
string - L0
make_string:lenUTF-16 units atptr. - push
- L0
push. It takesv. - push_
property - L0
push_property. It takeskeyandv. - read_
units - L0
read_units:lenunits ofsfromstart, written atptr. - read_
words - L0
read_words:lenwords ofb’s magnitude fromstart, written atptr. - recover
- Makes the runtime ready to go on after a caught throw, and ends the
call
entermarked. It frees every value handle and builder made after that mark and before thethrow: what the abandoned frames held, since a program keeps no handle across a call of the host but its literals, made before any. Then it clearshas_thrown. A handle thatthrownmade stays. Without a mark it frees nothing. - same
- L0
same. - seal
- L0
seal. It consumes the builder. - sign
- L0
sign. - substring
- L0
substring. - text
- L0
text. - throw
- L0
throw: keepsv, which it takes, and traps. - thrown
- The value the last
throwkept, as an owned handle, orundefined. - to_bool
- L0
to_bool. - to_f64
- L0
to_f64. - unit
- L0
unit. - with_
memory - The host’s access to the memory, as a loader writes the program’s bytes.
Type Aliases§
- Code
- The code of a function:
(param $self i64) (param $args i64) (result i64)(l0-design.md§12). It borrows both handles and answers an owned one, or callsthrow.