Add IfZero in the syntax + placeholders
Also add (* TODO ifzero *) all around as placeholders
This commit is contained in:
parent
b00976d359
commit
7bc7921fc3
|
@ -30,7 +30,7 @@ let rec cps_value (t: S.term) : T.value = match t with
|
||||||
| S.Var v -> T.VVar v
|
| S.Var v -> T.VVar v
|
||||||
| S.Lit v -> T.VLit v
|
| S.Lit v -> T.VLit v
|
||||||
| S.BinOp (l, op, r) -> T.VBinOp (cps_value l, op, cps_value r)
|
| S.BinOp (l, op, r) -> T.VBinOp (cps_value l, op, cps_value r)
|
||||||
| S.Let _ | S.Lam _ | S.App _ | S.Print _ -> raise NotValue
|
| S.Let _ | S.Lam _ | S.App _ | S.Print _ | S.IfZero _ -> raise NotValue
|
||||||
|
|
||||||
let cps_value_as_term (t: S.term) (cont: T.variable): T.term =
|
let cps_value_as_term (t: S.term) (cont: T.variable): T.term =
|
||||||
T.TailCall(T.vvar cont, [cps_value t])
|
T.TailCall(T.vvar cont, [cps_value t])
|
||||||
|
@ -69,6 +69,9 @@ 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 _ ->
|
||||||
|
(* TODO ifzero *)
|
||||||
|
assert false
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -49,6 +49,8 @@ let rec cook_term env { S.place; S.value } =
|
||||||
T.Let (f, T.Lam (T.Self f, x, t1), t2)
|
T.Let (f, T.Lam (T.Self f, x, t1), t2)
|
||||||
| S.Let (S.Recursive, _, { S.place; _ }, _) ->
|
| S.Let (S.Recursive, _, { S.place; _ }, _) ->
|
||||||
error place "the right-hand side of 'let rec' must be a lambda-abstraction"
|
error place "the right-hand side of 'let rec' must be a lambda-abstraction"
|
||||||
|
| S.IfZero (expr, tIf, tElse) ->
|
||||||
|
T.IfZero (cook_term env expr, cook_term env tIf, cook_term env tElse)
|
||||||
|
|
||||||
let cook_term t =
|
let cook_term t =
|
||||||
cook_term Env.empty t
|
cook_term Env.empty t
|
||||||
|
|
|
@ -86,6 +86,9 @@ 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 _ ->
|
||||||
|
(* TODO ifzero *)
|
||||||
|
assert false
|
||||||
|
|
||||||
|
|
||||||
let apply_of_arity name args branches =
|
let apply_of_arity name args branches =
|
||||||
|
|
|
@ -228,6 +228,9 @@ 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 _ ->
|
||||||
|
(* TODO ifzero *)
|
||||||
|
assert false
|
||||||
| S.Swi (v, bs) ->
|
| S.Swi (v, bs) ->
|
||||||
T.Switch (
|
T.Switch (
|
||||||
read_tag v,
|
read_tag v,
|
||||||
|
|
|
@ -44,5 +44,6 @@ and term =
|
||||||
| BinOp of term * binop * term
|
| BinOp of term * binop * term
|
||||||
| Print of term
|
| Print of term
|
||||||
| Let of variable * term * term
|
| Let of variable * term * term
|
||||||
|
| IfZero of term * term * term
|
||||||
|
|
||||||
[@@deriving show { with_path = false }]
|
[@@deriving show { with_path = false }]
|
||||||
|
|
|
@ -30,6 +30,7 @@ and term_ =
|
||||||
| BinOp of term * binop * term
|
| BinOp of term * binop * term
|
||||||
| Print of term
|
| Print of term
|
||||||
| Let of recursive * variable * term * term
|
| Let of recursive * variable * term * term
|
||||||
|
| IfZero of term * term * term
|
||||||
|
|
||||||
(* Every abstract syntax tree node of type [term] is annotated with a place,
|
(* Every abstract syntax tree node of type [term] is annotated with a place,
|
||||||
that is, a position in the source code. This allows us to produce a good
|
that is, a position in the source code. This allows us to produce a good
|
||||||
|
|
|
@ -73,6 +73,7 @@ and term =
|
||||||
| Print of value * term
|
| Print of value * term
|
||||||
| LetVal of variable * value * term
|
| LetVal of variable * value * term
|
||||||
| LetBlo of variable * block * term
|
| LetBlo of variable * block * term
|
||||||
|
| IfZero of value * term * term
|
||||||
|
|
||||||
[@@deriving show { with_path = false }]
|
[@@deriving show { with_path = false }]
|
||||||
|
|
||||||
|
@ -130,3 +131,6 @@ and fv_term (t : term) =
|
||||||
union
|
union
|
||||||
(fv_block b1)
|
(fv_block b1)
|
||||||
(remove x (fv_term t2))
|
(remove x (fv_term t2))
|
||||||
|
| IfZero _ ->
|
||||||
|
(* TODO ifzero *)
|
||||||
|
assert false
|
||||||
|
|
|
@ -40,6 +40,7 @@ and term =
|
||||||
| Print of value * term
|
| Print of value * term
|
||||||
| LetVal of variable * value * term
|
| LetVal of variable * value * term
|
||||||
| LetBlo of variable * block * term
|
| LetBlo of variable * block * term
|
||||||
|
| IfZero of value * term * term
|
||||||
| Swi of value * branch list
|
| Swi of value * branch list
|
||||||
|
|
||||||
(* A branch [tag xs -> t] is labeled with an integer tag [tag], and is
|
(* A branch [tag xs -> t] is labeled with an integer tag [tag], and is
|
||||||
|
|
|
@ -21,6 +21,9 @@ 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 _ ->
|
||||||
|
(* TODO ifzero *)
|
||||||
|
assert false
|
||||||
|
|
||||||
let show term =
|
let show term =
|
||||||
Format.asprintf "@[<v 0>%a@]" fmt_term term
|
Format.asprintf "@[<v 0>%a@]" fmt_term term
|
||||||
|
|
|
@ -28,6 +28,9 @@ 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 _ ->
|
||||||
|
(* TODO ifzero *)
|
||||||
|
assert false
|
||||||
| 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