about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-09-12 10:00:43 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-09-12 10:00:43 -0700
commit59e47aca14ce352a1814953df4be220406c94747 (patch)
tree6d9aab829a480d5a0babe4d969c6e63dde6db3c9
parentf8b9e5c0dccd1563764426878ba0f2f982c3f310 (diff)
downloadmu-59e47aca14ce352a1814953df4be220406c94747.tar.gz
3341
Process type abbreviations in function headers.

Still a couple of places where doing this causes strange errors. We'll
track those down next.
-rw-r--r--018type_abbreviations.cc1
-rw-r--r--053recipe_header.cc22
-rw-r--r--061text.mu26
-rw-r--r--064list.mu4
-rw-r--r--066stream.mu2
-rw-r--r--081print.mu2
-rw-r--r--088file.mu8
-rw-r--r--090scenario_filesystem_test.mu2
-rw-r--r--edit/001-editor.mu6
-rw-r--r--edit/002-typing.mu2
-rw-r--r--edit/004-programming-environment.mu4
-rw-r--r--edit/005-sandbox.mu6
-rw-r--r--sandbox/001-editor.mu4
-rw-r--r--sandbox/002-typing.mu2
-rw-r--r--sandbox/005-sandbox.mu2
15 files changed, 58 insertions, 35 deletions
diff --git a/018type_abbreviations.cc b/018type_abbreviations.cc
index beb7bdab..03afe351 100644
--- a/018type_abbreviations.cc
+++ b/018type_abbreviations.cc
@@ -178,6 +178,7 @@ void expand_type_abbreviations(const recipe_ordinal r) {
       trace(9992, "transform") << "product type after expanding abbreviations: " << names_to_string(inst.products.at(i).type) << end();
     }
   }
+  // End Expand Type Abbreviations(caller)
 }
 
 void expand_type_abbreviations(type_tree* type) {
diff --git a/053recipe_header.cc b/053recipe_header.cc
index d385d41c..0bbba110 100644
--- a/053recipe_header.cc
+++ b/053recipe_header.cc
@@ -142,6 +142,28 @@ if (result.has_header) {
   trace(9999, "parse") << "recipe " << result.name << " has a header" << end();
 }
 
+//: Support type abbreviations in headers.
+
+:(scenario type_abbreviations_in_recipe_headers)
+type string = address:array:character
+def main [
+  local-scope
+  a:string <- foo
+  1:character/raw <- index *a, 0
+]
+def foo -> a:string [
+  local-scope
+  load-ingredients
+  a <- new [abc]
+]
++mem: storing 97 in location 1
+
+:(before "End Expand Type Abbreviations(caller)")
+for (long int i = 0; i < SIZE(caller.ingredients); ++i)
+  expand_type_abbreviations(caller.ingredients.at(i).type);
+for (long int i = 0; i < SIZE(caller.products); ++i)
+  expand_type_abbreviations(caller.products.at(i).type);
+
 //: Rewrite 'load-ingredients' to instructions to create all reagents in the header.
 
 :(before "End Rewrite Instruction(curr, recipe result)")
diff --git a/061text.mu b/061text.mu
index 47c2cdc3..2fa60f1c 100644
--- a/061text.mu
+++ b/061text.mu
@@ -16,7 +16,7 @@ def array-to-text-line x:address:array:_elem -> y:address:array:character [
   y <- to-text *x
 ]
 
-def equal a:address:array:character, b:address:array:character -> result:boolean [
+def equal a:text, b:text -> result:boolean [
   local-scope
   load-ingredients
   a-len:number <- length *a
@@ -167,7 +167,7 @@ def buffer-full? in:address:buffer -> result:boolean [
 def append buf:address:buffer, x:_elem -> buf:address:buffer [
   local-scope
   load-ingredients
-  text:address:array:character <- to-text x
+  text:text <- to-text x
   len:number <- length *text
   i:number <- copy 0
   {
@@ -277,7 +277,7 @@ scenario buffer-append-handles-backspace [
   ]
 ]
 
-def buffer-to-array in:address:buffer -> result:address:array:character [
+def buffer-to-array in:address:buffer -> result:text [
   local-scope
   load-ingredients
   {
@@ -300,7 +300,7 @@ def buffer-to-array in:address:buffer -> result:address:array:character [
   }
 ]
 
-def append a:address:array:character, b:address:array:character -> result:address:array:character [
+def append a:text, b:text -> result:text [
   local-scope
   load-ingredients
   # handle null addresses
@@ -391,7 +391,7 @@ scenario replace-character-in-text [
   ]
 ]
 
-def replace s:address:array:character, oldc:character, newc:character, from:number/optional -> s:address:array:character [
+def replace s:text, oldc:character, newc:character, from:number/optional -> s:text [
   local-scope
   load-ingredients
   len:number <- length *s
@@ -452,7 +452,7 @@ scenario replace-all-characters [
 ]
 
 # replace underscores in first with remaining args
-def interpolate template:address:array:character -> result:address:array:character [
+def interpolate template:text -> result:text [
   local-scope
   load-ingredients  # consume just the template
   # compute result-len, space to allocate for result
@@ -626,7 +626,7 @@ def space? c:character -> result:boolean [
   result <- equal c, 12288/ideographic-space
 ]
 
-def trim s:address:array:character -> result:address:array:character [
+def trim s:text -> result:text [
   local-scope
   load-ingredients
   len:number <- length *s
@@ -736,7 +736,7 @@ scenario trim-newline-tab [
   ]
 ]
 
-def find-next text:address:array:character, pattern:character, idx:number -> next-index:number [
+def find-next text:text, pattern:character, idx:number -> next-index:number [
   local-scope
   load-ingredients
   len:number <- length *text
@@ -842,7 +842,7 @@ scenario text-find-next-second [
 
 # search for a pattern of multiple characters
 # fairly dumb algorithm
-def find-next text:address:array:character, pattern:address:array:character, idx:number -> next-index:number [
+def find-next text:text, pattern:text, idx:number -> next-index:number [
   local-scope
   load-ingredients
   first:character <- index *pattern, 0
@@ -923,7 +923,7 @@ scenario find-next-suffix-match-2 [
 ]
 
 # checks if pattern matches at index 'idx'
-def match-at text:address:array:character, pattern:address:array:character, idx:number -> result:boolean [
+def match-at text:text, pattern:text, idx:number -> result:boolean [
   local-scope
   load-ingredients
   pattern-len:number <- length *pattern
@@ -1060,7 +1060,7 @@ scenario match-at-inside-bounds-2 [
   ]
 ]
 
-def split s:address:array:character, delim:character -> result:address:array:address:array:character [
+def split s:text, delim:character -> result:address:array:text [
   local-scope
   load-ingredients
   # empty text? return empty array
@@ -1192,7 +1192,7 @@ scenario text-split-empty-piece [
   ]
 ]
 
-def split-first text:address:array:character, delim:character -> x:address:array:character, y:address:array:character [
+def split-first text:text, delim:character -> x:text, y:text [
   local-scope
   load-ingredients
   # empty text? return empty texts
@@ -1224,7 +1224,7 @@ scenario text-split-first [
   ]
 ]
 
-def copy-range buf:address:array:character, start:number, end:number -> result:address:array:character [
+def copy-range buf:text, start:number, end:number -> result:text [
   local-scope
   load-ingredients
   # if end is out of bounds, trim it
diff --git a/064list.mu b/064list.mu
index dd9a7f73..408bd0e3 100644
--- a/064list.mu
+++ b/064list.mu
@@ -258,7 +258,7 @@ scenario removing-from-singleton-list [
   ]
 ]
 
-def to-text in:address:list:_elem -> result:address:array:character [
+def to-text in:address:list:_elem -> result:text [
   local-scope
   load-ingredients
   buf:address:buffer <- new-buffer 80
@@ -267,7 +267,7 @@ def to-text in:address:list:_elem -> result:address:array:character [
 ]
 
 # variant of 'to-text' which stops printing after a few elements (and so is robust to cycles)
-def to-text-line in:address:list:_elem -> result:address:array:character [
+def to-text-line in:address:list:_elem -> result:text [
   local-scope
   load-ingredients
   buf:address:buffer <- new-buffer 80
diff --git a/066stream.mu b/066stream.mu
index bf0d1845..d3a16b0c 100644
--- a/066stream.mu
+++ b/066stream.mu
@@ -52,7 +52,7 @@ def peek in:address:stream:_elem -> result:_elem, empty?:boolean [
   result <- index *s, idx
 ]
 
-def read-line in:address:stream:character -> result:address:array:character, in:address:stream:character [
+def read-line in:address:stream:character -> result:text, in:address:stream:character [
   local-scope
   load-ingredients
   idx:number <- get *in, index:offset
diff --git a/081print.mu b/081print.mu
index 59ce9ed6..c9937387 100644
--- a/081print.mu
+++ b/081print.mu
@@ -643,7 +643,7 @@ def show-screen screen:address:screen -> screen:address:screen [
   show-display
 ]
 
-def print screen:address:screen, s:address:array:character -> screen:address:screen [
+def print screen:address:screen, s:text -> screen:address:screen [
   local-scope
   load-ingredients
   color:number, color-found?:boolean <- next-ingredient
diff --git a/088file.mu b/088file.mu
index 1d616cf3..2b8e02aa 100644
--- a/088file.mu
+++ b/088file.mu
@@ -10,7 +10,7 @@ container file-mapping [
   contents:text
 ]
 
-def start-reading fs:address:filesystem, filename:address:array:character -> contents:address:source:character [
+def start-reading fs:address:filesystem, filename:text -> contents:address:source:character [
   local-scope
   load-ingredients
   {
@@ -55,7 +55,7 @@ def transmit-from-file file:number, sink:address:sink:character -> sink:address:
   file <- $close-file file
 ]
 
-def transmit-from-text contents:address:array:character, sink:address:sink:character -> sink:address:sink:character [
+def transmit-from-text contents:text, sink:address:sink:character -> sink:address:sink:character [
   local-scope
   load-ingredients
   i:number <- copy 0
@@ -71,7 +71,7 @@ def transmit-from-text contents:address:array:character, sink:address:sink:chara
   sink <- close sink
 ]
 
-def start-writing fs:address:filesystem, filename:address:array:character -> sink:address:sink:character, routine-id:number [
+def start-writing fs:address:filesystem, filename:text -> sink:address:sink:character, routine-id:number [
   local-scope
   load-ingredients
   source:address:source:character, sink:address:sink:character <- new-channel 30
@@ -100,7 +100,7 @@ def transmit-to-file file:number, source:address:source:character -> source:addr
   file <- $close-file file
 ]
 
-def transmit-to-fake-file fs:address:filesystem, filename:address:array:character, source:address:source:character -> fs:address:filesystem, source:address:source:character [
+def transmit-to-fake-file fs:address:filesystem, filename:text, source:address:source:character -> fs:address:filesystem, source:address:source:character [
   local-scope
   load-ingredients
   # compute new file contents
diff --git a/090scenario_filesystem_test.mu b/090scenario_filesystem_test.mu
index 0eefadad..820c075e 100644
--- a/090scenario_filesystem_test.mu
+++ b/090scenario_filesystem_test.mu
@@ -79,7 +79,7 @@ scenario write-to-existing-file-preserves-other-files [
   ]
 ]
 
-def slurp fs:address:filesystem, filename:address:array:character -> contents:address:array:character [
+def slurp fs:address:filesystem, filename:text -> contents:text [
   local-scope
   load-ingredients
   source:address:source:character <- start-reading fs, filename
diff --git a/edit/001-editor.mu b/edit/001-editor.mu
index f59c43e1..83bd5edf 100644
--- a/edit/001-editor.mu
+++ b/edit/001-editor.mu
@@ -2,7 +2,7 @@
 
 # temporary main for this layer: just render the given text at the given
 # screen dimensions, then stop
-def! main text:address:array:character [
+def! main text:text [
   local-scope
   load-ingredients
   open-console
@@ -48,7 +48,7 @@ container editor-data [
 # creates a new editor widget and renders its initial appearance to screen
 #   top/left/right constrain the screen area available to the new editor
 #   right is exclusive
-def new-editor s:address:array:character, screen:address:screen, left:number, right:number -> result:address:editor-data, screen:address:screen [
+def new-editor s:text, screen:address:screen, left:number, right:number -> result:address:editor-data, screen:address:screen [
   local-scope
   load-ingredients
   # no clipping of bounds
@@ -71,7 +71,7 @@ def new-editor s:address:array:character, screen:address:screen, left:number, ri
   <editor-initialization>
 ]
 
-def insert-text editor:address:editor-data, text:address:array:character -> editor:address:editor-data [
+def insert-text editor:address:editor-data, text:text -> editor:address:editor-data [
   local-scope
   load-ingredients
   # early exit if text is empty
diff --git a/edit/002-typing.mu b/edit/002-typing.mu
index f30e50ec..d81cc991 100644
--- a/edit/002-typing.mu
+++ b/edit/002-typing.mu
@@ -2,7 +2,7 @@
 
 # temporary main: interactive editor
 # hit ctrl-c to exit
-def! main text:address:array:character [
+def! main text:text [
   local-scope
   load-ingredients
   open-console
diff --git a/edit/004-programming-environment.mu b/edit/004-programming-environment.mu
index 261be52b..4f4c6e61 100644
--- a/edit/004-programming-environment.mu
+++ b/edit/004-programming-environment.mu
@@ -21,7 +21,7 @@ container programming-environment-data [
   sandbox-in-focus?:boolean  # false => cursor in recipes; true => cursor in current-sandbox
 ]
 
-def new-programming-environment screen:address:screen, initial-recipe-contents:address:array:character, initial-sandbox-contents:address:array:character -> result:address:programming-environment-data, screen:address:screen [
+def new-programming-environment screen:address:screen, initial-recipe-contents:text, initial-sandbox-contents:text -> result:address:programming-environment-data, screen:address:screen [
   local-scope
   load-ingredients
   width:number <- screen-width screen
@@ -540,7 +540,7 @@ def update-cursor screen:address:screen, recipes:address:editor-data, current-sa
 ]
 
 # like 'render' for texts, but with colorization for comments like in the editor
-def render-code screen:address:screen, s:address:array:character, left:number, right:number, row:number -> row:number, screen:address:screen [
+def render-code screen:address:screen, s:text, left:number, right:number, row:number -> row:number, screen:address:screen [
   local-scope
   load-ingredients
   return-unless s
diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu
index 507a6f0f..668a39f5 100644
--- a/edit/005-sandbox.mu
+++ b/edit/005-sandbox.mu
@@ -207,7 +207,7 @@ def! update-sandbox sandbox:address:sandbox-data, env:address:programming-enviro
   *sandbox <- put *sandbox, screen:offset, fake-screen
 ]
 
-def update-status screen:address:screen, msg:address:array:character, color:number -> screen:address:screen [
+def update-status screen:address:screen, msg:text, color:number -> screen:address:screen [
   local-scope
   load-ingredients
   screen <- move-cursor screen, 0, 2
@@ -355,7 +355,7 @@ def sandbox-menu-columns left:number, right:number -> edit-button-left:number, e
 
 # print a text 's' to 'editor' in 'color' starting at 'row'
 # clear rest of last line, move cursor to next line
-def render-text screen:address:screen, s:address:array:character, left:number, right:number, color:number, row:number -> row:number, screen:address:screen [
+def render-text screen:address:screen, s:text, left:number, right:number, color:number, row:number -> row:number, screen:address:screen [
   local-scope
   load-ingredients
   return-unless s
@@ -601,7 +601,7 @@ scenario run-instruction-manages-screen-per-sandbox [
   ]
 ]
 
-def editor-contents editor:address:editor-data -> result:address:array:character [
+def editor-contents editor:address:editor-data -> result:text [
   local-scope
   load-ingredients
   buf:address:buffer <- new-buffer 80
diff --git a/sandbox/001-editor.mu b/sandbox/001-editor.mu
index f59c43e1..afa7d953 100644
--- a/sandbox/001-editor.mu
+++ b/sandbox/001-editor.mu
@@ -2,7 +2,7 @@
 
 # temporary main for this layer: just render the given text at the given
 # screen dimensions, then stop
-def! main text:address:array:character [
+def! main text:text [
   local-scope
   load-ingredients
   open-console
@@ -71,7 +71,7 @@ def new-editor s:address:array:character, screen:address:screen, left:number, ri
   <editor-initialization>
 ]
 
-def insert-text editor:address:editor-data, text:address:array:character -> editor:address:editor-data [
+def insert-text editor:address:editor-data, text:text -> editor:address:editor-data [
   local-scope
   load-ingredients
   # early exit if text is empty
diff --git a/sandbox/002-typing.mu b/sandbox/002-typing.mu
index b8ca7462..a30b81ae 100644
--- a/sandbox/002-typing.mu
+++ b/sandbox/002-typing.mu
@@ -2,7 +2,7 @@
 
 # temporary main: interactive editor
 # hit ctrl-c to exit
-def! main text:address:array:character [
+def! main text:text [
   local-scope
   load-ingredients
   open-console
diff --git a/sandbox/005-sandbox.mu b/sandbox/005-sandbox.mu
index df6d9817..90fa9bca 100644
--- a/sandbox/005-sandbox.mu
+++ b/sandbox/005-sandbox.mu
@@ -585,7 +585,7 @@ scenario run-instruction-manages-screen-per-sandbox [
   ]
 ]
 
-def editor-contents editor:address:editor-data -> result:address:array:character [
+def editor-contents editor:address:editor-data -> result:text [
   local-scope
   load-ingredients
   buf:address:buffer <- new-buffer 80