diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-05-15 23:00:16 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-05-15 23:00:16 -0700 |
commit | 87ef6a67a37ccb3e5e1568738631d9059f9d2019 (patch) | |
tree | 4ee3efacd6da31acb1f5f76b6e6f422250959c6f | |
parent | 5f06655c6a76989db28e3484444573a949c28c9f (diff) | |
download | mu-87ef6a67a37ccb3e5e1568738631d9059f9d2019.tar.gz |
1380 - list data structure
-rw-r--r-- | 063list.mu | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/063list.mu b/063list.mu new file mode 100644 index 00000000..00f36c7c --- /dev/null +++ b/063list.mu @@ -0,0 +1,55 @@ +container list [ + value:location + next:address:list +] + +# result:address:list <- push x:location, in:address:list +recipe push [ + default-space:address:array:location <- new location:type, 30:literal + x:location <- next-ingredient + in:address:list <- next-ingredient + result:address:list <- new list:type + val:address:location <- get-address result:address:list/deref, value:offset + val:address:location/deref <- copy x:location + next:address:address:list <- get-address result:address:list/deref, next:offset + next:address:address:list/deref <- copy in:address:list + reply result:address:list +] + +# result:location <- first in:address:list +recipe first [ + default-space:address:array:location <- new location:type, 30:literal + in:address:list <- next-ingredient + result:location <- get in:address:list/deref, value:offset + reply result:location +] + +# result:address:list <- rest in:address:list +recipe rest [ + default-space:address:array:location <- new location:type, 30:literal + in:address:list <- next-ingredient + result:address:list <- get in:address:list/deref, next:offset + reply result:address:list +] + +scenario list-handling [ + run [ +#? $start-tracing #? 1 + 1:address:list <- copy 0:literal + 1:address:list <- push 3:literal, 1:address:list + 1:address:list <- push 4:literal, 1:address:list + 1:address:list <- push 5:literal, 1:address:list + 2:number <- first 1:address:list + 1:address:list <- rest 1:address:list + 3:number <- first 1:address:list + 1:address:list <- rest 1:address:list + 4:number <- first 1:address:list + 1:address:list <- rest 1:address:list + ] + memory-should-contain [ + 1 <- 0 # empty to empty, dust to dust.. + 2 <- 5 + 3 <- 4 + 4 <- 3 + ] +] |