about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xsubx/apps/handlebin19426 -> 19478 bytes
-rw-r--r--subx/apps/handle.subx36
-rwxr-xr-xsubx/test_apps8
3 files changed, 32 insertions, 12 deletions
diff --git a/subx/apps/handle b/subx/apps/handle
index 5b1156a6..3d355737 100755
--- a/subx/apps/handle
+++ b/subx/apps/handle
Binary files differdiff --git a/subx/apps/handle.subx b/subx/apps/handle.subx
index f64d8ee1..60b4021a 100644
--- a/subx/apps/handle.subx
+++ b/subx/apps/handle.subx
@@ -15,10 +15,11 @@
 # To run (from the subx directory):
 #   $ ./subx translate *.subx apps/handle.subx -o apps/handle
 #   $ ./subx run apps/handle
-# Expected result is a hard abort:
-#   ........lookup failed
-# (This file is a prototype, so the tests in this file aren't real tests. Don't
-# expect to run anything in the same process after they've completed.)
+# Expected result is a successful lookup followed by a hard abort:
+#   lookup succeeded
+#   lookup failed
+# (This file is a prototype. The 'tests' in it aren't real; failures are
+# expected.)
 
 == code
 #   instruction                     effective address                                                   register    displacement    immediate
@@ -212,15 +213,22 @@ lookup:  # h : (handle T) -> EAX : (address T)
     # EAX = handle
     8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           0/r32/EAX   8/disp8         .                 # copy *(EBP+8) to EAX
     # - inline {
+    # push handle->alloc_id
+    ff          6/subop/push        0/mod/indirect  0/rm32/EAX    .           .             .           .           .               .                 # push *EAX
+    # EAX = handle->address (payload)
+    8b/copy                         1/mod/*+disp8   0/rm32/EAX    .           .             .           .           4/disp8         .                 # copy *(EAX+4) to EAX
     # push handle->address
-    ff          6/subop/push        1/mod/*+disp8   0/rm32/EAX    .           .             .           .           4/disp8         .                 # push *(EAX+4)
-    # EAX = handle->alloc_id
-    8b/copy                         0/mod/indirect  0/rm32/EAX    .           .             .           0/r32/EAX   .               .                 # copy *EAX to EAX
-    # if (EAX != *ESP) abort
-    39/compare                      0/mod/indirect  4/rm32/sib    4/base/ESP  4/index/none  .           0/r32/EAX   .               .                 # compare *ESP and EAX
+    50/push-EAX
+    # EAX = payload->alloc_id
+    8b/copy                         0/mod/indirect  0/rm32/EAX    .           .             .           .           .               .                 # copy *EAX to EAX
+    # if (EAX != handle->alloc_id) abort
+    39/compare                      1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none  .           0/r32/EAX   4/disp8         .                 # compare *(ESP+4) and EAX
     75/jump-if-not-equal  $lookup:abort/disp8
-    # return ESP+4
+    # EAX = pop handle->address
     58/pop-to-EAX
+    # discard handle->alloc_id
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # add 4
     05/add-to-EAX  4/imm32
     # - }
     # . epilog
@@ -295,6 +303,14 @@ test-lookup-success:
     # clean up
     # . *Next-alloc-id = 1
     c7          0/subop/copy        0/mod/indirect  5/rm32/.disp32            .             .           .     Next-alloc-id/disp32  1/imm32           # copy to *Next-alloc-id
+    # write(2/stderr, "lookup succeeded\n")
+    # . . push args
+    68/push  "lookup succeeded\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
     # . restore registers
     5a/pop-to-EDX
     59/pop-to-ECX
diff --git a/subx/test_apps b/subx/test_apps
index 08153d67..dd179655 100755
--- a/subx/test_apps
+++ b/subx/test_apps
@@ -131,9 +131,13 @@ test `uname` = 'Linux'  &&  examples/ex12
 echo handle
 ./subx translate 0*.subx apps/handle.subx  -o apps/handle
 [ "$1" != record ]  &&  git diff --exit-code apps/handle
-./subx run apps/handle 2>&1  |grep -q 'lookup failed'
+./subx run apps/handle >& handle.out  ||  true
+grep -q 'lookup succeeded' handle.out  ||  { echo "missing success test"; exit 1; }
+grep -q 'lookup failed' handle.out  ||  { echo "missing failure test"; exit 1; }
 test `uname` = 'Linux'  &&  {
-  apps/handle test 2>&1  |grep -q 'lookup failed'
+  apps/handle >& handle.out  ||  true
+  grep -q 'lookup succeeded' handle.out  ||  { echo "missing success test"; exit 1; }
+  grep -q 'lookup failed' handle.out  ||  { echo "missing failure test"; exit 1; }
 }
 
 echo factorial