about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-09-12 00:47:44 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-09-12 00:47:44 -0700
commite2b367dc2548ab80fc3e0949ee4f327c1c447758 (patch)
treee5562a63b46356cd1757a2ac24ebe0e07fce597c
parentea19d0dc2c11f48ca384fb087b4e44ef400bfaa2 (diff)
downloadmu-e2b367dc2548ab80fc3e0949ee4f327c1c447758.tar.gz
3338
Process type abbreviations in container definitions.
-rw-r--r--030container.cc25
-rw-r--r--061text.mu2
-rw-r--r--088file.mu4
-rw-r--r--edit/005-sandbox.mu4
-rw-r--r--edit/009-sandbox-test.mu2
-rw-r--r--edit/010-sandbox-trace.mu2
-rw-r--r--edit/011-errors.mu4
-rw-r--r--lambda-to-mu.mu2
-rw-r--r--sandbox/005-sandbox.mu4
-rw-r--r--sandbox/009-sandbox-test.mu2
-rw-r--r--sandbox/010-sandbox-trace.mu2
-rw-r--r--sandbox/011-errors.mu4
12 files changed, 41 insertions, 16 deletions
diff --git a/030container.cc b/030container.cc
index 986e9581..4ef56d74 100644
--- a/030container.cc
+++ b/030container.cc
@@ -781,6 +781,31 @@ container foo [
 ]
 +error: container 'foo' contains multiple elements on a single line. Containers and exclusive containers must only contain elements, one to a line, no code.
 
+//: support type abbreviations in container definitions
+
+:(scenario type_abbreviations_in_containers)
+type foo = number
+container bar [
+  x:foo
+]
+def main [
+  1:number <- copy 34
+  2:foo <- get 1:bar/unsafe, 0:offset
+]
++mem: storing 34 in location 2
+
+:(after "Transform.push_back(expand_type_abbreviations)")
+Transform.push_back(expand_type_abbreviations_in_containers);
+:(code)
+// extremely inefficient; we process all types over and over again, once for every single recipe
+// but it doesn't seem to cause any noticeable slowdown
+void expand_type_abbreviations_in_containers(unused const recipe_ordinal r) {
+  for (map<type_ordinal, type_info>::iterator p = Type.begin(); p != Type.end(); ++p) {
+    for (int i = 0; i < SIZE(p->second.elements); ++i)
+      expand_type_abbreviations(p->second.elements.at(i).type);
+  }
+}
+
 //: ensure scenarios are consistent by always starting new container
 //: declarations at the same type number
 :(before "End Setup")  //: for tests
