container duplex-list [
value:location
next:address:duplex-list
prev:address:duplex-list
]
recipe push-duplex [
local-scope
x:location <- next-ingredient
in:address:duplex-list <- next-ingredient
result:address:duplex-list <- new duplex-list:type
val:address:location <- get-address result:address:duplex-list/deref, value:offset
val:address:location/deref <- copy x:location
next:address:address:duplex-list <- get-address result:address:duplex-list/deref, next:offset
next:address:address:duplex-list/deref <- copy in:address:duplex-list
reply-unless in:address:duplex-list, result:address:duplex-list
prev:address:address:duplex-list <- get-address in:address:duplex-list/deref, prev:offset
prev:address:address:duplex-list/deref <- copy result:address:duplex-list
reply result:address:duplex-list
]
recipe first-duplex [
local-scope
in:address:duplex-list <- next-ingredient
reply-unless in:address:duplex-list, 0:literal
result:location <- get in:address:duplex-list/deref, value:offset
reply result:location
]
recipe next-duplex [
local-scope
in:address:duplex-list <- next-ingredient
reply-unless in:address:duplex-list, 0:literal
result:address:duplex-list <- get in:address:duplex-list/deref, next:offset
reply result:address:duplex-list
]
recipe prev-duplex [
local-scope
in:address:duplex-list <- next-ingredient
reply-unless in:address:duplex-list, 0:literal
result:address:duplex-list <- get in:address:duplex-list/deref, prev:offset
reply result:address:duplex-list
]
scenario duplex-list-handling [
run [
1:number <- copy 34:literal
2:number <- copy 35:literal
3:address:duplex-list <- copy 0:literal
3:address:duplex-list <- push-duplex 3:literal, 3:address:duplex-list
3:address:duplex-list <- push-duplex 4:literal, 3:address:duplex-list
3:address:duplex-list <- push-duplex 5:literal, 3:address:duplex-list
4:address:duplex-list <- copy 3:address:duplex-list
5:number <- first 4:address:duplex-list
4:address:duplex-list <- next-duplex 4:address:duplex-list
6:number <- first 4:address:duplex-list
4:address:duplex-list <- next-duplex 4:address:duplex-list
7:number <- first 4:address:duplex-list
8:address:duplex-list <- next-duplex 4:address:duplex-list
9:number <- first 8:address:duplex-list
10:address:duplex-list <- next-duplex 8:address:duplex-list
11:address:duplex-list <- prev-duplex 8:address:duplex-list
4:address:duplex-list <- prev-duplex 4:address:duplex-list
12:number <- first 4:address:duplex-list
4:address:duplex-list <- prev-duplex 4:address:duplex-list
13:number <- first 4:address:duplex-list
14:boolean <- equal 3:address:duplex-list, 4:address:duplex-list
]
memory-should-contain [
0 <- 0
1 <- 34
2 <- 35
5 <- 5
6 <- 4
7 <- 3
8 <- 0
9 <- 0
10 <- 0
11 <- 0
12 <- 4
13 <- 5
14 <- 1
]
]
recipe insert-duplex [
local-scope
x:location <- next-ingredient
in:address:duplex-list <- next-ingredient
new-node:address:duplex-list <- new duplex-list:type
val:address:location <- get-address new-node:address:duplex-list/deref, value:offset
val:address:location/deref <- copy x:location
next-node:address:duplex-list <- get in:address:duplex-list/deref, next:offset
y:address:address:duplex-list <- get-address in:address:duplex-list/deref, next:offset
y:address:address:duplex-list/deref <- copy new-node:address:duplex-list
y:address:address:duplex-list <- get-address new-node:address:duplex-list/deref, prev:offset
y:address:address:duplex-list/deref <- copy in:address:duplex-list
y:address:address:duplex-list <- get-address new-node:address:duplex-list/deref, next:offset
y:address:address:duplex-list/deref <- copy next-node:address:duplex-list
reply-unless next-node:address:duplex-list, new-node:address:duplex-list
y:address:address:duplex-list <- get-address next-node:address:duplex-list/deref, prev:offset
y:address:address:duplex-list/deref <- copy new-node:address:duplex-list
reply new-node:address:duplex-list
]
scenario inserting-into-duplex-list [
run [
1:address:duplex-list <- copy 0:literal
1:address:duplex-list <- push-duplex 3:literal, 1:address:duplex-list
1:address:duplex-list <- push-duplex 4:literal, 1:address:duplex-list
1:address:duplex-list <- push-duplex 5:literal, 1:address:duplex-list
2:address:duplex-list <- next-duplex 1:address:duplex-list
2:address:duplex-list <- insert-duplex 6:literal, 2:address:duplex-list
2:address:duplex-list <- copy 1:address:duplex-list
3:number <- first 2:address:duplex-list
2:address:duplex-list <- next-duplex 2:address:duplex-list
4:number <- first 2:address:duplex-list
2:address:duplex-list <- next-duplex 2:address:duplex-list
5:number <- first 2:address:duplex-list
2:address:duplex-list <- next-duplex 2:address:duplex-list
6:number <- first 2:address:duplex-list
2:address:duplex-list <- prev-duplex 2:address:duplex-list
7:number <- first 2:address:duplex-list
2:address:duplex-list <- prev-duplex 2:address:duplex-list
8:number <- first 2:address:duplex-list
2:address:duplex-list <- prev-duplex 2:address:duplex-list
9:number <- first 2:address:duplex-list
10:boolean <- equal 1:address:duplex-list, 2:address:duplex-list
]
memory-should-contain [
3 <- 5
4 <- 4
5 <- 6
6 <- 3
7 <- 6
8 <- 4
9 <- 5
10 <- 1
]
]
scenario inserting-at-end-of-duplex-list [
run [
1:address:duplex-list <- copy 0:literal
1:address:duplex-list <- push-duplex 3:literal, 1:address:duplex-list
1:address:duplex-list <- push-duplex 4:literal, 1:address:duplex-list
1:address:duplex-list <- push-duplex 5:literal, 1:address:duplex-list
2:address:duplex-list <- next-duplex 1:address:duplex-list
2:address:duplex-list <- next-duplex 2:address:duplex-list
2:address:duplex-list <- insert-duplex 6:literal, 2:address:duplex-list
2:address:duplex-list <- copy 1:address:duplex-list
3:number <- first 2:address:duplex-list
2:address:duplex-list <- next-duplex 2:address:duplex-list
4:number <- first 2:address:duplex-list
2:address:duplex-list <- next-duplex 2:address:duplex-list
5:number <- first 2:address:duplex-list
2:address:duplex-list <- next-duplex 2:address:duplex-list
6:number <- first 2:address:duplex-list
2:address:duplex-list <- prev-duplex 2:address:duplex-list
7:number <- first 2:address:duplex-list
2:address:duplex-list <- prev-duplex 2:address:duplex-list
8:number <- first 2:address:duplex-list
2:address:duplex-list <- prev-duplex 2:address:duplex-list
9:number <- first 2:address:duplex-list
10:boolean <- equal 1:address:duplex-list, 2:address:duplex-list
]
memory-should-contain [
3 <- 5
4 <- 4
5 <- 3
6 <- 6
7 <- 3
8 <- 4
9 <- 5
10 <- 1
]
]
scenario inserting-after-start-of-duplex-list [
run [
1:address:duplex-list <- copy 0:literal
1:address:duplex-list <- push-duplex 3:literal, 1:address:duplex-list
1:address:duplex-list <- push-duplex 4:literal, 1:address:duplex-list
1:address:duplex-list <- push-duplex 5:literal, 1:address:duplex-list
2:address:duplex-list <- insert-duplex 6:literal, 1:address:duplex-list
2:address:duplex-list <- copy 1:address:duplex-list
3:number <- first 2:address:duplex-list
2:address:duplex-list <- next-duplex 2:address:duplex-list
4:number <- first 2:address:duplex-list
2:address:duplex-list <- next-duplex 2:address:duplex-list
5:number <- first 2:address:duplex-list
2:address:duplex-list <- next-duplex 2:address:duplex-list
6:number <- first 2:address:duplex-list
2:address:duplex-list <- prev-duplex 2:address:duplex-list
7:number <- first 2:address:duplex-list
2:address:duplex-list <- prev-duplex 2:address:duplex-list
8:number <- first 2:address:duplex-list
2:address:duplex-list <- prev-duplex 2:address:duplex-list
9:number <- first 2:address:duplex-list
10:boolean <- equal 1:address:duplex-list, 2:address:duplex-list
]
memory-should-contain [
3 <- 5
4 <- 6
5 <- 4
6 <- 3
7 <- 4
8 <- 6
9 <- 5
10 <- 1
]
]
recipe remove-duplex [
local-scope
in:address:duplex-list <- next-ingredient
reply-unless in:address:duplex-list, in:address:duplex-list
next-node:address:duplex-list <- get in:address:duplex-list/deref, next:offset
prev-node:address:duplex-list <- get in:address:duplex-list/deref, prev:offset
x:address:address:duplex-list <- get-address in:address:duplex-list/deref, next:offset
x:address:address:duplex-list/deref <- copy 0:literal
x:address:address:duplex-list <- get-address in:address:duplex-list/deref, prev:offset
x:address:address:duplex-list/deref <- copy 0:literal
{
break-unless next-node:address:duplex-list
x:address:address:duplex-list <- get-address next-node:address:duplex-list/deref, prev:offset
x:address:address:duplex-list/deref <- copy prev-node:address:duplex-list
}
{
break-unless prev-node:address:duplex-list
x:address:address:duplex-list <- get-address prev-node:address:duplex-list/deref, next:offset
x:address:address:duplex-list/deref <- copy next-node:address:duplex-list
reply prev-node:address:duplex-list
}
reply next-node:address:duplex-list
]
scenario removing-from-duplex-list [
run [
1:address:duplex-list <- copy 0:literal
1:address:duplex-list <- push-duplex 3:literal, 1:address:duplex-list
1:address:duplex-list <- push-duplex 4:literal, 1:address:duplex-list
1:address:duplex-list <- push-duplex 5:literal, 1:address:duplex-list
2:address:duplex-list <- next-duplex 1:address:duplex-list
2:address:duplex-list <- remove-duplex 2:address:duplex-list
3:boolean <- equal 2:address:duplex-list, 0:literal
2:address:duplex-list <- copy 1:address:duplex-list
4:number <- first 2:address:duplex-list
2:address:duplex-list <- next-duplex 2:address:duplex-list
5:number <- first 2:address:duplex-list
6:address:duplex-list <- next-duplex 2:address:duplex-list
2:address:duplex-list <- prev-duplex 2:address:duplex-list
7:number <- first 2:address:duplex-list
8:boolean <- equal 1:address:duplex-list, 2:address:duplex-list
]
memory-should-contain [
3 <- 0
4 <- 5
5 <- 3
6 <- 0
7 <- 5
8 <- 1
]
]
scenario removing-from-start-of-duplex-list [
run [
1:address:duplex-list <- copy 0:literal
1:address:duplex-list <- push-duplex 3:literal, 1:address:duplex-list
1:address:duplex-list <- push-duplex 4:literal, 1:address:duplex-list
1:address:duplex-list <- push-duplex 5:literal, 1:address:duplex-list
1:address:duplex-list <- remove-duplex 1:address:duplex-list
2:address:duplex-list <- copy 1:address:duplex-list
3:number <- first 2:address:duplex-list
2:address:duplex-list <- next-duplex 2:address:duplex-list
4:number <- first 2:address:duplex-list
5:address:duplex-list <- next-duplex 2:address:duplex-list
2:address:duplex-list <- prev-duplex 2:address:duplex-list
6:number <- first 2:address:duplex-list
7:boolean <- equal 1:address:duplex-list, 2:address:duplex-list
]
memory-should-contain [
3 <- 4
4 <- 3
5 <- 0
6 <- 4
7 <- 1
]
]
scenario removing-from-end-of-duplex-list [
run [
1:address:duplex-list <- copy 0:literal
1:address:duplex-list <- push-duplex 3:literal, 1:address:duplex-list
1:address:duplex-list <- push-duplex 4:literal, 1:address:duplex-list
1:address:duplex-list <- push-duplex 5:literal, 1:address:duplex-list
2:address:duplex-list <- next-duplex 1:address:duplex-list
2:address:duplex-list <- next-duplex 2:address:duplex-list
2:address:duplex-list <- remove-duplex 2:address:duplex-list
3:boolean <- equal 2:address:duplex-list, 0:literal
2:address:duplex-list <- copy 1:address:duplex-list
4:number <- first 2:address:duplex-list
2:address:duplex-list <- next-duplex 2:address:duplex-list
5:number <- first 2:address:duplex-list
6:address:duplex-list <- next-duplex 2:address:duplex-list
2:address:duplex-list <- prev-duplex 2:address:duplex-list
7:number <- first 2:address:duplex-list
8:boolean <- equal 1:address:duplex-list, 2:address:duplex-list
]
memory-should-contain [
3 <- 0
4 <- 5
5 <- 4
6 <- 0
7 <- 5
8 <- 1
]
]
scenario removing-from-singleton-list [
run [
1:address:duplex-list <- copy 0:literal
1:address:duplex-list <- push-duplex 3:literal, 1:address:duplex-list
2:address:duplex-list <- remove-duplex 1:address:duplex-list
3:address:duplex-list <- get 1:address:duplex-list/deref, next:offset
4:address:duplex-list <- get 1:address:duplex-list/deref, prev:offset
]
memory-should-contain [
2 <- 0
3 <- 0
4 <- 0
]
]