From 5987486862b8c989452bc62d359168a5686b462e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 28 May 2017 14:28:07 -0700 Subject: 3887 - clean up early exits in interpreter loop It's always confusing when `break` refers to a `switch` but `continue` refers to the loop around the `switch`. But we've done ugly things like this and `goto` for expedience. However, we're starting to run into cases where we now need to insert code at every `continue` or `continue`-mimicking `goto` inside the core interpreter loop. Better to make the loop single-entry-single-exit. Common things to run after every instruction will now happen inside the `finish_instruction` function rather than at the `finish_instruction` label. --- 032array.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to '032array.cc') diff --git a/032array.cc b/032array.cc index 778daa97..3b521263 100644 --- a/032array.cc +++ b/032array.cc @@ -66,7 +66,8 @@ case CREATE_ARRAY: { put(Memory, base_address+i, 0); } // no need to update product - goto finish_instruction; + write_products = false; + break; } :(scenario copy_array) @@ -557,13 +558,14 @@ case PUT_INDEX: { trace(9998, "run") << "address to copy to is " << address << end(); // optimization: directly write the element rather than updating 'product' // and writing the entire array + write_products = false; vector value = read_memory(current_instruction().ingredients.at(2)); // Write Memory in PUT_INDEX in Run for (int i = 0; i < SIZE(value); ++i) { trace(9999, "mem") << "storing " << no_scientific(value.at(i)) << " in location " << address+i << end(); put(Memory, address+i, value.at(i)); } - goto finish_instruction; + break; } :(scenario put_index_out_of_bounds) -- cgit 1.4.1-2-gfad0