Created
January 4, 2022 02:57
-
-
Save geekrelief/7d5238fe59adae279c153c1668a7dd91 to your computer and use it in GitHub Desktop.
getTypeImplEx: A version of `getTypeImpl` that returns the "expressed" type after transformations.
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 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