Shared trait and types for the OtherFunc interpreter ecosystem.
Defines the Interpreter trait that all language crates implement, plus supporting types for async I/O and execution statistics.
Interpretertrait —execute(code, input) -> Result<String, String>, with optionalexecute_with_io/resume_with_iofor coroutine-style HTTP outbound andset_envfor injecting secretsIoRequest— enum yielded when an interpreter needs external I/O:HttpRequest { url, method, headers, body }orKvRequest { op, key, value }KvOp—Get,Set, orDeletefor persistent key-value storageExecResult—Complete(String)orNeedsIo(IoRequest), returned byexecute_with_ioExecutionStats—instructions_executed: u64+execution_time: Duration
use otherfunc_core::Interpreter;
// All interpreter crates (otherfunc-brainfuck, otherfunc-forth, etc.)
// implement this trait:
fn run(interp: &mut dyn Interpreter, code: &str) -> Result<String, String> {
interp.execute(code, "")
}use otherfunc_core::{ExecResult, Interpreter};
fn run_with_io(interp: &mut dyn Interpreter, code: &str) -> Result<String, String> {
match interp.execute_with_io(code, "")? {
ExecResult::Complete(output) => Ok(output),
ExecResult::NeedsIo(req) => {
let response = "..."; // fulfill the I/O request
match interp.resume_with_io(response)? {
ExecResult::Complete(output) => Ok(output),
ExecResult::NeedsIo(_) => todo!("loop until complete"),
}
}
}
}cargo test -p otherfunc-core