diff --git a/lib/risc/block_compiler.rb b/lib/risc/block_compiler.rb index 4821a687..86f0dfc4 100644 --- a/lib/risc/block_compiler.rb +++ b/lib/risc/block_compiler.rb @@ -2,19 +2,18 @@ module Risc # A BlockCompiler is much like a Mehtodcompiler, exept for blocks # - class BlockCompiler + class BlockCompiler < CallableCompiler attr_reader :block , :risc_instructions , :constants def initialize( block , method) @method = method - @regs = [] @block = block - name = "#{method.self_type.name}.init" - @risc_instructions = Risc.label(name, name) - @risc_instructions << Risc.label( name, "unreachable") - @current = @risc_instructions - @constants = [] + super() + end + + def source_name + "#{@method.self_type.name}.init" end # determine how given name need to be accsessed. @@ -35,5 +34,20 @@ module Risc slot_def << name end + # resolve a symbol to a type. Allowed symbols are :frame , :receiver and arguments + # which return the respective types, otherwise nil + def resolve_type( name ) + case name + when :frame + return @block.frame_type + when :arguments + return @block.arguments_type + when :receiver + return @block.self_type + else + return nil + end + end + end end diff --git a/lib/vool/block_statement.rb b/lib/vool/block_statement.rb index 77af2ede..3e946ba3 100644 --- a/lib/vool/block_statement.rb +++ b/lib/vool/block_statement.rb @@ -24,7 +24,7 @@ module Vool 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) + block_compiler.add_mom(head) block_compiler end diff --git a/test/support/compiling.rb b/test/support/compiling.rb index d0af48cd..bc2f3e09 100644 --- a/test/support/compiling.rb +++ b/test/support/compiling.rb @@ -38,8 +38,16 @@ module MomCompile @method.source.to_mom( compiler ) end def compile_first_block( block_input ) - mom = compile_first_method( "main_local = 5 ; self.main{|val| #{block_input}}") - mom.next(4) # ignore local assign (1) and call (3) + source = "main_local = 5 ; self.main{|val| #{block_input}}" + vool = RubyX::RubyCompiler.compile( as_test_main(source) ).normalize + mom_c = vool.to_mom(nil) + compiler = mom_c.method_compilers.find{|c| c.get_method.name == :main and c.get_method.self_type.object_class.name == :Test} + block = nil + vool.each {|b| block = b if b.is_a?(Vool::BlockStatement)} + assert block + block_c = compiler.block_compilers.first + assert block_c + block.body.to_mom(block_c) end def compile_mom(input) Risc.boot! diff --git a/test/vool/blocks/test_assign.rb b/test/vool/blocks/test_assign.rb index d4730511..7c31412e 100644 --- a/test/vool/blocks/test_assign.rb +++ b/test/vool/blocks/test_assign.rb @@ -10,8 +10,8 @@ module VoolBlocks @ins = compile_first_block( "local = 5") end - def test_class_compiles - #assert_equal Mom::SlotLoad , @ins.class , @ins + def test_block_compiles + assert_equal Mom::SlotLoad , @ins.class , @ins end def pest_slot_is_set assert @ins.left