about summary refs log tree commit diff stats
path: root/021arithmetic.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-07-25 14:19:28 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-07-25 17:14:58 -0700
commite46306432ddb75a89f69d92ccc175a23f0b72072 (patch)
tree48ed3828064f29cefaf14e3fe61d7dc02cac0e80 /021arithmetic.cc
parente83602d3917eba137cd8fb37605076fff5a746b1 (diff)
downloadmu-e46306432ddb75a89f69d92ccc175a23f0b72072.tar.gz
1848 - core instructions now check for ingredients
Also standardized warnings.
Diffstat (limited to '021arithmetic.cc')
-rw-r--r--021arithmetic.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/021arithmetic.cc b/021arithmetic.cc
index 0701e82a..51df6f46 100644
--- a/021arithmetic.cc
+++ b/021arithmetic.cc
@@ -43,6 +43,10 @@ SUBTRACT,
 Recipe_ordinal["subtract"] = SUBTRACT;
 :(before "End Primitive Recipe Implementations")
 case SUBTRACT: {
+  if (ingredients.empty()) {
+    raise << current_recipe_name() << ": 'subtract' has no ingredients\n" << end();
+    break;
+  }
   assert(scalar(ingredients.at(0)));
   double result = ingredients.at(0).at(0);
   for (long long int i = 1; i < SIZE(ingredients); ++i) {
@@ -116,6 +120,10 @@ DIVIDE,
 Recipe_ordinal["divide"] = DIVIDE;
 :(before "End Primitive Recipe Implementations")
 case DIVIDE: {
+  if (ingredients.empty()) {
+    raise << current_recipe_name() << ": 'divide' has no ingredients\n" << end();
+    break;
+  }
   assert(scalar(ingredients.at(0)));
   double result = ingredients.at(0).at(0);
   for (long long int i = 1; i < SIZE(ingredients); ++i) {
@@ -155,6 +163,10 @@ DIVIDE_WITH_REMAINDER,
 Recipe_ordinal["divide-with-remainder"] = DIVIDE_WITH_REMAINDER;
 :(before "End Primitive Recipe Implementations")
 case DIVIDE_WITH_REMAINDER: {
+  if (SIZE(ingredients) != 2) {
+    raise << current_recipe_name() << ": 'divide-with-remainder' requires exactly two ingredients, but got " << current_instruction().to_string() << '\n' << end();
+    break;
+  }
   long long int quotient = ingredients.at(0).at(0) / ingredients.at(1).at(0);
   long long int remainder = static_cast<long long int>(ingredients.at(0).at(0)) % static_cast<long long int>(ingredients.at(1).at(0));
   products.resize(2);