about summary refs log tree commit diff stats
path: root/027call_ingredient.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-06-15 22:12:03 -0700
committerKartik Agaram <vc@akkartik.com>2018-06-15 22:12:03 -0700
commit0edd9b9fc60440213e4df926ea511419ee291f1e (patch)
tree84b22f7afdeb9110ad7105c5fc070dacff178502 /027call_ingredient.cc
parent3f34ac9369978b396d00a4fd02c9fb06b8eea621 (diff)
downloadmu-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 '027call_ingredient.cc')
-rw-r--r--027call_ingredient.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/027call_ingredient.cc b/027call_ingredient.cc
index 46fafe7e..00e44ea3 100644
--- a/027call_ingredient.cc
+++ b/027call_ingredient.cc
@@ -68,6 +68,9 @@ case NEXT_INGREDIENT: {
     }
     products.push_back(
         current_call().ingredient_atoms.at(current_call().next_ingredient_to_process));
+    if (is_mu_scalar(current_call().ingredients.at(current_call().next_ingredient_to_process))
+        && is_mu_address(current_instruction().products.at(0)))
+      products.at(0).insert(products.at(0).begin(), /*alloc id*/0);
     assert(SIZE(products) == 1);  products.resize(2);  // push a new vector
     products.at(1).push_back(1);
     ++current_call().next_ingredient_to_process;
@@ -94,6 +97,18 @@ def f [
 ]
 +error: f: no ingredient to save in '11:num'
 
+:(scenario pass_null_ingredient_for_address)
+def main [
+  f 0
+]
+def f [
+  1:address:num <- next-ingredient
+]
++mem: storing 0 in location 2
+$error: 0
+
+//: another primitive: 'rewind-ingredients' to rescan ingredients from the start
+
 :(scenario rewind_ingredients)
 def main [
   f 2
@@ -124,6 +139,8 @@ case REWIND_INGREDIENTS: {
   break;
 }
 
+//: another primitive: 'ingredient' for random access
+
 :(scenario ingredient)
 def main [
   f 1, 2