about summary refs log tree commit diff stats
path: root/069allocate.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-05-13 00:51:31 -0700
committerKartik Agaram <vc@akkartik.com>2020-05-18 00:44:49 -0700
commit456b44fbfb6003195aceef8ed41f194cd2e27b80 (patch)
tree9044af8f1e58c4fb601d397606b85906f4fb4994 /069allocate.subx
parente5118fa9fb6b1925f785f810767ca642097622d3 (diff)
downloadmu-456b44fbfb6003195aceef8ed41f194cd2e27b80.tar.gz
mu.subx: first code-gen test passing!
Diffstat (limited to '069allocate.subx')
-rw-r--r--069allocate.subx32
1 files changed, 32 insertions, 0 deletions
diff --git a/069allocate.subx b/069allocate.subx
index 31afc4ff..b6433689 100644
--- a/069allocate.subx
+++ b/069allocate.subx
@@ -457,6 +457,38 @@ _pending-test-lookup-failure:
     5d/pop-to-ebp
     c3/return
 
+# when comparing handles, just treat them as pure values
+handle-equal?:  # a: handle, b: handle -> eax: boolean
+    # . prologue
+    55/push-ebp
+    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
+    # . save registers
+    51/push-ecx
+    # eax = false
+    b8/copy-to-eax  0/imm32/false
+$handle-equal?:compare-alloc-id:
+    # ecx = a->alloc_id
+    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   8/disp8         .                 # copy *(ebp+8) to ecx
+    # if (ecx != b->alloc_id) return false
+    39/compare                      1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0x10/disp8      .                 # compare ecx and *(ebp+16)
+    75/jump-if-!=  $handle-equal?:end/disp8
+$handle-equal?:compare-address:
+    # ecx = handle->address
+    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0xc/disp8       .                 # copy *(ebp+12) to ecx
+    # if (ecx != b->address) return false
+    39/compare                      1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0x14/disp8      .                 # compare ecx and *(ebp+20)
+    75/jump-if-!=  $handle-equal?:end/disp8
+$handle-equal?:return-true:
+    # return true
+    b8/copy-to-eax  1/imm32/true
+$handle-equal?:end:
+    # . restore registers
+    59/pop-to-ecx
+    # . epilogue
+    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
+    5d/pop-to-ebp
+    c3/return
+
 # helper: create a nested allocation descriptor (useful for tests)
 allocate-region:  # ad: (addr allocation-descriptor), n: int, out: (addr handle allocation-descriptor)
     # . prologue