tmatrix.nim 519 B

123456789101112131415161718192021222324252627282930
  1. discard """
  2. output: "21"
  3. """
  4. import macros
  5. type
  6. TMat = object
  7. dummy: int
  8. proc `*`(a, b: TMat): TMat = nil
  9. proc `+`(a, b: TMat): TMat = nil
  10. proc `-`(a, b: TMat): TMat = nil
  11. proc `$`(a: TMat): string = result = $a.dummy
  12. proc mat21(): TMat =
  13. result.dummy = 21
  14. macro optOps{ (`+`|`-`|`*`) ** a }(a: TMat): untyped =
  15. echo treeRepr(a)
  16. result = newCall(bindSym"mat21")
  17. #macro optPlus{ `+` * a }(a: varargs[TMat]): expr =
  18. # result = newIntLitNode(21)
  19. var x, y, z: TMat
  20. echo x + y * z - x
  21. #echo x + y + z