about summary refs log tree commit diff stats
path: root/032array.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-12 13:10:23 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-12 17:00:19 -0700
commit3663ca6c2d4c42c4a7bf6af4b2edf71dd8d10dd7 (patch)
tree330d04974b9d30bff1b16adc8d14a3d9fd77643d /032array.cc
parenta70d593dfb8eea87a898a69adeb9689a21199edf (diff)
downloadmu-3663ca6c2d4c42c4a7bf6af4b2edf71dd8d10dd7.tar.gz
1356 - snapshot #2: floating point support
I added one test to check that divide can return a float, then hacked at
the rippling failures across the entire entire codebase until all tests
pass. Now I need to look at the changes I made and see if there's a
system to them, identify other places that I missed, and figure out the
best way to cover all cases. I also need to show real rather than
encoded values in the traces, but I can't use value() inside reagent
methods because of the name clash with the member variable. So let's
take a snapshot before we attempt any refactoring. This was non-trivial
to get right.

Even if I convince myself that I've gotten it right, I might back this
all out if I can't easily *persuade others* that I've gotten it right.
Diffstat (limited to '032array.cc')
-rw-r--r--032array.cc21
1 files changed, 12 insertions, 9 deletions
diff --git a/032array.cc b/032array.cc
index 67b03293..19a4ac50 100644
--- a/032array.cc
+++ b/032array.cc
@@ -53,7 +53,7 @@ if (x.types.at(0) != Type_number["array"] && size_of(x) != data.size())
   if (r.types.at(0) == Type_number["array"]) {
     assert(r.types.size() > 1);
     // skip the 'array' type to get at the element type
-    return 1 + Memory[r.value]*size_of(array_element(r.types));
+    return 1 + value(Memory[r.value])*size_of(array_element(r.types));
   }
 
 //:: To access elements of an array, use 'index'
@@ -98,7 +98,8 @@ case INDEX: {
 //?   if (Trace_stream) Trace_stream->dump_layer = "run"; //? 1
   reagent base = canonize(current_instruction().ingredients.at(0));
 //?   trace("run") << "ingredient 0 after canonize: " << base.to_string(); //? 1
-  index_t base_address = base.value;
+  assert(!is_negative(base.value));
+  index_t base_address = value(base.value);
   assert(base.types.at(0) == Type_number["array"]);
   reagent offset = canonize(current_instruction().ingredients.at(1));
 //?   trace("run") << "ingredient 1 after canonize: " << offset.to_string(); //? 1
@@ -106,11 +107,12 @@ case INDEX: {
   vector<type_number> element_type = array_element(base.types);
 //?   trace("run") << "offset: " << offset_val.at(0); //? 1
 //?   trace("run") << "size of elements: " << size_of(element_type); //? 1
-  index_t src = base_address + 1 + offset_val.at(0)*size_of(element_type);
+  assert(offset_val.size() == 1);  // scalar
+  index_t src = base_address + 1 + value(offset_val.at(0))*size_of(element_type);
   trace("run") << "address to copy is " << src;
   trace("run") << "its type is " << element_type.at(0);
   reagent tmp;
-  tmp.set_value(src);
+  tmp.set_value(mu_integer(src));
   copy(element_type.begin(), element_type.end(), inserter(tmp.types, tmp.types.begin()));
   products.push_back(read_memory(tmp));
   break;
@@ -153,13 +155,14 @@ Recipe_number["index-address"] = INDEX_ADDRESS;
 :(before "End Primitive Recipe Implementations")
 case INDEX_ADDRESS: {
   reagent base = canonize(current_instruction().ingredients.at(0));
-  index_t base_address = base.value;
+  assert(!is_negative(base.value));
+  index_t base_address = value(base.value);
   assert(base.types.at(0) == Type_number["array"]);
-  reagent offset = canonize(current_instruction().ingredients.at(1));
-  vector<long long int> offset_val(read_memory(offset));
+  vector<long long int>& offset_val = ingredients.at(1);
+  assert(offset_val.size() == 1);
   vector<type_number> element_type = array_element(base.types);
-  index_t result = base_address + 1 + offset_val.at(0)*size_of(element_type);
+  index_t result = base_address + 1 + value(offset_val.at(0))*size_of(element_type);
   products.resize(1);
-  products.at(0).push_back(result);
+  products.at(0).push_back(mu_integer(result));  // address must be a positive integer
   break;
 }