aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEdvard Thörnros <edvard.thornros@gmail.com>2021-02-17 21:56:34 +0100
committerEdvard Thörnros <edvard.thornros@gmail.com>2021-02-19 18:02:06 +0100
commiteca549af7e048ecddd61fcedd4202b1fe8948b1d (patch)
tree51b118405798de411f8fa843169aabe4301e9daf /src
parent5241e1243f285742a76289e53982587f2b9cb603 (diff)
downloadsylt-eca549af7e048ecddd61fcedd4202b1fe8948b1d.tar.gz
RuntimeTypeError -> ValueError
Diffstat (limited to 'src')
-rw-r--r--src/error.rs7
-rw-r--r--src/vm.rs16
2 files changed, 12 insertions, 11 deletions
diff --git a/src/error.rs b/src/error.rs
index deab89e..4e2209e 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -14,11 +14,12 @@ pub enum ErrorKind {
TypeError(Op, Vec<Type>),
/// (External function, parameters)
ExternTypeMismatch(String, Vec<Type>),
- RuntimeTypeError(Op, Vec<Value>),
+ ValueError(Op, Vec<Value>),
/// (Indexed value, length, index)
IndexOutOfBounds(Value, usize, usize),
+ /// Sanity checking errors
AssertFailed,
InvalidProgram,
Unreachable,
@@ -50,11 +51,11 @@ impl fmt::Display for ErrorKind {
ErrorKind::ExternTypeMismatch(name, types) => {
write!(f, "{} Extern function '{}' doesn't accept argument(s) with type(s) {:?}", "Type Error".bold(), name, types)
}
- ErrorKind::RuntimeTypeError(op, values) => {
+ ErrorKind::ValueError(op, values) => {
let values = values
.iter()
.fold(String::new(), |a, v| { format!("{}{:?}, ", a, v) });
- write!(f, "{} Cannot apply {:?} to values {}", "Runtime Type Error".bold(), op, values)
+ write!(f, "{} Cannot apply {:?} to values {}", "Value Error".bold(), op, values)
}
ErrorKind::AssertFailed => {
write!(f, "{}", "Assertion failed".bold())
diff --git a/src/vm.rs b/src/vm.rs
index bfb5ce4..2318aa6 100644
--- a/src/vm.rs
+++ b/src/vm.rs
@@ -26,7 +26,7 @@ macro_rules! one_op {
let b = $fun(&a);
if b.is_nil() {
$self.push(b);
- error!($self, ErrorKind::RuntimeTypeError($op, vec![a]));
+ error!($self, ErrorKind::ValueError($op, vec![a]));
}
$self.push(b);
};
@@ -38,7 +38,7 @@ macro_rules! two_op {
let c = $fun(&a, &b);
if c.is_nil() {
$self.push(c);
- error!($self, ErrorKind::RuntimeTypeError($op, vec![a, b]));
+ error!($self, ErrorKind::ValueError($op, vec![a, b]));
}
$self.push(c);
};
@@ -301,7 +301,7 @@ impl VM {
}
(val, slot) => {
self.stack.push(Value::Nil);
- error!(self, ErrorKind::RuntimeTypeError(op, vec![val, slot]), String::from("Cannot index type"));
+ error!(self, ErrorKind::ValueError(op, vec![val, slot]), String::from("Cannot index type"));
}
}
}
@@ -313,7 +313,7 @@ impl VM {
let slot = ty.fields.get(field).unwrap().0;
self.push(values.borrow()[slot].clone());
} else {
- error!(self, ErrorKind::RuntimeTypeError(op, vec![inst]));
+ error!(self, ErrorKind::ValueError(op, vec![inst]));
}
}
@@ -324,7 +324,7 @@ impl VM {
let slot = ty.fields.get(field).unwrap().0;
values.borrow_mut()[slot] = value;
} else {
- error!(self, ErrorKind::RuntimeTypeError(op, vec![inst]));
+ error!(self, ErrorKind::ValueError(op, vec![inst]));
}
}
@@ -597,7 +597,7 @@ impl VM {
self.push(value);
} else {
self.push(Value::Nil);
- error!(self, ErrorKind::RuntimeTypeError(op, vec![inst]));
+ error!(self, ErrorKind::ValueError(op, vec![inst]));
}
}
@@ -608,10 +608,10 @@ impl VM {
if let Value::Instance(ty, _) = inst {
let ty = &ty.fields.get(field).unwrap().1;
if ty != &Type::from(&value) {
- error!(self, ErrorKind::RuntimeTypeError(op, vec![Value::from(ty)]));
+ error!(self, ErrorKind::ValueError(op, vec![inst]));
}
} else {
- error!(self, ErrorKind::RuntimeTypeError(op, vec![inst]));
+ error!(self, ErrorKind::ValueError(op, vec![inst]));
}
}