aboutsummaryrefslogtreecommitdiffstats
path: root/src/vm.rs
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-01-10 14:06:38 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-01-10 14:06:38 +0100
commit78749296776b2d9b7cb1d03b93c97ceb32c8c0b3 (patch)
tree45b29dada0784b3b7c6264dae61169fe4ecaa84d /src/vm.rs
parentde8108932c3ac9ef1ea70ea5b0c74f369c36c442 (diff)
downloadsylt-78749296776b2d9b7cb1d03b93c97ceb32c8c0b3.tar.gz
take Paths where files are needed
Diffstat (limited to 'src/vm.rs')
-rw-r--r--src/vm.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/vm.rs b/src/vm.rs
index 530eeec..5d8b5f8 100644
--- a/src/vm.rs
+++ b/src/vm.rs
@@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::fmt;
+use std::path::{Path, PathBuf};
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub enum Value {
@@ -36,17 +37,17 @@ pub enum Op {
#[derive(Debug)]
pub struct Block {
name: String,
- filename: String,
+ file: PathBuf,
ops: Vec<Op>,
last_line_offset: Option<usize>,
line_offsets: HashMap<usize, usize>,
}
impl Block {
- pub fn new(name: &str, filename: &str) -> Self {
+ pub fn new(name: &str, file: &Path) -> Self {
Self {
name: String::from(name),
- filename: String::from(filename),
+ file: file.to_owned(),
ops: Vec::new(),
last_line_offset: None,
line_offsets: HashMap::new(),
@@ -90,7 +91,7 @@ pub enum VMErrorKind {
#[derive(Debug)]
pub struct VMError {
kind: VMErrorKind,
- filename: String,
+ file: PathBuf,
line: usize,
message: Option<String>,
}
@@ -117,7 +118,7 @@ impl fmt::Display for VMError {
Some(s) => format!("\n{}", s),
None => String::from(""),
};
- write!(f, "{}:{} [Runtime Error] {}{}", self.filename, self.line, self.kind, message)
+ write!(f, "{:?}:{} [Runtime Error] {}{}", self.file, self.line, self.kind, message)
}
}
@@ -164,7 +165,7 @@ impl VM {
VMError {
kind,
- filename: self.block.filename.clone(),
+ file: self.block.file.clone(),
line: find_line(),
message,
}