ttypenodes.nim 430 B

1234567891011121314151617
  1. import macros
  2. macro makeEnum(): untyped =
  3. newTree(nnkEnumTy, newEmptyNode(), ident"a", ident"b", ident"c")
  4. macro makeObject(): untyped =
  5. newTree(nnkObjectTy, newEmptyNode(), newEmptyNode(), newTree(nnkRecList,
  6. newTree(nnkIdentDefs, ident"x", ident"y", ident"int", newEmptyNode())))
  7. type
  8. Foo = makeEnum()
  9. Bar = makeObject()
  10. doAssert {a, b, c} is set[Foo]
  11. let bar = Bar(x: 3, y: 4)
  12. doAssert (bar.x, bar.y) == (3, 4)