about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-07-21 22:34:15 -0700
committerKartik Agaram <vc@akkartik.com>2019-07-21 23:29:38 -0700
commit0d219f0a732d81dad124906f5594a06b023fa3a0 (patch)
tree1e450a89e25e609c900c57edfb88ded4e96cf8da
parentac8a9396b96259ed2d068abf30863540a21648f3 (diff)
downloadmu-0d219f0a732d81dad124906f5594a06b023fa3a0.tar.gz
5438 - raise error on uppercase hex
We can now translate layers 49-56 using the self-hosted translator
(`translate` and `ntranslate`).

As a follow-up to commit 5404, the self-hosted translator is a little
more strict than the C++ translator in 3 places:

a) All .subx files must define a data segment.

b) All .subx files must define an `Entry` label.

c) All numbers must be in *lowercase* hex.

In all cases, where programs work with the C++ translator but violate
the self-hosted translator's assumptions, we must make sure we raise
errors rather than silently emit bad code.
-rw-r--r--subx/056trace.subx4
-rw-r--r--subx/067parse-hex.subx75
-rwxr-xr-xsubx/apps/assortbin34167 -> 34326 bytes
-rwxr-xr-xsubx/apps/crenshaw2-1bin24575 -> 24734 bytes
-rwxr-xr-xsubx/apps/crenshaw2-1bbin25134 -> 25293 bytes
-rwxr-xr-xsubx/apps/dquotesbin40723 -> 40882 bytes
-rwxr-xr-xsubx/apps/factorialbin23491 -> 23650 bytes
-rwxr-xr-xsubx/apps/handlebin24350 -> 24509 bytes
-rwxr-xr-xsubx/apps/hexbin27584 -> 27743 bytes
-rwxr-xr-xsubx/apps/packbin46819 -> 46978 bytes
-rwxr-xr-xsubx/apps/surveybin42817 -> 42976 bytes
-rwxr-xr-xsubx/apps/testsbin32979 -> 33138 bytes
12 files changed, 72 insertions, 7 deletions
diff --git a/subx/056trace.subx b/subx/056trace.subx
index cc245e3f..c1105b15 100644
--- a/subx/056trace.subx
+++ b/subx/056trace.subx
@@ -984,7 +984,7 @@ _test-stream-line-ABABA:
     # length
     8/imm32
     # data
-    41 42 41 42 41 0A 00 00  # 8 bytes
+    41 42 41 42 41 0a 00 00  # 8 bytes
 
 _test-stream-empty:
     # write
@@ -1004,6 +1004,6 @@ _test-stream-filled:
     # length
     8/imm32
     # data
-    41 41 41 41 0A 41 41 41  # 8 bytes
+    41 41 41 41 0a 41 41 41  # 8 bytes
 
 # . . vim:nowrap:textwidth=0
diff --git a/subx/067parse-hex.subx b/subx/067parse-hex.subx
index bbfc4ec9..45d168d9 100644
--- a/subx/067parse-hex.subx
+++ b/subx/067parse-hex.subx
@@ -795,15 +795,80 @@ test-hex-above-f:
     c3/return
 
 from-hex-char:  # in/EAX : byte -> out/EAX : nibble
-    # no error checking; accepts argument in EAX
-    # if (EAX <= '9') return EAX - '0'
+$from-hex-char:check0:
+    # if (EAX < '0') goto abort
+    3d/compare-EAX-with  0x30/imm32/0
+    7c/jump-if-lesser  $from-hex-char:abort/disp8
+$from-hex-char:check1:
+    # if (EAX > 'f') goto abort
+    3d/compare-EAX-with  0x66/imm32/f
+    7f/jump-if-greater  $from-hex-char:abort/disp8
+$from-hex-char:check2:
+    # if (EAX > '9') goto next check
     3d/compare-EAX-with  0x39/imm32/9
-    7f/jump-if-greater  $from-hex-char:else/disp8
+    7f/jump-if-greater  $from-hex-char:check3/disp8
+$from-hex-char:digit:
+    # return EAX - '0'
     2d/subtract-from-EAX  0x30/imm32/0
     c3/return
