fix many tests with preloading

preloading, something akin to builtin, loads some very small predefined (macro) methods for the tests to work (ie call)
This commit is contained in:
2019-09-12 22:27:10 +03:00
parent e33b9f565d
commit 4bf23defc8
42 changed files with 98 additions and 126 deletions

View File

@ -1,6 +1,14 @@
module ScopeHelper
def in_Test(statements)
"class Test ; #{statements} ; end"
end
def as_test_main(statements)
in_Test("def main(arg) ; #{statements}; end")
end
def in_Space(statements)
"class Space ; #{statements} ; end"
end
@ -17,18 +25,19 @@ end
module VoolCompile
include ScopeHelper
include Mom
include Preloader
def compile_main( input )
input = as_main( input )
def compile_main( input , preload = nil)
input = get_preload(preload) + as_main( input )
collection = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(input)
assert collection.is_a?(Mom::MomCollection) , collection.class.name
compiler = collection.compilers.first
compiler = collection.compilers.find{|comp| comp.callable.name == :main}
assert compiler.is_a?(Mom::MethodCompiler)
assert_equal Mom::MethodCompiler , compiler.class
compiler
end
def compile_main_block( block_input , method_input = "main_local = 5")
source = as_main("#{method_input} ; self.main{|val| #{block_input}}")
def compile_main_block( block_input , method_input = "main_local = 5" , preload = nil)
source = get_preload(preload) + as_main("#{method_input} ; self.main{|val| #{block_input}}")
mom_col = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom( source )
compiler = mom_col.method_compilers.find{|c| c.get_method.name.to_s.start_with?("main") }
block = compiler.block_compilers.first

View File

@ -1,16 +1,19 @@
module Parfait
module MethodHelper
def make_method(name = :meth , clazz = :Object)
@obj = Parfait.object_space.get_type_by_class_name(clazz)
@args = Parfait::Type.for_hash( @obj.object_class , { bar: :Integer , foo: :Type})
@frame = Parfait::Type.for_hash( @obj.object_class , { local_bar: :Integer , local_foo: :Type})
@method = Parfait::CallableMethod.new( name , @obj , @args , @frame)
end
end
class ParfaitTest < MiniTest::Test
include MethodHelper
def setup
Parfait.boot!(Parfait.default_test_options)
@space = Parfait.object_space
end
def make_method
@obj = Parfait.object_space.get_type_by_class_name(:Object)
@args = Parfait::Type.for_hash( @obj.object_class , { bar: :Integer , foo: :Type})
@frame = Parfait::Type.for_hash( @obj.object_class , { local_bar: :Integer , local_foo: :Type})
@method = Parfait::CallableMethod.new( :meth , @obj , @args , @frame)
end
end
class BigParfaitTest < ParfaitTest
def setup

20
test/support/preloader.rb Normal file
View File

@ -0,0 +1,20 @@
module Preloader
def builtin
{
"Integer.div4" => "def div4; X.div4;end",
"Integer.ge" => "def >; X.comparison(:>);end",
"Object.get" => "def get_internal_word(at); X.get_internal_word;end",
}
end
def get_preload(preload)
return "" unless preload
preload.split(";").collect do |loads|
raise "no preload #{loads}" unless builtin[loads]
clazz , meth = loads.split(".")
"class #{clazz}; #{builtin[loads]};end;"
end.join
end
def preload
get_preload(@preload)
end
end