about summary refs log tree commit diff stats
path: root/subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-06-28 17:31:33 -0700
committerKartik Agaram <vc@akkartik.com>2019-06-28 17:31:33 -0700
commit397f7c4687a85e999efe07e803b16f900d411442 (patch)
treeface56cfc122da5710f848f76aeb9c99533d5c9f /subx
parent33ba3de93d0b474756cded10b50eb1641f02b394 (diff)
downloadmu-397f7c4687a85e999efe07e803b16f900d411442.tar.gz
.
Diffstat (limited to 'subx')
-rwxr-xr-xsubx/apps/assortbin27316 -> 27376 bytes
-rw-r--r--subx/apps/assort.subx6
-rwxr-xr-xsubx/apps/packbin42230 -> 42290 bytes
-rw-r--r--subx/apps/subx-common.subx82
-rwxr-xr-xsubx/apps/surveybin27549 -> 27609 bytes
5 files changed, 44 insertions, 44 deletions
diff --git a/subx/apps/assort b/subx/apps/assort
index eae83c2c..188fc4b4 100755
--- a/subx/apps/assort
+++ b/subx/apps/assort
Binary files differdiff --git a/subx/apps/assort.subx b/subx/apps/assort.subx
index ab58fa3e..2f9ca98e 100644
--- a/subx/apps/assort.subx
+++ b/subx/apps/assort.subx
@@ -448,7 +448,7 @@ read-segments:  # in : (address buffered-file), table : (address stream {string,
     #       continue
     #     if slice-equal?(word-slice, "==")
     #       var segment-name = next-word(line)
-    #       segment-slot = get-or-insert(table, segment-name, row-size=8)
+    #       segment-slot = get-or-insert-slice(table, segment-name, row-size=8)
     #       curr-segment = *segment-slot
     #       if curr-segment != 0
     #         continue
@@ -667,13 +667,13 @@ $read-segments:check-for-segment-header:
 #?     # . . discard args
 #?     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
 #?     # }}}
-    # segment-slot/EAX = get-or-insert(table, segment-name, value-size=8)
+    # segment-slot/EAX = get-or-insert-slice(table, segment-name, value-size=8)
     # . . push args
     68/push  8/imm32/value-size
     52/push-EDX
     ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
     # . . call
-    e8/call  get-or-insert/disp32
+    e8/call  get-or-insert-slice/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
     # curr-segment = *segment-slot
diff --git a/subx/apps/pack b/subx/apps/pack
index 9169701e..d90d266a 100755
--- a/subx/apps/pack
+++ b/subx/apps/pack
Binary files differdiff --git a/subx/apps/subx-common.subx b/subx/apps/subx-common.subx
index 09a692ce..4555d75e 100644
--- a/subx/apps/subx-common.subx
+++ b/subx/apps/subx-common.subx
@@ -6,24 +6,24 @@
 # . 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
 
 # 'table' is a stream of (key, value) rows
-# keys are always strings
-# values may be any type but have size 'n'
+# keys are always strings (addresses; size 4 bytes)
+# values may be any type, but rows (key+value) always occupy 'row-size' bytes
 # scan 'table' for a row with a key 's' and return the address of the corresponding value
 # if no row is found, save 's' in the next available row
-# if there are no rows free, return null
+# if there are no rows free, abort
 # TODO: pass in an allocation descriptor
-get-or-insert:  # table : (address stream {string, _}), s : (address slice), n : int -> EAX : (address _)
+get-or-insert-slice:  # table : (address stream {string, _}), s : (address slice), row-size : int -> EAX : (address _)
     # pseudocode:
     #   curr = table->data
     #   max = &table->data[table->write]
     #   while curr < max
     #     if slice-equal?(s, *curr)
     #       return curr+4
-    #     curr += n
+    #     curr += row-size
     #   if table->write >= table->length
     #     abort
     #   *max = slice-to-string(Heap, s)
-    #   table->write += n
+    #   table->write += row-size
     #   return max+4
     #
     # . prolog
