next instruction working

but no clock yet
This commit is contained in:
Torsten Ruger 2015-07-24 13:56:31 +03:00
parent f5ece67233
commit 5d42da9d03
2 changed files with 42 additions and 8 deletions

View File

@ -2,10 +2,20 @@ class RegisterView
include React::Component include React::Component
required_param :interpreter required_param :interpreter
define_state :registers
before_mount do
interpreter.register_event(:register_changed, self)
registers! interpreter.registers
end
def register_changed reg , old , bl
registers! interpreter.registers
end
def render def render
div :class => :row do div :class => :row do
interpreter.registers.each do |r , has| registers.each do |r , has|
div :class => "col-md-1" do div :class => "col-md-1" do
"#{r} : #{has}" "#{r} : #{has}"
end end

View File

@ -12,22 +12,40 @@ class Interpreter
@registers = Hash[(0...12).collect{|i| ["r#{i}" , "undefined"]}] @registers = Hash[(0...12).collect{|i| ["r#{i}" , "undefined"]}]
end end
def start block def start bl
set_block block set_block bl
end end
def set_block block
return if @block == block def set_block bl
return if @block == bl
raise "Error, nil block" unless bl
old = @block old = @block
@block = block @block = bl
trigger(:block_changed , old , block) trigger(:block_changed , old , bl)
set_instruction block.codes.first set_instruction bl.codes.first
end end
def set_instruction i def set_instruction i
return if @instruction == i return if @instruction == i
raise "Error, nil instruction" unless i
old = @instruction old = @instruction
@instruction = i @instruction = i
trigger(:instruction_changed, old , i) trigger(:instruction_changed, old , i)
end end
def get_register( reg )
reg = reg.symbol if reg.is_a? Register::RegisterReference
raise "Not a register #{reg}" unless Register::RegisterReference.look_like_reg(reg)
@registers[reg]
end
def set_register reg , val
old = get_register( reg ) # also ensures format
return if old === val
@registers[reg] = val
trigger(:register_changed, reg , old , val)
end
def tick def tick
name = @instruction.class.name.split("::").last name = @instruction.class.name.split("::").last
fetch = send "execute_#{name}" fetch = send "execute_#{name}"
@ -40,4 +58,10 @@ class Interpreter
set_block target set_block target
false false
end end
def execute_LoadConstant
to = @instruction.register
value = @instruction.constant.object_id
set_register( to , value )
true
end
end end