use fake memory

fix integer offset bug
(which only didn’t cause errors as fixnums are still an order too big
and the famous +1 error hit the empty space)
This commit is contained in:
Torsten Ruger
2018-05-28 15:09:59 +03:00
parent 6c06f61ab8
commit f9a89db10c
14 changed files with 42 additions and 20 deletions

View File

@ -34,7 +34,7 @@ module Risc
def range_check(index)
raise "index too low #{index} < #{min}" if index < min
raise "index too big #{index} < #{min}" if index >= size
raise "index too big #{index} >= #{size}" if index >= size
end
end
end

View File

@ -51,7 +51,7 @@ module Risc
raise "No position #{pos.to_s(16)}" unless position
if position.is_a?(Position::CodePosition)
raise "Setting Code #{clock}-#{position}, #{position.method}"
#return set_pc(position.at + Parfait::BinaryCode.offset)
#return set_pc(position.at + Parfait::BinaryCode.byte_offset)
end
log.debug "Setting Position #{clock}-#{position}, #{position.binary}"
raise "not instruction position #{position}-#{position.class}-#{position.object.class}" unless position.is_a?(Position::InstructionPosition)
@ -120,7 +120,7 @@ module Risc
def execute_Branch
label = @instruction.label
pos = Position.get(label).at
pos += Parfait::BinaryCode.offset if label.is_a?(Parfait::BinaryCode)
pos += Parfait::BinaryCode.byte_offset if label.is_a?(Parfait::BinaryCode)
set_pc pos
false
end
@ -218,7 +218,7 @@ module Risc
meth = @instruction.method
at = Position.get(meth.binary).at
log.debug "Call to #{meth.name} at:#{at}"
set_pc(at + Parfait::BinaryCode.offset)
set_pc(at + Parfait::BinaryCode.byte_offset)
#set_instruction @instruction.method.risc_instructions
false
end

View File

@ -106,9 +106,9 @@ module Risc
first_method = Parfait.object_space.types.values.first.methods
before = at
Position.set( first_method.binary , at , first_method)
Position.set( first_method.cpu_instructions, at + Parfait::BinaryCode.offset , first_method.binary)
Position.set( first_method.cpu_instructions, at + Parfait::BinaryCode.byte_offset , first_method.binary)
log.debug "Method #{first_method.name}:#{before.to_s(16)} len: #{(at - before).to_s(16)}"
log.debug "Instructions #{first_method.cpu_instructions.object_id.to_s(16)}:#{(before+Parfait::BinaryCode.offset).to_s(16)}"
log.debug "Instructions #{first_method.cpu_instructions.object_id.to_s(16)}:#{(before+Parfait::BinaryCode.byte_offset).to_s(16)}"
at
end

View File

@ -5,8 +5,7 @@ module Parfait
def self.allocate
r = super
puts "#{self.memory_size}"
r.instance_variable_set(:@memory , [])
r.instance_variable_set(:@memory , Risc::FakeMemory.new(self.type_length , self.memory_size))
r
end

View File

@ -28,7 +28,7 @@ module Risc
next_meth = next_method
return unless next_meth
Position.set( next_meth.binary , next_pos , next_meth)
next_cpu_pos = next_pos + Parfait::BinaryCode.offset
next_cpu_pos = next_pos + Parfait::BinaryCode.byte_offset
Position.set( next_meth.cpu_instructions, next_cpu_pos , next_meth.binary)
end
end

View File

@ -36,7 +36,7 @@ module Risc
next_binary.extend_one unless next_binary.next
next_binary = next_binary.next
raise "end of line " unless next_binary
nekst = Position.get(next_binary).at + Parfait::BinaryCode.offset
nekst = Position.get(next_binary).at + Parfait::BinaryCode.byte_offset
Position.log.debug "Jump to: #{nekst.to_s(16)}"
end
Position.set(@instruction.next, nekst , next_binary)