about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-10-02 00:28:08 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-10-02 00:28:08 -0700
commitaf7a5722df4b71f679bd2bae40601916682bbb59 (patch)
tree60489d5cbb4367470393eb276df995be42dd9576
parent2142ccfc37db49b59ff7e4da47a59adb3a043615 (diff)
downloadmu-af7a5722df4b71f679bd2bae40601916682bbb59.tar.gz
2234 - check type of get's product
Already I'm finding type errors in the programming environment.
-rw-r--r--030container.cc33
-rw-r--r--031address.cc2
-rw-r--r--065duplex_list.mu20
-rw-r--r--edit/011-editor-undo.mu18
4 files changed, 53 insertions, 20 deletions
diff --git a/030container.cc b/030container.cc
index 8071ff4c..1f62fe58 100644
--- a/030container.cc
+++ b/030container.cc
@@ -140,13 +140,24 @@ case GET: {
     raise << maybe(Recipe[r].name) << "second ingredient of 'get' should have type 'offset', but got " << inst.ingredients.at(1).original_string << '\n' << end();
     break;
   }
+  long long int offset_value = 0;
   if (is_integer(offset.name)) {  // later layers permit non-integer offsets
-    long long int offset_value = to_integer(offset.name);
+    offset_value = to_integer(offset.name);
     if (offset_value < 0 || offset_value >= SIZE(Type[base_type].elements)) {
       raise << maybe(Recipe[r].name) << "invalid offset " << offset_value << " for " << Type[base_type].name << '\n' << end();
       break;
     }
   }
+  else {
+    offset_value = offset.value;
+  }
+  reagent product = inst.products.at(0);
+  // Update GET product in Check
+  reagent element;
+  element.types = Type[base_type].elements.at(offset_value);
+  if (!types_match(product, element)) {
+    raise << maybe(Recipe[r].name) << "'get' " << offset.original_string << " (" << offset_value << ") on " << Type[base_type].name << " can't be saved in " << product.original_string << "; type should be " << dump_types(element) << '\n' << end();
+  }
   break;
 }
 :(before "End Primitive Recipe Implementations")
@@ -175,6 +186,16 @@ case GET: {
   break;
 }
 