-$from-hex-char:else:
-    # otherwise return EAX - 'a' + 10
+$from-hex-char:check3:
+    # if (EAX < 'a') goto abort
+    3d/compare-EAX-with  0x61/imm32/a
+    7c/jump-if-lesser  $from-hex-char:abort/disp8
+$from-hex-char:letter:
+    # return EAX - ('a'-10)
     2d/subtract-from-EAX  0x57/imm32/a-10
     c3/return
 
+$from-hex-char:abort:
+    # . _write(2/stderr, error)
+    # . . push args
+    68/push  "invalid hex char: "/imm32
+    68/push  2/imm32/stderr
+    # . . call
+    e8/call  _write/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # . clear-stream(Stderr+4)
+    # . . save EAX
+    50/push-EAX
+    # . . push args
+    b8/copy-to-EAX  Stderr/imm32
+    05/add-to-EAX  4/imm32
+    50/push-EAX
+    # . . call
+    e8/call  clear-stream/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # . . restore EAX
+    58/pop-to-EAX
+    # . print-int32-buffered(Stderr, EAX)
+    # . . push args
+    50/push-EAX
+    68/push  Stderr/imm32
+    # . . call
+    e8/call  print-int32-buffered/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # . flush(Stderr)
+    # . . push args
+    68/push  Stderr/imm32
+    # . . call
+    e8/call  flush/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # . _write(2/stderr, "\n")
+    # . . push args
+    68/push  "\n"/imm32
+    68/push  2/imm32/stderr
+    # . . call
+    e8/call  _write/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # . syscall(exit, 1)
+    bb/copy-to-EBX  1/imm32
+    b8/copy-to-EAX  1/imm32/exit
+    cd/syscall  0x80/imm8
+    # never gets here
+
 # . . vim:nowrap:textwidth=0
diff --git a/subx/apps/assort b/subx/apps/assort
index d096be37..61aadb87 100755
--- a/subx/apps/assort
+++ b/subx/apps/assort
Binary files differdiff --git a/subx/apps/crenshaw2-1 b/subx/apps/crenshaw2-1
index db50d1cf..d4593a77 100755
--- a/subx/apps/crenshaw2-1
+++ b/subx/apps/crenshaw2-1
Binary files differdiff --git a/subx/apps/crenshaw2-1b b/subx/apps/crenshaw2-1b
index 4e05331b..51919217 100755
--- a/subx/apps/crenshaw2-1b
+++ b/subx/apps/crenshaw2-1b
Binary files differdiff --git a/subx/apps/dquotes b/subx/apps/dquotes
index 49ca7a1a..3bcefaf0 100755
--- a/subx/apps/dquotes
+++ b/subx/apps/dquotes
Binary files differdiff --git a/subx/apps/factorial b/subx/apps/factorial
index 820890e5..311ef05c 100755
--- a/subx/apps/factorial
+++ b/subx/apps/factorial
Binary files differdiff --git a/subx/apps/handle b/subx/apps/handle
index 1ba82034..63f7511b 100755
--- a/subx/apps/handle
+++ b/subx/apps/handle
Binary files differdiff --git a/subx/apps/hex b/subx/apps/hex
index 230e3f2d..f3ad62f1 100755
--- a/subx/apps/hex
+++ b/subx/apps/hex
Binary files differdiff --git a/subx/apps/pack b/subx/apps/pack
index 757378f9..737d0c33 100755
--- a/subx/apps/pack
+++ b/subx/apps/pack
Binary files differdiff --git a/subx/apps/survey b/subx/apps/survey
index 4d30e651..299ea71c 100755
--- a/subx/apps/survey
+++ b/subx/apps/survey
Binary files differdiff --git a/subx/apps/tests b/subx/apps/tests
index 58ece991..00201e83 100755
--- a/subx/apps/tests
+++ b/subx/apps/tests
Binary files differ