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:
parent
6c06f61ab8
commit
f9a89db10c
@ -8,10 +8,13 @@ module Parfait
|
|||||||
#
|
#
|
||||||
class BinaryCode < Data16
|
class BinaryCode < Data16
|
||||||
attr_reader :next
|
attr_reader :next
|
||||||
def self.offset
|
|
||||||
2 * 4 # size of type (2, type+next) * word_size (4)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
def self.type_length
|
||||||
|
2 #type + next (could get from space, maybe later)
|
||||||
|
end
|
||||||
|
def self.byte_offset
|
||||||
|
self.type_length * 4 # size of type * word_size (4)
|
||||||
|
end
|
||||||
#16 - 2 -1 , two instance variables and one for the jump
|
#16 - 2 -1 , two instance variables and one for the jump
|
||||||
def self.data_length
|
def self.data_length
|
||||||
13
|
13
|
||||||
@ -45,7 +48,7 @@ module Parfait
|
|||||||
|
|
||||||
def each_block( &block )
|
def each_block( &block )
|
||||||
block.call( self )
|
block.call( self )
|
||||||
@next.each( &block ) if @next
|
@next.each_block( &block ) if @next
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
@ -68,8 +71,9 @@ module Parfait
|
|||||||
#raise "invalid index #{index}" unless @next
|
#raise "invalid index #{index}" unless @next
|
||||||
extend_to( index )
|
extend_to( index )
|
||||||
@next.set_word( index - data_length , word)
|
@next.set_word( index - data_length , word)
|
||||||
|
else
|
||||||
|
set_internal_word(index + 2 , word)
|
||||||
end
|
end
|
||||||
set_internal_word(index + 2 , word)
|
|
||||||
end
|
end
|
||||||
def set_last(word)
|
def set_last(word)
|
||||||
set_word( data_length , word)
|
set_word( data_length , word)
|
||||||
|
@ -24,6 +24,9 @@ module Parfait
|
|||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
def self.integer_index
|
||||||
|
type_length
|
||||||
|
end
|
||||||
def data_length
|
def data_length
|
||||||
raise "called #{self}"
|
raise "called #{self}"
|
||||||
end
|
end
|
||||||
|
@ -19,8 +19,12 @@ module Parfait
|
|||||||
def value
|
def value
|
||||||
get_internal_word(Integer.integer_index)
|
get_internal_word(Integer.integer_index)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.type_length
|
||||||
|
2 # 0 type, 1 next_i
|
||||||
|
end
|
||||||
def self.integer_index
|
def self.integer_index
|
||||||
3 # 1 type, 2 next_i
|
type_length
|
||||||
end
|
end
|
||||||
|
|
||||||
# :integer?, :odd?, :even?, :upto, :downto, :times, :succ, :next, :pred, :chr, :ord, :to_i, :to_int, :floor,
|
# :integer?, :odd?, :even?, :upto, :downto, :times, :succ, :next, :pred, :chr, :ord, :to_i, :to_int, :floor,
|
||||||
@ -42,17 +46,26 @@ module Parfait
|
|||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
def self.type_length
|
||||||
|
1 # 0 type
|
||||||
|
end
|
||||||
end
|
end
|
||||||
class TrueClass < Data4
|
class TrueClass < Data4
|
||||||
#FIXME: this is "just" for compilation
|
#FIXME: this is "just" for compilation
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
def self.type_length
|
||||||
|
1 # 0 type
|
||||||
|
end
|
||||||
end
|
end
|
||||||
class NilClass < Data4
|
class NilClass < Data4
|
||||||
#FIXME: this is "just" for compilation
|
#FIXME: this is "just" for compilation
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
def self.type_length
|
||||||
|
1 # 0 type
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,9 @@ module Parfait
|
|||||||
def self.get_length_index
|
def self.get_length_index
|
||||||
2 # 2 is the amount of attributes, type and char_length. the offset after which chars start
|
2 # 2 is the amount of attributes, type and char_length. the offset after which chars start
|
||||||
end
|
end
|
||||||
|
def self.type_length
|
||||||
|
2 # 0 type , 1 char_length
|
||||||
|
end
|
||||||
def self.get_indexed( i )
|
def self.get_indexed( i )
|
||||||
i + get_length_index * 4
|
i + get_length_index * 4
|
||||||
end
|
end
|
||||||
|
@ -34,7 +34,7 @@ module Risc
|
|||||||
|
|
||||||
def range_check(index)
|
def range_check(index)
|
||||||
raise "index too low #{index} < #{min}" if index < min
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -51,7 +51,7 @@ module Risc
|
|||||||
raise "No position #{pos.to_s(16)}" unless position
|
raise "No position #{pos.to_s(16)}" unless position
|
||||||
if position.is_a?(Position::CodePosition)
|
if position.is_a?(Position::CodePosition)
|
||||||
raise "Setting Code #{clock}-#{position}, #{position.method}"
|
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
|
end
|
||||||
log.debug "Setting Position #{clock}-#{position}, #{position.binary}"
|
log.debug "Setting Position #{clock}-#{position}, #{position.binary}"
|
||||||
raise "not instruction position #{position}-#{position.class}-#{position.object.class}" unless position.is_a?(Position::InstructionPosition)
|
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
|
def execute_Branch
|
||||||
label = @instruction.label
|
label = @instruction.label
|
||||||
pos = Position.get(label).at
|
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
|
set_pc pos
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
@ -218,7 +218,7 @@ module Risc
|
|||||||
meth = @instruction.method
|
meth = @instruction.method
|
||||||
at = Position.get(meth.binary).at
|
at = Position.get(meth.binary).at
|
||||||
log.debug "Call to #{meth.name} at:#{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
|
#set_instruction @instruction.method.risc_instructions
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
@ -106,9 +106,9 @@ module Risc
|
|||||||
first_method = Parfait.object_space.types.values.first.methods
|
first_method = Parfait.object_space.types.values.first.methods
|
||||||
before = at
|
before = at
|
||||||
Position.set( first_method.binary , at , first_method)
|
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 "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
|
at
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,8 +5,7 @@ module Parfait
|
|||||||
|
|
||||||
def self.allocate
|
def self.allocate
|
||||||
r = super
|
r = super
|
||||||
puts "#{self.memory_size}"
|
r.instance_variable_set(:@memory , Risc::FakeMemory.new(self.type_length , self.memory_size))
|
||||||
r.instance_variable_set(:@memory , [])
|
|
||||||
r
|
r
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ module Risc
|
|||||||
next_meth = next_method
|
next_meth = next_method
|
||||||
return unless next_meth
|
return unless next_meth
|
||||||
Position.set( next_meth.binary , next_pos , 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)
|
Position.set( next_meth.cpu_instructions, next_cpu_pos , next_meth.binary)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -36,7 +36,7 @@ module Risc
|
|||||||
next_binary.extend_one unless next_binary.next
|
next_binary.extend_one unless next_binary.next
|
||||||
next_binary = next_binary.next
|
next_binary = next_binary.next
|
||||||
raise "end of line " unless next_binary
|
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)}"
|
Position.log.debug "Jump to: #{nekst.to_s(16)}"
|
||||||
end
|
end
|
||||||
Position.set(@instruction.next, nekst , next_binary)
|
Position.set(@instruction.next, nekst , next_binary)
|
||||||
|
@ -36,7 +36,7 @@ module Risc
|
|||||||
sl = main_ticks(26)
|
sl = main_ticks(26)
|
||||||
assert_equal SlotToReg , sl.class
|
assert_equal SlotToReg , sl.class
|
||||||
assert_equal :r1 , sl.array.symbol
|
assert_equal :r1 , sl.array.symbol
|
||||||
assert_equal 3 , sl.index
|
assert_equal 2 , sl.index
|
||||||
assert_equal :r1 , sl.register.symbol
|
assert_equal :r1 , sl.register.symbol
|
||||||
assert_equal 9 , @interpreter.get_register(:r1)
|
assert_equal 9 , @interpreter.get_register(:r1)
|
||||||
end
|
end
|
||||||
|
@ -61,7 +61,7 @@ module Risc
|
|||||||
sl = main_ticks( base + 3 )
|
sl = main_ticks( base + 3 )
|
||||||
assert_equal SlotToReg , sl.class
|
assert_equal SlotToReg , sl.class
|
||||||
assert_equal :r1 , sl.array.symbol #load from message
|
assert_equal :r1 , sl.array.symbol #load from message
|
||||||
assert_equal 3 , sl.index
|
assert_equal 2 , sl.index
|
||||||
assert_equal :r1 , sl.register.symbol
|
assert_equal :r1 , sl.register.symbol
|
||||||
end
|
end
|
||||||
def test_op
|
def test_op
|
||||||
|
@ -60,7 +60,7 @@ module Risc
|
|||||||
assert_equal RegToSlot , sl.class
|
assert_equal RegToSlot , sl.class
|
||||||
assert_equal :r1 , sl.register.symbol #return
|
assert_equal :r1 , sl.register.symbol #return
|
||||||
assert_equal :r2 , sl.array.symbol #parfait integer
|
assert_equal :r2 , sl.array.symbol #parfait integer
|
||||||
assert_equal 3 , sl.index
|
assert_equal 2 , sl.index
|
||||||
end
|
end
|
||||||
def test_return
|
def test_return
|
||||||
done = main_ticks(43)
|
done = main_ticks(43)
|
||||||
|
@ -39,7 +39,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_first_binary_jump
|
def test_first_binary_jump
|
||||||
bin = Parfait.object_space.get_init.binary
|
bin = Parfait.object_space.get_init.binary
|
||||||
assert 0 != bin.get_word(14) , "index 0 is 0 #{bin.inspect}"
|
assert 0 != bin.get_word(Parfait::BinaryCode.data_length) , "index 0 is 0 #{bin.inspect}"
|
||||||
end
|
end
|
||||||
def test_second_binary_first
|
def test_second_binary_first
|
||||||
bin = Parfait.object_space.get_init.binary.next
|
bin = Parfait.object_space.get_init.binary.next
|
||||||
|
Loading…
x
Reference in New Issue
Block a user