Skip to content
This repository has been archived by the owner on Dec 6, 2019. It is now read-only.

Changes to make ASTInterpreter2 compile under Julia 1.0 #28

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
julia 0.6
DebuggerFramework 0.1.1
Nullables
Markdown
27 changes: 14 additions & 13 deletions src/ASTInterpreter2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module ASTInterpreter2
using DebuggerFramework
using DebuggerFramework: FileLocInfo, BufferLocInfo, Suppressed
using Base.Meta
using Base: LineEdit
using REPL.REPL.LineEdit
using Nullables
import Base: +

export @enter, @make_stack
Expand All @@ -19,7 +20,7 @@ end

struct JuliaStackFrame
meth::Method
code::CodeInfo
code::Core.CodeInfo
locals::Vector{Nullable{Any}}
ssavalues::Vector{Any}
sparams::Vector{Any}
Expand Down Expand Up @@ -118,8 +119,8 @@ end


const SEARCH_PATH = []
__init__() = append!(SEARCH_PATH,[joinpath(JULIA_HOME,"../share/julia/base/"),
joinpath(JULIA_HOME,"../include/")])
__init__() = append!(SEARCH_PATH,[joinpath(Base.Sys.BINDIR,"../share/julia/base/"),
joinpath(Base.Sys.BINDIR,"../include/")])
function loc_for_fname(file, line, defline)
if startswith(string(file),"REPL[")
hist_idx = parse(Int,string(file)[6:end-1])
Expand All @@ -143,7 +144,7 @@ function DebuggerFramework.locinfo(frame::JuliaStackFrame)
end

