2017-04-10 16:12:15 +03:00
|
|
|
|
2018-06-29 23:04:50 +03:00
|
|
|
module ScopeHelper
|
2017-04-10 16:12:15 +03: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 08:28:29 +03:00
|
|
|
in_Space("def main(arg) ; #{statements}; end")
|
2017-04-10 16:12:15 +03:00
|
|
|
end
|
2017-04-13 14:14:43 +03:00
|
|
|
|
|
|
|
def as_test_main( statements )
|
2017-09-07 08:16:37 +03:00
|
|
|
in_Test("def main(arg) ; #{statements}; end")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module MomCompile
|
2018-06-29 23:04:50 +03:00
|
|
|
include ScopeHelper
|
2017-09-07 08:16:37 +03:00
|
|
|
|
2018-07-02 15:52:51 +03:00
|
|
|
def compile_method(input)
|
2019-02-08 23:03:23 +02:00
|
|
|
statements = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_vool(input)
|
2018-07-02 15:52:51 +03:00
|
|
|
assert statements.is_a?(Vool::ClassStatement)
|
|
|
|
ret = statements.to_mom(nil)
|
2018-03-16 12:33:11 +05:30
|
|
|
assert_equal Parfait::Class , statements.clazz.class , statements
|
|
|
|
@method = statements.clazz.get_method(:main)
|
2017-12-10 20:47:26 +02:00
|
|
|
assert_equal Parfait::VoolMethod , @method.class
|
2018-07-02 15:52:51 +03:00
|
|
|
ret
|
2018-06-30 19:20:17 +03:00
|
|
|
end
|
|
|
|
def compile_first_method( input )
|
2018-07-02 15:52:51 +03:00
|
|
|
ret = compile_method( as_test_main( input ))
|
|
|
|
assert_equal Mom::MomCompiler , ret.class
|
2018-07-09 19:32:17 +03: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 15:52:51 +03:00
|
|
|
assert_equal Risc::MethodCompiler , compiler.class
|
2018-07-05 14:02:38 +03:00
|
|
|
@method.source.to_mom( compiler )
|
2018-07-01 11:59:07 +03:00
|
|
|
end
|
2018-07-18 10:13:19 +03:00
|
|
|
def compile_first_block( block_input , method_input = "main_local = 5")
|
|
|
|
source = "#{method_input} ; self.main{|val| #{block_input}}"
|
2018-07-20 21:27:55 +03:00
|
|
|
vool = Ruby::RubyCompiler.compile( as_test_main(source) ).to_vool
|
2018-07-10 22:03:32 +03: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 16:48:23 +03:00
|
|
|
end
|
2018-07-02 15:52:51 +03:00
|
|
|
def compile_mom(input)
|
2019-02-08 23:03:23 +02:00
|
|
|
RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(input)
|
2017-09-07 08:16:37 +03:00
|
|
|
end
|
|
|
|
|
2017-09-09 23:36:43 +03:00
|
|
|
def check_array( should , is )
|
|
|
|
index = 0
|
|
|
|
test = is
|
|
|
|
while(test)
|
2017-09-10 12:57:25 +03:00
|
|
|
# if we assert here, we get output pointing here. Without stack, not useful
|
2017-12-10 20:47:26 +02:00
|
|
|
raise "Wrong class for #{index+1}, #{dump(is)}" if should[index] != test.class
|
2017-09-09 23:36:43 +03:00
|
|
|
index += 1
|
|
|
|
test = test.next
|
|
|
|
end
|
2017-09-10 12:57:25 +03:00
|
|
|
assert 1 #just to get an assertion in the output.
|
2017-09-09 23:36:43 +03:00
|
|
|
end
|
|
|
|
def dump(is)
|
|
|
|
res =[]
|
|
|
|
while(is)
|
|
|
|
res << is.class.name.split("::").last
|
|
|
|
is = is.next
|
|
|
|
end
|
2018-03-20 23:31:42 +05:30
|
|
|
ret = ""
|
2018-04-20 09:56:06 +03:00
|
|
|
res.to_s.split(",").each_slice(5).each do |line|
|
2018-03-20 23:31:42 +05:30
|
|
|
ret += " " + line.join(",") + " ,\n"
|
|
|
|
end
|
|
|
|
ret.gsub('"' , '')
|
2017-09-09 23:36:43 +03:00
|
|
|
end
|
|
|
|
|
2017-04-10 16:12:15 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Ignored
|
|
|
|
def == other
|
|
|
|
return false unless other.class == self.class
|
|
|
|
Sof::Util.attributes(self).each do |a|
|
|
|
|
begin
|
|
|
|
left = send(a)
|
|
|
|
rescue NoMethodError
|
|
|
|
next # not using instance variables that are not defined as attr_readers for equality
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
right = other.send(a)
|
|
|
|
rescue NoMethodError
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return false unless left.class == right.class
|
|
|
|
return false unless left == right
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|