From 26ed2bcec620c639faef25c75e4076888068e45e Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Mon, 22 Aug 2022 20:04:03 -0700 Subject: Allow 0-length allocs. --- bytecode/src/bytecode.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'bytecode/src/bytecode.rs') 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 -- cgit v1.3.1