summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2013-05-27 23:16:56 +0200
committerAraq <rumpf_a@web.de>2013-05-27 23:16:56 +0200
commitc67abd7e61764c681c4ef472996b8d01269fce83 (patch)
treec14155e848197e56d7db09cfd3b5285e222c772b
parente1b668c868dbc647bb5da98d8e4769c2c9b351fd (diff)
downloadNim-c67abd7e61764c681c4ef472996b8d01269fce83.tar.gz
Revert "more test made green"
This reverts commit 911e6e710f28f454cf8bc1bb493c1a28c4694b76.
-rw-r--r--compiler/ast.nim3
-rw-r--r--compiler/lambdalifting.nim2
-rw-r--r--compiler/seminst.nim37
-rw-r--r--compiler/semtypes.nim2
-rw-r--r--tests/compile/tobjects.nim86
-rw-r--r--tests/compile/toverprc.nim55
6 files changed, 89 insertions, 96 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 00e4b3bda..5f3ce2613 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -1285,8 +1285,7 @@ proc getStrOrChar*(a: PNode): string =
 proc isGenericRoutine*(s: PSym): bool = 
   case s.kind
   of skProc, skTemplate, skMacro, skIterator, skMethod, skConverter:
-    result = sfFromGeneric in s.flags or
-             (s.ast != nil and s.ast[genericParamsPos].kind != nkEmpty)
+    result = sfFromGeneric in s.flags
   else: nil
 
 proc isRoutine*(s: PSym): bool {.inline.} =
diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim
index 9a40b350e..163ea4136 100644
--- a/compiler/lambdalifting.nim
+++ b/compiler/lambdalifting.nim
@@ -220,7 +220,7 @@ proc getHiddenParam(routine: PSym): PSym =
 
 proc isInnerProc(s, outerProc: PSym): bool {.inline.} =
   result = s.kind in {skProc, skMethod, skConverter} and
-    s.owner == outerProc
+    s.owner == outerProc and not isGenericRoutine(s)
   #s.typ.callConv == ccClosure
 
 proc addClosureParam(i: PInnerContext, e: PEnv) =
diff --git a/compiler/seminst.nim b/compiler/seminst.nim
index 15be33261..ed842d98e 100644
--- a/compiler/seminst.nim
+++ b/compiler/seminst.nim
@@ -91,8 +91,17 @@ proc instantiateBody(c: PContext, n: PNode, result: PSym) =
     addDecl(c, result)
     pushProcCon(c, result)
     # add params to scope
-    for i in 1 .. <result.typ.n.len:
-      var param = result.typ.n.sons[i].sym
+    let origFormalParams = result.typ.n
+    result.typ.n = newNodeI(nkFormalParams,
+                            origFormalParams.info,
+                            origFormalParams.len)
+    result.typ.n.sons[0] = copyNode(origFormalParams.sons[0])
+    for i in 1 .. <result.typ.len:
+      let origParam = origFormalParams[i].sym
+      var param = copySym(origParam)
+      result.typ.n.sons[i] = newSymNode(param)
+      param.typ = result.typ.sons[i]
+      param.ast = origParam.ast
       param.owner = result
       addParamOrResult(c, param, result.kind)
     # debug result.typ.n
@@ -141,15 +150,6 @@ proc instGenericContainer(c: PContext, n: PNode, header: PType): PType =
 
 proc fixupProcType(c: PContext, genericType: PType,
                    inst: TInstantiation): PType =
-  # XXX: This is starting to look suspiciously like ReplaceTypeVarsT
-  # there are few apparent differences, but maybe the code could be
-  # moved over.
-  # * the code here uses the new genericSym.position property when
-  #   doing lookups. 
-  # * the handling of tyTypeDesc seems suspicious in ReplaceTypeVarsT
-  #   typedesc params were previously handled in the second pass of
-  #   semParamList
-  # * void (nkEmpty) params doesn't seem to be stripped in ReplaceTypeVarsT
   result = genericType
   if result == nil: return
 
