From 6ce51c38db98f64139b01b3a4fd3d8855beb5924 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 26 Jul 2015 12:51:57 +0300 Subject: [PATCH] better view for registers --- app/debugger.rb | 13 ++++++++- app/main.rb | 4 --- app/register_view.rb | 61 +++++++++++++++++++++++-------------------- app/registers_view.rb | 26 ++++++++++++++++++ 4 files changed, 71 insertions(+), 33 deletions(-) create mode 100644 app/registers_view.rb diff --git a/app/debugger.rb b/app/debugger.rb index 0a72284..e0a3c93 100644 --- a/app/debugger.rb +++ b/app/debugger.rb @@ -1,4 +1,9 @@ +require "register_view" +require "class_view" +require "source_view" +require "block_view" + class Debugger include React::Component @@ -26,7 +31,13 @@ class Debugger BlockView interpreter: interpreter 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 diff --git a/app/main.rb b/app/main.rb index 85038e8..640bf5a 100644 --- a/app/main.rb +++ b/app/main.rb @@ -6,10 +6,6 @@ require "interpreter" require 'opal-react' -require "class_view" -require "register_view" -require "source_view" -require "block_view" require "debugger" require 'opal-jquery' diff --git a/app/register_view.rb b/app/register_view.rb index 4e80a95..839c79f 100644 --- a/app/register_view.rb +++ b/app/register_view.rb @@ -1,45 +1,50 @@ + class RegisterView include React::Component required_param :interpreter - define_state :registers + required_param :register + + define_state :objects_id + define_state :fields => [] before_mount do interpreter.register_event(:register_changed, self) - registers! interpreter.registers + register_changed( register , nil , interpreter.registers[register]) end - def register_changed reg , old , bl - registers! interpreter.registers + def register_changed reg , old , value + 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 def render - div.row do - registers.each do |r , has| - div.col_md_1 do - div.row do - div.col_md_12 do - "#{r} : #{has}" - end - if object = has_object(has) - 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 + div.row do + div.col_md_12 do + objects_id.to_s + end + fields.each do |variable| + div.col_md_12 do + variable.span + end end end end - def has_object has - object = Virtual.machine.objects[has] - end end diff --git a/app/registers_view.rb b/app/registers_view.rb new file mode 100644 index 0000000..85ec19c --- /dev/null +++ b/app/registers_view.rb @@ -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