add loop examples
This commit is contained in:
parent
6350e4a40f
commit
dbeec4ee76
5 changed files with 110 additions and 49 deletions
|
@ -1,15 +1,21 @@
|
|||
use std::{env::args, fs};
|
||||
|
||||
use microlang::Context;
|
||||
use microlang::{Context, Value};
|
||||
|
||||
pub fn main() {
|
||||
unsafe { backtrace_on_stack_overflow::enable() };
|
||||
let mut context = Context::empty();
|
||||
let lines = fs::read_to_string(args().nth(1).expect("Pass a file as arg 1.")).expect("File could not be read.");
|
||||
for line in lines.lines() {
|
||||
match context.eval(line.into()) {
|
||||
Err(err) => panic!("Failed : {err:?}"),
|
||||
Ok((_, value)) => println!("{}", value.serialize()),
|
||||
context.define_built("print", |values, _| {
|
||||
for val in values {
|
||||
print!("{} ", val.serialize());
|
||||
}
|
||||
println!();
|
||||
Ok(Value::None)
|
||||
});
|
||||
|
||||
let lines = fs::read_to_string(args().nth(1).expect("Pass a file as arg 1.")).expect("File could not be read.");
|
||||
match context.eval(lines) {
|
||||
Err(err) => panic!("Failed : {err:?}"),
|
||||
Ok((_, value)) => println!("{}", value.serialize()),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue