about summary refs log tree commit diff stats
path: root/subx/apps/pack.subx
diff options
context:
space:
mode:
Diffstat (limited to 'subx/apps/pack.subx')
-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