diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-06-15 22:12:03 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-06-15 22:12:03 -0700 |
commit | 0edd9b9fc60440213e4df926ea511419ee291f1e (patch) | |
tree | 84b22f7afdeb9110ad7105c5fc070dacff178502 /022arithmetic.cc | |
parent | 3f34ac9369978b396d00a4fd02c9fb06b8eea621 (diff) | |
download | mu-0edd9b9fc60440213e4df926ea511419ee291f1e.tar.gz |
4257 - abortive attempt at safe fat pointers
I've been working on this slowly over several weeks, but it's too hard to support 0 as the null value for addresses. I constantly have to add exceptions for scalar value corresponding to an address type (now occupying 2 locations). The final straw is the test for 'reload': x:num <- reload text 'reload' returns an address. But there's no way to know that for arbitrary instructions. New plan: let's put this off for a bit and first create support for literals. Then use 'null' instead of '0' for addresses everywhere. Then it'll be easy to just change what 'null' means.
Diffstat (limited to '022arithmetic.cc')
-rw-r--r-- | 022arithmetic.cc | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/022arithmetic.cc b/022arithmetic.cc index 530541aa..50a54578 100644 --- a/022arithmetic.cc +++ b/022arithmetic.cc @@ -95,18 +95,25 @@ case SUBTRACT: { } break; } +:(code) +bool is_raw(const reagent& r) { + return has_property(r, "raw"); +} + :(before "End Primitive Recipe Implementations") case SUBTRACT: { - double result = ingredients.at(0).at(0); + double result = scalar_ingredient(ingredients, 0); for (int i = 1; i < SIZE(ingredients); ++i) - result -= ingredients.at(i).at(0); + result -= scalar_ingredient(ingredients, i); products.resize(1); products.at(0).push_back(result); break; } :(code) -bool is_raw(const reagent& r) { - return has_property(r, "raw"); +double scalar_ingredient(const vector<vector<double> >& ingredients, int i) { + if (is_mu_address(current_instruction().ingredients.at(i))) + return ingredients.at(i).at(1); // skip alloc id + return ingredients.at(i).at(0); } :(scenario subtract_literal) |