summary refs log tree commit diff stats
path: root/compiler/semmagic.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2013-12-24 01:30:48 +0100
committerAraq <rumpf_a@web.de>2013-12-24 01:30:48 +0100
commit1081c104d06c084e73230d0c7fc73b3824fb4f1d (patch)
treea1861108b9788f961023091d391be7968f187c50 /compiler/semmagic.nim
parentc3b3339e779dfe19ed1891295a763aea47981131 (diff)
parentfeb9af48f1600ce814bc3b62765894ba503ec108 (diff)
downloadNim-1081c104d06c084e73230d0c7fc73b3824fb4f1d.tar.gz
Merge branch 'vm2' of github.com:Araq/Nimrod into vm2
Diffstat (limited to 'compiler/semmagic.nim')
-rw-r--r--compiler/semmagic.nim28
1 files changed, 21 insertions, 7 deletions
diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim
index 88567b10a..aab4c82f5 100644
--- a/compiler/semmagic.nim
+++ b/compiler/semmagic.nim
@@ -32,15 +32,29 @@ proc semInstantiationInfo(c: PContext, n: PNode): PNode =
   result.add(filename)
   result.add(line)
 
+ 
+proc evalTypeTrait(trait: PNode, operand: PType, context: PSym): PNode =
+  let typ = operand.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-1)
+    result.typ = newType(tyInt, context)
+    result.info = trait.info
+  else:
+    internalAssert false
+
 proc semTypeTraits(c: PContext, n: PNode): PNode =
   checkMinSonsLen(n, 2)
-  internalAssert n.sons[1].kind == nkSym
-  let typArg = n.sons[1].sym
-  if typArg.kind == skType or
-    (typArg.kind == skParam and typArg.typ.sonsLen > 0):
-    # This is either a type known to sem or a typedesc
-    # param to a regular proc (again, known at instantiation)
-    result = evalTypeTrait(n[0], n[1], GetCurrOwner())
+  let t = n.sons[1].typ
+  internalAssert t != nil
+  if t.kind == tyTypeDesc and t.len == 0:
+    result = n
+  elif not containsGenericType(t):
+    result = evalTypeTrait(n[0], t, GetCurrOwner())
   else:
     # a typedesc variable, pass unmodified to evals
     result = n