diff options
author | Ridho Pratama <p.ridho@yahoo.co.id> | 2019-10-08 16:12:24 +0700 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-10-08 11:12:24 +0200 |
commit | 7ef4bffa797623c608c15329717f0a9ee06a5d38 (patch) | |
tree | 7f15164d5f4ab3709dcdd064d3c8238c719e6913 /compiler/renderer.nim | |
parent | dbcffcfccb39a35f2f8e2447a22776e5e761ce72 (diff) | |
download | Nim-7ef4bffa797623c608c15329717f0a9ee06a5d38.tar.gz |
renderer letAux fix only for octal literal (#12343)
* renderer letAux fix only for octal literal * Handle when it's octal -1 for i64 * Added testcases
Diffstat (limited to 'compiler/renderer.nim')
-rw-r--r-- | compiler/renderer.nim | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/compiler/renderer.nim b/compiler/renderer.nim index a92ce999f..54090d844 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -314,6 +314,7 @@ proc litAux(g: TSrcGen; n: PNode, x: BiggestInt, size: int): string = while result != nil and result.kind in {tyGenericInst, tyRange, tyVar, tyLent, tyDistinct, tyOrdinal, tyAlias, tySink}: result = lastSon(result) + let typ = n.typ.skip if typ != nil and typ.kind in {tyBool, tyEnum}: if sfPure in typ.sym.flags: @@ -324,11 +325,13 @@ proc litAux(g: TSrcGen; n: PNode, x: BiggestInt, size: int): string = if e.sym.position == x: result &= e.sym.name.s return - - let y = x and ((1 shl (size*8)) - 1) - if nfBase2 in n.flags: result = "0b" & toBin(y, size * 8) - elif nfBase8 in n.flags: result = "0o" & toOct(y, size * 3) - elif nfBase16 in n.flags: result = "0x" & toHex(y, size * 2) + + if nfBase2 in n.flags: result = "0b" & toBin(x, size * 8) + elif nfBase8 in n.flags: + var y = if size < sizeof(BiggestInt): x and ((1 shl (size*8)) - 1) + else: x + result = "0o" & toOct(y, size * 3) + elif nfBase16 in n.flags: result = "0x" & toHex(x, size * 2) else: result = $x proc ulitAux(g: TSrcGen; n: PNode, x: BiggestInt, size: int): string = |