Skip to content

Commit

Permalink
Handle machine errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumplation committed Sep 1, 2024
1 parent ae07f66 commit c9f6291
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions gastronomy-cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl App {
}
KeyCode::Char('N') | KeyCode::Char('n') | KeyCode::Right => {
let stride = if key_event.modifiers.contains(event::KeyModifiers::SHIFT) {
5
50
} else {
1
};
Expand All @@ -65,7 +65,7 @@ impl App {
}
KeyCode::Char('P') | KeyCode::Char('p') | KeyCode::Left => {
let stride = if key_event.modifiers.contains(event::KeyModifiers::SHIFT) {
5
50
} else {
1
};
Expand Down
12 changes: 8 additions & 4 deletions gastronomy/src/uplc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{ffi::OsStr, fs, path::Path};
use anyhow::{anyhow, Context, Result};
use pallas::ledger::primitives::conway::{Language, MintedTx};
use uplc::{
ast::{FakeNamedDeBruijn, NamedDeBruijn, Program},
ast::{FakeNamedDeBruijn, NamedDeBruijn, Program, Term},
machine::{
cost_model::{CostModel, ExBudget},
Machine, MachineState,
Expand Down Expand Up @@ -131,9 +131,13 @@ pub fn execute_program(program: Program<NamedDeBruijn>) -> Result<Vec<(MachineSt
.map_err(|err| anyhow!("could not get initial state: {}", err))?;
let mut states = vec![(state.clone(), machine.ex_budget)];
while !matches!(state, MachineState::Done(_)) {
state = machine
.step(state)
.map_err(|err| anyhow!("could not evaluate state: {}", err))?;
state = match machine.step(state) {
Ok(state) => state,
Err(err) => {
eprintln!("Machine Error: {}", err);
MachineState::Done(Term::Error)
}
};
states.push((state.clone(), machine.ex_budget));
}

Expand Down
Binary file added test_data/bad_mint_pool.tx
Binary file not shown.

0 comments on commit c9f6291

Please sign in to comment.