summary refs log tree commit diff stats
path: root/compiler/vm.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-03-22 02:52:06 +0100
committerAraq <rumpf_a@web.de>2014-03-22 02:52:06 +0100
commite53fc91282bc8a5dabc4f12e041fa6ce5400c007 (patch)
treebe7fcdd03635a91596ab813643f3b293db7d30e8 /compiler/vm.nim
parentfb5ece805ff5b752ec2e9dc0c49fc34d5abdc6a9 (diff)
downloadNim-e53fc91282bc8a5dabc4f12e041fa6ce5400c007.tar.gz
fixed tuples in a static context; preparations for correct compile time evaluation of integral ops
Diffstat (limited to 'compiler/vm.nim')
-rw-r--r--compiler/vm.nim26
1 files changed, 25 insertions, 1 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim
index 5c8e533f1..06f0e8886 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -902,8 +902,32 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
       let newLen = regs[rb].intVal.int
       if regs[ra].node.isNil: stackTrace(c, tos, pc, errNilAccess)
       else: setLen(regs[ra].node.sons, newLen)
-    of opcSwap, opcReset:
+    of opcSwap:
+      let rb = instr.regB
+      if regs[ra].kind == regs[rb].kind:
+        case regs[ra].kind
+        of rkNone: discard
+        of rkInt: swap regs[ra].intVal, regs[rb].intVal
+        of rkFloat: swap regs[ra].floatVal, regs[rb].floatVal
+        of rkNode: swap regs[ra].node, regs[rb].node
+        of rkRegisterAddr: swap regs[ra].regAddr, regs[rb].regAddr
+        of rkNodeAddr: swap regs[ra].nodeAddr, regs[rb].nodeAddr
+      else:
+        internalError(c.debug[pc], "cannot swap operands")
+    of opcReset:
       internalError(c.debug[pc], "too implement")
+    of opcNarrowS:
+      decodeBC(rkInt)
+      let min = -(1 shl (rc-1))
+      let max = (1 shl (rc-1))-1
+      if regs[rb].intVal >= min and regs[rb].intVal <= max:
+        regs[ra].intVal = regs[rb].intVal
+      else:
+        stackTrace(c, tos, pc, errGenerated,
+          msgKindToString(errUnhandledExceptionX) % "value out of range")
+    of opcNarrowU:
+      decodeBC(rkInt)
+      regs[ra].intVal = regs[rb].intVal and ((1'i64 shl rc)-1)
     of opcIsNil:
       decodeB(rkInt)
       regs[ra].intVal = ord(regs[rb].node.kind == nkNilLit)