diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2024-05-12 08:21:14 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2024-05-12 08:21:14 -0700 |
| commit | 8ec4edc977e0ed87f86c7e74c13d3633cb788069 (patch) | |
| tree | 0a2ef1c6c89e5187e4082adf22d4ab87925cd7dd /bytecode/src/heap.rs | |
| parent | Use strings for errors. (diff) | |
| download | sml-8ec4edc977e0ed87f86c7e74c13d3633cb788069.tar.zst | |
Revert "Use strings for errors."
This reverts commit 7b87d7185fc93b92606fcacbc1ea3d7a8e02cb20.
It was an interesting experiment, but String seems to be worse than
Box<dyn Error> in every way.
Diffstat (limited to 'bytecode/src/heap.rs')
| -rw-r--r-- | bytecode/src/heap.rs | 13 |
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(()) |
