aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-01-10 14:09:27 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-01-10 14:09:27 +0100
commita3e8c6388e4f4bb3b33b87e49d82fd5a9df631ce (patch)
tree2ff24a067b388992946408b67093f4b6a491e0c0
parentd42c86f010abf52e3853760bbbadb888517d7afe (diff)
downloadsylt-a3e8c6388e4f4bb3b33b87e49d82fd5a9df631ce.tar.gz
rename vm::VMError -> vm::Error
-rw-r--r--src/main.rs2
-rw-r--r--src/vm.rs12
2 files changed, 7 insertions, 7 deletions
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<PathBuf> {
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<String>) -> VMError {
+ fn error(&self, kind: VMErrorKind, message: Option<String>) -> 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;