add register logging and fix function return
return semantics used to be different, now only register is given
This commit is contained in:
parent
b4a18bc59b
commit
472b1a638a
@ -28,7 +28,7 @@ module Risc
|
|||||||
attr_reader :flags # somewhat like the lags on a cpu, hash sym => bool (zero .. . )
|
attr_reader :flags # somewhat like the lags on a cpu, hash sym => bool (zero .. . )
|
||||||
|
|
||||||
#start in state :stopped and set registers to unknown
|
#start in state :stopped and set registers to unknown
|
||||||
def initialize
|
def initialize()
|
||||||
@state = :stopped
|
@state = :stopped
|
||||||
@stdout = ""
|
@stdout = ""
|
||||||
@registers = {}
|
@registers = {}
|
||||||
@ -40,21 +40,21 @@ module Risc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def start instruction
|
def start( instruction )
|
||||||
initialize
|
initialize
|
||||||
set_state(:running)
|
set_state(:running)
|
||||||
set_instruction instruction
|
set_instruction instruction
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_state state
|
def set_state( state )
|
||||||
old = @state
|
old = @state
|
||||||
return if state == old
|
return if state == old
|
||||||
@state = state
|
@state = state
|
||||||
trigger(:state_changed , old , state )
|
trigger(:state_changed , old , state )
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_instruction i
|
def set_instruction( i )
|
||||||
return if @instruction == i
|
raise "set to same instruction #{i}" if @instruction == i
|
||||||
old = @instruction
|
old = @instruction
|
||||||
@instruction = i
|
@instruction = i
|
||||||
trigger(:instruction_changed, old , i)
|
trigger(:instruction_changed, old , i)
|
||||||
@ -67,7 +67,7 @@ module Risc
|
|||||||
@registers[reg]
|
@registers[reg]
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_register reg , val
|
def set_register( reg , val )
|
||||||
old = get_register( reg ) # also ensures format
|
old = get_register( reg ) # also ensures format
|
||||||
if val.is_a? Fixnum
|
if val.is_a? Fixnum
|
||||||
@flags[:zero] = (val == 0)
|
@flags[:zero] = (val == 0)
|
||||||
@ -90,6 +90,7 @@ module Risc
|
|||||||
name = @instruction.class.name.split("::").last
|
name = @instruction.class.name.split("::").last
|
||||||
log.debug "#{@clock.to_s}: #{@instruction.to_s}"
|
log.debug "#{@clock.to_s}: #{@instruction.to_s}"
|
||||||
fetch = send "execute_#{name}"
|
fetch = send "execute_#{name}"
|
||||||
|
log.debug register_dump
|
||||||
return unless fetch
|
return unless fetch
|
||||||
set_instruction @instruction.next
|
set_instruction @instruction.next
|
||||||
end
|
end
|
||||||
@ -133,9 +134,12 @@ module Risc
|
|||||||
else
|
else
|
||||||
index = get_register(@instruction.index)
|
index = get_register(@instruction.index)
|
||||||
end
|
end
|
||||||
if object.is_a?(Symbol)
|
case object
|
||||||
|
when Symbol
|
||||||
raise "Must convert symbol to word:#{object}" unless( index == 2 )
|
raise "Must convert symbol to word:#{object}" unless( index == 2 )
|
||||||
value = object.to_s.length
|
value = object.to_s.length
|
||||||
|
when nil
|
||||||
|
raise "error #{@instruction} retrieves nil"
|
||||||
else
|
else
|
||||||
value = object.get_internal_word( index )
|
value = object.get_internal_word( index )
|
||||||
end
|
end
|
||||||
@ -196,8 +200,8 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def execute_FunctionReturn
|
def execute_FunctionReturn
|
||||||
object = get_register( @instruction.register )
|
link = get_register( @instruction.register )
|
||||||
link = object.get_internal_word( @instruction.index )
|
log.debug "Return to #{link}"
|
||||||
@instruction = link
|
@instruction = link
|
||||||
# we jump back to the call instruction. so it is as if the call never happened and we continue
|
# we jump back to the call instruction. so it is as if the call never happened and we continue
|
||||||
true
|
true
|
||||||
@ -272,5 +276,18 @@ module Risc
|
|||||||
raise "unimplemented '#{@instruction.operator}' #{@instruction}"
|
raise "unimplemented '#{@instruction.operator}' #{@instruction}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def register_dump
|
||||||
|
(0..7).collect do |reg|
|
||||||
|
value = @registers["r#{reg}".to_sym]
|
||||||
|
str = "#{reg}-" +
|
||||||
|
case value
|
||||||
|
when String
|
||||||
|
value[0..10]
|
||||||
|
else
|
||||||
|
value.class.name.split("::").last
|
||||||
|
end
|
||||||
|
end.join("|")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user