diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-08-22 20:04:03 -0700 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-08-22 20:04:03 -0700 |
| commit | 26ed2bcec620c639faef25c75e4076888068e45e (patch) | |
| tree | 325568953d4929d99f3d8265d1daaab2a529ae54 /bytecode | |
| parent | d4bd262329827738d08a431f9556fbe6fa8d5a80 (diff) | |
| download | chromatopelma-26ed2bcec620c639faef25c75e4076888068e45e.tar.zst | |
Allow 0-length allocs.
Diffstat (limited to 'bytecode')
| -rw-r--r-- | bytecode/src/bytecode.rs | 10 |
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 |
