about summary refs log tree commit diff stats
path: root/020run.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-08-07 12:56:09 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-08-07 12:56:09 -0700
commit6d2b1168e31d23ba4e9312d70607d2e67e5cd833 (patch)
tree77d4ce21b7812da9fe191e5f319f2acfa9dd3085 /020run.cc
parent49659e7291dfa02f1b11db721fd80eddbeb19876 (diff)
downloadmu-6d2b1168e31d23ba4e9312d70607d2e67e5cd833.tar.gz
1951 - warn when copying scalars to arrays, etc.
Diffstat (limited to '020run.cc')
-rw-r--r--020run.cc40
1 files changed, 40 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