Add internal error handling to VM, plus function arity
* VM is able to handle basic runtime errors although there is no way to catch this in executing code currently * If a function is called with the wrong number of arguments (arity) it will invoke a runtime error. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,9 +1,24 @@
|
||||
use crate::obj::prelude::*;
|
||||
use snafu::Snafu;
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
pub enum Error {
|
||||
#[snafu(display("attempted to pop an empty stack"))]
|
||||
EmptyStack,
|
||||
#[snafu(display("missing attribute: {}", global_sym_lookup(*attr).unwrap()))]
|
||||
MissingAttr {
|
||||
attr: Sym,
|
||||
},
|
||||
|
||||
#[snafu(display("{}", error))]
|
||||
ValueError {
|
||||
error: String,
|
||||
value: ObjRef,
|
||||
},
|
||||
|
||||
#[snafu(display("incorrect function arity; expected {} but got {} instead", expected, got))]
|
||||
ArityError {
|
||||
expected: usize,
|
||||
got: usize,
|
||||
},
|
||||
}
|
||||
|
||||
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
||||
|
||||
Reference in New Issue
Block a user