@@ -40,10 +40,10 @@ get-or-insert:  # table : (address stream {string, _}), s : (address slice), n :
     # max/EDX = table->data + table->write
     8b/copy                         0/mod/indirect  6/rm32/ESI    .           .             .           2/r32/EDX   .               .                 # copy *ESI to EDX
     8d/copy-address                 0/mod/indirect  4/rm32/sib    1/base/ECX  2/index/EDX   .           2/r32/EDX   .               .                 # copy ECX+EDX to EDX
-$get-or-insert:search-loop:
+$get-or-insert-slice:search-loop:
     # if (curr >= max) break
     39/compare                      3/mod/direct    1/rm32/ECX    .           .             .           2/r32/EDX   .               .                 # compare ECX with EDX
-    7d/jump-if-greater-or-equal  $get-or-insert:not-found/disp8
+    7d/jump-if-greater-or-equal  $get-or-insert-slice:not-found/disp8
     # if (slice-equal?(s, *curr)) return *(curr+4)
     # . EAX = slice-equal?(s, *curr)
     # . . push args
@@ -55,21 +55,21 @@ $get-or-insert:search-loop:
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     # . if (EAX != 0) return EAX = curr+4
     3d/compare-EAX-and  0/imm32
-    74/jump-if-equal  $get-or-insert:mismatch/disp8
+    74/jump-if-equal  $get-or-insert-slice:mismatch/disp8
     8d/copy-address                 1/mod/*+disp8   1/rm32/ECX    .           .             .           0/r32/EAX   4/disp8         .                 # copy ECX+4 to EAX
-    eb/jump  $get-or-insert:end/disp8
-$get-or-insert:mismatch:
-    # curr += n
+    eb/jump  $get-or-insert-slice:end/disp8
+$get-or-insert-slice:mismatch:
+    # curr += row-size
     03/add                          1/mod/*+disp8   5/rm32/EBP    .           .             .           1/r32/ECX   0x10/disp8      .                 # add *(EBP+16) to ECX
     # loop
-    eb/jump  $get-or-insert:search-loop/disp8
-$get-or-insert:not-found:
+    eb/jump  $get-or-insert-slice:search-loop/disp8
+$get-or-insert-slice:not-found:
     # result/EAX = 0
     31/xor                          3/mod/direct    0/rm32/EAX    .           .             .           0/r32/EAX   .               .                 # clear EAX
     # if (table->write >= table->length) abort
     8b/copy                         0/mod/indirect  6/rm32/ESI    .           .             .           1/r32/ECX   .               .                 # copy *ESI to ECX
     3b/compare                      1/mod/*+disp8   6/rm32/ESI    .           .             .           1/r32/ECX   8/disp8         .                 # compare ECX with *(ESI+8)
-    7d/jump-if-greater-or-equal  $get-or-insert:abort/disp8
+    7d/jump-if-greater-or-equal  $get-or-insert-slice:abort/disp8
     # *max = slice-to-string(Heap, s)
     # . EAX = slice-to-string(Heap, s)
     # . . push args
@@ -81,8 +81,8 @@ $get-or-insert:not-found:
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     # . *max = EAX
     89/copy                         0/mod/indirect  2/rm32/EDX    .           .             .           0/r32/EAX   .               .                 # copy EAX to *EDX
-    # table->write += n
-    # . EAX = n
+    # table->write += row-size
+    # . EAX = row-size
     8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           0/r32/EAX   0x10/disp8      .                 # copy *(EBP+16) to EAX
     # . table->write += EAX
     01/add                          0/mod/indirect  6/rm32/ESI    .           .             .           0/r32/EAX   .               .                 # add EAX to *ESI
@@ -91,7 +91,7 @@ $get-or-insert:not-found:
     89/copy                         3/mod/direct    0/rm32/EAX    .           .             .           2/r32/EDX   .               .                 # copy EDX to EAX
     # . EAX += 4
     05/add-to-EAX  4/imm32
-$get-or-insert:end:
+$get-or-insert-slice:end:
     # . restore registers
     5e/pop-to-ESI
     5a/pop-to-EDX
@@ -101,10 +101,10 @@ $get-or-insert:end:
     5d/pop-to-EBP
     c3/return
 
-$get-or-insert:abort:
+$get-or-insert-slice:abort:
     # . _write(2/stderr, error)
     # . . push args
-    68/push  "get-or-insert: too many segments"/imm32
+    68/push  "get-or-insert-slice: too many segments"/imm32
     68/push  2/imm32/stderr
     # . . call
     e8/call  _write/disp32
@@ -116,7 +116,7 @@ $get-or-insert:abort:
     cd/syscall  0x80/imm8
     # never gets here
 
-test-get-or-insert:
+test-get-or-insert-slice:
     # . prolog
     55/push-EBP
     89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
@@ -130,21 +130,21 @@ test-get-or-insert:
     68/push  _test-code-segment-end/imm32/end
     68/push  _test-code-segment/imm32/start
     89/copy                         3/mod/direct    2/rm32/EDX    .           .             .           4/r32/ESP   .               .                 # copy ESP to EDX
-$test-get-or-insert:first-call:
+$test-get-or-insert-slice:first-call:
     # - start with an empty table, insert one key, verify that it was inserted
-    # EAX = get-or-insert(table, "code" slice, 8 bytes per row)
+    # EAX = get-or-insert-slice(table, "code" slice, 8 bytes per row)
     # . . push args
     68/push  8/imm32/row-size
     52/push-EDX
     51/push-ECX
     # . . call
-    e8/call  get-or-insert/disp32
+    e8/call  get-or-insert-slice/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
     # check-ints-equal(EAX - table->data, 4, msg)  # first row's value slot returned
     # . check-ints-equal(EAX - table, 16, msg)
     # . . push args
-    68/push  "F - test-get-or-insert/0"/imm32
+    68/push  "F - test-get-or-insert-slice/0"/imm32
     68/push  0x10/imm32
     29/subtract                     3/mod/direct    0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # subtract ECX from EAX
     50/push-EAX
@@ -152,10 +152,10 @@ $test-get-or-insert:first-call:
     e8/call  check-ints-equal/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
-$test-get-or-insert:check2:
+$test-get-or-insert-slice:check2:
     # check-ints-equal(table->write, row-size = 8, msg)
     # . . push args
-    68/push  "F - test-get-or-insert/1"/imm32
+    68/push  "F - test-get-or-insert-slice/1"/imm32
     68/push  8/imm32/row-size
     ff          6/subop/push        0/mod/indirect  1/rm32/ECX    .           .             .           .           .               .                 # push *ECX
     # . . call
@@ -164,28 +164,28 @@ $test-get-or-insert:check2:
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
     # check-string-equal(*table->data, "code", msg)
     # . . push args
-    68/push  "F - test-get-or-insert/2"/imm32
+    68/push  "F - test-get-or-insert-slice/2"/imm32
     68/push  "code"/imm32
     ff          6/subop/push        1/mod/*+disp8   1/rm32/ECX    .           .             .           .           0xc/disp8       .                 # push *(ECX+12)
     # . . call
     e8/call  check-string-equal/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
-$test-get-or-insert:second-call:
+$test-get-or-insert-slice:second-call:
     # - insert the same key again, verify that it was reused
-    # EAX = get-or-insert(table, "code" slice, 8 bytes per row)
+    # EAX = get-or-insert-slice(table, "code" slice, 8 bytes per row)
     # . . push args
     68/push  8/imm32/row-size
     52/push-EDX
     51/push-ECX
     # . . call
-    e8/call  get-or-insert/disp32
+    e8/call  get-or-insert-slice/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
     # check-ints-equal(EAX - table->data, 4, msg)
     # . check-ints-equal(EAX - table, 16, msg)
     # . . push args
-    68/push  "F - test-get-or-insert/3"/imm32
+    68/push  "F - test-get-or-insert-slice/3"/imm32
     68/push  0x10/imm32
     29/subtract                     3/mod/direct    0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # subtract ECX from EAX
     50/push-EAX
@@ -196,7 +196,7 @@ $test-get-or-insert:second-call:
     # no new row inserted
     # . check-ints-equal(table->write, row-size = 8, msg)
     # . . push args
-    68/push  "F - test-get-or-insert/4"/imm32
+    68/push  "F - test-get-or-insert-slice/4"/imm32
     68/push  8/imm32/row-size
     ff          6/subop/push        0/mod/indirect  1/rm32/ECX    .           .             .           .           .               .                 # push *ECX
     # . . call
@@ -205,32 +205,32 @@ $test-get-or-insert:second-call:
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
     # check-string-equal(*table->data, "code", msg)
     # . . push args
-    68/push  "F - test-get-or-insert/5"/imm32
+    68/push  "F - test-get-or-insert-slice/5"/imm32
     68/push  "code"/imm32
     ff          6/subop/push        1/mod/*+disp8   1/rm32/ECX    .           .             .           .           0xc/disp8       .                 # push *(ECX+12)
     # . . call
     e8/call  check-string-equal/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
-$test-get-or-insert:third-call:
+$test-get-or-insert-slice:third-call:
     # - insert a new key, verify that it was inserted
     # EDX : (address slice) = "data"
     c7          0/subop/copy        0/mod/indirect  2/rm32/EDX    .           .             .           .           .               _test-data-segment/imm32  # copy to *EDX
     c7          0/subop/copy        1/mod/*+disp8   2/rm32/EDX    .           .             .           .           4/disp8         _test-data-segment-end/imm32  # copy to *(EDX+4)
-    # EAX = get-or-insert(table, "data" slice, 8 bytes per row)
+    # EAX = get-or-insert-slice(table, "data" slice, 8 bytes per row)
     # . . push args
     68/push  8/imm32/row-size
     52/push-EDX
     51/push-ECX
     # . . call
-    e8/call  get-or-insert/disp32
+    e8/call  get-or-insert-slice/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
     # table gets a new row
     # check-ints-equal(EAX - table->data, 12, msg)  # second row's value slot returned
     # . check-ints-equal(EAX - table, 24, msg)
     # . . push args
-    68/push  "F - test-get-or-insert/6"/imm32
+    68/push  "F - test-get-or-insert-slice/6"/imm32
     68/push  0x18/imm32
     29/subtract                     3/mod/direct    0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # subtract ECX from EAX
     50/push-EAX
@@ -240,7 +240,7 @@ $test-get-or-insert:third-call:
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
     # check-ints-equal(table->write, 2 rows = 16, msg)
     # . . push args
-    68/push  "F - test-get-or-insert/7"/imm32
+    68/push  "F - test-get-or-insert-slice/7"/imm32
     68/push  0x10/imm32/two-rows
     ff          6/subop/push        0/mod/indirect  1/rm32/ECX    .           .             .           .           .               .                 # push *ECX
     # . . call
@@ -250,14 +250,14 @@ $test-get-or-insert:third-call:
     # check-string-equal(*table->data+8, "data", msg)
     # check-string-equal(*(table+20), "data", msg)
     # . . push args
-    68/push  "F - test-get-or-insert/8"/imm32
+    68/push  "F - test-get-or-insert-slice/8"/imm32
     68/push  "data"/imm32
     ff          6/subop/push        1/mod/*+disp8   1/rm32/ECX    .           .             .           .           0x14/disp8      .                 # push *(ECX+20)
     # . . call
     e8/call  check-string-equal/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
-$test-get-or-insert:end:
+$test-get-or-insert-slice:end:
     # . epilog
     89/copy                         3/mod/direct    4/rm32/ESP    .           .             .           5/r32/EBP   .               .                 # copy EBP to ESP
     5d/pop-to-EBP
diff --git a/subx/apps/survey b/subx/apps/survey
index 1fd5cd5d..dedf6a9b 100755
--- a/subx/apps/survey
+++ b/subx/apps/survey
Binary files differ