diff --git a/lib/vool.rb b/lib/vool.rb index 9af1d184..7267beaf 100644 --- a/lib/vool.rb +++ b/lib/vool.rb @@ -18,4 +18,4 @@ require_relative "vool/send_statement" require_relative "vool/variables" require_relative "vool/while_statement" -require_relative "vool/compiler" +require_relative "vool/ruby_compiler" diff --git a/lib/vool/compiler.rb b/lib/vool/ruby_compiler.rb similarity index 91% rename from lib/vool/compiler.rb rename to lib/vool/ruby_compiler.rb index 35bd1ae1..30a3daac 100644 --- a/lib/vool/compiler.rb +++ b/lib/vool/ruby_compiler.rb @@ -1,5 +1,13 @@ module Vool - class Compiler < AST::Processor + # This RubyCompiler compiles incoming ruby (string) into vools internal representation + # with the help of the parser gem. The parser outputs an abstract ast (nodes) + # that get transformed into concrete, specific classes. + # + # As a second step, it extracts classes, methods, ivars and locals. + # + # The next step is then to normalize the code and then finally to compile + # to the next level down, MOM (Minimal Object Machine) + class RubyCompiler < AST::Processor def self.compile(input) ast = Parser::Ruby22.parse( input ) diff --git a/test/vool/test_all.rb b/test/vool/test_all.rb index 65f18f56..6ac8d62a 100644 --- a/test/vool/test_all.rb +++ b/test/vool/test_all.rb @@ -1,2 +1,2 @@ require_relative "helper" -require_relative "test_compiler" +require_relative "test_ruby_compiler" diff --git a/test/vool/test_array_statement.rb b/test/vool/test_array_statement.rb index 151d8835..0c83853b 100644 --- a/test/vool/test_array_statement.rb +++ b/test/vool/test_array_statement.rb @@ -4,15 +4,15 @@ module Vool class TestArray < MiniTest::Test def test_empty - lst = Compiler.compile( "[]") + lst = RubyCompiler.compile( "[]") assert_equal ArrayStatement , lst.class end def test_one - lst = Compiler.compile( "[1]") + lst = RubyCompiler.compile( "[1]") assert_equal ArrayStatement , lst.class end def test_two - lst = Compiler.compile( "[1,2]") + lst = RubyCompiler.compile( "[1,2]") assert_equal ArrayStatement , lst.class end end diff --git a/test/vool/test_assignment_statement.rb b/test/vool/test_assignment_statement.rb index 52a192a8..7d1e7080 100644 --- a/test/vool/test_assignment_statement.rb +++ b/test/vool/test_assignment_statement.rb @@ -4,20 +4,20 @@ module Vool class TestAssignment < MiniTest::Test def test_local - lst = Compiler.compile( "foo = bar") + lst = RubyCompiler.compile( "foo = bar") assert_equal LocalAssignment , lst.class end def test_local_name - lst = Compiler.compile( "foo = bar") + lst = RubyCompiler.compile( "foo = bar") assert_equal :foo , lst.name end def test_instance - lst = Compiler.compile( "@foo = bar") + lst = RubyCompiler.compile( "@foo = bar") assert_equal InstanceAssignment , lst.class end def test_instance_name - lst = Compiler.compile( "@foo = bar") + lst = RubyCompiler.compile( "@foo = bar") assert_equal :foo , lst.name end diff --git a/test/vool/test_basic_values.rb b/test/vool/test_basic_values.rb index 99efdd04..148da0d6 100644 --- a/test/vool/test_basic_values.rb +++ b/test/vool/test_basic_values.rb @@ -4,45 +4,45 @@ module Vool class TestBasicValues < MiniTest::Test def test_self - lst = Compiler.compile( "self") + lst = RubyCompiler.compile( "self") assert_equal SelfStatement , lst.class end def test_nil - lst = Compiler.compile( "nil") + lst = RubyCompiler.compile( "nil") assert_equal NilStatement , lst.class end def test_false - lst = Compiler.compile( "false") + lst = RubyCompiler.compile( "false") assert_equal FalseStatement , lst.class end def test_true - lst = Compiler.compile( "true") + lst = RubyCompiler.compile( "true") assert_equal TrueStatement , lst.class end def test_integer - lst = Compiler.compile( "123") + lst = RubyCompiler.compile( "123") assert_equal IntegerStatement , lst.class end def test_string - lst = Compiler.compile( "'string'") + lst = RubyCompiler.compile( "'string'") assert_equal StringStatement , lst.class , lst.inspect end def test_sym - lst = Compiler.compile( ":symbol") + lst = RubyCompiler.compile( ":symbol") assert_equal SymbolStatement , lst.class , lst.inspect end def test_dstr assert_raises RuntimeError do - Compiler.compile( '"dstr#{self}"') + RubyCompiler.compile( '"dstr#{self}"') end end def test_scope - lst = Compiler.compile( "begin ; 1 ; end") + lst = RubyCompiler.compile( "begin ; 1 ; end") assert_equal ScopeStatement , lst.class , lst.inspect end def test_scope_contents - lst = Compiler.compile( "begin ; 1 ; end") + lst = RubyCompiler.compile( "begin ; 1 ; end") assert_equal 1 , lst.statements.first.value end end diff --git a/test/vool/test_class_statement.rb b/test/vool/test_class_statement.rb index 9711bb19..b8947abe 100644 --- a/test/vool/test_class_statement.rb +++ b/test/vool/test_class_statement.rb @@ -5,7 +5,7 @@ module Vool def setup input = "class Tryout < Base;end" - @lst = Compiler.compile( input ) + @lst = RubyCompiler.compile( input ) end def test_compile_class diff --git a/test/vool/test_hash_statement.rb b/test/vool/test_hash_statement.rb index 31096fb9..dd9c3b8f 100644 --- a/test/vool/test_hash_statement.rb +++ b/test/vool/test_hash_statement.rb @@ -4,31 +4,31 @@ module Vool class HashArray < MiniTest::Test def test_empty - lst = Compiler.compile( "{}") + lst = RubyCompiler.compile( "{}") assert_equal HashStatement , lst.class end def test_empty_length - lst = Compiler.compile( "{}") + lst = RubyCompiler.compile( "{}") assert_equal 0 , lst.length end def test_one - lst = Compiler.compile( "{ 1 => 2}") + lst = RubyCompiler.compile( "{ 1 => 2}") assert_equal HashStatement , lst.class end def test_one_length - lst = Compiler.compile( "{ 1 => 2}") + lst = RubyCompiler.compile( "{ 1 => 2}") assert_equal 1 , lst.length end def test_one_pair - lst = Compiler.compile( "{ 1 => 2}") + lst = RubyCompiler.compile( "{ 1 => 2}") assert_equal 1 , lst.hash.keys.first.value end def test_two_length - lst = Compiler.compile( "{ sym: :works , 'string_too' => 2}") + lst = RubyCompiler.compile( "{ sym: :works , 'string_too' => 2}") assert_equal 2 , lst.length end def test_two_key_one - lst = Compiler.compile( "{ sym: :works , 'string_too' => 2}") + lst = RubyCompiler.compile( "{ sym: :works , 'string_too' => 2}") assert_equal :sym , lst.hash.keys.first.value end end diff --git a/test/vool/test_if_statement.rb b/test/vool/test_if_statement.rb index 59d4eafe..4aeadbcb 100644 --- a/test/vool/test_if_statement.rb +++ b/test/vool/test_if_statement.rb @@ -7,15 +7,15 @@ module Vool "if(10 < 12) ; true ; end" end def test_if_basic - lst = Compiler.compile( basic_if ) + lst = RubyCompiler.compile( basic_if ) assert_equal IfStatement , lst.class end def test_if_basic_cond - lst = Compiler.compile( basic_if ) + lst = RubyCompiler.compile( basic_if ) assert_equal SendStatement , lst.condition.class end def test_if_basic_branches - lst = Compiler.compile( basic_if ) + lst = RubyCompiler.compile( basic_if ) assert_equal TrueStatement , lst.if_true.class assert_nil lst.if_false end @@ -24,15 +24,15 @@ module Vool "if(false) ; true ; else ; false; end" end def test_if_double - lst = Compiler.compile( double_if ) + lst = RubyCompiler.compile( double_if ) assert_equal IfStatement , lst.class end def test_if_double_cond - lst = Compiler.compile( double_if ) + lst = RubyCompiler.compile( double_if ) assert_equal FalseStatement , lst.condition.class end def test_if_double_branches - lst = Compiler.compile( double_if ) + lst = RubyCompiler.compile( double_if ) assert_equal TrueStatement , lst.if_true.class assert_equal FalseStatement, lst.if_false.class end @@ -41,15 +41,15 @@ module Vool "true if(false)" end def test_if_reverse - lst = Compiler.compile( reverse_if ) + lst = RubyCompiler.compile( reverse_if ) assert_equal IfStatement , lst.class end def test_if_reverse_cond - lst = Compiler.compile( reverse_if ) + lst = RubyCompiler.compile( reverse_if ) assert_equal FalseStatement , lst.condition.class end def test_if_reverse_branches - lst = Compiler.compile( reverse_if ) + lst = RubyCompiler.compile( reverse_if ) assert_equal TrueStatement , lst.if_true.class assert_nil lst.if_false end @@ -58,15 +58,15 @@ module Vool "true unless(false)" end def test_if_reverse - lst = Compiler.compile( reverse_unless ) + lst = RubyCompiler.compile( reverse_unless ) assert_equal IfStatement , lst.class end def test_if_reverse_cond - lst = Compiler.compile( reverse_unless ) + lst = RubyCompiler.compile( reverse_unless ) assert_equal FalseStatement , lst.condition.class end def test_if_reverse_branches - lst = Compiler.compile( reverse_unless ) + lst = RubyCompiler.compile( reverse_unless ) assert_nil lst.if_true assert_equal TrueStatement ,lst.if_false.class end @@ -75,15 +75,15 @@ module Vool "false ? true : false" end def test_if_ternary - lst = Compiler.compile( ternary ) + lst = RubyCompiler.compile( ternary ) assert_equal IfStatement , lst.class end def test_if_ternary_cond - lst = Compiler.compile( ternary ) + lst = RubyCompiler.compile( ternary ) assert_equal FalseStatement , lst.condition.class end def test_if_ternary_branches - lst = Compiler.compile( ternary ) + lst = RubyCompiler.compile( ternary ) assert_equal TrueStatement , lst.if_true.class assert_equal FalseStatement, lst.if_false.class end diff --git a/test/vool/test_logical_statement.rb b/test/vool/test_logical_statement.rb index 8ea47b11..6861c6b7 100644 --- a/test/vool/test_logical_statement.rb +++ b/test/vool/test_logical_statement.rb @@ -4,7 +4,7 @@ module Vool class TestLogical < MiniTest::Test def simple - Compiler.compile( "@a and @b") + RubyCompiler.compile( "@a and @b") end def test_simple lst = simple @@ -24,16 +24,16 @@ module Vool end def test_or - lst = Compiler.compile( "@a or @b") + lst = RubyCompiler.compile( "@a or @b") assert_equal :or , lst.name end def test_or2 - lst = Compiler.compile( "@a || @b") + lst = RubyCompiler.compile( "@a || @b") assert_equal :or , lst.name end def test_and2 - lst = Compiler.compile( "@a && @b") + lst = RubyCompiler.compile( "@a && @b") assert_equal :and , lst.name end end diff --git a/test/vool/test_method_statement.rb b/test/vool/test_method_statement.rb index 392a558f..e966718d 100644 --- a/test/vool/test_method_statement.rb +++ b/test/vool/test_method_statement.rb @@ -5,7 +5,7 @@ module Vool def basic_setup() input = "def tryout(arg1, arg2) ; true ; false ; end " - @lst = Compiler.compile( input ) + @lst = RubyCompiler.compile( input ) end def test_method basic_setup diff --git a/test/vool/test_return_statement.rb b/test/vool/test_return_statement.rb index 7199c4d6..91dc4a0d 100644 --- a/test/vool/test_return_statement.rb +++ b/test/vool/test_return_statement.rb @@ -4,17 +4,17 @@ module Vool class TestReturnStatement < MiniTest::Test def test_return_const - lst = Compiler.compile( "return 1" ) + lst = RubyCompiler.compile( "return 1" ) assert_equal ReturnStatement , lst.class end def test_return_value - lst = Compiler.compile( "return 1" ) + lst = RubyCompiler.compile( "return 1" ) assert_equal 1 , lst.return_value.value end def test_return_send - lst = Compiler.compile( "return foo" ) + lst = RubyCompiler.compile( "return foo" ) assert_equal SendStatement , lst.return_value.class assert_equal :foo , lst.return_value.name end diff --git a/test/vool/test_compiler.rb b/test/vool/test_ruby_compiler.rb similarity index 100% rename from test/vool/test_compiler.rb rename to test/vool/test_ruby_compiler.rb diff --git a/test/vool/test_send_statement.rb b/test/vool/test_send_statement.rb index 19937ff4..a3265ec9 100644 --- a/test/vool/test_send_statement.rb +++ b/test/vool/test_send_statement.rb @@ -4,58 +4,58 @@ module Vool class TestSend < MiniTest::Test def test_simple - lst = Compiler.compile( "foo") + lst = RubyCompiler.compile( "foo") assert_equal SendStatement , lst.class end def test_simple_name - lst = Compiler.compile( "foo") + lst = RubyCompiler.compile( "foo") assert_equal :foo , lst.name end def test_simple_receiver - lst = Compiler.compile( "foo") + lst = RubyCompiler.compile( "foo") assert_equal SelfStatement , lst.receiver.class end def test_simple_args - lst = Compiler.compile( "foo") + lst = RubyCompiler.compile( "foo") assert_equal [] , lst.arguments end def test_one_arg - lst = Compiler.compile( "bar(1)") + lst = RubyCompiler.compile( "bar(1)") assert_equal SendStatement , lst.class end def test_one_arg_name - lst = Compiler.compile( "bar(1)") + lst = RubyCompiler.compile( "bar(1)") assert_equal :bar , lst.name end def test_one_arg_receiver - lst = Compiler.compile( "bar(1)") + lst = RubyCompiler.compile( "bar(1)") assert_equal SelfStatement , lst.receiver.class end def test_one_arg_args - lst = Compiler.compile( "bar(1)") + lst = RubyCompiler.compile( "bar(1)") assert_equal 1 , lst.arguments.first.value end def test_super0_receiver - lst = Compiler.compile( "super") + lst = RubyCompiler.compile( "super") assert_equal SuperStatement , lst.receiver.class end def test_super0 - lst = Compiler.compile( "super") + lst = RubyCompiler.compile( "super") assert_equal SendStatement , lst.class end def test_super_receiver - lst = Compiler.compile( "super(1)") + lst = RubyCompiler.compile( "super(1)") assert_equal SuperStatement , lst.receiver.class end def test_super_args - lst = Compiler.compile( "super(1)") + lst = RubyCompiler.compile( "super(1)") assert_equal 1 , lst.arguments.first.value end def test_super_name #is nil - lst = Compiler.compile( "super(1)") + lst = RubyCompiler.compile( "super(1)") assert_nil lst.name end diff --git a/test/vool/test_variables.rb b/test/vool/test_variables.rb index 8c86cb1a..ef4cb41e 100644 --- a/test/vool/test_variables.rb +++ b/test/vool/test_variables.rb @@ -7,51 +7,51 @@ module Vool # in other words ther is no way of knowing if a name is variable or method # one needs an assignemnt first, to "tell" the parser it's a local def test_local_basic - lst = Compiler.compile( "foo = 1 ; foo") + lst = RubyCompiler.compile( "foo = 1 ; foo") assert_equal ScopeStatement , lst.class assert_equal LocalVariable , lst.statements[1].class end def test_local_nane - lst = Compiler.compile( "foo = 1 ; foo") + lst = RubyCompiler.compile( "foo = 1 ; foo") assert_equal LocalVariable , lst.statements[1].class end def test_instance_basic - lst = Compiler.compile( "@var" ) + lst = RubyCompiler.compile( "@var" ) assert_equal InstanceVariable , lst.class assert_equal :var , lst.name end def test_instance_return - lst = Compiler.compile( "return @var" ) + lst = RubyCompiler.compile( "return @var" ) assert_equal InstanceVariable , lst.return_value.class end def test_class_basic - lst = Compiler.compile( "@@var" ) + lst = RubyCompiler.compile( "@@var" ) assert_equal ClassVariable , lst.class assert_equal :var , lst.name end def test_class_return - lst = Compiler.compile( "return @@var" ) + lst = RubyCompiler.compile( "return @@var" ) assert_equal ClassVariable , lst.return_value.class end def test_module_basic - lst = Compiler.compile( "Module" ) + lst = RubyCompiler.compile( "Module" ) assert_equal ModuleName , lst.class assert_equal :Module , lst.name end def test_module_base_scoped - lst = Compiler.compile( "::Module" ) + lst = RubyCompiler.compile( "::Module" ) assert_equal ModuleName , lst.class assert_equal :Module , lst.name end def test_module_module_scoped - assert_raises {Compiler.compile( "M::Module" ) } + assert_raises {RubyCompiler.compile( "M::Module" ) } end end end diff --git a/test/vool/test_while_statement.rb b/test/vool/test_while_statement.rb index e7263dec..48840ee5 100644 --- a/test/vool/test_while_statement.rb +++ b/test/vool/test_while_statement.rb @@ -7,15 +7,15 @@ module Vool "while(10 < 12) ; true ; end" end def test_while_basic - lst = Compiler.compile( basic_while ) + lst = RubyCompiler.compile( basic_while ) assert_equal WhileStatement , lst.class end def test_while_basic_cond - lst = Compiler.compile( basic_while ) + lst = RubyCompiler.compile( basic_while ) assert_equal SendStatement , lst.condition.class end def test_while_basic_branches - lst = Compiler.compile( basic_while ) + lst = RubyCompiler.compile( basic_while ) assert_equal TrueStatement , lst.statements.class end @@ -23,15 +23,15 @@ module Vool "true while(false)" end def test_while_reverse_branches - lst = Compiler.compile( reverse_while ) + lst = RubyCompiler.compile( reverse_while ) assert_equal WhileStatement , lst.class end def test_while_reverse_cond - lst = Compiler.compile( reverse_while ) + lst = RubyCompiler.compile( reverse_while ) assert_equal FalseStatement , lst.condition.class end def test_while_reverse_branches - lst = Compiler.compile( reverse_while ) + lst = RubyCompiler.compile( reverse_while ) assert_equal TrueStatement , lst.statements.class end