2019-09-13 21:06:18 +02:00
|
|
|
require_relative "preloader"
|
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
|
|
|
|
2019-09-13 13:07:12 +02:00
|
|
|
def compiler_with_main(options = {})
|
|
|
|
compiler = RubyX::RubyXCompiler.new(RubyX.default_test_options.merge(options))
|
|
|
|
compiler.ruby_to_vool( "class Space;def main(arg);return;end;end" )
|
|
|
|
compiler
|
|
|
|
end
|
2019-09-12 21:27:10 +02:00
|
|
|
def in_Test(statements)
|
|
|
|
"class Test ; #{statements} ; end"
|
|
|
|
end
|
|
|
|
|
|
|
|
def as_test_main(statements)
|
|
|
|
in_Test("def main(arg) ; #{statements}; end")
|
|
|
|
end
|
|
|
|
|
2017-04-10 15:12:15 +02:00
|
|
|
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
|
|
|
|
2019-09-12 12:10:31 +02:00
|
|
|
def as_main_block( block_input = "return 5", method_input = "main_local = 5")
|
|
|
|
as_main("#{method_input} ; self.main{|val| #{block_input}}")
|
2019-08-13 18:32:17 +02:00
|
|
|
end
|
|
|
|
|
2017-09-07 07:16:37 +02:00
|
|
|
end
|
2019-08-06 17:33:27 +02:00
|
|
|
module VoolCompile
|
|
|
|
include ScopeHelper
|
2019-10-03 19:55:41 +02:00
|
|
|
include SlotMachine
|
2019-09-12 21:27:10 +02:00
|
|
|
include Preloader
|
2019-08-06 17:33:27 +02:00
|
|
|
|
2019-09-12 21:27:10 +02:00
|
|
|
def compile_main( input , preload = nil)
|
|
|
|
input = get_preload(preload) + as_main( input )
|
2019-10-03 19:55:41 +02:00
|
|
|
collection = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot(input)
|
|
|
|
assert collection.is_a?(SlotMachine::SlotCollection) , collection.class.name
|
2019-09-28 14:07:20 +02:00
|
|
|
compiler = collection.compilers.find_compiler_name(:main)
|
2019-10-03 19:55:41 +02:00
|
|
|
assert_equal SlotMachine::MethodCompiler , compiler.class
|
2019-08-07 11:06:06 +02:00
|
|
|
compiler
|
2019-08-06 17:33:27 +02:00
|
|
|
end
|
2019-09-12 21:27:10 +02:00
|
|
|
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}}")
|
2019-10-03 20:07:55 +02:00
|
|
|
slot_col = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot( source )
|
|
|
|
compiler = slot_col.method_compilers.find_compiler_name(:main)
|
|
|
|
block = slot_col.method_compilers.find_compiler_name(:main_block)
|
2019-08-13 19:35:27 +02:00
|
|
|
assert block
|
2019-10-03 19:55:41 +02:00
|
|
|
block.slot_instructions.next
|
2019-08-07 14:08:45 +02:00
|
|
|
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
|
|
|
|
2019-10-03 19:55:41 +02:00
|
|
|
module SlotMachineCompile
|
2018-06-29 22:04:50 +02:00
|
|
|
include ScopeHelper
|
2017-09-07 07:16:37 +02:00
|
|
|
|
2019-10-03 19:55:41 +02:00
|
|
|
def compile_slot(input)
|
|
|
|
RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_slot(input)
|
2017-09-07 07:16:37 +02:00
|
|
|
end
|
|
|
|
|
2017-04-10 15:12:15 +02:00
|
|
|
end
|