Merge pull request #3654 from jangko/vm_uinttouint64conv

fixed #2514 unable to echo uint8-32 at compile time
This commit is contained in:
Andreas Rumpf 2015-12-21 00:37:48 +01:00
commit 17a78f4f8d
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