summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-07-29 01:25:05 +0200
committerAraq <rumpf_a@web.de>2011-07-29 01:25:05 +0200
commitdce8949b9b05af3bac9d5ec0866b99ef22f78384 (patch)
treec35532d6c90cd7d056d026494819fd4fa3f06a34 /compiler
parent68d7c61c2424ec1b6a1cf6886375d75f308fedbe (diff)
downloadNim-dce8949b9b05af3bac9d5ec0866b99ef22f78384.tar.gz
bugfix: 'final' not passed to generic
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/ast.nim20
-rwxr-xr-xcompiler/ccgtypes.nim6
-rwxr-xr-xcompiler/lists.nim65
-rwxr-xr-xcompiler/ropes.nim4
-rwxr-xr-xcompiler/semexprs.nim2
-rwxr-xr-xcompiler/semtypinst.nim15
6 files changed, 50 insertions, 62 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index f176f6eb1..58ef9f6c2 100755
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -625,13 +625,11 @@ proc ValueToString*(a: PNode): string
 const 
   debugIds* = false
 
-proc registerID*(id: PIdObj)
-# implementation
+when debugIds:
+  var usedIds: TIntSet
 
-var usedIds: TIntSet
-
-proc registerID(id: PIdObj) = 
-  if debugIDs: 
+proc registerID*(id: PIdObj) = 
+  when debugIDs: 
     if (id.id == - 1) or ContainsOrIncl(usedIds, id.id): 
       InternalError("ID already used: " & $(id.id))
   
@@ -761,7 +759,7 @@ proc NewType(kind: TTypeKind, owner: PSym): PType =
   result.size = - 1
   result.align = 2            # default alignment
   result.id = getID()
-  if debugIds: 
+  when debugIds: 
     RegisterId(result)        
   #if result.id < 2000 then
   #  MessageOut(typeKindToStr[kind] & ' has id: ' & toString(result.id))
@@ -784,7 +782,7 @@ proc copyType(t: PType, owner: PSym, keepId: bool): PType =
     result.id = t.id
   else: 
     result.id = getID()
-    if debugIds: RegisterId(result)
+    when debugIds: RegisterId(result)
   result.sym = t.sym          # backend-info should not be copied
   
 proc copySym(s: PSym, keepId: bool = false): PSym = 
@@ -796,7 +794,7 @@ proc copySym(s: PSym, keepId: bool = false): PSym =
     result.id = s.id
   else: 
     result.id = getID()
-    if debugIds: RegisterId(result)
+    when debugIds: RegisterId(result)
   result.flags = s.flags
   result.magic = s.magic
   copyStrTable(result.tab, s.tab)
@@ -816,7 +814,7 @@ proc NewSym(symKind: TSymKind, Name: PIdent, owner: PSym): PSym =
   result.owner = owner
   result.offset = - 1
   result.id = getID()
-  if debugIds: 
+  when debugIds: 
     RegisterId(result)
   #if result.id < 2000:
   #  MessageOut(name.s & " has id: " & toString(result.id))
@@ -1005,4 +1003,4 @@ proc getStrOrChar*(a: PNode): string =
     internalError(a.info, "getStrOrChar")
     result = ""
   
-if debugIDs: usedIds = InitIntSet()
+when debugIDs: usedIds = InitIntSet()
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim
index ddaeed729..7237fec8b 100755
--- a/compiler/ccgtypes.nim
+++ b/compiler/ccgtypes.nim
@@ -152,10 +152,10 @@ proc getGlobalTempName(): PRope =
   inc(gId)
 
 proc ccgIntroducedPtr(s: PSym): bool = 
-  var pt = s.typ
+  var pt = skipTypes(s.typ, abstractInst)
   assert skResult != s.kind
   case pt.Kind
-  of tyObject: 
+  of tyObject:
     # XXX quick hack floatSize*2 for the pegs module under 64bit
     if (optByRef in s.options) or (getSize(pt) > platform.floatSize * 2): 
       result = true           # requested anyway
