diff --git a/lib/mom/instruction/label.rb b/lib/mom/instruction/label.rb index 79a4581e..c51f1149 100644 --- a/lib/mom/instruction/label.rb +++ b/lib/mom/instruction/label.rb @@ -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 diff --git a/lib/parfait/integer.rb b/lib/parfait/integer.rb index b53deb2f..6675e985 100644 --- a/lib/parfait/integer.rb +++ b/lib/parfait/integer.rb @@ -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, diff --git a/lib/parfait/space.rb b/lib/parfait/space.rb index de6e77ab..114751bd 100644 --- a/lib/parfait/space.rb +++ b/lib/parfait/space.rb @@ -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) diff --git a/test/parfait/test_integer.rb b/test/parfait/test_integer.rb index 8ee46eb3..40b69d84 100644 --- a/test/parfait/test_integer.rb +++ b/test/parfait/test_integer.rb @@ -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 diff --git a/test/parfait/test_space.rb b/test/parfait/test_space.rb index 9b0131f7..699cf9ac 100644 --- a/test/parfait/test_space.rb +++ b/test/parfait/test_space.rb @@ -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