From 9700dddcacfed9a8952ff30c775826c30ba943f4 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 28 Nov 2023 03:17:03 +0100 Subject: [PATCH] =?UTF-8?q?s=C3=A9pare=20les=20probl=C3=A8mes=20pour=20mie?= =?UTF-8?q?ux=20comprendre=20parce=20que=20l=C3=A0=20c'est=20un=20calvere?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit les types des fonctions sont pas là pour avoir un truc par défaut mais sont probablement pas définitif --- flap/src/hopix/hopixTypechecker.ml | 158 ++++++++++++++++++++++++----- 1 file changed, 133 insertions(+), 25 deletions(-) diff --git a/flap/src/hopix/hopixTypechecker.ml b/flap/src/hopix/hopixTypechecker.ml index bec91ab..adb8c2b 100644 --- a/flap/src/hopix/hopixTypechecker.ml +++ b/flap/src/hopix/hopixTypechecker.ml @@ -45,7 +45,120 @@ let check_type_scheme ;; let synth_literal : HopixAST.literal -> HopixTypes.aty = - fun l -> failwith "Students! This is your job! (synth_literal)" + fun l -> + match l with + | LInt _ -> HopixTypes.hint + | LChar _ -> HopixTypes.hchar + | LString _ -> HopixTypes.hstring + +and synth_pattern + : HopixTypes.typing_environment -> HopixAST.pattern Position.located + -> HopixTypes.aty * HopixTypes.typing_environment + = + fun env Position.{ value = p; position = pos } -> + failwith "Students! This is your job! (synth_pattern)" + +and synth_variable + : HopixTypes.typing_environment -> identifier Position.located + -> ty Position.located list option -> HopixTypes.aty + = + fun tenv i tx -> failwith "Students! This is your job! (synth_variable)" + +and synth_tagged + : HopixTypes.typing_environment -> constructor Position.located + -> ty Position.located list option -> expression Position.located list -> HopixTypes.aty + = + fun tenv cons tlist e_args_list -> failwith "Students! This is your job! (synth_tagged)" + +and synth_apply + : HopixTypes.typing_environment -> expression Position.located + -> expression Position.located -> HopixTypes.aty + = + fun tenv f x -> failwith "Students! This is your job! (synth_apply)" + +and synth_record + : HopixTypes.typing_environment + -> (label Position.located * expression Position.located) list + -> ty Position.located list option -> HopixTypes.aty + = + fun tenv field tlist -> failwith "Students! This is your job! (synth_record)" + +and synth_fun + : HopixTypes.typing_environment -> pattern Position.located + -> expression Position.located -> HopixTypes.aty + = + fun tenv pat expr -> failwith "Students! This is your job! (synth_fun)" + +and synth_tannot + : HopixTypes.typing_environment -> expression Position.located -> ty Position.located + -> HopixTypes.aty + = + fun tenv expr t -> + (* TODO : ici on ne peut pas synthesisé. cf Cours*) + failwith "Students! This is your job! (synth_tannot)" + +and synth_field + : HopixTypes.typing_environment -> expression Position.located + -> label Position.located -> ty Position.located list option -> HopixTypes.aty + = + fun tenv expr lbl tlist -> failwith "Students! This is your job! (synth_field)" + +and synth_tuple + : HopixTypes.typing_environment -> expression Position.located list -> HopixTypes.aty + = + fun tenv elist -> failwith "Students! This is your job! (synth_tuple)" + +and synth_sequence + : HopixTypes.typing_environment -> expression Position.located list -> HopixTypes.aty + = + fun tenv elist -> failwith "Students! This is your job! (synth_sequence)" + +and synth_define + : HopixTypes.typing_environment -> value_definition -> expression Position.located + -> HopixTypes.aty + = + fun tenv vdef expr -> failwith "Students! This is your job! (synth_define)" + +and synth_ref + : HopixTypes.typing_environment -> expression Position.located -> HopixTypes.aty + = + fun tenv expr -> failwith "Students! This is your job! (synth_ref)" + +and synth_assign + : HopixTypes.typing_environment -> expression Position.located + -> expression Position.located -> HopixTypes.aty + = + fun tenv ref expr -> failwith "Students! This is your job! (synth_assign)" + +and synth_read + : HopixTypes.typing_environment -> expression Position.located -> HopixTypes.aty + = + fun tenv ref -> failwith "Students! This is your job! (synth_read)" + +and synth_case + : HopixTypes.typing_environment -> expression Position.located + -> branch Position.located list -> HopixTypes.aty + = + fun tenv expr branches -> failwith "Students! This is your job! (synth_case)" + +and synth_ifthenelse + : HopixTypes.typing_environment -> expression Position.located + -> expression Position.located -> expression Position.located -> HopixTypes.aty + = + fun tenv ecase eif eelse -> failwith "Students! This is your job! (synth_ifthenelse)" + +and synth_while + : HopixTypes.typing_environment -> expression Position.located + -> expression Position.located -> HopixTypes.aty + = + fun tenv ecase expr -> failwith "Students! This is your job! (synth_while)" + +and synth_for + : HopixTypes.typing_environment -> identifier Position.located + -> expression Position.located -> expression Position.located + -> expression Position.located -> HopixTypes.aty + = + fun tenv id estart eend expr -> failwith "Students! This is your job! (synth_for)" ;; let rec check_pattern @@ -54,37 +167,32 @@ let rec check_pattern = fun env Position.({ value = p; position = pos } as pat) expected -> failwith "Students! This is your job! (check_pattern)" - -and synth_pattern - : HopixTypes.typing_environment -> HopixAST.pattern Position.located - -> HopixTypes.aty * HopixTypes.typing_environment - = - fun env Position.{ value = p; position = pos } -> - failwith "Students! This is your job! (synth_pattern)" ;; let rec synth_expression : HopixTypes.typing_environment -> HopixAST.expression Position.located -> HopixTypes.aty = - fun env Position.{ value = e; position = pos } -> + fun env Position.{ value = e; position = _ } -> match e with - | Literal l -> type_of_literal l.value - | Variable (id, tlist) -> failwith "Students! This is your job! Variable" - | Tagged (cons, _, []) -> - HopixTypes.hbool (*Pas sûr, j'ai regardé comme dans hopixInterpreter au début*) - | Apply (a, b) -> failwith "Students! This is your job! Apply" - | Record (field, tliste) -> failwith "Students! This is your job! Record" - | Fun _ -> - failwith "Students! This is your job! Fun synth" - (* TODO : ici on ne peut pas synthesisé. cf Cours*) - | TypeAnnotation (expr, t) -> failwith "Students! This is your job! TypeAnnotation" - -and type_of_literal l = - match l with - | LInt _ -> HopixTypes.hint - | LChar _ -> HopixTypes.hchar - | LString _ -> HopixTypes.hstring + | Literal l -> synth_literal l.value + | Variable (id, tlist) -> synth_variable env id tlist + | Tagged (cons, tlist, elist) -> synth_tagged env cons tlist elist + | Apply (elist1, elist2) -> synth_apply env elist1 elist2 + | Record (field, tlist) -> synth_record env field tlist + | Fun (FunctionDefinition (def, expr)) -> synth_fun env def expr + | TypeAnnotation (expr, t) -> synth_tannot env expr t + | Field (expr, lbl, tlist) -> synth_field env expr lbl tlist + | Tuple elist -> synth_tuple env elist + | Sequence elist -> synth_sequence env elist + | Define (vdef, expr) -> synth_define env vdef expr + | Ref expr -> synth_ref env expr + | Assign (expr1, expr2) -> synth_assign env expr1 expr2 + | Read expr -> synth_read env expr + | Case (expr, branches) -> synth_case env expr branches + | IfThenElse (ecase, eif, eelse) -> synth_ifthenelse env ecase eif eelse + | While (ecase, expr) -> synth_while env ecase expr + | For (id, ecase, expr1, expr2) -> synth_for env id ecase expr1 expr2 and check_expression : HopixTypes.typing_environment -> HopixAST.expression Position.located