Skip to content

Commit 7a25d75

Browse files
committed
Cleanup
1 parent b66f6e2 commit 7a25d75

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

src/DebuggerFramework.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
__precompile__()
22
module DebuggerFramework
33
using TerminalUI
4-
5-
abstract StackFrame
4+
5+
abstract type StackFrame end
66

77
function print_var(io::IO, name, val::Nullable, undef_callback)
88
print(" | ")
@@ -28,13 +28,13 @@ module DebuggerFramework
2828
print_locdesc(io, frame)
2929
print_locals(io, frame)
3030
end
31-
31+
3232
function print_backtrace(state)
3333
for (num, frame) in enumerate(state.stack)
3434
print_frame(state, Base.pipe_writer(state.terminal), num, frame)
3535
end
3636
end
37-
37+
3838
print_backtrace(state, _::Void) = nothing
3939

4040
function execute_command(state, frame, ::Val{:bt}, cmd)
@@ -67,14 +67,14 @@ module DebuggerFramework
6767
"""
6868
function debug
6969
end
70-
71-
type DebuggerState
70+
71+
mutable struct DebuggerState
7272
stack
7373
level
7474
main_mode
7575
terminal
7676
end
77-
77+
7878
function print_status_synthtic(io, state, frame, lines_before, total_lines)
7979
return 0
8080
end
@@ -104,8 +104,8 @@ module DebuggerFramework
104104
end
105105
print(io, String(take!(outbuf)))
106106
end
107-
108-
immutable AbstractDiagnostic; end
107+
108+
struct AbstractDiagnostic; end
109109

110110
function execute_command
111111
end

test/brainstack.jl

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ reload("DebuggerFramework")
1515

1616
module BrainStack
1717
using DebuggerFramework
18-
immutable BrainStackAST
18+
struct BrainStackAST
1919
stmts::Vector{Vector{Int}}
2020
end
21-
21+
2222
function Base.parse(::Type{BrainStackAST}, data)
2323
BrainStackAST(map(enumerate(split(data, '\n', keep=false))) do args
2424
lineno, line = args
@@ -27,15 +27,15 @@ module BrainStack
2727
map(x->parse(Int,x), parts[2:end])
2828
end)
2929
end
30-
31-
type BrainStackInterpreterState
30+
31+
mutable struct BrainStackInterpreterState
3232
ast::BrainStackAST
3333
stack::Vector{Tuple{Int, Int}}
3434
idx::Int
3535
pos::Int
3636
ncalls::Int
3737
end
38-
38+
3939
# Helpfully split up the interpreter to be re-usable from the debugger below
4040
enter(ast::BrainStackAST) = BrainStackInterpreterState(ast, [(0,0)], 1, 1, 0)
4141
function step_one!(state::BrainStackInterpreterState)
@@ -58,20 +58,20 @@ module BrainStack
5858
while step_one!(state); end
5959
state.ncalls
6060
end
61-
62-
61+
62+
6363
# Debugger support
64-
immutable BrainStackStackRef <: DebuggerFramework.StackFrame
64+
struct BrainStackStackRef <: DebuggerFramework.StackFrame
6565
state::BrainStackInterpreterState
6666
idx::Int
6767
end
68-
68+
6969
function DebuggerFramework.debug(ast::BrainStackAST, args...)
7070
state = enter(ast)
7171
stack = [BrainStackStackRef(state, 0)]
7272
DebuggerFramework.RunDebugger(stack, args...)
7373
end
74-
74+
7575
function idxpos(frame)
7676
if frame.idx == 0
7777
idx, pos = frame.state.idx, frame.state.pos
@@ -80,7 +80,7 @@ module BrainStack
8080
end
8181
idx, pos
8282
end
83-
83+
8484
function DebuggerFramework.print_status_synthtic(io::IO, state, frame::BrainStackStackRef, lines_before, total_lines)
8585
ast = frame.state.ast
8686
idx, pos = idxpos(frame)
@@ -93,17 +93,18 @@ module BrainStack
9393
end
9494
(opno != length(ast.stmts[idx])) && print(io, ' ')
9595
end
96+
return 1
9697
end
97-
98+
9899
DebuggerFramework.locdesc(frame::BrainStackStackRef) = "statement $(idxpos(frame)[1])"
99-
100+
100101
function update_stack!(ds, state, stack)
101102
ds.stack = [BrainStackStackRef(state, i) for i = 0:length(stack)-1]
102103
if ds.level > length(ds.stack)
103104
ds.level = length(ds.stack)
104105
end
105106
end
106-
107+
107108
function DebuggerFramework.execute_command(state, frame::BrainStackStackRef, cmd::Val{:si}, command)
108109
step_one!(frame.state)
109110
update_stack!(state, frame.state, frame.state.stack)

test/llvmir.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module LLVMIRDebugger
1515
#include "llvm/IRReader/IRReader.h"
1616
#include "llvm/Support/MemoryBuffer.h"
1717
#include "llvm/IR/ModuleSlotTracker.h"
18-
18+
1919
// This is a private LLVM header at the moment
2020
#include "lib/ExecutionEngine/Interpreter/Interpreter.h"
2121
@@ -55,7 +55,7 @@ module LLVMIRDebugger
5555
function Base.parse(::Type{pcpp"llvm::Module"}, data)
5656
mod = icxx"""
5757
llvm::SMDiagnostic Err;
58-
auto mod =
58+
auto mod =
5959
llvm::parseIR($(convert(vcpp"llvm::MemoryBufferRef", data)),
6060
Err, jl_LLVMContext);
6161
if (!mod) {
@@ -145,12 +145,12 @@ module LLVMIRDebugger
145145
BB = icxx"$(frame.state.Interp)->ECStack[$(frame.idx)].CurBB;"
146146
"function $(getName(F)), BB $(getName(BB))"
147147
end
148-
148+
149149
immutable AggregateValue
150150
values::Vector{Any}
151151
end
152152
Base.print(io::IO, val::AggregateValue) = print(io, val.values)
153-
153+
154154
function fromGenericValue(typ::pcpp"llvm::Type", val::vcpp"llvm::GenericValue")
155155
if icxx"$typ->isVoidTy();"
156156
return nothing
@@ -164,7 +164,7 @@ module LLVMIRDebugger
164164
elseif icxx"$typ->isPointerTy();"
165165
return icxx"$val.PointerVal;"
166166
elseif icxx"$typ->isAggregateType();"
167-
return AggregateValue(Any[fromGenericValue(x...) for x in
167+
return AggregateValue(Any[fromGenericValue(x...) for x in
168168
zip(icxx"$typ->subtypes();", icxx"$val.AggregateVal;")])
169169
elseif icxx"$typ->isIntegerTy();"
170170
# Good enough for now
@@ -173,7 +173,7 @@ module LLVMIRDebugger
173173
error("Unsupported type")
174174
end
175175
end
176-
176+
177177
function DebuggerFramework.print_locals(io::IO, frame::LLVMIRFrame)
178178
MST = icxx"new llvm::ModuleSlotTracker{$(frame.state.M), true};"
179179
icxx"$MST->incorporateFunction(*$(CurFunction(frame)));"
@@ -187,15 +187,15 @@ module LLVMIRDebugger
187187
end
188188
icxx"delete $MST;"
189189
end
190-
190+
191191
function update_stack!(ds, state)
192192
stacksize = Int(icxx"$(state.Interp)->ECStack.size();"-1)
193193
ds.stack = [LLVMIRFrame(state, i) for i = stacksize:-1:0]
194194
if ds.level > length(ds.stack)
195195
ds.level = length(ds.stack)
196196
end
197197
end
198-
198+
199199
function DebuggerFramework.execute_command(state, frame::LLVMIRFrame, cmd::Val{:si}, command)
200200
step_one!(frame.state)
201201
update_stack!(state, frame.state)

test/runtests.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using DebuggerFramework
22
using Base.Test
33

4-
# write your own tests here
5-
@test 1 == 2
4+
include("brainstack.jl")

0 commit comments

Comments
 (0)