about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--020run.cc9
-rw-r--r--021arithmetic.cc4
-rw-r--r--024compare.cc10
-rw-r--r--029tools.cc2
-rw-r--r--030container.cc5
-rw-r--r--032array.cc7
-rw-r--r--033exclusive_container.cc2
-rw-r--r--035call_ingredient.cc3
-rw-r--r--038scheduler.cc2
-rw-r--r--043new.cc2
-rw-r--r--053continuation.cc2
-rw-r--r--064random.cc2
-rw-r--r--081run_interactive.cc12
-rw-r--r--082persist.cc2
14 files changed, 35 insertions, 29 deletions
diff --git a/020run.cc b/020run.cc
index 72fc2b7c..c981349f 100644
--- a/020run.cc
+++ b/020run.cc
@@ -88,10 +88,13 @@ void run_current_routine()
         cout << "not a primitive op: " << current_instruction().operation << '\n';
       }
     }
-    if (SIZE(products) < SIZE(current_instruction().products))
+    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();
-    for (long long int i = 0; i < SIZE(current_instruction().products); ++i) {
-      write_memory(current_instruction().products.at(i), products.at(i));
+    }
+    else {
+      for (long long int i = 0; i < SIZE(current_instruction().products); ++i) {
+        write_memory(current_instruction().products.at(i), products.at(i));
+      }
     }
     // End of Instruction
     ++current_step_index();
