2018-03-25 17:22:02 +02:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# In rubyx everything truely is an object. (most smalltalk/ruby systems use a union
|
|
|
|
# for integers/pointers that are called objects, but are really very different)
|
|
|
|
#
|
|
|
|
# Objects have type as their first member. No exception.
|
|
|
|
#
|
|
|
|
# So where is the data? In DataObjects. DataObjects are opague carriers of data.
|
|
|
|
# Opague to rubyx that is. There is no way to get at it or pass the data around.
|
|
|
|
#
|
|
|
|
# To use Data, Risc instructions have to be used. Luckily there is not soo much one
|
|
|
|
# actually wants to do with data, moving it between DataObject , comparing and
|
|
|
|
# logical and math operation that are bundled into the OperatorInstruction.
|
|
|
|
#
|
|
|
|
# For safe access the access code needs to know the length of the data, which is
|
2018-03-31 18:12:06 +02:00
|
|
|
# encoded in the class/type name. Ie An Integer derives from Data4, which is 4 long
|
|
|
|
# ( one for the type, one for the next, one word for the integer and currently still a marker)
|
2018-03-25 17:22:02 +02:00
|
|
|
#
|
|
|
|
# DataObjects still have a type, and so can have objects before the data starts
|
|
|
|
#
|
|
|
|
# A marker class
|
|
|
|
module Parfait
|
|
|
|
class DataObject < Object
|
|
|
|
def initialize
|
2018-04-01 10:56:04 +02:00
|
|
|
super
|
2018-03-25 17:22:02 +02:00
|
|
|
@memory = []
|
|
|
|
end
|
|
|
|
def data_length
|
|
|
|
raise "called #{self}"
|
|
|
|
end
|
|
|
|
def data_start
|
2018-04-01 10:56:04 +02:00
|
|
|
return get_type.get_length
|
2018-03-25 17:22:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# 1 -based index
|
|
|
|
def get_internal_word(index)
|
2018-04-01 10:56:04 +02:00
|
|
|
return super if index <= data_start
|
2018-03-25 17:22:02 +02:00
|
|
|
@memory[index]
|
|
|
|
end
|
|
|
|
|
|
|
|
# 1 -based index
|
|
|
|
def set_internal_word(index , value)
|
2018-04-01 10:56:04 +02:00
|
|
|
return super if index <= data_start
|
2018-03-25 17:22:02 +02:00
|
|
|
raise "Word[#{index}] = nil" if( value.nil? )
|
|
|
|
@memory[index] = value
|
|
|
|
value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-31 18:12:06 +02:00
|
|
|
class Data4 < DataObject
|
2018-03-25 17:22:02 +02:00
|
|
|
def data_length
|
2018-03-31 18:12:06 +02:00
|
|
|
3
|
2018-03-25 17:22:02 +02:00
|
|
|
end
|
2018-03-29 16:38:59 +02:00
|
|
|
def padded_length
|
2018-03-29 17:03:21 +02:00
|
|
|
2 * 4
|
2018-03-29 16:38:59 +02:00
|
|
|
end
|
2018-03-25 17:22:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
class Data8 < DataObject
|
|
|
|
def data_length
|
|
|
|
7
|
|
|
|
end
|
2018-03-29 16:38:59 +02:00
|
|
|
def padded_length
|
2018-03-29 17:03:21 +02:00
|
|
|
8 * 4
|
2018-03-29 16:38:59 +02:00
|
|
|
end
|
2018-03-25 17:22:02 +02:00
|
|
|
end
|
|
|
|
class Data16 < DataObject
|
|
|
|
def data_length
|
|
|
|
15
|
|
|
|
end
|
2018-03-29 16:38:59 +02:00
|
|
|
def padded_length
|
2018-03-29 17:03:21 +02:00
|
|
|
16 * 4
|
2018-03-29 16:38:59 +02:00
|
|
|
end
|
2018-03-25 17:22:02 +02:00
|
|
|
end
|
|
|
|
end
|