fixed VM touint conversion #2514

This commit is contained in:
jangko 2015-12-18 19:09:15 +07:00
commit 26d02c9120
2 changed files with 85 additions and 1 deletions

View file

@ -359,7 +359,14 @@ proc opConv*(dest: var TFullReg, src: TFullReg, desttyp, srctyp: PType): bool =
of tyFloat..tyFloat64:
dest.intVal = int(src.floatVal)
else:
dest.intVal = src.intVal and ((1 shl (desttyp.size*8))-1)
let srcDist = (sizeof(src.intVal) - srctyp.size) * 8
let destDist = (sizeof(dest.intVal) - desttyp.size) * 8
when system.cpuEndian == bigEndian:
dest.intVal = (src.intVal shr srcDist) shl srcDist
dest.intVal = (dest.intVal shr destDist) shl destDist
else:
dest.intVal = (src.intVal shl srcDist) shr srcDist
dest.intVal = (dest.intVal shl destDist) shr destDist
of tyFloat..tyFloat64:
if dest.kind != rkFloat:
myreset(dest); dest.kind = rkFloat