renaming mom builtin to macro

This commit is contained in:
2019-09-11 20:17:43 +03:00
parent 5ea91df4c1
commit 616dd3487c
55 changed files with 49 additions and 47 deletions

10
test/mom/macro/README.md Normal file
View File

@ -0,0 +1,10 @@
# Builtin Testing
At the Module level (word/object/integer) mostly testing that
- functions exist
- they compile
- basic length tests (no "contents")
Minimal tests for risc compilation, and again length only (should be array too)
Functionality is tested by interpreter over in interpreter dir

29
test/mom/macro/helper.rb Normal file
View File

@ -0,0 +1,29 @@
require_relative "../helper"
module Mom
module Builtin
class BootTest < MiniTest::Test
def setup
Parfait.boot!(Parfait.default_test_options)
Builtin.compiler_for( Parfait.object_space.get_class.instance_type , 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)
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

View File

@ -0,0 +1,30 @@
require_relative "helper"
module Mom
module Builtin
class TestIntComp1Risc < BootTest
def setup
super
@method = get_int_compiler(:<)
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
end
end
class TestIntComp2Risc < BootTest
def setup
super
@method = get_int_compiler(:>=)
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
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestIntDiv10Risc < BootTest
def setup
super
@method = get_int_compiler(:div10)
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
end
end
end
end

View File

@ -0,0 +1,19 @@
require_relative "helper"
module Mom
module Builtin
class TestIntDiv4Risc < BootTest
def setup
super
@method = get_int_compiler(:div4)
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
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestObjectExitRisc < BootTest
def setup
super
@method = get_object_compiler(:exit)
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
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestWordGetRisc < BootTest
def setup
super
@method = get_word_compiler(:get_internal_byte)
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
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestWordGetRisc < BootTest
def setup
super
@method = get_object_compiler(:get_internal_word)
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
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestObjectInitRisc < BootTest
def setup
super
@method = get_object_compiler(:__init__)
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
end
end
end
end

View File

@ -0,0 +1,71 @@
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

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestObjectMissingRisc < BootTest
def setup
super
@method = get_object_compiler(:_method_missing)
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
end
end
end
end

View File

@ -0,0 +1,69 @@
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

View File

@ -0,0 +1,27 @@
require_relative "helper"
module Mom
module Builtin
class TestIntOperatorsRisc < 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_compile
each_method do |method|
assert_equal Risc::MethodCompiler , method.to_risc.class
end
end
def test_risc_length
each_method do |method|
assert_equal 39 , method.to_risc.risc_instructions.length
end
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestWordPutRisc < BootTest
def setup
super
@method = get_word_compiler(:putstring)
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
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestWordSetRisc < BootTest
def setup
super
@method = get_word_compiler(:set_internal_byte)
end
def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class
end
def test_risc_length
assert_equal 17 , @method.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,18 @@
require_relative "helper"
module Mom
module Builtin
class TestWordSetRisc < BootTest
def setup
super
@method = get_object_compiler(:set_internal_word)
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
end
end
end
end

View File

@ -0,0 +1,42 @@
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