nanvm_lib/vm/internal/ifunction.rs
1use crate::vm::{Any, Array, IVm};
2
3use super::IComplex;
4
5/// A function: what a program can do with one, and nothing it cannot.
6///
7/// A program can call a function, read its `length`, read its text, and
8/// compare it by identity. It cannot look inside one — the language has no
9/// function constructor, and the text is a rendering of the code, not the
10/// code — so how a VM
11/// represents a function, a Rust static function, an EDAG it interprets, or
12/// both, is the VM's own, and nothing here depends on the choice. There is
13/// no constructor here for the same reason: construction is each VM's own
14/// capability, [`IStaticFunction`](super::IStaticFunction) for one.
15pub trait IFunction<A: IVm>: IComplex<A> {
16 fn call(&self, args: Array<A>) -> Result<Any<A>, Any<A>>;
17 fn length(&self) -> u32;
18 /// The function's text, `String(f)`, or `None` for a function that has
19 /// none: see [`IStaticFunction`](super::IStaticFunction).
20 fn text(&self) -> Option<&'static str>;
21}