aboutsummaryrefslogtreecommitdiffstats
path: root/bytecode
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-08-22 20:04:03 -0700
committerRose Hogenson <rhogenson@posteo.net>2022-08-22 20:04:03 -0700
commit26ed2bcec620c639faef25c75e4076888068e45e (patch)
tree325568953d4929d99f3d8265d1daaab2a529ae54 /bytecode
parentd4bd262329827738d08a431f9556fbe6fa8d5a80 (diff)
downloadchromatopelma-26ed2bcec620c639faef25c75e4076888068e45e.tar.zst
Allow 0-length allocs.
Diffstat (limited to 'bytecode')
-rw-r--r--bytecode/src/bytecode.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/bytecode/src/bytecode.rs b/bytecode/src/bytecode.rs
index 313b2fb..e784d57 100644
--- a/bytecode/src/bytecode.rs
+++ b/bytecode/src/bytecode.rs
@@ -152,7 +152,11 @@ impl Interpreter {
fn alloc(&mut self, dest: Local, size: Arg) -> Result<(), String> {
let n = self.read_arg(size).to_int()?;
if n < 0 {
- return Err(String::from("tried to allocate negative memory"));
+ return Err(String::from("need a positive argument to alloc"));
+ }
+ if n == 0 {
+ self.set_arg(dest, Value(0));
+ return Ok(());
}
let p = self
.heap
@@ -163,8 +167,8 @@ impl Interpreter {
fn alloc_bytevector(&mut self, dest: Local, size: Arg) -> Result<(), String> {
let n = self.read_arg(size).to_int()?;
- if n < 0 {
- return Err(String::from("tried to allocate negative memory"));
+ if n <= 0 {
+ return Err(String::from("need a positive argument to alloc_bytevector"));
}
let p = self
.heap