about summary refs log tree commit diff stats
path: root/apps/mulisp.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-09-18 11:42:08 -0700
committerKartik Agaram <vc@akkartik.com>2019-09-18 11:42:08 -0700
commitfd2b373ad0a99a606883acd78126044a391a0e2f (patch)
treedad9ac08a56d13bacf3d28cb7eb83d17ac52e994 /apps/mulisp.subx
parenta5fa978579a2d9a08d89463e55b77ab3513ccfca (diff)
downloadmu-fd2b373ad0a99a606883acd78126044a391a0e2f.tar.gz
5663
Snapshot of mulisp before we put it on the back-burner. It's going to take
too long, and we're better off building out the lower layers that make
it more convenient to create.
Diffstat (limited to 'apps/mulisp.subx')
-rw-r--r--apps/mulisp.subx67
1 files changed, 63 insertions, 4 deletions
diff --git a/apps/mulisp.subx b/apps/mulisp.subx
index 59e1f561..4ae26e82 100644
--- a/apps/mulisp.subx
+++ b/apps/mulisp.subx
@@ -62,14 +62,14 @@ $main:end:
 #   - char: cell{ tag: 2/CHAR, data: $int 0 }
 #     data contains the utf-8 code of the character (no compound glyphs, no
 #     modifiers, etc., etc.)
-#   - string: cell{ tag: 3/STRING, data: $(address array byte)
+#   - string: cell{ tag: 3/STRING, data: $(address stream byte)
 #     data contains an (address array byte) containing the string in utf-8
 #   - symbol: cell{ tag: 4/SYMBOL, data: $(address array byte) 0 }
 #     data contains an (address array byte) containing the name of the symbol in utf-8
 #     alternatively, data could contain an index into the table of interned symbols
 #   - pair: cell{ tag: 5/PAIR, data: $(address cell) $(address cell)  }
 #     data contains pointers to car and cdr
-#   - array: cell{ tag: 6/ARRAY, data: $tag $(address array data)
+#   - array: cell{ tag: 6/ARRAY, data: $tag $(address stream data)
 #     data contains a pointer to an array of 8-byte data fields and the common
 #     tag for them all
 
@@ -102,18 +102,21 @@ $repl:end:
 # pairs start with '('
 # arrays start with '['
 # symbols start with anything else but quote, backquote, unquote or splice
+# only one s-expression per line
 lisp-read:  # in : (address buffered-file) -> eax : (address cell)
     # . prolog
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # . save registers
+    51/push-ecx
     # var s/ecx : (address stream) = new-stream(512)
     81 5/subop/subtract %esp 0x200/imm32
     68/push 0x200/imm32/size
     68/push 0/imm32/read
     68/push 0/imm32/write
     89/<- %ecx 4/r32/esp
-    #
+$lisp-read:loop:
+    # read line into s
     (clear-stream %ecx)
     (read-line-buffered *(ebp+8) %ecx)
     # if (s->write == 0) return null
@@ -121,18 +124,74 @@ lisp-read:  # in : (address buffered-file) -> eax : (address cell)
     75/jump-if-not-equal $lisp-read:loop/disp8
     b8/copy-to-eax 0/imm32/eof
     eb/jump $lisp-read:end/disp8
-$lisp-read:loop:
     # return s
     89/<- %eax 1/r32/ecx
 $lisp-read:end:
     # . reclaim locals
     81 0/subop/add %esp 0x20c/imm32
     # . restore registers
+    59/pop-to-ecx
+    # . epilog
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+# lisp-read:  in : (address buffered-file) -> (address cell)
+#   token tmp = next-token(in)
+#   if is-int(tmp) return cell(tmp)
+#   if is-string(tmp) return cell(tmp)
+#   if is-pair(tmp) ...
+#   if is-array(tmp) ...
+
+next-token:  # in : (address buffered-file), line : (address stream), result : (address slice)
+    # pseudocode:
+    #   if (line->read >= line->write)
+    #     read-line-buffered(in, line)
+    #     recurse
+    #   if (line->data[line->read] == ' ')
+    #     skip-chars-matching-whitespace(line)
+    #     recurse
+    #   if (line->data[line->read] == '#')
+    #     read-line-buffered(in, line)
+    #     recurse
+    #   eax = line->data[line->read]
+    #   if (eax == '"')
+    #     result->start = &line->data[line->read]
+    #     skip-string(in)
+    #     result->end = &line->data[line->read]
+    #     return
+    #   if (is-digit(eax))
+    #     result->start = &line->data[line->read]
+    #     skip-hex-int(in)
+    #     result->end = &line->data[line->read]
+    #     return
+    #   if (eax in '(' ')' '[' ']')
+    #     result->start = &line->data[line->read]
+    #     ++line->read
+    #     result->en = &line->data[line->read]
+    #     return
+    #   else
+    #     result->start = &line->data[line->read]
+    #     skip-lisp-word(line)
+    #     result->en = &line->data[line->read]
+    #     return
+    #
+    # . prolog
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+$next-token:end:
+    # . reclaim locals
+    # . restore registers
     # . epilog
     89/<- %esp 5/r32/ebp
     5d/pop-to-ebp
     c3/return
 
+new-int-cell:  # in : (address slice) -> eax : (address cell)
+
+new-string-cell:  # in : (address slice) -> eax : (address cell)
+
 lisp-eval:  # in : (address cell) -> eax : (address cell)
     # . prolog
     55/push-ebp