From 10e9a9a8d42373b4c1e7db6bc69e2500f756cb18 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 22 Jun 2021 23:11:55 -0700 Subject: 2 failing tests remaining We just need to support unary operators. --- shell/infix.mu | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'shell/infix.mu') 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) { -- cgit 1.4.1-2-gfad0