move to parfait integers in risc layer
loading constants means loading parfait objects objects have to me collected in machine integer ok, string/true/false/nil next
This commit is contained in:
parent
6e941ebcb7
commit
9e9b5c7f37
@ -10,6 +10,11 @@ module Mom
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
def to_parfait(compiler)
|
||||
value = Parfait::Integer.new(@value)
|
||||
compiler.add_constant(value)
|
||||
value
|
||||
end
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Integer).instance_type
|
||||
end
|
||||
|
@ -108,7 +108,11 @@ module Mom
|
||||
type = known_object.respond_to?(:ct_type) ? known_object.ct_type : :int
|
||||
right = compiler.use_reg( type )
|
||||
case known_object
|
||||
when Constant , Parfait::Object , Risc::Label
|
||||
when Constant
|
||||
parfait = known_object.to_parfait(compiler)
|
||||
const = Risc.load_constant(instruction, parfait , right)
|
||||
raise "Can't have slots into Constants" if slots.length > 0
|
||||
when Parfait::Object , Risc::Label
|
||||
const = Risc.load_constant(instruction, known_object , right)
|
||||
if slots.length > 0
|
||||
# desctructively replace the existing value to be loaded if more slots
|
||||
|
@ -9,6 +9,12 @@
|
||||
module Parfait
|
||||
class Integer < Data2
|
||||
|
||||
#FIXME: this is "just" for compilation
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
attr_reader :value
|
||||
|
||||
# :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,
|
||||
|
@ -55,6 +55,11 @@ module Risc
|
||||
@objects ||= Collector.collect_space
|
||||
end
|
||||
|
||||
# add a constant (which get created during compilatio and need to be linked)
|
||||
def add_constant(const)
|
||||
raise "Must be Parfait #{const}" unless const.is_a?(Parfait::Object)
|
||||
@constants << const
|
||||
end
|
||||
# To create binaries, objects (and labels) need to have a position
|
||||
# (so objects can be loaded and branches know where to jump)
|
||||
#
|
||||
|
@ -132,5 +132,8 @@ module Risc
|
||||
@regs.clear
|
||||
end
|
||||
|
||||
def add_constant(const)
|
||||
Risc.machine.add_constant(const)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -11,6 +11,12 @@ module Risc
|
||||
assert_equal Hash , objects.class
|
||||
assert 350 < objects.length
|
||||
end
|
||||
def test_constant_fail
|
||||
assert_raises {@machine.add_constant( 1 )}
|
||||
end
|
||||
def test_constant
|
||||
assert @machine.add_constant( Parfait::Integer.new(5) )
|
||||
end
|
||||
end
|
||||
class TestMachinePositions < MiniTest::Test
|
||||
def setup
|
||||
|
Loading…
Reference in New Issue
Block a user