@@ -167,8 +167,7 @@ proc fixupProcType(c: PContext, genericType: PType,
     if genericType.sons == nil: return
     var head = 0
     for i in 0 .. <genericType.sons.len:
-      let origType = genericType.sons[i]
-      var changed = fixupProcType(c, origType, inst)
+      var changed = fixupProcType(c, genericType.sons[i], inst)
       if changed != genericType.sons[i]:
         var changed = changed.skipIntLit
         if result == genericType:
@@ -195,11 +194,7 @@ proc fixupProcType(c: PContext, genericType: PType,
         
         if result.n != nil:
           if result.n.kind == nkRecList:
-            for son in result.n.sons:
-              if son.typ == origType:
-                son.typ = changed
-                son.sym = copySym(son.sym, true)
-                son.sym.typ = changed
+            result.n.sons[head].typ = changed
           if result.n.kind == nkFormalParams:
             if i != 0:
               let origParam = result.n.sons[head].sym
@@ -210,14 +205,14 @@ proc fixupProcType(c: PContext, genericType: PType,
 
       # won't be advanced on empty (void) nodes
       inc head
-  
+        
   of tyGenericInvokation:
     result = newTypeWithSons(c, tyGenericInvokation, genericType.sons)
     for i in 1 .. <genericType.sons.len:
       result.sons[i] = fixupProcType(c, result.sons[i], inst)
     result = instGenericContainer(c, getInfoContext(-1), result)
-  
-  else: nil
+  else:
+    nil
 
 proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
                       info: TLineInfo): PSym =
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 65a93c137..351794435 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -374,7 +374,7 @@ proc semCaseBranch(c: PContext, t, branch: PNode, branchIndex: int,
       # for ``{}`` we want to trigger the type mismatch in ``fitNode``:
       if r.kind != nkCurly or len(r) == 0:
         checkMinSonsLen(t, 1)
-        branch.sons[i] = skipConv(fitNode(c, t.sons[0].typ, r))
+        branch.sons[i] = fitNode(c, t.sons[0].typ, r)
         inc(covered)
       else:
         # constant sets have special rules
diff --git a/tests/compile/tobjects.nim b/tests/compile/tobjects.nim
index 06fa15583..68705d944 100644
--- a/tests/compile/tobjects.nim
+++ b/tests/compile/tobjects.nim
@@ -1,52 +1,52 @@
-type
-  TBase = object of TObject
-    x, y: int
-
-  TSubclassKind = enum ka, kb, kc, kd, ke, kf
-  TSubclass = object of TBase
-    case c: TSubclassKind
-    of ka, kb, kc, kd:
-      a, b: int
-    of ke:
-      d, e, f: char
-    else: nil
-    n: bool
+type

+  TBase = object of TObject

+    x, y: int

+

+  TSubclassKind = enum ka, kb, kc, kd, ke, kf

+  TSubclass = object of TBase

+    case c: TSubclassKind

+    of ka, kb, kc, kd:

+      a, b: int

+    of ke:

+      d, e, f: char

+    else: nil

+    n: bool

 
 type
   TMyObject = object of TObject
-    case disp: range[0..4]
+    case disp: range[0..4]:
       of 0: arg: char
       of 1: s: string
       else: wtf: bool
       
 var
   x: TMyObject
-
-var
-  global: int
-
-var
-  s: string
-  r: float = 0.0
-  i: int = 500 + 400
-
-case i
-of 500..999: write(stdout, "ha!\n")
-of 1000..3000, 12: write(stdout, "ganz schön groß\n")
-of 1, 2, 3: write(stdout, "1 2 oder 3\n")
-else: write(stdout, "sollte nicht passieren\n")
-
-case readLine(stdin)
-of "Rumpf": write(stdout, "Hallo Meister!\n")
-of "Andreas": write(stdout, "Hallo Meister!\n")
-else: write(stdout, "Nicht mein Meister!\n")
-
-global = global + 1
-write(stdout, "Hallo wie heißt du? \n")
-s = readLine(stdin)
-i = 0
-while i < len(s):
-  if s[i] == 'c': write(stdout, "'c' in deinem Namen gefunden\n")
-  i = i + 1
-
-write(stdout, "Du heißt " & s)
+

+var

+  global: int

+

+var

+  s: string

+  r: float = 0.0

+  i: int = 500 + 400

+

+case i

+of 500..999: write(stdout, "ha!\n")

+of 1000..3000, 12: write(stdout, "ganz schön groß\n")

+of 1, 2, 3: write(stdout, "1 2 oder 3\n")

+else: write(stdout, "sollte nicht passieren\n")

+

+case readLine(stdin)

+of "Rumpf": write(stdout, "Hallo Meister!\n")

+of "Andreas": write(stdout, "Hallo Meister!\n")

+else: write(stdout, "Nicht mein Meister!\n")

+

+global = global + 1

+write(stdout, "Hallo wie heißt du? \n")

+s = readLine(stdin)

+i = 0

+while i < len(s):

+  if s[i] == 'c': write(stdout, "'c' in deinem Namen gefunden\n")

+  i = i + 1

+

+write(stdout, "Du heißt " & s)

diff --git a/tests/compile/toverprc.nim b/tests/compile/toverprc.nim
index 6d75fdf78..467dd36c3 100644
--- a/tests/compile/toverprc.nim
+++ b/tests/compile/toverprc.nim
@@ -1,30 +1,30 @@
-# Test overloading of procs when used as function pointers
-
-import strutils
-
-proc parseInt(x: float): int {.noSideEffect.} = nil
-proc parseInt(x: bool): int {.noSideEffect.} = nil
-proc parseInt(x: float32): int {.noSideEffect.} = nil
-proc parseInt(x: int8): int {.noSideEffect.} = nil
-proc parseInt(x: TFile): int {.noSideEffect.} = nil
-proc parseInt(x: char): int {.noSideEffect.} = nil
-proc parseInt(x: int16): int {.noSideEffect.} = nil
-
-type
-  TParseInt = proc (x: string): int {.noSideEffect.}
-
-var
-  q = TParseInt(parseInt)
-  p: TParseInt = parseInt
-
-proc takeParseInt(x: proc (y: string): int {.noSideEffect.}): int = 
-  result = x("123")
-  
-echo "Give a list of numbers (separated by spaces): "
-var x = stdin.readline.split.map(parseInt).max
-echo x, " is the maximum!"
-echo "another number: ", takeParseInt(parseInt)
-
+# Test overloading of procs when used as function pointers

+

+import strutils

+

+proc parseInt(x: float): int {.noSideEffect.} = nil

+proc parseInt(x: bool): int {.noSideEffect.} = nil

+proc parseInt(x: float32): int {.noSideEffect.} = nil

+proc parseInt(x: int8): int {.noSideEffect.} = nil

+proc parseInt(x: TFile): int {.noSideEffect.} = nil

+proc parseInt(x: char): int {.noSideEffect.} = nil

+proc parseInt(x: int16): int {.noSideEffect.} = nil

+

+type

+  TParseInt = proc (x: string): int {.noSideEffect.}

+

+var

+  q = TParseInt(parseInt)

+  p: TParseInt = parseInt

+

+proc takeParseInt(x: proc (y: string): int {.noSideEffect.}): int = 

+  result = x("123")

+  

+echo "Give a list of numbers (separated by spaces): "

+var x = stdin.readline.split.map(parseInt).max

+echo x, " is the maximum!"

+echo "another number: ", takeParseInt(parseInt)

+

 
 type
   TFoo[a,b] = object
@@ -33,4 +33,3 @@ type
 
 proc bar[a,b](f: TFoo[a,b], x: a) = echo(x, " ", f.lorem, f.ipsum)
 proc bar[a,b](f: TFoo[a,b], x: b) = echo(x, " ", f.lorem, f.ipsum)
-