about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-04-23 14:51:20 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-04-23 14:51:20 -0700
commit991d76f32817f5515fb8db25a7d5ca2912cfe4ac (patch)
treec6b719df15532d4d5b91feae1f927f2be8a7dc9e
parent538815670a8747e68dd95cd43e0ac1fce184f781 (diff)
downloadmu-991d76f32817f5515fb8db25a7d5ca2912cfe4ac.tar.gz
2860 - rename 'index-address' to 'put-index'
-rw-r--r--032array.cc83
-rw-r--r--054parse_tree.cc8
-rw-r--r--070text.mu40
-rw-r--r--072channel.mu3
-rw-r--r--073array.mu3
-rw-r--r--079table.mu7
-rw-r--r--081print.mu12
-rwxr-xr-xbuild_and_test_until2
-rw-r--r--chessboard.mu19
9 files changed, 78 insertions, 99 deletions
diff --git a/032array.cc b/032array.cc
index 35d86fa6..e54b7ea6 100644
--- a/032array.cc
+++ b/032array.cc
@@ -315,48 +315,50 @@ def main [
 ]
 # just don't die
 
-//:: To write to elements of containers, you need their address.
+//:: To write to elements of arrays, use 'put'.
 
-:(scenario index_address)
+:(scenario put_index)
 def main [
   1:array:number:3 <- create-array
   2:number <- copy 14
   3:number <- copy 15
   4:number <- copy 16
-  5:address:number <- index-address 1:array:number, 0
+  1:array:number <- put-index 1:array:number, 1, 34
 ]
-+mem: storing 2 in location 5
++mem: storing 34 in location 3
 
 :(before "End Primitive Recipe Declarations")
-INDEX_ADDRESS,
+PUT_INDEX,
 :(before "End Primitive Recipe Numbers")
-put(Recipe_ordinal, "index-address", INDEX_ADDRESS);
+put(Recipe_ordinal, "put-index", PUT_INDEX);
 :(before "End Primitive Recipe Checks")
