summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-01-06 00:29:18 +0100
committerAraq <rumpf_a@web.de>2012-01-06 00:29:18 +0100
commit071b1e395719b18f3a2d9a96dc126cfbbabf05f6 (patch)
tree359165d02ead485b2b0d406de264a3f177eae77a
parent8aa4e4670716f04e6029c24b052c09a4a3cc0ae4 (diff)
downloadNim-071b1e395719b18f3a2d9a96dc126cfbbabf05f6.tar.gz
test t99bott.nim works now
-rwxr-xr-xcompiler/evals.nim38
-rwxr-xr-xcompiler/sem.nim2
-rwxr-xr-xtests/reject/t99bott.nim8
-rwxr-xr-xtodo.txt1
4 files changed, 24 insertions, 25 deletions
diff --git a/compiler/evals.nim b/compiler/evals.nim
index 42a8da305..d4602aa24 100755
--- a/compiler/evals.nim
+++ b/compiler/evals.nim
@@ -70,8 +70,8 @@ proc popStackFrame*(c: PEvalContext) {.inline.} =
 proc evalMacroCall*(c: PEvalContext, n: PNode, sym: PSym): PNode
 proc evalAux(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode
 
-proc raiseCannotEval(c: PEvalContext, n: PNode): PNode = 
-  result = newNodeI(nkExceptBranch, n.info) 
+proc raiseCannotEval(c: PEvalContext, info: TLineInfo): PNode = 
+  result = newNodeI(nkExceptBranch, info)
   # creating a nkExceptBranch without sons 
   # means that it could not be evaluated
 
@@ -96,11 +96,8 @@ proc stackTrace(c: PEvalContext, n: PNode, msg: TMsgKind, arg = "") =
   stackTraceAux(c.tos)
   LocalError(n.info, msg, arg)
 
-proc isSpecial(n: PNode): bool {.inline.} = 
-  result = (n.kind == nkExceptBranch) 
-  # or (n.kind == nkEmpty)
-  # XXX this does not work yet! Better to compile too much than to compile to
-  # few programs
+proc isSpecial(n: PNode): bool {.inline.} =
+  result = n.kind == nkExceptBranch
 
 proc myreset(n: PNode) {.inline.} =
   when defined(system.reset): reset(n[])
@@ -311,7 +308,8 @@ proc evalVariable(c: PStackFrame, sym: PSym, flags: TEvalFlags): PNode =
       result = copyTree(result)
     if result != nil: return 
     x = x.next
-  result = emptyNode
+  result = raiseCannotEval(nil, sym.info)
+  #result = emptyNode
 
 proc evalGlobalVar(c: PEvalContext, s: PSym, flags: TEvalFlags): PNode =
   result = IdNodeTableGet(c.globals, s)
@@ -350,7 +348,7 @@ proc evalArrayAccess(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
     else: 
       stackTrace(c, n, errIndexOutOfBounds)
   of nkStrLit..nkTripleStrLit:
-    if efLValue in flags: return raiseCannotEval(c, n)
+    if efLValue in flags: return raiseCannotEval(c, n.info)
     result = newNodeIT(nkCharLit, x.info, getSysType(tyChar))
     if (idx >= 0) and (idx < len(x.strVal)): 
       result.intVal = ord(x.strVal[int(idx) + 0])
@@ -366,7 +364,7 @@ proc evalFieldAccess(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
   result = evalAux(c, n.sons[0], flags)
   if isSpecial(result): return 
   var x = result
-  if x.kind != nkPar: return raiseCannotEval(c, n)
+  if x.kind != nkPar: return raiseCannotEval(c, n.info)
   var field = n.sons[1].sym
   for i in countup(0, sonsLen(x) - 1): 
     var it = x.sons[i]
@@ -396,7 +394,7 @@ proc evalAsgn(c: PEvalContext, n: PNode): PNode =
 
     result = evalAux(c, n.sons[1], {})
     if isSpecial(result): return
-    if result.kind != nkCharLit: return raiseCannotEval(c, n)
+    if result.kind != nkCharLit: return raiseCannotEval(c, n.info)
 
     if (idx >= 0) and (idx < len(x.strVal)): 
       x.strVal[int(idx)] = chr(int(result.intVal))
@@ -464,7 +462,7 @@ proc evalSym(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
   of skEnumField: result = newIntNodeT(s.position, n)
   else: result = nil
   if result == nil or sfImportc in s.flags:
-    result = raiseCannotEval(c, n)
+    result = raiseCannotEval(c, n.info)
   
 proc evalIncDec(c: PEvalContext, n: PNode, sign: biggestInt): PNode = 
   result = evalAux(c, n.sons[1], {efLValue})
@@ -475,7 +473,7 @@ proc evalIncDec(c: PEvalContext, n: PNode, sign: biggestInt): PNode =
   var b = result
   case a.kind
   of nkCharLit..nkInt64Lit: a.intval = a.intVal + sign * getOrdValue(b)
-  else: return raiseCannotEval(c, n)
+  else: return raiseCannotEval(c, n.info)
   result = emptyNode
 
 proc getStrValue(n: PNode): string = 
@@ -512,7 +510,7 @@ proc evalAnd(c: PEvalContext, n: PNode): PNode =
   if result.intVal != 0: result = evalAux(c, n.sons[2], {})
   
 proc evalNew(c: PEvalContext, n: PNode): PNode = 
-  if c.optEval: return raiseCannotEval(c, n)
+  if c.optEval: return raiseCannotEval(c, n.info)
   # we ignore the finalizer for now and most likely forever :-)
   result = evalAux(c, n.sons[1], {efLValue})
   if isSpecial(result): return 
@@ -536,7 +534,7 @@ proc evalDeref(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
     # XXX efLValue?
     result = result.sons[0]
   else:
-    result = raiseCannotEval(c, n)
+    result = raiseCannotEval(c, n.info)
   
 proc evalAddr(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode = 
   result = evalAux(c, n.sons[0], {efLValue})
@@ -728,7 +726,7 @@ proc evalAppendStrCh(c: PEvalContext, n: PNode): PNode =
   var b = result
   case a.kind
   of nkStrLit..nkTripleStrLit: add(a.strVal, chr(int(getOrdValue(b))))
-  else: return raiseCannotEval(c, n)
+  else: return raiseCannotEval(c, n.info)
   result = emptyNode
 
 proc evalConStrStr(c: PEvalContext, n: PNode): PNode = 
@@ -750,7 +748,7 @@ proc evalAppendStrStr(c: PEvalContext, n: PNode): PNode =
   var b = result
   case a.kind
   of nkStrLit..nkTripleStrLit: a.strVal = a.strVal & getStrOrChar(b)
-  else: return raiseCannotEval(c, n)
+  else: return raiseCannotEval(c, n.info)
   result = emptyNode
 
 proc evalAppendSeqElem(c: PEvalContext, n: PNode): PNode = 
@@ -761,7 +759,7 @@ proc evalAppendSeqElem(c: PEvalContext, n: PNode): PNode =
   if isSpecial(result): return 
   var b = result
   if a.kind == nkBracket: addSon(a, copyTree(b))
-  else: return raiseCannotEval(c, n)
+  else: return raiseCannotEval(c, n.info)
   result = emptyNode
 
 proc evalRepr(c: PEvalContext, n: PNode): PNode = 
@@ -868,7 +866,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
   case m
   of mNone: result = evalCall(c, n)
   of mOf: result = evalOf(c, n)
-  of mSizeOf: result = raiseCannotEval(c, n)
+  of mSizeOf: result = raiseCannotEval(c, n.info)
   of mHigh: result = evalHigh(c, n)
   of mExit: result = evalExit(c, n)
   of mNew, mNewFinalize: result = evalNew(c, n)
@@ -1217,7 +1215,7 @@ proc evalAux(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
     result.typ = n.typ
   of nkIdentDefs, nkCast, nkYieldStmt, nkAsmStmt, nkForStmt, nkPragmaExpr, 
      nkLambda, nkContinueStmt, nkIdent: 
-    result = raiseCannotEval(c, n)
+    result = raiseCannotEval(c, n.info)
   else: InternalError(n.info, "evalAux: " & $n.kind)
   if result == nil:
     InternalError(n.info, "evalAux: returned nil " & $n.kind)
diff --git a/compiler/sem.nim b/compiler/sem.nim
index 67acabdd3..37eedc384 100755
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -97,7 +97,7 @@ proc semAndEvalConstExpr(c: PContext, n: PNode): PNode =
   result = semConstExpr(c, n)
   
 include seminst, semcall
-    
+
 proc semAfterMacroCall(c: PContext, n: PNode, s: PSym): PNode = 
   result = n
   case s.typ.sons[0].kind
diff --git a/tests/reject/t99bott.nim b/tests/reject/t99bott.nim
index a4729b985..7d11ba4b0 100755
--- a/tests/reject/t99bott.nim
+++ b/tests/reject/t99bott.nim
@@ -1,8 +1,8 @@
 discard """
   file: "t99bott.nim"
-  line: 25
-  errormsg: "constant expression expected"
-  disabled: true
+  line: 26
+  errormsg: "cannot evaluate 'GetBottleNumber(bn)'"
+  disabled: false
 """
 ## 99 Bottles of Beer
 ## http://www.99-bottles-of-beer.net/
@@ -23,7 +23,7 @@ proc GetBottleNumber(n: int): string =
   return bs & " of beer"
 
 for bn in countdown(99, 1):
-  const cur = GetBottleNumber(bn) #ERROR_MSG constant expression expected
+  const cur = GetBottleNumber(bn)
   echo(cur, " on the wall, ", cur, ".")
   echo("Take one down and pass it around, ", GetBottleNumber(bn-1), 
        " on the wall.\n")
diff --git a/todo.txt b/todo.txt
index 380e9469d..091426bc5 100755
--- a/todo.txt
+++ b/todo.txt
@@ -3,6 +3,7 @@ version 0.8.14
 
 - BUG: type TX = TTable[string, int]
 - BUG: temp2.nim triggers weird compiler bug
+- fix line info in assertions
 - implicit invokation of `items`/`pairs` seems nice; ensure items(23) does
   not compile though