From a3e8c6388e4f4bb3b33b87e49d82fd5a9df631ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sun, 10 Jan 2021 14:09:27 +0100 Subject: rename vm::VMError -> vm::Error --- src/main.rs | 2 +- src/vm.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index f599011..ed85961 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ fn file_from_args() -> Option { std::env::args().skip(1).map(|s| Path::new(&s).to_owned()).find(|p| p.is_file()) } -fn run_file(path: &Path) -> Result<(), vm::VMError> { +fn run_file(path: &Path) -> Result<(), vm::Error> { let tokens = tokenizer::file_to_tokens(path); let block = compiler::compile("main", path, tokens); // path -> str might fail vm::run_block(block) diff --git a/src/vm.rs b/src/vm.rs index 5d8b5f8..ca541a0 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -89,7 +89,7 @@ pub enum VMErrorKind { } #[derive(Debug)] -pub struct VMError { +pub struct Error { kind: VMErrorKind, file: PathBuf, line: usize, @@ -112,7 +112,7 @@ impl fmt::Display for VMErrorKind { } } -impl fmt::Display for VMError { +impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let message = match &self.message { Some(s) => format!("\n{}", s), @@ -123,7 +123,7 @@ impl fmt::Display for VMError { } -pub fn run_block(block: Block) -> Result<(), VMError> { +pub fn run_block(block: Block) -> Result<(), Error> { let mut vm = VM { stack: Vec::new(), @@ -153,7 +153,7 @@ impl VM { self.stack.get(self.stack.len() - amount) } - fn error(&self, kind: VMErrorKind, message: Option) -> VMError { + fn error(&self, kind: VMErrorKind, message: Option) -> Error { let find_line = || { for i in (0..=self.ip).rev() { if let Some(line) = self.block.line_offsets.get(&i) { @@ -163,7 +163,7 @@ impl VM { return 0; }; - VMError { + Error { kind, file: self.block.file.clone(), line: find_line(), @@ -171,7 +171,7 @@ impl VM { } } - pub fn run(&mut self) -> Result<(), VMError>{ + pub fn run(&mut self) -> Result<(), Error>{ const PRINT_WHILE_RUNNING: bool = true; const PRINT_BLOCK: bool = true; -- cgit v1.2.1