macro tests for all object mom instructions

This commit is contained in:
Torsten Rüger 2019-09-11 18:43:20 +03:00
parent 2c4f040654
commit f264aec94a
9 changed files with 200 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,35 @@
require_relative "helper"
module RubyX
module Builtin
class TestObjectExit < MiniTest::Test
include BuiltinHelper
def source
<<GET
class Space
def main(arg)
return
end
end
class Object
def exit(at)
X.exit
end
end
GET
end
def test_mom_meth
assert_equal :exit , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::Exit , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 40 , compiler.to_risc.risc_instructions.length
end
end
end
end

View File

@ -1,25 +1,17 @@
require_relative "helper"
module RubyX
module Builtin
class TestObjectGet < MiniTest::Test
def setup
get = <<GET
include BuiltinHelper
def source
<<GET
class Object
def get_internal_word(at)
X.get_internal_word
end
end
GET
@mom = RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(get)
end
def compiler
@mom.method_compilers.first
end
def test_mom_col
assert_equal Mom::MomCollection , @mom.class
end
def test_mom_com
assert_equal Mom::MethodCompiler , @mom.method_compilers.first.class
end
def test_mom_meth
assert_equal :get_internal_word , compiler.callable.name

View File

@ -0,0 +1,35 @@
require_relative "helper"
module RubyX
module Builtin
class TestObjectInit < MiniTest::Test
include BuiltinHelper
def source
<<GET
class Space
def main(arg)
return
end
end
class Object
def __init(at)
X.__init
end
end
GET
end
def test_mom_meth
assert_equal :__init , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::Init , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 31 , compiler.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,35 @@
require_relative "helper"
module RubyX
module Builtin
class TestObjectMissing < MiniTest::Test
include BuiltinHelper
def source
<<GET
class Space
def main(arg)
return
end
end
class Object
def method_missing(at)
X.method_missing
end
end
GET
end
def test_mom_meth
assert_equal :method_missing , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::MethodMissing , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 42 , compiler.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,30 @@
require_relative "helper"
module RubyX
module Builtin
class TestObjectGet < MiniTest::Test
include BuiltinHelper
def source
<<GET
class Object
def set_internal_word(at , value)
X.set_internal_word
end
end
GET
end
def test_mom_meth
assert_equal :set_internal_word , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::SetInternalWord , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 19 , compiler.to_risc.risc_instructions.length
end
end
end
end