Move builtin wholesale to Mom
Since Builtin generates risc, just like mom instructions, it was a design mistake to put builtin into risc in the first place. Now that borders are coming more into focus, it make much more sense to have the builtin in mom. In fact the instructions should be moved out and a seperate invocation mechanism used , so functions can be parsed, not generated (wip)
This commit is contained in:
@ -1,21 +0,0 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
module Builtin
|
||||
class BuiltinTest < MiniTest::Test
|
||||
include Ticker
|
||||
def setup
|
||||
end
|
||||
end
|
||||
class BootTest < MiniTest::Test
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@functions = Builtin.boot_functions
|
||||
end
|
||||
def get_compiler( name )
|
||||
@functions.each.find{|meth|
|
||||
meth.callable.name == name}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,105 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
module Builtin
|
||||
class TestIntDiv4 < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_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
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 47 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntDiv10 < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_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
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 76 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntComp1 < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_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
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 28 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntComp2 < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_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
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 27 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestIntOperators < BootTest
|
||||
def setup
|
||||
super
|
||||
end
|
||||
def each_method &block
|
||||
Risc.operators.each do |name|
|
||||
method = get_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
|
||||
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 49 , method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,96 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
module Builtin
|
||||
class TestObjectFunctionGet < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_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_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 20 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestObjectFunctionSet < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_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
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 21 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestObjectFunctionMissing < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_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
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 48 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestObjectFunctionExit < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_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
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 46 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestObjectFunctionInit < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_compiler(:__init__)
|
||||
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_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 48 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,60 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
module Builtin
|
||||
class TestWordPut < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_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
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 50 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestWordGet < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_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
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
def test_risc_length
|
||||
assert_equal 48 , @method.to_risc.risc_instructions.length
|
||||
end
|
||||
end
|
||||
class TestWordSet < BootTest
|
||||
def setup
|
||||
super
|
||||
@method = get_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
|
||||
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
|
@ -1,9 +1,12 @@
|
||||
require_relative "helper"
|
||||
|
||||
# TODO move these to interpreter dir
|
||||
module Risc
|
||||
module Mom
|
||||
module Builtin
|
||||
class IntCmp < BuiltinTest
|
||||
include Ticker
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_smaller_true
|
||||
run_main_return "4 < 5"
|
@ -1,8 +1,11 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
module Mom
|
||||
module Builtin
|
||||
class IntMath < BuiltinTest
|
||||
include Ticker
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_add
|
||||
run_main_return "5 + 5"
|
@ -1,23 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
class TestBuiltinFunction < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@functions = Builtin.boot_functions
|
||||
end
|
||||
def test_has_boot_function
|
||||
assert @functions
|
||||
end
|
||||
def test_boot_function_type
|
||||
assert_equal Array, @functions.class
|
||||
end
|
||||
def test_boot_function_length
|
||||
assert_equal 22, @functions.length
|
||||
end
|
||||
def test_boot_function_first
|
||||
assert_equal Mom::MethodCompiler, @functions.first.class
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user