slightly changing built return logic

very tempted to add immediately, but bigger change
This commit is contained in:
Torsten Ruger 2018-04-07 00:35:54 +03:00
parent dd0d162ebf
commit db55ec3fd6
4 changed files with 19 additions and 19 deletions

View File

@ -36,7 +36,7 @@ module Mom
def build_with(builder) def build_with(builder)
from = method_source from = method_source
risc = builder.build { typed_method << from } risc = builder.build { typed_method << from }
build_message_data(builder) risc << build_message_data(builder)
builder.compiler.reset_regs builder.compiler.reset_regs
return risc return risc
end end

View File

@ -25,9 +25,16 @@ module Risc
end end
def build(&block) def build(&block)
@built = nil
instance_eval(&block) instance_eval(&block)
return built return @built
end end
def build_and_add(&block)
risc = build(&block)
@compiler.add_code(risc)
end
def add_instruction(ins) def add_instruction(ins)
if(@built) if(@built)
@built << ins @built << ins

View File

@ -47,17 +47,17 @@ module Risc
compiler = Risc::MethodCompiler.create_method(:Object,:__init__ , compiler = Risc::MethodCompiler.create_method(:Object,:__init__ ,
Parfait::NamedList.type_for({}) , Parfait::NamedList.type_for({})) Parfait::NamedList.type_for({}) , Parfait::NamedList.type_for({}))
builder = Risc::Builder.new(compiler) builder = Risc::Builder.new(compiler)
risc = builder.build do builder.build_and_add do
space << Parfait.object_space space << Parfait.object_space
message << space[:first_message] message << space[:first_message]
next_message << message[:next_message] next_message << message[:next_message]
space[:first_message] << next_message space[:first_message] << next_message
end end
risc = Mom::MessageSetup.new(Parfait.object_space.get_main).build_with( builder )
compiler.add_code(risc) compiler.add_code(risc)
Mom::MessageSetup.new(Parfait.object_space.get_main).build_with( builder ) builder.build_and_add do
builder.build do
message << message[:next_message] message << message[:next_message]
message[:receiver] << space message[:receiver] << space
end end

View File

@ -9,6 +9,12 @@ module Risc
compiler = Risc::MethodCompiler.new( init ) compiler = Risc::MethodCompiler.new( init )
@builder = Builder.new(compiler) @builder = Builder.new(compiler)
end end
def test_has_build
assert @builder.respond_to?(:build)
end
def test_has_attribute
assert_nil @builder.built
end
def test_alloc_space def test_alloc_space
reg = @builder.space reg = @builder.space
assert_equal RiscValue , reg.class assert_equal RiscValue , reg.class
@ -60,17 +66,4 @@ module Risc
assert_equal :r0 , built.array.symbol assert_equal :r0 , built.array.symbol
end end
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 end