Thanks to visit codestin.com
Credit goes to lib.rs

3 releases

Uses new Rust 2024

0.1.2 Aug 21, 2025
0.1.1 Aug 21, 2025
0.1.0 Aug 20, 2025

#1652 in Rust patterns

35 downloads per month

MIT license

25KB
579 lines

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);
}

Dependencies

~1–1.4MB
~25K SLoC