diff --git a/main.ml b/main.ml index c3fcd30..a7b503a 100644 --- a/main.ml +++ b/main.ml @@ -16,7 +16,7 @@ let process source_code_file no_typing = try let ast = Parser.prog Lexer.token lexbuf in close_in ic; - if not no_typing then Typer.typing ast else Ast.Tunit; + if not no_typing then Typer.typing ast; Compiler.compile ast source_code_file with | Lexer.Lexing_error c -> diff --git a/typer.ml b/typer.ml index 0964f60..fb7a48d 100644 --- a/typer.ml +++ b/typer.ml @@ -126,21 +126,20 @@ let rec type_expr env e = | Tabool -> Tint | _ -> error "not array type (array_size primitive)" end - | _ -> error "not implemented (call compiler with --no-typing option)" and type_stmt env s = - match s with + begin match s with | Sassign(i,e,s) -> let env = Tmap.add i (type_expr env e) env in type_stmt env s | Srefassign(i,e) -> let ty1 = type_expr env (Eident i) in let ty2 = type_expr env e in - if ty1 == ty2 then Tunit else error "not identic type (ref assign)" + if ty1 == ty2 then () else error "not identic type (ref assign)" | Saassign(i,e1,e2) -> let tya = type_expr env (Eident i) in begin match type_expr env e1 with | Tint -> begin match type_expr env e2 with - | Tint -> if tya == Taint then Tunit else error "not integer type (array element assign)" - | Tbool -> if tya == Tabool then Tunit else error "not boolean type (array element assign)" + | Tint -> if tya == Taint then () else error "not integer type (array element assign)" + | Tbool -> if tya == Tabool then () else error "not boolean type (array element assign)" | _ -> error "incoherent type (array element assign)" end | _ -> error "not integer type (array assign accessor)" @@ -154,18 +153,18 @@ and type_stmt env s = | Tbool -> type_stmt env s1; type_stmt env s2; type_block env b | _ -> error "not boolean type (for statement condition)" end - | Sprint e -> type_expr env e (* print bool (0/1) or unit (0) is ok *) + | Sprint e -> let _ = type_expr env e in () (* print bool (0/1) or unit (0) is ok *) | Sif (e,s1,s2) -> begin begin match type_expr env e with - | Tbool -> Tbool + | Tbool -> () | _ -> error "not boolean type (if condition statement)" end; type_stmt env s1; type_stmt env s2 end - | Sexit -> Tunit - | Sskip -> Tunit - | _ -> error "not implemented (call compiler with --no-typing option)" + | Sexit -> () + | Sskip -> () + end and type_block env b = match b with