From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- .../tests/object/bind/missing-super-class.tig | 5 ++++ .../tests/object/good/class-to-different-class.tig | 8 ++++++ tiger-compiler/tests/object/good/class-to-nil.tig | 6 +++++ .../good/empty-class-inheritance-complex.tig | 7 ++++++ .../object/good/empty-class-inheritance-simple.tig | 5 ++++ tiger-compiler/tests/object/good/empty-class.tig | 4 +++ .../object/good/forward-reference-to-class.tig | 14 +++++++++++ tiger-compiler/tests/object/good/funny.tig | 29 ++++++++++++++++++++++ .../tests/object/good/object-renamer.tig | 25 +++++++++++++++++++ tiger-compiler/tests/object/good/override.tig | 28 +++++++++++++++++++++ tiger-compiler/tests/object/good/self.tig | 16 ++++++++++++ .../tests/object/good/simple-class-call-method.tig | 10 ++++++++ .../tests/object/good/simple-class-structlike.tig | 6 +++++ tiger-compiler/tests/object/good/simple-class.tig | 10 ++++++++ .../tests/object/type/bad-member-bindings.tig | 7 ++++++ .../tests/object/type/circular-inheritance.tig | 7 ++++++ .../tests/object/type/class-as-bad-parameter.tig | 7 ++++++ .../object/type/class-equals-different-class.tig | 8 ++++++ .../type/class-greater-than-different-class.tig | 8 ++++++ .../type/class-lower-than-different-class.tig | 8 ++++++ .../type/class-not-equals-different-class.tig | 8 ++++++ tiger-compiler/tests/object/type/class-to-int.tig | 6 +++++ .../tests/object/type/class-to-string.tig | 6 +++++ .../tests/object/type/incompatible-covariance.tig | 13 ++++++++++ 24 files changed, 251 insertions(+) create mode 100755 tiger-compiler/tests/object/bind/missing-super-class.tig create mode 100755 tiger-compiler/tests/object/good/class-to-different-class.tig create mode 100755 tiger-compiler/tests/object/good/class-to-nil.tig create mode 100755 tiger-compiler/tests/object/good/empty-class-inheritance-complex.tig create mode 100755 tiger-compiler/tests/object/good/empty-class-inheritance-simple.tig create mode 100755 tiger-compiler/tests/object/good/empty-class.tig create mode 100644 tiger-compiler/tests/object/good/forward-reference-to-class.tig create mode 100644 tiger-compiler/tests/object/good/funny.tig create mode 100644 tiger-compiler/tests/object/good/object-renamer.tig create mode 100755 tiger-compiler/tests/object/good/override.tig create mode 100644 tiger-compiler/tests/object/good/self.tig create mode 100755 tiger-compiler/tests/object/good/simple-class-call-method.tig create mode 100755 tiger-compiler/tests/object/good/simple-class-structlike.tig create mode 100755 tiger-compiler/tests/object/good/simple-class.tig create mode 100755 tiger-compiler/tests/object/type/bad-member-bindings.tig create mode 100755 tiger-compiler/tests/object/type/circular-inheritance.tig create mode 100755 tiger-compiler/tests/object/type/class-as-bad-parameter.tig create mode 100755 tiger-compiler/tests/object/type/class-equals-different-class.tig create mode 100755 tiger-compiler/tests/object/type/class-greater-than-different-class.tig create mode 100755 tiger-compiler/tests/object/type/class-lower-than-different-class.tig create mode 100755 tiger-compiler/tests/object/type/class-not-equals-different-class.tig create mode 100755 tiger-compiler/tests/object/type/class-to-int.tig create mode 100755 tiger-compiler/tests/object/type/class-to-string.tig create mode 100755 tiger-compiler/tests/object/type/incompatible-covariance.tig (limited to 'tiger-compiler/tests/object') 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 -- cgit v1.2.3