From 0edf822f996c5def4588cc207d1977cffc3e9a0c Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 14 Apr 2015 18:31:26 -0700 Subject: 1062 - bugfix: wasn't aliasing Current_routine You can't write tests for stupidity. --- cpp/013run | 5 +++-- cpp/026new | 8 ++++---- cpp/027space | 8 ++++---- cpp/028space_surround | 2 +- cpp/029string | 6 +++--- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/cpp/013run b/cpp/013run index 5ba9af70..1606a82d 100644 --- a/cpp/013run +++ b/cpp/013run @@ -27,7 +27,7 @@ struct routine { }; :(before "End Globals") -routine Current_routine(0); +routine* Current_routine = NULL; :(code) void run(recipe_number r) { @@ -35,7 +35,7 @@ void run(recipe_number r) { } void run(routine rr) { - Current_routine = rr; + Current_routine = &rr; while (!done(rr)) { vector& instructions = steps(rr); size_t& pc = running_at(rr); @@ -59,6 +59,7 @@ void run(routine rr) { } ++pc; } + Current_routine = NULL; } //: Some helpers. diff --git a/cpp/026new b/cpp/026new index 9c9bbc04..02196c49 100644 --- a/cpp/026new +++ b/cpp/026new @@ -45,7 +45,7 @@ Next_recipe_number++; :(before "End Primitive Recipe Implementations") case NEW: { vector result; - result.push_back(Current_routine.alloc); + result.push_back(Current_routine->alloc); write_memory(instructions[pc].products[0], result); vector types; types.push_back(instructions[pc].ingredients[0].value); @@ -53,12 +53,12 @@ case NEW: { // array vector capacity = read_memory(instructions[pc].ingredients[1]); trace("mem") << "array size is " << capacity[0]; - Memory[Current_routine.alloc] = capacity[0]; - Current_routine.alloc += capacity[0]*size_of(types); + Memory[Current_routine->alloc] = capacity[0]; + Current_routine->alloc += capacity[0]*size_of(types); } else { // scalar - Current_routine.alloc += size_of(types); + Current_routine->alloc += size_of(types); } break; } diff --git a/cpp/027space b/cpp/027space index 9d3ef572..2a845015 100644 --- a/cpp/027space +++ b/cpp/027space @@ -52,7 +52,7 @@ result.properties.push_back(pair >("raw", vector( :(code) int space(const reagent& x) { - return Current_routine.calls.top().default_space; + return Current_routine->calls.top().default_space; } int address(int offset, int base) { @@ -67,8 +67,8 @@ int address(int offset, int base) { :(after "void write_memory(reagent x, vector data)") if (x.name == "default-space") { assert(data.size() == 1); - Current_routine.calls.top().default_space = data[0]; -//? cout << "AAA " << Current_routine.calls.top().default_space << '\n'; //? 1 + Current_routine->calls.top().default_space = data[0]; +//? cout << "AAA " << Current_routine->calls.top().default_space << '\n'; //? 1 return; } @@ -82,6 +82,6 @@ recipe main [ :(after "vector read_memory(reagent x)") if (x.name == "default-space") { vector result; - result.push_back(Current_routine.calls.top().default_space); + result.push_back(Current_routine->calls.top().default_space); return result; } diff --git a/cpp/028space_surround b/cpp/028space_surround index 7126911d..dd4fb44f 100644 --- a/cpp/028space_surround +++ b/cpp/028space_surround @@ -27,7 +27,7 @@ recipe main [ :(replace{} "int space(const reagent& x)") int space(const reagent& x) { - return space(x, space_index(x), Current_routine.calls.top().default_space); + return space(x, space_index(x), Current_routine->calls.top().default_space); } int space(const reagent& x, int space_index, int base) { diff --git a/cpp/029string b/cpp/029string index 9a1a094e..320337c4 100644 --- a/cpp/029string +++ b/cpp/029string @@ -58,13 +58,13 @@ Type_number["character"] = Next_type_number++; if (instructions[pc].ingredients[0].properties[0].second[0] == "literal-string") { // allocate an array just large enough for it vector result; - result.push_back(Current_routine.alloc); + result.push_back(Current_routine->alloc); write_memory(instructions[pc].products[0], result); // assume that all characters fit in a single location //? cout << "new string literal: " << instructions[pc].ingredients[0].name << '\n'; //? 1 - Memory[Current_routine.alloc++] = instructions[pc].ingredients[0].name.size(); + Memory[Current_routine->alloc++] = instructions[pc].ingredients[0].name.size(); for (size_t i = 0; i < instructions[pc].ingredients[0].name.size(); ++i) { - Memory[Current_routine.alloc++] = instructions[pc].ingredients[0].name[i]; + Memory[Current_routine->alloc++] = instructions[pc].ingredients[0].name[i]; } // mu strings are not null-terminated in memory break; -- cgit 1.4.1-2-gfad0