diff --git a/lib/ruby/class_statement.rb b/lib/ruby/class_statement.rb index a6152302..b5a73bf9 100644 --- a/lib/ruby/class_statement.rb +++ b/lib/ruby/class_statement.rb @@ -42,8 +42,12 @@ module Ruby unless class_send.name == :attr raise "Only remapping attr and cattr, not #{class_send.name}" end - attr = class_send.arguments.first.value - [ getter_for(attr) , setter_for(attr) ] + methods = [] + class_send.arguments.each do |attr| + methods << getter_for(attr.value) + methods << setter_for(attr.value) + end + methods end # creates a getter method for the given instance name (sym) diff --git a/lib/rubyx/rubyx_compiler.rb b/lib/rubyx/rubyx_compiler.rb index 61780677..2dd83cde 100644 --- a/lib/rubyx/rubyx_compiler.rb +++ b/lib/rubyx/rubyx_compiler.rb @@ -99,13 +99,14 @@ module RubyX parfait = ["object"] parfait.each do |file| path = File.expand_path("../../parfait/#{file}.rb",__FILE__) + puts "Loading #{path}" ruby_to_vool(File.read(path)) end end def self.ruby_to_binary( ruby , options) compiler = RubyXCompiler.new(options) -# compiler.load_parfait + compiler.load_parfait if options[:load_parfait] compiler.ruby_to_vool(ruby) platform = options[:platform] raise "No platform given" unless platform diff --git a/test/parfait/helper.rb b/test/parfait/helper.rb index 2fb0206e..11fbb387 100644 --- a/test/parfait/helper.rb +++ b/test/parfait/helper.rb @@ -5,7 +5,7 @@ module Parfait include AST::Sexp def rewrite(input) - ast = Parser::Ruby22.parse( input ) + ast = Parser::CurrentRuby.parse( input ) new_ast = process(ast) new_ast.to_s end diff --git a/test/ruby/helper.rb b/test/ruby/helper.rb index 44535654..6bcf3eea 100644 --- a/test/ruby/helper.rb +++ b/test/ruby/helper.rb @@ -20,4 +20,17 @@ module Ruby $stdout = orig_stdout end end + module AttributeTests + include RubyTests + def setup + super + @vool = compile( "class Tryout < Base; #{attr_def};end" ).to_vool + end + def getter + @vool.body.statements.first + end + def setter + @vool.body.statements.last + end + end end diff --git a/test/ruby/test_class_statement.rb b/test/ruby/test_class_statement.rb index e0307d95..6d9f3ecf 100644 --- a/test/ruby/test_class_statement.rb +++ b/test/ruby/test_class_statement.rb @@ -74,51 +74,4 @@ module Ruby assert_raises_muted { compile( input ).to_vool} end end - class TestClassStatementTransform < MiniTest::Test - include RubyTests - - def setup - input = "class Tryout < Base;attr :page ;end" - @vool = compile( input ).to_vool - end - def getter - @vool.body.statements.first - end - def setter - @vool.body.statements.last - end - def test_class - assert_equal Vool::ClassStatement , @vool.class - end - def test_body - assert_equal Vool::Statements , @vool.body.class - end - def test_getter - assert_equal Vool::MethodStatement , getter.class - end - def test_getter_return - assert_equal Vool::ReturnStatement , getter.body.class - end - def test_getter_name - assert_equal :page , getter.name - end - def test_setter - assert_equal Vool::MethodStatement , setter.class - end - def test_setter_assign - assert_equal Vool::Statements , setter.body.class - assert_equal Vool::IvarAssignment , setter.body.first.class - end - def test_setter_return - assert_equal Vool::Statements , setter.body.class - assert_equal Vool::ReturnStatement , setter.body.last.class - end - def test_setter_name - assert_equal :page= , setter.name - end - def test_setter_args - assert_equal [:val] , setter.args - end - end - end diff --git a/test/ruby/test_class_statement2.rb b/test/ruby/test_class_statement2.rb new file mode 100644 index 00000000..9cec264b --- /dev/null +++ b/test/ruby/test_class_statement2.rb @@ -0,0 +1,48 @@ +require_relative "helper" + +module Ruby + class TestClassStatementTransform < MiniTest::Test + include AttributeTests + + def attr_def + "attr :page" + end + + def test_class + assert_equal Vool::ClassStatement , @vool.class + end + def test_body + assert_equal Vool::Statements , @vool.body.class + end + def test_method_len + assert_equal 2 , @vool.body.length , "setter, getter" + end + def test_getter + assert_equal Vool::MethodStatement , getter.class + end + def test_getter_return + assert_equal Vool::ReturnStatement , getter.body.class + end + def test_getter_name + assert_equal :page , getter.name + end + def test_setter + assert_equal Vool::MethodStatement , setter.class + end + def test_setter_assign + assert_equal Vool::Statements , setter.body.class + assert_equal Vool::IvarAssignment , setter.body.first.class + end + def test_setter_return + assert_equal Vool::Statements , setter.body.class + assert_equal Vool::ReturnStatement , setter.body.last.class + end + def test_setter_name + assert_equal :page= , setter.name + end + def test_setter_args + assert_equal [:val] , setter.args + end + end + +end diff --git a/test/ruby/test_class_statement3.rb b/test/ruby/test_class_statement3.rb new file mode 100644 index 00000000..24e037d6 --- /dev/null +++ b/test/ruby/test_class_statement3.rb @@ -0,0 +1,47 @@ +require_relative "helper" + +module Ruby + class TestClassStatementTransformList < MiniTest::Test + include AttributeTests + + def attr_def + "attr :page , :size" + end + def test_class + assert_equal Vool::ClassStatement , @vool.class + end + def test_body + assert_equal Vool::Statements , @vool.body.class + end + def test_method_len + assert_equal 4 , @vool.body.length , "2 setters, 2 getters" + end + def test_getter + assert_equal Vool::MethodStatement , getter.class + end + def test_getter_return + assert_equal Vool::ReturnStatement , getter.body.class + end + def test_getter_name + assert_equal :page , getter.name + end + def test_setter + assert_equal Vool::MethodStatement , setter.class + end + def test_setter_assign + assert_equal Vool::Statements , setter.body.class + assert_equal Vool::IvarAssignment , setter.body.first.class + end + def test_setter_return + assert_equal Vool::Statements , setter.body.class + assert_equal Vool::ReturnStatement , setter.body.last.class + end + def test_setter_name + assert_equal :size= , setter.name + end + def test_setter_args + assert_equal [:val] , setter.args + end + end + +end diff --git a/test/rubyx/test_rubyx_compiler2.rb b/test/rubyx/test_rubyx_compiler2.rb index 79bd039b..5d34231a 100644 --- a/test/rubyx/test_rubyx_compiler2.rb +++ b/test/rubyx/test_rubyx_compiler2.rb @@ -30,7 +30,7 @@ module RubyX @comp = RubyXCompiler.ruby_to_binary(code , load_parfait: true , platform: :interpreter) end - def test_load + def pest_load object = Parfait.object_space.get_class_by_name(:Object) assert_equal Parfait::Class , object.class object = object.instance_type