summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/idgen.nim2
-rw-r--r--compiler/vm.nim26
-rw-r--r--compiler/vmdef.nim1
-rw-r--r--compiler/vmgen.nim3
-rw-r--r--doc/c2nim.txt2
5 files changed, 30 insertions, 4 deletions
diff --git a/compiler/idgen.nim b/compiler/idgen.nim
index c4f5f2a9e..d932e3d9d 100644
--- a/compiler/idgen.nim
+++ b/compiler/idgen.nim
@@ -19,7 +19,7 @@ const
 when debugIds:
   import intsets
   
-  var usedIds = InitIntSet()
+  var usedIds = initIntSet()
 
 proc registerID*(id: PIdObj) = 
   when debugIds: 
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)
diff --git a/compiler/vmdef.nim b/compiler/vmdef.nim
index 102fc3024..7725d79b8 100644
--- a/compiler/vmdef.nim
+++ b/compiler/vmdef.nim
@@ -64,6 +64,7 @@ type
     opcContainsSet, opcRepr, opcSetLenStr, opcSetLenSeq,
     opcSwap, opcIsNil, opcOf, opcIs,
     opcSubStr, opcConv, opcCast, opcQuit, opcReset,
+    opcNarrowS, opcNarrowU,
     
     opcAddStrCh,
     opcAddStrStr,
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim
index 0fc71189d..5e51ecf4c 100644
--- a/compiler/vmgen.nim
+++ b/compiler/vmgen.nim
@@ -1226,7 +1226,8 @@ proc genVarSection(c: PCtx; n: PNode) =
         if s.position == 0:
           if sfImportc in s.flags: c.importcSym(a.info, s)
           else:
-            let sa = if s.ast.isNil: getNullValue(s.typ, a.info) else: s.ast
+            let sa = if s.ast.isNil: getNullValue(s.typ, a.info) 
+                     else: canonConst(s.ast)
             c.globals.add(sa)
             s.position = c.globals.len
         if a.sons[2].kind == nkEmpty:
diff --git a/doc/c2nim.txt b/doc/c2nim.txt
index 7dec8b995..6788ef569 100644
--- a/doc/c2nim.txt
+++ b/doc/c2nim.txt
@@ -74,7 +74,7 @@ Is translated into:
       printf("%s\x0A", x)
   else:
     template OUT*(x: expr): stmt = 
-      nil
+      discard
   
 As can been seen from the example, C's macros with parameters are mapped
 to Nimrod's templates. This mapping is the best one can do, but it is of course