diff options
author | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2013-06-10 19:14:36 +0200 |
---|---|---|
committer | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2013-06-10 22:42:16 +0200 |
commit | c7a4412f8ae0edef821fa5d7e64cb200eb4a9830 (patch) | |
tree | 8d745e848dbd4f193c246191edfc982f4e53ff01 /tests/caas/idetools_api.nim | |
parent | 281424ddeda680aeed19d96db7724f92aa6d32c1 (diff) | |
download | Nim-c7a4412f8ae0edef821fa5d7e64cb200eb4a9830.tar.gz |
Adds skMethod example to idetools api test.
Diffstat (limited to 'tests/caas/idetools_api.nim')
-rw-r--r-- | tests/caas/idetools_api.nim | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/caas/idetools_api.nim b/tests/caas/idetools_api.nim index 930d26429..6327f4c22 100644 --- a/tests/caas/idetools_api.nim +++ b/tests/caas/idetools_api.nim @@ -21,3 +21,23 @@ type proc adder(a, b: int): int = result = a + b + +type + PExpr = ref object of TObject ## abstract base class for an expression + PLiteral = ref object of PExpr + x: int + PPlusExpr = ref object of PExpr + a, b: PExpr + +# watch out: 'eval' relies on dynamic binding +method eval(e: PExpr): int = + # override this base method + quit "to override!" + +method eval(e: PLiteral): int = e.x +method eval(e: PPlusExpr): int = eval(e.a) + eval(e.b) + +proc newLit(x: int): PLiteral = PLiteral(x: x) +proc newPlus(a, b: PExpr): PPlusExpr = PPlusExpr(a: a, b: b) + +echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4))) |