Last active
August 29, 2015 14:16
-
-
Save fowlmouth/9c40de9a3700868a7419 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BracketExpr(Sym(typeDesc), Sym(test_obj)) | |
ObjectTy(Empty(), RecList(Sym(x), Sym(y), Sym(z), Sym(a))) | |
x:int | |
y:float | |
z:string | |
a:array[range[0, 4], int] | |
BracketExpr(Sym(typeDesc), BracketExpr(Sym(array), BracketExpr(Sym(range), IntLi | |
t(0), IntLit(4)), Sym(int))) | |
BracketExpr(Sym(typeDesc), BracketExpr(Sym(ref), Sym(test_ref:ObjectType))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import macros | |
type | |
test_obj = object | |
x: int | |
y: float | |
z: string | |
a: test_arr | |
test_arr = array[5, int] | |
test_ref = ref object of RootObj | |
y: int | |
from strutils import repeatChar | |
macro showType (t:stmt): stmt = | |
var ty = getType(t) | |
var indentation = 0 | |
template indent: expr = repeatChar(indentation*2, ' ') | |
while ty[1].kind == nnkSym and indentation < 5: | |
echo indent, lispRepr(ty) | |
ty = getType(ty[1]) | |
indentation += 1 | |
echo indent, lispRepr(ty) | |
if ty.kind == nnkObjectTy and ty[1].kind == nnkRecList: | |
# show fields | |
for child in ty[1].children: | |
echo indent, child,":", getType(child).repr | |
echo "" | |
showType test_obj | |
showType test_arr | |
showType test_ref | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment