Skip to content

Commit 381ee91

Browse files
authored
minor code quality improvements (#446)
1 parent 7fa7e2a commit 381ee91

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/breakpoints.jl

+7-5
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ function framecode_matches_breakpoint(framecode::FrameCode, bp::BreakpointFileLo
165165
return false
166166
end
167167
else
168-
path, _ = whereis(framecode, 1)
168+
w = whereis(framecode, 1)
169+
w === nothing && return false
170+
path, _ = w
169171
path = CodeTracking.maybe_fix_path(path)
170172
ispath(path) && (path = realpath(path))
171173

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

188190
function prepare_slotfunction(framecode::FrameCode, body::Union{Symbol,Expr})
189-
ismeth = framecode.scope isa Method
190191
uslotnames = Set{Symbol}()
191192
slotnames = Symbol[]
192193
for name in framecode.src.slotnames
@@ -223,13 +224,14 @@ function prepare_slotfunction(framecode::FrameCode, body::Union{Symbol,Expr})
223224
push!(assignments, :($maxexsym = $maxexpr))
224225
push!(assignments, :($slotname = $maxexsym > 0 ? something($dataname.locals[$maxexsym]) : $default))
225226
end
226-
if ismeth
227-
syms = sparam_syms(framecode.scope)
227+
scope = framecode.scope
228+
if isa(scope, Method)
229+
syms = sparam_syms(scope)
228230
for i = 1:length(syms)
229231
push!(assignments, Expr(:(=), syms[i], :($dataname.sparams[$i])))
230232
end
231233
end
232-
funcname = ismeth ? gensym("slotfunction") : gensym(Symbol(framecode.scope, "_slotfunction"))
234+
funcname = isa(scope, Method) ? gensym("slotfunction") : gensym(Symbol(scope, "_slotfunction"))
233235
return Expr(:function, Expr(:call, funcname, framename), Expr(:block, assignments..., body))
234236
end
235237

src/interpret.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ end
282282
function structname(frame, node)
283283
name = node.args[1]
284284
if isa(name, GlobalRef)
285-
mod = name.module
285+
mod = name.mod
286286
name = name.name
287287
else
288288
mod = moduleof(frame)
@@ -489,7 +489,7 @@ function step_expr!(@nospecialize(recurse), frame, @nospecialize(node), istoplev
489489
elseif node.head === :const
490490
g = node.args[1]
491491
if isa(g, GlobalRef)
492-
mod, name = g.module, g.name
492+
mod, name = g.mod, g.name
493493
else
494494
mod, name = moduleof(frame), g::Symbol
495495
end

src/utils.jl

+10-2
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ function lineoffset(framecode::FrameCode)
299299
return offset
300300
end
301301

302-
getline(ln) = Int(isexpr(ln, :line) ? ln.args[1] : ln.line)::Int
302+
function getline(ln::Union{LineTypes,Expr})
303+
_getline(ln::LineTypes) = ln.line
304+
_getline(ln::Expr) = ln.args[1] # assuming ln.head === :line
305+
return Int(_getline(ln))::Int
306+
end
303307
# work around compiler error on 1.2
304308
@static if v"1.2.0" <= VERSION < v"1.3"
305309
getfile(ln) = begin
@@ -317,7 +321,11 @@ getline(ln) = Int(isexpr(ln, :line) ? ln.args[1] : ln.line)::Int
317321
CodeTracking.maybe_fixup_stdlib_path(path)
318322
end
319323
else
320-
getfile(ln) = CodeTracking.maybe_fixup_stdlib_path(String(isexpr(ln, :line) ? ln.args[2] : ln.file)::String)
324+
function getfile(ln::Union{LineTypes,Expr})
325+
_getfile(ln::LineTypes) = ln.file::Symbol
326+
_getfile(ln::Expr) = ln.args[2]::Symbol # assuming ln.head === :line
327+
return CodeTracking.maybe_fixup_stdlib_path(String(_getfile(ln)))
328+
end
321329
end
322330

323331
function firstline(ex::Expr)

0 commit comments

Comments
 (0)