summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorYuriy Glukhov <yuriy.glukhov@gmail.com>2015-09-07 13:49:32 +0300
committerYuriy Glukhov <yuriy.glukhov@gmail.com>2015-09-07 13:49:32 +0300
commit4ef4ad305cbef808c0677219b38def8e054eeb90 (patch)
tree6c9aa910b871bf29e48f3526ab4f6140e9984b8a
parenta480bebfce3a06c07edab820acd080983cec7a6b (diff)
downloadNim-4ef4ad305cbef808c0677219b38def8e054eeb90.tar.gz
Fixed nimvm in generics.
-rw-r--r--compiler/semexprs.nim14
-rw-r--r--compiler/semfold.nim2
-rw-r--r--lib/system.nim6
3 files changed, 14 insertions, 8 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index fe74e75dd..3ff04a4fc 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -124,6 +124,9 @@ proc semSym(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
         return newSymNode(u, n.info)
     result = newSymNode(s, n.info)
   of skVar, skLet, skResult, skForVar:
+    if s.magic == mNimvm:
+      localError(n.info, "illegal context for 'nimvm' magic")
+
     markUsed(n.info, s)
     styleCheckUse(n.info, s)
     # if a proc accesses a global variable, it is not side effect free:
@@ -1769,9 +1772,14 @@ proc semWhen(c: PContext, n: PNode, semCheck = true): PNode =
   #   ...
   # else:
   #   ...
-  let whenNimvm = n.sons.len == 2 and n.sons[0].kind == nkElifBranch and
-      n.sons[1].kind == nkElse and n.sons[0].sons[0].kind == nkIdent and
-      lookUp(c, n.sons[0].sons[0]).magic == mNimvm
+  var whenNimvm = false
+  if n.sons.len == 2 and n.sons[0].kind == nkElifBranch and
+      n.sons[1].kind == nkElse:
+    let exprNode = n.sons[0].sons[0]
+    if exprNode.kind == nkIdent:
+      whenNimvm = lookUp(c, exprNode).magic == mNimvm
+    elif exprNode.kind == nkSym:
+      whenNimvm = exprNode.sym.magic == mNimvm
 
   for i in countup(0, sonsLen(n) - 1):
     var it = n.sons[i]
diff --git a/compiler/semfold.nim b/compiler/semfold.nim
index 22cf05aa8..2ab43a9c9 100644
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -640,8 +640,6 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
       of mNaN: result = newFloatNodeT(NaN, n)
       of mInf: result = newFloatNodeT(Inf, n)
       of mNegInf: result = newFloatNodeT(NegInf, n)
-      of mNimvm:
-        localError(n.info, "illegal context for 'nimvm' magic")
       else:
         if sfFakeConst notin s.flags: result = copyTree(s.ast)
     of {skProc, skMethod}:
diff --git a/lib/system.nim b/lib/system.nim
index 5bd8c56c7..65b633266 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1173,12 +1173,12 @@ const
     ## "i386", "alpha", "powerpc", "powerpc64", "powerpc64el", "sparc",
     ## "amd64", "mips", "mipsel", "arm", "arm64".
 
-  nimvm* {.magic: "Nimvm".}: bool = false
+  seqShallowFlag = low(int)
+
+let nimvm* {.magic: "Nimvm".}: bool = false
     ## may be used only in "when" expression.
     ## It is true in Nim VM context and false otherwise
 
-  seqShallowFlag = low(int)
-
 proc compileOption*(option: string): bool {.
   magic: "CompileOption", noSideEffect.}
   ## can be used to determine an on|off compile-time option. Example: