add status view and fixes

This commit is contained in:
Torsten Ruger 2015-07-28 16:16:09 +03:00
parent 557c455167
commit 756ab31a61
5 changed files with 57 additions and 5 deletions

View File

@ -1,5 +1,4 @@
require "source_view"
require "instruction_view"
class BlockView
@ -16,6 +15,7 @@ class BlockView
end
def update_block
return unless interpreter.instruction
block_name! interpreter.block.name
codes = interpreter.block.codes.dup
slice = codes.index(interpreter.instruction) #- 1
@ -32,12 +32,18 @@ class BlockView
return unless block
div.block_view do
div do
h4 { method_name}
h4 {"Block: #{block_name}"}
button.btn.btn_default { "next" }.on(:click) { interpreter.tick }
end
block.each do |code|
InstructionView :interpreter => interpreter , :instruction => code
end
end
end
def method_name
bl = interpreter.block
return bl.method if bl.method.is_a? String
"#{bl.method.for_class.name}.#{bl.method.name}"
end
end

View File

@ -3,6 +3,7 @@ require "register_view"
require "class_view"
require "source_view"
require "block_view"
require "status_view"
class Debugger
@ -24,6 +25,7 @@ class Debugger
end
SourceView :interpreter => interpreter
BlockView :interpreter => interpreter
StatusView :interpreter => interpreter
div.registers_view do
interpreter.registers.each do |r , oid|
RegisterView interpreter: interpreter , register: r

View File

@ -12,7 +12,7 @@ class SourceView
end
def instruction_changed old , ins
text = source_text(ins.source)
text = ins ? source_text(ins.source) : "exit"
return if sources.last == text
sources << text
sources.shift if sources.length > 5

41
app/status_view.rb Normal file
View File

@ -0,0 +1,41 @@
class StatusView
include React::Component
required_param :interpreter
define_state :state => "starting"
define_state :stdout
before_mount do
interpreter.register_event(:instruction_changed, self)
end
def update_state
state! interpreter.state
stdout! interpreter.stdout
end
def instruction_changed old , nex
update_state
end
def render
div.status_view do
div do
button.btn.btn_default { "next" }.on(:click) { interpreter.tick }
" ".br
end
div do
h4 {"Status:"}
state.to_s.br
end
div do
h4 {"Stdout:"}
end
div do
interpreter.stdout.br
end
end
end
end

View File

@ -20,7 +20,10 @@ class Interpreter
# collect the output
attr_reader :stdout
attr_reader :state
def initialize
@state = "runnnig"
@stdout = ""
@registers = {}
(0...12).each do |r|
@ -42,8 +45,8 @@ class Interpreter
end
def set_instruction i
@state = "exited" unless i
return if @instruction == i
raise "Error, nil instruction" unless i
old = @instruction
@instruction = i
trigger(:instruction_changed, old , i)
@ -142,7 +145,7 @@ class Interpreter
raise "NO string for putstring #{str}" unless str.is_a? Symbol
@stdout += str.to_s
when :exit
@instruction = nil
set_instruction(nil)
return false
else
raise "un-implemented syscall #{name}"