diff --git a/app/block_view.rb b/app/block_view.rb index 0d27c42..6480cb1 100644 --- a/app/block_view.rb +++ b/app/block_view.rb @@ -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 diff --git a/app/debugger.rb b/app/debugger.rb index 9526659..7fe5060 100644 --- a/app/debugger.rb +++ b/app/debugger.rb @@ -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 diff --git a/app/source_view.rb b/app/source_view.rb index b288ebe..3efbb68 100644 --- a/app/source_view.rb +++ b/app/source_view.rb @@ -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 diff --git a/app/status_view.rb b/app/status_view.rb new file mode 100644 index 0000000..a7cc425 --- /dev/null +++ b/app/status_view.rb @@ -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 diff --git a/lib/interpreter.rb b/lib/interpreter.rb index 52c8f1b..21b606d 100644 --- a/lib/interpreter.rb +++ b/lib/interpreter.rb @@ -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}"