From 34cffe16617b0c8951799e06668abf3ec4dcab7f Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 15 Dec 2023 13:41:12 +0100 Subject: [PATCH] ew :( --- flap/src/fopix/hobixToFopix.ml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/flap/src/fopix/hobixToFopix.ml b/flap/src/fopix/hobixToFopix.ml index 765647f..7789adc 100644 --- a/flap/src/fopix/hobixToFopix.ml +++ b/flap/src/fopix/hobixToFopix.ml @@ -120,9 +120,9 @@ let free_variables = | [ s ] -> f s | s :: xs -> M.union (f s) (unions f xs) in - (*Une variable libre est une variable qui peut être substitué*) + (* Une variable libre est une variable qui peut être substitué *) - (*TODO : rajouter des explications pour While Define et Fun*) + (* TODO : rajouter des explications pour While Define et Fun *) let rec fvs = function | S.Literal _ -> M.empty | S.Variable x -> M.singleton x @@ -204,7 +204,8 @@ let translate (p : S.t) env = | S.RecFunctions fdefs -> let fs, defs = define_recursive_functions fdefs in fs @ List.map (fun (x, e) -> T.DefineValue (x, e)) defs - and define_recursive_functions rdefs = failwith "Students! This is your job!" + and define_recursive_functions rdefs = + failwith "Students! This is your job (define_recursive_functions)!" and expression env = function | S.Literal l -> [], T.Literal (literal l) | S.While (cond, e) -> @@ -218,14 +219,20 @@ let translate (p : S.t) env = | Some e -> e in [], xc - | S.Define (vdef, a) -> failwith "Students! This is your job!" - | S.Apply (a, bs) -> failwith "Students! This is your job!" + | S.Define (vdef, a) -> + let afs, a = expression env a in + (match vdef with + | S.SimpleValue (id, b) -> + let bfs, b = expression env b in + afs @ bfs, T.Define (identifier id, a, b) + | S.RecFunctions _ -> failwith "Students! This is your job (S.RecFunctions)!") + | S.Apply (a, bs) -> failwith "Students! This is your job (S.Apply)!" | S.IfThenElse (a, b, c) -> let afs, a = expression env a in let bfs, b = expression env b in let cfs, c = expression env c in afs @ bfs @ cfs, T.IfThenElse (a, b, c) - | S.Fun (x, e) -> failwith "Students! This is your job!" + | S.Fun (x, e) -> failwith "Students! This is your job (S.Fun)!" | S.AllocateBlock a -> let afs, a = expression env a in afs, allocate_block a