fix: plus que 3 code tests faux
This commit is contained in:
parent
0c5225da77
commit
8d1cf1a683
13
src/out.tam
13
src/out.tam
|
@ -1,4 +1,4 @@
|
|||
; fichiersRat/src-rat-tam-test/testfun2.rat
|
||||
; fichiersRat/src-rat-tam-test/testfun5.rat
|
||||
JUMP main
|
||||
|
||||
pgcd
|
||||
|
@ -70,16 +70,15 @@ SUBR IMul
|
|||
CALL (ST) norm
|
||||
RETURN (2) 4
|
||||
|
||||
f
|
||||
f1
|
||||
LOAD (1) -1[LB]
|
||||
POP (1) 1
|
||||
RETURN (1) 1
|
||||
RETURN (0) 1
|
||||
|
||||
main
|
||||
LOADL 3
|
||||
LOADL 4
|
||||
SUBR IAdd
|
||||
CALL (ST) f
|
||||
LOADL 13
|
||||
CALL (ST) f1
|
||||
LOAD (1) 0[SB]
|
||||
SUBR IOut
|
||||
|
||||
HALT
|
|
@ -1,3 +1,4 @@
|
|||
; fichiersRat/test.rat
|
||||
JUMP main
|
||||
|
||||
pgcd
|
||||
|
@ -80,7 +81,7 @@ LOAD (1) -1[LB]
|
|||
LOAD (1) 3[LB]
|
||||
SUBR IAdd
|
||||
SUBR IAdd
|
||||
POP (1) 2
|
||||
POP (1) 1
|
||||
RETURN (1) 2
|
||||
|
||||
main
|
||||
|
@ -105,7 +106,7 @@ CALL (ST) norm
|
|||
LOADL 5
|
||||
LOAD (2) 2[SB]
|
||||
LOAD (1) -2[ST]
|
||||
CALL (ST) add
|
||||
CALL (SB) add
|
||||
LOAD (2) 2[SB]
|
||||
CALL (ST) rout
|
||||
label2
|
||||
|
|
|
@ -18,7 +18,7 @@ let rec analyse_code_expression e =
|
|||
begin
|
||||
let InfoFun(nom,_,_) = info_ast_to_info i in
|
||||
(List.fold_right (fun e res -> res ^ analyse_code_expression e) le "") ^
|
||||
"CALL (ST) " ^nom ^ "\n"
|
||||
"CALL (ST) " ^ nom ^ "\n"
|
||||
end
|
||||
|
||||
| Ident(i) ->
|
||||
|
@ -58,13 +58,13 @@ let rec analyse_code_expression e =
|
|||
end
|
||||
|
||||
|
||||
and analyse_code_instruction i =
|
||||
and analyse_code_instruction i taille_return taille_args taille_var =
|
||||
match i with
|
||||
| Declaration(i, e) ->
|
||||
analyse_code_expression e
|
||||
|
||||
| Affectation(i, e) ->
|
||||
let InfoVar(_,t,base,reg) = (info_ast_to_info i) in
|
||||
let InfoVar(_, t, base, reg) = (info_ast_to_info i) in
|
||||
analyse_code_expression e ^
|
||||
"STORE (" ^ (string_of_int (getTaille t)) ^ ") " ^ (string_of_int base) ^ "[" ^ reg ^ "]\n"
|
||||
|
||||
|
@ -85,10 +85,10 @@ and analyse_code_instruction i =
|
|||
let etiq2 = getEtiquette () in
|
||||
(analyse_code_expression e) ^
|
||||
"JUMPIF (0) " ^ etiq1 ^ "\n" ^
|
||||
(analyse_code_bloc b1) ^
|
||||
(analyse_code_bloc b1 taille_return taille_args taille_var) ^
|
||||
"JUMP " ^ etiq2 ^ "\n" ^
|
||||
etiq1 ^ "\n" ^
|
||||
(analyse_code_bloc b2) ^
|
||||
(analyse_code_bloc b2 taille_return taille_args taille_var) ^
|
||||
etiq2 ^ "\n"
|
||||
|
||||
| TantQue(e, b) ->
|
||||
|
@ -97,34 +97,40 @@ and analyse_code_instruction i =
|
|||
etiq_while ^ "\n" ^
|
||||
(analyse_code_expression e) ^
|
||||
"JUMPIF (0) " ^ etiq_fin ^ "\n" ^
|
||||
(analyse_code_bloc b) ^
|
||||
(analyse_code_bloc b taille_return taille_args taille_var) ^
|
||||
"JUMP " ^ etiq_while ^ "\n" ^
|
||||
etiq_fin ^ "\n"
|
||||
|
||||
| Retour(e) ->
|
||||
(analyse_code_expression e)
|
||||
(analyse_code_expression e) ^
|
||||
"POP (" ^ taille_return ^ ") " ^ taille_var ^ "\n" ^
|
||||
"RETURN (" ^ taille_return ^ ") " ^ taille_args ^ "\n"
|
||||
|
||||
|
||||
| Empty -> ""
|
||||
|
||||
and analyse_code_bloc bloc =
|
||||
and analyse_code_bloc bloc taille_return taille_args taille_var =
|
||||
List.fold_right (
|
||||
fun i res -> (analyse_code_instruction i) ^ res
|
||||
fun i res -> (analyse_code_instruction i taille_return taille_args taille_var) ^ res
|
||||
) bloc ""
|
||||
|
||||
and analyse_code_fonction (AstPlacement.Fonction(info, l_typinfo, bloc)) =
|
||||
match info_ast_to_info info with
|
||||
| InfoFun(name, t, l_t) ->
|
||||
let taille_var = string_of_int (List.fold_right (fun e res -> taille_variables_declarees e + res) bloc 0) in
|
||||
let taille_return = string_of_int (getTaille t) in
|
||||
let taille_args = string_of_int (List.fold_right (fun e res -> getTaille e + res) l_t 0) in
|
||||
name ^ "\n" ^
|
||||
(analyse_code_bloc bloc) ^
|
||||
"POP (" ^ taille_return ^ ") " ^ taille_args ^ "\n" ^
|
||||
"RETURN (" ^ taille_return ^ ") " ^ taille_args ^ "\n\n"
|
||||
(analyse_code_bloc bloc taille_return taille_args taille_var) ^
|
||||
"POP (" ^ taille_return ^ ") " ^ taille_var ^ "\n" ^
|
||||
"RETURN (0) " ^ taille_args ^ "\n\n"
|
||||
|
||||
| _ -> failwith "spa normal"
|
||||
|
||||
let analyser (AstPlacement.Programme(fonctions, prog)) =
|
||||
let code = getEntete () in
|
||||
let code = code ^ List.fold_right (fun e res_q -> (analyse_code_fonction e) ^ res_q) fonctions "" in
|
||||
let code = code ^ List.fold_right (fun e res -> (analyse_code_fonction e) ^ res) fonctions "" in
|
||||
let code = code ^ "main\n" in
|
||||
let code = code ^ analyse_code_bloc prog in
|
||||
let code = code ^ (analyse_code_bloc prog "0" "0" "0") in
|
||||
code ^ "\nHALT"
|
||||
end
|
||||
|
|
|
@ -84,7 +84,7 @@ let%expect_test "factfun1" =
|
|||
let%expect_test "factfun2" =
|
||||
runtam "../../fichiersRat/src-rat-tam-test/testfun2.rat";
|
||||
[%expect{| 7 |}]
|
||||
(*
|
||||
|
||||
let%expect_test "factfun3" =
|
||||
runtam "../../fichiersRat/src-rat-tam-test/testfun3.rat";
|
||||
[%expect{| 10 |}]
|
||||
|
@ -108,4 +108,3 @@ let%expect_test "factfuns" =
|
|||
let%expect_test "factrec" =
|
||||
runtam "../../fichiersRat/src-rat-tam-test/factrec.rat";
|
||||
[%expect{| 120 |}]
|
||||
*)
|
Loading…
Reference in a new issue