diff --git a/061text.mu b/061text.mu
index 40041b3b..47c2cdc3 100644
--- a/061text.mu
+++ b/061text.mu
@@ -115,7 +115,7 @@ scenario text-equal-common-lengths-but-distinct [
 # A new type to help incrementally construct texts.
 container buffer [
   length:number
-  data:address:array:character
+  data:text
 ]
 
 def new-buffer capacity:number -> result:address:buffer [
diff --git a/088file.mu b/088file.mu
index 8a34b375..1d616cf3 100644
--- a/088file.mu
+++ b/088file.mu
@@ -6,8 +6,8 @@ container filesystem [
 ]
 
 container file-mapping [
-  name:address:array:character
-  contents:address:array:character
+  name:text
+  contents:text
 ]
 
 def start-reading fs:address:filesystem, filename:address:array:character -> contents:address:source:character [
diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu
index b49e342e..507a6f0f 100644
--- a/edit/005-sandbox.mu
+++ b/edit/005-sandbox.mu
@@ -31,8 +31,8 @@ after <programming-environment-initialization> [
 ]
 
 container sandbox-data [
-  data:address:array:character
-  response:address:array:character
+  data:text
+  response:text
   # coordinates to track clicks
   # constraint: will be 0 for sandboxes at positions before env.render-from
   starting-row-on-screen:number
diff --git a/edit/009-sandbox-test.mu b/edit/009-sandbox-test.mu
index b02461a1..7ff9125d 100644
--- a/edit/009-sandbox-test.mu
+++ b/edit/009-sandbox-test.mu
@@ -87,7 +87,7 @@ recipe foo [
 # this requires tracking a couple more things
 container sandbox-data [
   response-starting-row-on-screen:number
-  expected-response:address:array:character
+  expected-response:text
 ]
 
 # include expected response when saving or restoring a sandbox
diff --git a/edit/010-sandbox-trace.mu b/edit/010-sandbox-trace.mu
index 8a860d31..ae054cd4 100644
--- a/edit/010-sandbox-trace.mu
+++ b/edit/010-sandbox-trace.mu
@@ -169,7 +169,7 @@ scenario clicking-on-app-trace-does-nothing [
 ]
 
 container sandbox-data [
-  trace:address:array:character
+  trace:text
   display-trace?:boolean
 ]
 
diff --git a/edit/011-errors.mu b/edit/011-errors.mu
index 6498d9a5..31ad561d 100644
--- a/edit/011-errors.mu
+++ b/edit/011-errors.mu
@@ -1,7 +1,7 @@
 ## handling malformed programs
 
 container programming-environment-data [
-  recipe-errors:address:array:character
+  recipe-errors:text
 ]
 
 # copy code from recipe editor, persist, load into mu, save any errors
@@ -74,7 +74,7 @@ before <render-components-end> [
 ]
 
 container sandbox-data [
-  errors:address:array:character
+  errors:text
 ]
 
 def! update-sandbox sandbox:address:sandbox-data, env:address:programming-environment-data, idx:number -> sandbox:address:sandbox-data, env:address:programming-environment-data [
diff --git a/lambda-to-mu.mu b/lambda-to-mu.mu
index 32727916..ed3cd72c 100644
--- a/lambda-to-mu.mu
+++ b/lambda-to-mu.mu
@@ -23,7 +23,7 @@ def lambda-to-mu in:address:array:character -> out:address:array:character [
 
 # 'parse' will turn lambda expressions into trees made of cells
 exclusive-container cell [
-  atom:address:array:character
+  atom:text
   pair:pair
 ]
 
diff --git a/sandbox/005-sandbox.mu b/sandbox/005-sandbox.mu
index 810aab5f..df6d9817 100644
--- a/sandbox/005-sandbox.mu
+++ b/sandbox/005-sandbox.mu
@@ -18,8 +18,8 @@ after <programming-environment-initialization> [
 ]
 
 container sandbox-data [
-  data:address:array:character
-  response:address:array:character
+  data:text
+  response:text
   # coordinates to track clicks
   # constraint: will be 0 for sandboxes at positions before env.render-from
   starting-row-on-screen:number
diff --git a/sandbox/009-sandbox-test.mu b/sandbox/009-sandbox-test.mu
index c89775a4..a0da09a8 100644
--- a/sandbox/009-sandbox-test.mu
+++ b/sandbox/009-sandbox-test.mu
@@ -84,7 +84,7 @@ def foo [
 # this requires tracking a couple more things
 container sandbox-data [
   response-starting-row-on-screen:number
-  expected-response:address:array:character
+  expected-response:text
 ]
 
 # include expected response when saving or restoring a sandbox
diff --git a/sandbox/010-sandbox-trace.mu b/sandbox/010-sandbox-trace.mu
index c42a9dfc..ea1d332f 100644
--- a/sandbox/010-sandbox-trace.mu
+++ b/sandbox/010-sandbox-trace.mu
@@ -159,7 +159,7 @@ scenario clicking-on-app-trace-does-nothing [
 ]
 
 container sandbox-data [
-  trace:address:array:character
+  trace:text
   display-trace?:boolean
 ]
 
diff --git a/sandbox/011-errors.mu b/sandbox/011-errors.mu
index 108ec0ab..17e7982f 100644
--- a/sandbox/011-errors.mu
+++ b/generated by cgit-pink 1.4.1-2-gfad0 (git 2.36.2.497.gbbea4dcf42) at 2024-11-22 19:12:32 +0000
 


'del'>-  recipe-errors:address:array:character
+  recipe-errors:text
 ]
 
 # copy code from recipe editor, persist, load into mu, save any errors
@@ -73,7 +73,7 @@ before <render-components-end> [
 ]
 
 container sandbox-data [
-  errors:address:array:character
+  errors:text
 ]
 
 def! update-sandbox sandbox:address:sandbox-data, env:address:programming-environment-data, idx:number -> sandbox:address:sandbox-data, env:address:programming-environment-data [