summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/vm.nim14
-rw-r--r--compiler/vmgen.nim9
2 files changed, 13 insertions, 10 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim
index 848cbfcf0..05ee3b90e 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -489,17 +489,21 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
       decodeB(rkFloat)
       regs[ra].floatVal = regs[rb].floatVal
     of opcAsgnIntFromFloat32:
-      decodeB(rkFloat)
+      let rb = instr.regB
+      ensureKind(rkInt)
       regs[ra].intVal = cast[int32](float32(regs[rb].floatVal))
     of opcAsgnIntFromFloat64:
-      decodeB(rkFloat)
+      let rb = instr.regB
+      ensureKind(rkInt)
       regs[ra].intVal = cast[int64](regs[rb].floatVal)
     of opcAsgnFloat32FromInt:
-      decodeB(rkInt)
+      let rb = instr.regB
+      ensureKind(rkFloat)
       regs[ra].floatVal = cast[float32](int32(regs[rb].intVal))
     of opcAsgnFloat64FromInt:
-      decodeB(rkInt)
-      regs[ra].floatVal = cast[float64](int64(regs[rb].intVal))
+      let rb = instr.regB
+      ensureKind(rkFloat)
+      regs[ra].floatVal = cast[float64](int64(regs[rb].intVal))      
     of opcAsgnComplex:
       asgnComplex(regs[ra], regs[instr.regB])
     of opcAsgnRef:
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim
index 527c3cf2e..ea0fb35ff 100644
--- a/compiler/vmgen.nim
+++ b/compiler/vmgen.nim
@@ -811,8 +811,7 @@ proc genCastIntFloat(c: PCtx; n: PNode; dest: var TDest) =
     c.freeTemp(tmp3)
   elif src_size == dst_size and src.kind in allowedIntegers and
                            dst.kind in {tyFloat, tyFloat32, tyFloat64}:
-
-    let tmp = c.getTemp(n.sons[1].typ)
+    let tmp = c.genx(n[1])
     if dest < 0: dest = c.getTemp(n[0].typ)
     if dst.kind == tyFloat32:
       c.gABC(n, opcAsgnFloat32FromInt, dest, tmp)
@@ -821,15 +820,15 @@ proc genCastIntFloat(c: PCtx; n: PNode; dest: var TDest) =
     c.freeTemp(tmp)
 
   elif src_size == dst_size and src.kind in {tyFloat, tyFloat32, tyFloat64} and
-                           dst.kind in allowedIntegers:
-              
-    let tmp = c.getTemp(n.sons[1].typ)
+                           dst.kind in allowedIntegers:         
+    let tmp = c.genx(n[1])
     if dest < 0: dest = c.getTemp(n[0].typ)
     if src.kind == tyFloat32:
       c.gABC(n, opcAsgnIntFromFloat32, dest, tmp)
     else:
       c.gABC(n, opcAsgnIntFromFloat64, dest, tmp)
     c.freeTemp(tmp)
+
   else:
     globalError(c.config, n.info, "VM is only allowed to 'cast' between integers and/or floats of same size")