rubyx/stash/test_runner.rb

48 lines
1.4 KiB
Ruby
Raw Normal View History

require_relative 'helper'
2014-05-03 14:13:44 +02:00
require "yaml"
2014-05-08 18:31:36 +02:00
require "parslet/convenience"
class TestRunner < MiniTest::Test
# this creates test methods dynamically , one for each file in runners directory
def self.runnable_methods
methods = []
Dir[File.join(File.dirname(__FILE__) , "runners" , "*.rb")].each do |file|
meth = File.basename(file).split(".").first
name = "test_#{meth}"
methods << name
self.send(:define_method, name ) {
execute file
}
end
methods
end
def execute file
string = File.read(file)
2014-07-29 17:33:11 +02:00
parser = Parser::Salama.new
2014-08-22 17:00:23 +02:00
object_space = Register::Program.new "Arm"
2016-12-08 18:39:16 +01:00
#TODO : files would have to include s-expressions now
2015-11-19 09:10:13 +01:00
syntax = parser.parse_with_debug(string, reporter: Parslet::ErrorReporter::Deepest.new)
assert syntax
parts = Parser::Transform.new.apply(syntax)
# file is a list of statements, all but the last must be a function
# and the last is wrapped as a main
parts.each_with_index do |part,index|
2014-05-14 11:02:54 +02:00
if index == (parts.length - 1)
expr = part.compile( program.context )
2014-05-14 11:02:54 +02:00
else
expr = part.compile( program.context )
2014-08-22 17:00:23 +02:00
raise "should be function definition for now" unless expr.is_a? Register::Function
end
end
#object writer takes machine
2014-05-19 16:32:41 +02:00
writer = Elf::ObjectWriter.new(program , Elf::Constants::TARGET_ARM)
2014-05-05 14:59:29 +02:00
writer.save(file.gsub(".rb" , ".o"))
2014-05-05 14:59:29 +02:00
# puts program.to_yaml
end
end