diff --git a/interprete/gram.o b/interprete/gram.o new file mode 100644 index 0000000..92ebe1d Binary files /dev/null and b/interprete/gram.o differ diff --git a/interprete/interp b/interprete/interp index 1155daf..822a488 100755 Binary files a/interprete/interp and b/interprete/interp differ diff --git a/interprete/interp.o b/interprete/interp.o new file mode 100644 index 0000000..fc1a335 Binary files /dev/null and b/interprete/interp.o differ diff --git a/interprete/lex.o b/interprete/lex.o new file mode 100644 index 0000000..ce31071 Binary files /dev/null and b/interprete/lex.o differ diff --git a/progs/ex1-V3.kat b/progs/ex1-V3.kat deleted file mode 100644 index 26e0ab6..0000000 --- a/progs/ex1-V3.kat +++ /dev/null @@ -1,261 +0,0 @@ -class Point(var x, y: Integer, var name: String) is { - var static next : Integer - def static incr() : Integer is - { Point.next := Point.next + 1; result := Point.next; } - def static howMany() : Integer := Point.next - def static init () is { Point.next := 0; } - - /* attributs supplementaires à initialiser dans le constructeur */ - var hasClone : Integer - var index : Integer - /* la valeur du champ ci-dessous est indefinie si hasClone vaut 0. - * Le probleme est qu'on n'a pas l'equivalent de NULL (du bon type) - */ - var clone : Point - - - /* L'en-tete du constructeur doit etre identique a celui de la classe. - * Les parametres précédés de var correspondent implictement à des attributs - * de meme nom qui seront intialises automatiquement à la valeur du - * parametre, comme si on avait la ligne suivante en tete du constructeur: - * this.x := x; this.y := y; this.name := name; - */ - - def Point(var x, y: Integer, var name: String) is - { this.index := Point.incr(); this.hasClone := 0; } - - def getx() : Integer := this.x /* pas de this implicite */ - - def gety() : Integer := this.y - - def setName(s: String) is { this.name := s; } - - def isCloned() : Integer := this.hasClone <> 0 - - def move(dx: Integer, dy: Integer, verbose: Integer) : Point is { - this.x := this.x + dx; this.y := this.y + dy; - if verbose then { this.print(verbose); } else {} - /* pseudo variable 'result' dans laquelle, par convention, on laisse - * la valeur de retour d'une fonction qui a un type de retour. - * On aurait pu ecrire aussi - * return this; - */ - result := this; - } - - def print(verbose : Integer) is { - if verbose then "Inside Point::print".println(); else { } - /* Exemples avec l'operateur & de concatenation de chaines */ - this.name.print(); - ( "= (" & this.x.toString() & ", " & this.y.toString() & ")" ).println(); - } - - /* par defaut, on ajoute un ' au nom de l'objet. Modifiable avec setName */ - def clone() : Point is - { this.hasClone = 1; - /* On memorise le dernier clone construit à partir de cet objet - * si on voulait on pourrait le chainer a la fin de la liste des clones - */ - this.clone := new Point(this.x, this.y, this.name & "'"); - result := this.clone; - } - - /* imprime le clone de cet objet, s'il existe, ainsi que recursivement - * les clones de ce dernier - */ - def allClones () is { - if this.hasClone <> 0 then { this.clone.print(1); this.clone.allClones(); } - else { } - } - - def egal(p: Point) : Integer is { /* autre version */ - b1, b2: Integer - is - b1 := p.x - this.x; - b2 := p.y - this.y; - result := 0; - if b1 then { } else { result := b2 = 0; } - } -} /* Fin de la classe Point */ - -class Couleur(var coul: Integer) is { - /* 3 couleurs : couleur = 0, 1 ou 2 - * Le corps du constructeur garantit qu'on a bien que trois couleurs. - */ - - def Couleur (var coul: Integer) is { - if this.coul < 0 then this.coul := 0; - else if this.coul > 2 then this.coul := 0; else {} - } - - def name(verbose: Integer) : String is { - aux: String - is - if verbose then "Inside Couleur::couleur".println(); else {} - if this.coul = 0 then result:= "Blanc"; - else { dummy : String - is - dummy := "Noir"; aux := "Gris"; - if this.coul = 1 then aux := dummy; else { } - result := aux; - } - } - - def estGris() : Integer is { - "Inside Couleur::estGris".println(); - result := this.coul = 2; - } -} - -class CouleurFactory() is { - var static theBlanc, theNoir, theGris : Couleur - - def CouleurFactory() is {} - - def static init() is { - CouleurFactory.theBlanc := new Couleur(0); - CouleurFactory.theNoir := new Couleur(1); - CouleurFactory.theGris := new Couleur(2); - } - def static blanc() : Couleur := CouleurFactory.theBlanc - def static noir() : Couleur := CouleurFactory.theNoir - def static gris() : Couleur := CouleurFactory.theGris -} - -/* ci-dessous on ne met pas var devant x et y sinon ca definirait deux - * nouveaux champs qui masqueraient ceux herites de Point - */ -class PointColore(x, y:Integer, var coul: Couleur) extends Point is { - - def couleur() : Couleur := this.coul - - def colore() : Integer := this.coul.estGris() <> 0 - - def PointColore (x, y:Integer, var coul: Couleur) - : Point(x, y, "P-" & Point.howMany().toString() ) is { /* empty */ } - - /* pas PointColore: pas de covariance ! On ne peut pas reutiliser le - * clone de Point car ca nous donnerait une instance de Point. - * On n'a pas le mecanisme predefini de Java qui permet de remonter jusqu'a - * la racine de la hierarchie tout en allouant un objet de la bonne classe. - */ - def override clone() : Point /* pas PointColore. Pas de covariance ! */ - /* ci-dessous x et y sont les champs herites de Point */ - := new PointColore(this.x, this.y, this.coul) - - def estGris() : Integer := this.coul.estGris() - - def override print(verbose : Integer) is { - if verbose then "Inside PointColore::print".println(); else { } - super.print(verbose); /* usage classique de super */ - this.couleur().name(1).println(); - } -} - -class PointNoir(xc, yc:Integer) extends PointColore is { - def override estGris() : Integer := 0 - def override colore() : Integer := 1 - def override couleur() : Couleur := CouleurFactory.noir() - def PointNoir(xc, yc:Integer) - : PointColore(xc, yc, CouleurFactory.noir()) is { /* empty */ } -} - - -class DefaultPoint() extends PointColore is { - def override estGris() : Integer := 0 - def override couleur() : Couleur := CouleurFactory.blanc() - def DefaultPoint() - : PointColore(0, 0, CouleurFactory.blanc()) is { /* empty */ } -} - -class Test () is { - def static test(p: Point, p2: PointColore, p3: PointNoir) is { - c, c2, c3: String - true: Integer - is - true := 1; - p.print(true); - p2.print(true); - "Appel 1: ".println(); - if p2.colore() <> 0 then c := "colore"; else c := "gris"; - "Appel 2: ".println(); - if p3.colore() <> 0 then c2 := "colore"; else c2 := "gris"; - "Appel 3: ".println(); - if p3.colore() <> 0 then c3 := "colore"; else c3 := "gris"; - "Resultats de test: ".println(); - c.print(); " ".print(); - c2.print(); " ".print(); - c3.print(); - "".println(); /* imprime une ligne vide */ - } - - def static test2(p: PointColore) is { p.couleur().name(1).print(); } - - def Test() is {} -} - -{ /* Bloc qui correspond au programme principal */ - p1, p2, p3, clone1, clone2: Point - true, false, fv: Integer - o: PointColore - pn: PointNoir - dp: DefaultPoint - is - "Debut du programme".println(); - Point.init(); - CouleurFactory.init(); - true := 1; - false := 0; - p1 := new Point(1, 5, "p1"); - p2 := new Point(2, 3, "p2"); - p3 := new Point(0, 0, "p3"); - fv := 12; - o := new PointColore(0, 0, CouleurFactory.blanc()); - pn := new PointNoir(+1, -1); - dp := new DefaultPoint(); - p1.print(0); - p2.print(0); - p2.move(p1.getx(), p1.gety(), 0); - p2.print(0); - o.print(0); - o.setName("origine"); - o.print(true); - p2.move(p1.getx()-2*5-3, p1.gety(), 0); - p2.print(true); - - "On va essayer le clonage:".println(); - clone1 := p1.clone(); clone1.print(false); - "p1 isCloned: ".print(); - if p1.isCloned() then "OK".println(); else "KO".println(); - clone2 := clone1.clone(); clone2.move(54, 36, 0).print(false); - - "Impression de tous les clones de p1:".println(); - p1.allClones(); - "Fin de l'impression de tous les clones".println(); - - /* Ne doit pas compiler car clone() renvoie statiquement un Point alors - * que o est declare comme PointColore - * o := o.clone(); - */ - - "Valeur du compteur de nombre de points: ".println(); - Point.howMany().toString().println(); - - p1 := p1.clone().move(+2, -3, 0); - p1.print(true); - o.clone().print(true); - "test(Point, PointColore, PointNoir)".println(); - Test.test(p1, o, pn); - "test(PointNoir, PointNoir, PointNoir)".println(); - Test.test(pn, pn, pn); - p1 := pn; /* affectation entre pointeurs ! */ - Test.test2(o); - Test.test2(pn); - o := pn; /* Idem : on doit avoir de la liaison dynamique ci-dessous */ - - "test(PointNoir, PointNoir, PointNoir)".println(); - Test.test(p1, o, pn); - Test.test2(o); - Test.test2(pn); - "\nDone".println(); -} diff --git a/progs/ex1_prog.txt b/progs/ex1_prog.txt new file mode 100644 index 0000000..ef7a5cd --- /dev/null +++ b/progs/ex1_prog.txt @@ -0,0 +1,652 @@ +JUMP start +-- ----- VTABLES ----- +ALLOC 9 +DUPN 1 +PUSHA Point_4_egal +STORE 0 +DUPN 1 +PUSHA Point_9_allClones +STORE 1 +DUPN 1 +PUSHA Point_5_clone +STORE 2 +DUPN 1 +PUSHA Point_5_print +STORE 3 +DUPN 1 +PUSHA Point_4_move +STORE 4 +DUPN 1 +PUSHA Point_8_isCloned +STORE 5 +DUPN 1 +PUSHA Point_7_setName +STORE 6 +DUPN 1 +PUSHA Point_4_gety +STORE 7 +DUPN 1 +PUSHA Point_4_getx +STORE 8 +ALLOC 2 +DUPN 1 +PUSHA Couleur_7_estGris +STORE 0 +DUPN 1 +PUSHA Couleur_4_name +STORE 1 +ALLOC 12 +DUPN 1 +PUSHA Point_4_egal +STORE 0 +DUPN 1 +PUSHA Point_9_allClones +STORE 1 +DUPN 1 +PUSHA PointColore_5_clone +STORE 2 +DUPN 1 +PUSHA PointColore_5_print +STORE 3 +DUPN 1 +PUSHA Point_4_move +STORE 4 +DUPN 1 +PUSHA Point_8_isCloned +STORE 5 +DUPN 1 +PUSHA Point_7_setName +STORE 6 +DUPN 1 +PUSHA Point_4_gety +STORE 7 +DUPN 1 +PUSHA Point_4_getx +STORE 8 +DUPN 1 +PUSHA PointColore_7_estGris +STORE 9 +DUPN 1 +PUSHA PointColore_6_colore +STORE 10 +DUPN 1 +PUSHA PointColore_7_couleur +STORE 11 +ALLOC 12 +DUPN 1 +PUSHA Point_4_egal +STORE 0 +DUPN 1 +PUSHA Point_9_allClones +STORE 1 +DUPN 1 +PUSHA PointColore_5_clone +STORE 2 +DUPN 1 +PUSHA PointColore_5_print +STORE 3 +DUPN 1 +PUSHA Point_4_move +STORE 4 +DUPN 1 +PUSHA Point_8_isCloned +STORE 5 +DUPN 1 +PUSHA Point_7_setName +STORE 6 +DUPN 1 +PUSHA Point_4_gety +STORE 7 +DUPN 1 +PUSHA Point_4_getx +STORE 8 +DUPN 1 +PUSHA PointNoir_7_estGris +STORE 9 +DUPN 1 +PUSHA PointNoir_6_colore +STORE 10 +DUPN 1 +PUSHA PointNoir_7_couleur +STORE 11 +ALLOC 12 +DUPN 1 +PUSHA Point_4_egal +STORE 0 +DUPN 1 +PUSHA Point_9_allClones +STORE 1 +DUPN 1 +PUSHA PointColore_5_clone +STORE 2 +DUPN 1 +PUSHA PointColore_5_print +STORE 3 +DUPN 1 +PUSHA Point_4_move +STORE 4 +DUPN 1 +PUSHA Point_8_isCloned +STORE 5 +DUPN 1 +PUSHA Point_7_setName +STORE 6 +DUPN 1 +PUSHA Point_4_gety +STORE 7 +DUPN 1 +PUSHA Point_4_getx +STORE 8 +DUPN 1 +PUSHA DefaultPoint_7_estGris +STORE 9 +DUPN 1 +PUSHA PointColore_6_colore +STORE 10 +DUPN 1 +PUSHA DefaultPoint_7_couleur +STORE 11 +-- ----- STATIC ATTRIBS ----- +PUSHN 4 +-- ----- MAIN INSTRUCTION ----- +start: NOP +START +PUSHN 11 +PUSHS "Debut du programme" +DUPN 1 +WRITES +PUSHS "\n" +WRITES +POPN 1 +PUSHA Point_4_init +CALL +POPN 1 +PUSHA CouleurFactory_4_init +CALL +POPN 1 +PUSHL 5 +PUSHI 1 +STOREL 5 +PUSHL 6 +PUSHI 0 +STOREL 6 +PUSHL 0 +PUSHA _CTOR_Point_ +CALL +STOREL 0 +PUSHL 1 +PUSHA _CTOR_Point_ +CALL +STOREL 1 +PUSHL 2 +PUSHA _CTOR_Point_ +CALL +STOREL 2 +PUSHL 7 +PUSHI 12 +STOREL 7 +PUSHL 8 +PUSHA _CTOR_PointColore_ +CALL +STOREL 8 +PUSHL 9 +PUSHA _CTOR_PointNoir_ +CALL +STOREL 9 +PUSHL 10 +PUSHA _CTOR_DefaultPoint_ +CALL +STOREL 10 +PUSHI 0 +PUSHI 0 +PUSHL 0 +DUPN 1 +LOAD 0 +LOAD 3 +CALL +POPN 2 +POPN 1 +PUSHI 0 +PUSHI 0 +PUSHL 1 +DUPN 1 +LOAD 0 +LOAD 3 +CALL +POPN 2 +POPN 1 +PUSHI 0 +PUSHI 0 +PUSHL 0 +DUPN 1 +LOAD 0 +LOAD 8 +CALL +POPN 1 +PUSHI 0 +PUSHL 0 +DUPN 1 +LOAD 0 +LOAD 7 +CALL +POPN 1 +PUSHI 0 +PUSHL 1 +DUPN 1 +LOAD 0 +LOAD 4 +CALL +POPN 4 +POPN 1 +PUSHI 0 +PUSHI 0 +PUSHL 1 +DUPN 1 +LOAD 0 +LOAD 3 +CALL +POPN 2 +POPN 1 +PUSHI 0 +PUSHI 0 +PUSHL 8 +DUPN 1 +LOAD 0 +LOAD 3 +CALL +POPN 2 +POPN 1 +PUSHI 0 +PUSHS "origine" +PUSHL 8 +DUPN 1 +LOAD 0 +LOAD 6 +CALL +POPN 2 +POPN 1 +PUSHI 0 +PUSHL 5 +PUSHL 8 +DUPN 1 +LOAD 0 +LOAD 3 +CALL +POPN 2 +POPN 1 +PUSHI 0 +PUSHI 0 +PUSHL 0 +DUPN 1 +LOAD 0 +LOAD 8 +CALL +POPN 1 +PUSHI 2 +PUSHI 5 +MUL +SUB +PUSHI 3 +SUB +PUSHI 0 +PUSHL 0 +DUPN 1 +LOAD 0 +LOAD 7 +CALL +POPN 1 +PUSHI 0 +PUSHL 1 +DUPN 1 +LOAD 0 +LOAD 4 +CALL +POPN 4 +POPN 1 +PUSHI 0 +PUSHL 5 +PUSHL 1 +DUPN 1 +LOAD 0 +LOAD 3 +CALL +POPN 2 +POPN 1 +PUSHS "On va essayer le clonage:" +DUPN 1 +WRITES +PUSHS "\n" +WRITES +POPN 1 +PUSHL 3 +PUSHI 0 +PUSHL 0 +DUPN 1 +LOAD 0 +LOAD 2 +CALL +POPN 1 +STOREL 3 +PUSHI 0 +PUSHL 6 +PUSHL 3 +DUPN 1 +LOAD 0 +LOAD 3 +CALL +POPN 2 +POPN 1 +PUSHS "p1 isCloned: " +DUPN 1 +WRITES +POPN 1 +PUSHI 0 +PUSHL 0 +DUPN 1 +LOAD 0 +LOAD 5 +CALL +POPN 1 +JZ lbl1 +PUSHS "OK" +DUPN 1 +WRITES +PUSHS "\n" +WRITES +POPN 1 +JUMP lbl2 +lbl1: NOP +PUSHS "KO" +DUPN 1 +WRITES +PUSHS "\n" +WRITES +POPN 1 +lbl2: NOP +PUSHL 4 +PUSHI 0 +PUSHL 3 +DUPN 1 +LOAD 0 +LOAD 2 +CALL +POPN 1 +STOREL 4 +PUSHI 0 +PUSHL 6 +PUSHI 0 +PUSHI 54 +PUSHI 36 +PUSHI 0 +PUSHL 4 +DUPN 1 +LOAD 0 +LOAD 4 +CALL +POPN 4 +DUPN 1 +LOAD 0 +LOAD 3 +CALL +POPN 2 +POPN 1 +PUSHS "Impression de tous les clones de p1:" +DUPN 1 +WRITES +PUSHS "\n" +WRITES +POPN 1 +PUSHI 0 +PUSHL 0 +DUPN 1 +LOAD 0 +LOAD 1 +CALL +POPN 1 +POPN 1 +PUSHS "Fin de l'impression de tous les clones" +DUPN 1 +WRITES +PUSHS "\n" +WRITES +POPN 1 +PUSHS "Valeur du compteur de nombre de points: " +DUPN 1 +WRITES +PUSHS "\n" +WRITES +POPN 1 +PUSHA Point_7_howMany +CALL +STR +DUPN 1 +WRITES +PUSHS "\n" +WRITES +POPN 1 +PUSHL 0 +PUSHI 0 +PUSHI 2 +PUSHI 0 +PUSHI 3 +SUB +PUSHI 0 +PUSHI 0 +PUSHL 0 +DUPN 1 +LOAD 0 +LOAD 2 +CALL +POPN 1 +DUPN 1 +LOAD 0 +LOAD 4 +CALL +POPN 4 +STOREL 0 +PUSHI 0 +PUSHL 5 +PUSHL 0 +DUPN 1 +LOAD 0 +LOAD 3 +CALL +POPN 2 +POPN 1 +PUSHI 0 +PUSHL 5 +PUSHI 0 +PUSHL 8 +DUPN 1 +LOAD 0 +LOAD 2 +CALL +POPN 1 +DUPN 1 +LOAD 0 +LOAD 3 +CALL +POPN 2 +POPN 1 +PUSHS "test(Point, PointColore, PointNoir)" +DUPN 1 +WRITES +PUSHS "\n" +WRITES +POPN 1 +PUSHL 0 +PUSHL 8 +PUSHL 9 +PUSHA Test_4_test +CALL +POPN 1 +PUSHS "test(PointNoir, PointNoir, PointNoir)" +DUPN 1 +WRITES +PUSHS "\n" +WRITES +POPN 1 +PUSHL 9 +PUSHL 9 +PUSHL 9 +PUSHA Test_4_test +CALL +POPN 1 +PUSHL 0 +PUSHL 9 +STOREL 0 +PUSHL 8 +PUSHA Test_5_test2 +CALL +POPN 1 +PUSHL 9 +PUSHA Test_5_test2 +CALL +POPN 1 +PUSHL 8 +PUSHL 9 +STOREL 8 +PUSHS "test(PointNoir, PointNoir, PointNoir)" +DUPN 1 +WRITES +PUSHS "\n" +WRITES +POPN 1 +PUSHL 0 +PUSHL 8 +PUSHL 9 +PUSHA Test_4_test +CALL +POPN 1 +PUSHL 8 +PUSHA Test_5_test2 +CALL +POPN 1 +PUSHL 9 +PUSHA Test_5_test2 +CALL +POPN 1 +PUSHS "\nDone" +DUPN 1 +WRITES +PUSHS "\n" +WRITES +POPN 1 +STOP +-- ----- FUNCTIONS ----- +_CTOR_Point_: NOP +ALLOC 7 +PUSHI 0 +STORE 0 +PUSHN 0 +PUSHL -4 +LOAD 4 +PUSHL -3 +STORE 3 +PUSHL -4 +LOAD 5 +PUSHL -2 +STORE 4 +PUSHL -4 +LOAD 6 +PUSHL -1 +STORE 5 +PUSHL -4 +LOAD 2 +PUSHA Point_4_incr +CALL +STORE 1 +PUSHL -4 +LOAD 3 +PUSHI 0 +STORE 2 +_CTOR_Couleur_: NOP +ALLOC 2 +PUSHI 1 +STORE 0 +PUSHN 0 +PUSHL -2 +LOAD 1 +PUSHL -1 +STORE 0 +PUSHL -2 +LOAD 1 +PUSHI 0 +INF +JZ lbl3 +PUSHL -2 +LOAD 1 +PUSHI 0 +STORE 0 +JUMP lbl4 +lbl3: NOP +PUSHL -2 +LOAD 1 +PUSHI 2 +SUP +JZ lbl5 +PUSHL -2 +LOAD 1 +PUSHI 0 +STORE 0 +JUMP lbl6 +lbl5: NOP +PUSHN 0 +lbl6: NOP +lbl4: NOP +_CTOR_CouleurFactory_: NOP +ALLOC 1 +PUSHI 2 +STORE 0 +PUSHN 0 +_CTOR_PointColore_: NOP +ALLOC 8 +PUSHI 3 +STORE 0 +PUSHL -3 +PUSHL -2 +PUSHS "P-" +PUSHA Point_7_howMany +CALL +STR +CONCAT +PUSHL -4 +PUSHA _CTOR_Point_ +CALL +POPN 4 +PUSHN 0 +PUSHL -4 +LOAD 7 +PUSHL -1 +STORE 6 +_CTOR_PointNoir_: NOP +ALLOC 8 +PUSHI 4 +STORE 0 +PUSHL -2 +PUSHL -1 +PUSHA CouleurFactory_4_noir +CALL +PUSHL -4 +PUSHA _CTOR_PointColore_ +CALL +POPN 4 +PUSHN 0 +_CTOR_DefaultPoint_: NOP +ALLOC 8 +PUSHI 5 +STORE 0 +PUSHI 0 +PUSHI 0 +PUSHA CouleurFactory_5_blanc +CALL +PUSHL -4 +PUSHA _CTOR_PointColore_ +CALL +POPN 4 +PUSHN 0 +_CTOR_Test_: NOP +ALLOC 1 +PUSHI 6 +STORE 0 +PUSHN 0 diff --git a/progs/gn.kat b/progs/gn.kat index a53d560..7e515bf 100644 --- a/progs/gn.kat +++ b/progs/gn.kat @@ -8,7 +8,7 @@ class TriNombre() is { var last: Integer /* Par defaut, on est isole */ var suivant: TriNombre /* valeur arbitraire si last = 1 */ - def TriNombre () is { trinome := 0; } + def TriNombre () is { this.trinome := 0; } def suivant() : TriNombre := this.suivant diff --git a/progs/grandMere.kat b/progs/grandMere.kat index 448cdf6..c7c5ed9 100644 --- a/progs/grandMere.kat +++ b/progs/grandMere.kat @@ -18,7 +18,7 @@ class B() extends A is { class C(v : Integer) extends B is { var vc: Integer def C(v : Integer): B() is { - vc := 3 + this.va + this.vb; + this.vc := 3 + this.va + this.vb; "C::(): ".print(); this.vc.toString().println(); } @@ -33,7 +33,7 @@ class D(v : Integer) extends C is result := this.va + this.vb + this.vc + this.vd; } def D(v : Integer): C(12) is { - vd := this.vc + 4; + this.vd := this.vc + 4; "D::(): ".print(); this.vd.toString().println(); } diff --git a/progs/masking1.kat b/progs/masking1.kat index 6cf12df..9a1c4d8 100644 --- a/progs/masking1.kat +++ b/progs/masking1.kat @@ -1,13 +1,13 @@ class A() is { var v: Integer def f() : Integer := this.v - def A() is { v := 1; } + def A() is { this.v := 1; } } class A2() extends A is { var v: String def g() : String := this.v - def A2() : A() is { v := "coucou"; } + def A2() : A() is { this.v := "coucou"; } } class A3() extends A2 is { @@ -19,7 +19,7 @@ class A3() extends A2 is { ((A2 this).v).println(); this.v.toString().println(); } - def A3() : A2() is { v := 5; } + def A3() : A2() is { this.v := 5; } } class A4() extends A3 is { def z() : Integer := this.v diff --git a/test/test.ml b/test/test.ml index 219a35b..c90360b 100644 --- a/test/test.ml +++ b/test/test.ml @@ -1,22 +1,19 @@ open Utils -let%test_unit "ex1-parse" = - ignore @@ parse_file "../progs/ex1.kat" +let%test "ex1-parse" = + file_ast "../progs/ex1.kat" -let%test_unit "ex1-V3-file-parse" = - ignore @@ parse_file "../progs/ex1-V3.kat" +let%test "gn-file-parse" = + file_ast "../progs/gn.kat" -let%test_unit "gn-file-parse" = - ignore @@ parse_file "../progs/gn.kat" +let%test "grandMere-file-parse" = + file_ast "../progs/grandMere.kat" -let%test_unit "grandMere-file-parse" = - ignore @@ parse_file "../progs/grandMere.kat" +let%test "masking1-file-parse" = + file_ast "../progs/masking1.kat" -let%test_unit "masking1-file-parse" = - ignore @@ parse_file "../progs/masking1.kat" - -let%test_unit "test-file-parse" = - ignore @@ parse_file "../progs/test.kat" +let%test "test-file-parse" = + file_ast "../progs/test.kat" let%test "err1-file-parse" = diff --git a/test/utils.ml b/test/utils.ml index 0f2e69c..766ddb2 100644 --- a/test/utils.ml +++ b/test/utils.ml @@ -20,10 +20,6 @@ let expects_parse_err str = try ignore @@ parse_str str; false with Parser.Error -> true -let file_parse_err file = - try ignore @@ parse_file file; false - with Parser.Error -> true - let expects_ctx_err str = try Contextual.check_all @@ parse_str str; false with Contextual.Contextual_error _ -> true @@ -32,9 +28,16 @@ let expects_syntax_err str = try ignore @@ parse_str str; false with Ast.Syntax_error _ -> true +let expects_ast str = + Contextual.check_all @@ parse_str str; true + +let file_parse_err file = + try ignore @@ parse_file file; false + with Parser.Error -> true + let file_ctx_err file = try Contextual.check_all @@ parse_file file; false with Contextual.Contextual_error _ -> true -let expects_ast str = - Contextual.check_all @@ parse_str str; true +let file_ast file = + Contextual.check_all @@ parse_file file; true