Skip to content

Commit

Permalink
Merge pull request #29 from pfitzseb/sp/betterlinenumbers
Browse files Browse the repository at this point in the history
slightly better line numbers
  • Loading branch information
timholy committed Feb 15, 2019
2 parents e2f5344 + db01ee8 commit 0c9a08a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,10 @@ isgotonode(node) = isa(node, GotoNode) || isexpr(node, :gotoifnot)

location(frame) = location(frame, frame.pc[])
function location(frame, pc)
ln = frame.code.code.codelocs[pc.next_stmt]
return frame.code.scope isa Method ? ln + frame.code.scope.line - 1 : ln
codeloc = frame.code.code.codelocs[pc.next_stmt]
return frame.code.scope isa Method ?
frame.code.code.linetable[codeloc].line :
codeloc
end
function next_line!(stack, frame, dbstack = nothing)
initial = location(frame)
Expand Down
15 changes: 15 additions & 0 deletions test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,18 @@ JuliaInterpreter.finish_and_return!(JuliaStackFrame[], frame, true)
val = @interpret(BigInt())
@test isa(val, BigInt) && val == 0
@test isa(@interpret(Base.GMP.version()), VersionNumber)

# "correct" line numbers
defline = @__LINE__() + 1
function f(x)
x = 2x
# comment
# comment
x = 2x
# comment
return x*x
end
frame = JuliaInterpreter.enter_call(f, 3)
@test JuliaInterpreter.location(frame, JuliaInterpreter.JuliaProgramCounter(1)) == defline + 1
@test JuliaInterpreter.location(frame, JuliaInterpreter.JuliaProgramCounter(3)) == defline + 4
@test JuliaInterpreter.location(frame, JuliaInterpreter.JuliaProgramCounter(5)) == defline + 6

0 comments on commit 0c9a08a

Please sign in to comment.