diff --git a/lib/mom/mom_compiler.rb b/lib/mom/mom_compiler.rb index 68cec826..6968ab07 100644 --- a/lib/mom/mom_compiler.rb +++ b/lib/mom/mom_compiler.rb @@ -40,7 +40,7 @@ module Mom cpu_instructions << cpu if cpu nekst = nekst.next end - Risc::Assembler.new(compiler.method , cpu_instructions ) + Risc::Assembler.new(compiler.get_method , cpu_instructions ) end end diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index ad5839af..79c80430 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -135,7 +135,7 @@ module Risc def add_known(name) case name 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 ) return ret when :space diff --git a/lib/risc/builtin.rb b/lib/risc/builtin.rb index c933544b..9d5594fc 100644 --- a/lib/risc/builtin.rb +++ b/lib/risc/builtin.rb @@ -47,12 +47,12 @@ module Risc def self.compiler_for( type , mod , name) compiler = mod.send(name , nil) - type.add_method( compiler.method ) + compiler.add_method_to(type) compiler end def self.operator_compiler(int_type , op) compiler = Integer.operator_method(op) - int_type.add_method(compiler.method) + compiler.add_method_to(int_type) compiler end end diff --git a/lib/risc/builtin/integer.rb b/lib/risc/builtin/integer.rb index 2eae1785..19b65996 100644 --- a/lib/risc/builtin/integer.rb +++ b/lib/risc/builtin/integer.rb @@ -8,7 +8,7 @@ module Risc def div4(context) source = "div4" compiler = compiler_for(:Integer,:div4 ,{}) - builder = compiler.compiler_builder(compiler.method) + builder = compiler.compiler_builder(compiler.source) me = builder.add_known( :receiver ) builder.reduce_int( source , me ) two = compiler.use_reg :fixnum , 2 @@ -33,10 +33,10 @@ module Risc end def comparison( operator ) 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") - false_label = Risc.label(compiler.method , "false_label_#{builder.object_id.to_s(16)}") - merge_label = Risc.label(compiler.method , "merge_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.source , "merge_label_#{builder.object_id.to_s(16)}") builder.reduce_int( "#{operator} fix me", me ) builder.reduce_int( "#{operator} fix arg", other ) if(operator.to_s.start_with?('<') ) @@ -63,7 +63,7 @@ module Risc end def operator_method( op_sym ) 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") builder.reduce_int( op_sym.to_s + " fix me", me ) builder.reduce_int( op_sym.to_s + " fix arg", other ) @@ -76,7 +76,7 @@ module Risc def div10( context ) s = "div_10 " 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 me = builder.add_known( :receiver ) tmp = builder.add_known( :receiver ) diff --git a/lib/risc/builtin/object.rb b/lib/risc/builtin/object.rb index 1b5b093b..25689074 100644 --- a/lib/risc/builtin/object.rb +++ b/lib/risc/builtin/object.rb @@ -9,7 +9,7 @@ module Risc # (this method returns a new method off course, like all builtin) def get_internal_word( context ) 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" me , index = builder.self_and_int_arg(source) # reduce me to me[index] @@ -25,7 +25,7 @@ module Risc def set_internal_word( context ) compiler = compiler_for(:Object , :set_internal_word , {at: :Integer, :value => :Object} ) source = "set_internal_word" - builder = compiler.compiler_builder(compiler.method) + builder = compiler.compiler_builder(compiler.source) me , index = builder.self_and_int_arg(source) value = builder.load_int_arg_at(source , 1) # do the set @@ -38,7 +38,7 @@ module Risc # Even if it's just this one, sys_exit (later raise) def _method_missing( context ) compiler = compiler_for(:Object,:method_missing ,{}) - emit_syscall( compiler.compiler_builder(compiler.method) , :exit ) + emit_syscall( compiler.compiler_builder(compiler.source) , :exit ) return compiler end @@ -48,7 +48,7 @@ module Risc def __init__ context compiler = MethodCompiler.compiler_for_class(:Object,:__init__ , Parfait::NamedList.type_for({}) , Parfait::NamedList.type_for({})) - builder = compiler.compiler_builder(compiler.method) + builder = compiler.compiler_builder(compiler.source) builder.build do space << Parfait.object_space message << space[:next_message] @@ -63,7 +63,7 @@ module Risc message[:receiver] << space 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) builder.build do add_load_constant("__init__ load return", exit_label , ret_tmp) @@ -87,7 +87,7 @@ module Risc def exit( context ) compiler = compiler_for(:Object,:exit ,{}) - builder = compiler.compiler_builder(compiler.method) + builder = compiler.compiler_builder(compiler.source) exit_sequence(builder) return compiler end diff --git a/lib/risc/builtin/word.rb b/lib/risc/builtin/word.rb index 3cdbaa08..f10871c4 100644 --- a/lib/risc/builtin/word.rb +++ b/lib/risc/builtin/word.rb @@ -6,7 +6,7 @@ module Risc def putstring( context) 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 ) index = Parfait::Word.get_length_index reg = RegisterValue.new(:r2 , :Integer) @@ -21,7 +21,7 @@ module Risc def get_internal_byte( context) compiler = compiler_for(:Word , :get_internal_byte , {at: :Integer}) source = "get_internal_byte" - builder = compiler.compiler_builder(compiler.method) + builder = compiler.compiler_builder(compiler.source) me , index = builder.self_and_int_arg(source) builder.reduce_int( source + " fix arg", index ) # reduce me to me[index] @@ -39,7 +39,7 @@ module Risc def set_internal_byte( context ) compiler = compiler_for(:Word, :set_internal_byte , {at: :Integer , :value => :Integer} ) source = "set_internal_byte" - builder = compiler.compiler_builder(compiler.method) + builder = compiler.compiler_builder(compiler.source) me , index = builder.self_and_int_arg(source) value = builder.load_int_arg_at(source , 1 ) builder.reduce_int( source + " fix me", value ) diff --git a/lib/risc/method_compiler.rb b/lib/risc/method_compiler.rb index 522b8e28..a9258395 100644 --- a/lib/risc/method_compiler.rb +++ b/lib/risc/method_compiler.rb @@ -21,8 +21,15 @@ module Risc @constants = [] @block_compilers = [] 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 # 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) 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) # method_name is a Symbol # args a hash that will be converted to a type diff --git a/lib/vool/basic_values.rb b/lib/vool/basic_values.rb index fe9facc5..a77b994d 100644 --- a/lib/vool/basic_values.rb +++ b/lib/vool/basic_values.rb @@ -70,7 +70,7 @@ module Vool @my_type = type end def slot_definition(compiler) - @my_type = compiler.method.self_type + @my_type = compiler.resolve_type(:receiver) Mom::SlotDefinition.new(:message , [:receiver]) end def ct_type diff --git a/lib/vool/block_statement.rb b/lib/vool/block_statement.rb index c304adad..77af2ede 100644 --- a/lib/vool/block_statement.rb +++ b/lib/vool/block_statement.rb @@ -21,7 +21,7 @@ module Vool # to the method compiler for further processing def to_mom( 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) head = body.to_mom( block_compiler ) #block_compiler.add_mom(head) @@ -41,7 +41,7 @@ module Vool # to CallableMethod) def parfait_block(compiler) 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 private diff --git a/lib/vool/send_statement.rb b/lib/vool/send_statement.rb index 7e8897ac..ea8497d8 100644 --- a/lib/vool/send_statement.rb +++ b/lib/vool/send_statement.rb @@ -72,7 +72,7 @@ module Vool # - 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 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) simple_call(compiler) else diff --git a/lib/vool/variables.rb b/lib/vool/variables.rb index 650d9f42..7ef13adb 100644 --- a/lib/vool/variables.rb +++ b/lib/vool/variables.rb @@ -11,12 +11,8 @@ module Vool class LocalVariable < Expression include Named def slot_definition(compiler) - if compiler.method.arguments_type.variable_index(@name) - type = :arguments - else - type = :frame - end - Mom::SlotDefinition.new(:message , [type , @name]) + slot_def = compiler.slot_type_for(@name) + Mom::SlotDefinition.new(:message , slot_def) end def to_s name.to_s diff --git a/test/mom/test_block_statement.rb b/test/mom/test_block_statement.rb index b5f1c929..4d484882 100644 --- a/test/mom/test_block_statement.rb +++ b/test/mom/test_block_statement.rb @@ -13,10 +13,10 @@ module Vool assert_equal Mom::MomCompiler , @ret.class end 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 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 class TestBlockCreated < MiniTest::Test @@ -24,7 +24,7 @@ module Vool def setup Parfait.boot! @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 def test_block_arg_type assert_equal Parfait::Type, @block.arguments_type.class @@ -44,7 +44,7 @@ module Vool def setup Parfait.boot! @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 def test_block_arg_type assert_equal Parfait::Type, @block.arguments_type.class diff --git a/test/support/compiling.rb b/test/support/compiling.rb index 727177cf..d0af48cd 100644 --- a/test/support/compiling.rb +++ b/test/support/compiling.rb @@ -33,7 +33,7 @@ module MomCompile def compile_first_method( input ) ret = compile_method( as_test_main( input )) 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 @method.source.to_mom( compiler ) end