Created
September 2, 2013 06:36
-
-
Save mflamer/6409814 to your computer and use it in GitHub Desktop.
Proposed arity type trait
This file contains 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
#---evals.nim--- | |
proc evalTypeTrait*(trait, operand: PNode, context: PSym): PNode = | |
InternalAssert operand.kind == nkSym | |
let typ = operand.sym.typ.skipTypes({tyTypeDesc}) | |
case trait.sym.name.s.normalize | |
of "name": | |
result = newStrNode(nkStrLit, typ.typeToString(preferName)) | |
result.typ = newType(tyString, context) | |
result.info = trait.info | |
of "arity": | |
result = newIntNode(nkIntLit, typ.n.len) | |
result.typ = newType(tyInt, context) | |
result.info = trait.info | |
else: | |
internalAssert false | |
#---typetraits.nim--- | |
proc arity*(t: typedesc): int {.magic: "TypeTrait".} | |
## Returns the arity of the given type |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment