diff --git a/Cargo.toml b/Cargo.toml index ff9f776..ffe8671 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,3 +24,7 @@ path = "example/repl.rs" [[bin]] name = "run" path = "example/run.rs" + +[[bin]] +name = "no_std" +path = "example/no_std.rs" diff --git a/example/no_std.rs b/example/no_std.rs new file mode 100644 index 0000000..468bee4 --- /dev/null +++ b/example/no_std.rs @@ -0,0 +1,22 @@ +#![no_std] + +use alloc::string::ToString; +use microlang::Context; + +extern crate alloc; + +pub fn main() { + // Context instantiation. + let mut context = Context::empty(); + + // Script to evaluate. + let lines = include_str!("./data/hello_world.mc"); + + // Script evaluation. + match context.eval(lines.to_string()) { + // May return errors raised during parsing or actual evaluation. + Err(err) => panic!("Failed : {err:?}"), + // Success returns the parsed AST alongside the value resulting from the evaluation. + Ok((_, value)) => assert_eq!(value.serialize(), "hello world".to_string()), + } +}