tbindsym.nim 983 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. discard """
  2. nimout: '''initApple
  3. deinitApple
  4. Coral
  5. enum
  6. redCoral, blackCoral'''
  7. output: '''TFoo
  8. TBar'''
  9. """
  10. # bug #1319
  11. import macros
  12. type
  13. TTextKind = enum
  14. TFoo, TBar
  15. macro test: untyped =
  16. var x = @[TFoo, TBar]
  17. result = newStmtList()
  18. for i in x:
  19. result.add newCall(newIdentNode("echo"),
  20. case i
  21. of TFoo:
  22. bindSym("TFoo")
  23. of TBar:
  24. bindSym("TBar"))
  25. test()
  26. # issue 7827, bindSym power up
  27. {.experimental: "dynamicBindSym".}
  28. type
  29. Apple = ref object
  30. name: string
  31. color: int
  32. weight: int
  33. proc initApple(name: string): Apple =
  34. discard
  35. proc deinitApple(x: Apple) =
  36. discard
  37. macro wrapObject(obj: typed, n: varargs[untyped]): untyped =
  38. let m = n[0]
  39. for x in m:
  40. var z = bindSym x
  41. echo z.repr
  42. wrapObject(Apple):
  43. initApple
  44. deinitApple
  45. type
  46. Coral = enum
  47. redCoral
  48. blackCoral
  49. macro mixer(): untyped =
  50. let m = "Co" & "ral"
  51. let x = bindSym(m)
  52. echo x.repr
  53. echo getType(x).repr
  54. mixer()