2017-04-10 15:12:15 +02:00
|
|
|
|
2018-06-29 22:04:50 +02:00
|
|
|
module ScopeHelper
|
2017-04-10 15:12:15 +02:00
|
|
|
|
|
|
|
def in_Test(statements)
|
|
|
|
"class Test ; #{statements} ; end"
|
|
|
|
end
|
|
|
|
|
|
|
|
def in_Space(statements)
|
|
|
|
"class Space ; #{statements} ; end"
|
|
|
|
end
|
|
|
|
|
|
|
|
def as_main(statements)
|
2018-07-04 07:28:29 +02:00
|
|
|
in_Space("def main(arg) ; #{statements}; end")
|
2017-04-10 15:12:15 +02:00
|
|
|
end
|
2017-04-13 13:14:43 +02:00
|
|
|
|
|
|
|
def as_test_main( statements )
|
2017-09-07 07:16:37 +02:00
|
|
|
in_Test("def main(arg) ; #{statements}; end")
|
|
|
|
end
|
|
|
|
end
|
2019-08-06 17:33:27 +02:00
|
|
|
module VoolCompile
|
|
|
|
include ScopeHelper
|
2019-08-07 11:06:06 +02:00
|
|
|
include Mom
|
2019-08-06 17:33:27 +02:00
|
|
|
|
2019-08-07 14:08:45 +02:00
|
|
|
def compile_vool_method(input)
|
|
|
|
statements = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_vool(as_main(input))
|
|
|
|
assert statements.is_a?(Vool::Statement) , statements.class
|
|
|
|
statements
|
|
|
|
end
|
2019-08-06 17:33:27 +02:00
|
|
|
def compile_method(input)
|
2019-08-07 11:06:06 +02:00
|
|
|
collection = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(input)
|
|
|
|
assert collection.is_a?(Mom::MomCollection)
|
|
|
|
compiler = collection.compilers.first
|
|
|
|
assert compiler.is_a?(Mom::MethodCompiler)
|
|
|
|
compiler
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
|
|
|
def compile_first_method( input )
|
|
|
|
ret = compile_method( as_test_main( input ))
|
2019-08-07 11:06:06 +02:00
|
|
|
assert_equal Mom::MethodCompiler , ret.class
|
|
|
|
ret
|
|
|
|
end
|
2019-08-07 14:08:45 +02:00
|
|
|
def compile_first_block( block_input , method_input = "main_local = 5")
|
|
|
|
source = "#{method_input} ; self.main{|val| #{block_input}}"
|
|
|
|
vool = Ruby::RubyCompiler.compile( as_test_main(source) ).to_vool
|
|
|
|
mom_c = vool.to_mom(nil)
|
|
|
|
compiler = mom_c.method_compilers.find{|c| c.get_method.name == :main and c.get_method.self_type.object_class.name == :Test}
|
|
|
|
block = nil
|
|
|
|
vool.each {|b| block = b if b.is_a?(Vool::BlockStatement)}
|
|
|
|
assert block
|
|
|
|
block_c = compiler.block_compilers.first
|
|
|
|
assert block_c
|
|
|
|
block.body.to_mom(block_c)
|
|
|
|
end
|
2019-08-07 11:06:06 +02:00
|
|
|
def check_array( should , is )
|
|
|
|
index = 0
|
|
|
|
test = is
|
|
|
|
while(test)
|
|
|
|
# if we assert here, we get output pointing here. Without stack, not useful
|
|
|
|
raise "Wrong class for #{index+1}, #{dump(is)}" if should[index] != test.class
|
|
|
|
index += 1
|
|
|
|
test = test.next
|
|
|
|
end
|
|
|
|
assert 1 #just to get an assertion in the output.
|
|
|
|
end
|
|
|
|
def dump(is)
|
|
|
|
res =[]
|
|
|
|
while(is)
|
|
|
|
res << is.class.name.split("::").last
|
|
|
|
is = is.next
|
|
|
|
end
|
|
|
|
ret = ""
|
|
|
|
res.to_s.split(",").each_slice(5).each do |line|
|
|
|
|
ret += " " + line.join(",") + " ,\n"
|
|
|
|
end
|
|
|
|
ret.gsub('"' , '')
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
2019-08-07 11:06:06 +02:00
|
|
|
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
2017-09-07 07:16:37 +02:00
|
|
|
|
|
|
|
module MomCompile
|
2018-06-29 22:04:50 +02:00
|
|
|
include ScopeHelper
|
2017-09-07 07:16:37 +02:00
|
|
|
|
2018-07-02 14:52:51 +02:00
|
|
|
def compile_method(input)
|
2019-02-08 22:03:23 +01:00
|
|
|
statements = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_vool(input)
|
2018-07-02 14:52:51 +02:00
|
|
|
assert statements.is_a?(Vool::ClassStatement)
|
|
|
|
ret = statements.to_mom(nil)
|
2018-03-16 08:03:11 +01:00
|
|
|
assert_equal Parfait::Class , statements.clazz.class , statements
|
|
|
|
@method = statements.clazz.get_method(:main)
|
2017-12-10 19:47:26 +01:00
|
|
|
assert_equal Parfait::VoolMethod , @method.class
|
2018-07-02 14:52:51 +02:00
|
|
|
ret
|
2018-06-30 18:20:17 +02:00
|
|
|
end
|
|
|
|
def compile_first_method( input )
|
2018-07-02 14:52:51 +02:00
|
|
|
ret = compile_method( as_test_main( input ))
|
|
|
|
assert_equal Mom::MomCompiler , ret.class
|
2018-07-09 18:32:17 +02:00
|
|
|
compiler = ret.method_compilers.find{|c| c.get_method.name == :main and c.get_method.self_type.object_class.name == :Test}
|
2018-07-02 14:52:51 +02:00
|
|
|
assert_equal Risc::MethodCompiler , compiler.class
|
2018-07-05 13:02:38 +02:00
|
|
|
@method.source.to_mom( compiler )
|
2018-07-01 10:59:07 +02:00
|
|
|
end
|
2018-07-18 09:13:19 +02:00
|
|
|
def compile_first_block( block_input , method_input = "main_local = 5")
|
|
|
|
source = "#{method_input} ; self.main{|val| #{block_input}}"
|
2018-07-20 20:27:55 +02:00
|
|
|
vool = Ruby::RubyCompiler.compile( as_test_main(source) ).to_vool
|
2018-07-10 21:03:32 +02:00
|
|
|
mom_c = vool.to_mom(nil)
|
|
|
|
compiler = mom_c.method_compilers.find{|c| c.get_method.name == :main and c.get_method.self_type.object_class.name == :Test}
|
|
|
|
block = nil
|
|
|
|
vool.each {|b| block = b if b.is_a?(Vool::BlockStatement)}
|
|
|
|
assert block
|
|
|
|
block_c = compiler.block_compilers.first
|
|
|
|
assert block_c
|
|
|
|
block.body.to_mom(block_c)
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
2018-07-02 14:52:51 +02:00
|
|
|
def compile_mom(input)
|
2019-02-08 22:03:23 +01:00
|
|
|
RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(input)
|
2017-09-07 07:16:37 +02:00
|
|
|
end
|
|
|
|
|
2017-04-10 15:12:15 +02:00
|
|
|
end
|