diff --git a/021arithmetic.cc b/021arithmetic.cc
index 2a21c2cf..9c1de78b 100644
--- a/021arithmetic.cc
+++ b/021arithmetic.cc
@@ -43,7 +43,6 @@ SUBTRACT,
 Recipe_ordinal["subtract"] = SUBTRACT;
 :(before "End Primitive Recipe Implementations")
 case SUBTRACT: {
-  products.resize(1);
   if (ingredients.empty()) {
     raise << current_recipe_name() << ": 'subtract' has no ingredients\n" << end();
     break;
@@ -54,6 +53,7 @@ case SUBTRACT: {
     assert(scalar(ingredients.at(i)));
     result -= ingredients.at(i).at(0);
   }
+  products.resize(1);
   products.at(0).push_back(result);
   break;
 }
@@ -120,7 +120,6 @@ DIVIDE,
 Recipe_ordinal["divide"] = DIVIDE;
 :(before "End Primitive Recipe Implementations")
 case DIVIDE: {
-  products.resize(1);
   if (ingredients.empty()) {
     raise << current_recipe_name() << ": 'divide' has no ingredients\n" << end();
     break;
@@ -131,6 +130,7 @@ case DIVIDE: {
     assert(scalar(ingredients.at(i)));
     result /= ingredients.at(i).at(0);
   }
+  products.resize(1);
   products.at(0).push_back(result);
   break;
 }
diff --git a/024compare.cc b/024compare.cc
index 7fb8c2e8..fb3481fd 100644
--- a/024compare.cc
+++ b/024compare.cc
@@ -6,7 +6,6 @@ EQUAL,
 Recipe_ordinal["equal"] = EQUAL;
 :(before "End Primitive Recipe Implementations")
 case EQUAL: {
-  products.resize(1);
   if (SIZE(ingredients) <= 1) {
     raise << current_recipe_name() << ": 'equal' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end();
     break;
@@ -19,6 +18,7 @@ case EQUAL: {
       break;
     }
   }
+  products.resize(1);
   products.at(0).push_back(result);
   break;
 }
@@ -61,7 +61,6 @@ GREATER_THAN,
 Recipe_ordinal["greater-than"] = GREATER_THAN;
 :(before "End Primitive Recipe Implementations")
 case GREATER_THAN: {
-  products.resize(1);
   bool result = true;
   if (SIZE(ingredients) <= 1) {
     raise << current_recipe_name() << ": 'greater-than' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end();
@@ -79,6 +78,7 @@ case GREATER_THAN: {
     }
   }
   finish_greater_than:
+  products.resize(1);
   products.at(0).push_back(result);
   break;
 }
@@ -117,7 +117,6 @@ LESSER_THAN,
 Recipe_ordinal["lesser-than"] = LESSER_THAN;
 :(before "End Primitive Recipe Implementations")
 case LESSER_THAN: {
-  products.resize(1);
   bool result = true;
   if (SIZE(ingredients) <= 1) {
     raise << current_recipe_name() << ": 'lesser-than' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end();
@@ -135,6 +134,7 @@ case LESSER_THAN: {
     }
   }
   finish_lesser_than:
+  products.resize(1);
   products.at(0).push_back(result);
   break;
 }
@@ -173,7 +173,6 @@ GREATER_OR_EQUAL,
 Recipe_ordinal["greater-or-equal"] = GREATER_OR_EQUAL;
 :(before "End Primitive Recipe Implementations")
 case GREATER_OR_EQUAL: {
-  products.resize(1);
   bool result = true;
   if (SIZE(ingredients) <= 1) {
     raise << current_recipe_name() << ": 'greater-or-equal' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end();
@@ -191,6 +190,7 @@ case GREATER_OR_EQUAL: {
     }
   }
   finish_greater_or_equal:
+  products.resize(1);
   products.at(0).push_back(result);
   break;
 }
@@ -237,7 +237,6 @@ LESSER_OR_EQUAL,
 Recipe_ordinal["lesser-or-equal"] = LESSER_OR_EQUAL;
 :(before "End Primitive Recipe Implementations")
 case LESSER_OR_EQUAL: {
-  products.resize(1);
   bool result = true;
   if (SIZE(ingredients) <= 1) {
     raise << current_recipe_name() << ": 'lesser-or-equal' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end();
@@ -255,6 +254,7 @@ case LESSER_OR_EQUAL: {
     }
   }
   finish_lesser_or_equal:
+  products.resize(1);
   products.at(0).push_back(result);
   break;
 }
diff --git a/029tools.cc b/029tools.cc
index de4b488c..11130e5f 100644
--- a/029tools.cc
+++ b/029tools.cc
@@ -189,12 +189,12 @@ _SYSTEM,
 Recipe_ordinal["$system"] = _SYSTEM;
 :(before "End Primitive Recipe Implementations")
 case _SYSTEM: {
-  products.resize(1);
   if (current_instruction().ingredients.empty()) {
     raise << current_recipe_name() << ": '$system' requires exactly one ingredient, but got none\n" << end();
     break;
   }
   int status = system(current_instruction().ingredients.at(0).name.c_str());
+  products.resize(1);
   products.at(0).push_back(status);
   break;
 }
diff --git a/030container.cc b/030container.cc
index 55de2a2d..6159f3a0 100644
--- a/030container.cc
+++ b/030container.cc
@@ -107,7 +107,6 @@ GET,
 Recipe_ordinal["get"] = GET;
 :(before "End Primitive Recipe Implementations")
 case GET: {
-  products.resize(1);
   if (SIZE(ingredients) != 2) {
     raise << current_recipe_name() << ": 'get' expects exactly 2 ingredients in '" << current_instruction().to_string() << "'\n" << end();
     break;
@@ -143,7 +142,7 @@ case GET: {
   reagent tmp;
   tmp.set_value(src);
   tmp.types.push_back(src_type);
-  products.at(0) = read_memory(tmp);
+  products.push_back(read_memory(tmp));
   break;
 }
 
@@ -192,7 +191,6 @@ GET_ADDRESS,
 Recipe_ordinal["get-address"] = GET_ADDRESS;
 :(before "End Primitive Recipe Implementations")
 case GET_ADDRESS: {
-  products.resize(1);
   reagent base = current_instruction().ingredients.at(0);
   long long int base_address = base.value;
   if (base_address == 0) {
@@ -219,6 +217,7 @@ case GET_ADDRESS: {
     result += size_of(Type[base_type].elements.at(i));
   }
   trace(Primitive_recipe_depth, "run") << "address to copy is " << result << end();
+  products.resize(1);
   products.at(0).push_back(result);
   break;
 }
diff --git a/032array.cc b/032array.cc
index eae33f4c..54e69e79 100644
--- a/032array.cc
+++ b/032array.cc
@@ -79,7 +79,6 @@ INDEX,
 Recipe_ordinal["index"] = INDEX;
 :(before "End Primitive Recipe Implementations")
 case INDEX: {
-  products.resize(1);
   if (SIZE(ingredients) != 2) {
     raise << current_recipe_name() << ": 'index' expects exactly 2 ingredients in '" << current_instruction().to_string() << "'\n" << end();
     break;
@@ -107,7 +106,7 @@ case INDEX: {
   reagent tmp;
   tmp.set_value(src);
   copy(element_type.begin(), element_type.end(), inserter(tmp.types, tmp.types.begin()));
-  products.at(0) = read_memory(tmp);
+  products.push_back(read_memory(tmp));
   break;
 }
 
@@ -175,7 +174,6 @@ INDEX_ADDRESS,
 Recipe_ordinal["index-address"] = INDEX_ADDRESS;
 :(before "End Primitive Recipe Implementations")
 case INDEX_ADDRESS: {
-  products.resize(1);
   if (SIZE(ingredients) != 2) {
     raise << current_recipe_name() << ": 'index-address' expects exactly 2 ingredients in '" << current_instruction().to_string() << "'\n" << end();
     break;
@@ -198,6 +196,7 @@ case INDEX_ADDRESS: {
     break;
   }
   long long int result = base_address + 1 + offset_val.at(0)*size_of(element_type);
+  products.resize(1);
   products.at(0).push_back(result);
   break;
 }
@@ -250,7 +249,6 @@ LENGTH,
 Recipe_ordinal["length"] = LENGTH;
 :(before "End Primitive Recipe Implementations")
 case LENGTH: {
-  products.resize(1);
   if (SIZE(ingredients) != 1) {
     raise << current_recipe_name() << ": 'length' expects exactly 2 ingredients in '" << current_instruction().to_string() << "'\n" << end();
     break;
@@ -264,6 +262,7 @@ case LENGTH: {
     raise << current_recipe_name() << ": tried to access location 0 in '" << current_instruction().to_string() << "'\n" << end();
     break;
   }
+  products.resize(1);
   products.at(0).push_back(Memory[x.value]);
   break;
 }
diff --git a/033exclusive_container.cc b/033exclusive_container.cc
index eb3ff6f2..e2f520f8 100644
--- a/033exclusive_container.cc
+++ b/033exclusive_container.cc
@@ -83,7 +83,6 @@ MAYBE_CONVERT,
 Recipe_ordinal["maybe-convert"] = MAYBE_CONVERT;
 :(before "End Primitive Recipe Implementations")
 case MAYBE_CONVERT: {
-  products.resize(1);
   if (SIZE(ingredients) != 2) {
     raise << current_recipe_name() << ": 'maybe-convert' expects exactly 2 ingredients in '" << current_instruction().to_string() << "'\n" << end();
     break;
@@ -111,6 +110,7 @@ case MAYBE_CONVERT: {
   else {
     result = 0;
   }
+  products.resize(1);
   products.at(0).push_back(result);
   break;
 }
diff --git a/035call_ingredient.cc b/035call_ingredient.cc
index a2dd97ad..599906da 100644
--- a/035call_ingredient.cc
+++ b/035call_ingredient.cc
@@ -39,7 +39,6 @@ Recipe_ordinal["next-ingredient"] = NEXT_INGREDIENT;
 case NEXT_INGREDIENT: {
   if (!ingredients.empty()) {
     raise << current_recipe_name() << ": 'next-ingredient' didn't expect any ingredients in '" << current_instruction().to_string() << "'\n" << end();
-    products.resize(2);
     break;
   }
   assert(!Current_routine->calls.empty());
@@ -102,12 +101,10 @@ Recipe_ordinal["ingredient"] = INGREDIENT;
 case INGREDIENT: {
   if (SIZE(ingredients) != 1) {
     raise << current_recipe_name() << ": 'ingredient' expects exactly one ingredient, but got '" << current_instruction().to_string() << "'\n" << end();
-    products.resize(2);
     break;
   }
   if (!is_literal(current_instruction().ingredients.at(0))) {
     raise << current_recipe_name() << ": 'ingredient' expects a literal ingredient, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end();
-    products.resize(2);
     break;
   }
   assert(scalar(ingredients.at(0)));
diff --git a/038scheduler.cc b/038scheduler.cc
index 5925abab..d32fb76a 100644
--- a/038scheduler.cc
+++ b/038scheduler.cc
@@ -281,7 +281,6 @@ ROUTINE_STATE,
 Recipe_ordinal["routine-state"] = ROUTINE_STATE;
 :(before "End Primitive Recipe Implementations")
 case ROUTINE_STATE: {
-  products.resize(1);
   if (SIZE(ingredients) != 1) {
     raise << current_recipe_name() << ": 'routine-state' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end();
     break;
@@ -298,6 +297,7 @@ case ROUTINE_STATE: {
       break;
     }
   }
+  products.resize(1);
   products.at(0).push_back(result);
   break;
 }
diff --git a/043new.cc b/043new.cc
index c324bff7..89c3cc23 100644
--- a/043new.cc
+++ b/043new.cc
@@ -56,7 +56,6 @@ NEW,
 Recipe_ordinal["new"] = NEW;
 :(before "End Primitive Recipe Implementations")
 case NEW: {
-  products.resize(1);
   if (ingredients.empty() || SIZE(ingredients) > 2) {
     raise << current_recipe_name() << ": 'new' requires one or two ingredients, but got " << current_instruction().to_string() << '\n' << end();
     break;
@@ -90,6 +89,7 @@ case NEW: {
   const long long int result = Current_routine->alloc;
   trace(Primitive_recipe_depth, "mem") << "new alloc: " << result << end();
   // save result
+  products.resize(1);
   products.at(0).push_back(result);
   // initialize allocated space
   for (long long int address = result; address < result+size; ++address) {
diff --git a/053continuation.cc b/053continuation.cc
index 5885fd40..20cf1b05 100644
--- a/053continuation.cc
+++ b/053continuation.cc
@@ -193,7 +193,6 @@ REPLY_DELIMITED_CONTINUATION,
 Recipe_ordinal["reply-delimited-continuation"] = REPLY_DELIMITED_CONTINUATION;
 :(before "End Primitive Recipe Implementations")
 case REPLY_DELIMITED_CONTINUATION: {
-  products.resize(1);
   // first clear any existing ingredients, to isolate the creation of the
   // continuation from its calls
   Current_routine->calls.front().ingredient_atoms.clear();
@@ -211,6 +210,7 @@ case REPLY_DELIMITED_CONTINUATION: {
     Current_routine->calls.pop_front();
   }
   // return it as the result of the 'reset' call
+  products.resize(1);
   products.at(0).push_back(Next_delimited_continuation_id);
   ++Next_delimited_continuation_id;
   break;  // continue to process rest of 'reset' call
diff --git a/064random.cc b/064random.cc
index cdc519c9..bd171132 100644
--- a/064random.cc
+++ b/064random.cc
@@ -27,7 +27,6 @@ ROUND,
 Recipe_ordinal["round"] = ROUND;
 :(before "End Primitive Recipe Implementations")
 case ROUND: {
-  products.resize(1);
   if (SIZE(ingredients) != 1) {
     raise << current_recipe_name() << ": 'round' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end();
     break;
@@ -36,6 +35,7 @@ case ROUND: {
     raise << current_recipe_name() << ": first ingredient of 'round' should be a number, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end();
     break;
   }
+  products.resize(1);
   products.at(0).push_back(rint(ingredients.at(0).at(0)));
   break;
 }
diff --git a/081run_interactive.cc b/081run_interactive.cc
index 59c79432..e627b0f6 100644
--- a/081run_interactive.cc
+++ b/081run_interactive.cc
@@ -27,7 +27,6 @@ Recipe_ordinal["run-interactive"] = RUN_INTERACTIVE;
 //? cerr << "run-interactive: " << RUN_INTERACTIVE << '\n'; //? 1
 :(before "End Primitive Recipe Implementations")
 case RUN_INTERACTIVE: {
-  products.resize(4);
   if (SIZE(ingredients) != 1) {
     raise << current_recipe_name() << ": 'run-interactive' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end();
     break;
@@ -38,6 +37,7 @@ case RUN_INTERACTIVE: {
   }
   bool new_code_pushed_to_stack = run_interactive(ingredients.at(0).at(0));
   if (!new_code_pushed_to_stack) {
+    products.resize(4);
     products.at(0).push_back(0);
     products.at(1).push_back(trace_contents("warn"));
     products.at(2).push_back(0);
@@ -153,6 +153,14 @@ void record_products(const instruction& instruction, const vector<vector<double>
     // string
     if (i < SIZE(instruction.products)) {
       if (is_mu_string(instruction.products.at(i))) {
+        if (!scalar(products.at(i))) {
+          tb_shutdown();
+          cerr << read_mu_string(trace_contents("warn")) << '\n';
+          cerr << SIZE(products.at(i)) << ": ";
+          for (long long int j = 0; j < SIZE(products.at(i)); ++j)
+            cerr << products.at(i).at(j) << ' ';
+          cerr << '\n';
+        }
         assert(scalar(products.at(i)));
         out << read_mu_string(products.at(i).at(0)) << '\n';
         continue;
@@ -281,7 +289,6 @@ RELOAD,
 Recipe_ordinal["reload"] = RELOAD;
 :(before "End Primitive Recipe Implementations")
 case RELOAD: {
-  products.resize(1);
   if (SIZE(ingredients) != 1) {
     raise << current_recipe_name() << ": 'reload' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end();
     break;
@@ -302,6 +309,7 @@ case RELOAD: {
   Trace_stream->newline();  // flush trace
   Disable_redefine_warnings = false;
   Hide_warnings = false;
+  products.resize(1);
   products.at(0).push_back(trace_contents("warn"));
   // hack: assume collect_layers isn't set anywhere else
   if (Trace_stream->is_narrowly_collecting("warn")) {
diff --git a/082persist.cc b/082persist.cc
index f10b44a2..3b0bb987 100644
--- a/082persist.cc
+++ b/082persist.cc
@@ -8,7 +8,6 @@ RESTORE,
 Recipe_ordinal["restore"] = RESTORE;
 :(before "End Primitive Recipe Implementations")
 case RESTORE: {
-  products.resize(1);
   if (SIZE(ingredients) != 1) {
     raise << current_recipe_name() << ": 'restore' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end();
     break;
@@ -26,6 +25,7 @@ case RESTORE: {
   }
   if (Current_scenario) break;  // do nothing in tests
   string contents = slurp("lesson/"+filename);
+  products.resize(1);
   if (contents.empty())
     products.at(0).push_back(0);
   else