From d3a9db3aff54ea485f409eaaef3d8f56ad77f0dc Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 5 Oct 2020 11:00:05 -0700 Subject: 6958 --- html/apps/mulisp.mu.html | 128 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 html/apps/mulisp.mu.html (limited to 'html/apps/mulisp.mu.html') diff --git a/html/apps/mulisp.mu.html b/html/apps/mulisp.mu.html new file mode 100644 index 00000000..b24d4473 --- /dev/null +++ b/html/apps/mulisp.mu.html @@ -0,0 +1,128 @@ + + + + +Mu - apps/mulisp.mu + + + + + + + + + + +https://github.com/akkartik/mu/blob/master/apps/mulisp.mu +
+ 1 # To run unit tests:
+ 2 #   $ ./a.elf test
+ 3 fn main args-on-stack: (addr array addr array byte) -> exit-status/ebx: int {
+ 4   var args/eax: (addr array addr array byte) <- copy args-on-stack
+ 5   var tmp/ecx: int <- length args
+ 6   $main-body: {
+ 7     # if (len(args) > 1 && args[1] == "test") run-tests()
+ 8     compare tmp, 1
+ 9     {
+10       break-if-<=
+11       # if (args[1] == "test") run-tests()
+12       var tmp2/ecx: (addr addr array byte) <- index args, 1
+13       var tmp3/eax: boolean <- string-equal? *tmp2, "test"
+14       compare tmp3, 0
+15       {
+16         break-if-=
+17         run-tests
+18         exit-status <- copy 0  # TODO: get at Num-test-failures somehow
+19       }
+20       break $main-body
+21     }
+22     # otherwise operate interactively
+23     enable-keyboard-immediate-mode
+24     repl
+25     enable-keyboard-type-mode
+26     exit-status <- copy 0
+27   }
+28 }
+29 
+30 type cell {
+31   tag: int
+32     # 0: nil
+33     # 1: num
+34     # 2: char
+35     value: int
+36     # 3: sym
+37     # 4: string
+38     name: (handle array byte)
+39     # 4: array
+40     # 5: tree
+41     left: (handle cell)
+42     right: (handle cell)
+43     # 6: stream
+44     stream: (handle stream byte)
+45 }
+46 
+47 fn repl {
+48   var c: (handle cell)
+49   var c-ah/ecx: (addr handle cell) <- address c
+50   lisp-read c-ah
+51   var c-a/eax: (addr cell) <- lookup c
+52   compare c-a, 0
+53   break-if-=
+54   lisp-eval c-a c-ah
+55   lisp-print c-a
+56   loop
+57 }
+58 
+59 fn lisp-read out: (addr handle cell) {
+60 }
+61 
+62 fn lisp-eval in: (addr cell), out: (addr handle cell) {
+63 }
+64 
+65 fn lisp-print in: (addr cell) {
+66 }
+
+ + + -- cgit 1.4.1-2-gfad0