about summary refs log tree commit diff stats
path: root/100array-equal.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-04-03 12:35:53 -0700
committerKartik Agaram <vc@akkartik.com>2020-04-03 12:35:53 -0700
commitbfcc0f858aa324739ad645e2056d73a47ab66f82 (patch)
tree24a22e364b2c1d535013c604b7a9620a31606e71 /100array-equal.subx
parentf730f2f2c7934f52091a848b71f9031ea99e2377 (diff)
downloadmu-bfcc0f858aa324739ad645e2056d73a47ab66f82.tar.gz
6182 - start of support for safe handles
So far it's unclear how to do this in a series of small commits. Still
nibbling around the edges. In this commit we standardize some terminology:

The length of an array or stream is denominated in the high-level elements.
The _size_ is denominated in bytes.

The thing we encode into the type is always the size, not the length.

There's still an open question of what to do about the Mu `length` operator.
I'd like to modify it to provide the length. Currently it provides the
size. If I can't fix that I'll rename it.
Diffstat (limited to '100array-equal.subx')
-rw-r--r--100array-equal.subx28
1 files changed, 14 insertions, 14 deletions
diff --git a/100array-equal.subx b/100array-equal.subx
index ca222619..e1449279 100644
--- a/100array-equal.subx
+++ b/100array-equal.subx
@@ -4,12 +4,12 @@
 
 array-equal?:  # a: (addr array int), b: (addr array int) -> eax: boolean
     # pseudocode:
-    #   lena = a->length
-    #   if (lena != b->length) return false
+    #   asize = a->size
+    #   if (asize != b->size) return false
     #   i = 0
     #   curra = a->data
     #   currb = b->data
-    #   while i < lena
+    #   while i < asize
     #     i1 = *curra
     #     i2 = *currb
     #     if (c1 != c2) return false
@@ -18,7 +18,7 @@ array-equal?:  # a: (addr array int), b: (addr array int) -> eax: boolean
     #
     # registers:
     #   i: ecx
-    #   lena: edx
+    #   asize: edx
     #   curra: esi
     #   currb: edi
     #   i1: eax
@@ -37,10 +37,10 @@ array-equal?:  # a: (addr array int), b: (addr array int) -> eax: boolean
     8b/-> *(ebp+8) 6/r32/esi
     # edi = b
     8b/-> *(ebp+0xc) 7/r32/edi
-    # var lena/edx: int = a->length
+    # var asize/edx: int = a->size
     8b/-> *esi 2/r32/edx
-$array-equal?:lengths:
-    # if (lena != b->length) return false
+$array-equal?:sizes:
+    # if (asize != b->size) return false
     39/compare *edi 2/r32/edx
     75/jump-if-!= $array-equal?:false/disp8
     # var curra/esi: (addr byte) = a->data
@@ -52,7 +52,7 @@ $array-equal?:lengths:
     # var vala/eax: int
     # var valb/ebx: int
 $array-equal?:loop:
-    # if (i >= lena) return true
+    # if (i >= asize) return true
     39/compare %ecx 2/r32/edx
     7d/jump-if->= $array-equal?:true/disp8
     # var vala/eax: int = *curra
@@ -104,7 +104,7 @@ test-compare-empty-with-empty-array:
     5d/pop-to-ebp
     c3/return
 
-test-compare-empty-with-non-empty-array:  # also checks length-mismatch code path
+test-compare-empty-with-non-empty-array:  # also checks size-mismatch code path
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
@@ -147,7 +147,7 @@ test-compare-equal-arrays:
     5d/pop-to-ebp
     c3/return
 
-test-compare-inequal-arrays-equal-lengths:
+test-compare-inequal-arrays-equal-sizes:
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
@@ -165,7 +165,7 @@ test-compare-inequal-arrays-equal-lengths:
     89/<- %edx 4/r32/esp
     #
     (array-equal? %ecx %edx)  # => eax
-    (check-ints-equal %eax 0 "F - test-compare-inequal-arrays-equal-lengths")
+    (check-ints-equal %eax 0 "F - test-compare-inequal-arrays-equal-sizes")
     # . epilogue
     89/<- %esp 5/r32/ebp
     5d/pop-to-ebp
@@ -173,7 +173,7 @@ test-compare-inequal-arrays-equal-lengths:
 
 parse-array-of-ints:  # ad: (addr allocation-descriptor), s: (addr string) -> result/eax: (handle array int)
     # pseudocode
-    #   end = &s->data[s->length]
+    #   end = &s->data[s->size]
     #   curr = s->data
     #   size = 0
     #   while true
@@ -209,8 +209,8 @@ parse-array-of-ints:  # ad: (addr allocation-descriptor), s: (addr string) -> re
     8b/-> *(ebp+0xc) 6/r32/esi
     # var curr/ecx: (addr byte) = s->data
     8d/copy-address *(esi+4) 1/r32/ecx
-    # var end/edx: (addr byte) = &s->data[s->length]
-    # . edx = s->length
+    # var end/edx: (addr byte) = &s->data[s->size]
+    # . edx = s->size
     8b/-> *esi 2/r32/edx
     # . edx += curr
     01/add-to %edx 1/r32/ecx