mirror of
https://github.com/LucasVbr/postscript-compiler.git
synced 2026-05-13 17:22:00 +00:00
feat(typing): Function and tests of commands
This commit is contained in:
+33
-10
@@ -177,8 +177,7 @@ let test_tp_expr =
|
|||||||
IntT;
|
IntT;
|
||||||
BoolT;
|
BoolT;
|
||||||
] in
|
] in
|
||||||
try ((List.map function_to_test input_values) = expected_result) with
|
(List.map function_to_test input_values) = expected_result
|
||||||
_ -> false
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(* ----- Typage d'une commande ----- *)
|
(* ----- Typage d'une commande ----- *)
|
||||||
@@ -203,9 +202,13 @@ let rec tp_cmd (env: environment) (cmd: com) =
|
|||||||
else raise (Failure "Invalid type of Conditionnal Command")
|
else raise (Failure "Invalid type of Conditionnal Command")
|
||||||
| Loop(cmd1) ->
|
| Loop(cmd1) ->
|
||||||
let _ = (tp_cmd env cmd1) in VoidT
|
let _ = (tp_cmd env cmd1) in VoidT
|
||||||
| CallC(name, list_expr) -> VoidT (* TODO Faire l'appel *)
|
| CallC(name, list_expr) -> tp_expr env (CallE(name, list_expr)) (* TODO => Question: Il faut renvoyer le type ??? *)
|
||||||
| Return(expr) -> (tp_expr env expr)
|
| Return(expr) -> (tp_expr env expr)
|
||||||
;;
|
;;
|
||||||
|
(* val tp_cmd :
|
||||||
|
environment -> Lang.com
|
||||||
|
-> Lang.tp = <fun>
|
||||||
|
*)
|
||||||
|
|
||||||
(* - tp_cmd: TESTS - *)
|
(* - tp_cmd: TESTS - *)
|
||||||
let test_tp_cmd =
|
let test_tp_cmd =
|
||||||
@@ -213,18 +216,38 @@ let test_tp_cmd =
|
|||||||
localvars=[
|
localvars=[
|
||||||
("i", IntT);
|
("i", IntT);
|
||||||
("f", FloatT);
|
("f", FloatT);
|
||||||
("b", BoolT);
|
|
||||||
("l", LitT);
|
|
||||||
("s", StringT);
|
|
||||||
];
|
];
|
||||||
funbind=[
|
funbind=[
|
||||||
Fundecl(BoolT, "fun1", [Vardecl(IntT, "a"); Vardecl(FloatT, "b")])
|
Fundecl(BoolT, "fun1", [Vardecl(IntT, "a"); Vardecl(FloatT, "b")])
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
and input_values = []
|
and input_values = [
|
||||||
and expected_result = [] in
|
Skip;
|
||||||
try ((List.map function_to_test input_values) = expected_result) with
|
Exit;
|
||||||
_ -> false
|
Assign("test", Const(IntV(5)));
|
||||||
|
Seq(Skip, Exit);
|
||||||
|
Seq(Skip, Return(Const(FloatV(5.))));
|
||||||
|
|
||||||
|
CondC(
|
||||||
|
BinOp(BCompar(BCge), Const(IntV(4)), Const(IntV(5))),
|
||||||
|
Skip, Skip
|
||||||
|
);
|
||||||
|
Loop(Exit);
|
||||||
|
|
||||||
|
CallC("fun1", [VarE("i"); VarE("f")]);
|
||||||
|
Return(Const(IntV(5)));
|
||||||
|
]
|
||||||
|
and expected_result = [
|
||||||
|
VoidT;
|
||||||
|
VoidT;
|
||||||
|
VoidT;
|
||||||
|
VoidT; FloatT;
|
||||||
|
VoidT;
|
||||||
|
VoidT;
|
||||||
|
BoolT;
|
||||||
|
IntT;
|
||||||
|
] in
|
||||||
|
(List.map function_to_test input_values) = expected_result
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(* let tp_fundefn fundefns = ;; *)
|
(* let tp_fundefn fundefns = ;; *)
|
||||||
|
|||||||
Reference in New Issue
Block a user