ajout Record/Sequence/Ref/Read/Tagged et début Apply

This commit is contained in:
Nicolas PENELOUX 2023-11-06 18:04:31 +01:00
parent 682b727dd2
commit e2d2c1c127

View file

@ -352,13 +352,24 @@ and value_definition runtime = function
(expression' runtime.environment runtime.memory expr)
in
{ runtime with environment = env' }
| RecFunctions _rf ->
(*
| RecFunctions _rf -> let env' = define_rec_functions environment _rf
in
{ runtime with environment = env' }
(* Ici on ajoute les noms des fonctions à l'environnement
* pour qu'elles puissent s'appeller dans leur corps de fonction
* => Retourne l'environnement modifié *)
(* TODO *)
runtime
(* TODO : commentaire explicatif *)
and define_rec_functions env _rf =
let environment = List.fold_left (fun env (id,_,_) ->
Environment.bind env (id.value) VUnit) env _rf (* En gros ici on bind toute les fonctions de l'env avec VUnit*)
in
*)
and expression' environment memory e =
expression (position e) environment memory (value e)
@ -372,12 +383,12 @@ and expression _pos environment _memory = function
| Variable (id, _) ->
(* On cherche l'id dans l'environnement *)
Environment.lookup id.position id.value environment
| Tagged _ ->
| Tagged(constructor,_,list_t) -> (* On ignore le type car on interprète *)
(* TODO *)
failwith "Students! This is your job (Tagged)!"
| Record _ ->
(* TODO *)
failwith "Students! This is your job (Record)!"
VTagged(constructor.value, List.map(expression' environment _memory) list_t)
| Record(label,list_r) -> failwith ("Todo corriger l'erreur de type")
(*TODO : réparer *)
(*VRecord(List.map(label.value, expression' environment _memory) list_r)*)
| Field _ ->
(* TODO *)
failwith "Students! This is your job (Field)!"
@ -385,28 +396,33 @@ and expression _pos environment _memory = function
(* Cas pour le Tuple vide
* Un tuple vide ne contient rien (logique), donc on utilise un VUnit*)
VUnit
(*Sinon, on associe pour chaque*)
| Tuple list_exp -> VTuple (List.map (expression' environment _memory) list_exp)
| Sequence _ ->
(* TODO *)
failwith "Students! This is your job (Sequence)!"
| Sequence(list_exp) -> failwith ("Todo corriger l'erreur")
(*List.map(expression' environment _memory) list_exp *)
| Define _ ->
(* TODO *)
failwith "Students! This is your job (Define)!"
| Fun _ ->
(* TODO *)
failwith "Students! This is your job (Fun)!"
| Apply _ ->
| Apply(a,b) -> apply_values a b environment _memory
(* TODO *)
failwith "Students! This is your job (Apply)!"
| Ref ref ->
let dref = expression' environment _memory ref in
VLocation (Memory.allocate _memory Mint.one dref)
let reference = expression' environment _memory ref in (* On créé un VLocation et on alloue de la mémoire pour la valeur de la référence*)
VLocation (Memory.allocate _memory Mint.one reference)
| Assign _ ->
(* TODO *)
failwith "Students! This is your job (Assign)!"
| Read _ ->
(* TODO *)
failwith "Students! This is your job (Read)!"
| Read read ->
let loc = value_as_location (expression' environment _memory read) in
(match loc with
| Some (adr) -> Memory.read (Memory.dereference _memory adr) (Mint.zero) (* On lis la valeur de la mémoire*)
| None -> failwith "erreur") (* TODO : faire une vrai erreur *)
| Case _ ->
(* TODO *)
failwith "Students! This is your job (Case)!"
@ -422,6 +438,16 @@ and expression _pos environment _memory = function
| TypeAnnotation _ ->
(* On ignore le type car on interprète *)
VUnit
and apply_values a b env mem =
let nom_indetermine = expression' env mem b in
match expression' env mem a with
(*| VPrimitive(_,f) -> f mem nom_indetermine*)
(*TODO A FINIR *)
| VClosure(env',pattern,expr') -> failwith "Students ! The project is so boring !"
and literal_expression = function
| LInt n -> VInt n