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)
|
def initialize(value)
|
||||||
@value = value
|
@value = value
|
||||||
end
|
end
|
||||||
|
def to_parfait(compiler)
|
||||||
|
value = Parfait::Integer.new(@value)
|
||||||
|
compiler.add_constant(value)
|
||||||
|
value
|
||||||
|
end
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_class_by_name(:Integer).instance_type
|
Parfait.object_space.get_class_by_name(:Integer).instance_type
|
||||||
end
|
end
|
||||||
|
@ -108,7 +108,11 @@ module Mom
|
|||||||
type = known_object.respond_to?(:ct_type) ? known_object.ct_type : :int
|
type = known_object.respond_to?(:ct_type) ? known_object.ct_type : :int
|
||||||
right = compiler.use_reg( type )
|
right = compiler.use_reg( type )
|
||||||
case known_object
|
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)
|
const = Risc.load_constant(instruction, known_object , right)
|
||||||
if slots.length > 0
|
if slots.length > 0
|
||||||
# desctructively replace the existing value to be loaded if more slots
|
# desctructively replace the existing value to be loaded if more slots
|
||||||
|
@ -9,6 +9,12 @@
|
|||||||
module Parfait
|
module Parfait
|
||||||
class Integer < Data2
|
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,
|
# :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,
|
# :ceil, :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize,
|
||||||
# :singleton_method_added, :coerce, :i, :+@, :-@, :fdiv, :div, :divmod, :%, :modulo, :remainder, :abs, :magnitude,
|
# :singleton_method_added, :coerce, :i, :+@, :-@, :fdiv, :div, :divmod, :%, :modulo, :remainder, :abs, :magnitude,
|
||||||
|
@ -55,6 +55,11 @@ module Risc
|
|||||||
@objects ||= Collector.collect_space
|
@objects ||= Collector.collect_space
|
||||||
end
|
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
|
# To create binaries, objects (and labels) need to have a position
|
||||||
# (so objects can be loaded and branches know where to jump)
|
# (so objects can be loaded and branches know where to jump)
|
||||||
#
|
#
|
||||||
|
@ -132,5 +132,8 @@ module Risc
|
|||||||
@regs.clear
|
@regs.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_constant(const)
|
||||||
|
Risc.machine.add_constant(const)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,6 +11,12 @@ module Risc
|
|||||||
assert_equal Hash , objects.class
|
assert_equal Hash , objects.class
|
||||||
assert 350 < objects.length
|
assert 350 < objects.length
|
||||||
end
|
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
|
end
|
||||||
class TestMachinePositions < MiniTest::Test
|
class TestMachinePositions < MiniTest::Test
|
||||||
def setup
|
def setup
|
||||||
|
Loading…
Reference in New Issue
Block a user