Browse Source

add array alloc/abandon

jmelesky 4 years ago
parent
commit
6190775f86
1 changed files with 7 additions and 0 deletions
  1. 7 0
      src/main.rs

+ 7 - 0
src/main.rs

@@ -175,8 +175,15 @@ fn um_step(um: &mut UMState, op: UMOp) {
             panic!("Halt reached")
         },
         UMOp::Allocate(b, c) => {
+            let new_arr = vec![032; um.regs[c as usize] as usize];
+            let new_arr_add = um.mem.len() as u32;
+            um.mem.push(new_arr);
+            um.regs[b as usize] = new_arr_add;
         },
         UMOp::Abandon(c) => {
+            let i = um.arrmap[&um.regs[c as usize]];
+            um.arrmap.remove(&um.regs[c as usize]);
+            um.mem[i] = vec![0u32; 0];
         },
         UMOp::Output(c) => {
             print!("{}", um.regs[c as usize] as u8 as char)