[fine] Panic embeds description, start match
This commit is contained in:
parent
548d9387d6
commit
9ce5794c30
3 changed files with 94 additions and 35 deletions
|
|
@ -10,8 +10,8 @@ use thiserror::Error;
|
|||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum VMErrorCode {
|
||||
#[error("code panic (syntax or semantic error)")]
|
||||
Panic,
|
||||
#[error("code panic (syntax or semantic error): {0}")]
|
||||
Panic(Rc<str>),
|
||||
#[error("internal error: stack underflow")]
|
||||
StackUnderflow,
|
||||
#[error("internal error: stack type mismatch: {0:?} is not {1:?}")]
|
||||
|
|
@ -394,7 +394,12 @@ fn eval_one(
|
|||
stack: &mut Vec<Frame>,
|
||||
) -> Result<Flow> {
|
||||
match instruction {
|
||||
Instruction::Panic => return Err(VMErrorCode::Panic),
|
||||
Instruction::Panic(index) => {
|
||||
let v = f
|
||||
.get_string(index)
|
||||
.unwrap_or_else(|_| "!!panic string out of range!!".into());
|
||||
return Err(VMErrorCode::Panic(v));
|
||||
}
|
||||
Instruction::BoolNot => {
|
||||
let value = f.pop_bool()?;
|
||||
f.push_bool(!value);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue