From db55ec3fd6340bd0a18c13af68c87c5284a08663 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 7 Apr 2018 00:35:54 +0300 Subject: [PATCH] slightly changing built return logic very tempted to add immediately, but bigger change --- lib/mom/instruction/message_setup.rb | 2 +- lib/risc/builder.rb | 9 ++++++++- lib/risc/builtin/object.rb | 8 ++++---- test/risc/test_builder.rb | 19 ++++++------------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/mom/instruction/message_setup.rb b/lib/mom/instruction/message_setup.rb index 562312dd..f80a7582 100644 --- a/lib/mom/instruction/message_setup.rb +++ b/lib/mom/instruction/message_setup.rb @@ -36,7 +36,7 @@ module Mom def build_with(builder) from = method_source risc = builder.build { typed_method << from } - build_message_data(builder) + risc << build_message_data(builder) builder.compiler.reset_regs return risc end diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index ff94c9bd..3504eddf 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -25,9 +25,16 @@ module Risc end def build(&block) + @built = nil instance_eval(&block) - return built + return @built end + + def build_and_add(&block) + risc = build(&block) + @compiler.add_code(risc) + end + def add_instruction(ins) if(@built) @built << ins diff --git a/lib/risc/builtin/object.rb b/lib/risc/builtin/object.rb index e87b9381..9c6a4931 100644 --- a/lib/risc/builtin/object.rb +++ b/lib/risc/builtin/object.rb @@ -47,17 +47,17 @@ module Risc compiler = Risc::MethodCompiler.create_method(:Object,:__init__ , Parfait::NamedList.type_for({}) , Parfait::NamedList.type_for({})) builder = Risc::Builder.new(compiler) - risc = builder.build do + builder.build_and_add do space << Parfait.object_space message << space[:first_message] next_message << message[:next_message] space[:first_message] << next_message end - compiler.add_code(risc) - Mom::MessageSetup.new(Parfait.object_space.get_main).build_with( builder ) + risc = Mom::MessageSetup.new(Parfait.object_space.get_main).build_with( builder ) + compiler.add_code(risc) - builder.build do + builder.build_and_add do message << message[:next_message] message[:receiver] << space end diff --git a/test/risc/test_builder.rb b/test/risc/test_builder.rb index 5b7e55a9..838ffdea 100644 --- a/test/risc/test_builder.rb +++ b/test/risc/test_builder.rb @@ -9,6 +9,12 @@ module Risc compiler = Risc::MethodCompiler.new( init ) @builder = Builder.new(compiler) end + def test_has_build + assert @builder.respond_to?(:build) + end + def test_has_attribute + assert_nil @builder.built + end def test_alloc_space reg = @builder.space assert_equal RiscValue , reg.class @@ -60,17 +66,4 @@ module Risc assert_equal :r0 , built.array.symbol end end - - class TestBuilderNoBoot < MiniTest::Test - - def setup - @builder = Builder.new(nil) - end - def test_has_build - assert_nil @builder.build{ } - end - def test_has_attribute - assert_nil @builder.built - end - end end