about summary refs log tree commit diff stats
path: root/074console.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-07-29 14:37:57 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-07-29 14:37:57 -0700
commit502d2ea540bbb66f2bb5e649c7c7743973859092 (patch)
tree583d581c6641da87378e8536ef3d87d6bbb3a6f7 /074console.mu
parent10ffce9815b0242259730629668215b01dccbda1 (diff)
downloadmu-502d2ea540bbb66f2bb5e649c7c7743973859092.tar.gz
1883 - type-deducing in more .mu files
Diffstat (limited to '074console.mu')
-rw-r--r--074console.mu75
1 files changed, 34 insertions, 41 deletions
diff --git a/074console.mu b/074console.mu
index 031f0781..b60e17cc 100644
--- a/074console.mu
+++ b/074console.mu
@@ -22,37 +22,35 @@ container console [
 recipe new-fake-console [
   local-scope
   result:address:console <- new console:type
-  buf:address:address:array:character <- get-address result:address:console/lookup, data:offset
-#?   $start-tracing #? 1
-  buf:address:address:array:character/lookup <- next-ingredient
-#?   $stop-tracing #? 1
-  idx:address:number <- get-address result:address:console/lookup, index:offset
-  idx:address:number/lookup <- copy 0
-  reply result:address:console
+  buf:address:address:array:character <- get-address *result, data:offset
+  *buf <- next-ingredient
+  idx:address:number <- get-address *result, index:offset
+  *idx <- copy 0
+  reply result
 ]
 
 recipe read-event [
   local-scope
   x:address:console <- next-ingredient
   {
-    break-unless x:address:console
-    idx:address:number <- get-address x:address:console/lookup, index:offset
-    buf:address:array:event <- get x:address:console/lookup, data:offset
+    break-unless x
+    idx:address:number <- get-address *x, index:offset
+    buf:address:array:event <- get *x, data:offset
     {
-      max:number <- length buf:address:array:event/lookup
-      done?:boolean <- greater-or-equal idx:address:number/lookup, max:number
-      break-unless done?:boolean
+      max:number <- length *buf
+      done?:boolean <- greater-or-equal *idx, max
+      break-unless done?
       dummy:address:event <- new event:type
-      reply dummy:address:event/lookup, x:address:console/same-as-ingredient:0, 1/found, 1/quit
+      reply *dummy, x/same-as-ingredient:0, 1/found, 1/quit
     }
-    result:event <- index buf:address:array:event/lookup, idx:address:number/lookup
-    idx:address:number/lookup <- add idx:address:number/lookup, 1
-    reply result:event, x:address:console/same-as-ingredient:0, 1/found, 0/quit
+    result:event <- index *buf, *idx
+    *idx <- add *idx, 1
+    reply result, x/same-as-ingredient:0, 1/found, 0/quit
   }
   # real event source is infrequent; avoid polling it too much
   switch
   result:event, found?:boolean <- check-for-interaction
-  reply result:event, x:address:console/same-as-ingredient:0, found?:boolean, 0/quit
+  reply result, x/same-as-ingredient:0, found?, 0/quit
 ]
 
 # variant of read-event for just keyboard events. Discards everything that
@@ -60,20 +58,13 @@ recipe read-event [
 # newlines, tabs, ctrl-d..
 recipe read-key [
   local-scope
-#?   $print default-space:address:array:location #? 1
-#?   $exit #? 1
-#?   $start-tracing #? 1
   console:address <- next-ingredient
-  x:event, console:address, found?:boolean, quit?:boolean <- read-event console:address
-#?   $print [aaa 1] #? 1
-  reply-if quit?:boolean, 0, console:address/same-as-ingredient:0, found?:boolean, quit?:boolean
-#?   $print [aaa 2] #? 1
-  reply-unless found?:boolean, 0, console:address/same-as-ingredient:0, found?:boolean, quit?:boolean
-#?   $print [aaa 3] #? 1
-  c:address:character <- maybe-convert x:event, text:variant
-  reply-unless c:address:character, 0, console:address/same-as-ingredient:0, 0/found, 0/quit
-#?   $print [aaa 4] #? 1
-  reply c:address:character/lookup, console:address/same-as-ingredient:0, 1/found, 0/quit
+  x:event, console, found?:boolean, quit?:boolean <- read-event console
+  reply-if quit?, 0, console/same-as-ingredient:0, found?, quit?
+  reply-unless found?, 0, console/same-as-ingredient:0, found?, quit?
+  c:address:character <- maybe-convert x, text:variant
+  reply-unless c, 0, console/same-as-ingredient:0, 0/found, 0/quit
+  reply *c, console/same-as-ingredient:0, 1/found, 0/quit
 ]
 
 recipe send-keys-to-channel [
@@ -82,23 +73,25 @@ recipe send-keys-to-channel [
   chan:address:channel <- next-ingredient
   screen:address <- next-ingredient
   {
-    c:character, console:address, found?:boolean, quit?:boolean <- read-key console:address
-    loop-unless found?:boolean
-    break-if quit?:boolean
-    assert c:character, [invalid event, expected text]
-    print-character screen:address, c:character
-    chan:address:channel <- write chan:address:channel, c:character
+    c:character, console, found?:boolean, quit?:boolean <- read-key console
+    loop-unless found?
+    break-if quit?
+    assert c, [invalid event, expected text]
+    screen <- print-character screen, c
+    chan <- write chan, c
     loop
   }
+  reply console/same-as-ingredient:0, chan/same-as-ingredient:1, screen/same-as-ingredient:2
 ]
 
 recipe wait-for-event [
   local-scope
   console:address <- next-ingredient
   {
-    _, console:address, found?:boolean <- read-event console:address
-    loop-unless found?:boolean
+    _, console, found?:boolean <- read-event console
+    loop-unless found?
   }
+  reply console/same-as-ingredient:0
 ]
 
 # use this helper to skip rendering if there's lots of other events queued up
@@ -106,10 +99,10 @@ recipe has-more-events? [
   local-scope
   console:address <- next-ingredient
   {
-    break-unless console:address
+    break-unless console
     # fake consoles should be plenty fast; never skip
     reply 0/false
   }
   result:boolean <- interactions-left?
-  reply result:boolean
+  reply result
 ]