Skip to content

Instantly share code, notes, and snippets.

@geekrelief
Created January 4, 2022 02:57
Show Gist options
  • Save geekrelief/7d5238fe59adae279c153c1668a7dd91 to your computer and use it in GitHub Desktop.
Save geekrelief/7d5238fe59adae279c153c1668a7dd91 to your computer and use it in GitHub Desktop.
getTypeImplEx: A version of `getTypeImpl` that returns the "expressed" type after transformations.
import std / macros
type
Vec[N: static[int], T] = object
arr: array[N, T]
Vec4[T] = Vec[4, T]
Vec4f = Vec4[float32]
var a: Vec4f
proc isTypeDesc(n: NimNode): bool =
var t = n.getType
t.kind == nnkBracketExpr and t[0].kind == nnkSym and t[0].strVal == "typeDesc"
proc getTypeImplEx(n: NimNode): NimNode =
if n.isTypeDesc():
n.getTypeImpl[1].getTypeImpl
else:
n.getTypeImpl
macro test(t: typed) =
expectKind t, nnkSym
echo t.getImpl.treeRepr
var tyImpl = t.getTypeImplEx()
echo tyImpl.treeRepr
test(a)
test(Vec4f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment