about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--059stop.subx3
-rw-r--r--078table.subx245
-rwxr-xr-xapps/assortbin35948 -> 36540 bytes
-rwxr-xr-xapps/crenshaw2-1bin29682 -> 30274 bytes
-rwxr-xr-xapps/crenshaw2-1bbin30241 -> 30833 bytes
-rwxr-xr-xapps/dquotesbin42504 -> 43096 bytes
-rwxr-xr-xapps/factorialbin28694 -> 29286 bytes
-rwxr-xr-xapps/handlebin29548 -> 30140 bytes
-rwxr-xr-xapps/hexbin38341 -> 38933 bytes
-rwxr-xr-xapps/packbin48634 -> 49226 bytes
-rwxr-xr-xapps/surveybin45231 -> 45823 bytes
-rwxr-xr-xapps/testsbin34760 -> 35352 bytes
12 files changed, 245 insertions, 3 deletions
diff --git a/059stop.subx b/059stop.subx
index 7fc99a27..f4e90707 100644
--- a/059stop.subx
+++ b/059stop.subx
@@ -39,7 +39,8 @@
 
 # Configure an exit-descriptor for a call pushing 'nbytes' bytes of args to
 # the stack.
-# Ugly that we need to know the size of args, but so it goes.
+# Ugly that we need to know the size of args. Don't allocate variables between
+# tailor-exit-descriptor and the call it's for.
 tailor-exit-descriptor:  # ed : (address exit-descriptor), nbytes : int -> <void>
     # . prolog
     55/push-EBP
diff --git a/078table.subx b/078table.subx
index 0a6e7c57..6518789c 100644
--- a/078table.subx
+++ b/078table.subx
@@ -1085,7 +1085,7 @@ $test-get-or-stop:success:
     # . . push args
     52/push-EDX/ed
     68/push  _test-error-buffered-file/imm32
-    68/push  "foo"/imm32
+    68/push  "foo"/imm32/abort-prefix
     68/push  8/imm32/row-size
     68/push  "code"/imm32
     51/push-ECX
@@ -1110,7 +1110,7 @@ $test-get-or-stop:failure:
     # . . push args
     52/push-EDX/ed
     68/push  _test-error-buffered-file/imm32
-    68/push  "foo"/imm32
+    68/push  "foo"/imm32/abort-prefix
     68/push  8/imm32/row-size
     68/push  "data"/imm32
     51/push-ECX
@@ -1140,6 +1140,247 @@ $test-get-or-stop:end:
     5d/pop-to-EBP
     c3/return
 
