updated a bunch of stuff

This commit is contained in:
Moritz Gmeiner 2024-09-01 19:16:30 +02:00
commit 67bb5fe8fd
24 changed files with 675 additions and 694 deletions

View file

@ -10,6 +10,9 @@ struct CliArgs {
#[arg(long, action = ArgAction::SetTrue)]
vm: bool,
#[arg(long, action=ArgAction::SetTrue)]
debug: bool,
}
/*
@ -22,7 +25,8 @@ fn main() {
let cli_args = CliArgs::parse();
if cli_args.vm {
use rlox2_vm::LoxError;
unimplemented!()
/* use rlox2_vm::LoxError;
let mut vm = rlox2_vm::VM::default();
@ -35,7 +39,9 @@ fn main() {
if let Err(err) = rlox2_vm::run(&source, &mut vm) {
eprintln!("{err}");
match err {
LoxError::LexerError { .. } | LoxError::CompileError { .. } => std::process::exit(65),
LoxError::LexerError { .. } | LoxError::CompileError { .. } => {
std::process::exit(65)
}
LoxError::RuntimeError { .. } => std::process::exit(70),
LoxError::Exit { exit_code } => std::process::exit(exit_code),
}
@ -46,12 +52,14 @@ fn main() {
}
}
rlox2_vm::run_repl(&mut vm);
rlox2_vm::run_repl(&mut vm); */
} else {
use rlox2_interpreter::LoxError;
let mut runtime = rlox2_interpreter::Runtime::default();
runtime.set_debug(cli_args.debug);
if let Some(file_name) = cli_args.file_name {
let source = std::fs::read_to_string(&file_name).unwrap_or_else(|err| {
eprintln!("Reading script file {file_name} failed: {err}");
@ -61,9 +69,9 @@ fn main() {
if let Err(err) = rlox2_interpreter::run(&source, &mut runtime) {
eprintln!("{err}");
match err {
LoxError::LexerError { .. } | LoxError::ParserError { .. } | LoxError::ResolverError { .. } => {
std::process::exit(65)
}
LoxError::LexerError { .. }
| LoxError::ParserError { .. }
| LoxError::ResolverError { .. } => std::process::exit(65),
LoxError::RuntimeError { .. } => std::process::exit(70),
LoxError::Exit { exit_code } => std::process::exit(exit_code),
}