about summary refs log tree commit diff stats
path: root/sandbox/012-editor-undo.mu
Commit message (Expand)AuthorAgeFilesLines
* 4262 - literal 'null'Kartik Agaram2018-06-171-1/+1
* 4261 - start using literals for 'true' and 'false'Kartik Agaram2018-06-171-2/+2
* 4134 - 'input' = 'ingredient'Kartik K. Agaram2017-12-031-1/+1
* 3980Kartik K. Agaram2017-08-221-14/+14
* 3879Kartik K. Agaram2017-05-261-3/+3
* 3700Kartik K. Agaram2016-11-281-2/+2
* 3699Kartik K. Agaram2016-11-281-3/+2
* 3698Kartik K. Agaram2016-11-271-24/+24
* 3552Kartik K. Agaram2016-10-221-4/+4
* 3489Kartik K. Agaram2016-10-081-59/+59
* 3457Kartik K. Agaram2016-10-061-59/+59
* 3445Kartik K. Agaram2016-10-061-107/+107
* 3429 - standardize Mu scenariosKartik K. Agaram2016-09-281-245/+258
* 3396Kartik K. Agaram2016-09-171-223/+223
* 3391 - type abbreviations everywhereKartik K. Agaram2016-09-171-359/+359
* 3337 - first use of type abbreviations: textKartik K. Agaram2016-09-121-48/+48
* 2983 - migrate buttons over to sandbox/Kartik K. Agaram2016-05-191-0/+1895
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 065duplex_list.mu</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="none">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 1.05em; }
.muScenario { color: #00af00; }
.Delimiter { color: #a04060; }
.CommentedCode { color: #6c6c6c; }
.Comment { color: #9090ff; }
.Constant { color: #00a0a0; }
.Special { color: #ff6060; }
.muControl { color: #c0a020; }
.muRecipe { color: #ff8700; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment"># A doubly linked list permits bidirectional traversal.</span>

container duplex-list [
  value:location
  next:address:duplex-list
  prev:address:duplex-list
]

<span class="Comment"># result:address:duplex-list &lt;- push-duplex x:location, in:address:duplex-list</span>
<span class="muRecipe">recipe</span> push-duplex [
  <span class="Constant">local-scope</span>
  x:location<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  in:address:duplex-list<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  result:address:duplex-list<span class="Special"> &lt;- </span>new duplex-list:type
  val:address:location<span class="Special"> &lt;- </span>get-address result:address:duplex-list/deref, value:offset
  val:address:location/deref<span class="Special"> &lt;- </span>copy x:location
  next:address:address:duplex-list<span class="Special"> &lt;- </span>get-address result:address:duplex-list/deref, next:offset
  next:address:address:duplex-list/deref<span class="Special"> &lt;- </span>copy in:address:duplex-list
  <span class="muControl">reply-unless</span> in:address:duplex-list, result:address:duplex-list
  prev:address:address:duplex-list<span class="Special"> &lt;- </span>get-address in:address:duplex-list/deref, prev:offset
  prev:address:address:duplex-list/deref<span class="Special"> &lt;- </span>copy result:address:duplex-list
  <span class="muControl">reply</span> result:address:duplex-list
]

<span class="Comment"># result:location &lt;- first-duplex in:address:duplex-list</span>
<span class="muRecipe">recipe</span> first-duplex [
  <span class="Constant">local-scope</span>
  in:address:duplex-list<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="muControl">reply-unless</span> in:address:duplex-list, <span class="Constant">0:literal</span>
  result:location<span class="Special"> &lt;- </span>get in:address:duplex-list/deref, value:offset
  <span class="muControl">reply</span> result:location
]

<span class="Comment"># result:address:duplex-list &lt;- next-duplex in:address:duplex-list</span>
<span class="muRecipe">recipe</span> next-duplex [
  <span class="Constant">local-scope</span>
  in:address:duplex-list<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="muControl">reply-unless</span> in:address:duplex-list, <span class="Constant">0:literal</span>
  result:address:duplex-list<span class="Special"> &lt;- </span>get in:address:duplex-list/deref, next:offset
  <span class="muControl">reply</span> result:address:duplex-list
]

<span class="Comment"># result:address:duplex-list &lt;- prev-duplex in:address:duplex-list</span>
<span class="muRecipe">recipe</span> prev-duplex [
  <span class="Constant">local-scope</span>
  in:address:duplex-list<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="muControl">reply-unless</span> in:address:duplex-list, <span class="Constant">0:literal</span>
  result:address:duplex-list<span class="Special"> &lt;- </span>get in:address:duplex-list/deref, prev:offset
  <span class="muControl">reply</span> result:address:duplex-list
]

<span class="muScenario">scenario</span> duplex-list-handling [
  run [
    <span class="Comment"># reserve locations 0, 1 and 2 to check for missing null check</span>
    1:number<span class="Special"> &lt;- </span>copy <span class="Constant">34:literal</span>
    2:number<span class="Special"> &lt;- </span>copy <span class="Constant">35:literal</span>
    3:address:duplex-list<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
    3:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">3:literal</span>, 3:address:duplex-list
    3:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">4:literal</span>, 3:address:duplex-list
    3:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">5:literal</span>, 3:address:duplex-list
    4:address:duplex-list<span class="Special"> &lt;- </span>copy 3:address:duplex-list
    5:number<span class="Special"> &lt;- </span>first 4:address:duplex-list
    4:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 4:address:duplex-list
    6:number<span class="Special"> &lt;- </span>first 4:address:duplex-list
    4:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 4:address:duplex-list
    7:number<span class="Special"> &lt;- </span>first 4:address:duplex-list
    8:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 4:address:duplex-list
    9:number<span class="Special"> &lt;- </span>first 8:address:duplex-list
    10:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 8:address:duplex-list
    11:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 8:address:duplex-list
    4:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 4:address:duplex-list
    12:number<span class="Special"> &lt;- </span>first 4:address:duplex-list
    4:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 4:address:duplex-list
    13:number<span class="Special"> &lt;- </span>first 4:address:duplex-list
    14:boolean<span class="Special"> &lt;- </span>equal 3:address:duplex-list, 4:address:duplex-list
<span class="CommentedCode">#?     $dump-trace #? 1</span>
  ]
  memory-should-contain [
    0<span class="Special"> &lt;- </span>0  <span class="Comment"># no modifications to null pointers</span>
    1<span class="Special"> &lt;- </span>34
    2<span class="Special"> &lt;- </span>35
    5<span class="Special"> &lt;- </span>5  <span class="Comment"># scanning next</span>
    6<span class="Special"> &lt;- </span>4
    7<span class="Special"> &lt;- </span>3
    8<span class="Special"> &lt;- </span>0  <span class="Comment"># null</span>
    9<span class="Special"> &lt;- </span>0  <span class="Comment"># first of null</span>
    10<span class="Special"> &lt;- </span>0  <span class="Comment"># next of null</span>
    11<span class="Special"> &lt;- </span>0  <span class="Comment"># prev of null</span>
    12<span class="Special"> &lt;- </span>4  <span class="Comment"># then start scanning prev</span>
    13<span class="Special"> &lt;- </span>5
    14<span class="Special"> &lt;- </span>1  <span class="Comment"># list back at start</span>
  ]
]

<span class="Comment"># l:address:duplex-list &lt;- insert-duplex x:location, in:address:duplex-list</span>
<span class="Comment"># Inserts 'x' after 'in'. Returns some pointer into the list.</span>
<span class="muRecipe">recipe</span> insert-duplex [
  <span class="Constant">local-scope</span>
  x:location<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  in:address:duplex-list<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  new-node:address:duplex-list<span class="Special"> &lt;- </span>new duplex-list:type
  val:address:location<span class="Special"> &lt;- </span>get-address new-node:address:duplex-list/deref, value:offset
  val:address:location/deref<span class="Special"> &lt;- </span>copy x:location
  next-node:address:duplex-list<span class="Special"> &lt;- </span>get in:address:duplex-list/deref, next:offset
  <span class="Comment"># in.next = new-node</span>
  y:address:address:duplex-list<span class="Special"> &lt;- </span>get-address in:address:duplex-list/deref, next:offset
  y:address:address:duplex-list/deref<span class="Special"> &lt;- </span>copy new-node:address:duplex-list
  <span class="Comment"># new-node.prev = in</span>
  y:address:address:duplex-list<span class="Special"> &lt;- </span>get-address new-node:address:duplex-list/deref, prev:offset
  y:address:address:duplex-list/deref<span class="Special"> &lt;- </span>copy in:address:duplex-list
  <span class="Comment"># new-node.next = next-node</span>
  y:address:address:duplex-list<span class="Special"> &lt;- </span>get-address new-node:address:duplex-list/deref, next:offset
  y:address:address:duplex-list/deref<span class="Special"> &lt;- </span>copy next-node:address:duplex-list
  <span class="Comment"># if next-node is not null</span>
  <span class="muControl">reply-unless</span> next-node:address:duplex-list, new-node:address:duplex-list
  <span class="Comment"># next-node.prev = new-node</span>
  y:address:address:duplex-list<span class="Special"> &lt;- </span>get-address next-node:address:duplex-list/deref, prev:offset
  y:address:address:duplex-list/deref<span class="Special"> &lt;- </span>copy new-node:address:duplex-list
  <span class="muControl">reply</span> new-node:address:duplex-list  <span class="Comment"># just signalling something changed; don't rely on the result</span>
]

<span class="muScenario">scenario</span> inserting-into-duplex-list [
  run [
    1:address:duplex-list<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>  <span class="Comment"># 1 points to head of list</span>
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">3:literal</span>, 1:address:duplex-list
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">4:literal</span>, 1:address:duplex-list
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">5:literal</span>, 1:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 1:address:duplex-list  <span class="Comment"># 2 points inside list</span>
    2:address:duplex-list<span class="Special"> &lt;- </span>insert-duplex <span class="Constant">6:literal</span>, 2:address:duplex-list
    <span class="Comment"># check structure like before</span>
    2:address:duplex-list<span class="Special"> &lt;- </span>copy 1:address:duplex-list
    3:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    4:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    5:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    6:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 2:address:duplex-list
    7:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 2:address:duplex-list
    8:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 2:address:duplex-list
    9:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    10:boolean<span class="Special"> &lt;- </span>equal 1:address:duplex-list, 2:address:duplex-list
  ]
  memory-should-contain [
    3<span class="Special"> &lt;- </span>5  <span class="Comment"># scanning next</span>
    4<span class="Special"> &lt;- </span>4
    5<span class="Special"> &lt;- </span>6  <span class="Comment"># inserted element</span>
    6<span class="Special"> &lt;- </span>3
    7<span class="Special"> &lt;- </span>6  <span class="Comment"># then prev</span>
    8<span class="Special"> &lt;- </span>4
    9<span class="Special"> &lt;- </span>5
    10<span class="Special"> &lt;- </span>1  <span class="Comment"># list back at start</span>
  ]
]

<span class="muScenario">scenario</span> inserting-at-end-of-duplex-list [
  run [
    1:address:duplex-list<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>  <span class="Comment"># 1 points to head of list</span>
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">3:literal</span>, 1:address:duplex-list
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">4:literal</span>, 1:address:duplex-list
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">5:literal</span>, 1:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 1:address:duplex-list  <span class="Comment"># 2 points inside list</span>
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list  <span class="Comment"># now at end of list</span>
    2:address:duplex-list<span class="Special"> &lt;- </span>insert-duplex <span class="Constant">6:literal</span>, 2:address:duplex-list
    <span class="Comment"># check structure like before</span>
    2:address:duplex-list<span class="Special"> &lt;- </span>copy 1:address:duplex-list
    3:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    4:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    5:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    6:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 2:address:duplex-list
    7:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 2:address:duplex-list
    8:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 2:address:duplex-list
    9:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    10:boolean<span class="Special"> &lt;- </span>equal 1:address:duplex-list, 2:address:duplex-list
  ]
  memory-should-contain [
    3<span class="Special"> &lt;- </span>5  <span class="Comment"># scanning next</span>
    4<span class="Special"> &lt;- </span>4
    5<span class="Special"> &lt;- </span>3
    6<span class="Special"> &lt;- </span>6  <span class="Comment"># inserted element</span>
    7<span class="Special"> &lt;- </span>3  <span class="Comment"># then prev</span>
    8<span class="Special"> &lt;- </span>4
    9<span class="Special"> &lt;- </span>5
    10<span class="Special"> &lt;- </span>1  <span class="Comment"># list back at start</span>
  ]
]

<span class="muScenario">scenario</span> inserting-after-start-of-duplex-list [
  run [
    1:address:duplex-list<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>  <span class="Comment"># 1 points to head of list</span>
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">3:literal</span>, 1:address:duplex-list
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">4:literal</span>, 1:address:duplex-list
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">5:literal</span>, 1:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>insert-duplex <span class="Constant">6:literal</span>, 1:address:duplex-list
    <span class="Comment"># check structure like before</span>
    2:address:duplex-list<span class="Special"> &lt;- </span>copy 1:address:duplex-list
    3:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    4:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    5:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    6:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 2:address:duplex-list
    7:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 2:address:duplex-list
    8:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 2:address:duplex-list
    9:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    10:boolean<span class="Special"> &lt;- </span>equal 1:address:duplex-list, 2:address:duplex-list
  ]
  memory-should-contain [
    3<span class="Special"> &lt;- </span>5  <span class="Comment"># scanning next</span>
    4<span class="Special"> &lt;- </span>6  <span class="Comment"># inserted element</span>
    5<span class="Special"> &lt;- </span>4
    6<span class="Special"> &lt;- </span>3
    7<span class="Special"> &lt;- </span>4  <span class="Comment"># then prev</span>
    8<span class="Special"> &lt;- </span>6
    9<span class="Special"> &lt;- </span>5
    10<span class="Special"> &lt;- </span>1  <span class="Comment"># list back at start</span>
  ]
]

<span class="Comment"># l:address:duplex-list &lt;- remove-duplex in:address:duplex-list</span>
<span class="Comment"># Removes 'in' from its surrounding list. Returns some valid pointer into the</span>
<span class="Comment"># rest of the list.</span>
<span class="Comment">#</span>
<span class="Comment"># Returns null if and only if list is empty. Beware: in that case any pointers</span>
<span class="Comment"># to the head are now invalid.</span>
<span class="muRecipe">recipe</span> remove-duplex [
  <span class="Constant">local-scope</span>
  in:address:duplex-list<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># if 'in' is null, return</span>
  <span class="muControl">reply-unless</span> in:address:duplex-list, in:address:duplex-list
  next-node:address:duplex-list<span class="Special"> &lt;- </span>get in:address:duplex-list/deref, next:offset
  prev-node:address:duplex-list<span class="Special"> &lt;- </span>get in:address:duplex-list/deref, prev:offset
  <span class="Comment"># null in's pointers</span>
  x:address:address:duplex-list<span class="Special"> &lt;- </span>get-address in:address:duplex-list/deref, next:offset
  x:address:address:duplex-list/deref<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
  x:address:address:duplex-list<span class="Special"> &lt;- </span>get-address in:address:duplex-list/deref, prev:offset
  x:address:address:duplex-list/deref<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># if next-node is not null</span>
    <span class="muControl">break-unless</span> next-node:address:duplex-list
    <span class="Comment"># next-node.prev = prev-node</span>
    x:address:address:duplex-list<span class="Special"> &lt;- </span>get-address next-node:address:duplex-list/deref, prev:offset
    x:address:address:duplex-list/deref<span class="Special"> &lt;- </span>copy prev-node:address:duplex-list
  <span class="Delimiter">}</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># if prev-node is not null</span>
    <span class="muControl">break-unless</span> prev-node:address:duplex-list
    <span class="Comment"># prev-node.next = next-node</span>
    x:address:address:duplex-list<span class="Special"> &lt;- </span>get-address prev-node:address:duplex-list/deref, next:offset
    x:address:address:duplex-list/deref<span class="Special"> &lt;- </span>copy next-node:address:duplex-list
    <span class="muControl">reply</span> prev-node:address:duplex-list
  <span class="Delimiter">}</span>
  <span class="muControl">reply</span> next-node:address:duplex-list
]

<span class="muScenario">scenario</span> removing-from-duplex-list [
  run [
    1:address:duplex-list<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>  <span class="Comment"># 1 points to head of list</span>
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">3:literal</span>, 1:address:duplex-list
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">4:literal</span>, 1:address:duplex-list
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">5:literal</span>, 1:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 1:address:duplex-list  <span class="Comment"># 2 points at second element</span>
    2:address:duplex-list<span class="Special"> &lt;- </span>remove-duplex 2:address:duplex-list
    3:boolean<span class="Special"> &lt;- </span>equal 2:address:duplex-list, <span class="Constant">0:literal</span>
    <span class="Comment"># check structure like before</span>
    2:address:duplex-list<span class="Special"> &lt;- </span>copy 1:address:duplex-list
    4:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    5:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    6:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 2:address:duplex-list
    7:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    8:boolean<span class="Special"> &lt;- </span>equal 1:address:duplex-list, 2:address:duplex-list
  ]
  memory-should-contain [
    3<span class="Special"> &lt;- </span>0  <span class="Comment"># remove returned non-null</span>
    4<span class="Special"> &lt;- </span>5  <span class="Comment"># scanning next, skipping deleted element</span>
    5<span class="Special"> &lt;- </span>3
    6<span class="Special"> &lt;- </span>0  <span class="Comment"># no more elements</span>
    7<span class="Special"> &lt;- </span>5  <span class="Comment"># prev of final element</span>
    8<span class="Special"> &lt;- </span>1  <span class="Comment"># list back at start</span>
  ]
]

<span class="muScenario">scenario</span> removing-from-start-of-duplex-list [
  run [
    1:address:duplex-list<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>  <span class="Comment"># 1 points to head of list</span>
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">3:literal</span>, 1:address:duplex-list
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">4:literal</span>, 1:address:duplex-list
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">5:literal</span>, 1:address:duplex-list
    <span class="Comment"># removing from head? return value matters.</span>
    1:address:duplex-list<span class="Special"> &lt;- </span>remove-duplex 1:address:duplex-list
    <span class="Comment"># check structure like before</span>
    2:address:duplex-list<span class="Special"> &lt;- </span>copy 1:address:duplex-list
    3:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    4:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    5:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 2:address:duplex-list
    6:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    7:boolean<span class="Special"> &lt;- </span>equal 1:address:duplex-list, 2:address:duplex-list
  ]
  memory-should-contain [
    3<span class="Special"> &lt;- </span>4  <span class="Comment"># scanning next, skipping deleted element</span>
    4<span class="Special"> &lt;- </span>3
    5<span class="Special"> &lt;- </span>0  <span class="Comment"># no more elements</span>
    6<span class="Special"> &lt;- </span>4  <span class="Comment"># prev of final element</span>
    7<span class="Special"> &lt;- </span>1  <span class="Comment"># list back at start</span>
  ]
]

<span class="muScenario">scenario</span> removing-from-end-of-duplex-list [
  run [
    1:address:duplex-list<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>  <span class="Comment"># 1 points to head of list</span>
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">3:literal</span>, 1:address:duplex-list
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">4:literal</span>, 1:address:duplex-list
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">5:literal</span>, 1:address:duplex-list
    <span class="Comment"># delete last element</span>
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 1:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>remove-duplex 2:address:duplex-list
    3:boolean<span class="Special"> &lt;- </span>equal 2:address:duplex-list, <span class="Constant">0:literal</span>
    <span class="Comment"># check structure like before</span>
    2:address:duplex-list<span class="Special"> &lt;- </span>copy 1:address:duplex-list
    4:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    5:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    6:address:duplex-list<span class="Special"> &lt;- </span>next-duplex 2:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>prev-duplex 2:address:duplex-list
    7:number<span class="Special"> &lt;- </span>first 2:address:duplex-list
    8:boolean<span class="Special"> &lt;- </span>equal 1:address:duplex-list, 2:address:duplex-list
  ]
  memory-should-contain [
    3<span class="Special"> &lt;- </span>0  <span class="Comment"># remove returned non-null</span>
    4<span class="Special"> &lt;- </span>5  <span class="Comment"># scanning next, skipping deleted element</span>
    5<span class="Special"> &lt;- </span>4
    6<span class="Special"> &lt;- </span>0  <span class="Comment"># no more elements</span>
    7<span class="Special"> &lt;- </span>5  <span class="Comment"># prev of final element</span>
    8<span class="Special"> &lt;- </span>1  <span class="Comment"># list back at start</span>
  ]
]

<span class="muScenario">scenario</span> removing-from-singleton-list [
  run [
    1:address:duplex-list<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>  <span class="Comment"># 1 points to singleton list</span>
    1:address:duplex-list<span class="Special"> &lt;- </span>push-duplex <span class="Constant">3:literal</span>, 1:address:duplex-list
    2:address:duplex-list<span class="Special"> &lt;- </span>remove-duplex 1:address:duplex-list
    3:address:duplex-list<span class="Special"> &lt;- </span>get 1:address:duplex-list/deref, next:offset
    4:address:duplex-list<span class="Special"> &lt;- </span>get 1:address:duplex-list/deref, prev:offset
  ]
  memory-should-contain [
    2<span class="Special"> &lt;- </span>0  <span class="Comment"># remove returned null</span>
    3<span class="Special"> &lt;- </span>0  <span class="Comment"># removed node is also detached</span>
    4<span class="Special"> &lt;- </span>0
  ]
]
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->