diff options
| -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 |
