diff --git a/lib/rubyx/rubyx_compiler.rb b/lib/rubyx/rubyx_compiler.rb index 42ceddcf..f938dc6d 100644 --- a/lib/rubyx/rubyx_compiler.rb +++ b/lib/rubyx/rubyx_compiler.rb @@ -83,7 +83,14 @@ module RubyX # ruby_to_vool compiles the ruby to ast, and then to vool def ruby_to_vool(ruby_source) ruby_tree = Ruby::RubyCompiler.compile( ruby_source ) - @vool = ruby_tree.to_vool + unless(@vool) + @vool = ruby_tree.to_vool + return @vool + end + unless(@vool.is_a?(Vool::ScopeStatement)) + @vool = Vool::ScopeStatement.new([@vool]) + end + @vool << ruby_tree.to_vool end diff --git a/test/rubyx/test_rubyx_compiler3.rb b/test/rubyx/test_rubyx_compiler3.rb index 4671caa0..dff6e7f6 100644 --- a/test/rubyx/test_rubyx_compiler3.rb +++ b/test/rubyx/test_rubyx_compiler3.rb @@ -5,16 +5,31 @@ module RubyX include ScopeHelper include RubyXHelper - def setup -# code = "class Space ; def main(arg);return arg;end; end" -# @compiler = ruby_to_binary(code, :interpreter) + def space_source_for( name ) + "class Space ; def #{name}(arg);return arg;end; end" end - def test_to_binary - code = "class Space ; def main(arg);return arg;end; end" - @linker = RubyXCompiler.ruby_to_binary(code, :interpreter) + def test_return_linker + @linker = RubyXCompiler.ruby_to_binary(space_source_for("main"), :interpreter) assert_equal Risc::Linker , @linker.class end - def test_method + def test_one_vool_call + compiler = RubyXCompiler.new + compiler.ruby_to_vool(space_source_for("main")) + assert_equal Vool::ClassStatement , compiler.vool.class + end + def test_two_vool_calls + compiler = RubyXCompiler.new + compiler.ruby_to_vool(space_source_for("main")) + compiler.ruby_to_vool(space_source_for("twain")) + assert_equal Vool::ScopeStatement , compiler.vool.class + assert_equal 2 , compiler.vool.length + end + def test_bin_two_sources + compiler = RubyXCompiler.new + compiler.ruby_to_vool(space_source_for("main")) + compiler.ruby_to_vool(space_source_for("twain")) +# linker = compiler.to_binary(:interpreter) +# assert_equal Vool::ScopeStatement , linker.class end end end