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:
2020-10-13 14:07:22 -07:00
parent c738c52455
commit 902da3f2f3
9 changed files with 98 additions and 50 deletions

View File

@@ -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>;