tcompiletimetable.nim 700 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. discard """
  2. nimout: '''2
  3. 3
  4. 4:2
  5. Got Hi
  6. Got Hey'''
  7. """
  8. # bug #404
  9. import macros, tables, strtabs
  10. var ZOOT{.compileTime.} = initTable[int, int](2)
  11. var iii {.compiletime.} = 1
  12. macro zoo: untyped =
  13. ZOOT[iii] = iii*2
  14. inc iii
  15. echo iii
  16. zoo
  17. zoo
  18. macro tupleUnpack: untyped =
  19. var (y,z) = (4, 2)
  20. echo y, ":", z
  21. tupleUnpack
  22. # bug #903
  23. var x {.compileTime.}: StringTableRef
  24. macro addStuff(stuff, body: untyped): untyped =
  25. result = newNimNode(nnkStmtList)
  26. if x.isNil:
  27. x = newStringTable(modeStyleInsensitive)
  28. x[$stuff] = ""
  29. macro dump(): untyped =
  30. result = newNimNode(nnkStmtList)
  31. for y in x.keys: echo "Got ", y
  32. addStuff("Hey"): echo "Hey"
  33. addStuff("Hi"): echo "Hi"
  34. dump()