+# if no row is found, stop(ed)
+get-slice-or-stop:  # table : (address stream {string, _}), key : (address slice), row-size : int,
+                    # abort-message-prefix : (address string), err : (address buffered-file), ed : (address exit-descriptor)
+                    # -> EAX : (address _)
+    # pseudocode:
+    #   curr = table->data
+    #   max = &table->data[table->write]
+    #   while curr < max
+    #     if slice-equal?(key, *curr)
+    #       return curr+4
+    #     curr += row-size
+    #   write-buffered(err, msg)
+    #   stop(ed)
+    #
+    # . prolog
+    55/push-EBP
+    89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
+    # . save registers
+    51/push-ECX
+    52/push-EDX
+    56/push-ESI
+    # ESI = table
+    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           6/r32/ESI   8/disp8         .                 # copy *(EBP+8) to ESI
+    # curr/ECX = table->data
+    8d/copy-address                 1/mod/*+disp8   6/rm32/ESI    .           .             .           1/r32/ECX   0xc/disp8       .                 # copy ESI+12 to ECX
+    # 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-slice-or-stop:search-loop:
+    # if (curr >= max) stop(ed)
+    39/compare                      3/mod/direct    1/rm32/ECX    .           .             .           2/r32/EDX   .               .                 # compare ECX with EDX
+    73/jump-if-greater-or-equal-unsigned  $get-slice-or-stop:stop/disp8
+    # if (slice-equal?(key, *curr)) return curr+4
+    # . EAX = slice-equal?(key, *curr)
+    # . . push args
+    ff          6/subop/push        0/mod/indirect  1/rm32/ECX    .           .             .           .           .               .                 # push *ECX
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
+    # . . call
+    e8/call  slice-equal?/disp32
+    # . . discard args
+    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-slice-or-stop:mismatch/disp8
+    8d/copy-address                 1/mod/*+disp8   1/rm32/ECX    .           .             .           0/r32/EAX   4/disp8         .                 # copy ECX+4 to EAX
+    eb/jump  $get-slice-or-stop:end/disp8
+$get-slice-or-stop: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-slice-or-stop:search-loop/disp8
+$get-slice-or-stop:end:
+    # . restore registers
+    5e/pop-to-ESI
+    5a/pop-to-EDX
+    59/pop-to-ECX
+    # . epilog
+    89/copy                         3/mod/direct    4/rm32/ESP    .           .             .           5/r32/EBP   .               .                 # copy EBP to ESP
+    5d/pop-to-EBP
+    c3/return
+
+$get-slice-or-stop:stop:
+    # . write-buffered(err, abort-message-prefix)
+    # . . push args
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x14/disp8      .                 # push *(EBP+20)
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x18/disp8      .                 # push *(EBP+24)
+    # . . call
+    e8/call  write-buffered/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # . write-buffered(err, error)
+    # . . push args
+    68/push  ": get-slice-or-stop: key not found: "/imm32
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x18/disp8      .                 # push *(EBP+24)
+    # . . call
+    e8/call  write-buffered/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # . write-slice-buffered(err, key)
+    # . . push args
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x18/disp8      .                 # push *(EBP+24)
+    # . . call
+    e8/call  write-slice-buffered/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # . write-buffered(err, "\n")
+    # . . push args
+    68/push  "\n"/imm32
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x18/disp8      .                 # push *(EBP+24)
+    # . . call
+    e8/call  write-buffered/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # . stop(ed, 1)
+    # . . push args
+    68/push  1/imm32
+    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x1c/disp8      .                 # push *(EBP+28)
+    # . . call
+    e8/call  stop/disp32
+    # never gets here
+$get-slice-or-stop:terminus:
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # syscall(exit, 1)
+    b8/copy-to-EAX  1/imm32/exit
+    cd/syscall  0x80/imm8
+
+test-get-slice-or-stop:
+    # This test uses exit-descriptors. Use EBP for setting up local variables.
+    # . prolog
+    55/push-EBP
+    89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
+    # setup
+    # . clear-stream(_test-error-stream)
+    # . . push args
+    68/push  _test-error-stream/imm32
+    # . . call
+    e8/call  clear-stream/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # . clear-stream(_test-error-buffered-file+4)
+    # . . push args
+    b8/copy-to-EAX  _test-error-buffered-file/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
+    # var table/ECX : (address stream {string, number}) = stream(2 rows * 8 bytes)
+    81          5/subop/subtract    3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x10/imm32        # subtract from ESP
+    68/push  0x10/imm32/length
+    68/push  0/imm32/read
+    68/push  0/imm32/write
+    89/copy                         3/mod/direct    1/rm32/ECX    .           .             .           4/r32/ESP   .               .                 # copy ESP to ECX
+    # var ed/EDX : (address exit-descriptor)
+    68/push  0/imm32
+    68/push  0/imm32
+    89/copy                         3/mod/direct    2/rm32/EDX    .           .             .           4/r32/ESP   .               .                 # copy ESP to EDX
+    # var slice/EBX = "code"
+    # . (EAX..EBX) = "code"
+    b8/copy-to-EAX  "code"/imm32
+    8b/copy                         0/mod/indirect  0/rm32/EAX    .           .             .           3/r32/EBX   .               .                 # copy *EAX to EBX
+    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    0/base/EAX  3/index/EBX   .           3/r32/EBX   4/disp8         .                 # copy EAX+EBX+4 to EBX
+    05/add-to-EAX  4/imm32
+    # . EBX = {EAX, EBX}
+    53/push-EBX
+    50/push-EAX
+    89/copy                         3/mod/direct    3/rm32/EBX    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBX
+    # size 'ed' for the calls to 'get-or-stop' (define no locals past this point)
+    # . tailor-exit-descriptor(ed, 24)
+    # . . push args
+    68/push  0x18/imm32/nbytes-of-args-for-get-or-stop
+    52/push-EDX
+    # . . call
+    e8/call  tailor-exit-descriptor/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # insert(table, "code", 8 bytes per row)
+    # . . push args
+    68/push  8/imm32/row-size
+    68/push  "code"/imm32
+    51/push-ECX
+    # . . call
+    e8/call  get-or-insert/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+$test-get-slice-or-stop:success:
+    # EAX = get-slice-or-stop(table, slice, row-size=8, msg, _test-error-buffered-file, ed)
+    # . . push args
+    52/push-EDX/ed
+    68/push  _test-error-buffered-file/imm32
+    68/push  "foo"/imm32/abort-prefix
+    68/push  8/imm32/row-size
+    53/push-EBX/slice
+    51/push-ECX
+    # . . call
+    e8/call  get-slice-or-stop/disp32
+    # registers except ESP may be clobbered at this point
+    # restore register args, discard others
+    59/pop-to-ECX
+    5b/pop-to-EBX
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    5a/pop-to-EDX
+$test-get-slice-or-stop:success-assertion:
+    # 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-slice-or-stop/0"/imm32
+    68/push  0x10/imm32
+    29/subtract                     3/mod/direct    0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # subtract ECX from EAX
+    50/push-EAX
+    # . . 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-slice-or-stop:failure:
+    # slice = "segment2"
+    # . *EBX = "segment2"->data
+    b8/copy-to-EAX  "segment2"/imm32
+    05/add-to-EAX  4/imm32
+    89/copy                         0/mod/indirect  3/rm32/EBX    .           .             .           0/r32/EAX   .               .                 # copy EAX to *EBX
+    # . *(EBX+4) = "segment2"->data + len("segment2")
+    05/add-to-EAX  8/imm32/strlen
+    89/copy                         1/mod/*+disp8   3/rm32/EBX    .           .             .           0/r32/EAX   4/disp8         .                 # copy EAX to *(EBX+4)
+    # EAX = get-slice-or-stop(table, slice, row-size=8, msg, _test-error-buffered-file, ed)
+    # . . push args
+    52/push-EDX/ed
+    68/push  _test-error-buffered-file/imm32
+    68/push  "foo"/imm32/abort-prefix
+    68/push  8/imm32/row-size
+    53/push-EBX/slice
+    51/push-ECX
+    # . . call
+    e8/call  get-slice-or-stop/disp32
+    # registers except ESP may be clobbered at this point
+    # restore register args, discard others
+    59/pop-to-ECX
+    5b/pop-to-EBX
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    5a/pop-to-EDX
+$test-get-slice-or-stop:failure-assertion:
+    # check that get-or-stop tried to call stop(1)
+    # . check-ints-equal(ed->value, 2, msg)
+    # . . push args
+    68/push  "F - test-get-or-stop/1"/imm32
+    68/push  2/imm32
+    # . . push ed->value
+    ff          6/subop/push        1/mod/*+disp8   2/rm32/EDX    .           .             .           .           4/disp8         .                 # push *(EDX+4)
+    # . . 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-slice-or-stop:end:
+    # . epilog
+    # don't restore ESP from EBP; manually reclaim locals
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x2c/imm32        # add to ESP
+    5d/pop-to-EBP
+    c3/return
+
 # if no row is found, return null (0)
 maybe-get:  # table : (address stream {string, _}), key : (address string), row-size : int -> EAX : (address _)
     # pseudocode:
diff --git a/apps/assort b/apps/assort
index 97660d3c..94b0ea4e 100755
--- a/apps/assort
+++ b/apps/assort
Binary files differdiff --git a/apps/crenshaw2-1 b/apps/crenshaw2-1
index 4b8559fd..fa879144 100755
--- a/apps/crenshaw2-1
+++ b/apps/crenshaw2-1
Binary files differdiff --git a/apps/crenshaw2-1b b/apps/crenshaw2-1b
index f1f34232..347cb749 100755
--- a/apps/crenshaw2-1b
+++ b/apps/crenshaw2-1b
Binary files differdiff --git a/apps/dquotes b/apps/dquotes
index 1ccfd2a7..efa60694 100755
--- a/apps/dquotes
+++ b/apps/dquotes
Binary files differdiff --git a/apps/factorial b/apps/factorial
index b7b51d79..62c9e9c8 100755
--- a/apps/factorial
+++ b/apps/factorial
Binary files differdiff --git a/apps/handle b/apps/handle
index 9ed11054..94326ff3 100755
--- a/apps/handle
+++ b/apps/handle
Binary files differdiff --git a/apps/hex b/apps/hex
index 7bf66c63..15b7ec2f 100755
--- a/apps/hex
+++ b/apps/hex
Binary files differdiff --git a/apps/pack b/apps/pack
index ead510f0..44797c67 100755
--- a/apps/pack
+++ b/apps/pack
Binary files differdiff --git a/apps/survey b/apps/survey
index 6ca419a6..9adb79a1 100755
--- a/apps/survey
+++ b/apps/survey
Binary files differdiff --git a/apps/tests b/apps/tests
index cfb1fbe7..537be047 100755
--- a/apps/tests
+++ b/apps/tests
Binary files differ
28 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279