Since typedesc are exception in macros and they are not implicitly converted to NimNode on macro call, we need some means to perform such conversion on demand. Fortunately it is as simple as declaring new magic "NGetType" proc with typedesc parameter. NOTE: Keeping actual macro exceptional behavior for typedesc is important, since it allows passing typedesc macro parameter to other procs or macros expecting type parameter. If typedesc parameter was implicitly converted, then we would lost this ability.
20 lines
427 B
Nim
20 lines
427 B
Nim
discard """
|
|
msg: '''ObjectTy(Sym(Model), RecList(Sym(name), Sym(password)))
|
|
BracketExpr(Sym(typeDesc), Sym(User))'''
|
|
"""
|
|
import strutils, macros
|
|
|
|
type
|
|
Model = object of RootObj
|
|
User = object of Model
|
|
name : string
|
|
password : string
|
|
|
|
macro testUser: expr =
|
|
return newLit(User.getType.lispRepr)
|
|
|
|
macro testGeneric(T: typedesc[Model]): expr =
|
|
return newLit(T.getType.lispRepr)
|
|
|
|
echo testUser
|
|
echo User.testGeneric
|