about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-06-22 23:11:55 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-06-22 23:11:55 -0700
commit10e9a9a8d42373b4c1e7db6bc69e2500f756cb18 (patch)
tree7050d07a9d8576bc0345e15e043f2d4174f7d881
parent156b74c7594a472e042db4cecf983df63d8aa3bb (diff)
downloadmu-10e9a9a8d42373b4c1e7db6bc69e2500f756cb18.tar.gz
2 failing tests remaining
We just need to support unary operators.
-rw-r--r--shell/infix.mu46
1 files changed, 44 insertions, 2 deletions
diff --git a/shell/infix.mu b/shell/infix.mu
index e8396bcc..a59cd3e8 100644
--- a/shell/infix.mu
+++ b/shell/infix.mu
@@ -184,10 +184,22 @@ fn transform-infix-2 _x-ah: (addr handle cell), trace: (addr trace), at-head-of-
 #?   draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "x", 1/fg 0/bg
 #?   dump-cell-from-cursor-over-full-screen left-ah, 2/fg 0/bg
   transform-infix-2 left-ah, trace, 1/at-head-of-list
-  var right-ah/ecx: (addr handle cell) <- get x, right
+  var right-ah/edx: (addr handle cell) <- get x, right
 #?   draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "y", 1/fg 0/bg
 #?   dump-cell-from-cursor-over-full-screen right-ah, 3/fg 0/bg
-  transform-infix-2 right-ah, trace, 0/not-at-head-of-list
+  var right-at-head-of-list?/eax: boolean <- copy at-head-of-list?
+  {
+    compare right-at-head-of-list?, 0/false
+    break-if-=
+    # if left is a quote or unquote, cdr is still head of list
+    {
+      var left-is-quote-or-unquote?/eax: boolean <- quote-or-unquote? left-ah
+      compare left-is-quote-or-unquote?, 0/false
+    }
+    break-if-!=
+    right-at-head-of-list? <- copy 0/false
+  }
+  transform-infix-2 right-ah, trace, right-at-head-of-list?
 #?   draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "z", 1/fg 0/bg
   trace-higher trace
     # trace "=> " x-ah {{{
@@ -462,6 +474,36 @@ fn operator-grapheme? g: grapheme -> _/eax: boolean {
   return 0/false
 }
 
+fn quote-or-unquote? _x-ah: (addr handle cell) -> _/eax: boolean {
+  var x-ah/eax: (addr handle cell) <- copy _x-ah
+  var x/eax: (addr cell) <- lookup *x-ah
+  {
+    var quote?/eax: boolean <- symbol-equal? x, "'"
+    compare quote?, 0/false
+    break-if-=
+    return 1/true
+  }
+  {
+    var backquote?/eax: boolean <- symbol-equal? x, "`"
+    compare backquote?, 0/false
+    break-if-=
+    return 1/true
+  }
+  {
+    var unquote?/eax: boolean <- symbol-equal? x, ","
+    compare unquote?, 0/false
+    break-if-=
+    return 1/true
+  }
+  {
+    var unquote-splice?/eax: boolean <- symbol-equal? x, ",@"
+    compare unquote-splice?, 0/false
+    break-if-=
+    return 1/true
+  }
+  return 0/false
+}
+
 # helpers for tests
 
 fn check-infix actual: (addr array byte), expected: (addr array byte), message: (addr array byte) {