Skip to main content

Crate funct

Crate funct 

Source
Expand description

funct — a small functional embeddable language (see docs/funct-spec.md).

Highlights:

  • stack-based bytecode VM with fully reified state: pause between any two instructions, inspect, snapshot (Clone), serialize to disk, resume
  • |> pipes + UFCS, real pattern matching, Result/Option + ?
  • atoms as the only escaping mutable state (capture/restore them)
  • hot reload by name-keyed function table
  • frictionless Rust interop (register1, register_type, call_typed)

Re-exports§

pub use interop::FromValue;
pub use interop::ToValue;
pub use value::Value;
pub use value::VariantPayload;
pub use vm::Cause;
pub use vm::Fault;
pub use vm::Funct;
pub use vm::FunctError;
pub use vm::RunResult;
pub use vm::Status;
pub use vm::StepResult;
pub use vm::StopWhen;
pub use vm::VmState;

Modules§

ast
AST. Pipes and UFCS sugar are desugared by the parser, so the compiler never sees |>.
bytecode
Bytecode. Everything here is plain serializable data — protos (and thus whole programs) can be written to disk and reloaded.
compiler
AST → bytecode compiler.
interop
Rust interop: value conversions, function registration, host types.
json
Conversions between funct Value and serde_json::Value, for host protocols that cross thread/process boundaries as JSON (render frames, state snapshots, message-bus payloads).
lexer
Lexer. Newlines are significant (statement terminators) per spec §3.1: a Newline token is suppressed when the previous token can’t end a statement (operator, comma, open bracket, |>, =>, …) or when the next line starts with a continuation token (|>, ., else, closing bracket, …).
parser
Recursive-descent parser. Desugars |> pipes (with _ holes), UFCS method-call syntax, subjectless match, and string interpolation.
prelude
Prelude: built-in natives (atoms, I/O, basics) plus a small stdlib written in funct itself (map/filter/fold/…), compiled at engine startup.
snapshot
Serialization of VM state to disk (spec §6.2 “serializable for save/restore” + §7 atom externalization).
testing
Test runner for tests written in funct itself.
value
Runtime values. All non-Atom values are immutable with structural sharing (shared-pointer clone-on-write). Atom is the only user-visible mutable cell; Cell is the internal slot used for captured let mut locals.
vm
The engine + reified VM.

Macros§

vals
Convert Vec<impl ToValue>-ish heterogeneous args: vals![1, "x", 2.0].