From 960e680db01537831d46c62448e8940e1abc4be8 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 18 Jun 2015 10:50:54 -0700 Subject: 1591 --- 037call_reply.cc | 17 +++++++++++++++++ 065duplex_list.mu | 46 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/037call_reply.cc b/037call_reply.cc index 0d277658..fa224216 100644 --- a/037call_reply.cc +++ b/037call_reply.cc @@ -135,3 +135,20 @@ if (curr.name == "reply-if") { curr.operation = Recipe_number["reply"]; curr.ingredients.swap(results); } +// rewrite `reply-unless a, b, c, ...` to +// ``` +// jump-if a, 1:offset +// reply b, c, ... +// ``` +if (curr.name == "reply-unless") { + assert(curr.products.empty()); + curr.operation = Recipe_number["jump-if"]; + vector results; + copy(++curr.ingredients.begin(), curr.ingredients.end(), inserter(results, results.end())); + curr.ingredients.resize(1); + curr.ingredients.push_back(reagent("1:offset")); + result.steps.push_back(curr); + curr.clear(); + curr.operation = Recipe_number["reply"]; + curr.ingredients.swap(results); +} diff --git a/065duplex_list.mu b/065duplex_list.mu index 8c5f6011..c33bce97 100644 --- a/065duplex_list.mu +++ b/065duplex_list.mu @@ -86,15 +86,17 @@ recipe insert-duplex [ # in.next = new-node 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 + # new-node.prev = in + 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 # new-node.next = next-node 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 + # if next-node is not null + reply-unless next-node:address:duplex-list, new-node:address:duplex-list # next-node.prev = new-node 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 - # new-node.prev = in - 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 reply new-node:address:duplex-list # just signalling something changed; don't rely on the result ] @@ -134,3 +136,41 @@ scenario inserting-into-duplex-list [ 10 <- 1 # list back at start ] ] + +scenario inserting-at-end-of-duplex-list [ + run [ + 1:address:duplex-list <- copy 0:literal # 1 points to head of list + 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 points inside list + 2:address:duplex-list <- next-duplex 2:address:duplex-list # now at end of list + 2:address:duplex-list <- insert-duplex 6:literal, 2:address:duplex-list + # check structure like before + 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 # scanning next + 4 <- 4 + 5 <- 3 + 6 <- 6 # inserted element + 7 <- 3 # then prev + 8 <- 4 + 9 <- 5 + 10 <- 1 # list back at start + ] +] -- cgit 1.4.1-2-gfad0