summary refs log tree commit diff stats
path: root/compiler/sigmatch.nim
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2012-10-02 16:45:34 +0300
committerZahary Karadjov <zahary@gmail.com>2012-10-03 01:59:49 +0300
commit9c8bc3a244b4bbcdc56fdd255bb4e1a7ed30f781 (patch)
treec5d561cdd51566a5f46c2c2558b36ffdd24f42b5 /compiler/sigmatch.nim
parent770d4a997eab25a04cdfd83b325491a2e63bea08 (diff)
downloadNim-9c8bc3a244b4bbcdc56fdd255bb4e1a7ed30f781.tar.gz
the `is` operator now works with type classes and type variables
bugfixes:
the DLL tests were failing on Mac OS X, due to an incorrect DynlibFormat
Diffstat (limited to 'compiler/sigmatch.nim')
-rwxr-xr-xcompiler/sigmatch.nim37
1 files changed, 5 insertions, 32 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 82a8c9399..8f1ca5f36 100755
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -11,7 +11,7 @@
 ## the call to overloaded procs, generic procs and operators.
 
 import 
-  intsets, ast, astalgo, semdata, types, msgs, renderer, lookups, semtypinst, 
+  intsets, ast, astalgo, semdata, types, msgs, renderer, lookups, semtypinst,
   magicsys, condsyms, idents, lexer, options
 
 type
@@ -257,37 +257,6 @@ proc tupleRel(c: var TCandidate, f, a: PType): TTypeRelation =
           var y = a.n.sons[i].sym
           if x.name.id != y.name.id: return isNone
 
-proc matchTypeClass(c: var TCandidate, typeClass, t: PType): TTypeRelation =
-  for i in countup(0, typeClass.sonsLen - 1):
-    let req = typeClass.sons[i]
-    var match = req.kind == skipTypes(t, {tyRange, tyGenericInst}).kind
-      
-    if not match:
-      case req.kind
-      of tyGenericBody:
-        if t.kind == tyGenericInst and t.sons[0] == req:
-          match = true
-          put(c.bindings, typeClass, t)
-      of tyTypeClass:
-        match = matchTypeClass(c, req, t) == isGeneric
-      else: nil
-    elif t.kind in {tyObject}:
-      match = sameType(t, req)
-
-    if tfAny in typeClass.flags:
-      if match: return isGeneric
-    else:
-      if not match: return isNone
-
-  # if the loop finished without returning, either all constraints matched
-  # or none of them matched.
-  result = if tfAny in typeClass.flags: isNone else: isGeneric
-
-proc matchTypeClass*(typeClass, typ: PType): bool =
-  var c: TCandidate
-  InitCandidate(c, typeClass)
-  result = matchTypeClass(c, typeClass, typ) == isGeneric
-
 proc procTypeRel(c: var TCandidate, f, a: PType): TTypeRelation =
   proc inconsistentVarTypes(f, a: PType): bool {.inline.} =
     result = f.kind != a.kind and (f.kind == tyVar or a.kind == tyVar)
@@ -330,6 +299,10 @@ proc procTypeRel(c: var TCandidate, f, a: PType): TTypeRelation =
         result = isNone
   else: nil
 
+proc matchTypeClass(c: var TCandidate, f, a: PType): TTypeRelation =
+  result = if matchTypeClass(c.bindings, f, a): isGeneric
+           else: isNone
+
 proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation = 
   # is a subtype of f?
   result = isNone
='#n70'>70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114