feat: tout est bon TODO: des ptits tests en plus c'est tjrs mieux
This commit is contained in:
parent
cb4b00f4ad
commit
13ed03e015
|
@ -177,6 +177,7 @@ type expression =
|
||||||
| NewType of typ
|
| NewType of typ
|
||||||
| Adresse of Tds.info_ast
|
| Adresse of Tds.info_ast
|
||||||
| Tuple of expression list
|
| Tuple of expression list
|
||||||
|
| Nothing
|
||||||
|
|
||||||
(* instructions existantes Rat *)
|
(* instructions existantes Rat *)
|
||||||
(* = instruction de AstTds + informations associées aux identificateurs, mises à jour *)
|
(* = instruction de AstTds + informations associées aux identificateurs, mises à jour *)
|
||||||
|
|
16
src/fichiersRat/src-rat-tam-test/Segment.rat
Normal file
16
src/fichiersRat/src-rat-tam-test/Segment.rat
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
typedef Point = struct { int x int y };
|
||||||
|
typedef Segment = struct { Point a Point b };
|
||||||
|
|
||||||
|
Segment slide(Segment s Point d) {
|
||||||
|
((s.a).x) += (d.x);
|
||||||
|
((s.a).y) += (d.y);
|
||||||
|
((s.b).x) += (d.x);
|
||||||
|
((s.b).y) += (d.y);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
Segment s = {{1 2}{3 4}};
|
||||||
|
Point p = {1 -1};
|
||||||
|
print call slide(s p);
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
main{
|
main{
|
||||||
typedef Point = struct { int x int y int z };
|
typedef Point = struct { int x int y int z };
|
||||||
Point p = { 1 2 3 };
|
Point p = { 2 4 3 };
|
||||||
print (p.x);
|
(p.y) = 1;
|
||||||
|
print (p.y);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
main{
|
main{
|
||||||
typedef Point = struct { struct{ int a int b } x int y int z };
|
typedef Point = struct { int y struct{ int a int b } x int z };
|
||||||
Point p = { {1 2} 3 4};
|
Point p = { 3 {2 1} 4 };
|
||||||
print ((p.x).b);
|
print ((p.x).a);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,47 @@ let rec getTailleAvant aff n =
|
||||||
in tai
|
in tai
|
||||||
| _ -> failwith "TODO or not TODO"
|
| _ -> failwith "TODO or not TODO"
|
||||||
end
|
end
|
||||||
| Attribut(aff,info) -> failwith "TODO"
|
| Attribut(aff2, info) -> (** (A.c).x
|
||||||
|
avec A = (1 2 (3 4) 5) = (a b c d)
|
||||||
|
avec c = (x y)
|
||||||
|
ici A ~ aff2 | c ~ info | x ~ n *)
|
||||||
|
begin
|
||||||
|
match info_ast_to_info info with
|
||||||
|
| InfoVar(n2, _, _, _) ->
|
||||||
|
let t2 = getType aff2 in
|
||||||
|
let aff_gen = Ident (info_to_info_ast (InfoVar("", t2, 0, ""))) in
|
||||||
|
getTailleAvant aff_gen n
|
||||||
|
| _ -> failwith "adaidadj"
|
||||||
|
end
|
||||||
|
|
||||||
|
and getType aff =
|
||||||
|
match aff with
|
||||||
|
| Dref(aff2, _) -> getType aff2
|
||||||
|
| Ident(info) ->
|
||||||
|
begin
|
||||||
|
match info_ast_to_info info with
|
||||||
|
| InfoVar(_, t, _, _) -> t
|
||||||
|
| _ -> failwith "prooblemo"
|
||||||
|
end
|
||||||
|
| Attribut(aff2, info) ->
|
||||||
|
begin
|
||||||
|
match info_ast_to_info info with
|
||||||
|
| InfoVar(n, _, _, _) ->
|
||||||
|
begin
|
||||||
|
match getType aff2 with
|
||||||
|
| Struct(l_typstr) ->
|
||||||
|
let t2 = List.fold_left (
|
||||||
|
fun res (t, s) ->
|
||||||
|
if s = n then
|
||||||
|
t
|
||||||
|
else
|
||||||
|
res
|
||||||
|
) Undefined l_typstr
|
||||||
|
in t2
|
||||||
|
| _ -> failwith "pas ok"
|
||||||
|
end
|
||||||
|
| _ -> failwith "sproblematik"
|
||||||
|
end
|
||||||
|
|
||||||
and getTailleAttribut aff n =
|
and getTailleAttribut aff n =
|
||||||
match aff with
|
match aff with
|
||||||
|
@ -47,7 +87,45 @@ and getTailleAttribut aff n =
|
||||||
) l_typstr 0
|
) l_typstr 0
|
||||||
| _ -> failwith "TODO' or not TODO'"
|
| _ -> failwith "TODO' or not TODO'"
|
||||||
end
|
end
|
||||||
| Attribut(aff,info) -> failwith "TODO'"
|
| Attribut(_, _) -> getTaille (getType aff)
|
||||||
|
|
||||||
|
and getBase aff =
|
||||||
|
match aff with
|
||||||
|
| Dref (a,_) -> getBase a
|
||||||
|
| Ident(i) ->
|
||||||
|
begin
|
||||||
|
match info_ast_to_info i with
|
||||||
|
| InfoVar(_, _, base, _) -> base
|
||||||
|
| _ -> failwith "spa bon"
|
||||||
|
end
|
||||||
|
| Attribut(a,i) ->
|
||||||
|
begin
|
||||||
|
match info_ast_to_info i with
|
||||||
|
| InfoVar (n,_,_,_) ->
|
||||||
|
let ib = getBase a in
|
||||||
|
let ita = getTailleAvant aff n in
|
||||||
|
let res = ib + ita in
|
||||||
|
res
|
||||||
|
| _ -> failwith "v vhjbhki"
|
||||||
|
end
|
||||||
|
|
||||||
|
and getReg aff =
|
||||||
|
match aff with
|
||||||
|
| Dref (a,_) -> getReg a
|
||||||
|
| Ident(i) ->
|
||||||
|
begin
|
||||||
|
match info_ast_to_info i with
|
||||||
|
| InfoVar(_, _, _, reg) -> reg
|
||||||
|
| _ -> failwith "spa bon"
|
||||||
|
end
|
||||||
|
| Attribut(a,_) -> getReg a
|
||||||
|
|
||||||
|
and extraction_info aff =
|
||||||
|
match aff with
|
||||||
|
| Dref(aff2, _) -> extraction_info aff2
|
||||||
|
| Ident(info) -> info
|
||||||
|
| Attribut(aff2, _) -> extraction_info aff2
|
||||||
|
|
||||||
|
|
||||||
and analyse_code_affectable a =
|
and analyse_code_affectable a =
|
||||||
match a with
|
match a with
|
||||||
|
@ -63,25 +141,10 @@ and analyse_code_affectable a =
|
||||||
| _ -> failwith "w-wtf bwo y-you okay -.-"
|
| _ -> failwith "w-wtf bwo y-you okay -.-"
|
||||||
end
|
end
|
||||||
|
|
||||||
| Attribut(a, i) ->
|
| Attribut(_, _) ->
|
||||||
begin
|
let base = getBase a in
|
||||||
let rec extraction_info aff =
|
let reg = getReg a in
|
||||||
match aff with
|
"LOAD (" ^ (string_of_int (getTaille (getType a))) ^ ") " ^ (string_of_int (base)) ^ "[" ^ reg ^ "]\n"
|
||||||
| Dref(aff2, _) -> extraction_info aff2
|
|
||||||
| Ident(info) -> info
|
|
||||||
| Attribut(_, info) -> info
|
|
||||||
in
|
|
||||||
match (info_ast_to_info (extraction_info a)) with
|
|
||||||
| InfoVar(_, _, base, reg) ->
|
|
||||||
begin
|
|
||||||
match info_ast_to_info i with
|
|
||||||
| InfoVar(n, _, _, _) ->
|
|
||||||
let t_avant = getTailleAvant a n in
|
|
||||||
"LOAD (" ^ (string_of_int (getTailleAttribut a n)) ^ ") " ^ (string_of_int (base + t_avant)) ^ "[" ^ reg ^ "]\n"
|
|
||||||
| _ -> failwith "g pu d'ID"
|
|
||||||
end
|
|
||||||
| _ -> failwith "toujours pas bon"
|
|
||||||
end
|
|
||||||
|
|
||||||
and analyse_code_expression e =
|
and analyse_code_expression e =
|
||||||
match e with
|
match e with
|
||||||
|
@ -143,6 +206,8 @@ and analyse_code_expression e =
|
||||||
| Tuple(l_expr) ->
|
| Tuple(l_expr) ->
|
||||||
List.fold_right (fun e res -> analyse_code_expression e ^ res) l_expr ""
|
List.fold_right (fun e res -> analyse_code_expression e ^ res) l_expr ""
|
||||||
|
|
||||||
|
| Nothing -> ""
|
||||||
|
|
||||||
and analyse_code_instruction i taille_return taille_args taille_var =
|
and analyse_code_instruction i taille_return taille_args taille_var =
|
||||||
match i with
|
match i with
|
||||||
| Declaration(i, e) ->
|
| Declaration(i, e) ->
|
||||||
|
@ -173,12 +238,16 @@ and analyse_code_instruction i taille_return taille_args taille_var =
|
||||||
"STOREI (" ^ string_of_int (getTaille t) ^ ")\n"
|
"STOREI (" ^ string_of_int (getTaille t) ^ ")\n"
|
||||||
|
|
||||||
| Attribut(aff, info) ->
|
| Attribut(aff, info) ->
|
||||||
|
begin
|
||||||
|
match (info_ast_to_info (extraction_info aff)) with
|
||||||
|
| InfoVar(_, _, _, reg) ->
|
||||||
begin
|
begin
|
||||||
match (info_ast_to_info info) with
|
match (info_ast_to_info info) with
|
||||||
| InfoVar(n, _, base, reg) ->
|
| InfoVar(n, _, _, _) ->
|
||||||
let t_avant = getTailleAvant aff n in
|
|
||||||
(analyse_code_expression e) ^
|
(analyse_code_expression e) ^
|
||||||
"STORE (" ^ (string_of_int (getTailleAttribut aff n)) ^ ") " ^ (string_of_int (base + t_avant)) ^ "[" ^ reg ^ "]\n"
|
"STORE (" ^ (string_of_int (getTailleAttribut a n)) ^ ") " ^ (string_of_int (getBase a)) ^ "[" ^ reg ^ "]\n"
|
||||||
|
| _ -> failwith "toujours pas bonn"
|
||||||
|
end
|
||||||
| _ -> failwith "toujours pas bon"
|
| _ -> failwith "toujours pas bon"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -296,9 +365,43 @@ and analyse_code_instruction i taille_return taille_args taille_var =
|
||||||
affichage base reg t
|
affichage base reg t
|
||||||
| _ -> failwith "spa bon"
|
| _ -> failwith "spa bon"
|
||||||
end
|
end
|
||||||
| Attribut(a,i) -> failwith "ok3"
|
| Attribut(a2,i) ->
|
||||||
|
match info_ast_to_info i with
|
||||||
|
| InfoVar(n, t, _, _) ->
|
||||||
|
let base = getBase a in
|
||||||
|
let reg = getReg a in
|
||||||
|
affichage base reg t
|
||||||
|
| _ -> failwith "zifj"
|
||||||
|
end
|
||||||
|
| AppelFonction(i, le) ->
|
||||||
|
begin
|
||||||
|
match info_ast_to_info i with
|
||||||
|
| InfoFun(nom, Struct(l_typstr), _) ->
|
||||||
|
let t = Struct(l_typstr) in
|
||||||
|
let base = -getTaille t in
|
||||||
|
let reg = "ST" in
|
||||||
|
(List.fold_right (fun e res -> analyse_code_expression e ^ res) le "") ^
|
||||||
|
"CALL (ST) " ^ nom ^ "\n" ^
|
||||||
|
(affichage base reg t) ^
|
||||||
|
"POP (0) " ^ (string_of_int (getTaille t)) ^ "\n"
|
||||||
|
(* List.fold_right (
|
||||||
|
fun (t, _) res ->
|
||||||
|
let i =
|
||||||
|
match t with
|
||||||
|
| Bool -> AffichageBool(Nothing)
|
||||||
|
| Int -> AffichageInt(Nothing)
|
||||||
|
| Rat -> AffichageRat(Nothing)
|
||||||
|
| Pointeur(_) -> AffichagePointeur(Nothing)
|
||||||
|
| Struct(l_ts) -> AffichageStruct(Tuple(List.map (fun _ -> Nothing) l_ts), t)
|
||||||
|
| _ -> failwith "peut pas print des non printable, duuuh"
|
||||||
|
in
|
||||||
|
"LOADL ' '\n" ^
|
||||||
|
"SUBR COut\n" ^
|
||||||
|
(analyse_code_instruction i "0" "0" "0") ^
|
||||||
|
res
|
||||||
|
) l_typstr "LOADL ' '\nSUBR COut\n" *)
|
||||||
|
| _ -> failwith "bizreement pas ok"
|
||||||
end
|
end
|
||||||
|
|
||||||
| _ -> failwith "spa cool ca"
|
| _ -> failwith "spa cool ca"
|
||||||
in
|
in
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,14 @@ let rec recherche_type tds t =
|
||||||
| _ -> failwith "un truc louche ca"
|
| _ -> failwith "un truc louche ca"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
| _ ->
|
||||||
|
begin
|
||||||
|
match t with
|
||||||
|
| Struct (l_typstr) ->
|
||||||
|
let n_l_typstr = (List.map (fun (t, n) -> (recherche_type tds t, n)) l_typstr) in
|
||||||
|
Struct n_l_typstr
|
||||||
| _ -> t
|
| _ -> t
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
let rec analyse_tds_affectable tds a modif =
|
let rec analyse_tds_affectable tds a modif =
|
||||||
|
@ -64,6 +71,7 @@ let rec analyse_tds_affectable tds a modif =
|
||||||
let info = extraction_info n_aff in
|
let info = extraction_info n_aff in
|
||||||
match info_ast_to_info info with
|
match info_ast_to_info info with
|
||||||
| InfoVar(_, t, _, _) ->
|
| InfoVar(_, t, _, _) ->
|
||||||
|
begin
|
||||||
match t with
|
match t with
|
||||||
| Struct(l_att) ->
|
| Struct(l_att) ->
|
||||||
let t = List.fold_right (fun (t, n) res -> if str = n then t else res) l_att Undefined in
|
let t = List.fold_right (fun (t, n) res -> if str = n then t else res) l_att Undefined in
|
||||||
|
@ -71,8 +79,10 @@ let rec analyse_tds_affectable tds a modif =
|
||||||
AstTds.Attribut(n_aff, info_to_info_ast (InfoVar(str, t, 0, "")))
|
AstTds.Attribut(n_aff, info_to_info_ast (InfoVar(str, t, 0, "")))
|
||||||
else
|
else
|
||||||
raise (MauvaiseUtilisationIdentifiant str)
|
raise (MauvaiseUtilisationIdentifiant str)
|
||||||
| _ -> raise (MauvaiseUtilisationIdentifiant str)
|
| _ ->
|
||||||
|
let _ = print_endline (string_of_type t) in
|
||||||
|
raise (MauvaiseUtilisationIdentifiant str)
|
||||||
|
end
|
||||||
| _ -> raise (MauvaiseUtilisationIdentifiant str)
|
| _ -> raise (MauvaiseUtilisationIdentifiant str)
|
||||||
|
|
||||||
(* analyse_tds_expression : AstSyntax.expression -> AstTds.expression *)
|
(* analyse_tds_expression : AstSyntax.expression -> AstTds.expression *)
|
||||||
|
@ -214,6 +224,11 @@ let rec analyse_tds_instruction tds i =
|
||||||
raise (MauvaiseUtilisationIdentifiant n)
|
raise (MauvaiseUtilisationIdentifiant n)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
| Attribut(aff2, n) ->
|
||||||
|
begin
|
||||||
|
(** RAF *)
|
||||||
|
Affectation(n_a, ne)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
| AstSyntax.Constante (n,v) ->
|
| AstSyntax.Constante (n,v) ->
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -148,7 +148,17 @@ let rec analyse_type_instruction opt i =
|
||||||
raise (TypeInattendu(nt, t))
|
raise (TypeInattendu(nt, t))
|
||||||
| _ -> failwith "wut"
|
| _ -> failwith "wut"
|
||||||
end
|
end
|
||||||
| AstTds.Attribut _ -> failwith "TODOOO"
|
| AstTds.Attribut(aff2, info) ->
|
||||||
|
begin
|
||||||
|
match info_ast_to_info info with
|
||||||
|
| InfoVar(_, t, _, _) ->
|
||||||
|
if est_compatible t nt then
|
||||||
|
let na, _ = analyse_type_affectable aff2 in
|
||||||
|
AstType.Affectation(Attribut(na, info), ne)
|
||||||
|
else
|
||||||
|
raise (TypeInattendu(nt, t))
|
||||||
|
| _ -> failwith "pas bon du tout"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
| AstTds.Affichage e ->
|
| AstTds.Affichage e ->
|
||||||
|
|
|
@ -151,3 +151,7 @@ let%expect_test "printPointeur" =
|
||||||
let%expect_test "printStruct" =
|
let%expect_test "printStruct" =
|
||||||
runtam "../../fichiersRat/src-rat-tam-test/testprintStruct.rat";
|
runtam "../../fichiersRat/src-rat-tam-test/testprintStruct.rat";
|
||||||
[%expect{| { 1 2 } |}]
|
[%expect{| { 1 2 } |}]
|
||||||
|
|
||||||
|
let%expect_test "Segment" =
|
||||||
|
runtam "../../fichiersRat/src-rat-tam-test/Segment.rat";
|
||||||
|
[%expect{| { { 2 1 } { 4 3 } } |}]
|
Loading…
Reference in a new issue