-case INDEX_ADDRESS: {
-  if (SIZE(inst.ingredients) != 2) {
-    raise << maybe(get(Recipe, r).name) << "'index-address' expects exactly 2 ingredients in '" << to_original_string(inst) << "'\n" << end();
+case PUT_INDEX: {
+  if (SIZE(inst.ingredients) != 3) {
+    raise << maybe(get(Recipe, r).name) << "'put-index' expects exactly 3 ingredients in '" << to_original_string(inst) << "'\n" << end();
     break;
   }
   reagent base = inst.ingredients.at(0);
-  canonize_type(base);
+  if (!canonize_type(base)) break;
   if (!is_mu_array(base)) {
-    raise << maybe(get(Recipe, r).name) << "'index-address' on a non-array " << base.original_string << '\n' << end();
+    raise << maybe(get(Recipe, r).name) << "'put-index' on a non-array " << base.original_string << '\n' << end();
     break;
   }
-  if (inst.products.empty()) break;
-  reagent product = inst.products.at(0);
-  canonize_type(product);
+  if (!is_mu_number(inst.ingredients.at(1))) {
+    raise << maybe(get(Recipe, r).name) << "second ingredient of 'put-index' should have type 'number', but got " << inst.ingredients.at(1).original_string << '\n' << end();
+    break;
+  }
+  reagent value = inst.ingredients.at(2);
+  canonize_type(value);
   reagent element;
-  element.type = new type_tree("address", get(Type_ordinal, "address"),
-                               new type_tree(*array_element(base.type)));
-  if (!types_coercible(product, element)) {
-    raise << maybe(get(Recipe, r).name) << "'index' on " << base.original_string << " can't be saved in " << product.original_string << "; type should be " << names_to_string_without_quotes(element.type) << '\n' << end();
+  element.type = new type_tree(*array_element(base.type));
+  if (!types_coercible(element, value)) {
+    raise << maybe(get(Recipe, r).name) << "'put-index " << base.original_string << ", " << inst.ingredients.at(1).original_string << "' should store " << names_to_string_without_quotes(element.type) << " but " << value.name << " has type " << names_to_string_without_quotes(value.type) << '\n' << end();
     break;
   }
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case INDEX_ADDRESS: {
+case PUT_INDEX: {
   reagent base = current_instruction().ingredients.at(0);
   canonize(base);
   int base_address = base.value;
@@ -372,13 +374,19 @@ case INDEX_ADDRESS: {
     raise << maybe(current_recipe_name()) << "invalid index " << no_scientific(offset_val.at(0)) << '\n' << end();
     break;
   }
-  int result = base_address + 1 + offset_val.at(0)*size_of(element_type);
-  products.resize(1);
-  products.at(0).push_back(result);
-  break;
+  int address = base_address + 1 + offset_val.at(0)*size_of(element_type);
+  trace(9998, "run") << "address to copy to is " << address << end();
+  // optimization: directly write the element rather than updating 'product'
+  // and writing the entire array
+  vector<double> value = read_memory(current_instruction().ingredients.at(2));
+  for (int i = 0; i < SIZE(value); ++i) {
+    trace(9999, "mem") << "storing " << no_scientific(value.at(i)) << " in location " << address+i << end();
+    put(Memory, address+i, value.at(i));
+  }
+  goto finish_instruction;
 }
 
-:(scenario index_address_out_of_bounds)
+:(scenario put_index_out_of_bounds)
 % Hide_errors = true;
 def main [
   1:array:point:3 <- create-array
@@ -388,12 +396,12 @@ def main [
   5:number <- copy 14
   6:number <- copy 15
   7:number <- copy 16
-  8:address:array:point <- copy 1/unsafe
-  index-address *8:address:array:point, 4  # less than size of array in locations, but larger than its length in elements
+  8:point <- merge 34, 35
+  1:array:point <- put-index 1:array:point, 4, 8:point  # '4' is less than size of array in locations, but larger than its length in elements
 ]
 +error: main: invalid index 4
 
-:(scenario index_address_out_of_bounds_2)
+:(scenario put_index_out_of_bounds_2)
 % Hide_errors = true;
 def main [
   1:array:point:3 <- create-array
@@ -403,26 +411,11 @@ def main [
   5:number <- copy 14
   6:number <- copy 15
   7:number <- copy 16
-  8:address:array:point <- copy 1/unsafe
-  index-address *8:address:array:point, -1
+  8:point <- merge 34, 35
+  1:array:point <- put-index 1:array:point, -1, 8:point
 ]
 +error: main: invalid index -1
 
-:(scenario index_address_product_type_mismatch)
-% Hide_errors = true;
-def main [
-  1:array:point:3 <- create-array
-  2:number <- copy 14
-  3:number <- copy 15
-  4:number <- copy 16
-  5:number <- copy 14
-  6:number <- copy 15
-  7:number <- copy 16
-  8:address:array:point <- copy 1/unsafe
-  9:address:number <- index-address *8:address:array:point, 0
-]
-+error: main: 'index' on *8:address:array:point can't be saved in 9:address:number; type should be (address point)
-
 //:: compute the length of an array
 
 :(scenario array_length)
@@ -470,7 +463,7 @@ case LENGTH: {
 //: stop copying potentially huge arrays into it.
 :(before "End should_copy_ingredients Special-cases")
 recipe_ordinal r = current_instruction().operation;
-if (r == CREATE_ARRAY || r == INDEX || r == INDEX_ADDRESS || r == LENGTH)
+if (r == CREATE_ARRAY || r == INDEX || r == PUT_INDEX || r == LENGTH)
   return false;
 
 //: a particularly common array type is the string, or address:array:character
diff --git a/054parse_tree.cc b/054parse_tree.cc
index 8724b6f4..0ad8773f 100644
--- a/054parse_tree.cc
+++ b/054parse_tree.cc
@@ -72,10 +72,10 @@ container bar [
 :(scenario dilated_reagent_in_static_array)
 def main [
   {1: (array (address shared number) 3)} <- create-array
-  5:address:address:shared:number <- index-address {1: (array (address shared number) 3)}, 0
-  *5:address:address:shared:number <- new number:type
-  **5:address:address:shared:number <- copy 34
-  6:number <- copy **5:address:address:shared:number
+  5:address:shared:number <- new number:type
+  {1: (array (address shared number) 3)} <- put-index {1: (array (address shared number) 3)}, 0, 5:address:shared:number
+  *5:address:shared:number <- copy 34
+  6:number <- copy *5:address:shared:number
 ]
 +run: creating array of size 4
 +mem: storing 34 in location 6
diff --git a/070text.mu b/070text.mu
index 1e1999c7..93fe3f41 100644
--- a/070text.mu
+++ b/070text.mu
@@ -149,8 +149,7 @@ def grow-buffer in:address:shared:buffer -> in:address:shared:buffer [
     done?:boolean <- greater-or-equal i, oldlen
     break-if done?
     src:character <- index *olddata, i
-    dest:address:character <- index-address *newdata, i
-    *dest <- copy src
+    *newdata <- put-index *newdata, i, src
     i <- add i, 1
     loop
   }
@@ -203,8 +202,7 @@ def append in:address:shared:buffer, c:character -> in:address:shared:buffer [
     in <- grow-buffer in
   }
   s:address:shared:array:character <- get *in, data:offset
-  dest:address:character <- index-address *s, len
-  *dest <- copy c
+  *s <- put-index *s, len, c
   len <- add len, 1
   *in <- put *in, length:offset, len
 ]
@@ -317,8 +315,7 @@ def to-text n:number -> result:address:shared:array:character [
     break-if done?
     # result[j] = tmp[i]
     src:character <- index *buf, i
-    dest:address:character <- index-address *result, j
-    *dest <- copy src
+    *result <- put-index *result, j, src
     i <- subtract i, 1
     j <- add j, 1
     loop
@@ -356,8 +353,7 @@ def buffer-to-array in:address:shared:buffer -> result:address:shared:array:char
     done?:boolean <- greater-or-equal i, len
     break-if done?
     src:character <- index *s, i
-    dest:address:character <- index-address *result, i
-    *dest <- copy src
+    *result <- put-index *result, i, src
     i <- add i, 1
     loop
   }
@@ -411,9 +407,8 @@ def append a:address:shared:array:character, b:address:shared:array:character ->
     a-done?:boolean <- greater-or-equal i, a-len
     break-if a-done?
     # result[result-idx] = a[i]
-    out:address:character <- index-address *result, result-idx
     in:character <- index *a, i
-    *out <- copy in
+    *result <- put-index *result, result-idx, in
     i <- add i, 1
     result-idx <- add result-idx, 1
     loop
@@ -425,9 +420,8 @@ def append a:address:shared:array:character, b:address:shared:array:character ->
     b-done?:boolean <- greater-or-equal i, b-len
     break-if b-done?
     # result[result-idx] = a[i]
-    out:address:character <- index-address *result, result-idx
     in:character <- index *b, i
-    *out <- copy in
+    *result <- put-index *result, result-idx, in
     i <- add i, 1
     result-idx <- add result-idx, 1
     loop
@@ -464,8 +458,7 @@ def replace s:address:shared:array:character, oldc:character, newc:character, fr
   i:number <- find-next s, oldc, from
   done?:boolean <- greater-or-equal i, len
   return-if done?, s/same-as-ingredient:0
-  dest:address:character <- index-address *s, i
-  *dest <- copy newc
+  *s <- put-index *s, i, newc
   i <- add i, 1
   s <- replace s, oldc, newc, i
 ]
@@ -551,8 +544,7 @@ def interpolate template:address:shared:array:character -> result:address:shared
       underscore?:boolean <- equal in, 95/_
       break-if underscore?
       # result[result-idx] = template[i]
-      out:address:character <- index-address *result, result-idx
-      *out <- copy in
+      *result <- put-index *result, result-idx, in
       i <- add i, 1
       result-idx <- add result-idx, 1
       loop
@@ -565,8 +557,7 @@ def interpolate template:address:shared:array:character -> result:address:shared
       break-if arg-done?
       # result[result-idx] = a[j]
       in:character <- index *a, j
-      out:address:character <- index-address *result, result-idx
-      *out <- copy in
+      *result <- put-index *result, result-idx, in
       j <- add j, 1
       result-idx <- add result-idx, 1
       loop
@@ -583,8 +574,7 @@ def interpolate template:address:shared:array:character -> result:address:shared
     break-if tem-done?
     # result[result-idx] = template[i]
     in:character <- index *template, i
-    out:address:character <- index-address *result, result-idx:number
-    *out <- copy in
+    *result <- put-index *result, result-idx, in
     i <- add i, 1
     result-idx <- add result-idx, 1
     loop
@@ -732,8 +722,7 @@ def trim s:address:shared:array:character -> result:address:shared:array:charact
     break-if done?
     # result[j] = s[i]
     src:character <- index *s, i
-    dest:address:character <- index-address *result, j
-    *dest <- copy src
+    *result <- put-index *result, j, src
     i <- add i, 1
     j <- add j, 1
     loop
@@ -1131,8 +1120,8 @@ def split s:address:shared:array:character, delim:character -> result:address:sh
     break-if done?
     end:number <- find-next s, delim, start
     # copy start..end into result[curr-result]
-    dest:address:address:shared:array:character <- index-address *result, curr-result
-    *dest <- copy-range s, start, end
+    dest:address:shared:array:character <- copy-range s, start, end
+    *result <- put-index *result, curr-result, dest
     # slide over to next slice
     start <- add end, 1
     curr-result <- add curr-result, 1
@@ -1272,8 +1261,7 @@ def copy-range buf:address:shared:array:character, start:number, end:number -> r
     done?:boolean <- greater-or-equal src-idx, end
     break-if done?
     src:character <- index *buf, src-idx
-    dest:address:character <- index-address *result, dest-idx
-    *dest <- copy src
+    *result <- put-index *result, dest-idx, src
     src-idx <- add src-idx, 1
     dest-idx <- add dest-idx, 1
     loop
diff --git a/072channel.mu b/072channel.mu
index 81bc1479..0847f2ce 100644
--- a/072channel.mu
+++ b/072channel.mu
@@ -71,8 +71,7 @@ def write out:address:shared:sink:_elem, val:_elem -> out:address:shared:sink:_e
   # store val
   circular-buffer:address:shared:array:_elem <- get *chan, data:offset
   free:number <- get *chan, first-free:offset
-  dest:address:_elem <- index-address *circular-buffer, free
-  *dest <- copy val
+  *circular-buffer <- put-index *circular-buffer, free, val
   # mark its slot as filled
   # todo: clear the slot itself
   free <- add free, 1
diff --git a/073array.mu b/073array.mu
index fcd1fcb7..7fa580c5 100644
--- a/073array.mu
+++ b/073array.mu
@@ -31,8 +31,7 @@ def new-array -> result:address:shared:array:character [
     break-if done?
     curr-value:character, exists?:boolean <- next-ingredient
     assert exists?, [error in rewinding ingredients to new-array]
-    tmp:address:character <- index-address *result, i
-    *tmp <- copy curr-value
+    *result <- put-index *result, i, curr-value
     i <- add i, 1
     loop
   }
diff --git a/079table.mu b/079table.mu
index 2ef03fa6..9040f6ce 100644
--- a/079table.mu
+++ b/079table.mu
@@ -53,11 +53,12 @@ def put table:address:shared:table:_key:_value, key:_key, value:_value -> table:
   _, hash <- divide-with-remainder hash, capacity
   hash <- abs hash  # in case hash overflows into a negative integer
   table-data:address:shared:array:table_row:_key:_value <- get *table, data:offset
-  x:address:table_row:_key:_value <- index-address *table-data, hash
-  occupied?:boolean <- get *x, occupied?:offset
+  x:table_row:_key:_value <- index *table-data, hash
+  occupied?:boolean <- get x, occupied?:offset
   not-occupied?:boolean <- not occupied?:boolean
   assert not-occupied?, [can't handle collisions yet]
-  *x <- merge 1/true, key, value
+  new-row:table_row:_key:_value <- merge 1/true, key, value
+  *table-data <- put-index *table-data, hash, new-row
 ]
 
 def abs n:number -> result:number [
diff --git a/081print.mu b/081print.mu
index bfa8ac93..21b0cfe4 100644
--- a/081print.mu
+++ b/081print.mu
@@ -37,8 +37,8 @@ def clear-screen screen:address:shared:screen -> screen:address:shared:screen [
     {
       done?:boolean <- greater-or-equal i, max
       break-if done?
-      curr:address:screen-cell <- index-address *buf, i
-      *curr <- merge 0/empty, 7/white
+      curr:screen-cell <- merge 0/empty, 7/white
+      *buf <- put-index *buf, i, curr
       i <- add i, 1
       loop
     }
@@ -149,13 +149,13 @@ def print screen:address:shared:screen, c:character -> screen:address:shared:scr
         column <- subtract column, 1
         *screen <- put *screen, cursor-column:offset, column
         index <- subtract index, 1
-        cursor:address:screen-cell <- index-address *buf, index
-        *cursor <- merge 32/space, 7/white
+        cursor:screen-cell <- merge 32/space, 7/white
+        *buf <- put-index *buf, index, cursor
       }
       return
     }
-    cursor:address:screen-cell <- index-address *buf, index
-    *cursor <- merge c, color
+    cursor:screen-cell <- merge c, color
+    *buf <- put-index *buf, index, cursor
     # increment column unless it's already all the way to the right
     {
       right:number <- subtract width, 1
diff --git a/build_and_test_until b/build_and_test_until
index 96eb9e43..fc0d7689 100755
--- a/build_and_test_until
+++ b/build_and_test_until
@@ -17,7 +17,7 @@ then
   # All sorts of strange bugs ensue.
   sleep 1
   set -v  # Darwin's clang and valgrind is shit.
-  CFLAGS=${CFLAGS:-"-g -O3"} make test
+  CFLAGS=${CFLAGS:-"-g -O3"} make #test
 else
   set -v
   CXX=${CXX:-clang++} CFLAGS=${CFLAGS:-"-O3 -fsanitize=undefined -Wno-tautological-constant-out-of-range-compare"} make ${2:-valgrind}
diff --git a/chessboard.mu b/chessboard.mu
index fe709f40..91e2e3fd 100644
--- a/chessboard.mu
+++ b/chessboard.mu
@@ -116,8 +116,8 @@ def new-board initial-position:address:shared:array:character -> board:address:s
   {
     done?:boolean <- equal col, 8
     break-if done?
-    file:address:address:shared:array:character <- index-address *board, col
-    *file <- new-file initial-position, col
+    file:address:shared:array:character <- new-file initial-position, col
+    *board <- put-index *board, col, file
     col <- add col, 1
     loop
   }
@@ -132,8 +132,8 @@ def new-file position:address:shared:array:character, index:number -> result:add
   {
     done?:boolean <- equal row, 8
     break-if done?
-    dest:address:character <- index-address *result, row
-    *dest <- index *position, index
+    square:character <- index *position, index
+    *result <- put-index *result, row, square
     row <- add row, 1
     index <- add index, 1
     loop
@@ -531,12 +531,11 @@ def make-move board:address:shared:array:address:shared:array:character, m:addre
   from-rank:number <- get *m, from-rank:offset
   to-file:number <- get *m, to-file:offset
   to-rank:number <- get *m, to-rank:offset
-  f:address:shared:array:character <- index *board, from-file
-  src:address:character/square <- index-address *f, from-rank
-  f <- index *board, to-file
-  dest:address:character/square <- index-address *f, to-rank
-  *dest <- copy *src
-  *src <- copy 32/space
+  from-f:address:shared:array:character <- index *board, from-file
+  to-f:address:shared:array:character <- index *board, to-file
+  src:character/square <- index *from-f, from-rank
+  *to-f <- put-index *to-f, to-rank, src
+  *from-f <- put-index *from-f, from-rank, 32/space
 ]
 
 scenario making-a-move [