@@ -352,7 +352,7 @@ proc getRecordDesc(m: BModule, typ: PType, name: PRope,
   var hasField = false
   if typ.kind == tyObject: 
     if typ.sons[0] == nil: 
-      if typ.sym != nil and sfPure in typ.sym.flags or tfFinal in typ.flags: 
+      if (typ.sym != nil and sfPure in typ.sym.flags) or tfFinal in typ.flags: 
         result = ropecg(m, "struct $1 {$n", [name])
       else: 
         result = ropecg(m, "struct $1 {$n#TNimType* m_type;$n", [name])
diff --git a/compiler/lists.nim b/compiler/lists.nim
index b4610ab2f..b23dfd071 100755
--- a/compiler/lists.nim
+++ b/compiler/lists.nim
@@ -24,23 +24,12 @@ type
 
   TCompareProc* = proc (entry: PListEntry, closure: Pointer): bool
 
-proc InitLinkedList*(list: var TLinkedList)
-proc Append*(list: var TLinkedList, entry: PListEntry)
-proc Prepend*(list: var TLinkedList, entry: PListEntry)
-proc Remove*(list: var TLinkedList, entry: PListEntry)
-proc InsertBefore*(list: var TLinkedList, pos, entry: PListEntry)
-proc Find*(list: TLinkedList, fn: TCompareProc, closure: Pointer): PListEntry
-proc AppendStr*(list: var TLinkedList, data: string)
-proc IncludeStr*(list: var TLinkedList, data: string): bool
-proc PrependStr*(list: var TLinkedList, data: string)
-# implementation
-
-proc InitLinkedList(list: var TLinkedList) = 
+proc InitLinkedList*(list: var TLinkedList) = 
   list.Counter = 0
   list.head = nil
   list.tail = nil
 
-proc Append(list: var TLinkedList, entry: PListEntry) = 
+proc Append*(list: var TLinkedList, entry: PListEntry) = 
   Inc(list.counter)
   entry.next = nil
   entry.prev = list.tail
@@ -50,28 +39,38 @@ proc Append(list: var TLinkedList, entry: PListEntry) =
   list.tail = entry
   if list.head == nil: list.head = entry
   
-proc newStrEntry(data: string): PStrEntry = 
-  new(result)
-  result.data = data
-
-proc AppendStr(list: var TLinkedList, data: string) = 
-  append(list, newStrEntry(data))
-
-proc PrependStr(list: var TLinkedList, data: string) = 
-  prepend(list, newStrEntry(data))
-
 proc Contains*(list: TLinkedList, data: string): bool = 
   var it = list.head
   while it != nil: 
     if PStrEntry(it).data == data: 
       return true
     it = it.next
+  
+proc newStrEntry(data: string): PStrEntry = 
+  new(result)
+  result.data = data
 
-proc IncludeStr(list: var TLinkedList, data: string): bool = 
+proc AppendStr*(list: var TLinkedList, data: string) = 
+  append(list, newStrEntry(data))
+
+proc IncludeStr*(list: var TLinkedList, data: string): bool = 
   if Contains(list, data): return true
   AppendStr(list, data)       # else: add to list
 
-proc InsertBefore(list: var TLinkedList, pos, entry: PListEntry) = 
+proc Prepend*(list: var TLinkedList, entry: PListEntry) = 
+  Inc(list.counter)
+  entry.prev = nil
+  entry.next = list.head
+  if list.head != nil: 
+    assert(list.head.prev == nil)
+    list.head.prev = entry
+  list.head = entry
+  if list.tail == nil: list.tail = entry
+
+proc PrependStr*(list: var TLinkedList, data: string) = 
+  prepend(list, newStrEntry(data))
+
+proc InsertBefore*(list: var TLinkedList, pos, entry: PListEntry) = 
   assert(pos != nil)
   if pos == list.head: 
     prepend(list, entry)
@@ -81,18 +80,8 @@ proc InsertBefore(list: var TLinkedList, pos, entry: PListEntry) =
     entry.prev = pos.prev
     if pos.prev != nil: pos.prev.next = entry
     pos.prev = entry
-
-proc Prepend(list: var TLinkedList, entry: PListEntry) = 
-  Inc(list.counter)
-  entry.prev = nil
-  entry.next = list.head
-  if list.head != nil: 
-    assert(list.head.prev == nil)
-    list.head.prev = entry
-  list.head = entry
-  if list.tail == nil: list.tail = entry
-  
-proc Remove(list: var TLinkedList, entry: PListEntry) = 
+ 
+proc Remove*(list: var TLinkedList, entry: PListEntry) = 
   Dec(list.counter)
   if entry == list.tail: 
     list.tail = entry.prev
@@ -101,7 +90,7 @@ proc Remove(list: var TLinkedList, entry: PListEntry) =
   if entry.next != nil: entry.next.prev = entry.prev
   if entry.prev != nil: entry.prev.next = entry.next
   
-proc Find(list: TLinkedList, fn: TCompareProc, closure: Pointer): PListEntry = 
+proc Find*(list: TLinkedList, fn: TCompareProc, closure: Pointer): PListEntry = 
   result = list.head
   while result != nil: 
     if fn(result, closure): return 
diff --git a/compiler/ropes.nim b/compiler/ropes.nim
index 36ac3ecf7..9b8a8466c 100755
--- a/compiler/ropes.nim
+++ b/compiler/ropes.nim
@@ -49,8 +49,8 @@
 #  The 'con' operator is associative! This does not matter however for
 #  the algorithms we use for ropes.
 #
-#  Note that the left and right pointers are not needed for leafs.
-#  Leafs have relatively high memory overhead (~30 bytes on a 32
+#  Note that the left and right pointers are not needed for leaves.
+#  Leaves have relatively high memory overhead (~30 bytes on a 32
 #  bit machines) and we produce many of them. This is why we cache and
 #  share leaves accross different rope trees.
 #  To cache them they are inserted in another tree, a splay tree for best
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 959a48267..28076754f 100755
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -480,7 +480,7 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
     # we assume that a procedure that calls something indirectly 
     # has side-effects:
     if tfNoSideEffect notin t.flags: incl(c.p.owner.flags, sfSideEffect)
-  else: 
+  else:
     result = overloadedCallOpr(c, n)
     # Now that nkSym does not imply an iteration over the proc/iterator space,
     # the old ``prc`` (which is likely an nkIdent) has to be restored:
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim
index e5f573248..fe45e7517 100755
--- a/compiler/semtypinst.nim
+++ b/compiler/semtypinst.nim
@@ -7,7 +7,7 @@
 #    distribution, for details about the copyright.
 #
 
-# This module does the instantiation of generic procs and types.
+# This module does the instantiation of generic types.
 
 import ast, astalgo, msgs, types, semdata
 
@@ -92,24 +92,24 @@ proc lookupTypeVar(cl: TReplTypeVars, t: PType): PType =
     InternalError(cl.info, "substitution with generic parameter")
   
 proc ReplaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType = 
-  var body, newbody, x, header: PType
   result = t
   if t == nil: return 
   case t.kind
   of tyGenericParam: 
     result = lookupTypeVar(cl, t)
   of tyGenericInvokation: 
-    body = t.sons[0]
+    var body = t.sons[0]
     if body.kind != tyGenericBody: InternalError(cl.info, "no generic body")
-    header = nil
-    for i in countup(1, sonsLen(t) - 1): 
+    var header: PType = nil
+    for i in countup(1, sonsLen(t) - 1):
+      var x: PType
       if t.sons[i].kind == tyGenericParam: 
         x = lookupTypeVar(cl, t.sons[i])
         if header == nil: header = copyType(t, t.owner, false)
         header.sons[i] = x
       else: 
         x = t.sons[i]
-      idTablePut(cl.typeMap, body.sons[i - 1], x)
+      idTablePut(cl.typeMap, body.sons[i-1], x)
     if header == nil: header = t
     result = searchInstTypes(gInstTypes, header)
     if result != nil: return 
@@ -119,7 +119,8 @@ proc ReplaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType =
       # but we already raised an error!
       addSon(result, header.sons[i])
     idTablePut(gInstTypes, header, result)
-    newbody = ReplaceTypeVarsT(cl, lastSon(body))
+    var newbody = ReplaceTypeVarsT(cl, lastSon(body))
+    newbody.flags = newbody.flags + t.flags + body.flags
     newbody.n = ReplaceTypeVarsN(cl, lastSon(body).n)
     addSon(result, newbody)   
     #writeln(output, ropeToStr(Typetoyaml(newbody)));