Expand description
§MiraScript for Rust
mirascript is the batteries-included Rust interface to the MiraScript compiler
and virtual machine. It re-exports the complete mirascript-vm API, including
the MiraRecord and MiraArray derive macros.
Compilation and execution are independent. A compiled script is reusable, while the runtime owns globals, standard-library values, execution state, and its arena:
use mirascript::{MiraValue, Runtime, compile};
let script = compile("answer + 1")?;
let mut runtime = Runtime::new();
runtime.insert_global("answer", 41)?;
assert_eq!(runtime.run(&script)?, MiraValue::number(42.0));Compiler configuration and bytecode definitions are available through core,
and the complete runtime crate is also available as vm.
let config = mirascript::core::CompileConfig::new();
let script = mirascript::compile_with("40 + 2", &config)?;
let mut runtime = mirascript::Runtime::new();
assert_eq!(
runtime.run(&script)?,
mirascript::MiraValue::number(42.0),
);Re-exports§
pub use mirascript_vm as vm;
Modules§
- core
- mirascript-core
Macros§
- global_
builtin - A macro to define a global builtin function and insert it into the runtime.
Structs§
- Compile
Config - Diagnostics
- Represents a diagnostic message produced by the compiler.
- Mira
Array Entry - One element produced by
MiraArray::iter. - Mira
Handle - A compact, runtime-checked handle to an arena-managed value.
- Mira
Native Fn - A named, single-threaded native function callable from MiraScript.
- Mira
Record Entry - One field produced by
MiraRecord::iter. - Mira
Script - A validated, reusable MiraScript program.
- Mira
Value - A compact value understood by the Rust VM.
- RunOptions
- Limits and injectable providers used for each Runtime execution.
- Runtime
- Persistent state used to execute compiled MiraScript programs.
- Runtime
Trace - Runtime source location and call stack attached to an execution error.
- Script
Id - Stable identity shared by clones of one compiled script.
Enums§
- Conversion
Path Segment - One segment in a failed Rust value conversion path.
- Conversion
Reason - The reason a MiraScript value could not be converted to a Rust type.
- Diagnostic
Code - Diagnostic codes for MiraScript compiler and tools.
- Diagnostic
Position Encoding - Encoding for counting positions in diagnostics.
- Input
Mode - Mode for reading input.
- Invalid
Bytecode Reason - Represents the reason for an invalid bytecode error.
- Mira
Error - An error produced while compiling, decoding, executing, or bridging values.
- Mira
Manageable - An owned value waiting to be inserted into a Runtime arena.
- Mira
Type - A MiraScript runtime value category.
- Runtime
Error Kind - A VM or standard-library execution failure.
Traits§
- Mira
Array - A read-only MiraScript array view.
- Mira
Extern - Reserved marker for a future MiraScript external value implementation.
- Mira
Function - A callable MiraScript function implementation.
- Mira
Module - A named collection of MiraScript-visible values.
- Mira
Record - A read-only MiraScript record view.
- Mira
Shaped Array - A fixed-shape array whose length is known from its Rust type.
- Mira
Shaped Record - A fixed-shape record whose field names are known from its Rust type.
- Runtime
Providers - Host capabilities used by non-deterministic standard-library functions.
- TryFrom
Mira - A trait for converting values from the runtime into Rust types.
Functions§
- compile
- Compile source with the default compiler configuration.
- compile_
with - Compile source with an explicit
CompileConfig. - default_
runtime_ providers - Return a reference-counted handle to the default runtime providers.
Type Aliases§
- Mira
Array Handle - A handle to a MiraScript array value.
- Mira
Array Iter - A sequential iterator over array elements.
- Mira
Extern Handle - A handle to a MiraScript extern value.
- Mira
Function Handle - A handle to a MiraScript function value.
- Mira
Module Handle - A handle to a MiraScript module value.
- Mira
Record Handle - A handle to a MiraScript record value.
- Mira
Record Iter - A sequential iterator over record fields.
- Mira
String Handle - A handle to a MiraScript string value.
- Result
- Result type returned by the MiraScript VM.
Attribute Macros§
- mira
- Expose a Rust function or inline module as a MiraScript value.
Derive Macros§
- Mira
Array - Derive a read-only MiraScript array view for a tuple struct.
- Mira
Record - Derive a read-only MiraScript record view for a named-field struct.