+:(code)
+string dump_types(const reagent& x) {
+  ostringstream out;
+  for (long long int i = 0; i < SIZE(x.types); ++i) {
+    if (i > 0) out << ':';
+    out << Type[x.types.at(i)].name;
+  }
+  return out.str();
+}
+
 :(scenario get_handles_nested_container_elements)
 recipe main [
   12:number <- copy 34
@@ -214,6 +235,16 @@ recipe main [
 ]
 +warn: main: invalid offset -1 for point-number
 
+:(scenario get_product_type_mismatch)
+% Hide_warnings = true;
+recipe main [
+  12:number <- copy 34
+  13:number <- copy 35
+  14:number <- copy 36
+  15:address:number <- get 12:point-number/raw, 1:offset
+]
++warn: main: 'get' 1:offset (1) on point-number can't be saved in 15:address:number; type should be number
+
 :(before "End Primitive Recipe Declarations")
 GET_ADDRESS,
 :(before "End Primitive Recipe Numbers")
diff --git a/031address.cc b/031address.cc
index b01bc036..d5f00b56 100644
--- a/031address.cc
+++ b/031address.cc
@@ -141,6 +141,8 @@ recipe main [
 
 :(after "Update GET base in Check")
 if (!canonize_type(base)) break;
+:(after "Update GET product in Check")
+if (!canonize_type(product)) break;
 :(after "Update GET base in Run")
 base = canonize(base);
 
diff --git a/065duplex_list.mu b/065duplex_list.mu
index 409f88cd..3cf01c47 100644
--- a/065duplex_list.mu
+++ b/065duplex_list.mu
@@ -1,7 +1,7 @@
 # A doubly linked list permits bidirectional traversal.
 
 container duplex-list [
-  value:location
+  value:character
   next:address:duplex-list
   prev:address:duplex-list
 ]
@@ -27,7 +27,7 @@ recipe first-duplex [
   local-scope
   in:address:duplex-list <- next-ingredient
   reply-unless in, 0
-  result:location <- get *in, value:offset
+  result:character <- get *in, value:offset
   reply result
 ]
 
@@ -410,11 +410,11 @@ scenario remove-range [
     2:address:duplex-list <- next-duplex 2:address:duplex-list
     remove-duplex-between 2:address:duplex-list, 0
     # now check the list
-    4:number <- get *1:address:duplex-list, value:offset
+    4:character <- get *1:address:duplex-list, value:offset
     5:address:duplex-list <- next-duplex 1:address:duplex-list
-    6:number <- get *5:address:duplex-list, value:offset
+    6:character <- get *5:address:duplex-list, value:offset
     7:address:duplex-list <- next-duplex 5:address:duplex-list
-    8:number <- get *7:address:duplex-list, value:offset
+    8:character <- get *7:address:duplex-list, value:offset
     9:address:duplex-list <- next-duplex 7:address:duplex-list
   ]
   memory-should-contain [
@@ -445,11 +445,11 @@ scenario remove-range-to-end [
     3:address:duplex-list <- next-duplex 3:address:duplex-list
     remove-duplex-between 2:address:duplex-list, 3:address:duplex-list
     # now check the list
-    4:number <- get *1:address:duplex-list, value:offset
+    4:character <- get *1:address:duplex-list, value:offset
     5:address:duplex-list <- next-duplex 1:address:duplex-list
-    6:number <- get *5:address:duplex-list, value:offset
+    6:character <- get *5:address:duplex-list, value:offset
     7:address:duplex-list <- next-duplex 5:address:duplex-list
-    8:number <- get *7:address:duplex-list, value:offset
+    8:character <- get *7:address:duplex-list, value:offset
     9:address:duplex-list <- next-duplex 7:address:duplex-list
   ]
   memory-should-contain [
@@ -471,9 +471,9 @@ scenario remove-range-empty [
     2:address:duplex-list <- next-duplex 1:address:duplex-list
     remove-duplex-between 1:address:duplex-list, 2:address:duplex-list
     # now check the list
-    4:number <- get *1:address:duplex-list, value:offset
+    4:character <- get *1:address:duplex-list, value:offset
     5:address:duplex-list <- next-duplex 1:address:duplex-list
-    6:number <- get *5:address:duplex-list, value:offset
+    6:character <- get *5:address:duplex-list, value:offset
     7:address:duplex-list <- next-duplex 5:address:duplex-list
   ]
   memory-should-contain [
diff --git a/edit/011-editor-undo.mu b/edit/011-editor-undo.mu
index adf85130..217cbd20 100644
--- a/edit/011-editor-undo.mu
+++ b/edit/011-editor-undo.mu
@@ -155,7 +155,7 @@ before <insert-character-end> [
     *after-row <- copy *cursor-row
     after-column:address:number <- get-address *typing, after-column:offset
     *after-column <- copy *cursor-column
-    after-top:address:number <- get-address *typing, after-top-of-screen:offset
+    after-top:address:address:duplex-list:character <- get-address *typing, after-top-of-screen:offset
     *after-top <- get *editor, top-of-screen:offset
     break +done-adding-insert-operation:label
   }
@@ -211,7 +211,7 @@ after <handle-undo> [
     remove-duplex-between *before-cursor, end
     *cursor-row <- get *typing, before-row:offset
     *cursor-column <- get *typing, before-column:offset
-    top:address:address:duplex-list <- get *editor, top-of-screen:offset
+    top:address:address:duplex-list <- get-address *editor, top-of-screen:offset
     *top <- get *typing, before-top-of-screen:offset
   }
 ]
@@ -407,7 +407,7 @@ after <handle-redo> [
     # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen
     *cursor-row <- get *typing, after-row:offset
     *cursor-column <- get *typing, after-column:offset
-    top:address:address:duplex-list <- get *editor, top-of-screen:offset
+    top:address:address:duplex-list <- get-address *editor, top-of-screen:offset
     *top <- get *typing, after-top-of-screen:offset
   }
 ]
@@ -725,7 +725,7 @@ before <move-cursor-end> [
     *after-row <- copy after-cursor-row
     after-column:address:number <- get-address *move, after-column:offset
     *after-column <- copy after-cursor-column
-    after-top:address:number <- get-address *move, after-top-of-screen:offset
+    after-top:address:address:duplex-list:character <- get-address *move, after-top-of-screen:offset
     *after-top <- get *editor, top-of-screen:offset
     break +done-adding-move-operation:label
   }
@@ -1516,7 +1516,7 @@ after <handle-redo> [
     # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen
     *cursor-row <- get *move, after-row:offset
     *cursor-column <- get *move, after-column:offset
-    top:address:address:duplex-list <- get *editor, top-of-screen:offset
+    top:address:address:duplex-list <- get-address *editor, top-of-screen:offset
     *top <- get *move, after-top-of-screen:offset
   }
 ]
@@ -1615,7 +1615,7 @@ before <backspace-character-end> [
       *after-row <- copy *cursor-row
       after-column:address:number <- get-address *deletion, after-column:offset
       *after-column <- copy *cursor-column
-      after-top:address:number <- get-address *deletion, after-top-of-screen:offset
+      after-top:address:address:duplex-list:character <- get-address *deletion, after-top-of-screen:offset
       *after-top <- get *editor, top-of-screen:offset
       break +done-adding-backspace-operation:label
     }
@@ -1642,7 +1642,7 @@ after <handle-undo> [
     *before-cursor <- copy old-cursor
     *cursor-row <- get *deletion, before-row:offset
     *cursor-column <- get *deletion, before-column:offset
-    top:address:address:duplex-list <- get *editor, top-of-screen:offset
+    top:address:address:duplex-list <- get-address *editor, top-of-screen:offset
     *top <- get *deletion, before-top-of-screen:offset
   }
 ]
@@ -1657,7 +1657,7 @@ after <handle-redo> [
     # assert cursor-row/cursor-column/top-of-screen match after-row/after-column/after-top-of-screen
     *cursor-row <- get *deletion, after-row:offset
     *cursor-column <- get *deletion, after-column:offset
-    top:address:address:duplex-list <- get *editor, top-of-screen:offset
+    top:address:address:duplex-list <- get-address *editor, top-of-screen:offset
     *top <- get *deletion, after-top-of-screen:offset
   }
 ]
@@ -1836,7 +1836,7 @@ before <delete-character-end> [
       *after-row <- copy *cursor-row
       after-column:address:number <- get-address *deletion, after-column:offset
       *after-column <- copy *cursor-column
-      after-top:address:number <- get-address *deletion, after-top-of-screen:offset
+      after-top:address:address:duplex-list:character <- get-address *deletion, after-top-of-screen:offset
       *after-top <- get *editor, top-of-screen:offset
       break +done-adding-delete-operation:label
     }