1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00

feat: more verbose-y log

This commit is contained in:
Natapat Samutpong 2022-01-26 11:05:42 +07:00
parent 7618eaa04a
commit 2416a77f61
2 changed files with 37 additions and 5 deletions

View file

@ -33,7 +33,7 @@ impl Display for Register {
#[derive(Clone, Debug)]
pub enum Instr {
// Load a literal value onto the stack.
Load { address: Register, label: usize },
// Load { address: Register, label: usize },
// Store a literal value into a register.
Store { address: Register, value: Type, label: usize },
// Call intrinsic function.
@ -53,7 +53,7 @@ pub enum Instr {
impl Display for Instr {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Instr::Load { address, label } => write!(f, "{}: LOAD {}", label, address),
// Instr::Load { address, label } => write!(f, "{}: LOAD {}", label, address),
Instr::Store { address, value , label} => write!(f, "{}: STORE {} {}", label, address, value),
Instr::Call { address, args, label } => write!(f, "{}: CALL {} {}", label, address, args),
Instr::IAdd { lhs, rhs, to, label } => write!(f, "{}: IADD {} {} {}", label, lhs, rhs, to),

View file

@ -1,4 +1,4 @@
use std::{fs::{read_to_string, File}, path::Path, io::Write};
use std::{fs::{read_to_string, File}, path::Path, io::Write, time::Instant};
use structopt::StructOpt;
@ -15,6 +15,7 @@ mod compiler;
use compiler::compile::Compiler;
fn main() {
let start = Instant::now();
let args = Args::from_args();
let src = cover_paren(read_to_string(&args.file).unwrap());
@ -29,14 +30,45 @@ fn main() {
let mut file = File::create(format!("{}.bbb", file_name)).unwrap();
let mut compiler = Compiler::new();
let before = Instant::now();
for instr in compiler.compile(result.unwrap(), 0).unwrap() {
write!(file, "{}\n", instr).unwrap();
}
let spent = before.elapsed();
let total = start.elapsed();
println!("Compiled in {}.{}s, Total of {}.{}s", spent.as_secs(), spent.subsec_millis(), total.as_secs(), total.subsec_millis());
},
1 => {
println!("Parsed AST: {:#?}", result);
let mut file = File::create(format!("{}.bbb", file_name)).unwrap();
let mut compiler = Compiler::new();
let before = Instant::now();
for instr in compiler.compile(result.unwrap(), 0).unwrap() {
write!(file, "{}\n", instr).unwrap();
}
let spent = before.elapsed();
let total = start.elapsed();
println!("Compiled in {}.{}s, Total of {}.{}s", spent.as_secs(), spent.subsec_millis(), total.as_secs(), total.subsec_millis());
},
1 => println!("{:?}", result),
2 | _ => {
println!("Tokens: {:?}", tokens);
println!("Parsed: {:#?}", result);
println!("Parsed AST: {:#?}", result);
let mut file = File::create(format!("{}.bbb", file_name)).unwrap();
let mut compiler = Compiler::new();
let before = Instant::now();
for instr in compiler.compile(result.unwrap(), 0).unwrap() {
write!(file, "{}\n", instr).unwrap();
}
let spent = before.elapsed();
let total = start.elapsed();
println!("Compiled in {}.{}s, Total of {}.{}s", spent.as_secs(), spent.subsec_millis(), total.as_secs(), total.subsec_millis());
}
}
}