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

View File

@ -0,0 +1,24 @@
## Pre - testing builtin
In the process of moving builtin from mom to parfait. Considering we started at risc, this
is progress.
Builtin methods should (will) use the Macro idea to actually become code and land in
the parfait code.
On the way there, we start by Testing and moving the old ones. Since we want to be able
to test some methods even after the move, without parsing/processing the whole of parfait
we have to have a method of "injecting" the single? methods.
## Mom level
There a re two test levels to every method. Mom being the first, where we basically just
see if the right Mom instruction has been generated
## Risc
Second level is to check the actual risc instructions that are generated.
Current tests test only the length, but there are some tests in interpreter dir that
test actual instructions. Should move those, as they are too detailed in a mains
(make the interpreter tests less brittle while at it.)

View File

@ -0,0 +1,17 @@
require_relative "../helper"
module RubyX
module MacroHelper
def setup
whole ="class Space;def main(arg);return;end;end;" + source
@mom = RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(whole)
@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,47 @@
require_relative "helper"
module RubyX
module Macro
class TestIntegerSame < MiniTest::Test
include MacroHelper
def op ; :== ; end
def len ; 25 ; end
def source
<<GET
class Integer
def #{op}(other)
X.comparison(:"#{op}")
end
end
GET
end
def test_mom_meth
assert_equal op , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_op
assert_equal Mom::Comparison , compiler.mom_instructions.next.class
assert_equal op , compiler.mom_instructions.next.operator
end
def test_risc
assert_equal len , compiler.to_risc.risc_instructions.length
end
end
class TestIntegerLg < TestIntegerSame
def op ; :> ; end
def len ; 26 ; end
end
class TestIntegerSm < TestIntegerSame
def op ; :< ; end
def len ; 26 ; end
end
class TestIntegerLe < TestIntegerSame
def op ; :>= ; end
end
class TestIntegerSe < TestIntegerSame
def op ; :<= ; end
end
end
end

View File

@ -0,0 +1,30 @@
require_relative "helper"
module RubyX
module Macro
class TestIntegerDiv10 < MiniTest::Test
include MacroHelper
def source
<<GET
class Integer
def div10
X.div10
end
end
GET
end
def test_mom_meth
assert_equal :div10 , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::Div10 , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 70 , compiler.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,30 @@
require_relative "helper"
module RubyX
module Macro
class TestIntegerDiv4 < MiniTest::Test
include MacroHelper
def source
<<GET
class Integer
def div4
X.div4
end
end
GET
end
def test_mom_meth
assert_equal :div4 , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::Div4 , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 41 , compiler.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,50 @@
require_relative "helper"
module RubyX
module Macro
class TestIntegerPlus < MiniTest::Test
include MacroHelper
def op ; :+ ; end
def source
<<GET
class Integer
def #{op}(other)
X.int_operator(:"#{op}")
end
end
GET
end
def test_mom_meth
assert_equal op , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_op
assert_equal Mom::IntOperator , compiler.mom_instructions.next.class
assert_equal op , compiler.mom_instructions.next.operator
end
def test_risc
assert_equal 42 , compiler.to_risc.risc_instructions.length
end
end
class TestIntegerMinus < TestIntegerPlus
def op ; :- ; end
end
class TestIntegerRS < TestIntegerPlus
def op ; :<< ; end
end
class TestIntegerRS < TestIntegerPlus
def op ; :>> ; end
end
class TestIntegerMul < TestIntegerPlus
def op ; :* ; end
end
class TestIntegerAnd < TestIntegerPlus
def op ; :& ; end
end
class TestIntegerOr < TestIntegerPlus
def op ; :| ; end
end
end
end

View File

@ -0,0 +1,30 @@
require_relative "helper"
module RubyX
module Macro
class TestObjectExit < MiniTest::Test
include MacroHelper
def source
<<GET
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

@ -0,0 +1,30 @@
require_relative "helper"
module RubyX
module Macro
class TestObjectGet < MiniTest::Test
include MacroHelper
def source
<<GET
class Object
def get_internal_word(at)
X.get_internal_word
end
end
GET
end
def test_mom_meth
assert_equal :get_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::GetInternalWord , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 18 , compiler.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,30 @@
require_relative "helper"
module RubyX
module Macro
class TestObjectInit < MiniTest::Test
include MacroHelper
def source
<<GET
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 Macro
class TestObjectMissing < MiniTest::Test
include MacroHelper
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 Macro
class TestObjectGet < MiniTest::Test
include MacroHelper
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

View File

@ -0,0 +1,30 @@
require_relative "helper"
module RubyX
module Macro
class TestWordGet < MiniTest::Test
include MacroHelper
def source
<<GET
class Word
def get_internal_byte(at)
X.get_internal_byte
end
end
GET
end
def test_mom_meth
assert_equal :get_internal_byte , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::GetInternalByte , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 41 , compiler.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,30 @@
require_relative "helper"
module RubyX
module Macro
class TestWordPutstring < MiniTest::Test
include MacroHelper
def source
<<GET
class Word
def putstring
X.putstring
end
end
GET
end
def test_mom_meth
assert_equal :putstring , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::Putstring , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 44 , compiler.to_risc.risc_instructions.length
end
end
end
end

View File

@ -0,0 +1,30 @@
require_relative "helper"
module RubyX
module Macro
class TestWordSet < MiniTest::Test
include MacroHelper
def source
<<GET
class Word
def set_internal_byte( at , value)
X.set_internal_byte
end
end
GET
end
def test_mom_meth
assert_equal :set_internal_byte , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::SetInternalByte , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 20 , compiler.to_risc.risc_instructions.length
end
end
end
end