fix register update

This commit is contained in:
Torsten Ruger 2015-07-30 14:00:49 +03:00
parent 08beaa2d93
commit e8a5a20db1
4 changed files with 46 additions and 7 deletions

View File

@ -114,7 +114,7 @@ class Interpreter
value = object_for( @instruction.register )
object = object_for( @instruction.array )
object.internal_object_set( @instruction.index , value )
trigger(:object_changed, @instruction.register )
trigger(:object_changed, @instruction.array )
true
end

View File

@ -12,11 +12,11 @@ module Main
init_blocks
end
def tick
@interpreter.tick
end
private
def marker var
return "W" if var.is_a? String
var.class.name.split("::").last[0]
end
def init_machine
machine = Virtual.machine.boot
code = Ast::ExpressionList.new( [Ast::CallSiteExpression.new(:putstring, [] ,Ast::StringExpression.new("Hello again"))])
@ -28,7 +28,11 @@ module Main
def init_registers
page._registers!.clear
@interpreter.registers.each do |reg , val|
page._registers << RegisterModel.new( :name => reg , :value => val)
model = RegisterModel.new( :name => reg , :value => val)
page._registers << model
@interpreter.register_event(:register_changed, model)
@interpreter.register_event(:object_changed, model)
model.register_changed( reg , nil , @interpreter.registers[reg])
end
end
def init_classes

View File

@ -1,10 +1,40 @@
class RegisterModel < Volt::Model
field :name
field :value
field :fields
def register_changed reg , old , ins
self.last._class_name = "" if( self.length > 0)
self << { :name => ins.to_s , :class_name => "active" }
end
def register_changed reg , old , value
reg = reg.symbol unless reg.is_a? Symbol
return unless reg == name
self.value = value
calc_fields
end
def object_changed reg
reg = reg.symbol unless reg.is_a? Symbol
return unless reg == name
puts "Object changed in #{reg}"
calc_fields
end
def calc_fields
#puts "My id #{objects_id} , #{objects_id.class}"
object = Virtual.machine.objects[value]
if object and ! object.is_a?(String)
self.fields.clear
clazz = object.class.name.split("::").last
#puts "found #{clazz}"
self.fields << clazz
object.get_instance_variables.each do |variable|
f = object.get_instance_variable(variable)
self.fields << f
end
end
end
end

View File

@ -35,7 +35,7 @@
<div class="status-view">
<div>
<button e-click="tick">Next</button>
<button e-click="@interpreter.tick">Next</button>
</div>
<div>
<h4> Status </h4>
@ -58,6 +58,11 @@
<div>
{{ reg.value }}
</div>
{{ reg.fields.each do |attribute| }}
<div class="col-md-12">
{{marker(attribute)}} {{attribute.object_id}}
</div>
{{end}}
</div>
{{end}}
</div>