make ints compile time mutable
to change the label value and use the allocated stubs
This commit is contained in:
parent
b81d9565de
commit
7847420d49
@ -1,6 +1,6 @@
|
||||
module Mom
|
||||
|
||||
# A Label is the only legal target for a branch (this is true in Mom and Risc)
|
||||
# A Label is the only legal target for a branch (in Mom, in Risc a BinaryCode is ok too)
|
||||
#
|
||||
# In the dynamic view (runtime) where the instructions form a graph,
|
||||
# branches fan out, Labels collect. In other words a branch is the place where
|
||||
@ -31,6 +31,7 @@ module Mom
|
||||
# Off course some specific place still has to be responsible for actually
|
||||
# adding the label to the instruction list (usually an if/while)
|
||||
def to_risc(compiler)
|
||||
|
||||
@risc_label ||= Risc::Label.new(self,name)
|
||||
end
|
||||
end
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -43,6 +43,9 @@ module Parfait
|
||||
int = int.next_integer
|
||||
end
|
||||
end
|
||||
|
||||
def test_set
|
||||
@int.set_value(1)
|
||||
assert_equal 1 , @int.value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -33,6 +33,10 @@ module Parfait
|
||||
assert_equal 14, int.instance_type.method_names.get_length
|
||||
end
|
||||
|
||||
def test_get_integer_instance
|
||||
int = @space.get_integer
|
||||
assert_equal Integer , int.class
|
||||
end
|
||||
def test_classes_class
|
||||
classes.each do |name|
|
||||
assert_equal :Class , @space.classes[name].get_class.name
|
||||
|
Loading…
Reference in New Issue
Block a user