diff --git a/lib/rubyx.rb b/lib/rubyx.rb index 572b7bf8..43bab94a 100644 --- a/lib/rubyx.rb +++ b/lib/rubyx.rb @@ -13,5 +13,5 @@ require "risc" require "risc/builtin/space" require "arm/arm_machine" require "arm/translator" - require "rubyx/ruby_compiler" +require "vool.rb" diff --git a/lib/vool.rb b/lib/vool.rb new file mode 100644 index 00000000..e72db3db --- /dev/null +++ b/lib/vool.rb @@ -0,0 +1,2 @@ +require_relative "vool/compiler" +require_relative "vool/class_statement" diff --git a/lib/vool/class_statement.rb b/lib/vool/class_statement.rb new file mode 100644 index 00000000..86d0374a --- /dev/null +++ b/lib/vool/class_statement.rb @@ -0,0 +1,10 @@ +module Vool + class ClassStatement + attr_reader :name, :super_class_name , :body + + def initialize( name , supe , body) + @name , @super_class_name , @body = name , supe , body + end + + end +end diff --git a/lib/vool/compiler.rb b/lib/vool/compiler.rb new file mode 100644 index 00000000..5744f660 --- /dev/null +++ b/lib/vool/compiler.rb @@ -0,0 +1,23 @@ +module Vool + class Compiler < ::Rubyx::Passes::TotalProcessor + + def self.compile(input) + ast = Parser::Ruby22.parse( input ) + self.new.process(ast) + end + + def on_class( statement ) + name , sup , body = *statement + ClassStatement.new( get_name(name) , get_name(sup) , body ) + end + + def get_name( statement ) + return nil unless statement + raise "Not const #{statement}" unless statement.type == :const + name = statement.children[1] + raise "Not symbol #{name}" unless name.is_a? Symbol + name + end + + end +end diff --git a/test/vool/helper.rb b/test/vool/helper.rb new file mode 100644 index 00000000..26258082 --- /dev/null +++ b/test/vool/helper.rb @@ -0,0 +1 @@ +require_relative "../helper" diff --git a/test/vool/test_class_statement.rb b/test/vool/test_class_statement.rb new file mode 100644 index 00000000..98477fb7 --- /dev/null +++ b/test/vool/test_class_statement.rb @@ -0,0 +1,24 @@ +require_relative "../helper" + +module Vool + class TestClassStatement < MiniTest::Test + + def setup + input = "class Tryout < Base;end" + @lst = Compiler.compile( input ) + end + + def test_compile_class + assert_equal ClassStatement , @lst.class + end + + def test_compile_class_name + assert_equal :Tryout , @lst.name + end + + def test_compile_class_super + assert_equal :Base , @lst.super_class_name + end + + end +end diff --git a/test/vool/test_compiler.rb b/test/vool/test_compiler.rb new file mode 100644 index 00000000..6a3f1070 --- /dev/null +++ b/test/vool/test_compiler.rb @@ -0,0 +1,2 @@ +require_relative "helper" +require_relative "test_class_statement"