From f264aec94acd5235c39126915090fe1935d8b4ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Wed, 11 Sep 2019 18:43:20 +0300 Subject: [PATCH] macro tests for all object mom instructions --- lib/mom/builtin/exit.rb | 8 ++++++ lib/mom/builtin/init.rb | 30 +++++++++++++++++++ lib/mom/builtin/method_missing.rb | 8 ++++++ test/rubyx/builtin/helper.rb | 15 ++++++++++ test/rubyx/builtin/test_object_exit.rb | 35 +++++++++++++++++++++++ test/rubyx/builtin/test_object_get.rb | 16 +++-------- test/rubyx/builtin/test_object_init.rb | 35 +++++++++++++++++++++++ test/rubyx/builtin/test_object_missing.rb | 35 +++++++++++++++++++++++ test/rubyx/builtin/test_object_set.rb | 30 +++++++++++++++++++ 9 files changed, 200 insertions(+), 12 deletions(-) create mode 100644 test/rubyx/builtin/test_object_exit.rb create mode 100644 test/rubyx/builtin/test_object_init.rb create mode 100644 test/rubyx/builtin/test_object_missing.rb create mode 100644 test/rubyx/builtin/test_object_set.rb diff --git a/lib/mom/builtin/exit.rb b/lib/mom/builtin/exit.rb index aa129909..0fe7acf1 100644 --- a/lib/mom/builtin/exit.rb +++ b/lib/mom/builtin/exit.rb @@ -9,4 +9,12 @@ module Mom end end end + class Exit < ::Mom::Instruction + def to_risc(compiler) + builder = compiler.builder(compiler.source) + builder.prepare_int_return # makes integer_tmp variable as return + Builtin.exit_sequence(builder) + return compiler + end + end end diff --git a/lib/mom/builtin/init.rb b/lib/mom/builtin/init.rb index 0165bc2a..272ac106 100644 --- a/lib/mom/builtin/init.rb +++ b/lib/mom/builtin/init.rb @@ -31,6 +31,36 @@ module Mom return compiler end end + end + class Init < ::Mom::Instruction + def to_risc(compiler) + builder = compiler.builder(compiler.source) + builder.build do + factory! << Parfait.object_space.get_factory_for(:Message) + message << factory[:next_object] + next_message! << message[:next_message] + factory[:next_object] << next_message + end + builder.reset_names + Mom::MessageSetup.new(Parfait.object_space.get_main).build_with( builder ) + builder.build do + message << message[:next_message] + space? << Parfait.object_space + message[:receiver] << space + end + + exit_label = Risc.label(compiler.source , "#{compiler.receiver_type.object_class.name}.#{compiler.source.name}" ) + ret_tmp = compiler.use_reg(:Label).set_builder(builder) + builder.build do + ret_tmp << exit_label + message[:return_address] << ret_tmp + add_code Risc.function_call( "__init__ issue call" , Parfait.object_space.get_main) + add_code exit_label + end + compiler.reset_regs + Builtin.exit_sequence(builder) + return compiler + end end end diff --git a/lib/mom/builtin/method_missing.rb b/lib/mom/builtin/method_missing.rb index f6f15678..de75f5bc 100644 --- a/lib/mom/builtin/method_missing.rb +++ b/lib/mom/builtin/method_missing.rb @@ -9,4 +9,12 @@ module Mom end end end + class MethodMissing < ::Mom::Instruction + def to_risc(compiler) + builder = compiler.builder(compiler.source) + builder.prepare_int_return # makes integer_tmp variable as return + Builtin.emit_syscall( builder , :exit ) + return compiler + end + end end diff --git a/test/rubyx/builtin/helper.rb b/test/rubyx/builtin/helper.rb index 26258082..1a8a1e43 100644 --- a/test/rubyx/builtin/helper.rb +++ b/test/rubyx/builtin/helper.rb @@ -1 +1,16 @@ require_relative "../helper" + +module RubyX + module BuiltinHelper + def setup + @mom = RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(source) + @mom.method_compilers.first + assert_equal Mom::MomCollection , @mom.class + assert_equal Mom::MethodCompiler , compiler.class + end + def compiler + @mom.method_compilers.last + end + + end +end diff --git a/test/rubyx/builtin/test_object_exit.rb b/test/rubyx/builtin/test_object_exit.rb new file mode 100644 index 00000000..af0bd5d1 --- /dev/null +++ b/test/rubyx/builtin/test_object_exit.rb @@ -0,0 +1,35 @@ +require_relative "helper" + +module RubyX + module Builtin + class TestObjectExit < MiniTest::Test + include BuiltinHelper + def source + <