fix an issue where instruction was in wrong code
embarrassingly used instance variable where it should have been local
This commit is contained in:
parent
6f0fad0957
commit
c0cd1e0740
@ -14,7 +14,7 @@ module Risc
|
|||||||
# fire events for changed pc and register contents
|
# fire events for changed pc and register contents
|
||||||
include Util::Eventable
|
include Util::Eventable
|
||||||
include Util::Logging
|
include Util::Logging
|
||||||
log_level :debug
|
log_level :info
|
||||||
|
|
||||||
attr_reader :instruction , :clock , :pc # current instruction and pc
|
attr_reader :instruction , :clock , :pc # current instruction and pc
|
||||||
attr_reader :registers # the registers, 16 (a hash, sym -> contents)
|
attr_reader :registers # the registers, 16 (a hash, sym -> contents)
|
||||||
@ -119,7 +119,9 @@ module Risc
|
|||||||
end
|
end
|
||||||
def execute_Branch
|
def execute_Branch
|
||||||
label = @instruction.label
|
label = @instruction.label
|
||||||
set_pc Position.get(label).at
|
pos = Position.get(label).at
|
||||||
|
pos += Parfait::BinaryCode.offset if label.is_a?(Parfait::BinaryCode)
|
||||||
|
set_pc pos
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,20 +24,22 @@ module Risc
|
|||||||
end
|
end
|
||||||
def init(at, binary)
|
def init(at, binary)
|
||||||
return if at == 0 and binary.nil?
|
return if at == 0 and binary.nil?
|
||||||
|
raise "faux pas" if Position.get(instruction).at < Position.get(binary).at
|
||||||
return unless @instruction.next
|
return unless @instruction.next
|
||||||
@binary = binary
|
@binary = binary
|
||||||
nekst = at + @instruction.byte_length
|
nekst = at + @instruction.byte_length
|
||||||
diff = nekst - Position.get(@binary).at
|
diff = nekst - Position.get(@binary).at
|
||||||
Position.log.debug "Diff: #{diff.to_s(16)} , next #{nekst.to_s(16)} , binary #{Position.get(@binary)}"
|
Position.log.debug "Diff: #{diff.to_s(16)} , next #{nekst.to_s(16)} , binary #{Position.get(@binary)}"
|
||||||
raise "Invalid position #{diff.to_s(16)} , next #{nekst.to_s(16)} #{self}" if diff < 8
|
raise "Invalid position #{diff.to_s(16)} , next #{nekst.to_s(16)} #{self}" if diff < 8
|
||||||
|
next_binary = @binary
|
||||||
if( (diff % (@binary.padded_length - @instruction.byte_length)) == 0 )
|
if( (diff % (@binary.padded_length - @instruction.byte_length)) == 0 )
|
||||||
@binary.extend_one unless @binary.next
|
next_binary.extend_one unless next_binary.next
|
||||||
@binary = @binary.next
|
next_binary = next_binary.next
|
||||||
raise "end of line " unless @binary
|
raise "end of line " unless next_binary
|
||||||
nekst = Position.get(@binary).at + Parfait::BinaryCode.offset
|
nekst = Position.get(next_binary).at + Parfait::BinaryCode.offset
|
||||||
Position.log.debug "Jump to: #{nekst.to_s(16)}"
|
Position.log.debug "Jump to: #{nekst.to_s(16)}"
|
||||||
end
|
end
|
||||||
Position.set(@instruction.next, nekst , @binary)
|
Position.set(@instruction.next, nekst , next_binary)
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_to(pos , binary)
|
def reset_to(pos , binary)
|
||||||
|
@ -9,31 +9,31 @@ module Risc
|
|||||||
assert_equal Parfait::Integer , get_return.class
|
assert_equal Parfait::Integer , get_return.class
|
||||||
assert_equal 10 , get_return.value
|
assert_equal 10 , get_return.value
|
||||||
end
|
end
|
||||||
def test_minus
|
def pest_minus
|
||||||
run_main "5 - 5"
|
run_main "5 - 5"
|
||||||
assert_equal 0 , get_return.value
|
assert_equal 0 , get_return.value
|
||||||
end
|
end
|
||||||
def test_minus_neg
|
def pest_minus_neg
|
||||||
run_main "5 - 15"
|
run_main "5 - 15"
|
||||||
assert_equal -10 , get_return.value
|
assert_equal -10 , get_return.value
|
||||||
end
|
end
|
||||||
def test_rshift
|
def pest_rshift
|
||||||
run_main "#{2**8} >> 3"
|
run_main "#{2**8} >> 3"
|
||||||
assert_equal 2**5 , get_return.value
|
assert_equal 2**5 , get_return.value
|
||||||
end
|
end
|
||||||
def test_lshift
|
def pest_lshift
|
||||||
run_main "#{2**8} << 3"
|
run_main "#{2**8} << 3"
|
||||||
assert_equal 2**11 , get_return.value
|
assert_equal 2**11 , get_return.value
|
||||||
end
|
end
|
||||||
def test_div10
|
def pest_div10
|
||||||
run_main "45.div10"
|
run_main "45.div10"
|
||||||
assert_equal 4 , get_return.value
|
assert_equal 4 , get_return.value
|
||||||
end
|
end
|
||||||
def test_div4
|
def pest_div4
|
||||||
run_main "45.div4"
|
run_main "45.div4"
|
||||||
assert_equal 11 , get_return.value
|
assert_equal 11 , get_return.value
|
||||||
end
|
end
|
||||||
def test_mult
|
def pest_mult
|
||||||
run_main "4 * 4"
|
run_main "4 * 4"
|
||||||
assert_equal 16 , get_return.value
|
assert_equal 16 , get_return.value
|
||||||
end
|
end
|
||||||
|
@ -68,7 +68,20 @@ module Risc
|
|||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 18396 , @interpreter.pc
|
assert_equal 18396 , @interpreter.pc
|
||||||
end
|
end
|
||||||
def test_tick_15
|
def test_tick_14_jump
|
||||||
|
14.times {@interpreter.tick}
|
||||||
|
assert_equal Branch , @interpreter.instruction.class
|
||||||
|
end
|
||||||
|
def test_tick_14_bin
|
||||||
|
13.times {@interpreter.tick}
|
||||||
|
binary_pos = binary_position
|
||||||
|
@interpreter.tick
|
||||||
|
assert_equal binary_pos , binary_position , "#{binary_pos.to_s(16)}!=#{binary_position.to_s(16)}"
|
||||||
|
end
|
||||||
|
def binary_position
|
||||||
|
Position.get(Position.get(@interpreter.instruction).binary).at
|
||||||
|
end
|
||||||
|
def test_tick_15 #more than a binary code worth
|
||||||
15.times {@interpreter.tick}
|
15.times {@interpreter.tick}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,17 +8,12 @@ module Risc
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
do_clean_compile
|
|
||||||
Vool::VoolCompiler.ruby_to_binary( @string_input , :interpreter)
|
Vool::VoolCompiler.ruby_to_binary( @string_input , :interpreter)
|
||||||
@interpreter = Interpreter.new
|
@interpreter = Interpreter.new
|
||||||
@interpreter.start_machine
|
@interpreter.start_machine
|
||||||
end
|
end
|
||||||
alias :do_setup :setup
|
alias :do_setup :setup
|
||||||
|
|
||||||
# must be after boot, but before main compile, to define method
|
|
||||||
def do_clean_compile
|
|
||||||
end
|
|
||||||
|
|
||||||
# check the given array of instructions is what the interpreter actually does
|
# check the given array of instructions is what the interpreter actually does
|
||||||
# possible second argument ignores the given amount, usually up until main
|
# possible second argument ignores the given amount, usually up until main
|
||||||
def check_chain( should , start_at = 0 )
|
def check_chain( should , start_at = 0 )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user