make ints compile time mutable

to change the label value and use the allocated stubs
This commit is contained in:
Torsten Ruger
2018-05-29 17:03:55 +03:00
parent b81d9565de
commit 7847420d49
5 changed files with 26 additions and 2 deletions

View File

@ -27,6 +27,12 @@ module Parfait
type_length
end
# 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
# :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,
# :singleton_method_added, :coerce, :i, :+@, :-@, :fdiv, :div, :divmod, :%, :modulo, :remainder, :abs, :magnitude,

View File

@ -52,6 +52,16 @@ module Parfait
attr_reader :classes , :types , :first_message , :next_integer
attr_reader :true_object , :false_object , :nil_object
# hand out one of the preallocated ints for use as constant
# the same code is hardcoded as risc instructions for "normal" use, to
# avoid the method call at runtime. But at compile time we want to keep
# the number of integers known (fixed).
def get_integer
int = @next_integer
@next_integer = @next_integer.next_integer
int
end
def each_type
@types.values.each do |type|
yield(type)