tshadow.nim 522 B

123456789101112131415161718192021222324252627282930
  1. discard """
  2. output: '''fish
  3. fish'''
  4. """
  5. import macros
  6. block:
  7. template init(initHook: proc(s: string)) =
  8. proc dostuff =
  9. var s = "fish"
  10. initHook(s)
  11. dostuff()
  12. init do(s: string):
  13. echo s
  14. block:
  15. macro init(initHook: proc(s: string)) =
  16. result = newStmtList(
  17. newProc(name = ident("dostuff"), body = newStmtList(
  18. newVarStmt(ident("s"), newStrLitNode("fish")),
  19. newCall(initHook, ident("s"))
  20. )),
  21. newCall("dostuff")
  22. )
  23. init proc(s: string) =
  24. echo s