From 0ee448dc2bd481bf9ce52dd6843bd00a1e2e6171 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 28 Mar 2015 19:26:40 -0700 Subject: 990 --- cpp/026new | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'cpp/026new') 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 types; types.push_back(instructions[pc].ingredients[0].value); - Current_routine.alloc += size_of(types); + if (instructions[pc].ingredients.size() > 1) { + // array + vector 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 -- cgit 1.4.1-2-gfad0