about summary refs log tree commit diff stats
path: root/baremetal/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-02-20 22:37:44 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-02-20 22:37:44 -0800
commit684c09620304457825981eaaaf7af8af2dc64d15 (patch)
treea89c5527329184811b429313fd7641b2e1a9f8b9 /baremetal/shell
parentc7c8eb0cb46bf7ec7f825bfd040fc94e8ddd4e83 (diff)
downloadmu-684c09620304457825981eaaaf7af8af2dc64d15.tar.gz
7761 - baremetal/shell: read input from keyboard
Diffstat (limited to 'baremetal/shell')
-rw-r--r--baremetal/shell/gap-buffer.mu16
-rw-r--r--baremetal/shell/main.mu17
-rw-r--r--baremetal/shell/sandbox.mu47
3 files changed, 72 insertions, 8 deletions
diff --git a/baremetal/shell/gap-buffer.mu b/baremetal/shell/gap-buffer.mu
index 3f31e096..a6263b1c 100644
--- a/baremetal/shell/gap-buffer.mu
+++ b/baremetal/shell/gap-buffer.mu
@@ -6,17 +6,17 @@ type gap-buffer {
   right: grapheme-stack
 }
 
-fn initialize-gap-buffer _self: (addr gap-buffer) {
+fn initialize-gap-buffer _self: (addr gap-buffer), max-word-size: int {
   var self/esi: (addr gap-buffer) <- copy _self
   var left/eax: (addr grapheme-stack) <- get self, left
-  initialize-grapheme-stack left, 0x10/max-word-size
+  initialize-grapheme-stack left, max-word-size
   var right/eax: (addr grapheme-stack) <- get self, right
-  initialize-grapheme-stack right, 0x10/max-word-size
+  initialize-grapheme-stack right, max-word-size
 }
 
 # just for tests
 fn initialize-gap-buffer-with self: (addr gap-buffer), s: (addr array byte) {
-  initialize-gap-buffer self
+  initialize-gap-buffer self, 0x10/max-word-size
   var stream-storage: (stream byte 0x10/max-word-size)
   var stream/ecx: (addr stream byte) <- address stream-storage
   write stream, s
@@ -280,7 +280,7 @@ fn gap-buffer-equal? _self: (addr gap-buffer), s: (addr array byte) -> _/eax: bo
 fn test-gap-buffer-equal-from-end {
   var _g: gap-buffer
   var g/esi: (addr gap-buffer) <- address _g
-  initialize-gap-buffer g
+  initialize-gap-buffer g, 0x10
   #
   var c/eax: grapheme <- copy 0x61/a
   add-grapheme-at-gap g, c
@@ -294,7 +294,7 @@ fn test-gap-buffer-equal-from-end {
 fn test-gap-buffer-equal-from-middle {
   var _g: gap-buffer
   var g/esi: (addr gap-buffer) <- address _g
-  initialize-gap-buffer g
+  initialize-gap-buffer g, 0x10
   #
   var c/eax: grapheme <- copy 0x61/a
   add-grapheme-at-gap g, c
@@ -309,7 +309,7 @@ fn test-gap-buffer-equal-from-middle {
 fn test-gap-buffer-equal-from-start {
   var _g: gap-buffer
   var g/esi: (addr gap-buffer) <- address _g
-  initialize-gap-buffer g
+  initialize-gap-buffer g, 0x10
   #
   var c/eax: grapheme <- copy 0x61/a
   add-grapheme-at-gap g, c
@@ -327,7 +327,7 @@ fn test-gap-buffer-equal-fails {
   # g = "aaa"
   var _g: gap-buffer
   var g/esi: (addr gap-buffer) <- address _g
-  initialize-gap-buffer g
+  initialize-gap-buffer g, 0x10
   var c/eax: grapheme <- copy 0x61/a
   add-grapheme-at-gap g, c
   add-grapheme-at-gap g, c
diff --git a/baremetal/shell/main.mu b/baremetal/shell/main.mu
new file mode 100644
index 00000000..ee2dda60
--- /dev/null
+++ b/baremetal/shell/main.mu
@@ -0,0 +1,17 @@
+# Experimental Mu shell
+# A Lisp with indent-sensitivity and infix, no macros. Commas are ignored.
+
+fn main {
+  var sandbox-storage: sandbox
+  var sandbox/esi: (addr sandbox) <- address sandbox-storage
+  initialize-sandbox sandbox
+  {
+    render-sandbox 0/screen, sandbox, 2/x, 2/y
+    var key/eax: byte <- read-key 0/keyboard
+    compare key, 0
+    loop-if-=
+    # no way to quit right now; just reboot
+    edit-sandbox sandbox, key
+    loop
+  }
+}
diff --git a/baremetal/shell/sandbox.mu b/baremetal/shell/sandbox.mu
new file mode 100644
index 00000000..e360b9e6
--- /dev/null
+++ b/baremetal/shell/sandbox.mu
@@ -0,0 +1,47 @@
+type sandbox {
+  data: (handle gap-buffer)
+}
+
+fn initialize-sandbox _self: (addr sandbox) {
+  var self/esi: (addr sandbox) <- copy _self
+  var data-ah/eax: (addr handle gap-buffer) <- get self, data
+  allocate data-ah
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
+  initialize-gap-buffer data, 0x1000/4KB
+}
+
+## some helpers for tests
+
+fn initialize-sandbox-with _self: (addr sandbox), s: (addr array byte) {
+  var self/esi: (addr sandbox) <- copy _self
+  var data-ah/eax: (addr handle gap-buffer) <- get self, data
+  allocate data-ah
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
+  initialize-gap-buffer-with data, s
+}
+
+fn allocate-sandbox-with _out: (addr handle sandbox), s: (addr array byte) {
+  var out/eax: (addr handle sandbox) <- copy _out
+  allocate out
+  var out-addr/eax: (addr sandbox) <- lookup *out
+  initialize-sandbox-with out-addr, s
+}
+
+fn add-grapheme-to-sandbox _self: (addr sandbox), c: grapheme {
+  var self/esi: (addr sandbox) <- copy _self
+  var data-ah/eax: (addr handle gap-buffer) <- get self, data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
+  add-grapheme-at-gap data, c
+}
+
+fn render-sandbox screen: (addr screen), _self: (addr sandbox), x: int, y: int {
+  var self/esi: (addr sandbox) <- copy _self
+  var data-ah/eax: (addr handle gap-buffer) <- get self, data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
+  var dummy/eax: int <- render-gap-buffer screen, data, x, y, 1/true
+}
+
+fn edit-sandbox self: (addr sandbox), key: byte {
+  var g/edx: grapheme <- copy key
+  add-grapheme-to-sandbox self, g
+}