sylt_common/
lib.rs

1pub mod blob;
2pub mod block;
3pub mod error;
4pub mod op;
5pub mod flat_value;
6pub mod prog;
7pub mod ty;
8pub mod upvalue;
9pub mod value;
10
11use std::borrow::Cow;
12use std::cell::RefCell;
13use std::rc::Rc;
14
15pub use blob::Blob;
16pub use block::{Block, BlockLinkState};
17pub use error::Error;
18pub use op::{Op, OpResult};
19pub use prog::Prog;
20pub use ty::Type;
21pub use upvalue::UpValue;
22pub use value::{MatchableValue, Value};
23
24/// A linkable external function. Created either manually or using
25/// [sylt_macro::extern_function].
26pub type RustFunction = fn(RuntimeContext) -> Result<Value, error::RuntimeError>;
27
28#[derive(Debug)]
29pub struct Frame {
30    pub stack_offset: usize,
31    pub block: Rc<RefCell<Block>>,
32    pub ip: usize,
33    pub contains_upvalues: bool,
34}
35
36pub trait Machine {
37    fn stack_from_base(&self, base: usize) -> Cow<[Value]>;
38    fn blobs(&self) -> &[Blob];
39    fn eval_op(&mut self, op: Op) -> Result<OpResult, Error>;
40    fn eval_call(&mut self, callable: Value, args: &[&Value]) -> Result<Value, Error>;
41    fn args(&self) -> &[String];
42}
43
44pub struct RuntimeContext<'m> {
45    pub typecheck: bool,
46    pub stack_base: usize,
47    pub machine: &'m mut dyn Machine,
48}