add serialization of values
This commit is contained in:
parent
da82c775db
commit
6350e4a40f
5 changed files with 87 additions and 26 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::io::stdin;
|
||||
use std::io::{stdin, stdout, Write};
|
||||
|
||||
use microlang::Context;
|
||||
|
||||
|
@ -6,9 +6,14 @@ pub fn main() {
|
|||
unsafe { backtrace_on_stack_overflow::enable() };
|
||||
let mut context = Context::empty();
|
||||
loop {
|
||||
print!("> ");
|
||||
stdout().flush().ok();
|
||||
let mut line = String::new();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
let res = context.eval(line);
|
||||
dbg!(res).ok();
|
||||
match res {
|
||||
Ok((_, value)) => println!("{}", value.serialize()),
|
||||
Err(e) => println!("Error : {e:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
15
example/run.rs
Normal file
15
example/run.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
use std::{env::args, fs};
|
||||
|
||||
use microlang::Context;
|
||||
|
||||
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()),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue