From 86e31035431364e1478c26000432e5a265351a1e Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 12 Feb 2019 22:41:42 +0200 Subject: [PATCH] More or less a stash --- lib/rubyx/rubyx_compiler.rb | 12 +++++++---- test/parfait/helper.rb | 13 +++++++++++ test/parfait/test_interpreted.rb | 37 ++++++++++++++++++++++++++++++++ test/parfait/test_object.rb | 3 +++ 4 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 test/parfait/test_interpreted.rb diff --git a/lib/rubyx/rubyx_compiler.rb b/lib/rubyx/rubyx_compiler.rb index 9635869b..3d7898bb 100644 --- a/lib/rubyx/rubyx_compiler.rb +++ b/lib/rubyx/rubyx_compiler.rb @@ -95,15 +95,19 @@ module RubyX @vool << ruby_tree.to_vool end + def load_parfait + parfait = ["object"] + parfait.each do |file| + path = File.expand_path("../../parfait/#{file}.rb",__FILE__) + ruby_to_vool(File.read(path)) + end + end def self.ruby_to_binary( ruby , platform , options) compiler = RubyXCompiler.new(options) +# compiler.load_parfait compiler.ruby_to_vool(ruby) - - # integrate other sources into vool tree - compiler.to_binary(platform) - end end end diff --git a/test/parfait/helper.rb b/test/parfait/helper.rb index 26258082..2fb0206e 100644 --- a/test/parfait/helper.rb +++ b/test/parfait/helper.rb @@ -1 +1,14 @@ require_relative "../helper" + +module Parfait + class ParfaitRewriter < AST::Processor + include AST::Sexp + + def rewrite(input) + ast = Parser::Ruby22.parse( input ) + new_ast = process(ast) + new_ast.to_s + end + + end +end diff --git a/test/parfait/test_interpreted.rb b/test/parfait/test_interpreted.rb new file mode 100644 index 00000000..4aa26fc0 --- /dev/null +++ b/test/parfait/test_interpreted.rb @@ -0,0 +1,37 @@ +# Test Parfait by parsing it and the tests, and interpreting it. +# (Later also run on arm, much like the mains) +# +# The difference betwen the running parfait and compiled parfait is namespace. +# +# In the running interpreter (the one that runs the tests/compiler), Parfait is namespaced +# to Parfait, because we define Class/Object/Hash/String etc. All that basic stuff that +# is not namespaced in ruby and thus would clash in the running interpreter. +# +# Which leads straight to the point, that in the compiled code parfait is not namespaced. +# Parfait files are actually without namespace, and the namespace is wrapped from the +# outside, so we are good to just parse parfait files. +# +# But the tests are defined for the interpreter (also namespaced) and minitest is used, +# so we can not just parse the tests. Instead we parse and rewrite the test (removing the +# namespace and defining a mini mintest while we are there), +# and then write a single main out. And interpret that. +# For each test defined in Parfait. +require_relative "helper" + +module Parfait + + class InterpretParfait < MiniTest::Test + def setup + parfait = ["object"] + parfait.each do |file| + ruby = File.read("./test/parfait/test_#{file}.rb") + not_scoped = ParfaitRewriter.new.rewrite(ruby) + #puts not_scoped + end + end + + def test_any + + end + end +end diff --git a/test/parfait/test_object.rb b/test/parfait/test_object.rb index e199c8f2..7d7772f1 100644 --- a/test/parfait/test_object.rb +++ b/test/parfait/test_object.rb @@ -16,5 +16,8 @@ module Parfait assert_equal @object.get_type , @object.set_internal_word(0, @object.get_type) end + def test_type + assert_equal "Parfait::Type" , @object.get_internal_word( 0 ).class.name + end end end