parent
ab872be476
commit
d8c3df2683
2 changed files with 14 additions and 2 deletions
|
|
@ -500,7 +500,11 @@ proc lsub(g: TSrcGen; n: PNode): int =
|
||||||
of nkUsingStmt:
|
of nkUsingStmt:
|
||||||
if sonsLen(n) > 1: result = MaxLineLen + 1
|
if sonsLen(n) > 1: result = MaxLineLen + 1
|
||||||
else: result = lsons(g, n) + len("using_")
|
else: result = lsons(g, n) + len("using_")
|
||||||
of nkReturnStmt: result = lsub(g, n.sons[0]) + len("return_")
|
of nkReturnStmt:
|
||||||
|
if n.len > 0 and n[0].kind == nkAsgn:
|
||||||
|
result = len("return_") + lsub(g, n[0][1])
|
||||||
|
else:
|
||||||
|
result = len("return_") + lsub(g, n[0])
|
||||||
of nkRaiseStmt: result = lsub(g, n.sons[0]) + len("raise_")
|
of nkRaiseStmt: result = lsub(g, n.sons[0]) + len("raise_")
|
||||||
of nkYieldStmt: result = lsub(g, n.sons[0]) + len("yield_")
|
of nkYieldStmt: result = lsub(g, n.sons[0]) + len("yield_")
|
||||||
of nkDiscardStmt: result = lsub(g, n.sons[0]) + len("discard_")
|
of nkDiscardStmt: result = lsub(g, n.sons[0]) + len("discard_")
|
||||||
|
|
@ -1335,7 +1339,10 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
|
||||||
gsub(g, n.sons[0])
|
gsub(g, n.sons[0])
|
||||||
of nkReturnStmt:
|
of nkReturnStmt:
|
||||||
putWithSpace(g, tkReturn, "return")
|
putWithSpace(g, tkReturn, "return")
|
||||||
gsub(g, n, 0)
|
if n.len > 0 and n[0].kind == nkAsgn:
|
||||||
|
gsub(g, n[0], 1)
|
||||||
|
else:
|
||||||
|
gsub(g, n, 0)
|
||||||
of nkRaiseStmt:
|
of nkRaiseStmt:
|
||||||
putWithSpace(g, tkRaise, "raise")
|
putWithSpace(g, tkRaise, "raise")
|
||||||
gsub(g, n, 0)
|
gsub(g, n, 0)
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,9 @@ proc fn2(x, y: float): float =
|
||||||
proc fn3(x, y: int): bool =
|
proc fn3(x, y: int): bool =
|
||||||
(((x and 3) div 4) or (x mod (y xor -1))) == 0 or y notin [1,2]
|
(((x and 3) div 4) or (x mod (y xor -1))) == 0 or y notin [1,2]
|
||||||
|
|
||||||
|
proc fn4(x: int): int =
|
||||||
|
if x mod 2 == 0: return x + 2
|
||||||
|
else: return 0
|
||||||
|
|
||||||
#------------------------------------
|
#------------------------------------
|
||||||
# bug #10807
|
# bug #10807
|
||||||
|
|
@ -103,11 +106,13 @@ static:
|
||||||
let fn1s = "proc fn1(x, y: int): int =\n result = 2 * (x + y)\n"
|
let fn1s = "proc fn1(x, y: int): int =\n result = 2 * (x + y)\n"
|
||||||
let fn2s = "proc fn2(x, y: float): float =\n result = (y + 2 * x) / (x - y)\n"
|
let fn2s = "proc fn2(x, y: float): float =\n result = (y + 2 * x) / (x - y)\n"
|
||||||
let fn3s = "proc fn3(x, y: int): bool =\n result = ((x and 3) div 4 or x mod (y xor -1)) == 0 or not contains([1, 2], y)\n"
|
let fn3s = "proc fn3(x, y: int): bool =\n result = ((x and 3) div 4 or x mod (y xor -1)) == 0 or not contains([1, 2], y)\n"
|
||||||
|
let fn4s = "proc fn4(x: int): int =\n if x mod 2 == 0:\n return x + 2\n else:\n return 0\n"
|
||||||
let fnAddr = "proc fn_unsafeaddr(x: int): int =\n result = cast[int](unsafeAddr(x))\n"
|
let fnAddr = "proc fn_unsafeaddr(x: int): int =\n result = cast[int](unsafeAddr(x))\n"
|
||||||
|
|
||||||
doAssert fn1.repr_to_string == fn1s
|
doAssert fn1.repr_to_string == fn1s
|
||||||
doAssert fn2.repr_to_string == fn2s
|
doAssert fn2.repr_to_string == fn2s
|
||||||
doAssert fn3.repr_to_string == fn3s
|
doAssert fn3.repr_to_string == fn3s
|
||||||
|
doAssert fn4.repr_to_string == fn4s
|
||||||
doAssert fn_unsafeaddr.repr_to_string == fnAddr
|
doAssert fn_unsafeaddr.repr_to_string == fnAddr
|
||||||
|
|
||||||
#------------------------------------
|
#------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue