core:eval
Compile and run a Wado program from a test.
[eval] takes a whole program as one source string, compiles it as a
wasi:cli/command, runs it, and returns what it wrote and how it stopped.
It is for testing code generators: generate a program, evaluate it, and
assert on its output.
Only wado test supports it, and a program for any other world that
reaches this module does not compile. The evaluated program gets nothing
but stdout, stderr and exit: no arguments, stdin, environment, files,
clock, randomness or network. Its use items may name core:* and nothing
else. Every outcome but a compile timeout is cached, keyed by the compiler,
the knobs, the budget and the source. See WEP 2026-09-26 (Eval).
Synopsis
let out = eval(`use { println, Stdout } from "core:cli";
export fn run() with Stdout { println("hello"); }`).unwrap();
assert out.status matches { Exited(0) };
assert out.stdout == "hello\n";
Globals
pub global DEFAULT_FUEL: u64
The fuel an evaluated program runs on unless the caller names another
budget. Running out stops it with [Status::OutOfFuel].
Functions
pub fn eval(source: String, fuel: u64 = DEFAULT_FUEL) -> Result<Output, EvalError>
#[benign(EvalHost)]
Compiles source as a wasi:cli/command program and runs it under fuel.
Err means the program never ran. Ok means it ran, however it stopped;
Output.status says how. stdout and stderr are decoded as UTF-8, with
U+FFFD where the bytes are not.
Structs
pub struct Output
What a program that ran wrote, and how it stopped. Output written before a trap is kept.
stdout: String
stderr: String
status: Status
pub struct CompileFailure
A source that did not compile.
rendered: String
The report wado compile would print.
codes: List<String>
The Code of each error, in report order.
Variants
pub variant EvalError
Why a program never ran.
CompileFailed(CompileFailure)
CompileTimedOut
The compile ran past the host's time limit.
Unavailable(String)
The program imports an interface the host does not link; the payload names it.
pub variant Status
How a program that ran came to stop.
Exited(i32)
Trapped(TrapKind)
OutOfFuel
OutOfMemory
Enums
pub enum TrapKind
Why a run stopped with a trap.
