Skip to main content

Crate warp_runtime

Crate warp_runtime 

Source
Expand description

Running compiled warp programs without the compiler: warp links this crate for its own runs, and its binary warp-runtime (main.rs) is the standalone executable warp build appends a program’s machine code to (notes/aot.md)

Modules§

c_calls
Calling C from a program, for a store of any state that keeps the run’s C handles: loading libraries, the hand-linked libc functions, and one wrapper for every C function as c_signatures.rs describes it. warp links these after reading the headers (src/ffi/link.rs); an executable links the functions it carries (standalone.rs)
c_signatures
C functions as warp calls them, without their headers: how each parameter and the result cross (notes/ffi_handles.md). warp reads a library’s headers into these (src/ffi); an executable carries the ones its program imports in front of its machine code, so the stub links them without reading a header (c_calls.rs, card exe-c-ffi)
c_structs
C structs as warp maps (card wasmtime-ffi): a struct a header defines (wasmtime_instance_t {uint64_t store_id; size_t __private;}) has a layout by the C rules of LP64 platforms; a call writes a map into its bytes and reads them back as one. Numbers are numbers, pointers handle ids, arrays lists, nested structs and unions maps (a union read back holds each of its members, the same bytes seen as each). A layout travels as text, so an executable carries it with the C function: {store_id:u64,__private:u64}, a union in <…>, an array [u8;16], a pointer ptr; a field without a name is an anonymous member (C11), its fields the struct’s own
engine
floats
Floats as a run shows them (P119)
foreign
The bridge of foreign_call(runtime, module, member, arguments) (warp’s lowering/foreign/foreign_modules.rs, notes/stdlib_connectors.md), shared by warp and its executables (card exe-foreign): one long-lived child per runtime and process, started on first use, speaking one JSON line per request and per answer. Python: python3 -u running FOREIGN_PYTHON_LOOP (WARP_PYTHON names another interpreter); JavaScript: node running FOREIGN_JS_LOOP (WARP_NODE), a global (Math) or a module it requires. A read gives the member itself, a call gives its result (a promise awaited); an exception is an error with the runtime’s message. A value without a JSON form stays in its runtime behind an id, a handle: it crosses as the record {$handle: 7, type: "date", text: "datetime.date(2020, 1, 2)"} and is that object again when it comes back, as an argument or as the receiver of d.isoformat() (the module position). Handles live until the process ends. A warp function given as an argument crosses as {$warp_function: 0}, its index among the call’s functions; node calls it back with the line {callback: 0, arguments: […]} and waits for its {value} or {error} (card js-callbacks).
fuel
gc_values
Warp’s GC Nodes (CLAUDE.md “Serialization”, warp’s type_kinds.rs) as JSON and back, for an executable’s foreign calls (card exe-foreign): what warp does with json_of(node_in(…)) and Builders::build(TaskValue::of(node_of(…))), without warp’s Node. warp’s tests/wasm/test_executable_foreign.rs holds these codes equal to warp’s.
host_words
The words of the program’s environment, imported from the “host” module and called like C functions: sleep_ms(ms) pauses, random() is a float in [0, 1), random_below(n) an int in 0..n, clock() the milliseconds since the Unix epoch. A program that defines a word of the same name keeps its own. warp adds the words that need its compiler, the network or threads (host.rs); these need nothing. signal_poll() and signal_listen(kind, id, argument) serve the handlers of system signals (system_signals.rs).
libm
The libm functions programs import from “m” (cos(x), pow(x, y) …), for a store of any state: Rust’s own f64 functions, so a standalone executable loads no C library (warp itself links the system’s libm, ffi.rs)
macho
Just enough of 64-bit Mach-O (macOS executables) to carry a program so the executable still signs cleanly: codesign wants every byte of the file inside a segment, its signature last. The carried program goes at the end of the last segment (__LINKEDIT), whose size grows to cover it; the old signature is dropped first. Anything that is not a 64-bit little-endian Mach-O (Linux’s ELF) passes unchanged.
output
The one WASI call warp programs make, fd_write (print), for a store of any state: the warp-runtime stub needs no WASI library
profile
WARP_PROFILE=: where a run spends its time, sampled at each epoch tick with wasmtime’s GuestProfiler and written as Firefox Profiler JSON when the run’s store drops (open it at https://profiler.firefox.com). Samples are taken at function entries and loop headers of the wasm, host calls show as markers. Engines counting fuel don’t tick, so their runs give no samples.
site_files
The files of a site (warp build --site, src/web/site.rs in warp) and how a request path finds one, shared by warp’s servers and web view and by an app warp build made: the stub carrying a site packed (card build-links)
standalone
A standalone executable is the warp-runtime stub carrying a program’s machine code: <executable><machine code, deflated><its length, u64 little-endian><TRAILER_MAGIC><zeros to a multiple of 16>, then, in a Mach-O executable, its code signature: the machine code lies inside the __LINKEDIT segment, so the executable signs and verifies cleanly (codesign --verify --strict, macho.rs). At start the executable looks for the trailer where its program would end and runs what it carries.
system_signals
System signals (notes/system_signals.md): handlers of events from outside the program, exported functions the runtime calls at check points: signal_poll() (at the start and end of main and at each loop start of a program with such handlers) and sleep, which wakes for them. on interrupt {…} is on·interrupt, run after a ctrl-c: the first poll installs the ctrl-c handler (Unix SIGINT, Windows SetConsoleCtrlHandler), which only sets a flag; a second ctrl-c within a second, or before the handler ran, ends the run at once (exit code 130), so a handler that ignores ctrl-c never makes a program unstoppable. on every 5 seconds {…} is on·every·0, started by signal_listen(0, 0, 5000) where the handler is declared. on file "notes.txt" change {…} is on·file·0, started by signal_watch(0, "notes.txt"): a timer of FILE_CHECK_PERIOD that fires only when the file’s modification time or size changed (it appeared, was written, or went). users := fetch url runs on·fetch·0 once the reply arrived (await_ready, src/web/fetches.rs). A run that allows it (warp run, built executables) stays after main while a timer or watch lives.
system_values
System values (notes/system_signals.md, P136): battery (percent), charging, online and dark mode read the machine’s state through the host word system_value(name), an i64 (booleans 0 or 1). Listeners on them (whenever battery < 20% {…}) compare readings at the program’s check points, so a reading is kept for READING_LIFETIME: a sleeping program polls often, the platform is asked at most once a second per value. macOS asks pmset and defaults, Linux /sys and gsettings; online is whether a route to the internet exists (a UDP connect sends nothing). A value the platform cannot give is a loud error, never a made-up reading. mouse_x, mouse_y, mouse_down: natively the pointer over the paint window (window_input), read each time; mouse_wheel the wheel steps turned over it (wheel); key_down whether a key is held over it, key code held which (lowering/signals/system_values.rs names it held_key); window_open whether that window shows; read before any paint, it opens the window (blank) where one can show. window_width, window_height (window.width, card make-width): the paint window’s inner size in points as it reports it, else as last written, else the view’s; writing one resizes the window through the warp binary’s resizer. display_width, display_height: the main screen’s size in points, read only; display_dpi its device pixels per inch (CoreGraphics’ physical size, xrandr’s millimetres), read only. The clipboard is watched by its change count, which reads no content: macOS asks the user before a program reads what another one copied, so the text is read only when the program asks for it (clipboard, clipboard_text).