diff options
-rw-r--r-- | 020run.cc | 40 | ||||
-rw-r--r-- | 031address.cc | 3 | ||||
-rw-r--r-- | 044space.cc | 1 |
3 files changed, 44 insertions, 0 deletions
diff --git a/020run.cc b/020run.cc index 1c76bbdb..151687f6 100644 --- a/020run.cc +++ b/020run.cc @@ -75,6 +75,20 @@ void run_current_routine() switch (current_instruction().operation) { // Primitive Recipe Implementations case COPY: { + if (SIZE(current_instruction().products) != SIZE(ingredients)) { + raise << "ingredients and products should match in '" << current_instruction().to_string() << "'\n" << end(); + break; + } + for (long long int i = 0; i < SIZE(ingredients); ++i) { + if (!is_mu_array(current_instruction().ingredients.at(i)) && is_mu_array(current_instruction().products.at(i))) { + raise << "can't copy " << current_instruction().ingredients.at(i).original_string << " to array " << current_instruction().products.at(i).original_string << "\n" << end(); + goto finish_instruction; + } + if (is_mu_array(current_instruction().ingredients.at(i)) && !is_mu_array(current_instruction().products.at(i))) { + raise << "can't copy array " << current_instruction().ingredients.at(i).original_string << " to " << current_instruction().products.at(i).original_string << "\n" << end(); + goto finish_instruction; + } + } copy(ingredients.begin(), ingredients.end(), inserter(products, products.begin())); break; } @@ -83,6 +97,7 @@ void run_current_routine() cout << "not a primitive op: " << current_instruction().operation << '\n'; } } + finish_instruction: if (SIZE(products) < SIZE(current_instruction().products)) { raise << SIZE(products) << " vs " << SIZE(current_instruction().products) << ": failed to write to all products! " << current_instruction().to_string() << end(); } @@ -240,6 +255,10 @@ bool is_literal(const reagent& r) { return SIZE(r.types) == 1 && r.types.at(0) == 0; } +bool is_mu_array(reagent r) { + return !r.types.empty() && r.types.at(0) == Type_ordinal["array"]; +} + :(scenario run_label) recipe main [ +foo @@ -261,3 +280,24 @@ recipe main [ 0 <- copy 34 ] -mem: storing 34 in location 0 + +:(scenario copy_checks_reagent_count) +% Hide_warnings = true; +recipe main [ + 1:number <- copy 34, 35 +] ++warn: ingredients and products should match in '1:number <- copy 34, 35' + +:(scenario write_scalar_to_array_disallowed) +% Hide_warnings = true; +recipe main [ + 1:array:number <- copy 34 +] ++warn: can't copy 34 to array 1:array:number + +:(scenario write_scalar_to_array_disallowed_2) +% Hide_warnings = true; +recipe main [ + 1:number, 2:array:number <- copy 34, 35 +] ++warn: can't copy 35 to array 2:array:number diff --git a/031address.cc b/031address.cc index b7b395c6..94c23210 100644 --- a/031address.cc +++ b/031address.cc @@ -29,6 +29,9 @@ if (x.value == 0) { return; } +:(after "bool is_mu_array(reagent r)") +r = canonize(r); + //: writes to address 0 always loudly fail :(scenario store_to_0_warns) % Hide_warnings = true; diff --git a/044space.cc b/044space.cc index 3a0fe57a..8331dabe 100644 --- a/044space.cc +++ b/044space.cc @@ -51,6 +51,7 @@ reagent r = absolutize(x); reagent absolutize(reagent x) { //? cout << "absolutize " << x.to_string() << '\n'; //? 4 if (is_raw(x) || is_dummy(x)) return x; + if (x.name == "default-space") return x; if (!x.initialized) { raise << current_instruction().to_string() << ": reagent not initialized: " << x.original_string << end(); return x; |