starting to fix builtin
start at Object get_interna_word using the pattern to replace the whole risc method with a single mom instruction. Copying the original risc code into the instrucitons to_risc also adding some very basic tests
This commit is contained in:
@ -7,5 +7,15 @@ module Risc
|
||||
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,5 +1,6 @@
|
||||
require_relative "helper"
|
||||
|
||||
# TODO move these to interpreter dir
|
||||
module Risc
|
||||
module Builtin
|
||||
class IntCmp < BuiltinTest
|
||||
|
24
test/risc/builtin/test_object.rb
Normal file
24
test/risc/builtin/test_object.rb
Normal file
@ -0,0 +1,24 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
module Builtin
|
||||
class TestObjectFunction1 < 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
|
||||
end
|
||||
end
|
@ -5,18 +5,19 @@ module Risc
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@functions = Builtin.boot_functions
|
||||
end
|
||||
def test_has_boot_function
|
||||
assert Builtin.boot_functions
|
||||
assert @functions
|
||||
end
|
||||
def test_boot_function_type
|
||||
assert_equal Array, Builtin.boot_functions.class
|
||||
assert_equal Array, @functions.class
|
||||
end
|
||||
def test_boot_function_length
|
||||
assert_equal 23, Builtin.boot_functions.length
|
||||
assert_equal 2, @functions.length
|
||||
end
|
||||
def test_boot_function_first
|
||||
assert_equal MethodCompiler, Builtin.boot_functions.first.class
|
||||
assert_equal Mom::MethodCompiler, @functions.first.class
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user