This commit is contained in:
Mylloon 2023-12-15 13:41:12 +01:00
parent edb1219070
commit 34cffe1661
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -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