parent
04720d4950
commit
5ed6a07083
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
48
test/ruby/test_class_statement2.rb
Normal file
48
test/ruby/test_class_statement2.rb
Normal file
@ -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
|
47
test/ruby/test_class_statement3.rb
Normal file
47
test/ruby/test_class_statement3.rb
Normal file
@ -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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user