diff options
author | Araq <rumpf_a@web.de> | 2014-03-27 19:20:59 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-03-27 19:20:59 +0100 |
commit | 3365b42bbe5e09f8e8a739597ae5e49e2ff2c259 (patch) | |
tree | 4d8ded5ab336ab4a3e07679dbc1ddd1d1cf5fbd0 | |
parent | dc956c485aa9d8becd3d9eb3c2086ebac3b6eeed (diff) | |
download | Nim-3365b42bbe5e09f8e8a739597ae5e49e2ff2c259.tar.gz |
fixes #1009
-rw-r--r-- | compiler/vm.nim | 2 | ||||
-rw-r--r-- | compiler/vmgen.nim | 9 | ||||
-rw-r--r-- | tests/vm/trgba.nim | 36 |
3 files changed, 45 insertions, 2 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim index 268289aca..0d5386502 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -318,7 +318,7 @@ proc opConv*(dest: var TFullReg, src: TFullReg, desttyp, srctyp: PType): bool = of tyFloat..tyFloat64: dest.intVal = system.toInt(src.floatVal) else: - dest.intVal = src.intVal and ((1 shl desttyp.size)-1) + dest.intVal = src.intVal and ((1 shl (desttyp.size*8))-1) of tyFloat..tyFloat64: if dest.kind != rkFloat: myreset(dest); dest.kind = rkFloat diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index e627fee48..3c0f8dbc9 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -41,7 +41,14 @@ proc codeListing(c: PCtx, result: var string, start=0) = let x = c.code[i] let opc = opcode(x) - if opc < firstABxInstr: + if opc in {opcConv, opcCast}: + let y = c.code[i+1] + let z = c.code[i+2] + result.addf("\t$#\tr$#, r$#, $#, $#", ($opc).substr(3), x.regA, x.regB, + c.types[y.regBx-wordExcess].typeToString, + c.types[z.regBx-wordExcess].typeToString) + inc i, 2 + elif opc < firstABxInstr: result.addf("\t$#\tr$#, r$#, r$#", ($opc).substr(3), x.regA, x.regB, x.regC) elif opc in relativeJumps: diff --git a/tests/vm/trgba.nim b/tests/vm/trgba.nim new file mode 100644 index 000000000..ec79f6aca --- /dev/null +++ b/tests/vm/trgba.nim @@ -0,0 +1,36 @@ +discard """ + output: '''[127, 127, 0, 255] +[127, 127, 0, 255] +''' +""" + +#bug #1009 +type + TAggRgba8* = array[4, byte] + +template R*(self: TAggRgba8): Byte = self[0] +template G*(self: TAggRgba8): Byte = self[1] +template B*(self: TAggRgba8): Byte = self[2] +template A*(self: TAggRgba8): Byte = self[3] + +template `R=`*(self: TAggRgba8, val: Byte) = + self[0] = val +template `G=`*(self: TAggRgba8, val: Byte) = + self[1] = val +template `B=`*(self: TAggRgba8, val: Byte) = + self[2] = val +template `A=`*(self: TAggRgba8, val: Byte) = + self[3] = val + +proc ABGR* (val: int| int64): TAggRgba8 = + var V = val + result.R = V and 0xFF + V = V shr 8 + result.G = V and 0xFF + V = V shr 8 + result.B = V and 0xFF + result.A = (V shr 8) and 0xFF + +const + c1 = ABGR(0xFF007F7F) +echo ABGR(0xFF007F7F).repr, c1.repr |