diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2024-06-02 09:17:55 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2024-06-02 09:17:55 -0700 |
| commit | 22b8b7e2478e3b205c89cc7a700058bfe39175f2 (patch) | |
| tree | ad6cf17b8729ab9af71d4d731162e738f3a7b057 /bytecode/src/heap.rs | |
| parent | 90c4eac546d2c950b27a84ef0e390ac33a1a347d (diff) | |
| download | sml-22b8b7e2478e3b205c89cc7a700058bfe39175f2.tar.zst | |
Add strings and IO.
Diffstat (limited to 'bytecode/src/heap.rs')
| -rw-r--r-- | bytecode/src/heap.rs | 7 |
1 files changed, 5 insertions, 2 deletions
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<dyn Error>> { + pub fn poke(&mut self, p: usize, off: usize, val: Value) -> Result<(), Box<dyn Error>> { 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(()) } } |
