summary refs log blame commit diff stats
path: root/tests/vm/tcompiletimetable.nim
blob: df6ead56fc15794bebc11112a376dda8541034f4 (plain) (tree)
1
2
3
4
5
6
7
8
9
10



           

          



          
                              



                                                
               
                   


          

   







                         

          
                                     















                                                       
discard """
  msg: '''2
3
4:2
Got Hi
Got Hey'''
"""

# bug #404

import macros, tables, strtabs

var ZOOT{.compileTime.} = initTable[int, int](2)
var iii {.compiletime.} = 1

macro zoo:stmt=
  ZOOT[iii] = iii*2
  inc iii
  echo iii

zoo
zoo


macro tupleUnpack: stmt =
  var (y,z) = (4, 2)
  echo y, ":", z

tupleUnpack

# bug #903

var x {.compileTime.}: StringTableRef

macro addStuff(stuff, body: expr): stmt {.immediate.} =
  result = newNimNode(nnkStmtList)

  if x.isNil:
    x = newStringTable(modeStyleInsensitive)
  x[$stuff] = ""

macro dump(): stmt =
  result = newNimNode(nnkStmtList)
  for y in x.keys: echo "Got ", y

addStuff("Hey"): echo "Hey"
addStuff("Hi"): echo "Hi"
dump()