diff --git a/lib/mom/instruction/message_setup.rb b/lib/mom/instruction/message_setup.rb index ab432b3e..cb6ef6d9 100644 --- a/lib/mom/instruction/message_setup.rb +++ b/lib/mom/instruction/message_setup.rb @@ -27,7 +27,7 @@ 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) - builder = compiler.builder(false) + builder = compiler.builder(false, self) build_with(builder) end diff --git a/lib/mom/instruction/resolve_method.rb b/lib/mom/instruction/resolve_method.rb index 3eec91f9..f762da23 100644 --- a/lib/mom/instruction/resolve_method.rb +++ b/lib/mom/instruction/resolve_method.rb @@ -32,7 +32,7 @@ module Mom def to_risc( compiler ) name_ = @name cache_entry_ = @cache_entry - builder = compiler.builder(false) + builder = compiler.builder(false, self) builder.build do word << name_ cache_entry << cache_entry_ diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index a33b7e95..a97548d7 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -12,10 +12,12 @@ module Risc # pass a compiler, to which instruction are added (usually) # second arg determines weather instructions are added (default true) # call build with a block to build - def initialize(compiler, auto_add) + def initialize(compiler, auto_add , for_source) @compiler = compiler @auto_add = auto_add @built = nil + @source = for_source + @source_used = false @names = {} end diff --git a/lib/risc/builtin/integer.rb b/lib/risc/builtin/integer.rb index 42b3127a..8eb9bcd9 100644 --- a/lib/risc/builtin/integer.rb +++ b/lib/risc/builtin/integer.rb @@ -8,7 +8,7 @@ module Risc def mod4(context) source = "mod4" compiler = compiler_for(:Integer,:mod4 ,{}) - builder = compiler.builder(true) + builder = compiler.builder(true, compiler.method) me = builder.add_known( :receiver ) builder.reduce_int( source , me ) two = compiler.use_reg :fixnum , 2 @@ -35,7 +35,7 @@ module Risc end def operator_method(op_name , op_sym ) compiler = compiler_for(:Integer, op_sym ,{other: :Integer}) - builder = compiler.builder(true) + builder = compiler.builder(true, compiler.method) me , other = builder.self_and_int_arg(op_name + "load receiver and arg") builder.reduce_int( op_name + " fix me", me ) builder.reduce_int( op_name + " fix arg", other ) @@ -48,7 +48,7 @@ module Risc def div10( context ) s = "div_10 " compiler = compiler_for(:Integer,:div10 ,{}) - builder = compiler.builder(true) + builder = compiler.builder(true, compiler.method) #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 39386561..3e9bf97f 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.builder(true) + builder = compiler.builder(true, compiler.method) 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.builder(true) + builder = compiler.builder(true, compiler.method) me , index = builder.self_and_int_arg(source) value = builder.load_int_arg_at(source , 2) @@ -39,7 +39,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.builder(true) , :exit ) + emit_syscall( compiler.builder(true, compiler.method) , :exit ) return compiler.method end # this is the really really first place the machine starts (apart from the jump here) @@ -48,7 +48,7 @@ module Risc def __init__ context compiler = Risc::MethodCompiler.create_method(:Object,:__init__ , Parfait::NamedList.type_for({}) , Parfait::NamedList.type_for({})) - builder = compiler.builder(true) + builder = compiler.builder(true, compiler.method) builder.build do space << Parfait.object_space message << space[:first_message] @@ -78,7 +78,7 @@ module Risc def exit( context ) compiler = compiler_for(:Object,:exit ,{}) - emit_syscall( compiler.builder(true) , :exit ) + emit_syscall( compiler.builder(true, compiler.method) , :exit ) return compiler.method end diff --git a/lib/risc/builtin/word.rb b/lib/risc/builtin/word.rb index c430e85a..fd2ad3a6 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.builder(true) + builder = compiler.builder(true, compiler.method) builder.add_slot_to_reg( "putstring" , :message , :receiver , :new_message ) index = Parfait::Word.get_length_index reg = RiscValue.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.builder(true) + builder = compiler.builder(true, compiler.method) 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.builder(true) + builder = compiler.builder(true, compiler.method) me , index = builder.self_and_int_arg(source) value = builder.load_int_arg_at(source , 2 ) builder.reduce_int( source + " fix me", value ) diff --git a/lib/risc/method_compiler.rb b/lib/risc/method_compiler.rb index 37032be2..c2d8eebb 100644 --- a/lib/risc/method_compiler.rb +++ b/lib/risc/method_compiler.rb @@ -110,8 +110,9 @@ module Risc # return a new builder that uses this compiler # must specify weather to add code automatically to compiler - def builder( auto_add ) - Builder.new(self , auto_add) + # second arg is the source for which to build, either method or mom::instruction + def builder( auto_add , source) + Builder.new(self , auto_add , source) end end end diff --git a/test/risc/test_builder.rb b/test/risc/test_builder.rb index 2bff05f3..ee7849a8 100644 --- a/test/risc/test_builder.rb +++ b/test/risc/test_builder.rb @@ -6,7 +6,7 @@ module Risc def setup Risc.machine.boot init = Parfait.object_space.get_init - @builder = Risc::MethodCompiler.new( init ).builder(false) + @builder = Risc::MethodCompiler.new( init ).builder(false , init) @label = Risc::Label.new("source","name") end def test_has_build @@ -102,7 +102,7 @@ module Risc def setup Risc.machine.boot @init = Parfait.object_space.get_init - @builder = Risc::MethodCompiler.new( @init ).builder(true) + @builder = Risc::MethodCompiler.new( @init ).builder(true, @init) end def test_inserts_built r1 = RiscValue.new(:r1 , :Space)