about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-10-05 21:09:42 -0700
committerKartik Agaram <vc@akkartik.com>2020-10-05 21:09:42 -0700
commit21387ef514e1fa91f8f10f0a5089cc4bc66f3c18 (patch)
tree1882fc5775fa4aed339f3550e75f8f1d997d0f02
parent6833b4542c3c9880eb3698ce58428ba992fd6062 (diff)
downloadmu-21387ef514e1fa91f8f10f0a5089cc4bc66f3c18.tar.gz
6963 - tile: more idiomatic conventional repl
-rw-r--r--305keyboard.subx2
-rw-r--r--400.mu2
-rw-r--r--apps/tile/main.mu72
3 files changed, 37 insertions, 39 deletions
diff --git a/305keyboard.subx b/305keyboard.subx
index 01dc9783..079814fa 100644
--- a/305keyboard.subx
+++ b/305keyboard.subx
@@ -155,7 +155,7 @@ $read-key-from-real-keyboard:end:
     c3/return
 
 # use this in type mode
-read-line-from-real-keyboard:  # in: (addr stream byte)
+read-line-from-real-keyboard:  # out: (addr stream byte)
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
diff --git a/400.mu b/400.mu
index 9f407565..93e6f03a 100644
--- a/400.mu
+++ b/400.mu
@@ -168,7 +168,7 @@ sig show-cursor-on-real-screen
 sig enable-keyboard-immediate-mode
 sig enable-keyboard-type-mode
 sig read-key-from-real-keyboard -> result/eax: grapheme
-sig read-line-from-real-keyboard in: (addr stream byte)
+sig read-line-from-real-keyboard out: (addr stream byte)
 sig open filename: (addr array byte), write?: boolean, out: (addr handle buffered-file)
 sig populate-buffered-file-containing contents: (addr array byte), out: (addr handle buffered-file)
 sig new-buffered-file out: (addr handle buffered-file)
diff --git a/apps/tile/main.mu b/apps/tile/main.mu
index ad692f63..c4a5f6c0 100644
--- a/apps/tile/main.mu
+++ b/apps/tile/main.mu
@@ -63,46 +63,44 @@ fn interactive {
 }
 
 fn repl {
-  enable-keyboard-immediate-mode
-  var env-storage: environment
-  var env/esi: (addr environment) <- address env-storage
-  initialize-environment env
-  var stack-storage: value-stack
-  var stack/edi: (addr value-stack) <- address stack-storage
-  initialize-value-stack stack, 0x10
-  print-string-to-real-screen "> "
-  $repl:loop: {
-    var key/eax: grapheme <- read-key-from-real-keyboard
-    print-grapheme-to-real-screen key
-    compare key, 4  # ctrl-d
-    break-if-=
-    compare key, 0xa  # newline
+  {
+    # prompt
+    var line-storage: (stream byte 0x100)
+    var line/ecx: (addr stream byte) <- address line-storage
+    print-string-to-real-screen "> "
+    # read
+    clear-stream line
+    read-line-from-real-keyboard line
+    var done?/eax: boolean <- stream-empty? line
+    compare done?, 0  # false
+    break-if-!=
+    # parse
+    var env-storage: environment
+    var env/esi: (addr environment) <- address env-storage
+    initialize-environment env
     {
+      var done?/eax: boolean <- stream-empty? line
+      compare done?, 0  # false
       break-if-!=
-      evaluate-environment env, stack
-      var empty?/eax: boolean <- value-stack-empty? stack
-      {
-        compare empty?, 0  # false
-        break-if-!=
-        var result/eax: int <- pop-int-from-value-stack stack
-        print-int32-decimal-to-real-screen result
-        print-string-to-real-screen "\n"
-      }
-      # clear line
-      var program-ah/eax: (addr handle program) <- get env, program
-      var program/eax: (addr program) <- lookup *program-ah
-      var sandbox-ah/eax: (addr handle sandbox) <- get program, sandboxes
-      var _sandbox/eax: (addr sandbox) <- lookup *sandbox-ah
-      var sandbox/esi: (addr sandbox) <- copy _sandbox
-      var line-ah/eax: (addr handle line) <- get sandbox, data
-      var line/eax: (addr line) <- lookup *line-ah
-      var cursor-word-ah/esi: (addr handle word) <- get sandbox, cursor-word
-      initialize-line line, cursor-word-ah
-      print-string-to-real-screen "> "
-      loop $repl:loop
+      var g/eax: grapheme <- read-grapheme line
+      process env, g
+      loop
     }
-    process env, key
+    # eval
+    var stack-storage: value-stack
+    var stack/edi: (addr value-stack) <- address stack-storage
+    initialize-value-stack stack, 0x10
+    evaluate-environment env, stack
+    # print
+    var empty?/eax: boolean <- value-stack-empty? stack
+    {
+      compare empty?, 0  # false
+      break-if-!=
+      var result/eax: int <- pop-int-from-value-stack stack
+      print-int32-decimal-to-real-screen result
+      print-string-to-real-screen "\n"
+    }
+    #
     loop
   }
-  enable-keyboard-type-mode
 }