Skip to content

Commit

Permalink
Merge pull request #4 from mirimmad/main
Browse files Browse the repository at this point in the history
graceful exit on ctrl+c
  • Loading branch information
tenderlove authored Dec 1, 2021
2 parents 83de67f + 1de2a93 commit f58db86
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions lib/asmrepl/repl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,40 @@ def start
pos = (state.rip - @buffer.memory.to_i)
@buffer.seek pos
use_history = true
loop do
cmd = nil
text = Reline.readmultiline(">> ", use_history) do |multiline_input|
if multiline_input =~ /\A\s*(\w+)\s*\Z/
register = $1
cmd = [:read, register]
else
cmd = :run
begin
loop do
cmd = nil
text = Reline.readmultiline(">> ", use_history) do |multiline_input|
if multiline_input =~ /\A\s*(\w+)\s*\Z/
register = $1
cmd = [:read, register]
else
cmd = :run
end
true
end
true
end

case cmd
in :run
break if text.chomp.empty?
binary = @assembler.assemble @parser.parse text.chomp
binary.bytes.each { |byte| @buffer.putc byte }
break
in [:read, "cpu"]
display_state state
in [:read, reg]
val = state[reg]
if val
puts sprintf("%#018x", state[reg])
case cmd
in :run
break if text.chomp.empty?
binary = @assembler.assemble @parser.parse text.chomp
binary.bytes.each { |byte| @buffer.putc byte }
break
in [:read, "cpu"]
display_state state
in [:read, reg]
val = state[reg]
if val
puts sprintf("%#018x", state[reg])
else
puts "Unknown command: "
puts " " + text
end
else
puts "Unknown command: "
puts " " + text
end
else
end
rescue Interrupt
exit 0
end
tracer.continue
end
Expand Down

0 comments on commit f58db86

Please sign in to comment.