sépare les problèmes pour mieux comprendre parce que là c'est un calvere
les types des fonctions sont pas là pour avoir un truc par défaut mais sont probablement pas définitif
This commit is contained in:
parent
3ee85d7766
commit
9700dddcac
1 changed files with 133 additions and 25 deletions
|
@ -45,7 +45,120 @@ let check_type_scheme
|
||||||
;;
|
;;
|
||||||
|
|
||||||
let synth_literal : HopixAST.literal -> HopixTypes.aty =
|
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
|
let rec check_pattern
|
||||||
|
@ -54,37 +167,32 @@ let rec check_pattern
|
||||||
=
|
=
|
||||||
fun env Position.({ value = p; position = pos } as pat) expected ->
|
fun env Position.({ value = p; position = pos } as pat) expected ->
|
||||||
failwith "Students! This is your job! (check_pattern)"
|
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
|
let rec synth_expression
|
||||||
: HopixTypes.typing_environment -> HopixAST.expression Position.located
|
: HopixTypes.typing_environment -> HopixAST.expression Position.located
|
||||||
-> HopixTypes.aty
|
-> HopixTypes.aty
|
||||||
=
|
=
|
||||||
fun env Position.{ value = e; position = pos } ->
|
fun env Position.{ value = e; position = _ } ->
|
||||||
match e with
|
match e with
|
||||||
| Literal l -> type_of_literal l.value
|
| Literal l -> synth_literal l.value
|
||||||
| Variable (id, tlist) -> failwith "Students! This is your job! Variable"
|
| Variable (id, tlist) -> synth_variable env id tlist
|
||||||
| Tagged (cons, _, []) ->
|
| Tagged (cons, tlist, elist) -> synth_tagged env cons tlist elist
|
||||||
HopixTypes.hbool (*Pas sûr, j'ai regardé comme dans hopixInterpreter au début*)
|
| Apply (elist1, elist2) -> synth_apply env elist1 elist2
|
||||||
| Apply (a, b) -> failwith "Students! This is your job! Apply"
|
| Record (field, tlist) -> synth_record env field tlist
|
||||||
| Record (field, tliste) -> failwith "Students! This is your job! Record"
|
| Fun (FunctionDefinition (def, expr)) -> synth_fun env def expr
|
||||||
| Fun _ ->
|
| TypeAnnotation (expr, t) -> synth_tannot env expr t
|
||||||
failwith "Students! This is your job! Fun synth"
|
| Field (expr, lbl, tlist) -> synth_field env expr lbl tlist
|
||||||
(* TODO : ici on ne peut pas synthesisé. cf Cours*)
|
| Tuple elist -> synth_tuple env elist
|
||||||
| TypeAnnotation (expr, t) -> failwith "Students! This is your job! TypeAnnotation"
|
| Sequence elist -> synth_sequence env elist
|
||||||
|
| Define (vdef, expr) -> synth_define env vdef expr
|
||||||
and type_of_literal l =
|
| Ref expr -> synth_ref env expr
|
||||||
match l with
|
| Assign (expr1, expr2) -> synth_assign env expr1 expr2
|
||||||
| LInt _ -> HopixTypes.hint
|
| Read expr -> synth_read env expr
|
||||||
| LChar _ -> HopixTypes.hchar
|
| Case (expr, branches) -> synth_case env expr branches
|
||||||
| LString _ -> HopixTypes.hstring
|
| 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
|
and check_expression
|
||||||
: HopixTypes.typing_environment -> HopixAST.expression Position.located
|
: HopixTypes.typing_environment -> HopixAST.expression Position.located
|
||||||
|
|
Reference in a new issue