Compare commits

...

2 commits

8 changed files with 33 additions and 18 deletions

View file

@ -69,9 +69,13 @@ let rec cps_term_inner (t: S.term) (cont: T.variable) (nameHint: string option)
let curCont = freshBlockVar () in
letCont curCont var (cps_term_inner next cont None) @@
cps_term_inner value curCont (Some (Atom.hint var))
| S.IfZero _ ->
(* TODO ifzero *)
assert false
| S.IfZero (expr, tIf, tElse) ->
let curCont = freshBlockVar ()
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 =
(** Entry point. Transforms a [Lambda] term into a [Tail] term, applying a

View file

@ -86,9 +86,10 @@ let rec walk_term fs t =
T.Branch(thisTag, freeVars, nBody) in
let fs = add_func fs arity thisFunc in
fs, T.LetBlo (var, T.Con(thisTag, T.vvars freeVars), nNext)
| S.IfZero _ ->
(* TODO ifzero *)
assert false
| S.IfZero (value, tIf, tElse) ->
let fs, tIf = walk_term fs tIf in
let fs, tElse = walk_term fs tElse in
fs, T.IfZero(value, tIf, tElse)
let apply_of_arity name args branches =

View file

@ -228,9 +228,12 @@ let rec finish_term (t : S.term) : C.stmt =
init_block x b1 @
[ finish_term t2 ]
)
| S.IfZero _ ->
(* TODO ifzero *)
assert false
| S.IfZero (expr, tIf, tElse) ->
T.IfElse (
T.Op2(T.K.Eq, to_int @@ finish_value expr,
T.Constant(T.K.Int32, "0")),
finish_term tIf,
finish_term tElse)
| S.Swi (v, bs) ->
T.Switch (
read_tag v,

View file

@ -131,6 +131,7 @@ and fv_term (t : term) =
union
(fv_block b1)
(remove x (fv_term t2))
| IfZero _ ->
(* TODO ifzero *)
assert false
| IfZero (cond, tIf, tElse) ->
union
(fv_value cond)
(union (fv_term tIf) (fv_term tElse))

View file

@ -21,9 +21,11 @@ and fmt_term fmt (t: S.term) = match t with
| S.LetBlo (var, block, next) ->
Format.fprintf fmt "@[<v 4>let %a = %a@] in@ %a"
fmt_var var fmt_block block fmt_term next
| S.IfZero _ ->
(* TODO ifzero *)
assert false
| S.IfZero (cond, tIf, tElse) ->
Format.fprintf fmt "@[<v 4>ifzero %a then@ %a@]@ @[<v 4>else@ %a@]@ "
fmt_val cond
fmt_term tIf
fmt_term tElse
let show term =
Format.asprintf "@[<v 0>%a@]" fmt_term term

View file

@ -28,9 +28,11 @@ let rec fmt_term fmt (term: S.term) = match term with
fmt_var name
fmt_block block
fmt_term next
| S.IfZero _ ->
(* TODO ifzero *)
assert false
| S.IfZero (cond, tIf, tElse) ->
Format.fprintf fmt "@[<v 4>ifzero %a then@ %a@]@ @[<v 4>else@ %a@]"
fmt_val cond
fmt_term tIf
fmt_term tElse
| S.Swi (value, branches) ->
Format.fprintf fmt "@[<v 4>switch(%a)" fmt_val value ;
List.iter

1
src/tests/simple_if.exp Normal file
View file

@ -0,0 +1 @@
1

View file

@ -0,0 +1 @@
ifzero 42 then print 0 else print 1