about summary refs log tree commit diff stats
path: root/cpp/026new
diff options
context:
space:
mode:
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