summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-11-15 23:03:14 +0100
committerAraq <rumpf_a@web.de>2011-11-15 23:03:14 +0100
commit7819b84475ca6ba1cf3e9976c7140ea11775b81d (patch)
tree4c0fa123e17c88108f812754093a47977a888745
parent5f018a504674f5f46520dadb6d9e9a06f30752cc (diff)
downloadNim-7819b84475ca6ba1cf3e9976c7140ea11775b81d.tar.gz
bugfixes: objects still invalid for constants; fixed a typo concerning 'high' in eval context
-rwxr-xr-xcompiler/evals.nim2
-rwxr-xr-xcompiler/seminst.nim7
-rwxr-xr-xcompiler/transf.nim11
-rwxr-xr-xcompiler/types.nim13
-rw-r--r--lib/pure/actors.cfg3
-rw-r--r--tests/accept/run/tactiontable.nim2
-rw-r--r--tests/reject/tactiontable2.nim28
-rwxr-xr-xtodo.txt1
8 files changed, 52 insertions, 15 deletions
diff --git a/compiler/evals.nim b/compiler/evals.nim
index 76bbf4c0a..cc05267f4 100755
--- a/compiler/evals.nim
+++ b/compiler/evals.nim
@@ -641,7 +641,7 @@ proc evalHigh(c: PEvalContext, n: PNode): PNode =
   result = evalAux(c, n.sons[1], {})
   if isSpecial(result): return 
   case skipTypes(n.sons[1].typ, abstractVar).kind
-  of tyOpenArray, tySequence: result = newIntNodeT(sonsLen(result), n)
+  of tyOpenArray, tySequence: result = newIntNodeT(sonsLen(result)-1, n)
   of tyString: result = newIntNodeT(len(result.strVal) - 1, n)
   else: InternalError(n.info, "evalHigh")
 
diff --git a/compiler/seminst.nim b/compiler/seminst.nim
index 130e00134..d7dbe623b 100755
--- a/compiler/seminst.nim
+++ b/compiler/seminst.nim
@@ -77,10 +77,9 @@ proc instantiateBody(c: PContext, n: PNode, result: PSym) =
     if result.kind in {skProc, skMethod, skConverter}: 
       addResult(c, result.typ.sons[0], n.info)
       addResultNode(c, n)
-    n.sons[bodyPos] = semStmtScope(c, n.sons[bodyPos])
-    if result.kind == skIterator:
-      # XXX Bad hack for tests/titer2:
-      n.sons[bodyPos] = transform(c.module, n.sons[bodyPos])
+    var b = semStmtScope(c, n.sons[bodyPos])
+    # XXX Bad hack for tests/titer2 and tests/tactiontable
+    n.sons[bodyPos] = transform(c.module, b)
     #echo "code instantiated ", result.name.s
     excl(result.flags, sfForward)
     popProcCon(c)
diff --git a/compiler/transf.nim b/compiler/transf.nim
index 78ca50e3b..3c715be6d 100755
--- a/compiler/transf.nim
+++ b/compiler/transf.nim
@@ -736,11 +736,12 @@ proc processTransf(context: PPassContext, n: PNode): PNode =
   # Note: For interactive mode we cannot call 'passes.skipCodegen' and skip
   # this step! We have to rely that the semantic pass transforms too errornous
   # nodes into an empty node.
-  if passes.skipCodegen(n) or context.fromCache: return n
+  if passes.skipCodegen(n) or context.fromCache or nfTransf in n.flags: return n
   var c = PTransf(context)
   pushTransCon(c, newTransCon(getCurrOwner(c)))
   result = PNode(transform(c, n))
   popTransCon(c)
+  incl(result.flags, nfTransf)
 
 proc openTransf(module: PSym, filename: string): PPassContext = 
   var n: PTransf
@@ -762,6 +763,10 @@ proc transfPass(): TPass =
   result.close = processTransf # we need to process generics too!
   
 proc transform*(module: PSym, n: PNode): PNode =
