Commit 634b779a authored by Guy Watson's avatar Guy Watson
Browse files

Add conditional branches

parent 088decd9
...@@ -36,6 +36,11 @@ ...@@ -36,6 +36,11 @@
[targetindex]) ;; a number depth [targetindex]) ;; a number depth
;; todo: the type of val should be unified with the target node ;; todo: the type of val should be unified with the target node
#:prop choice-weight 50] #:prop choice-weight 50]
[BranchIf Expr ([cond : Expr]
[val : Expr]
[targetnode]
[targetindex])
#:prop choice-weight 50]
) )
;; Define structured control instruction property ;; Define structured control instruction property
...@@ -125,7 +130,9 @@ ...@@ -125,7 +130,9 @@
wasm-like wasm-like
fresh fresh
[Branch (match-let ([(cons index node) (choose-br-target (current-hole))]) [Branch (match-let ([(cons index node) (choose-br-target (current-hole))])
(hash 'targetindex index 'targetnode node))]) (hash 'targetindex index 'targetnode node))]
[BranchIf (match-let ([(cons index node) (choose-br-target (current-hole))])
(hash 'targetindex index 'targetnode node))])
(add-att-rule (add-att-rule
wasm-like wasm-like
...@@ -164,6 +171,8 @@ ...@@ -164,6 +171,8 @@
'then int 'then int
'else int))]] 'else int))]]
[Branch [int (λ (n t) (hash 'val int))]] [Branch [int (λ (n t) (hash 'val int))]]
[BranchIf [int (λ (n t) (hash 'cond int
'val int))]]
) )
(add-prop (add-prop
...@@ -200,6 +209,12 @@ ...@@ -200,6 +209,12 @@
(append (append
(render-node (ast-child 'val n)) (render-node (ast-child 'val n))
`(br ,(ast-child 'targetindex n))))] `(br ,(ast-child 'targetindex n))))]
[BranchIf (λ (n)
(append
(render-node (ast-child 'val n))
(render-node (ast-child 'cond n))
`(br_if ,(ast-child 'targetindex n))))]
) )
(add-prop (add-prop
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment