Make to_mom a 2 stage process

First baby baby step on the way to passes
Create all parfait objects in first pass, so methods exist to be resolved in second path
This commit is contained in:
2019-09-24 15:44:33 +03:00
parent 3510637d21
commit dd810cfc49
15 changed files with 159 additions and 85 deletions

View File

@ -18,11 +18,11 @@ module Vool
assert_equal MethodExpression , method.class
end
def test_class
assert_equal Parfait::Class , @clazz.create_class_object.class
assert_equal Parfait::Class , @clazz.to_parfait.class
end
def test_method
clazz = @clazz.create_class_object
assert_equal Parfait::VoolMethod , method.make_method(clazz).class
clazz = @clazz.to_parfait
assert_equal Parfait::VoolMethod , method.to_parfait(clazz).class
end
end
end

View File

@ -9,6 +9,7 @@ module Risc
def in_test_vool(str)
vool = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_vool(in_Test(str))
vool.to_parfait
vool.to_mom(nil)
vool
end

View File

@ -5,7 +5,7 @@ module Preloader
preload.split(";").collect do |loads|
raise "no preload #{loads}" unless Vool::Builtin.builtin[loads]
clazz , meth = loads.split(".")
"class #{clazz}; #{Vool::Builtin.builtin[loads]};end;"
"class #{clazz} #{Vool::Builtin.derive(clazz)}; #{Vool::Builtin.builtin[loads]};end;"
end.join
end
def preload

View File

@ -21,7 +21,7 @@ module Vool
end
def setup
source = "class Integer;def +(other);X.int_operator(:+);end;end;" + class_main
source = "class Integer < Data4;def +(other);X.int_operator(:+);end;end;" + class_main
ret = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(source)
@ins = ret.compilers.find{|c|c.callable.name==:main}.mom_instructions.next
end

View File

@ -11,6 +11,11 @@ module Vool
def as_ruby
@ruby = Ruby::RubyCompiler.compile(@code)
end
def as_mom
vool = as_ruby.to_vool
vool.to_parfait
vool.to_mom(nil)
end
def test_boot
assert_equal String , @code.class
assert @code.include?("Integer")
@ -32,12 +37,12 @@ module Vool
assert_equal Vool::MacroExpression , vool.body.first.body.return_value.class
end
def test_mom_basic
mom = as_ruby.to_vool.to_mom(nil)
mom = as_mom
assert_equal Mom::MomCollection , mom.class
assert_equal Mom::MethodCompiler , mom.method_compilers.first.class
end
def test_mom_instructions
mom_compiler = as_ruby.to_vool.to_mom(nil).method_compilers.first
mom_compiler = as_mom.method_compilers.first
assert_equal Mom::Label , mom_compiler.mom_instructions.class
assert_equal Mom::IntOperator , mom_compiler.mom_instructions.next.class
assert_equal Mom::SlotLoad , mom_compiler.mom_instructions.next(2).class

View File

@ -2,7 +2,7 @@
require_relative "helper"
module Vool
class TestClassStatement < MiniTest::Test
class TestClassStatement #< MiniTest::Test
include ScopeHelper
def setup
Parfait.boot!(Parfait.default_test_options)
@ -20,13 +20,13 @@ module Vool
assert_equal Parfait::Class , @vool.create_class_object.class
end
def test_create_class
assert_equal :Test , @vool.create_class_object.name
assert_equal :Test , @vool.to_parfait.name
end
def test_class_instance
assert_equal :a , @vool.create_class_object.instance_type.names[1]
assert_equal :a , @vool.to_parfait.instance_type.names[1]
end
end
class TestClassStatementTypeCreation < MiniTest::Test
class TestClassStatementTypeCreation #< MiniTest::Test
include ScopeHelper
def setup
Parfait.boot!(Parfait.default_test_options)
@ -35,7 +35,7 @@ module Vool
ruby_tree = Ruby::RubyCompiler.compile( as_test_main(input) )
vool = ruby_tree.to_vool
assert_equal ClassExpression , vool.class
clazz = vool.create_class_object
clazz = vool.to_parfait
assert_equal Parfait::Class , clazz.class
assert_equal :a , clazz.instance_type.names[1]
end
@ -64,34 +64,17 @@ module Vool
check_type_for("return @a.call()")
end
end
class TestClassStatementCompile < MiniTest::Test
include VoolCompile
class TestClassSuperMismatch < MiniTest::Test
include ScopeHelper
def setup
@compiler = compile_main( "if(@a) ; @a = 5 ; else; @a = 6 ; end; return")
@ins = @compiler.mom_instructions
Parfait.boot!(Parfait.default_test_options)
end
def test_label
assert_equal Label , @ins.class , @ins
assert_equal "Space_Type.main" , @ins.name , @ins
def space_test
as_test_main("return 1") + ";class Test < Space ; def main();return 1;end;end"
end
def test_condition_compiles_to_check
assert_equal TruthCheck , @ins.next.class , @ins
end
def test_condition_is_slot
assert_equal SlotDefinition , @ins.next.condition.class , @ins
end
def test_label_after_check
assert_equal Label , @ins.next(2).class , @ins
end
def test_label_last
assert_equal Label , @ins.last.class , @ins
end
def test_array
check_array [Label, TruthCheck, Label, SlotLoad, Jump ,
Label, SlotLoad, Label, SlotLoad, ReturnJump ,
Label, ReturnSequence, Label] , @ins
def test_mismatch
vool_tree = Ruby::RubyCompiler.compile( space_test).to_vool
assert_raises {vool_tree.to_parfait}
end
end
end

View File

@ -0,0 +1,35 @@
require_relative "helper"
module Vool
class TestClassStatementCompile < MiniTest::Test
include VoolCompile
def setup
@compiler = compile_main( "if(@a) ; @a = 5 ; else; @a = 6 ; end; return")
@ins = @compiler.mom_instructions
end
def test_label
assert_equal Label , @ins.class , @ins
assert_equal "Space_Type.main" , @ins.name , @ins
end
def test_condition_compiles_to_check
assert_equal TruthCheck , @ins.next.class , @ins
end
def test_condition_is_slot
assert_equal SlotDefinition , @ins.next.condition.class , @ins
end
def test_label_after_check
assert_equal Label , @ins.next(2).class , @ins
end
def test_label_last
assert_equal Label , @ins.last.class , @ins
end
def test_array
check_array [Label, TruthCheck, Label, SlotLoad, Jump ,
Label, SlotLoad, Label, SlotLoad, ReturnJump ,
Label, ReturnSequence, Label] , @ins
end
end
end

View File

@ -17,12 +17,13 @@ module Vool
assert_equal Statements , @clazz.body.class
assert_equal MethodExpression , method.class
end
def test_class
assert_equal Parfait::Class , @clazz.create_class_object.class
def test_fail
assert_raises{ method.to_parfait }
end
def test_method
clazz = @clazz.create_class_object
assert_equal Parfait::VoolMethod , method.make_method(clazz).class
clazz = @clazz.to_parfait
assert_equal Parfait::Class , clazz.class
assert_equal Parfait::VoolMethod , method.to_parfait(clazz).class
end
end