:(scenarios run)
:(scenario new)
recipe main [
1:address:integer/raw <- new integer:type
2:address:integer/raw <- new integer:type
3:boolean/raw <- equal 1:address:integer/raw, 2:address:integer/raw
]
+mem: storing 0 in location 3
:(before "End Globals")
size_t Reserved_for_tests = 1000;
index_t Memory_allocated_until = Reserved_for_tests;
size_t Initial_memory_per_routine = 100000;
:(before "End Setup")
Memory_allocated_until = Reserved_for_tests;
Initial_memory_per_routine = 100000;
:(before "End routine Fields")
index_t alloc, alloc_max;
:(before "End routine Constructor")
alloc = Memory_allocated_until;
Memory_allocated_until += Initial_memory_per_routine;
alloc_max = Memory_allocated_until;
trace("new") << "routine allocated memory from " << alloc << " to " << alloc_max;
:(before "End Mu Types Initialization")
Type_number["type"] = 0;
:(after "Per-recipe Transforms")
if (inst.operation == Recipe_number["new"]) {
assert(inst.ingredients.size() >= 1);
assert(isa_literal(inst.ingredients[0]));
if (inst.ingredients[0].properties[0].second[0] == "type") {
inst.ingredients[0].set_value(Type_number[inst.ingredients[0].name]);
}
trace("new") << inst.ingredients[0].name << " -> " << inst.ingredients[0].value;
}
:(before "End Primitive Recipe Declarations")
NEW,
:(before "End Primitive Recipe Numbers")
Recipe_number["new"] = NEW;
:(before "End Primitive Recipe Implementations")
case NEW: {
size_t size = 0;
size_t array_length = 0;
{
vector<type_number> type;
type.push_back(current_instruction().ingredients[0].value);
if (current_instruction().ingredients.size() > 1) {
vector<long long int> capacity = read_memory(current_instruction().ingredients[1]);
array_length = capacity[0];
trace("mem") << "array size is " << array_length;
size = array_length*size_of(type) + 1;
}
else {
size = size_of(type);
}
}
assert(size <= Initial_memory_per_routine);
if (Current_routine->alloc + size >= Current_routine->alloc_max) {
Current_routine->alloc = Memory_allocated_until;
Memory_allocated_until += Initial_memory_per_routine;
Current_routine->alloc_max = Memory_allocated_until;
trace("new") << "routine allocated memory from " << Current_routine->alloc << " to " << Current_routine->alloc_max;
}
const index_t result = Current_routine->alloc;
trace("mem") << "new alloc: " << result;
if (current_instruction().ingredients.size() > 1) {
Memory[result] = array_length;
}
vector<long long int> tmp;
tmp.push_back(Current_routine->alloc);
write_memory(current_instruction().products[0], tmp);
Current_routine->alloc += size;
assert(Current_routine->alloc <= Current_routine->alloc_max);
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
]
+run: instruction main/0
+mem: array size is 5
+run: instruction main/1
+run: instruction main/2
+mem: storing 6 in location 3
:(scenario new_concurrent)
recipe f1 [
start-running f2:recipe
1:address:integer/raw <- new integer:type
]
recipe f2 [
2:address:integer/raw <- new integer:type
3:boolean/raw <- equal 1:address:integer/raw, 2:address:integer/raw
]
+mem: storing 0 in location 3
:(scenario new_overflow)
% Initial_memory_per_routine = 2;
recipe main [
1:address:integer/raw <- new integer:type
2:address:point/raw <- new point:type
]
+new: routine allocated memory from 1000 to 1002
+new: routine allocated memory from 1002 to 1004
:(scenario new_string)
recipe main [
1:address:array:character <- new [abc def]
2:character <- index 1:address:array:character/deref, 5:literal
]
+mem: storing 101 in location 2
:(after "case NEW" following "Primitive Recipe Implementations")
if (current_instruction().ingredients[0].properties[0].second[0] == "literal-string") {
vector<long long int> result;
result.push_back(Current_routine->alloc);
write_memory(current_instruction().products[0], result);
Memory[Current_routine->alloc++] = current_instruction().ingredients[0].name.size();
for (index_t i = 0; i < current_instruction().ingredients[0].name.size(); ++i) {
Memory[Current_routine->alloc++] = current_instruction().ingredients[0].name[i];
}
break;
}