Expand description
Konjure’s reusable language: nominal types, algebraic enums, methods, traits, functions, and persistent ECS systems with typed lifecycle callbacks.
The Rust implementation is shared unchanged by native and WASM clients. compile
resolves supplied modules and checks every initializer, default, and function or
callback body, including unused declarations. Machine preserves those checked
types, validates runtime values and world operations, and publishes only accepted
state. Source spans and deterministic snapshots are part of the public interface.
use konjure_lang::{compile, Machine, Limits, Value};
use std::collections::BTreeMap;
let program = compile("func twice(x: f64) -> Res[f64, DataError] { ret Ok((x * 2)?); }", &BTreeMap::new()).unwrap();
let mut machine = Machine::new(program, Limits::default())?;
assert_eq!(machine.invoke("twice", vec![Value::Number(3.)])?.to_string(), "Ok(6)");Type methods are checked before any machine exists:
use konjure_lang::compile;
use std::collections::BTreeMap;
let source = "type Counter { value: Number = 0; func read() -> Number { ret self.value; } }";
assert!(compile(source, &BTreeMap::new()).is_ok());
let invalid = "type Counter { func unused() -> Number { ret false; } }";
assert!(compile(invalid, &BTreeMap::new()).is_err());Functions are ordinary statically typed values. Named language and registered
native functions can be passed, returned, stored in lists and fields, and called
through arbitrary expressions. Polymorphic builtins such as print specialize
when an expected concrete function signature is available:
use konjure_lang::{compile, Limits, Machine};
use std::collections::BTreeMap;
let source = r#"
func report(output: func(String) -> Unit) -> Unit {
output("hello");
}
report(print);
"#;
let machine = Machine::new(compile(source, &BTreeMap::new()).unwrap(), Limits::default())?;
assert_eq!(machine.snapshot().logs, ["hello"]);Button.action stores func() -> Res[Unit, DataError]; Slider.action stores
func(Number) -> Res[Unit, DataError]. Hosts invoke these Rust-owned values with
Machine::invoke_component, without reconstructing a function name from JSON.
A read-only bound method captures a record copy. Mutating callbacks explicitly
use bind[T](entity).method to retain the entity/component identity and commit
receiver edits transactionally. The checker rejects capturing a mutating method
from a copied record. Anonymous closures are not part of the current syntax.
Numeric operations and indexing produce Res[T, DataError]; owned get
methods produce Opt[T]. Exhaustive match handles cases, and ? returns an
error or absence from a compatible result-returning function. Ordinary
Machine::invoke returns algebraic failures as values. Module initialization,
system callbacks and spatial::SpatialRuntime actions are host transaction
boundaries: an error result rejects that boundary with a source diagnostic.
Resource exhaustion and violated host contracts remain host diagnostics.
Re-exports§
pub use live::LiveClientMessage;pub use live::LiveCommand;pub use live::LiveDebugReport;pub use live::LiveDebugStatus;pub use live::LiveDiagnostic;pub use live::LiveError;pub use live::LiveEvent;pub use live::LiveHistory;pub use live::LivePeer;pub use live::LiveRole;pub use live::LiveRuntime;pub use live::LiveServerMessage;pub use live::ProgramSource;pub use diagnostics::render_diagnostic;pub use ast::Diagnostic;pub use ast::IndexExpr;pub use ast::Span;pub use ast::Type;pub use native::NativeFunction;pub use native::NativeRegistry;pub use parser::parse;pub use parser::tokenize;
Modules§
- ast
- Source-preserving syntax nodes used by the parser and interpreter.
- catalog
- Rust-owned standard-library declarations and executable reference documentation.
- diagnostics
- Terminal diagnostics render the same byte spans used by browser tooling.
- inspection
- Read-only access to accepted values. Inspection never evaluates source or invokes a method.
- live
- Deterministic, replayable command journal for a live language session.
- methods
- Checked signatures for native operations owned by their receiver types.
- native
- Explicit native-function boundary. Registered functions must be pure and bounded.
- parser
- Bounded lexer and parser for Konjure source modules.
- spatial
- Validated scene adaptation and fixed-step rigid-body simulation.
- ui
- Rust-owned projection of language controls into portable semantic UI.
Structs§
- Component
Reference - An entity handle paired with a concrete component identity, created by
bind[T]. - Entity
Snapshot - One stable entity with at most one component of each nominal class.
- Enum
Value - A checked algebraic case carrying its canonical nominal or applied type.
- Expression
Reference - Compiler-resolved source identity for an editor inspector. Inspectors do not evaluate source.
- Function
Value - An inspectable callable identity and canonical static signature. Values contain no executable code or host pointer. Machine entry points validate deserialized identities.
- Limits
- Resource bounds apply to each initialization, invocation, and tick.
- Machine
- A linked program and its persistent state. Clone creates an independent checkpoint.
- Method
Symbol - A callable component method, used by host action controls.
- Program
- Linked program. It owns all source text; imports never access the filesystem or network.
- Program
Metadata - Source-level semantic metadata for a program whose declarations and bodies are checked.
- Record
Value - A nominal type instance, copied by value at language boundaries.
- Snapshot
- Immutable inspection output. All maps and entity queries use stable ordering.
- Symbol
- A declaration available to editor navigation and generated reference pages.
- Trace
Entry - A bounded chronological execution record, linked to the exact source expression.
Enums§
- Function
Target - Stable callable identity included in an inspectable
FunctionValue. - Value
- Stable JSON representation shared by native and WebAssembly hosts.
Functions§
- compile
- Parse declarations, resolve explicit module imports, and validate type/trait contracts.
- compile_
with_ registry - Compile with explicit pure host signatures available to the static checker. The machine must receive a registry with these same signatures.