diff --git a/lib/vool/statements/class_statement.rb b/lib/vool/statements/class_statement.rb index 61639d29..9506c6c5 100644 --- a/lib/vool/statements/class_statement.rb +++ b/lib/vool/statements/class_statement.rb @@ -24,6 +24,12 @@ module Vool end def create_objects + create_class_object + body.collect([]).each {|node| node.set_class(@clazz) } + body.create_objects + end + + def create_class_object @clazz = Parfait.object_space.get_class_by_name(@name ) if(@clazz) #FIXME super class check with "sup" @@ -36,9 +42,6 @@ module Vool vars.each { |var| ivar_hash[var] = :Object } @clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) ) end - body.collect([]).each {|node| node.set_class(@clazz) } - body.create_objects end - end end diff --git a/lib/vool/statements/method_statement.rb b/lib/vool/statements/method_statement.rb index 59416816..43827c0f 100644 --- a/lib/vool/statements/method_statement.rb +++ b/lib/vool/statements/method_statement.rb @@ -36,7 +36,7 @@ module Vool typed_method = method.create_parfait_method(clazz.instance_type) compiler = Risc::MethodCompiler.new( typed_method ).init_method head = @body.to_mom( method ).flatten - head.to_risc(compiler) + compiler.add_mom(head) end private diff --git a/test/mom/to_risc/helper.rb b/test/mom/to_risc/helper.rb index 958c6e9b..491e0f75 100644 --- a/test/mom/to_risc/helper.rb +++ b/test/mom/to_risc/helper.rb @@ -34,7 +34,7 @@ module Risc end def preamble - [Label, SlotToReg , LoadConstant, RegToSlot, LoadConstant,RegToSlot, LoadConstant, SlotToReg, SlotToReg ] + [Label, LoadConstant, SlotToReg, RegToSlot ] end def postamble [ Label, FunctionReturn] @@ -57,19 +57,20 @@ module Risc index = 0 all = instruction.to_arr full_expect = preamble + expect + postamble - full_expect = expect + #full_expect = expect begin should = full_expect[index] - return "No instruction at #{index}" unless should + return "No instruction at #{index}\n#{should(all)}" unless should return "Expected at #{index+1}\n#{should(all)}" unless instruction.class == should + puts instruction.to_s index += 1 instruction = instruction.next end while( instruction ) nil end def should( all ) - #preamble.each {all.shift} - #postamble.each {all.pop} + preamble.each {all.shift} + postamble.each {all.pop} str = all.to_s.gsub("Risc::","") ret = "" str.split(",").each_slice(6).each do |line| diff --git a/test/mom/to_risc/test_assignment.rb b/test/mom/to_risc/test_assignment.rb index ea28dad7..5d397bc7 100644 --- a/test/mom/to_risc/test_assignment.rb +++ b/test/mom/to_risc/test_assignment.rb @@ -5,7 +5,18 @@ module Risc class TestAssignStatement < MiniTest::Test include Statements - def test_assign_op + def test_assign_local_assign + Parfait.object_space.get_main.add_local(:r , :Integer) + + @input = "r = 5" + + @expect = [LoadConstant, RegToSlot] + + assert_nil msg = check_nil , msg + end + + + def pest_assign_op Parfait.object_space.get_main.add_local(:r , :Integer) @input = "r = 10.mod4" @@ -15,9 +26,9 @@ module Risc end def pest_assign_ivar_notpresent - @input =s(:statements, s(:i_assignment, s(:ivar, :r), s(:int, 5))) - @expect = [] - assert_raises{ check_nil } + @input = "@r = 5" + @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] + assert_nil msg = check_nil , msg end def pest_assign_ivar @@ -30,16 +41,6 @@ module Risc assert_nil msg = check_nil , msg end - def pest_assign_local_assign - Parfait.object_space.get_main.add_local(:r , :Integer) - - @input = s(:statements, s(:l_assignment, s(:local, :r), s(:int, 5))) - - @expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg , - RegToSlot, Label, FunctionReturn] - assert_nil msg = check_nil , msg - end - def pest_assign_call Parfait.object_space.get_main.add_local(:r , :Object) @input = s(:statements, s(:l_assignment, s(:local, :r), s(:call, :main, s(:arguments))))