about summary refs log tree commit diff stats
path: root/apps/mu.subx
diff options
context:
space:
mode:
Diffstat (limited to 'apps/mu.subx')
-rw-r--r--apps/mu.subx24
1 files changed, 21 insertions, 3 deletions
diff --git a/apps/mu.subx b/apps/mu.subx
index b2ab76e1..ca4dc4b0 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -2580,7 +2580,7 @@ parse-type:  # ad: (address allocation-descriptor), in: (addr stream byte) -> re
     #   result = allocate(Tree)
     #   zero-out(result, *Tree-size)
     #   if s != "("
-    #     result->left = pos-slice(Type-id, s)
+    #     result->left = pos-or-insert-slice(Type-id, s)
     #     return
     #   result->left = parse-type(ad, in)
     #   result->right = parse-type-tree(ad, in)
@@ -2631,8 +2631,8 @@ parse-type:  # ad: (address allocation-descriptor), in: (addr stream byte) -> re
       (slice-equal? %ecx "(")
       3d/compare-eax-and 0/imm32/false
       75/jump-if-!= break/disp8
-      # result->left = pos-slice(Type-id, s)
-      (pos-slice Type-id %ecx)
+      # result->left = pos-or-insert-slice(Type-id, s)
+      (pos-or-insert-slice Type-id %ecx)
 #?       (write-buffered Stderr "=> {")
 #?       (print-int32-buffered Stderr %eax)
 #?       (write-buffered Stderr ", 0}\n")
@@ -2891,6 +2891,24 @@ $next-mu-token:end:
     5d/pop-to-ebp
     c3/return
 
+pos-or-insert-slice:  # arr: (addr stream (handle array byte)), s: (addr slice) -> index/eax: int
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # if (pos-slice(arr, s) != -1) return it
+    (pos-slice *(ebp+8) *(ebp+0xc))  # => eax
+    3d/compare-eax-and -1/imm32
+    75/jump-if-not-equal $pos-or-insert-slice:end/disp8
+    #
+    (slice-to-string Heap *(ebp+0xc))  # => eax
+    (write-int *(ebp+8) %eax)
+    (pos-slice *(ebp+8) *(ebp+0xc))  # => eax
+$pos-or-insert-slice:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
 # return the index in an array of strings matching 's'
 # index is denominated in elements, not bytes
 pos-slice:  # arr: (addr stream (handle array byte)), s: (addr slice) -> index/eax: int