diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-06-24 09:16:17 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-06-24 09:18:20 -0700 |
commit | 23d3a02226973f80188e84fa5dcedb14413c5b7f (patch) | |
tree | 3c73284cb795e74d78e53b72df470cafca4c70cf /065duplex_list.mu | |
parent | 377b00b045289a3fa8e88d4b2f129d797c687e2f (diff) | |
download | mu-23d3a02226973f80188e84fa5dcedb14413c5b7f.tar.gz |
4266 - space for alloc-id in heap allocations
This has taken me almost 6 weeks :(
Diffstat (limited to '065duplex_list.mu')
-rw-r--r-- | 065duplex_list.mu | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/065duplex_list.mu b/065duplex_list.mu index 7d369186..3a7de8f6 100644 --- a/065duplex_list.mu +++ b/065duplex_list.mu @@ -399,12 +399,17 @@ def remove-between start:&:duplex-list:_elem, end:&:duplex-list:_elem/contained- # start->next = end *next <- put *next, prev:offset, null *start <- put *start, next:offset, end - return-unless end + { + break-if end + stash [spliced:] next + return + } # end->prev->next = 0 # end->prev = start prev:&:duplex-list:_elem <- get *end, prev:offset assert prev, [malformed duplex list - 2] *prev <- put *prev, next:offset, null + stash [spliced:] next *end <- put *end, prev:offset, start ] @@ -437,6 +442,9 @@ scenario remove-range [ 12 <- 15 20 <- 0 ] + trace-should-contain [ + app: spliced: 16 <-> 17 <-> 18 + ] ] scenario remove-range-to-final [ @@ -472,6 +480,49 @@ scenario remove-range-to-final [ 12 <- 18 20 <- 0 # no more elements ] + trace-should-contain [ + app: spliced: 15 <-> 16 <-> 17 + ] +] + +scenario remove-range-to-penultimate [ + local-scope + # construct a duplex list with six elements [13, 14, 15, 16, 17, 18] + list:&:duplex-list:num <- push 18, null + list <- push 17, list + list <- push 16, list + list <- push 15, list + list <- push 14, list + list <- push 13, list + run [ + # delete 15 and 16 + # start pointer: to the second element + list2:&:duplex-list:num <- next list + # end pointer: to the last (sixth) element + end:&:duplex-list:num <- next list2 + end <- next end + end <- next end + remove-between list2, end + # now check the list + 10:num/raw <- get *list, value:offset + list <- next list + 11:num/raw <- get *list, value:offset + list <- next list + 12:num/raw <- get *list, value:offset + list <- next list + 13:num/raw <- get *list, value:offset + 20:&:duplex-list:num/raw <- next list + ] + memory-should-contain [ + 10 <- 13 + 11 <- 14 + 12 <- 17 + 13 <- 18 + 20 <- 0 # no more elements + ] + trace-should-contain [ + app: spliced: 15 <-> 16 + ] ] scenario remove-range-empty [ |