From bbc13946ed148bb8213c522c43789be9c8838961 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 25 Apr 2017 09:40:09 +0300 Subject: [PATCH] implements self sent with explicit and implicit self --- lib/vool/statements/basic_values.rb | 8 ++++ lib/vool/statements/send_statement.rb | 3 +- test/vool/to_mom/send/test_send_self.rb | 51 +++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 test/vool/to_mom/send/test_send_self.rb diff --git a/lib/vool/statements/basic_values.rb b/lib/vool/statements/basic_values.rb index 331f36c9..3d0238f4 100644 --- a/lib/vool/statements/basic_values.rb +++ b/lib/vool/statements/basic_values.rb @@ -33,6 +33,14 @@ module Vool end end class SelfStatement < Statement + attr_reader :clazz + + def set_class(clazz) + @clazz = clazz + end + def ct_type + @clazz.instance_type + end end class SuperStatement < Statement end diff --git a/lib/vool/statements/send_statement.rb b/lib/vool/statements/send_statement.rb index cae40d09..bb86ae57 100644 --- a/lib/vool/statements/send_statement.rb +++ b/lib/vool/statements/send_statement.rb @@ -56,7 +56,8 @@ module Vool def simple_call type = @receiver.ct_type - method = type.get_method(@name) + method = type.resolve_method(@name) + raise "No method #{@name} for #{type}" unless method [Mom::SimpleCall.new( method) ] end diff --git a/test/vool/to_mom/send/test_send_self.rb b/test/vool/to_mom/send/test_send_self.rb new file mode 100644 index 00000000..ebfd5c72 --- /dev/null +++ b/test/vool/to_mom/send/test_send_self.rb @@ -0,0 +1,51 @@ +require_relative "../helper" + +module Vool + class TestSendSelfMom < MiniTest::Test + include MomCompile + + def setup + Risc.machine.boot + @stats = compile_first_method( "self.get_internal_word(0)").first + end + + def test_class_compiles + assert_equal Mom::SlotConstant , @stats.first.class , @stats + end + def test_slot_is_set + assert @stats.first.left + end + def test_two_instructions_are_returned + assert_equal 3 , @stats.length + end + def test_receiver_move_class + assert_equal Mom::SlotConstant, @stats.first.class + end + def test_receiver_move + assert_equal :receiver, @stats.first.left[2] + end + def test_receiver + assert_equal SelfStatement, @stats.first.right.class + assert_equal :Test, @stats.first.right.clazz.name + end + def test_arg_one + assert_equal Mom::SlotConstant, @stats[1].class + end + def test_call_two + assert_equal Mom::SimpleCall, @stats[2].class + end + def test_call_has_method + assert_equal Parfait::TypedMethod, @stats[2].method.class + end + def test_call_has_right_method + assert_equal :get_internal_word, @stats[2].method.name + end + end + class TestSendSelfImplicitMom < TestSendSelfMom + + def setup + Risc.machine.boot + @stats = compile_first_method( "get_internal_word(0)").first + end + end +end