From 2961872f993bae36992ceaad754e8a35e8d0c249 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 30 Oct 2023 17:13:59 +0100 Subject: [PATCH] interpretation max (0/72 :))))) ) --- flap/src/hopix/hopixInterpreter.ml | 80 ++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 9 deletions(-) diff --git a/flap/src/hopix/hopixInterpreter.ml b/flap/src/hopix/hopixInterpreter.ml index faa02e8..d0f6ac2 100644 --- a/flap/src/hopix/hopixInterpreter.ml +++ b/flap/src/hopix/hopixInterpreter.ml @@ -343,13 +343,20 @@ and definition runtime d = and value_definition runtime = function | SimpleValue (id, _, expr) -> - (* TODO: Ici il faut associer l'ID et l'expression - * => Retourner l'environnement modifié *) - runtime - | RecFunctions rf -> - (* TODO: Ici faut ajouter les noms des fonctions à l'environnement + (* Ici on associe l'ID et l'expression + * => Retourne l'environnement modifié *) + let env' = + Environment.bind + runtime.environment + id.value + (expression' runtime.environment runtime.memory expr) + in + { runtime with environment = env' } + | RecFunctions _rf -> + (* Ici on ajoute les noms des fonctions à l'environnement * pour qu'elles puissent s'appeller dans leur corps de fonction - * => Il faut retourner un environnement modifié *) + * => Retourne l'environnement modifié *) + (* TODO *) runtime and expression' environment memory e = @@ -360,9 +367,64 @@ and expression' environment memory e = E, M ⊢ e ⇓ v, M' and E = [runtime.environment], M = [runtime.memory]. *) -and expression _ environment memory = - (* TODO *) - failwith "Students! This is your job!" +and expression _pos environment _memory = function + | Literal l -> literal_expression l.value + | Variable (id, _) -> + (* On cherche l'id dans l'environnement *) + Environment.lookup id.position id.value environment + | Tagged _ -> + (* TODO *) + failwith "Students! This is your job (Tagged)!" + | Record _ -> + (* TODO *) + failwith "Students! This is your job (Record)!" + | Field _ -> + (* TODO *) + failwith "Students! This is your job (Field)!" + | Tuple _ -> + (* TODO *) + failwith "Students! This is your job (Tuple)!" + | Sequence _ -> + (* TODO *) + failwith "Students! This is your job (Sequence)!" + | Define _ -> + (* TODO *) + failwith "Students! This is your job (Define)!" + | Fun _ -> + (* TODO *) + failwith "Students! This is your job (Fun)!" + | Apply _ -> + (* TODO *) + failwith "Students! This is your job (Apply)!" + | Ref _ -> + (* TODO *) + failwith "Students! This is your job (Ref)!" + | Assign _ -> + (* TODO *) + failwith "Students! This is your job (Assign)!" + | Read _ -> + (* TODO *) + failwith "Students! This is your job (Read)!" + | Case _ -> + (* TODO *) + failwith "Students! This is your job (Case)!" + | IfThenElse _ -> + (* TODO *) + failwith "Students! This is your job (IfThenElse)!" + | While _ -> + (* TODO *) + failwith "Students! This is your job (While)!" + | For _ -> + (* TODO *) + failwith "Students! This is your job (For)!" + | TypeAnnotation _ -> + (* On ignore le type car on interprète *) + VUnit + +and literal_expression = function + | LInt n -> VInt n + | LChar c -> VChar c + | LString s -> VString s (** This function returns the difference between two runtimes. *) and extract_observable runtime runtime' =