summaryrefslogtreecommitdiff
path: root/tiger-compiler/tests/object
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/tests/object
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/tests/object')
-rwxr-xr-xtiger-compiler/tests/object/bind/missing-super-class.tig5
-rwxr-xr-xtiger-compiler/tests/object/good/class-to-different-class.tig8
-rwxr-xr-xtiger-compiler/tests/object/good/class-to-nil.tig6
-rwxr-xr-xtiger-compiler/tests/object/good/empty-class-inheritance-complex.tig7
-rwxr-xr-xtiger-compiler/tests/object/good/empty-class-inheritance-simple.tig5
-rwxr-xr-xtiger-compiler/tests/object/good/empty-class.tig4
-rw-r--r--tiger-compiler/tests/object/good/forward-reference-to-class.tig14
-rw-r--r--tiger-compiler/tests/object/good/funny.tig29
-rw-r--r--tiger-compiler/tests/object/good/object-renamer.tig25
-rwxr-xr-xtiger-compiler/tests/object/good/override.tig28
-rw-r--r--tiger-compiler/tests/object/good/self.tig16
-rwxr-xr-xtiger-compiler/tests/object/good/simple-class-call-method.tig10
-rwxr-xr-xtiger-compiler/tests/object/good/simple-class-structlike.tig6
-rwxr-xr-xtiger-compiler/tests/object/good/simple-class.tig10
-rwxr-xr-xtiger-compiler/tests/object/type/bad-member-bindings.tig7
-rwxr-xr-xtiger-compiler/tests/object/type/circular-inheritance.tig7
-rwxr-xr-xtiger-compiler/tests/object/type/class-as-bad-parameter.tig7
-rwxr-xr-xtiger-compiler/tests/object/type/class-equals-different-class.tig8
-rwxr-xr-xtiger-compiler/tests/object/type/class-greater-than-different-class.tig8
-rwxr-xr-xtiger-compiler/tests/object/type/class-lower-than-different-class.tig8
-rwxr-xr-xtiger-compiler/tests/object/type/class-not-equals-different-class.tig8
-rwxr-xr-xtiger-compiler/tests/object/type/class-to-int.tig6
-rwxr-xr-xtiger-compiler/tests/object/type/class-to-string.tig6
-rwxr-xr-xtiger-compiler/tests/object/type/incompatible-covariance.tig13
24 files changed, 251 insertions, 0 deletions
diff --git a/tiger-compiler/tests/object/bind/missing-super-class.tig b/tiger-compiler/tests/object/bind/missing-super-class.tig
new file mode 100755
index 0000000..f36f54e
--- /dev/null
+++ b/tiger-compiler/tests/object/bind/missing-super-class.tig
@@ -0,0 +1,5 @@
+let
+ /* Super class doesn't exist. */
+ class Z extends Ghost {}
+in
+end \ No newline at end of file
diff --git a/tiger-compiler/tests/object/good/class-to-different-class.tig b/tiger-compiler/tests/object/good/class-to-different-class.tig
new file mode 100755
index 0000000..5327e36
--- /dev/null
+++ b/tiger-compiler/tests/object/good/class-to-different-class.tig
@@ -0,0 +1,8 @@
+let
+ type Cube = class {}
+ type Circle = class {}
+ var cube := new Cube
+ var circle := new Circle
+in
+ cube := circle
+end
diff --git a/tiger-compiler/tests/object/good/class-to-nil.tig b/tiger-compiler/tests/object/good/class-to-nil.tig
new file mode 100755
index 0000000..50d3b3e
--- /dev/null
+++ b/tiger-compiler/tests/object/good/class-to-nil.tig
@@ -0,0 +1,6 @@
+let
+ type Entity = class {}
+ var object := new Entity
+in
+ object := nil
+end
diff --git a/tiger-compiler/tests/object/good/empty-class-inheritance-complex.tig b/tiger-compiler/tests/object/good/empty-class-inheritance-complex.tig
new file mode 100755
index 0000000..1bd1809
--- /dev/null
+++ b/tiger-compiler/tests/object/good/empty-class-inheritance-complex.tig
@@ -0,0 +1,7 @@
+let
+ class A {}
+ class B extends A {}
+ class C extends B {}
+ class D extends A {}
+in
+end \ No newline at end of file
diff --git a/tiger-compiler/tests/object/good/empty-class-inheritance-simple.tig b/tiger-compiler/tests/object/good/empty-class-inheritance-simple.tig
new file mode 100755
index 0000000..e63f366
--- /dev/null
+++ b/tiger-compiler/tests/object/good/empty-class-inheritance-simple.tig
@@ -0,0 +1,5 @@
+let
+ class A {}
+ class B extends A {}
+in
+end \ No newline at end of file
diff --git a/tiger-compiler/tests/object/good/empty-class.tig b/tiger-compiler/tests/object/good/empty-class.tig
new file mode 100755
index 0000000..04bcc4c
--- /dev/null
+++ b/tiger-compiler/tests/object/good/empty-class.tig
@@ -0,0 +1,4 @@
+let
+ class A {}
+in
+end \ No newline at end of file
diff --git a/tiger-compiler/tests/object/good/forward-reference-to-class.tig b/tiger-compiler/tests/object/good/forward-reference-to-class.tig
new file mode 100644
index 0000000..218c379
--- /dev/null
+++ b/tiger-compiler/tests/object/good/forward-reference-to-class.tig
@@ -0,0 +1,14 @@
+let
+ /* A block of types. */
+ class A
+ {
+ /* Valid forward reference to B, defined in the same block
+ as the class enclosing this member. */
+ var b := new B
+ }
+ type t = int
+ class B
+ {
+ }
+in
+end \ No newline at end of file
diff --git a/tiger-compiler/tests/object/good/funny.tig b/tiger-compiler/tests/object/good/funny.tig
new file mode 100644
index 0000000..b43e82b
--- /dev/null
+++ b/tiger-compiler/tests/object/good/funny.tig
@@ -0,0 +1,29 @@
+let
+ class Exp
+ {
+ var id : int := 0
+ method id_get() : int = self.id
+ method accept(v : Visitor) = ()
+ }
+ class AssignExp extends Exp
+ {
+ var expression : string := "var foo := bar"
+ method get_expression() : string = self.expression
+ method set_expression(new_expr : string) = (self.expression = new_expr; ())
+ }
+ class Visitor
+ {
+ method visit(e : Exp) = print_int(e.id_get())
+ }
+ class PrintVisitor extends Visitor
+ {
+ method visit(e : AssignExp) = print(e.get_expression())
+ }
+
+ var exp := new AssignExp
+ var visitor := new PrintVisitor
+in
+ exp.accept(visitor);
+ exp.set_expression("var bar := foo");
+ exp.accept(visitor)
+end \ No newline at end of file
diff --git a/tiger-compiler/tests/object/good/object-renamer.tig b/tiger-compiler/tests/object/good/object-renamer.tig
new file mode 100644
index 0000000..d331249
--- /dev/null
+++ b/tiger-compiler/tests/object/good/object-renamer.tig
@@ -0,0 +1,25 @@
+let
+ class A
+ {
+ var a := 1
+ method k(b : int) : int = b
+ method toto(b : int) : int = self.a + b
+ }
+
+ class B extends A
+ {
+ var c : string := "salut"
+ method k(b : int) : int = b + 2
+ method t(b : int) : int = (print(self.c); self.a)
+ }
+
+ var a : A := new A
+ var b : B := new B
+in
+ a.k(1) + b.k(4);
+ b.t(1);
+ b.toto(2);
+ a.a;
+ b.c;
+ b.a
+end \ No newline at end of file
diff --git a/tiger-compiler/tests/object/good/override.tig b/tiger-compiler/tests/object/good/override.tig
new file mode 100755
index 0000000..550d3cd
--- /dev/null
+++ b/tiger-compiler/tests/object/good/override.tig
@@ -0,0 +1,28 @@
+let
+ class C
+ {
+ var a := 0
+ method m() : int = self.a
+ }
+ class D extends C
+ {
+ var b := 9
+ /* Override C.m(). */
+ method m() : int = self.a + self.b
+ }
+ var d : D := new D
+ /* Valid upcast due to inclusion polymorphism. */
+ var c : C := d
+ in
+ c.a := 42;
+ /* Note that accessing `c.b' is not allowed, since `c' is
+ statically known as a `C', even though it is actually a `D'
+ at run time. */
+ let
+ /* Polymorphic call. */
+ var res := c.m()
+ in
+ print_int(res);
+ print("\n")
+ end
+end \ No newline at end of file
diff --git a/tiger-compiler/tests/object/good/self.tig b/tiger-compiler/tests/object/good/self.tig
new file mode 100644
index 0000000..d7011e5
--- /dev/null
+++ b/tiger-compiler/tests/object/good/self.tig
@@ -0,0 +1,16 @@
+let
+ class self
+ {
+ var self : self := nil
+ method self() : self = self.self
+ }
+
+ var self : self := new self
+
+ class foo
+ {
+ var self := self
+ method self(self : self) : self = self.self
+ }
+in
+end \ No newline at end of file
diff --git a/tiger-compiler/tests/object/good/simple-class-call-method.tig b/tiger-compiler/tests/object/good/simple-class-call-method.tig
new file mode 100755
index 0000000..ab9c063
--- /dev/null
+++ b/tiger-compiler/tests/object/good/simple-class-call-method.tig
@@ -0,0 +1,10 @@
+let
+ class B
+ {
+ var a := 42
+ method m() : int = self.a
+ }
+ var b := new B
+in
+ b.m()
+end \ No newline at end of file
diff --git a/tiger-compiler/tests/object/good/simple-class-structlike.tig b/tiger-compiler/tests/object/good/simple-class-structlike.tig
new file mode 100755
index 0000000..cc25e2f
--- /dev/null
+++ b/tiger-compiler/tests/object/good/simple-class-structlike.tig
@@ -0,0 +1,6 @@
+let
+ class A {
+ var a := 5
+ }
+in
+end \ No newline at end of file
diff --git a/tiger-compiler/tests/object/good/simple-class.tig b/tiger-compiler/tests/object/good/simple-class.tig
new file mode 100755
index 0000000..ce530a2
--- /dev/null
+++ b/tiger-compiler/tests/object/good/simple-class.tig
@@ -0,0 +1,10 @@
+let
+ class B
+ {
+ var a := 42
+ method m() : int = self.a
+ }
+ var b := new B
+in
+ b.a := 51
+end \ No newline at end of file
diff --git a/tiger-compiler/tests/object/type/bad-member-bindings.tig b/tiger-compiler/tests/object/type/bad-member-bindings.tig
new file mode 100755
index 0000000..86f48ea
--- /dev/null
+++ b/tiger-compiler/tests/object/type/bad-member-bindings.tig
@@ -0,0 +1,7 @@
+let
+ type C = class {}
+ var c := new C
+in
+ c.missing_method();
+ c.missing_attribute
+end \ No newline at end of file
diff --git a/tiger-compiler/tests/object/type/circular-inheritance.tig b/tiger-compiler/tests/object/type/circular-inheritance.tig
new file mode 100755
index 0000000..b5c7d20
--- /dev/null
+++ b/tiger-compiler/tests/object/type/circular-inheritance.tig
@@ -0,0 +1,7 @@
+let
+ class A extends C {}
+ class B extends A {}
+ class C extends B {}
+in
+ ()
+end
diff --git a/tiger-compiler/tests/object/type/class-as-bad-parameter.tig b/tiger-compiler/tests/object/type/class-as-bad-parameter.tig
new file mode 100755
index 0000000..32b66a2
--- /dev/null
+++ b/tiger-compiler/tests/object/type/class-as-bad-parameter.tig
@@ -0,0 +1,7 @@
+let
+ type Entity = class {}
+ var a := new Entity
+ var b := new Entity
+in
+ strcmp(a, b)
+end
diff --git a/tiger-compiler/tests/object/type/class-equals-different-class.tig b/tiger-compiler/tests/object/type/class-equals-different-class.tig
new file mode 100755
index 0000000..16bab53
--- /dev/null
+++ b/tiger-compiler/tests/object/type/class-equals-different-class.tig
@@ -0,0 +1,8 @@
+let
+ type Cube = class {}
+ type Circle = class {}
+ var cube := new Cube
+ var circle := new Circle
+in
+ cube = circle
+end
diff --git a/tiger-compiler/tests/object/type/class-greater-than-different-class.tig b/tiger-compiler/tests/object/type/class-greater-than-different-class.tig
new file mode 100755
index 0000000..367aea8
--- /dev/null
+++ b/tiger-compiler/tests/object/type/class-greater-than-different-class.tig
@@ -0,0 +1,8 @@
+let
+ type Cube = class {}
+ type Circle = class {}
+ var cube := new Cube
+ var circle := new Circle
+in
+ cube > circle
+end
diff --git a/tiger-compiler/tests/object/type/class-lower-than-different-class.tig b/tiger-compiler/tests/object/type/class-lower-than-different-class.tig
new file mode 100755
index 0000000..e486599
--- /dev/null
+++ b/tiger-compiler/tests/object/type/class-lower-than-different-class.tig
@@ -0,0 +1,8 @@
+let
+ type Cube = class {}
+ type Circle = class {}
+ var cube := new Cube
+ var circle := new Circle
+in
+ cube < circle
+end
diff --git a/tiger-compiler/tests/object/type/class-not-equals-different-class.tig b/tiger-compiler/tests/object/type/class-not-equals-different-class.tig
new file mode 100755
index 0000000..7a38a05
--- /dev/null
+++ b/tiger-compiler/tests/object/type/class-not-equals-different-class.tig
@@ -0,0 +1,8 @@
+let
+ type Cube = class {}
+ type Circle = class {}
+ var cube := new Cube
+ var circle := new Circle
+in
+ cube <> circle
+end
diff --git a/tiger-compiler/tests/object/type/class-to-int.tig b/tiger-compiler/tests/object/type/class-to-int.tig
new file mode 100755
index 0000000..a69e5a4
--- /dev/null
+++ b/tiger-compiler/tests/object/type/class-to-int.tig
@@ -0,0 +1,6 @@
+let
+ type Entity = class {}
+ var object := new Entity
+in
+ object := 42
+end
diff --git a/tiger-compiler/tests/object/type/class-to-string.tig b/tiger-compiler/tests/object/type/class-to-string.tig
new file mode 100755
index 0000000..7630936
--- /dev/null
+++ b/tiger-compiler/tests/object/type/class-to-string.tig
@@ -0,0 +1,6 @@
+let
+ type Entity = class {}
+ var object := new Entity
+in
+ object := "string"
+end
diff --git a/tiger-compiler/tests/object/type/incompatible-covariance.tig b/tiger-compiler/tests/object/type/incompatible-covariance.tig
new file mode 100755
index 0000000..0ef37f5
--- /dev/null
+++ b/tiger-compiler/tests/object/type/incompatible-covariance.tig
@@ -0,0 +1,13 @@
+let
+ class Shape {}
+ class Square extends Shape {}
+ class Circle extends Shape {}
+
+ function update_radius(circle : Circle) = ()
+
+ var a := new Square
+ var b := new Circle
+in
+ update_radius(b);
+ update_radius(a)
+end