[fine] Panic embeds description, start match

This commit is contained in:
John Doty 2024-03-24 07:08:45 -07:00
parent 548d9387d6
commit 9ce5794c30
3 changed files with 94 additions and 35 deletions

View file

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