Skip to content

Commit

Permalink
minor code quality improvements (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Dec 19, 2020
1 parent 7fa7e2a commit 381ee91
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/breakpoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ function framecode_matches_breakpoint(framecode::FrameCode, bp::BreakpointFileLo
return false
end
else
path, _ = whereis(framecode, 1)
w = whereis(framecode, 1)
w === nothing && return false
path, _ = w
path = CodeTracking.maybe_fix_path(path)
ispath(path) && (path = realpath(path))

Expand All @@ -186,7 +188,6 @@ function shouldbreak(frame::Frame, pc::Int)
end

function prepare_slotfunction(framecode::FrameCode, body::Union{Symbol,Expr})
ismeth = framecode.scope isa Method
uslotnames = Set{Symbol}()
slotnames = Symbol[]
for name in framecode.src.slotnames
Expand Down Expand Up @@ -223,13 +224,14 @@ function prepare_slotfunction(framecode::FrameCode, body::Union{Symbol,Expr})
push!(assignments, :($maxexsym = $maxexpr))
push!(assignments, :($slotname = $maxexsym > 0 ? something($dataname.locals[$maxexsym]) : $default))
end
if ismeth
syms = sparam_syms(framecode.scope)
scope = framecode.scope
if isa(scope, Method)
syms = sparam_syms(scope)
for i = 1:length(syms)
push!(assignments, Expr(:(=), syms[i], :($dataname.sparams[$i])))
end
end
funcname = ismeth ? gensym("slotfunction") : gensym(Symbol(framecode.scope, "_slotfunction"))
funcname = isa(scope, Method) ? gensym("slotfunction") : gensym(Symbol(scope, "_slotfunction"))
return Expr(:function, Expr(:call, funcname, framename), Expr(:block, assignments..., body))
end

Expand Down
4 changes: 2 additions & 2 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ end
function structname(frame, node)
name = node.args[1]
if isa(name, GlobalRef)
mod = name.module
mod = name.mod
name = name.name
else
mod = moduleof(frame)
Expand Down Expand Up @@ -489,7 +489,7 @@ function step_expr!(@nospecialize(recurse), frame, @nospecialize(node), istoplev
elseif node.head === :const
g = node.args[1]
if isa(g, GlobalRef)
mod, name = g.module, g.name
mod, name = g.mod, g.name
else
mod, name = moduleof(frame), g::Symbol
end
Expand Down
12 changes: 10 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ function lineoffset(framecode::FrameCode)
return offset
end

getline(ln) = Int(isexpr(ln, :line) ? ln.args[1] : ln.line)::Int
function getline(ln::Union{LineTypes,Expr})
_getline(ln::LineTypes) = ln.line
_getline(ln::Expr) = ln.args[1] # assuming ln.head === :line
return Int(_getline(ln))::Int
end
# work around compiler error on 1.2
@static if v"1.2.0" <= VERSION < v"1.3"
getfile(ln) = begin
Expand All @@ -317,7 +321,11 @@ getline(ln) = Int(isexpr(ln, :line) ? ln.args[1] : ln.line)::Int
CodeTracking.maybe_fixup_stdlib_path(path)
end
else
getfile(ln) = CodeTracking.maybe_fixup_stdlib_path(String(isexpr(ln, :line) ? ln.args[2] : ln.file)::String)
function getfile(ln::Union{LineTypes,Expr})
_getfile(ln::LineTypes) = ln.file::Symbol
_getfile(ln::Expr) = ln.args[2]::Symbol # assuming ln.head === :line
return CodeTracking.maybe_fixup_stdlib_path(String(_getfile(ln)))
end
end

function firstline(ex::Expr)
Expand Down

0 comments on commit 381ee91

Please sign in to comment.