From d149e5d1e78ff8c85953313e1e98891ade979a85 Mon Sep 17 00:00:00 2001 From: Nicolas PENELOUX Date: Thu, 9 Nov 2023 22:38:50 +0100 Subject: [PATCH] =?UTF-8?q?d=C3=A9but=20pattern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flap/src/hopix/hopixInterpreter.ml | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/flap/src/hopix/hopixInterpreter.ml b/flap/src/hopix/hopixInterpreter.ml index 1a2147a..49c4006 100644 --- a/flap/src/hopix/hopixInterpreter.ml +++ b/flap/src/hopix/hopixInterpreter.ml @@ -541,11 +541,14 @@ and apply_expression f x environment memory = | VPrimitive (_, f) -> (* Fonction "primitive" *) f memory x_val - | VClosure (_env_fn, _pattern, _expr) -> - (* - let pattern _env_fn (value pattern) x_val with + | VClosure (_env_fn, _pattern, _expr) ->(* + + let pat = pattern _env_fn (value pattern) x_val in (*Pattern va nous calculer un nouvelle environnement*) + match pat with + | Some(env') -> expression' env' memory expression + | None -> failwith ("erreur")*) (* Fonction - * TODO: Pattern matching ici *)*) + * TODO: Pattern matching ici *) failwith "Students! This is your job (Apply)!" | _ -> assert false (* By typing *) @@ -554,14 +557,29 @@ and literal_expression = function | LChar c -> VChar c | LString s -> VString s + + (*TODO : à la place des TODO, mettre des autres fonctions pour calculer chaque cas*) + (* and pattern environment pattern expression = match pattern, expression with | PLiteral pl, _ -> literal_pattern pl | PWildcard, _ -> environment - | PTypeAnnotation(new_pattern,_), _ -> pattern environment new_pattern expression + | PVariable var,_ -> Environment.bind environment var.value expression + | PTypeAnnotation(new_pattern,_), _ -> pattern (environment new_pattern expression) + | PTaggedValue(cons,_,new_pattern),_ -> (*Erreur ?*)failwith "erreur" + | PTaggedValue(cons,_,new_pattern),VTagged(cons2,new_pattern2) -> (* TODO *)failwith "erreur" + | PRecord(r,_), _ -> (* Erreur ?*) failwith "erreur" + | PRecord(r,_),VRecord(r2) -> (*TODO*)failwith "erreur" + | PTuple(tab),_ -> (* Erreur ?*)failwith "erreur" + | PTuple(tab),VTuple(tab2) -> (*TODO*)failwith "erreur" + (* TODO POr et PAnd en vrai j'ai une idée mais la fatigue me rattrape + Je l'écris si jamais quelqu'un d'autre à part moi lis ceci + L'idée est de regarde pour POr si dans la liste de pattern, il y a au moins un élément qui match expression + PAreil pour And donc mais tout dois match*) -and litteral_pattern pl = + +and literal_pattern pl = match pl with | LInt n -> VInt n | LChar c -> VChar c