mikro

Crates.iomikro
lib.rsmikro
version0.1.2
created_at2025-08-20 23:41:07.693222+00
updated_at2025-08-21 19:23:12.465117+00
descriptionembeddable mikro interpreter for Rust apps
homepage
repository
max_upload_size
id1804084
size30,684
(WebAppEnjoyer)

documentation

README

mikro

micro is an embedded commands language for rust which supports: variables, if/else, for identifier in range loops and integration with a host state of any type (trough generics).

Defining a mikro function

fn print(args: &[Value], st: &mut State, i: &mut Interner) -> Result<Value, RuntimeError> {
        for (idx, v) in args.iter().enumerate() {
            if idx > 0 { st.out.push(' '); }
            match v {
                Value::Int(x) => st.out.push_str(&x.to_string()),
                Value::Float(x) => st.out.push_str(&x.to_string()),
                Value::Bool(x) => st.out.push_str(&x.to_string()),
                Value::Str(sym) => st.out.push_str(i.resolve(*sym)),
                Value::Unit => st.out.push_str("unit"),
            }
        }
        st.out.push('\n');
        Ok(Value::Unit)
}

Making a new interpreter out of a phf::Map of mikro function


static BUILTINS: mikro::Map<&'static str, Builtin<State>> = mikro::phf_map! {
        "print"  => print as Builtin<State>
};

struct State{}

fn main() {
let code = r#"
a = 0
print(a)
"#;    
let mut interpreter = Interpreter::<State>::new(&BUILTINS);
interpreter.run(&mut State{},code);
}
Commit count: 0

cargo fmt