summaryrefslogtreecommitdiffstats
path: root/bytecode/src/heap.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bytecode/src/heap.rs')
-rw-r--r--bytecode/src/heap.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/bytecode/src/heap.rs b/bytecode/src/heap.rs
index d956e2e..970db7d 100644
--- a/bytecode/src/heap.rs
+++ b/bytecode/src/heap.rs
@@ -1,4 +1,5 @@
use crate::value::Value;
+use std::error::Error;
pub const NUM_LOCALS: usize = 256;
@@ -107,9 +108,9 @@ impl Heap {
self.buf.resize(new_size * 2, 0);
}
- pub fn alloc(&mut self, size: i64) -> Result<usize, String> {
+ pub fn alloc(&mut self, size: i64) -> Result<usize, Box<dyn Error>> {
if size <= 0 {
- return Err(String::from("alloc of zero size"));
+ return Err(Box::from("alloc of zero size"));
}
let usize = usize::try_from(size).expect("32 bits in 2024 LULW");
self.collect_garbage();
@@ -124,16 +125,16 @@ impl Heap {
Ok(p)
}
- pub fn peek(&self, p: usize) -> Result<Value, String> {
+ pub fn peek(&self, p: usize) -> Result<Value, Box<dyn Error>> {
if p >= self.buf.len() {
- return Err(String::from("peek: out of range"));
+ return Err(Box::from("peek: out of range"));
}
Ok(Value(self.buf[p]))
}
- pub fn poke(&mut self, p: usize, val: Value) -> Result<(), String> {
+ pub fn poke(&mut self, p: usize, val: Value) -> Result<(), Box<dyn Error>> {
if p >= self.buf.len() {
- return Err(String::from("poke: out of range"));
+ return Err(Box::from("poke: out of range"));
}
self.buf[p] = val.repr();
Ok(())