about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-08-12 23:18:31 -0700
committerKartik Agaram <vc@akkartik.com>2019-08-12 23:18:31 -0700
commit15a84e24497c107cc1572e8e85115d37179d83f4 (patch)
tree5f7222de61a308b6e9214ad6bd550890a6101b14
parent94d68ac2444b24ddac693c5d0a06c82c07c4bc25 (diff)
downloadmu-15a84e24497c107cc1572e8e85115d37179d83f4.tar.gz
better error message when get aborts
-rw-r--r--078table.subx30
-rwxr-xr-xapps/assortbin34384 -> 34424 bytes
-rwxr-xr-xapps/crenshaw2-1bin27378 -> 27418 bytes
-rwxr-xr-xapps/crenshaw2-1bbin27937 -> 27977 bytes
-rwxr-xr-xapps/desugarbin33629 -> 33687 bytes
-rw-r--r--apps/desugar.subx3
-rwxr-xr-xapps/dquotesbin40940 -> 40980 bytes
-rwxr-xr-xapps/factorialbin26294 -> 26334 bytes
-rwxr-xr-xapps/handlebin27148 -> 27188 bytes
-rwxr-xr-xapps/hexbin36939 -> 36979 bytes
-rwxr-xr-xapps/packbin47070 -> 47110 bytes
-rwxr-xr-xapps/surveybin43605 -> 43707 bytes
-rw-r--r--apps/survey.subx19
-rwxr-xr-xapps/testsbin33196 -> 33236 bytes
14 files changed, 35 insertions, 17 deletions
diff --git a/078table.subx b/078table.subx
index cbe8222f..90976b11 100644
--- a/078table.subx
+++ b/078table.subx
@@ -1,7 +1,4 @@
-# - managing tables
-# SubX has rudimentary support for tables.
-#
-# Each table is a stream of (key, value) rows.
+# A table is a stream of (key, value) rows.
 #
 # Each row consists of a 4-byte key (address to a string) and a variable-size
 # value.
@@ -9,13 +6,14 @@
 # Accessing the table performs a linear scan for a key string, and always
 # requires passing in the row size.
 #
-# Table primitives have the form <variant>(stream, <arg>, row-size) -> address/EAX
+# Table primitives have the form <variant>(stream, <arg>, row-size, ...) -> address/EAX
 #
 # The following table shows available options for <variant>:
 #   if not found:           | arg=string              arg=slice
 #   ------------------------+---------------------------------------------------
 #   abort                   | get                     get-slice
 #   insert key              | get-or-insert           leaky-get-or-insert-slice
+# Some variants may take extra args.
 
 == code
 #   instruction                     effective address                                                   register    displacement    immediate
@@ -23,7 +21,7 @@
 # . 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes
 
 # if no row is found, abort
-get:  # table : (address stream {string, _}), key : (address string), row-size : int -> EAX : (address _)
+get:  # table : (address stream {string, _}), key : (address string), row-size : int, abort-message-prefix : (address string) -> EAX : (address _)
     # pseudocode:
     #   curr = table->data
     #   max = &table->data[table->write]
@@ -81,9 +79,17 @@ $get:end:
     c3/return
 
 $get:abort:
+    # . _write(2/stderr, abort-message-prefix)
+    # . . push args
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x14/disp8      .                 # push *(EBP+20)
+    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
     # . _write(2/stderr, error)
     # . . push args
-    68/push  "get: key not found: "/imm32
+    68/push  ": get: key not found: "/imm32
     68/push  2/imm32/stderr
     # . . call
     e8/call  _write/disp32
@@ -189,7 +195,7 @@ $test-get:end:
     c3/return
 
 # if no row is found, abort
-get-slice:  # table : (address stream {string, _}), key : (address slice), row-size : int -> EAX : (address _)
+get-slice:  # table : (address stream {string, _}), key : (address slice), row-size : int, abort-message-prefix : (address string) -> EAX : (address _)
     # pseudocode:
     #   curr = table->data
     #   max = &table->data[table->write]
@@ -247,6 +253,14 @@ $get-slice:end:
     c3/return
 
 $get-slice:abort:
+    # . _write(2/stderr, abort-message-prefix)
+    # . . push args
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x14/disp8      .                 # push *(EBP+20)
+    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
     # . _write(2/stderr, error)
     # . . push args
     68/push  "get-slice: key not found: "/imm32
diff --git a/apps/assort b/apps/assort
index 70d7aaf3..65c376cb 100755
--- a/apps/assort
+++ b/apps/assort
Binary files differdiff --git a/apps/crenshaw2-1 b/apps/crenshaw2-1
index 9b0e0c58..46a69570 100755
--- a/apps/crenshaw2-1
+++ b/apps/crenshaw2-1
Binary files differdiff --git a/apps/crenshaw2-1b b/apps/crenshaw2-1b
index 34adc8ea..1ecdf77d 100755
--- a/apps/crenshaw2-1b
+++ b/apps/crenshaw2-1b
Binary files differdiff --git a/apps/desugar b/apps/desugar
index d04778dc..7e37ec11 100755
--- a/apps/desugar
+++ b/apps/desugar
Binary files differdiff --git a/apps/desugar.subx b/apps/desugar.subx
index 25c21d78..a982a5c6 100644
--- a/apps/desugar.subx
+++ b/apps/desugar.subx
@@ -227,13 +227,14 @@ desugar-register: # word : (address slice), out : (address buffered-file)
     50/push-EAX
     # reg-num/EAX = get-slice(Registers, word, row-size=8)
     # . . push args
