Implement IfZero everywhere, untested
This commit is contained in:
parent
2a65d41cd8
commit
3141ce6fde
6 changed files with 30 additions and 18 deletions
10
src/CPS.ml
10
src/CPS.ml
|
@ -69,9 +69,13 @@ let rec cps_term_inner (t: S.term) (cont: T.variable) (nameHint: string option)
|
||||||
let curCont = freshBlockVar () in
|
let curCont = freshBlockVar () in
|
||||||
letCont curCont var (cps_term_inner next cont None) @@
|
letCont curCont var (cps_term_inner next cont None) @@
|
||||||
cps_term_inner value curCont (Some (Atom.hint var))
|
cps_term_inner value curCont (Some (Atom.hint var))
|
||||||
| S.IfZero _ ->
|
| S.IfZero (expr, tIf, tElse) ->
|
||||||
(* TODO ifzero *)
|
let curCont = freshBlockVar ()
|
||||||
assert false
|
and exprVal = freshVar () in
|
||||||
|
letCont curCont exprVal (T.IfZero(T.vvar exprVal,
|
||||||
|
cps_term_inner tIf cont None,
|
||||||
|
cps_term_inner tElse cont None)) @@
|
||||||
|
cps_term_inner expr curCont None
|
||||||
|
|
||||||
let cps_term (t: S.term): T.term =
|
let cps_term (t: S.term): T.term =
|
||||||
(** Entry point. Transforms a [Lambda] term into a [Tail] term, applying a
|
(** Entry point. Transforms a [Lambda] term into a [Tail] term, applying a
|
||||||
|
|
|
@ -86,9 +86,10 @@ let rec walk_term fs t =
|
||||||
T.Branch(thisTag, freeVars, nBody) in
|
T.Branch(thisTag, freeVars, nBody) in
|
||||||
let fs = add_func fs arity thisFunc in
|
let fs = add_func fs arity thisFunc in
|
||||||
fs, T.LetBlo (var, T.Con(thisTag, T.vvars freeVars), nNext)
|
fs, T.LetBlo (var, T.Con(thisTag, T.vvars freeVars), nNext)
|
||||||
| S.IfZero _ ->
|
| S.IfZero (value, tIf, tElse) ->
|
||||||
(* TODO ifzero *)
|
let fs, tIf = walk_term fs tIf in
|
||||||
assert false
|
let fs, tElse = walk_term fs tElse in
|
||||||
|
fs, T.IfZero(value, tIf, tElse)
|
||||||
|
|
||||||
|
|
||||||
let apply_of_arity name args branches =
|
let apply_of_arity name args branches =
|
||||||
|
|
|
@ -228,9 +228,11 @@ let rec finish_term (t : S.term) : C.stmt =
|
||||||
init_block x b1 @
|
init_block x b1 @
|
||||||
[ finish_term t2 ]
|
[ finish_term t2 ]
|
||||||
)
|
)
|
||||||
| S.IfZero _ ->
|
| S.IfZero (expr, tIf, tElse) ->
|
||||||
(* TODO ifzero *)
|
T.IfElse (
|
||||||
assert false
|
finish_value expr,
|
||||||
|
finish_term tIf,
|
||||||
|
finish_term tElse)
|
||||||
| S.Swi (v, bs) ->
|
| S.Swi (v, bs) ->
|
||||||
T.Switch (
|
T.Switch (
|
||||||
read_tag v,
|
read_tag v,
|
||||||
|
|
|
@ -131,6 +131,7 @@ and fv_term (t : term) =
|
||||||
union
|
union
|
||||||
(fv_block b1)
|
(fv_block b1)
|
||||||
(remove x (fv_term t2))
|
(remove x (fv_term t2))
|
||||||
| IfZero _ ->
|
| IfZero (cond, tIf, tElse) ->
|
||||||
(* TODO ifzero *)
|
union
|
||||||
assert false
|
(fv_value cond)
|
||||||
|
(union (fv_term tIf) (fv_term tElse))
|
||||||
|
|
|
@ -21,9 +21,11 @@ and fmt_term fmt (t: S.term) = match t with
|
||||||
| S.LetBlo (var, block, next) ->
|
| S.LetBlo (var, block, next) ->
|
||||||
Format.fprintf fmt "@[<v 4>let %a = %a@] in@ %a"
|
Format.fprintf fmt "@[<v 4>let %a = %a@] in@ %a"
|
||||||
fmt_var var fmt_block block fmt_term next
|
fmt_var var fmt_block block fmt_term next
|
||||||
| S.IfZero _ ->
|
| S.IfZero (cond, tIf, tElse) ->
|
||||||
(* TODO ifzero *)
|
Format.fprintf fmt "@[<v 4>ifzero %a then@ %a@]@ @[<v 4>else@ %a@]@ "
|
||||||
assert false
|
fmt_val cond
|
||||||
|
fmt_term tIf
|
||||||
|
fmt_term tElse
|
||||||
|
|
||||||
let show term =
|
let show term =
|
||||||
Format.asprintf "@[<v 0>%a@]" fmt_term term
|
Format.asprintf "@[<v 0>%a@]" fmt_term term
|
||||||
|
|
|
@ -28,9 +28,11 @@ let rec fmt_term fmt (term: S.term) = match term with
|
||||||
fmt_var name
|
fmt_var name
|
||||||
fmt_block block
|
fmt_block block
|
||||||
fmt_term next
|
fmt_term next
|
||||||
| S.IfZero _ ->
|
| S.IfZero (cond, tIf, tElse) ->
|
||||||
(* TODO ifzero *)
|
Format.fprintf fmt "@[<v 4>ifzero %a then@ %a@]@ @[<v 4>else@ %a@]"
|
||||||
assert false
|
fmt_val cond
|
||||||
|
fmt_term tIf
|
||||||
|
fmt_term tElse
|
||||||
| S.Swi (value, branches) ->
|
| S.Swi (value, branches) ->
|
||||||
Format.fprintf fmt "@[<v 4>switch(%a)" fmt_val value ;
|
Format.fprintf fmt "@[<v 4>switch(%a)" fmt_val value ;
|
||||||
List.iter
|
List.iter
|
||||||
|
|
Loading…
Reference in a new issue