Skip to main content

Crate nanvm_demos

Crate nanvm_demos 

Source
Expand description

The WASM demo pages’ samples (todo/wasm-demos.md), compiled by fjs compile into gen.samples/ and built for wasm32-unknown-unknown by gen.build.sh into the committed wasm/. A page loads a sample with its export, runs it with run_sample, and then reads what the sample wrote to standard output, one byte at a time, with output_byte: the page is FunctionalScript, which can call a function but cannot construct a view of the module’s memory.

Modules§

samples
The compiled samples. npm run gen writes gen.samples/mod.rs; one #[path] names that file, since a gen. name is never a Rust identifier.

Functions§

call
Calls a sample’s entry with one number, as a page calls a function sample: what it answered, or what it threw, each as spell writes it.
call_sample
Calls the sample loaded last with input and keeps the text of its answer for output_byte. Answers the text’s length in bytes where the call returned, -1 - length where it threw, and i32::MIN if no sample is loaded.
load
Loads a sample: initializes its module with the runtime value, and answers its default export, or what it threw.
output_byte
The indexth byte the last sample run wrote.
perform
Performs a sample’s entry: calls it with no arguments, and performs the effect it answers with an empty standard input. Answers what the sample wrote to standard output, or what it threw.
run_sample
Runs the sample loaded last and keeps its output. Answers the output’s length in bytes, or -1 if no sample is loaded or the sample threw.
spell
A value as the page spells it, as fjs/nanvm/demos/spell does for the JavaScript call: a string quoted as JSON quotes it, a bigint with its n, an array and an object with their nesting and no spaces, a function as (function), and anything else as String(value) spells it.

Type Aliases§

Module
A compiled module: what fjs compile writes as module, a function of the runtime value, on the VM the samples run on.