rubyx/test/compiler/expressions/compiler_helper.rb

33 lines
800 B
Ruby
Raw Normal View History

require_relative '../../helper'
2014-06-25 15:20:46 +03:00
require 'parslet/convenience'
2015-10-23 14:22:55 +03:00
Soml::Compiler.class_eval do
2015-10-14 15:17:33 +03:00
def set_main main
2015-10-22 18:16:29 +03:00
@clazz = Register.machine.space.get_class_by_name :Object
2015-10-14 15:17:33 +03:00
@method = main
end
end
2015-10-10 10:02:28 +03:00
module CompilerHelper
2015-07-02 10:44:44 +03:00
2015-10-14 13:48:42 +03:00
def set_main compiler
2015-10-22 18:16:29 +03:00
compiler.set_main Register.machine.space.get_main
2015-10-14 13:48:42 +03:00
end
2015-10-10 10:02:28 +03:00
def check
2015-10-22 18:16:29 +03:00
machine = Register.machine
machine.boot unless machine.booted
2015-10-10 10:02:28 +03:00
parser = Parser::Salama.new
parser = parser.send @root
syntax = parser.parse_with_debug(@string_input)
parts = Parser::Transform.new.apply(syntax)
#puts parts.inspect
2015-10-23 14:22:55 +03:00
compiler = Soml::Compiler.new
2015-10-14 13:48:42 +03:00
set_main(compiler)
2015-10-10 10:02:28 +03:00
produced = compiler.process( parts )
assert @output , "No output given"
assert_equal produced.class, @output , "Wrong class"
produced
end
2015-10-10 10:02:28 +03:00
end