add nostd example
This commit is contained in:
parent
e0ffe2a858
commit
a806471a0a
2 changed files with 26 additions and 0 deletions
|
@ -24,3 +24,7 @@ path = "example/repl.rs"
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "run"
|
name = "run"
|
||||||
path = "example/run.rs"
|
path = "example/run.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "no_std"
|
||||||
|
path = "example/no_std.rs"
|
||||||
|
|
22
example/no_std.rs
Normal file
22
example/no_std.rs
Normal file
|
@ -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()),
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue