From 7ef4bffa797623c608c15329717f0a9ee06a5d38 Mon Sep 17 00:00:00 2001
From: Ridho Pratama
Date: Tue, 8 Oct 2019 16:12:24 +0700
Subject: 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
---
compiler/renderer.nim | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
(limited to 'compiler')
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 =
--
cgit 1.4.1-2-gfad0