summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2013-06-03 01:21:21 +0200
committerAraq <rumpf_a@web.de>2013-06-03 01:21:21 +0200
commit865a43050d17bef796da956f080913076cf8e866 (patch)
tree446d063a1fddc9d182d0373cea3eaf8b5fca4c8a /compiler
parentdcff5571a2d4cf4b02a2b8434e84fee84a395688 (diff)
downloadNim-865a43050d17bef796da956f080913076cf8e866.tar.gz
fixes #385
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ast.nim33
-rw-r--r--compiler/sigmatch.nim21
2 files changed, 50 insertions, 4 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index e69b83181..6e5a17d99 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -920,7 +920,10 @@ proc discardSons(father: PNode) =
   father.sons = nil
 
 when defined(useNodeIds):
-  const nodeIdToDebug = 140600
+  const nodeIdToDebug = 612777 # 612794
+  #612840 # 612905 # 614635 # 614637 # 614641
+  # 423408
+  #429107 # 430443 # 441048 # 441090 # 441153
   var gNodeId: int
 
 proc newNode(kind: TNodeKind): PNode = 
@@ -933,6 +936,7 @@ proc newNode(kind: TNodeKind): PNode =
   when defined(useNodeIds):
     result.id = gNodeId
     if result.id == nodeIdToDebug:
+      echo "KIND ", result.kind
       writeStackTrace()
     inc gNodeId
 
@@ -973,6 +977,12 @@ proc newNodeI(kind: TNodeKind, info: TLineInfo): PNode =
   new(result)
   result.kind = kind
   result.info = info
+  when defined(useNodeIds):
+    result.id = gNodeId
+    if result.id == nodeIdToDebug:
+      echo "KIND ", result.kind
+      writeStackTrace()
+    inc gNodeId
 
 proc newNodeI*(kind: TNodeKind, info: TLineInfo, children: int): PNode =
   new(result)
@@ -980,6 +990,12 @@ proc newNodeI*(kind: TNodeKind, info: TLineInfo, children: int): PNode =
   result.info = info
   if children > 0:
     newSeq(result.sons, children)
+  when defined(useNodeIds):
+    result.id = gNodeId
+    if result.id == nodeIdToDebug:
+      echo "KIND ", result.kind
+      writeStackTrace()
+    inc gNodeId
 
 proc newNode*(kind: TNodeKind, info: TLineInfo, sons: TNodeSeq = @[],
              typ: PType = nil): PNode =
@@ -989,6 +1005,12 @@ proc newNode*(kind: TNodeKind, info: TLineInfo, sons: TNodeSeq = @[],
   result.typ = typ
   # XXX use shallowCopy here for ownership transfer:
   result.sons = sons
+  when defined(useNodeIds):
+    result.id = gNodeId
+    if result.id == nodeIdToDebug:
+      echo "KIND ", result.kind
+      writeStackTrace()
+    inc gNodeId
 
 proc newNodeIT(kind: TNodeKind, info: TLineInfo, typ: PType): PNode = 
   result = newNode(kind)
@@ -1178,6 +1200,9 @@ proc copyNode(src: PNode): PNode =
   result.info = src.info
   result.typ = src.typ
   result.flags = src.flags * PersistentNodeFlags
+  when defined(useNodeIds):
+    if result.id == nodeIdToDebug:
+      echo "COMES FROM ", src.id
   case src.Kind
   of nkCharLit..nkUInt64Lit: result.intVal = src.intVal
   of nkFloatLit..nkFloat128Lit: result.floatVal = src.floatVal
@@ -1193,6 +1218,9 @@ proc shallowCopy*(src: PNode): PNode =
   result.info = src.info
   result.typ = src.typ
   result.flags = src.flags * PersistentNodeFlags
+  when defined(useNodeIds):
+    if result.id == nodeIdToDebug:
+      echo "COMES FROM ", src.id
   case src.Kind
   of nkCharLit..nkUInt64Lit: result.intVal = src.intVal
   of nkFloatLit..nkFloat128Lit: result.floatVal = src.floatVal
@@ -1209,6 +1237,9 @@ proc copyTree(src: PNode): PNode =
   result.info = src.info
   result.typ = src.typ
   result.flags = src.flags * PersistentNodeFlags
+  when defined(useNodeIds):
+    if result.id == nodeIdToDebug:
+      echo "COMES FROM ", src.id
   case src.Kind
   of nkCharLit..nkUInt64Lit: result.intVal = src.intVal
   of nkFloatLit..nkFloat128Lit: result.floatVal = src.floatVal
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 4ca3e9d43..b90e73a64 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -851,6 +851,20 @@ proc prepareNamedParam(a: PNode) =
     var info = a.sons[0].info
     a.sons[0] = newIdentNode(considerAcc(a.sons[0]), info)
 
+proc arrayConstr(c: PContext, n: PNode): PType =
+  result = newTypeS(tyArrayConstr, c)
+  rawAddSon(result, makeRangeType(c, 0, 0, n.info))
+  addSonSkipIntLit(result, skipTypes(n.typ, {tyGenericInst, tyVar, tyOrdinal}))
+
+proc arrayConstr(c: PContext, info: TLineInfo): PType =
+  result = newTypeS(tyArrayConstr, c)
+  rawAddSon(result, makeRangeType(c, 0, -1, info))
+  rawAddSon(result, newTypeS(tyEmpty, c)) # needs an empty basetype!
+
+proc incrIndexType(t: PType) =
+  assert t.kind == tyArrayConstr
+  inc t.sons[0].n.sons[1].intVal
+
 proc matchesAux(c: PContext, n, nOrig: PNode,
                 m: var TCandidate, marker: var TIntSet) = 
   template checkConstraint(n: expr) {.immediate, dirty.} =
@@ -901,7 +915,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
       checkConstraint(n.sons[a].sons[1])
       if m.baseTypeMatch: 
         assert(container == nil)
-        container = newNodeI(nkBracket, n.sons[a].info)
+        container = newNodeIT(nkBracket, n.sons[a].info, arrayConstr(c, arg))
         addSon(container, arg)
         setSon(m.call, formal.position + 1, container)
         if f != formalLen - 1: container = nil
@@ -927,6 +941,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
                                     n.sons[a], nOrig.sons[a])
           if (arg != nil) and m.baseTypeMatch and (container != nil):
             addSon(container, arg)
+            incrIndexType(container.typ)
           else:
             m.state = csNoMatch
             return
@@ -952,7 +967,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
           return
         if m.baseTypeMatch:
           assert(container == nil)
-          container = newNodeI(nkBracket, n.sons[a].info)
+          container = newNodeIT(nkBracket, n.sons[a].info, arrayConstr(c, arg))
           addSon(container, arg)
           setSon(m.call, formal.position + 1, 
                  implicitConv(nkHiddenStdConv, formal.typ, container, m, c))
@@ -985,7 +1000,7 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
     if not ContainsOrIncl(marker, formal.position): 
       if formal.ast == nil:
         if formal.typ.kind == tyVarargs:
-          var container = newNodeI(nkBracket, n.info)
+          var container = newNodeIT(nkBracket, n.info, arrayConstr(c, n.info))
           addSon(m.call, implicitConv(nkHiddenStdConv, formal.typ,
                                       container, m, c))
         else: