Last active
November 17, 2018 08:27
-
-
Save kim366/927d1780744f2f512d4ea8a65e9d1c26 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const breakpoints = Int[4, 6] | |
const registeredvars = Symbol[] | |
const filename = "testscript.jl" | |
module Exec end | |
function evalandregister(line::String) | |
ast = Meta.parse(line) | |
typeof(ast) == Expr || return | |
if length(ast.args) == 2 && typeof(ast.args[1]) == Symbol | |
try | |
Exec.eval(ast.args[1]) | |
catch e | |
typeof(e) === UndefVarError && push!(registeredvars, ast.args[1]) | |
end | |
end | |
Exec.eval(ast) | |
end | |
function printvars() | |
for var in registeredvars | |
println(var, " = ", Exec.eval(var)) | |
end | |
end | |
function nextbreakpoint() | |
for line in @view lines[lineno:end] | |
if (lineno in breakpoints) | |
filter!(b -> b ≠ lineno, breakpoints) | |
break | |
else | |
evalandregister(line) | |
global lineno += 1 | |
end | |
end | |
end | |
input = "" | |
const lines = open(filename) do file; [eachline(file)...] end | |
lineno = 1 | |
while true | |
(lineno == 1 || input == "n") && nextbreakpoint() | |
input == "p" && printvars() | |
lineno <= length(lines) || break | |
global input = readline() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment