feat: all tests except the FUCKING VOID

This commit is contained in:
Guillotin Damien 2021-12-10 13:12:06 +01:00
parent 8d1cf1a683
commit a1fa41107b
4 changed files with 20 additions and 122 deletions

3
.gitignore vendored
View file

@ -1 +1,2 @@
_build/
_build/
srcTAM/

View file

@ -71,14 +71,20 @@ CALL (ST) norm
RETURN (2) 4
f1
PUSH 1
LOAD (1) -1[LB]
STORE (1) 3[LB]
POP (1) 1
LOADL ''
RETURN (0) 1
main
PUSH 1
LOADL 13
CALL (ST) f1
STORE (1) 0[SB]
LOAD (1) 0[SB]
SUBR IOut
POP (0) 1
HALT

View file

@ -1,114 +0,0 @@
; fichiersRat/test.rat
JUMP main
pgcd
LOADL 0
LOAD (1) -2[LB]
LOAD (1) -1[LB]
boucle
LOAD (1) 5[LB]
JUMPIF (0) fin
LOAD (1) 4[LB]
LOAD (1) 5 [LB]
SUBR IMod
STORE (1) 3[LB]
LOAD (1) 5[LB]
STORE (1) 4[LB]
LOAD (1) 3[LB]
STORE(1) 5[LB]
JUMP boucle
fin
LOAD (1) 4[LB]
RETURN (1) 2
norm
LOAD (1) -2[LB]
LOAD (1) -1[LB]
CALL (LB) pgcd
LOAD (1) -2[LB]
LOAD (1) 3[LB]
SUBR IDiv
LOAD (1) -1[LB]
LOAD (1) 3[LB]
SUBR IDiv
RETURN (2) 2
ROut
LOADL '['
SUBR COut
LOAD (1) -2[LB]
SUBR IOut
LOADL '/'
SUBR COut
LOAD (1) -1[LB]
SUBR IOut
LOADL ']'
SUBR COut
RETURN (0) 2
RAdd
LOAD (1) -4[LB]
LOAD (1) -1[LB]
SUBR IMul
LOAD (1) -2[LB]
LOAD (1) -3[LB]
SUBR IMul
SUBR IAdd
LOAD (1) -3[LB]
LOAD (1) -1[LB]
SUBR IMul
CALL (ST) norm
RETURN (2) 4
RMul
LOAD (1) -4[LB]
LOAD (1) -2[LB]
SUBR IMul
LOAD (1) -3[LB]
LOAD (1) -1[LB]
SUBR IMul
CALL (ST) norm
RETURN (2) 4
add
LOADL 0
LOADL 0
LOAD (1) -2[LB]
SUBR IAdd
STORE (1) 3[LB]
LOAD (1) -2[LB]
LOAD (1) -1[LB]
LOAD (1) 3[LB]
SUBR IAdd
SUBR IAdd
POP (1) 1
RETURN (1) 2
main
LOADL 3
LOADL 4
STORE (1) 0[SB]
LOAD (1) 0[SB]
LOADL 5
SUBR IAdd
LOAD (1) 0[SB]
LOADL 0
SUBR ILss
JUMPIF (0) label1
LOADL 1
LOADL 0
STORE (1) 2[SB]
JUMP label2
label1
LOADL 4
LOADL 3
CALL (ST) norm
LOADL 5
LOAD (2) 2[SB]
LOAD (1) -2[ST]
CALL (SB) add
LOAD (2) 2[SB]
CALL (ST) rout
label2
HALT

View file

@ -17,7 +17,7 @@ let rec analyse_code_expression e =
| AppelFonction(i, le) ->
begin
let InfoFun(nom,_,_) = info_ast_to_info i in
(List.fold_right (fun e res -> res ^ analyse_code_expression e) le "") ^
(List.fold_right (fun e res -> analyse_code_expression e ^ res) le "") ^
"CALL (ST) " ^ nom ^ "\n"
end
@ -38,8 +38,8 @@ let rec analyse_code_expression e =
(analyse_code_expression e) ^
begin
match u with
| Numerateur -> "LOAD (1) -2[ST]\n"
| Denominateur -> "LOAD (1) -1[ST]\n"
| Numerateur -> "POP (0) 1\n"
| Denominateur -> "POP (1) 1\n"
end
| Binaire(b, e1, e2) ->
@ -61,7 +61,10 @@ let rec analyse_code_expression e =
and analyse_code_instruction i taille_return taille_args taille_var =
match i with
| Declaration(i, e) ->
analyse_code_expression e
let InfoVar(_, t, base, reg) = info_ast_to_info i in
"PUSH " ^ (string_of_int (getTaille t)) ^ "\n" ^
analyse_code_expression e ^
"STORE (" ^ (string_of_int (getTaille t)) ^ ") " ^ (string_of_int base) ^ "[" ^ reg ^ "]\n"
| Affectation(i, e) ->
let InfoVar(_, t, base, reg) = (info_ast_to_info i) in
@ -74,7 +77,7 @@ and analyse_code_instruction i taille_return taille_args taille_var =
| AffichageRat(e) ->
(analyse_code_expression e) ^
"CALL (ST) rout\n"
"CALL (ST) ROut\n"
| AffichageBool(e) ->
(analyse_code_expression e) ^
@ -92,6 +95,7 @@ and analyse_code_instruction i taille_return taille_args taille_var =
etiq2 ^ "\n"
| TantQue(e, b) ->
let taille_var = string_of_int (List.fold_right (fun e res -> taille_variables_declarees e + res) b 0) in
let etiq_while = getEtiquette () in
let etiq_fin = getEtiquette () in
etiq_while ^ "\n" ^
@ -110,9 +114,11 @@ and analyse_code_instruction i taille_return taille_args taille_var =
| Empty -> ""
and analyse_code_bloc bloc taille_return taille_args taille_var =
let taille_var = string_of_int (List.fold_right (fun e res -> taille_variables_declarees e + res) bloc 0) in
List.fold_right (
fun i res -> (analyse_code_instruction i taille_return taille_args taille_var) ^ res
) bloc ""
) bloc "" ^
"POP (0) " ^ taille_var ^ "\n"
and analyse_code_fonction (AstPlacement.Fonction(info, l_typinfo, bloc)) =
match info_ast_to_info info with
@ -122,7 +128,6 @@ and analyse_code_fonction (AstPlacement.Fonction(info, l_typinfo, bloc)) =
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 taille_return taille_args taille_var) ^
"POP (" ^ taille_return ^ ") " ^ taille_var ^ "\n" ^
"RETURN (0) " ^ taille_args ^ "\n\n"
| _ -> failwith "spa normal"