about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-02-16 22:36:21 -0800
committerKartik Agaram <vc@akkartik.com>2019-02-16 22:36:21 -0800
commitbf1fe33c369d815676c4b7b3a334a6d971988f64 (patch)
treecb2e145edbfcf414dcd82fd2a021b568bfec4706
parent1c80a50634f6378bfc89bb6986c66cb212a08ee7 (diff)
downloadmu-bf1fe33c369d815676c4b7b3a334a6d971988f64.tar.gz
4975 - new plan for Phase 2
So far I've been assuming that I'd just statelessly convert each line in
a .subx file. But over the past week or so of constant interruptions I
gradually realized that code and data need different parsers.
-rw-r--r--subx/apps/pack.subx40
1 files changed, 36 insertions, 4 deletions
diff --git a/subx/apps/pack.subx b/subx/apps/pack.subx
index cf0a27d7..755f3d79 100644
--- a/subx/apps/pack.subx
+++ b/subx/apps/pack.subx
@@ -75,9 +75,9 @@ $main:end:
 # We'll operate on each line/instruction in isolation. That way we only need to
 # allocate memory for converting a single instruction.
 #
-# To pack an entire file:
-#   read every line
-#   convert it
+# To pack an entire file, convert every segment in it
+# To convert a code segment, convert every instruction (line) until the next segment header
+# To convert a non-data segment, convert every word until the next segment header
 #
 # primary state: line
 #   stream of 512 bytes; abort if it ever overflows
@@ -89,7 +89,15 @@ convert:  # in : (address buffered-file), out : (address buffered-file) -> <void
     #     clear-stream(line)
     #     EAX = read-line(in, line)
     #     if (EAX == EOF) break
-    #     convert-instruction(line, out)
+    #     word-slice = next-word(line)
+    #     if (slice-empty?(word-slice)) continue  # just whitespace
+    #     if (starts-with(word-slice, "#")) continue  # ignore comments
+    #     assert(slice-equal?(word-slice, "=="))
+    #     word-slice = next-word(line)
+    #     if (slice-equal?(word-slice, "code"))
+    #       convert-code-segment(in, out)
+    #     else
+    #       convert-data-segment(in, out)
     #   flush(out)
     #
     # . prolog
@@ -148,6 +156,30 @@ $convert:end:
     5d/pop-to-EBP
     c3/return
 
+convert-code-segment:  # in : (address buffered-file), out : (address buffered-file) -> <void>
+    # pseudocode:
+    #   var line = new-stream(512, 1)
+    #   repeatedly
+    #     clear-stream(line)
+    #     EAX = read-line(in, line)
+    #     if (EAX == EOF) break
+    #     word-slice = next-word(line)
+    #     if (slice-equal?(word-slice, "=="))
+    #       return
+    #     convert-instruction(line, out)
+
+convert-data-segment:  # in : (address buffered-file), out : (address buffered-file) -> <void>
+    # pseudocode:
+    #   var line = new-stream(512, 1)
+    #   repeatedly
+    #     clear-stream(line)
+    #     EAX = read-line(in, line)
+    #     if (EAX == EOF) break
+    #     word-slice = next-word(line)
+    #     if (slice-equal?(word-slice, "=="))
+    #       return
+    #     convert-data-word(line, out)
+
 # - To pack an instruction, following the C++ version:
 # read first word as opcode and write-slice
 # if 0f or f2 or f3 read second opcode and write-slice