about summary refs log tree commit diff stats
path: root/cpp/026new
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-03-28 19:26:40 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-03-28 19:26:40 -0700
commit0ee448dc2bd481bf9ce52dd6843bd00a1e2e6171 (patch)
tree598584e605d710dce38666a045a56d33870dc869 /cpp/026new
parentd39883ec7eaa17a3efafeff86ee3f0d75e4d0ebf (diff)
downloadmu-0ee448dc2bd481bf9ce52dd6843bd00a1e2e6171.tar.gz
990
Diffstat (limited to 'cpp/026new')
-rw-r--r--cpp/026new18
1 files changed, 17 insertions, 1 deletions
diff --git a/cpp/026new b/cpp/026new
index edc17b17..ffb4429a 100644
--- a/cpp/026new
+++ b/cpp/026new
@@ -47,6 +47,22 @@ case NEW: {
   write_memory(instructions[pc].products[0], result);
   vector<int> types;
   types.push_back(instructions[pc].ingredients[0].value);
-  Current_routine.alloc += size_of(types);
+  if (instructions[pc].ingredients.size() > 1) {
+    // array
+    vector<int> capacity = read_memory(instructions[pc].ingredients[1]);
+    Current_routine.alloc += capacity[0]*size_of(types);
+  }
+  else {
+    // scalar
+    Current_routine.alloc += size_of(types);
+  }
   break;
 }
+
+:(scenario "new_array")
+recipe main [
+  1:address:array:integer/raw <- new integer:type, 5:literal
+  2:address:integer/raw <- new integer:type
+  3:integer/raw <- subtract 2:address:integer/raw, 1:address:array:integer/raw
+]
++mem: storing 5 in location 3