add reg to slot
This commit is contained in:
parent
fe71ddc5ae
commit
cae5e323ec
@ -27,10 +27,10 @@ module Mom
|
||||
# Move method name, frame and arguemnt types from the method to the next_message
|
||||
# Get the message from Space and link it.
|
||||
def to_risc(compiler)
|
||||
method = compiler.use_reg( :TypedMethod )
|
||||
risc = move_method_to(compiler , method)
|
||||
message = compiler.use_reg( :Message )
|
||||
risc << get_message_to(compiler , message)
|
||||
builder = Risc::Builder.new(compiler)
|
||||
from = method_source
|
||||
risc = builder.build { typed_method << from }
|
||||
get_message_to(builder)
|
||||
|
||||
# move name args frame
|
||||
# this time using Risc instructions (create helpers?)
|
||||
@ -57,9 +57,9 @@ module Mom
|
||||
# also put it into next_message of current message
|
||||
# use given message register
|
||||
# return instructions to do this
|
||||
def get_message_to( compiler , message)
|
||||
Risc.build(compiler) do
|
||||
space << Parfait.object_space
|
||||
def get_message_to( builder )
|
||||
builder.build do
|
||||
# space << Parfait.object_space
|
||||
#message << space[:first_message]
|
||||
#risc << Risc.slot_to_reg(source + "get next message" , space , :first_message , message)
|
||||
end
|
||||
|
@ -10,9 +10,8 @@ module Risc
|
||||
|
||||
def method_missing(*args)
|
||||
super if args.length != 1
|
||||
name = args[0].to_s.capitalize.to_sym
|
||||
Risc.resolve_type(name , @compiler) #checking
|
||||
reg = @compiler.use_reg( name )
|
||||
type = Risc.resolve_type(args[0] , @compiler) #checking
|
||||
reg = @compiler.use_reg( type.object_class.name )
|
||||
reg.builder = self
|
||||
reg
|
||||
end
|
||||
@ -54,6 +53,8 @@ module Risc
|
||||
def self.resolve_type( object , compiler )
|
||||
object = object.type if object.is_a?(RiscValue)
|
||||
case object
|
||||
when :typed_method
|
||||
type = Parfait.object_space.get_class_by_name( :TypedMethod ).instance_type
|
||||
when :frame
|
||||
type = compiler.method.frame_type
|
||||
when :message , :next_message , :caller
|
||||
@ -65,6 +66,8 @@ module Risc
|
||||
when Parfait::Object
|
||||
type = Parfait.object_space.get_class_by_name( object.class.name.split("::").last.to_sym).instance_type
|
||||
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)
|
||||
raise "Not implemented/found object #{object}:#{object.class}" unless clazz
|
||||
type = clazz.instance_type
|
||||
|
@ -64,8 +64,6 @@ module Risc
|
||||
# - an RValue, which gets procuced by the [] below
|
||||
def <<( load )
|
||||
case load
|
||||
when RValue
|
||||
raise "not yet"
|
||||
when Parfait::Object
|
||||
ins = Risc.load_constant("#{load.class} to #{self.type}" , load , self)
|
||||
when RiscValue
|
||||
@ -77,6 +75,14 @@ module Risc
|
||||
return ins
|
||||
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)
|
||||
# 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
|
||||
|
@ -1,7 +1,7 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
class TestBuilder < MiniTest::Test
|
||||
class TestBuilderBoot #< MiniTest::Test
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@ -9,12 +9,6 @@ module Risc
|
||||
compiler = Risc::MethodCompiler.new( init )
|
||||
@builder = Builder.new(compiler)
|
||||
end
|
||||
def test_has_build
|
||||
assert_nil @builder.build{ }
|
||||
end
|
||||
def test_has_attribute
|
||||
assert_nil @builder.built
|
||||
end
|
||||
def test_register_alloc_space
|
||||
reg = @builder.space
|
||||
assert_equal RiscValue , reg.class
|
||||
@ -42,4 +36,17 @@ module Risc
|
||||
assert_equal :r1 , built.array.symbol
|
||||
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
|
||||
|
@ -44,5 +44,12 @@ module Risc
|
||||
assert_equal @r0 , instr.register
|
||||
assert_equal 4 , instr.index
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user