Add IfZero in the syntax + placeholders

Also add (* TODO ifzero *) all around as placeholders
This commit is contained in:
Théophile Bastian 2018-02-16 00:19:44 +01:00
parent b00976d359
commit 7bc7921fc3
10 changed files with 25 additions and 1 deletions

View File

@ -30,7 +30,7 @@ let rec cps_value (t: S.term) : T.value = match t with
| S.Var v -> T.VVar v
| S.Lit v -> T.VLit v
| 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 =
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
letCont curCont var (cps_term_inner next cont None) @@
cps_term_inner value curCont (Some (Atom.hint var))
| S.IfZero _ ->
(* TODO ifzero *)
assert false
let cps_term (t: S.term): T.term =
(** Entry point. Transforms a [Lambda] term into a [Tail] term, applying a

View File

@ -49,6 +49,8 @@ let rec cook_term env { S.place; S.value } =
T.Let (f, T.Lam (T.Self f, x, t1), t2)
| S.Let (S.Recursive, _, { S.place; _ }, _) ->
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 =
cook_term Env.empty t

View File

@ -86,6 +86,9 @@ 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
let apply_of_arity name args branches =

View File

@ -228,6 +228,9 @@ let rec finish_term (t : S.term) : C.stmt =
init_block x b1 @
[ finish_term t2 ]
)
| S.IfZero _ ->
(* TODO ifzero *)
assert false
| S.Swi (v, bs) ->
T.Switch (
read_tag v,

View File

@ -44,5 +44,6 @@ and term =
| BinOp of term * binop * term
| Print of term
| Let of variable * term * term
| IfZero of term * term * term
[@@deriving show { with_path = false }]

View File

@ -30,6 +30,7 @@ and term_ =
| BinOp of term * binop * term
| Print of 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,
that is, a position in the source code. This allows us to produce a good

View File

@ -73,6 +73,7 @@ and term =
| Print of value * term
| LetVal of variable * value * term
| LetBlo of variable * block * term
| IfZero of value * term * term
[@@deriving show { with_path = false }]
@ -130,3 +131,6 @@ and fv_term (t : term) =
union
(fv_block b1)
(remove x (fv_term t2))
| IfZero _ ->
(* TODO ifzero *)
assert false

View File

@ -40,6 +40,7 @@ and term =
| Print of value * term
| LetVal of variable * value * term
| LetBlo of variable * block * term
| IfZero of value * term * term
| Swi of value * branch list
(* A branch [tag xs -> t] is labeled with an integer tag [tag], and is

View File

@ -21,6 +21,9 @@ 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
let show term =
Format.asprintf "@[<v 0>%a@]" fmt_term term

View File

@ -28,6 +28,9 @@ 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.Swi (value, branches) ->
Format.fprintf fmt "@[<v 4>switch(%a)" fmt_val value ;
List.iter