realign and clean up
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use prometeu_bytecode::Value;
|
||||
use prometeu_bytecode::{Value, TRAP_OOB};
|
||||
use crate::vm_fault::VmFault;
|
||||
|
||||
pub struct HostReturn<'a> {
|
||||
@@ -17,7 +17,7 @@ impl<'a> HostReturn<'a> {
|
||||
}
|
||||
pub fn push_bounded(&mut self, v: u32) -> Result<(), VmFault> {
|
||||
if v > 0xFFFF {
|
||||
return Err(VmFault::Trap(prometeu_bytecode::abi::TRAP_OOB, "Bounded value overflow".into()));
|
||||
return Err(VmFault::Trap(TRAP_OOB, "Bounded value overflow".into()));
|
||||
}
|
||||
self.stack.push(Value::Bounded(v));
|
||||
Ok(())
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use prometeu_bytecode::Value;
|
||||
use prometeu_bytecode::{Value, TRAP_TYPE};
|
||||
use crate::vm_fault::VmFault;
|
||||
|
||||
pub fn expect_bounded(args: &[Value], idx: usize) -> Result<u32, VmFault> {
|
||||
@@ -7,13 +7,13 @@ pub fn expect_bounded(args: &[Value], idx: usize) -> Result<u32, VmFault> {
|
||||
Value::Bounded(b) => Some(*b),
|
||||
_ => None,
|
||||
})
|
||||
.ok_or_else(|| VmFault::Trap(prometeu_bytecode::abi::TRAP_TYPE, format!("Expected bounded at index {}", idx)))
|
||||
.ok_or_else(|| VmFault::Trap(TRAP_TYPE, format!("Expected bounded at index {}", idx)))
|
||||
}
|
||||
|
||||
pub fn expect_int(args: &[Value], idx: usize) -> Result<i64, VmFault> {
|
||||
args.get(idx)
|
||||
.and_then(|v| v.as_integer())
|
||||
.ok_or_else(|| VmFault::Trap(prometeu_bytecode::abi::TRAP_TYPE, format!("Expected integer at index {}", idx)))
|
||||
.ok_or_else(|| VmFault::Trap(TRAP_TYPE, format!("Expected integer at index {}", idx)))
|
||||
}
|
||||
|
||||
pub fn expect_bool(args: &[Value], idx: usize) -> Result<bool, VmFault> {
|
||||
@@ -22,5 +22,5 @@ pub fn expect_bool(args: &[Value], idx: usize) -> Result<bool, VmFault> {
|
||||
Value::Boolean(b) => Some(*b),
|
||||
_ => None,
|
||||
})
|
||||
.ok_or_else(|| VmFault::Trap(prometeu_bytecode::abi::TRAP_TYPE, format!("Expected boolean at index {}", idx)))
|
||||
.ok_or_else(|| VmFault::Trap(TRAP_TYPE, format!("Expected boolean at index {}", idx)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user