-  var c = openTransf(module, "")
-  result = processTransf(c, n)
+  if nfTransf in n.flags: 
+    result = n
+  else:
+    var c = openTransf(module, "")
+    result = processTransf(c, n)
+    incl(result.flags, nfTransf)
 
diff --git a/compiler/types.nim b/compiler/types.nim
index 7e34031aa..2a96f14af 100755
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -280,8 +280,8 @@ proc isGBCRef(t: PType): bool =
   result = t.kind in {tyRef, tySequence, tyString}
 
 proc containsGarbageCollectedRef(typ: PType): bool = 
-  # returns true if typ contains a reference, sequence or string (all the things
-  # that are garbage-collected)
+  # returns true if typ contains a reference, sequence or string (all the
+  # things that are garbage-collected)
   result = searchTypeFor(typ, isGBCRef)
 
 proc isTyRef(t: PType): bool =
@@ -868,11 +868,12 @@ proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind): bool =
     for i in countup(0, sonsLen(t) - 1): 
       result = typeAllowedAux(marker, t.sons[i], kind)
       if not result: break 
-  of tyObject: 
+  of tyObject:
+    if kind == skConst: return false
     for i in countup(0, sonsLen(t) - 1): 
-      result = typeAllowedAux(marker, t.sons[i], skVar)
-      if not result: break 
-    if result and t.n != nil: result = typeAllowedNode(marker, t.n, skVar)
+      result = typeAllowedAux(marker, t.sons[i], kind)
+      if not result: break
+    if result and t.n != nil: result = typeAllowedNode(marker, t.n, kind)
     
 proc typeAllowed(t: PType, kind: TSymKind): bool = 
   var marker = InitIntSet()
diff --git a/lib/pure/actors.cfg b/lib/pure/actors.cfg
new file mode 100644
index 000000000..c6bb9c545
--- /dev/null
+++ b/lib/pure/actors.cfg
@@ -0,0 +1,3 @@
+# to shut up the tester:
+--threads:on
+
diff --git a/tests/accept/run/tactiontable.nim b/tests/accept/run/tactiontable.nim
index 6fe39359c..e2f19a099 100644
--- a/tests/accept/run/tactiontable.nim
+++ b/tests/accept/run/tactiontable.nim
@@ -16,7 +16,7 @@ proc action3(arg: string) =
 proc action4(arg: string) = 
   echo "action 4 ", arg
 
-const
+var
   actionTable = {
     "A": action1, 
     "B": action2, 
diff --git a/tests/reject/tactiontable2.nim b/tests/reject/tactiontable2.nim
new file mode 100644
index 000000000..dbfa42f18
--- /dev/null
+++ b/tests/reject/tactiontable2.nim
@@ -0,0 +1,28 @@
+discard """
+  line: 21
+  errormsg: "invalid type: 'TTable'"
+"""
+
+import tables
+
+proc action1(arg: string) = 
+  echo "action 1 ", arg
+
+proc action2(arg: string) = 
+  echo "action 2 ", arg
+
+proc action3(arg: string) = 
+  echo "action 3 ", arg
+
+proc action4(arg: string) = 
+  echo "action 4 ", arg
+
+const
+  actionTable = {
+    "A": action1, 
+    "B": action2, 
+    "C": action3, 
+    "D": action4}.toTable
+
+actionTable["C"]("arg")
+
diff --git a/todo.txt b/todo.txt
index b47d4958e..8415973b9 100755
--- a/todo.txt
+++ b/todo.txt
@@ -19,6 +19,7 @@ version 0.9.0
   --> solve by implicit conversion from varargs to openarray
 - change overloading resolution
 - implement closures; implement proper coroutines
+- implement ``partial`` pragma for partial evaluation
 - implicit invokation of `items` seems nice
 - we need to support iteration of 2 different data structures in parallel
 - make exceptions compatible with C++ exceptions