+    68/push  "Registers"/imm32
     68/push  8/imm32/row-size
     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           8/disp8         .                 # push *(EBP+8)
     68/push  Registers/imm32
     # . . call
     e8/call  get-slice/disp32
     # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x10/imm32        # add to ESP
     # write-buffered(out, "3/mod/direct ")
     # . . push args
     68/push  "3/mod/direct "/imm32
diff --git a/apps/dquotes b/apps/dquotes
index b7a4adfe..bada9287 100755
--- a/apps/dquotes
+++ b/apps/dquotes
Binary files differdiff --git a/apps/factorial b/apps/factorial
index 8db732fa..ba94e958 100755
--- a/apps/factorial
+++ b/apps/factorial
Binary files differdiff --git a/apps/handle b/apps/handle
index ffaf43b4..6c590f36 100755
--- a/apps/handle
+++ b/apps/handle
Binary files differdiff --git a/apps/hex b/apps/hex
index 84575cfd..7d13505d 100755
--- a/apps/hex
+++ b/apps/hex
Binary files differdiff --git a/apps/pack b/apps/pack
index 720ba3ea..820f7962 100755
--- a/apps/pack
+++ b/apps/pack
Binary files differdiff --git a/apps/survey b/apps/survey
index 621efa5c..3431001b 100755
--- a/apps/survey
+++ b/apps/survey
Binary files differdiff --git a/apps/survey.subx b/apps/survey.subx
index 14f4eb55..4345b3ec 100644
--- a/apps/survey.subx
+++ b/apps/survey.subx
@@ -1435,7 +1435,7 @@ compute-addresses:  # segments : (address stream {string, segment-info}), labels
     #   while true
     #     if (lrow >= max) break
     #     seg-name : (address string) = lrow->segment-name
-    #     label-seg : (address segment-info) = get(segments, seg-name, row-size=16)
+    #     label-seg : (address segment-info) = get(segments, seg-name)
     #     lrow->address = label-seg->address + lrow->segment-offset
     #     trace-sssns("label " lrow->key " is at address " lrow->address)
     #     lrow += 16  # row-size
@@ -1589,18 +1589,19 @@ $compute-addresses:label-loop:
 #?     # . . discard args
 #?     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
 #?     # }}}
-    # label-seg/EDX : (address segment-info) = get(segments, seg-name, row-size=16)
+    # label-seg/EDX : (address segment-info) = get(segments, seg-name, row-size=16, "segment table")
     # . save EAX
     50/push-EAX
     # . EAX = get(segments, seg-name, row-size=16)
     # . . push args
+    68/push  "segment table"/imm32
     68/push  0x10/imm32/row-size
     52/push-EDX
     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           8/disp8         .                 # push *(EBP+8)
     # . . call
     e8/call  get/disp32
     # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x10/imm32        # add to ESP
     # . EDX = EAX
     89/copy                         3/mod/direct    2/rm32/EDX    .           .             .           0/r32/EAX   .               .                 # copy EAX to EDX
     # . restore EAX
@@ -2264,16 +2265,17 @@ $emit-segments:check-metadata:
 #?     # . . discard args
 #?     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
 #?     # }}}
-    # info/ESI = get-slice(labels, datum, row-size=16)
-    # . EAX = get-slice(labels, datum, row-size=16)
+    # info/ESI = get-slice(labels, datum, row-size=16, "label table")
+    # . EAX = get-slice(labels, datum, row-size=16, "label table")
     # . . push args
+    68/push  "label table"/imm32
     68/push  0x10/imm32/row-size
     57/push-EDI
     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x14/disp8      .                 # push *(EBP+20)
     # . . call
     e8/call  get-slice/disp32
     # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x10/imm32        # add to ESP
     # . ESI = EAX
     89/copy                         3/mod/direct    6/rm32/ESI    .           .             .           0/r32/EAX   .               .                 # copy EAX to ESI
 $emit-segments:check-global-variable:
@@ -3377,15 +3379,16 @@ emit-elf-header:  # out : (address buffered-file), segments : (address stream {s
     # *Elf_e_entry = get(labels, "Entry")->address
     # . EAX = labels
     8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           0/r32/EAX   0x10/disp8      .                 # copy *(EBP+16) to EAX
-    # . label-info/EAX = get(labels, "Entry", row-size=16)
+    # . label-info/EAX = get(labels, "Entry", row-size=16, "label table")
     # . . push args
+    68/push  "label table"/imm32
     68/push  0x10/imm32/row-size
     68/push  "Entry"/imm32
     50/push-EAX
     # . . call
     e8/call  get/disp32
     # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x10/imm32        # add to ESP
     # . EAX = label-info->address
     8b/copy                         1/mod/*+disp8   0/rm32/EAX    .           .             .           0/r32/EAX   8/disp8         .                 # copy *(EAX+8) to EAX
     # . *Elf_e_entry = EAX
diff --git a/apps/tests b/apps/tests
index 52af8441..fb27af91 100755
--- a/apps/tests
+++ b/apps/tests
Binary files differ