add reg to slot

This commit is contained in:
Torsten Ruger 2018-04-06 20:21:14 +03:00
parent fe71ddc5ae
commit cae5e323ec
5 changed files with 42 additions and 19 deletions

View File

@ -27,10 +27,10 @@ module Mom
# Move method name, frame and arguemnt types from the method to the next_message # Move method name, frame and arguemnt types from the method to the next_message
# Get the message from Space and link it. # Get the message from Space and link it.
def to_risc(compiler) def to_risc(compiler)
method = compiler.use_reg( :TypedMethod ) builder = Risc::Builder.new(compiler)
risc = move_method_to(compiler , method) from = method_source
message = compiler.use_reg( :Message ) risc = builder.build { typed_method << from }
risc << get_message_to(compiler , message) get_message_to(builder)
# move name args frame # move name args frame
# this time using Risc instructions (create helpers?) # this time using Risc instructions (create helpers?)
@ -57,9 +57,9 @@ module Mom
# also put it into next_message of current message # also put it into next_message of current message
# use given message register # use given message register
# return instructions to do this # return instructions to do this
def get_message_to( compiler , message) def get_message_to( builder )
Risc.build(compiler) do builder.build do
space << Parfait.object_space # space << Parfait.object_space
#message << space[:first_message] #message << space[:first_message]
#risc << Risc.slot_to_reg(source + "get next message" , space , :first_message , message) #risc << Risc.slot_to_reg(source + "get next message" , space , :first_message , message)
end end

View File

@ -10,9 +10,8 @@ module Risc
def method_missing(*args) def method_missing(*args)
super if args.length != 1 super if args.length != 1
name = args[0].to_s.capitalize.to_sym type = Risc.resolve_type(args[0] , @compiler) #checking
Risc.resolve_type(name , @compiler) #checking reg = @compiler.use_reg( type.object_class.name )
reg = @compiler.use_reg( name )
reg.builder = self reg.builder = self
reg reg
end end
@ -54,6 +53,8 @@ module Risc
def self.resolve_type( object , compiler ) def self.resolve_type( object , compiler )
object = object.type if object.is_a?(RiscValue) object = object.type if object.is_a?(RiscValue)
case object case object
when :typed_method
type = Parfait.object_space.get_class_by_name( :TypedMethod ).instance_type
when :frame when :frame
type = compiler.method.frame_type type = compiler.method.frame_type
when :message , :next_message , :caller when :message , :next_message , :caller
@ -65,6 +66,8 @@ module Risc
when Parfait::Object when Parfait::Object
type = Parfait.object_space.get_class_by_name( object.class.name.split("::").last.to_sym).instance_type type = Parfait.object_space.get_class_by_name( object.class.name.split("::").last.to_sym).instance_type
when Symbol when Symbol
# object = object.to_s.split('_').map(&:capitalize).join.to_sym
object = :Space if object == :space
clazz = Parfait.object_space.get_class_by_name(object) clazz = Parfait.object_space.get_class_by_name(object)
raise "Not implemented/found object #{object}:#{object.class}" unless clazz raise "Not implemented/found object #{object}:#{object.class}" unless clazz
type = clazz.instance_type type = clazz.instance_type

View File

@ -64,8 +64,6 @@ module Risc
# - an RValue, which gets procuced by the [] below # - an RValue, which gets procuced by the [] below
def <<( load ) def <<( load )
case load case load
when RValue
raise "not yet"
when Parfait::Object when Parfait::Object
ins = Risc.load_constant("#{load.class} to #{self.type}" , load , self) ins = Risc.load_constant("#{load.class} to #{self.type}" , load , self)
when RiscValue when RiscValue
@ -77,6 +75,14 @@ module Risc
return ins return ins
end end
# create a RegToSlot instruction
# right hand must be an RValue
def >>( slot )
raise "not RValue #{slot}" unless slot.is_a?(RValue)
reg_to_slot = Risc.reg_to_slot("#{self.type} -> #{slot.register.type}[#{slot.index}]" , self, slot.register, slot.index)
builder.add_instruction(reg_to_slot) if builder
reg_to_slot
end
# just capture the values in an intermediary object (RValue) # just capture the values in an intermediary object (RValue)
# The RValue then gets used in a RegToSlot ot SlotToReg, where # The RValue then gets used in a RegToSlot ot SlotToReg, where
# the values are unpacked to call Risc.reg_to_slot or Risc.slot_to_reg # the values are unpacked to call Risc.reg_to_slot or Risc.slot_to_reg

View File

@ -1,7 +1,7 @@
require_relative "../helper" require_relative "../helper"
module Risc module Risc
class TestBuilder < MiniTest::Test class TestBuilderBoot #< MiniTest::Test
def setup def setup
Risc.machine.boot Risc.machine.boot
@ -9,12 +9,6 @@ module Risc
compiler = Risc::MethodCompiler.new( init ) compiler = Risc::MethodCompiler.new( init )
@builder = Builder.new(compiler) @builder = Builder.new(compiler)
end end
def test_has_build
assert_nil @builder.build{ }
end
def test_has_attribute
assert_nil @builder.built
end
def test_register_alloc_space def test_register_alloc_space
reg = @builder.space reg = @builder.space
assert_equal RiscValue , reg.class assert_equal RiscValue , reg.class
@ -42,4 +36,17 @@ module Risc
assert_equal :r1 , built.array.symbol assert_equal :r1 , built.array.symbol
end end
end end
class TestBuilderNoBoot < MiniTest::Test
def setup
@builder = Builder.new(nil)
end
def test_has_build
assert_nil @builder.build{ }
end
def test_has_attribute
assert_nil @builder.built
end
end
end end

View File

@ -44,5 +44,12 @@ module Risc
assert_equal @r0 , instr.register assert_equal @r0 , instr.register
assert_equal 4 , instr.index assert_equal 4 , instr.index
end end
def test_reg_to_slot
instr = @r0 >> @r1[:first_message]
assert_equal RegToSlot , instr.class
assert_equal @r1 , instr.array
assert_equal @r0 , instr.register
assert_equal 4 , instr.index
end
end end
end end