From 22b8b7e2478e3b205c89cc7a700058bfe39175f2 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sun, 2 Jun 2024 09:17:55 -0700 Subject: Add strings and IO. --- bytecode/src/heap.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'bytecode/src/heap.rs') diff --git a/bytecode/src/heap.rs b/bytecode/src/heap.rs index 970db7d..f195613 100644 --- a/bytecode/src/heap.rs +++ b/bytecode/src/heap.rs @@ -132,11 +132,14 @@ impl Heap { Ok(Value(self.buf[p])) } - pub fn poke(&mut self, p: usize, val: Value) -> Result<(), Box> { + pub fn poke(&mut self, p: usize, off: usize, val: Value) -> Result<(), Box> { if p >= self.buf.len() { return Err(Box::from("poke: out of range")); } - self.buf[p] = val.repr(); + if off >= self.alloc_size(p) { + return Err(Box::from("poke: out of range")); + } + self.buf[p + off] = val.repr(); Ok(()) } } -- cgit v1.3.1