better view for registers

This commit is contained in:
Torsten Ruger 2015-07-26 12:51:57 +03:00
parent 6ba3c54690
commit 6ce51c38db
4 changed files with 71 additions and 33 deletions

View File

@ -1,4 +1,9 @@
require "register_view"
require "class_view"
require "source_view"
require "block_view"
class Debugger class Debugger
include React::Component include React::Component
@ -26,7 +31,13 @@ class Debugger
BlockView interpreter: interpreter BlockView interpreter: interpreter
end end
end end
RegisterView interpreter: interpreter div.row do
interpreter.registers.each do |r , oid|
div.col_md_1 do
RegisterView interpreter: interpreter , register: r
end
end
end
end end
end end
end end

View File

@ -6,10 +6,6 @@ require "interpreter"
require 'opal-react' require 'opal-react'
require "class_view"
require "register_view"
require "source_view"
require "block_view"
require "debugger" require "debugger"
require 'opal-jquery' require 'opal-jquery'

View File

@ -1,45 +1,50 @@
class RegisterView class RegisterView
include React::Component include React::Component
required_param :interpreter required_param :interpreter
define_state :registers required_param :register
define_state :objects_id
define_state :fields => []
before_mount do before_mount do
interpreter.register_event(:register_changed, self) interpreter.register_event(:register_changed, self)
registers! interpreter.registers register_changed( register , nil , interpreter.registers[register])
end end
def register_changed reg , old , bl def register_changed reg , old , value
registers! interpreter.registers return unless reg == register
objects_id! value
calc_fields
end
def calc_fields
puts "My id #{objects_id} , #{objects_id.class}"
object = Virtual.machine.objects[objects_id]
if object and ! object.is_a?(String)
has_fields = []
clazz = object.class.name.split("::").last
puts "found #{clazz}"
has_fields << clazz
object.get_instance_variables.each do |variable|
has_fields << object.get_instance_variable(variable).to_s
end
fields! has_fields
end
end end
def render def render
div.row do div.row do
registers.each do |r , has| div.col_md_12 do
div.col_md_1 do objects_id.to_s
div.row do end
div.col_md_12 do fields.each do |variable|
"#{r} : #{has}" div.col_md_12 do
end variable.span
if object = has_object(has) end
div.col_md_12 do
object.class.name.split("::").last.span
end
object.get_instance_variables.each do |variable|
div.col_md_12 do
## deal with String
## even better, make ObjectView
object.get_instance_variable(variable).to_s.span
end
end
end #if
end
end #row
end end
end end
end end
def has_object has
object = Virtual.machine.objects[has]
end
end end

26
app/registers_view.rb Normal file
View File

@ -0,0 +1,26 @@
require "register_view"
class RegistersView
include React::Component
required_param :interpreter
def render
div.row do
interpreter.registers.each do |r , has|
div.col_md_1 do
div.row do
div.col_md_12 do
" #{has}"
end
div.col_md_12 do
ObjectView :object_id => has
end
end
end #row
end
end
end
end