2023-04-14 15:27:24 +02:00
|
|
|
mod bc;
|
2023-04-12 12:46:24 +02:00
|
|
|
mod lc;
|
2023-04-14 15:27:24 +02:00
|
|
|
mod vm;
|
2023-03-29 20:03:16 +02:00
|
|
|
|
2023-04-12 12:46:24 +02:00
|
|
|
use std::env;
|
|
|
|
|
|
|
|
|
|
fn repl() {
|
2023-04-14 15:27:24 +02:00
|
|
|
|
2023-04-12 12:46:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn run_file() {
|
|
|
|
|
|
|
|
|
|
}
|
2023-04-04 19:03:57 +02:00
|
|
|
|
2023-04-04 20:34:36 +02:00
|
|
|
fn main() {
|
2023-04-12 12:46:24 +02:00
|
|
|
|
|
|
|
|
let num_args = env::args().len();
|
2023-10-08 11:20:00 +02:00
|
|
|
let mut chunk = bc::Chunk::new();
|
2023-04-12 12:46:24 +02:00
|
|
|
|
2023-10-08 11:20:00 +02:00
|
|
|
lc::compile("print(1+2*3)", &mut chunk);
|
2023-04-12 12:46:24 +02:00
|
|
|
|
|
|
|
|
if num_args == 1 {
|
|
|
|
|
repl();
|
|
|
|
|
} else if num_args == 2 {
|
|
|
|
|
run_file();
|
|
|
|
|
} else {
|
|
|
|
|
println!("Usage: rlox [path]");
|
|
|
|
|
}
|
2023-03-29 20:03:16 +02:00
|
|
|
}
|
2023-10-08 11:20:00 +02:00
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use crate::{bc::Chunk, lc::compile, vm::VM};
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_compile_and_run_pi_math() {
|
|
|
|
|
let source = "-(3 * 7 * 11 * 17) / -(500 + 1000 - 250)";
|
|
|
|
|
let mut chunk = Chunk::new();
|
|
|
|
|
compile(source, &mut chunk);
|
|
|
|
|
let mut vm = VM::new();
|
|
|
|
|
vm.run(&chunk).unwrap();
|
|
|
|
|
}
|
|
|
|
|
}
|