2018-08-29 20:05:54 +02:00
|
|
|
# Integer class for representing maths on Integers
|
|
|
|
# Integers are Objects, specifically DataObjects
|
|
|
|
# - they have fixed value
|
|
|
|
# - they are immutable
|
|
|
|
# (both by implementation, not design.
|
|
|
|
# Ie it would be possible to change the value, we just don't support that)
|
2018-03-31 18:12:06 +02:00
|
|
|
class Integer < Data4
|
2015-04-08 19:32:56 +02:00
|
|
|
|
2018-08-11 18:15:34 +02:00
|
|
|
attr :type, :next_integer
|
|
|
|
|
2018-03-31 18:12:06 +02:00
|
|
|
def initialize(value , next_i = nil)
|
2018-03-31 12:58:08 +02:00
|
|
|
super()
|
2018-08-11 18:15:34 +02:00
|
|
|
self.next_integer = next_i
|
2018-04-01 10:56:04 +02:00
|
|
|
set_internal_word(Integer.integer_index, value)
|
2018-03-31 12:25:59 +02:00
|
|
|
end
|
|
|
|
|
2018-04-01 10:56:04 +02:00
|
|
|
def value
|
|
|
|
get_internal_word(Integer.integer_index)
|
|
|
|
end
|
2018-05-28 14:09:59 +02:00
|
|
|
|
|
|
|
def self.type_length
|
|
|
|
2 # 0 type, 1 next_i
|
|
|
|
end
|
2018-11-21 19:29:22 +01:00
|
|
|
# index at which the next integer reference is. Used in risc reneration
|
|
|
|
def self.next_index
|
|
|
|
1
|
|
|
|
end
|
|
|
|
# index at which the actual integer is. Used in risc reneration
|
2018-03-31 18:12:06 +02:00
|
|
|
def self.integer_index
|
2018-05-28 14:09:59 +02:00
|
|
|
type_length
|
2018-03-31 18:12:06 +02:00
|
|
|
end
|
2018-03-31 18:37:24 +02:00
|
|
|
|
2018-05-29 19:52:58 +02:00
|
|
|
def to_s
|
2019-08-19 17:48:13 +02:00
|
|
|
"Integer " + value.to_s
|
2018-05-29 19:52:58 +02:00
|
|
|
end
|
2018-05-29 16:03:55 +02:00
|
|
|
# compile time method to set the actual value.
|
|
|
|
# this should not really be part of parfait, as ints are immutable at runtime.
|
|
|
|
def set_value(value)
|
|
|
|
set_internal_word(Integer.integer_index, value)
|
|
|
|
end
|
|
|
|
|
2015-05-11 17:55:49 +02:00
|
|
|
# :integer?, :odd?, :even?, :upto, :downto, :times, :succ, :next, :pred, :chr, :ord, :to_i, :to_int, :floor,
|
|
|
|
# :ceil, :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize,
|
2018-08-11 18:15:34 +02:00
|
|
|
# :singleton_method_added, :coerce, :i, :+, :-, :fdiv, :div, :divmod, :%, :modulo, :remainder, :abs, :magnitude,
|
2015-05-11 17:55:49 +02:00
|
|
|
# :real?, :zero?, :nonzero?, :step, :quo, :to_c, :real, :imaginary, :imag, :abs2, :arg, :angle, :phase,
|
|
|
|
# :rectangular, :rect, :polar, :conjugate, :conj, :>, :>=, :<, :<=, :between?
|
|
|
|
#
|
|
|
|
# Numeric
|
2018-08-11 18:15:34 +02:00
|
|
|
# :singleton_method_added, :coerce, :i, :+, :-, :fdiv, :div, :divmod, :%, :modulo, :remainder, :abs, :magnitude,
|
2015-05-11 17:55:49 +02:00
|
|
|
# :to_int, :real?, :integer?, :zero?, :nonzero?, :floor, :ceil, :round, :truncate, :step, :numerator, :denominator,
|
|
|
|
# :quo, :to_c, :real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, :conj,
|
|
|
|
# :>, :>=, :<, :<=, :between?
|
|
|
|
end
|
2018-03-19 16:48:56 +01:00
|
|
|
|
2018-05-30 22:49:01 +02:00
|
|
|
# Marker class. Same functionality as Integer
|
|
|
|
# (ie carrying an int, the return address)
|
|
|
|
#
|
|
|
|
# But the integer (address) needs to be adjusted by load address.
|
|
|
|
class ReturnAddress < Integer
|
2018-08-29 20:05:54 +02:00
|
|
|
|
|
|
|
def to_s
|
2019-08-19 17:48:13 +02:00
|
|
|
"ReturnAddress 0x" + object_id.to_s(16) + ":" + value.to_s
|
2018-08-29 20:05:54 +02:00
|
|
|
end
|
2018-05-30 22:49:01 +02:00
|
|
|
end
|
|
|
|
|
2018-03-19 16:48:56 +01:00
|
|
|
# adding other base classes in here for now:
|
2018-03-31 18:12:06 +02:00
|
|
|
class FalseClass < Data4
|
2018-03-31 12:47:02 +02:00
|
|
|
#FIXME: this is "just" for compilation
|
|
|
|
def initialize
|
2018-03-31 12:58:08 +02:00
|
|
|
super
|
2018-03-31 12:47:02 +02:00
|
|
|
end
|
2018-05-28 14:09:59 +02:00
|
|
|
def self.type_length
|
|
|
|
1 # 0 type
|
|
|
|
end
|
2018-03-19 16:48:56 +01:00
|
|
|
end
|
2018-03-31 18:12:06 +02:00
|
|
|
class TrueClass < Data4
|
2018-03-31 12:47:02 +02:00
|
|
|
#FIXME: this is "just" for compilation
|
|
|
|
def initialize
|
2018-03-31 12:58:08 +02:00
|
|
|
super
|
2018-03-31 12:47:02 +02:00
|
|
|
end
|
2018-05-28 14:09:59 +02:00
|
|
|
def self.type_length
|
|
|
|
1 # 0 type
|
|
|
|
end
|
2018-03-19 16:48:56 +01:00
|
|
|
end
|
2018-03-31 18:12:06 +02:00
|
|
|
class NilClass < Data4
|
2018-03-31 12:47:02 +02:00
|
|
|
#FIXME: this is "just" for compilation
|
|
|
|
def initialize
|
2018-03-31 12:58:08 +02:00
|
|
|
super
|
2018-03-31 12:47:02 +02:00
|
|
|
end
|
2018-05-28 14:09:59 +02:00
|
|
|
def self.type_length
|
|
|
|
1 # 0 type
|
|
|
|
end
|
2018-03-19 16:48:56 +01:00
|
|
|
end
|