rework macro tests, or are they builtin
small fixes too
This commit is contained in:
parent
4bf23defc8
commit
c9d7539479
@ -22,6 +22,10 @@ module Mom
|
||||
def to_risc(compiler)
|
||||
compiler.add_code Risc::Branch.new(self , return_label.risc_label(compiler))
|
||||
end
|
||||
|
||||
def to_s
|
||||
"ReturnJump: #{return_label}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@ module Mom
|
||||
def to_risc(compiler)
|
||||
builder = compiler.builder(compiler.source)
|
||||
builder.prepare_int_return # makes integer_tmp variable as return
|
||||
Builtin.exit_sequence(builder)
|
||||
Macro.exit_sequence(builder)
|
||||
return compiler
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,10 @@
|
||||
module Mom
|
||||
class Macro < Instruction
|
||||
|
||||
def to_s
|
||||
self.class.name.split("::").last
|
||||
end
|
||||
|
||||
# emit the syscall with given name
|
||||
# there is a Syscall instruction, but the message has to be saved and restored
|
||||
def self.emit_syscall( builder , name )
|
||||
|
@ -3,7 +3,7 @@ module Mom
|
||||
def to_risc(compiler)
|
||||
builder = compiler.builder(compiler.source)
|
||||
builder.prepare_int_return # makes integer_tmp variable as return
|
||||
Builtin.emit_syscall( builder , :exit )
|
||||
Macro.emit_syscall( builder , :exit )
|
||||
return compiler
|
||||
end
|
||||
end
|
||||
|
@ -7,7 +7,7 @@ module Mom
|
||||
word! << message[:receiver]
|
||||
integer! << word[Parfait::Word.get_length_index]
|
||||
end
|
||||
Mom::Builtin.emit_syscall( builder , :putstring )
|
||||
Mom::Macro.emit_syscall( builder , :putstring )
|
||||
compiler
|
||||
end
|
||||
end
|
||||
|
@ -3,27 +3,15 @@ require_relative "../helper"
|
||||
module Mom
|
||||
module Builtin
|
||||
class BootTest < MiniTest::Test
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
MomCollection.compiler_for( Parfait.object_space.get_class.instance_type , Parfait::Space , :main)
|
||||
end
|
||||
def get_int_compiler(name)
|
||||
obj_type = Parfait.object_space.get_type_by_class_name(:Integer)
|
||||
Builtin.compiler_for( obj_type , Integer , name)
|
||||
end
|
||||
def get_operator_compiler(name)
|
||||
obj_type = Parfait.object_space.get_type_by_class_name(:Integer)
|
||||
Builtin.operator_compiler( obj_type , name)
|
||||
include Preloader
|
||||
|
||||
def get_compiler(clazz , name)
|
||||
compiler = RubyX::RubyXCompiler.new(RubyX.default_test_options)
|
||||
coll = compiler.ruby_to_mom( get_preload("Space.main;#{clazz}.#{name}") )
|
||||
@method = coll.method_compilers.last
|
||||
@method
|
||||
end
|
||||
|
||||
def get_object_compiler(name)
|
||||
obj_type = Parfait.object_space.get_type_by_class_name(:Object)
|
||||
Builtin.compiler_for( obj_type , Object , name)
|
||||
end
|
||||
def get_word_compiler(name)
|
||||
obj_type = Parfait.object_space.get_type_by_class_name(:Word)
|
||||
Builtin.compiler_for( obj_type , Word , name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,26 +4,32 @@ module Mom
|
||||
module Builtin
|
||||
class TestIntComp1Risc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_int_compiler(:<)
|
||||
@method = get_compiler("Integer",:lt)
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal :< , @method.callable.name
|
||||
assert_equal 7 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 23 , @method.to_risc.risc_instructions.length
|
||||
assert_equal 26 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntComp2Risc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_int_compiler(:>=)
|
||||
@method = get_compiler("Integer",:gt)
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal :> , @method.callable.name
|
||||
assert_equal 7 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 22 , @method.to_risc.risc_instructions.length
|
||||
assert_equal 26 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,14 +4,17 @@ module Mom
|
||||
module Builtin
|
||||
class TestIntDiv10Risc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_int_compiler(:div10)
|
||||
@method = get_compiler("Integer",:div10)
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal :div10 , @method.callable.name
|
||||
assert_equal 7 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 67 , @method.to_risc.risc_instructions.length
|
||||
assert_equal 70 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,15 +4,18 @@ module Mom
|
||||
module Builtin
|
||||
class TestIntDiv4Risc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_int_compiler(:div4)
|
||||
@method = get_compiler("Integer",:div4)
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal :div4 , @method.callable.name
|
||||
assert_equal 7 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
assert_equal :div4 , @method.callable.name
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 38 , @method.to_risc.risc_instructions.length
|
||||
assert_equal 41 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,13 +5,17 @@ module Mom
|
||||
class TestObjectExitRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_object_compiler(:exit)
|
||||
@method = get_compiler("Object",:exit)
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal :exit , @method.callable.name
|
||||
assert_equal 7 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 37 , @method.to_risc.risc_instructions.length
|
||||
assert_equal 40 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,13 +5,17 @@ module Mom
|
||||
class TestWordGetRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_word_compiler(:get_internal_byte)
|
||||
@method = get_compiler("Word",:get)
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal :get_internal_byte , @method.callable.name
|
||||
assert_equal 7 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 38 , @method.to_risc.risc_instructions.length
|
||||
assert_equal 41 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,13 +5,17 @@ module Mom
|
||||
class TestWordGetRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_object_compiler(:get_internal_word)
|
||||
@method = get_compiler("Object",:get)
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal :get_internal_word , @method.callable.name
|
||||
assert_equal 7 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 15 , @method.to_risc.risc_instructions.length
|
||||
assert_equal 18 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,13 +5,17 @@ module Mom
|
||||
class TestObjectInitRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_object_compiler(:__init__)
|
||||
@method = get_compiler("Object",:init)
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal :__init__ , @method.callable.name
|
||||
assert_equal 7 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 19 , @method.to_risc.risc_instructions.length
|
||||
assert_equal 31 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,71 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestIntDiv4 < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_int_compiler(:div4)
|
||||
end
|
||||
def test_has_get_internal
|
||||
assert_equal Mom::MethodCompiler , @method.class
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntDiv10 < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_int_compiler(:div10)
|
||||
end
|
||||
def test_has_get_internal
|
||||
assert_equal Mom::MethodCompiler , @method.class
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntComp1 < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_int_compiler(:<)
|
||||
end
|
||||
def test_has_get_internal
|
||||
assert_equal Mom::MethodCompiler , @method.class
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntComp2 < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_int_compiler(:>=)
|
||||
end
|
||||
def test_has_get_internal
|
||||
assert_equal Mom::MethodCompiler , @method.class
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntOperators < BootTest
|
||||
def setup
|
||||
super
|
||||
end
|
||||
def each_method &block
|
||||
Risc.operators.each do |name|
|
||||
method = get_operator_compiler(name)
|
||||
block.yield(method)
|
||||
end
|
||||
end
|
||||
def test_has_get_internal
|
||||
each_method do |method|
|
||||
assert_equal Mom::MethodCompiler , method.class
|
||||
assert_equal 5 , method.mom_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -4,14 +4,17 @@ module Mom
|
||||
module Builtin
|
||||
class TestObjectMissingRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_object_compiler(:_method_missing)
|
||||
@method = get_compiler("Object",:missing)
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal :method_missing , @method.callable.name
|
||||
assert_equal 7 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 39 , @method.to_risc.risc_instructions.length
|
||||
assert_equal 42 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,69 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestObjectGet < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_object_compiler(:get_internal_word)
|
||||
end
|
||||
def test_has_get_internal
|
||||
assert_equal Mom::MethodCompiler , @method.class
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_return
|
||||
assert_equal ReturnSequence , @method.mom_instructions.next(3).class
|
||||
end
|
||||
end
|
||||
class TestObjectSet < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_object_compiler(:set_internal_word)
|
||||
end
|
||||
def test_has_get_internal
|
||||
assert_equal Mom::MethodCompiler , @method.class
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
end
|
||||
class TestObjectMissing < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_object_compiler(:_method_missing)
|
||||
end
|
||||
def test_has_get_internal
|
||||
assert_equal Mom::MethodCompiler , @method.class
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
end
|
||||
class TestObjectExit < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_object_compiler(:exit)
|
||||
end
|
||||
def test_has_get_internal
|
||||
assert_equal Mom::MethodCompiler , @method.class
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
end
|
||||
class TestObjectInit < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_object_compiler(:__init__)
|
||||
end
|
||||
def test_has_get_internal
|
||||
assert_equal Mom::MethodCompiler , @method.class
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal 2 , @method.mom_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -2,26 +2,35 @@ require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestIntOperatorsRisc < BootTest
|
||||
class TestIntOpPl < BootTest
|
||||
def setup
|
||||
super
|
||||
end
|
||||
def each_method &block
|
||||
Risc.operators.each do |name|
|
||||
method = get_operator_compiler(name)
|
||||
block.yield(method)
|
||||
@method = get_compiler("Integer",:and)
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal :& , @method.callable.name
|
||||
assert_equal 7 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
each_method do |method|
|
||||
assert_equal Risc::MethodCompiler , method.to_risc.class
|
||||
end
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
each_method do |method|
|
||||
assert_equal 39 , method.to_risc.risc_instructions.length
|
||||
assert_equal 42 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntOpMM < BootTest
|
||||
def setup
|
||||
@method = get_compiler("Integer",:or)
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal :| , @method.callable.name
|
||||
assert_equal 7 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 42 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,14 +4,17 @@ module Mom
|
||||
module Builtin
|
||||
class TestWordPutRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_word_compiler(:putstring)
|
||||
@method = get_compiler("Word",:put)
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal :putstring , @method.callable.name
|
||||
assert_equal 7 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 41 , @method.to_risc.risc_instructions.length
|
||||
assert_equal 44 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,11 @@ module Mom
|
||||
class TestWordSetRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_word_compiler(:set_internal_byte)
|
||||
@method = get_compiler("Word",:set)
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal :set_internal_byte , @method.callable.name
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
|
@ -4,14 +4,17 @@ module Mom
|
||||
module Builtin
|
||||
class TestWordSetRisc < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_object_compiler(:set_internal_word)
|
||||
@method = get_compiler("Word",:set)
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal :set_internal_byte , @method.callable.name
|
||||
assert_equal 7 , @method.mom_instructions.length
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 16 , @method.to_risc.risc_instructions.length
|
||||
assert_equal 20 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,42 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestWordPut < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_word_compiler(:putstring)
|
||||
end
|
||||
def test_has_get_internal
|
||||
assert_equal Mom::MethodCompiler , @method.class
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
end
|
||||
class TestWordGet < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_word_compiler(:get_internal_byte)
|
||||
end
|
||||
def test_has_get_internal
|
||||
assert_equal Mom::MethodCompiler , @method.class
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
end
|
||||
class TestWordSet < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_word_compiler(:set_internal_byte)
|
||||
end
|
||||
def test_has_get_internal
|
||||
assert_equal Mom::MethodCompiler , @method.class
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user