2017-04-10 15:12:15 +02:00
|
|
|
|
|
|
|
module CompilerHelper
|
|
|
|
|
|
|
|
def in_Test(statements)
|
|
|
|
"class Test ; #{statements} ; end"
|
|
|
|
end
|
|
|
|
|
|
|
|
def in_Space(statements)
|
|
|
|
"class Space ; #{statements} ; end"
|
|
|
|
end
|
|
|
|
|
|
|
|
def as_main(statements)
|
|
|
|
in_Space("def main ; #{statements}; end")
|
|
|
|
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
|
|
|
|
|
|
|
|
module MomCompile
|
|
|
|
include CompilerHelper
|
|
|
|
|
2018-03-18 06:20:37 +01:00
|
|
|
def compile_first_method( input )
|
2018-03-16 08:03:11 +01:00
|
|
|
# works a lot like Vool.ruby_to_vool
|
2018-03-18 06:20:37 +01:00
|
|
|
# but here we return the intermediate mom instructions that are otherwise not available
|
2018-03-16 08:03:11 +01:00
|
|
|
statements = Vool::RubyCompiler.compile as_test_main( input )
|
|
|
|
statements = statements.normalize
|
2018-06-26 19:46:58 +02:00
|
|
|
res = 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
|
2017-09-07 07:16:37 +02:00
|
|
|
#puts "#{res.class}"
|
2018-03-15 16:03:38 +01:00
|
|
|
res
|
2017-09-07 07:16:37 +02:00
|
|
|
end
|
|
|
|
|
2017-09-09 22:36:43 +02:00
|
|
|
def check_array( should , is )
|
|
|
|
index = 0
|
|
|
|
test = is
|
|
|
|
while(test)
|
2017-09-10 11:57:25 +02:00
|
|
|
# if we assert here, we get output pointing here. Without stack, not useful
|
2017-12-10 19:47:26 +01:00
|
|
|
raise "Wrong class for #{index+1}, #{dump(is)}" if should[index] != test.class
|
2017-09-09 22:36:43 +02:00
|
|
|
index += 1
|
|
|
|
test = test.next
|
|
|
|
end
|
2017-09-10 11:57:25 +02:00
|
|
|
assert 1 #just to get an assertion in the output.
|
2017-09-09 22:36:43 +02:00
|
|
|
end
|
|
|
|
def dump(is)
|
|
|
|
res =[]
|
|
|
|
while(is)
|
|
|
|
res << is.class.name.split("::").last
|
|
|
|
is = is.next
|
|
|
|
end
|
2018-03-20 19:01:42 +01:00
|
|
|
ret = ""
|
2018-04-20 08:56:06 +02:00
|
|
|
res.to_s.split(",").each_slice(5).each do |line|
|
2018-03-20 19:01:42 +01:00
|
|
|
ret += " " + line.join(",") + " ,\n"
|
|
|
|
end
|
|
|
|
ret.gsub('"' , '')
|
2017-09-09 22:36:43 +02:00
|
|
|
end
|
|
|
|
|
2017-04-10 15:12:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
module CleanCompile
|
|
|
|
def clean_compile(clazz_name , method_name , args , statements)
|
2018-03-25 18:37:51 +02:00
|
|
|
compiler = Vm::MethodCompiler.create_method(clazz_name,method_name,args )
|
2017-04-10 15:12:15 +02:00
|
|
|
compiler.process( Vm.ast_to_code( statements ) )
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|