start bytecode compilation

This commit is contained in:
nora 2021-12-29 17:00:30 +01:00
parent b35d12e041
commit c6765d7da6
14 changed files with 342 additions and 46 deletions

View file

@ -1,8 +1,12 @@
#![deny(clippy::disallowed_type)]
mod ast;
mod bird;
mod bytecode;
mod compile;
mod errors;
mod lex;
mod parse;
mod value;
pub use lex::*;
pub use parse::*;
@ -15,14 +19,23 @@ pub fn run_program(program: &str) {
let tokens = success.into_iter().collect::<Result<Vec<_>, _>>().unwrap();
println!(
"{:?}",
"Tokens:\n{:?}\n",
tokens.iter().map(|token| &token.kind).collect::<Vec<_>>()
);
let ast = parse::parse(tokens);
match ast {
Ok(ast) => println!("{:?}", ast),
Ok(ast) => {
println!("AST:\n{:?}\n", ast);
let bytecode = compile::compile(&ast);
match bytecode {
Ok(code) => println!("Bytecode:\n{:#?}\n", code),
Err(err) => errors::display_error(program, err),
}
}
Err(err) => errors::display_error(program, err),
}
} else {