makeing the method of the compiler more or less private
in preparation for using the same code for bocks
This commit is contained in:
parent
63b55f2aa4
commit
edea9ac080
@ -40,7 +40,7 @@ module Mom
|
|||||||
cpu_instructions << cpu if cpu
|
cpu_instructions << cpu if cpu
|
||||||
nekst = nekst.next
|
nekst = nekst.next
|
||||||
end
|
end
|
||||||
Risc::Assembler.new(compiler.method , cpu_instructions )
|
Risc::Assembler.new(compiler.get_method , cpu_instructions )
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -135,7 +135,7 @@ module Risc
|
|||||||
def add_known(name)
|
def add_known(name)
|
||||||
case name
|
case name
|
||||||
when :receiver
|
when :receiver
|
||||||
ret = compiler.use_reg compiler.method.self_type
|
ret = compiler.use_reg compiler.resolve_type(:receiver)
|
||||||
add_slot_to_reg(" load self" , :message , :receiver , ret )
|
add_slot_to_reg(" load self" , :message , :receiver , ret )
|
||||||
return ret
|
return ret
|
||||||
when :space
|
when :space
|
||||||
|
@ -47,12 +47,12 @@ module Risc
|
|||||||
|
|
||||||
def self.compiler_for( type , mod , name)
|
def self.compiler_for( type , mod , name)
|
||||||
compiler = mod.send(name , nil)
|
compiler = mod.send(name , nil)
|
||||||
type.add_method( compiler.method )
|
compiler.add_method_to(type)
|
||||||
compiler
|
compiler
|
||||||
end
|
end
|
||||||
def self.operator_compiler(int_type , op)
|
def self.operator_compiler(int_type , op)
|
||||||
compiler = Integer.operator_method(op)
|
compiler = Integer.operator_method(op)
|
||||||
int_type.add_method(compiler.method)
|
compiler.add_method_to(int_type)
|
||||||
compiler
|
compiler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ module Risc
|
|||||||
def div4(context)
|
def div4(context)
|
||||||
source = "div4"
|
source = "div4"
|
||||||
compiler = compiler_for(:Integer,:div4 ,{})
|
compiler = compiler_for(:Integer,:div4 ,{})
|
||||||
builder = compiler.compiler_builder(compiler.method)
|
builder = compiler.compiler_builder(compiler.source)
|
||||||
me = builder.add_known( :receiver )
|
me = builder.add_known( :receiver )
|
||||||
builder.reduce_int( source , me )
|
builder.reduce_int( source , me )
|
||||||
two = compiler.use_reg :fixnum , 2
|
two = compiler.use_reg :fixnum , 2
|
||||||
@ -33,10 +33,10 @@ module Risc
|
|||||||
end
|
end
|
||||||
def comparison( operator )
|
def comparison( operator )
|
||||||
compiler = compiler_for(:Integer, operator ,{other: :Integer})
|
compiler = compiler_for(:Integer, operator ,{other: :Integer})
|
||||||
builder = compiler.compiler_builder(compiler.method)
|
builder = compiler.compiler_builder(compiler.source)
|
||||||
me , other = builder.self_and_int_arg("#{operator} load receiver and arg")
|
me , other = builder.self_and_int_arg("#{operator} load receiver and arg")
|
||||||
false_label = Risc.label(compiler.method , "false_label_#{builder.object_id.to_s(16)}")
|
false_label = Risc.label(compiler.source , "false_label_#{builder.object_id.to_s(16)}")
|
||||||
merge_label = Risc.label(compiler.method , "merge_label_#{builder.object_id.to_s(16)}")
|
merge_label = Risc.label(compiler.source , "merge_label_#{builder.object_id.to_s(16)}")
|
||||||
builder.reduce_int( "#{operator} fix me", me )
|
builder.reduce_int( "#{operator} fix me", me )
|
||||||
builder.reduce_int( "#{operator} fix arg", other )
|
builder.reduce_int( "#{operator} fix arg", other )
|
||||||
if(operator.to_s.start_with?('<') )
|
if(operator.to_s.start_with?('<') )
|
||||||
@ -63,7 +63,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
def operator_method( op_sym )
|
def operator_method( op_sym )
|
||||||
compiler = compiler_for(:Integer, op_sym ,{other: :Integer})
|
compiler = compiler_for(:Integer, op_sym ,{other: :Integer})
|
||||||
builder = compiler.compiler_builder(compiler.method)
|
builder = compiler.compiler_builder(compiler.source)
|
||||||
me , other = builder.self_and_int_arg(op_sym.to_s + "load receiver and arg")
|
me , other = builder.self_and_int_arg(op_sym.to_s + "load receiver and arg")
|
||||||
builder.reduce_int( op_sym.to_s + " fix me", me )
|
builder.reduce_int( op_sym.to_s + " fix me", me )
|
||||||
builder.reduce_int( op_sym.to_s + " fix arg", other )
|
builder.reduce_int( op_sym.to_s + " fix arg", other )
|
||||||
@ -76,7 +76,7 @@ module Risc
|
|||||||
def div10( context )
|
def div10( context )
|
||||||
s = "div_10 "
|
s = "div_10 "
|
||||||
compiler = compiler_for(:Integer,:div10 ,{})
|
compiler = compiler_for(:Integer,:div10 ,{})
|
||||||
builder = compiler.compiler_builder(compiler.method)
|
builder = compiler.compiler_builder(compiler.source)
|
||||||
#FIX: this could load receiver once, reduce and then transfer twice
|
#FIX: this could load receiver once, reduce and then transfer twice
|
||||||
me = builder.add_known( :receiver )
|
me = builder.add_known( :receiver )
|
||||||
tmp = builder.add_known( :receiver )
|
tmp = builder.add_known( :receiver )
|
||||||
|
@ -9,7 +9,7 @@ module Risc
|
|||||||
# (this method returns a new method off course, like all builtin)
|
# (this method returns a new method off course, like all builtin)
|
||||||
def get_internal_word( context )
|
def get_internal_word( context )
|
||||||
compiler = compiler_for(:Object , :get_internal_word ,{at: :Integer})
|
compiler = compiler_for(:Object , :get_internal_word ,{at: :Integer})
|
||||||
builder = compiler.compiler_builder(compiler.method)
|
builder = compiler.compiler_builder(compiler.source)
|
||||||
source = "get_internal_word"
|
source = "get_internal_word"
|
||||||
me , index = builder.self_and_int_arg(source)
|
me , index = builder.self_and_int_arg(source)
|
||||||
# reduce me to me[index]
|
# reduce me to me[index]
|
||||||
@ -25,7 +25,7 @@ module Risc
|
|||||||
def set_internal_word( context )
|
def set_internal_word( context )
|
||||||
compiler = compiler_for(:Object , :set_internal_word , {at: :Integer, :value => :Object} )
|
compiler = compiler_for(:Object , :set_internal_word , {at: :Integer, :value => :Object} )
|
||||||
source = "set_internal_word"
|
source = "set_internal_word"
|
||||||
builder = compiler.compiler_builder(compiler.method)
|
builder = compiler.compiler_builder(compiler.source)
|
||||||
me , index = builder.self_and_int_arg(source)
|
me , index = builder.self_and_int_arg(source)
|
||||||
value = builder.load_int_arg_at(source , 1)
|
value = builder.load_int_arg_at(source , 1)
|
||||||
# do the set
|
# do the set
|
||||||
@ -38,7 +38,7 @@ module Risc
|
|||||||
# Even if it's just this one, sys_exit (later raise)
|
# Even if it's just this one, sys_exit (later raise)
|
||||||
def _method_missing( context )
|
def _method_missing( context )
|
||||||
compiler = compiler_for(:Object,:method_missing ,{})
|
compiler = compiler_for(:Object,:method_missing ,{})
|
||||||
emit_syscall( compiler.compiler_builder(compiler.method) , :exit )
|
emit_syscall( compiler.compiler_builder(compiler.source) , :exit )
|
||||||
return compiler
|
return compiler
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ module Risc
|
|||||||
def __init__ context
|
def __init__ context
|
||||||
compiler = MethodCompiler.compiler_for_class(:Object,:__init__ ,
|
compiler = MethodCompiler.compiler_for_class(:Object,:__init__ ,
|
||||||
Parfait::NamedList.type_for({}) , Parfait::NamedList.type_for({}))
|
Parfait::NamedList.type_for({}) , Parfait::NamedList.type_for({}))
|
||||||
builder = compiler.compiler_builder(compiler.method)
|
builder = compiler.compiler_builder(compiler.source)
|
||||||
builder.build do
|
builder.build do
|
||||||
space << Parfait.object_space
|
space << Parfait.object_space
|
||||||
message << space[:next_message]
|
message << space[:next_message]
|
||||||
@ -63,7 +63,7 @@ module Risc
|
|||||||
message[:receiver] << space
|
message[:receiver] << space
|
||||||
end
|
end
|
||||||
|
|
||||||
exit_label = Risc.label(compiler.method , "#{compiler.method.self_type.object_class.name}.#{compiler.method.name}" )
|
exit_label = Risc.label(compiler.source , "#{compiler.resolve_type(:receiver).object_class.name}.#{compiler.source.name}" )
|
||||||
ret_tmp = compiler.use_reg(:Label)
|
ret_tmp = compiler.use_reg(:Label)
|
||||||
builder.build do
|
builder.build do
|
||||||
add_load_constant("__init__ load return", exit_label , ret_tmp)
|
add_load_constant("__init__ load return", exit_label , ret_tmp)
|
||||||
@ -87,7 +87,7 @@ module Risc
|
|||||||
|
|
||||||
def exit( context )
|
def exit( context )
|
||||||
compiler = compiler_for(:Object,:exit ,{})
|
compiler = compiler_for(:Object,:exit ,{})
|
||||||
builder = compiler.compiler_builder(compiler.method)
|
builder = compiler.compiler_builder(compiler.source)
|
||||||
exit_sequence(builder)
|
exit_sequence(builder)
|
||||||
return compiler
|
return compiler
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ module Risc
|
|||||||
|
|
||||||
def putstring( context)
|
def putstring( context)
|
||||||
compiler = compiler_for(:Word , :putstring ,{})
|
compiler = compiler_for(:Word , :putstring ,{})
|
||||||
builder = compiler.compiler_builder(compiler.method)
|
builder = compiler.compiler_builder(compiler.source)
|
||||||
builder.add_slot_to_reg( "putstring" , :message , :receiver , :new_message )
|
builder.add_slot_to_reg( "putstring" , :message , :receiver , :new_message )
|
||||||
index = Parfait::Word.get_length_index
|
index = Parfait::Word.get_length_index
|
||||||
reg = RegisterValue.new(:r2 , :Integer)
|
reg = RegisterValue.new(:r2 , :Integer)
|
||||||
@ -21,7 +21,7 @@ module Risc
|
|||||||
def get_internal_byte( context)
|
def get_internal_byte( context)
|
||||||
compiler = compiler_for(:Word , :get_internal_byte , {at: :Integer})
|
compiler = compiler_for(:Word , :get_internal_byte , {at: :Integer})
|
||||||
source = "get_internal_byte"
|
source = "get_internal_byte"
|
||||||
builder = compiler.compiler_builder(compiler.method)
|
builder = compiler.compiler_builder(compiler.source)
|
||||||
me , index = builder.self_and_int_arg(source)
|
me , index = builder.self_and_int_arg(source)
|
||||||
builder.reduce_int( source + " fix arg", index )
|
builder.reduce_int( source + " fix arg", index )
|
||||||
# reduce me to me[index]
|
# reduce me to me[index]
|
||||||
@ -39,7 +39,7 @@ module Risc
|
|||||||
def set_internal_byte( context )
|
def set_internal_byte( context )
|
||||||
compiler = compiler_for(:Word, :set_internal_byte , {at: :Integer , :value => :Integer} )
|
compiler = compiler_for(:Word, :set_internal_byte , {at: :Integer , :value => :Integer} )
|
||||||
source = "set_internal_byte"
|
source = "set_internal_byte"
|
||||||
builder = compiler.compiler_builder(compiler.method)
|
builder = compiler.compiler_builder(compiler.source)
|
||||||
me , index = builder.self_and_int_arg(source)
|
me , index = builder.self_and_int_arg(source)
|
||||||
value = builder.load_int_arg_at(source , 1 )
|
value = builder.load_int_arg_at(source , 1 )
|
||||||
builder.reduce_int( source + " fix me", value )
|
builder.reduce_int( source + " fix me", value )
|
||||||
|
@ -21,8 +21,15 @@ module Risc
|
|||||||
@constants = []
|
@constants = []
|
||||||
@block_compilers = []
|
@block_compilers = []
|
||||||
end
|
end
|
||||||
attr_reader :method , :risc_instructions , :constants
|
attr_reader :risc_instructions , :constants
|
||||||
|
|
||||||
|
def get_method
|
||||||
|
@method
|
||||||
|
end
|
||||||
|
# sometimes the method is used as source (tb reviewed)
|
||||||
|
def source
|
||||||
|
@method
|
||||||
|
end
|
||||||
# helper method for builtin mainly
|
# helper method for builtin mainly
|
||||||
# the class_name is a symbol, which is resolved to the instance_type of that class
|
# the class_name is a symbol, which is resolved to the instance_type of that class
|
||||||
#
|
#
|
||||||
@ -34,6 +41,13 @@ module Risc
|
|||||||
compiler_for_type( clazz.instance_type , method_name , args , frame)
|
compiler_for_type( clazz.instance_type , method_name , args , frame)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_method_to( target )
|
||||||
|
target.add_method( @method )
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_block(arg_type , frame_type)
|
||||||
|
@method.create_block(arg_type ,frame_type)
|
||||||
|
end
|
||||||
# create a method for the given type ( Parfait type object)
|
# create a method for the given type ( Parfait type object)
|
||||||
# method_name is a Symbol
|
# method_name is a Symbol
|
||||||
# args a hash that will be converted to a type
|
# args a hash that will be converted to a type
|
||||||
|
@ -70,7 +70,7 @@ module Vool
|
|||||||
@my_type = type
|
@my_type = type
|
||||||
end
|
end
|
||||||
def slot_definition(compiler)
|
def slot_definition(compiler)
|
||||||
@my_type = compiler.method.self_type
|
@my_type = compiler.resolve_type(:receiver)
|
||||||
Mom::SlotDefinition.new(:message , [:receiver])
|
Mom::SlotDefinition.new(:message , [:receiver])
|
||||||
end
|
end
|
||||||
def ct_type
|
def ct_type
|
||||||
|
@ -21,7 +21,7 @@ module Vool
|
|||||||
# to the method compiler for further processing
|
# to the method compiler for further processing
|
||||||
def to_mom( compiler )
|
def to_mom( compiler )
|
||||||
parfait_block = self.parfait_block(compiler)
|
parfait_block = self.parfait_block(compiler)
|
||||||
block_compiler = Risc::BlockCompiler.new( parfait_block , compiler.method )
|
block_compiler = Risc::BlockCompiler.new( parfait_block , compiler.get_method )
|
||||||
compiler.add_block_compiler(block_compiler)
|
compiler.add_block_compiler(block_compiler)
|
||||||
head = body.to_mom( block_compiler )
|
head = body.to_mom( block_compiler )
|
||||||
#block_compiler.add_mom(head)
|
#block_compiler.add_mom(head)
|
||||||
@ -41,7 +41,7 @@ module Vool
|
|||||||
# to CallableMethod)
|
# to CallableMethod)
|
||||||
def parfait_block(compiler)
|
def parfait_block(compiler)
|
||||||
return @parfait_block if @parfait_block
|
return @parfait_block if @parfait_block
|
||||||
@parfait_block = compiler.method.create_block( make_arg_type , make_frame(compiler))
|
@parfait_block = compiler.create_block( make_arg_type , make_frame(compiler))
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -72,7 +72,7 @@ module Vool
|
|||||||
# - Setting up the next message, with receiver, arguments, and (importantly) return address
|
# - Setting up the next message, with receiver, arguments, and (importantly) return address
|
||||||
# - a CachedCall , or a SimpleCall, depending on wether the receiver type can be determined
|
# - a CachedCall , or a SimpleCall, depending on wether the receiver type can be determined
|
||||||
def to_mom( compiler )
|
def to_mom( compiler )
|
||||||
@receiver = SelfExpression.new(compiler.method.self_type) if @receiver.is_a?(SelfExpression)
|
@receiver = SelfExpression.new(compiler.resolve_type(:receiver)) if @receiver.is_a?(SelfExpression)
|
||||||
if(@receiver.ct_type)
|
if(@receiver.ct_type)
|
||||||
simple_call(compiler)
|
simple_call(compiler)
|
||||||
else
|
else
|
||||||
|
@ -11,12 +11,8 @@ module Vool
|
|||||||
class LocalVariable < Expression
|
class LocalVariable < Expression
|
||||||
include Named
|
include Named
|
||||||
def slot_definition(compiler)
|
def slot_definition(compiler)
|
||||||
if compiler.method.arguments_type.variable_index(@name)
|
slot_def = compiler.slot_type_for(@name)
|
||||||
type = :arguments
|
Mom::SlotDefinition.new(:message , slot_def)
|
||||||
else
|
|
||||||
type = :frame
|
|
||||||
end
|
|
||||||
Mom::SlotDefinition.new(:message , [type , @name])
|
|
||||||
end
|
end
|
||||||
def to_s
|
def to_s
|
||||||
name.to_s
|
name.to_s
|
||||||
|
@ -13,10 +13,10 @@ module Vool
|
|||||||
assert_equal Mom::MomCompiler , @ret.class
|
assert_equal Mom::MomCompiler , @ret.class
|
||||||
end
|
end
|
||||||
def test_has_method
|
def test_has_method
|
||||||
assert_equal Parfait::CallableMethod , @ret.method_compilers.first.method.class
|
assert_equal Parfait::CallableMethod , @ret.method_compilers.first.get_method.class
|
||||||
end
|
end
|
||||||
def test_method_has_block
|
def test_method_has_block
|
||||||
assert @ret.method_compilers.first.method.blocks , "No block created"
|
assert @ret.method_compilers.first.get_method.blocks , "No block created"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestBlockCreated < MiniTest::Test
|
class TestBlockCreated < MiniTest::Test
|
||||||
@ -24,7 +24,7 @@ module Vool
|
|||||||
def setup
|
def setup
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
@ret = compile_mom( as_test_main("self.main {|elem| local = 5 } "))
|
@ret = compile_mom( as_test_main("self.main {|elem| local = 5 } "))
|
||||||
@block = @ret.method_compilers.first.method.blocks
|
@block = @ret.method_compilers.first.get_method.blocks
|
||||||
end
|
end
|
||||||
def test_block_arg_type
|
def test_block_arg_type
|
||||||
assert_equal Parfait::Type, @block.arguments_type.class
|
assert_equal Parfait::Type, @block.arguments_type.class
|
||||||
@ -44,7 +44,7 @@ module Vool
|
|||||||
def setup
|
def setup
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
@ret = compile_mom( as_test_main("arg.each {|elem| arg = 5 } "))
|
@ret = compile_mom( as_test_main("arg.each {|elem| arg = 5 } "))
|
||||||
@block = @ret.method_compilers.first.method.blocks
|
@block = @ret.method_compilers.first.get_method.blocks
|
||||||
end
|
end
|
||||||
def test_block_arg_type
|
def test_block_arg_type
|
||||||
assert_equal Parfait::Type, @block.arguments_type.class
|
assert_equal Parfait::Type, @block.arguments_type.class
|
||||||
|
@ -33,7 +33,7 @@ module MomCompile
|
|||||||
def compile_first_method( input )
|
def compile_first_method( input )
|
||||||
ret = compile_method( as_test_main( input ))
|
ret = compile_method( as_test_main( input ))
|
||||||
assert_equal Mom::MomCompiler , ret.class
|
assert_equal Mom::MomCompiler , ret.class
|
||||||
compiler = ret.method_compilers.find{|c| c.method.name == :main and c.method.self_type.object_class.name == :Test}
|
compiler = ret.method_compilers.find{|c| c.get_method.name == :main and c.get_method.self_type.object_class.name == :Test}
|
||||||
assert_equal Risc::MethodCompiler , compiler.class
|
assert_equal Risc::MethodCompiler , compiler.class
|
||||||
@method.source.to_mom( compiler )
|
@method.source.to_mom( compiler )
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user