diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2024-05-11 22:15:46 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2024-05-11 22:15:46 -0700 |
| commit | 7b87d7185fc93b92606fcacbc1ea3d7a8e02cb20 (patch) | |
| tree | b59f04fce96fc34b0c1315c67c955aa90b121e19 /bytecode/src/heap.rs | |
| parent | df7dab936f11310cf8e422eb4c06b2815eaf2807 (diff) | |
| download | sml-7b87d7185fc93b92606fcacbc1ea3d7a8e02cb20.tar.zst | |
Use strings for errors.
Diffstat (limited to 'bytecode/src/heap.rs')
| -rw-r--r-- | bytecode/src/heap.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/bytecode/src/heap.rs b/bytecode/src/heap.rs index 970db7d..d956e2e 100644 --- a/bytecode/src/heap.rs +++ b/bytecode/src/heap.rs @@ -1,5 +1,4 @@ use crate::value::Value; -use std::error::Error; pub const NUM_LOCALS: usize = 256; @@ -108,9 +107,9 @@ impl Heap { self.buf.resize(new_size * 2, 0); } - pub fn alloc(&mut self, size: i64) -> Result<usize, Box<dyn Error>> { + pub fn alloc(&mut self, size: i64) -> Result<usize, String> { if size <= 0 { - return Err(Box::from("alloc of zero size")); + return Err(String::from("alloc of zero size")); } let usize = usize::try_from(size).expect("32 bits in 2024 LULW"); self.collect_garbage(); @@ -125,16 +124,16 @@ impl Heap { Ok(p) } - pub fn peek(&self, p: usize) -> Result<Value, Box<dyn Error>> { + pub fn peek(&self, p: usize) -> Result<Value, String> { if p >= self.buf.len() { - return Err(Box::from("peek: out of range")); + return Err(String::from("peek: out of range")); } Ok(Value(self.buf[p])) } - pub fn poke(&mut self, p: usize, val: Value) -> Result<(), Box<dyn Error>> { + pub fn poke(&mut self, p: usize, val: Value) -> Result<(), String> { if p >= self.buf.len() { - return Err(Box::from("poke: out of range")); + return Err(String::from("poke: out of range")); } self.buf[p] = val.repr(); Ok(()) |
