Initial Commit
This commit is contained in:
706 files changed
+135430
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import std::io;
|
||||
trait base {
|
||||
def id(&this): i64;
|
||||
def f(&this): i64 { return 1; }
|
||||
def twice(&this): i64 { return this.id() * 2; }
|
||||
}
|
||||
trait keeps: base { def f(&this): i64; }
|
||||
trait owns: base { def f(&this): i64 { return 2; } }
|
||||
trait left: base { def l(&this): i64; }
|
||||
trait right: base { def r(&this): i64; }
|
||||
trait all: left, right {
|
||||
def sum(&this): i64 { return this.twice() + this.l() + this.r(); }
|
||||
}
|
||||
struct z: all { var n: i64; }
|
||||
def z::id(&this): i64 { return this.n; }
|
||||
def z::l(&this): i64 { return 10; }
|
||||
def z::r(&this): i64 { return 100; }
|
||||
def main(): void {
|
||||
val x := z{ n = 3 };
|
||||
val k: &keeps = &x;
|
||||
val o: &owns = &x;
|
||||
val a: &all = &x;
|
||||
val b: &base = a;
|
||||
println($"{k.f()} {o.f()} {a.sum()} {b.twice()} {x.sum()}");
|
||||
}
|
||||
Reference in new issue
Block a user