function lookup_var_if_var(frame, x)
if isa(x, Union{SSAValue, GlobalRef, SlotNumber}) || isexpr(x, :static_parameter) || isexpr(x, :the_exception) || isexpr(x, :boundscheck)
if isa(x, Union{Core.SSAValue, GlobalRef, Core.SlotNumber}) || isexpr(x, :static_parameter) || isexpr(x, :the_exception) || isexpr(x, :boundscheck)
return lookup_var(frame, x)
end
x
Expand Down Expand Up @@ -220,7 +221,7 @@ function DebuggerFramework.language_specific_prompt(state, frame::JuliaStackFram
if haskey(state.language_modes, :julia)
return state.language_modes[:julia]
end
julia_prompt = LineEdit.Prompt(DebuggerFramework.promptname(state.level, "julia");
julia_prompt = REPL.LineEdit.Prompt(DebuggerFramework.promptname(state.level, "julia");
# Copy colors from the prompt object
prompt_prefix = state.repl.prompt_color,
prompt_suffix = (state.repl.envcolors ? Base.input_color : repl.input_color),
Expand All @@ -235,7 +236,7 @@ function DebuggerFramework.language_specific_prompt(state, frame::JuliaStackFram

julia_prompt.on_done = (s,buf,ok)->begin
if !ok
LineEdit.transition(s, :abort)
REPL.LineEdit.transition(s, :abort)
return false
end
xbuf = copy(buf)
Expand All @@ -248,14 +249,14 @@ function DebuggerFramework.language_specific_prompt(state, frame::JuliaStackFram
# Convenience hack. We'll see if this is more useful or annoying
for c in all_commands
!startswith(command, c) && continue
LineEdit.transition(s, state.main_mode)
LineEdit.state(s, state.main_mode).input_buffer = xbuf
REPL.LineEdit.transition(s, state.main_mode)
REPL.LineEdit.state(s, state.main_mode).input_buffer = xbuf
break
end
end
LineEdit.reset_state(s)
REPL.LineEdit.reset_state(s)
end
julia_prompt.keymap_dict = LineEdit.keymap([Base.REPL.mode_keymap(state.main_mode);state.standard_keymap])
julia_prompt.keymap_dict = REPL.LineEdit.keymap([Base.REPL.mode_keymap(state.main_mode);state.standard_keymap])
state.language_modes[:julia] = julia_prompt
return julia_prompt
end
Expand Down Expand Up @@ -367,7 +368,7 @@ function get_source(meth)
end
end

function copy_codeinfo(code::CodeInfo)
function copy_codeinfo(code::Core.CodeInfo)
old_code = code.code
code.code = UInt8[]
new_codeinfo = deepcopy(code)
Expand Down Expand Up @@ -420,7 +421,7 @@ function maybe_step_through_wrapper!(stack)
last = stack[1].code.code[end-1]
isexpr(last, :(=)) && (last = last.args[2])
is_kw = startswith(String(Base.unwrap_unionall(stack[1].meth.sig).parameters[1].name.name), "#kw")
if is_kw || isexpr(last, :call) && any(x->x==SlotNumber(1), last.args)
if is_kw || isexpr(last, :call) && any(x->x==Core.SlotNumber(1), last.args)
# If the last expr calls #self# or passes it to an implemetnation method,
# this is a wrapper function that we might want to step though
frame = stack[1]
Expand Down
4 changes: 3 additions & 1 deletion src/commands.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Markdown

function perform_return!(state)
returning_frame = state.stack[1]
returning_expr = pc_expr(returning_frame)
Expand Down Expand Up @@ -157,7 +159,7 @@ end

function DebuggerFramework.execute_command(state, frane::JuliaStackFrame, ::Val{:?}, cmd)
display(
Base.@md_str """
@md_str """
Basic Commands:\\
- `n` steps to the next line\\
- `s` steps into the next call\\
Expand Down
14 changes: 8 additions & 6 deletions src/interpret.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Implements a simple interpreter for julia's lowered AST

lookup_var(frame, val::SSAValue) = frame.ssavalues[val.id+1]
using Nullables

lookup_var(frame, val::Core.SSAValue) = frame.ssavalues[val.id+1]
lookup_var(frame, ref::GlobalRef) = getfield(ref.mod, ref.name)
lookup_var(frame, slot::SlotNumber) = get(frame.locals[slot.id])
lookup_var(frame, slot::Core.SlotNumber) = get(frame.locals[slot.id])
function lookup_var(frame, e::Expr)
isexpr(e, :the_exception) && return get(frame.last_exception[])
isexpr(e, :boundscheck) && return true
Expand All @@ -28,7 +30,7 @@ function evaluate_call(frame, call_expr)
arg = call_expr.args[i]
if isa(arg, QuoteNode)
args[i] = arg.value
elseif isa(arg, Union{SSAValue, GlobalRef, Slot})
elseif isa(arg, Union{Core.SSAValue, GlobalRef, Slot})
args[i] = lookup_var(frame, arg)
elseif isexpr(arg, :&)
args[i] = Expr(:&, lookup_var(frame, arg.args[1]))
Expand All @@ -51,7 +53,7 @@ function evaluate_call(frame, call_expr)
ret = eval(frame.meth.module, Expr(:foreigncall, args...))
else
f = to_function(args[1])
if isa(f, CodeInfo)
if isa(f, Core.CodeInfo)
ret = finish!(enter_call_expr(frame, call_expr))
else
# Don't go through eval since this may have unqouted, symbols and
Expand All @@ -63,7 +65,7 @@ function evaluate_call(frame, call_expr)
end

function do_assignment!(frame, lhs, rhs)
if isa(lhs, SSAValue)
if isa(lhs, Core.SSAValue)
frame.ssavalues[lhs.id+1] = rhs
elseif isa(lhs, Slot)
frame.locals[lhs.id] = Nullable{Any}(rhs)
Expand Down Expand Up @@ -171,7 +173,7 @@ is a wrapper (either because of optional arguments or becaue of keyword argument
"""
function iswrappercall(expr)
isexpr(expr, :(=)) && (expr = expr.args[2])
isexpr(expr, :call) && any(x->x==SlotNumber(1), expr.args)
isexpr(expr, :call) && any(x->x==Core.SlotNumber(1), expr.args)
end

pc_expr(frame, pc) = frame.code.code[pc.next_stmt]
Expand Down
13 changes: 7 additions & 6 deletions src/linearize.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

# Linearizer. Future versions of julia will emit fully-linear IR, so this way upgrading should be easier.
# This is taken from inference.jl on julia master
function newvar!(code::CodeInfo, typ)
function newvar!(code::Core.CodeInfo, typ)
if isa(code.ssavaluetypes, Int)
id = code.ssavaluetypes::Int
code.ssavaluetypes = id + 1
else
id = length(code.ssavaluetypes)
push!(code.ssavaluetypes, typ)
end
return SSAValue(id)
return Core.SSAValue(id)
end

is_meta_expr_head(head::Symbol) =
Expand All @@ -21,7 +22,7 @@ function is_ccall_static(e::Expr)
length(e.args) == 3 || return false
for i in 2:3
a = e.args[i]
(isa(a, Expr) || isa(a, Slot) || isa(a, SSAValue)) && return false
(isa(a, Expr) || isa(a, Slot) || isa(a, Core.SSAValue)) && return false
end
return true
elseif e.head === :static_parameter
Expand All @@ -30,7 +31,7 @@ function is_ccall_static(e::Expr)
return false
end

function linearize_arg!(args, i, stmts, code::CodeInfo)
function linearize_arg!(args, i, stmts, code::Core.CodeInfo)
a = args[i]
if isa(a, Symbol)
a = a::Symbol
Expand Down Expand Up @@ -90,7 +91,7 @@ function relabel!(body::Vector{Any})
end
end

function linearize!(code::CodeInfo)
function linearize!(code::Core.CodeInfo)
body = code.code
len = length(body)
next_i = 1
Expand Down Expand Up @@ -161,4 +162,4 @@ function linearize!(code::CodeInfo)
empty!(stmts)
end
relabel!(body)
end
end