Multiple C lines corresponding to a single nimrod line are joined together
This patch greatly improves the "step over" operation available in debuggers. In practice, there are often 4-8 lines of C code generated for each nimrod line Each such line will be responsible to a single step in the debugger that is a) not expected by the user b) taking the user to an incorrect line in the nimrod code To keep this working, all code generation should use the rope formatting facilities when producing new lines (i.e. $n and $N). New semantics for the format string are introduced: $n means "soft new line" that could be joined/broken when lineDir is enabled. $N means "hard new line" that will always appear as a new line. As an alternative to this approach, I also tested producing code like this: #line "code.nim" 154 foo = bar; \ foo(bar) \ This is better for readability of the final output, but unfortunately it didn't produce the desired result across all compilers/debuggers.
This commit is contained in:
parent
0f0dfd6379
commit
0b197ade6c
6 changed files with 81 additions and 61 deletions
|
|
@ -105,7 +105,7 @@ proc bitSetToWord(s: TBitSet, size: int): BiggestInt =
|
|||
proc genRawSetData(cs: TBitSet, size: int): PRope =
|
||||
var frmt: TFormatStr
|
||||
if size > 8:
|
||||
result = toRope('{' & tnl)
|
||||
result = ropef("{$n")
|
||||
for i in countup(0, size - 1):
|
||||
if i < size - 1:
|
||||
# not last iteration?
|
||||
|
|
@ -797,14 +797,14 @@ proc fixupCall(p: BProc, t: PNode, d: var TLoc, pl: PRope) =
|
|||
app(pl, addrLoc(d))
|
||||
app(pl, ")")
|
||||
app(p.s[cpsStmts], pl)
|
||||
app(p.s[cpsStmts], ';' & tnl)
|
||||
appf(p.s[cpsStmts], ";$n")
|
||||
else:
|
||||
var tmp: TLoc
|
||||
getTemp(p, typ.sons[0], tmp)
|
||||
app(pl, addrLoc(tmp))
|
||||
app(pl, ")")
|
||||
app(p.s[cpsStmts], pl)
|
||||
app(p.s[cpsStmts], ';' & tnl)
|
||||
appf(p.s[cpsStmts], ";$n")
|
||||
genAssignment(p, d, tmp, {}) # no need for deep copying
|
||||
else:
|
||||
app(pl, ")")
|
||||
|
|
@ -817,7 +817,7 @@ proc fixupCall(p: BProc, t: PNode, d: var TLoc, pl: PRope) =
|
|||
else:
|
||||
app(pl, ")")
|
||||
app(p.s[cpsStmts], pl)
|
||||
app(p.s[cpsStmts], ';' & tnl)
|
||||
appf(p.s[cpsStmts], ";$n")
|
||||
|
||||
proc openArrayLoc(a: TLoc): PRope =
|
||||
case skipTypes(a.t, abstractVar).kind
|
||||
|
|
@ -926,14 +926,14 @@ proc genNamedParamCall(p: BProc, t: PNode, d: var TLoc) =
|
|||
app(pl, addrLoc(d))
|
||||
app(pl, "]")
|
||||
app(p.s[cpsStmts], pl)
|
||||
app(p.s[cpsStmts], ';' & tnl)
|
||||
appf(p.s[cpsStmts], ";$n")
|
||||
else:
|
||||
var tmp: TLoc
|
||||
getTemp(p, typ.sons[0], tmp)
|
||||
app(pl, addrLoc(tmp))
|
||||
app(pl, "]")
|
||||
app(p.s[cpsStmts], pl)
|
||||
app(p.s[cpsStmts], ';' & tnl)
|
||||
appf(p.s[cpsStmts], ";$n")
|
||||
genAssignment(p, d, tmp, {}) # no need for deep copying
|
||||
else:
|
||||
app(pl, "]")
|
||||
|
|
@ -946,7 +946,7 @@ proc genNamedParamCall(p: BProc, t: PNode, d: var TLoc) =
|
|||
else:
|
||||
app(pl, "]")
|
||||
app(p.s[cpsStmts], pl)
|
||||
app(p.s[cpsStmts], ';' & tnl)
|
||||
appf(p.s[cpsStmts], ";$n")
|
||||
|
||||
proc genStrConcat(p: BProc, e: PNode, d: var TLoc) =
|
||||
# <Nimrod code>
|
||||
|
|
@ -1839,7 +1839,7 @@ proc genConstSimpleList(p: BProc, n: PNode): PRope =
|
|||
for i in countup(0, length - 2):
|
||||
appf(result, "$1,$n", [genNamedConstExpr(p, n.sons[i])])
|
||||
if length > 0: app(result, genNamedConstExpr(p, n.sons[length - 1]))
|
||||
app(result, '}' & tnl)
|
||||
appf(result, "}$n")
|
||||
|
||||
proc genConstExpr(p: BProc, n: PNode): PRope =
|
||||
case n.Kind
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue