ajout Record/Sequence/Ref/Read/Tagged et début Apply
This commit is contained in:
parent
682b727dd2
commit
e2d2c1c127
1 changed files with 41 additions and 15 deletions
|
@ -352,13 +352,24 @@ and value_definition runtime = function
|
||||||
(expression' runtime.environment runtime.memory expr)
|
(expression' runtime.environment runtime.memory expr)
|
||||||
in
|
in
|
||||||
{ runtime with environment = env' }
|
{ 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
|
(* Ici on ajoute les noms des fonctions à l'environnement
|
||||||
* pour qu'elles puissent s'appeller dans leur corps de fonction
|
* pour qu'elles puissent s'appeller dans leur corps de fonction
|
||||||
* => Retourne l'environnement modifié *)
|
* => Retourne l'environnement modifié *)
|
||||||
(* TODO *)
|
(* TODO *)
|
||||||
runtime
|
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 =
|
and expression' environment memory e =
|
||||||
expression (position e) environment memory (value e)
|
expression (position e) environment memory (value e)
|
||||||
|
|
||||||
|
@ -372,12 +383,12 @@ and expression _pos environment _memory = function
|
||||||
| Variable (id, _) ->
|
| Variable (id, _) ->
|
||||||
(* On cherche l'id dans l'environnement *)
|
(* On cherche l'id dans l'environnement *)
|
||||||
Environment.lookup id.position id.value environment
|
Environment.lookup id.position id.value environment
|
||||||
| Tagged _ ->
|
| Tagged(constructor,_,list_t) -> (* On ignore le type car on interprète *)
|
||||||
(* TODO *)
|
(* TODO *)
|
||||||
failwith "Students! This is your job (Tagged)!"
|
VTagged(constructor.value, List.map(expression' environment _memory) list_t)
|
||||||
| Record _ ->
|
| Record(label,list_r) -> failwith ("Todo corriger l'erreur de type")
|
||||||
(* TODO *)
|
(*TODO : réparer *)
|
||||||
failwith "Students! This is your job (Record)!"
|
(*VRecord(List.map(label.value, expression' environment _memory) list_r)*)
|
||||||
| Field _ ->
|
| Field _ ->
|
||||||
(* TODO *)
|
(* TODO *)
|
||||||
failwith "Students! This is your job (Field)!"
|
failwith "Students! This is your job (Field)!"
|
||||||
|
@ -385,28 +396,33 @@ and expression _pos environment _memory = function
|
||||||
(* Cas pour le Tuple vide
|
(* Cas pour le Tuple vide
|
||||||
* Un tuple vide ne contient rien (logique), donc on utilise un VUnit*)
|
* Un tuple vide ne contient rien (logique), donc on utilise un VUnit*)
|
||||||
VUnit
|
VUnit
|
||||||
|
(*Sinon, on associe pour chaque*)
|
||||||
| Tuple list_exp -> VTuple (List.map (expression' environment _memory) list_exp)
|
| 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 _ ->
|
| Define _ ->
|
||||||
(* TODO *)
|
(* TODO *)
|
||||||
failwith "Students! This is your job (Define)!"
|
failwith "Students! This is your job (Define)!"
|
||||||
| Fun _ ->
|
| Fun _ ->
|
||||||
(* TODO *)
|
(* TODO *)
|
||||||
failwith "Students! This is your job (Fun)!"
|
failwith "Students! This is your job (Fun)!"
|
||||||
| Apply _ ->
|
| Apply(a,b) -> apply_values a b environment _memory
|
||||||
(* TODO *)
|
(* TODO *)
|
||||||
failwith "Students! This is your job (Apply)!"
|
failwith "Students! This is your job (Apply)!"
|
||||||
| Ref ref ->
|
| Ref ref ->
|
||||||
let dref = expression' environment _memory ref in
|
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 dref)
|
VLocation (Memory.allocate _memory Mint.one reference)
|
||||||
| Assign _ ->
|
| Assign _ ->
|
||||||
(* TODO *)
|
(* TODO *)
|
||||||
failwith "Students! This is your job (Assign)!"
|
failwith "Students! This is your job (Assign)!"
|
||||||
| Read _ ->
|
| Read read ->
|
||||||
(* TODO *)
|
let loc = value_as_location (expression' environment _memory read) in
|
||||||
failwith "Students! This is your job (Read)!"
|
(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 _ ->
|
| Case _ ->
|
||||||
(* TODO *)
|
(* TODO *)
|
||||||
failwith "Students! This is your job (Case)!"
|
failwith "Students! This is your job (Case)!"
|
||||||
|
@ -422,6 +438,16 @@ and expression _pos environment _memory = function
|
||||||
| TypeAnnotation _ ->
|
| TypeAnnotation _ ->
|
||||||
(* On ignore le type car on interprète *)
|
(* On ignore le type car on interprète *)
|
||||||
VUnit
|
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
|
and literal_expression = function
|
||||||
| LInt n -> VInt n
|
| LInt n -> VInt n
|
||||||
|
|
Reference in a new issue