diff --git a/lib/mom/mom_collection.rb b/lib/mom/mom_collection.rb index 991a7955..28e245c8 100644 --- a/lib/mom/mom_collection.rb +++ b/lib/mom/mom_collection.rb @@ -16,7 +16,7 @@ module Mom # lazily instantiate the compiler for init function def init_compiler - @init_compilers ||= create_init_compiler + @init_compilers ||= MomCollection.create_init_compiler end # Return all compilers, namely the MethodCompilers passed in, plus the @@ -47,8 +47,8 @@ module Mom # - load fist message, set up Space as receiver # - call main, ie set up message for that etc # - exit (exit_sequence) which passes a machine int out to c - def create_init_compiler - compiler = self.class.compiler_for(:Object,:__init__ ,{}) + def self.create_init_compiler + compiler = compiler_for(:Object,:__init__ ,{}) compiler._reset_for_init # no return, just for init compiler.add_code Init.new("missing") return compiler diff --git a/lib/rubyx/interpret.rb b/lib/rubyx/interpret.rb index e0134fe4..485bdb3b 100644 --- a/lib/rubyx/interpret.rb +++ b/lib/rubyx/interpret.rb @@ -24,8 +24,10 @@ class RubyXC < Thor rescue fail MalformattedArgumentError , "No such file #{file}" end + code = get_preload + ruby + compiler = RubyX::RubyXCompiler.new(extract_options) - linker = compiler.ruby_to_binary(ruby, :interpreter) + linker = compiler.ruby_to_binary(code, :interpreter) puts "interpreting #{file}" diff --git a/lib/vool/basic_values.rb b/lib/vool/basic_values.rb index b4eee094..aaca4a23 100644 --- a/lib/vool/basic_values.rb +++ b/lib/vool/basic_values.rb @@ -105,5 +105,8 @@ module Vool def ct_type Parfait.object_space.get_type_by_class_name(:Word) end + def to_s(depth = 0) + ":#{@value}" + end end end diff --git a/lib/vool/builtin.rb b/lib/vool/builtin.rb index efda20c7..735e645f 100644 --- a/lib/vool/builtin.rb +++ b/lib/vool/builtin.rb @@ -14,7 +14,6 @@ module Vool { "Object.get" => "def get_internal_word(at); X.get_internal_word;end", "Object.missing" => "def method_missing(at); X.method_missing;end", - "Object.init" => "def __init__(at); X.init;end", "Object.exit" => "def exit; X.exit;end", "Integer.div4" => "def div4; X.div4;end", "Integer.div10" => "def div10; X.div10;end", @@ -32,7 +31,7 @@ module Vool "Word.put" => "def putstring(at); X.putstring;end", "Word.set" => "def set_internal_byte(at, val); X.set_internal_byte;end", "Word.get" => "def get_internal_byte(at); X.get_internal_byte;end", - "Space.main" => "def main(args);return;end", + "Space.main" => "def main(args);return nil;end", } end def self.builtin_code diff --git a/test/elf/helper.rb b/test/elf/helper.rb index 5cc834e1..490d2d04 100644 --- a/test/elf/helper.rb +++ b/test/elf/helper.rb @@ -3,10 +3,6 @@ require_relative "../helper" module Elf class FullTest < MiniTest::Test - DEBUG = false - - def setup - end def in_space(input) "class Space; #{input} ; end" diff --git a/test/mains/test_arm.rb b/test/mains/test_arm.rb index ec187a84..e622985a 100644 --- a/test/mains/test_arm.rb +++ b/test/mains/test_arm.rb @@ -49,8 +49,9 @@ module Mains def run_code(input , name ) puts "Compiling #{name}.o" if DEBUG + code = Vool::Builtin.builtin_code + input - linker = ::RubyX::RubyXCompiler.new({}).ruby_to_binary( input , :arm ) + linker = ::RubyX::RubyXCompiler.new({}).ruby_to_binary( code , :arm ) writer = Elf::ObjectWriter.new(linker) writer.save "mains.o" diff --git a/test/mom/macro/test_init.rb b/test/mom/macro/test_init.rb index 96888354..48421d1f 100644 --- a/test/mom/macro/test_init.rb +++ b/test/mom/macro/test_init.rb @@ -4,18 +4,19 @@ module Mom module Builtin class TestObjectInitRisc < BootTest def setup - super - @method = get_compiler("Object",:init) + Parfait.boot!(Parfait.default_test_options) + get_compiler("Space",:main) + @method = MomCollection.create_init_compiler end def test_mom_length assert_equal :__init__ , @method.callable.name - assert_equal 7 , @method.mom_instructions.length + assert_equal 2 , @method.mom_instructions.length end def test_compile assert_equal Risc::MethodCompiler , @method.to_risc.class end def test_risc_length - assert_equal 31 , @method.to_risc.risc_instructions.length + assert_equal 19 , @method.to_risc.risc_instructions.length end end end diff --git a/test/ruby/test_basic_values.rb b/test/ruby/test_basic_values.rb index 398321a7..e24ef963 100644 --- a/test/ruby/test_basic_values.rb +++ b/test/ruby/test_basic_values.rb @@ -99,7 +99,7 @@ module Ruby assert_equal "'string'" , compile_const( "'string'") end def test_sym - assert_equal "'symbol'" , compile_const( ":symbol") + assert_equal ":symbol" , compile_const( ":symbol") end def test_nil assert_equal "nil" , compile_const( "nil") diff --git a/test/rubyx/test_compile.rb b/test/rubyx/test_compile.rb new file mode 100644 index 00000000..da0f0d25 --- /dev/null +++ b/test/rubyx/test_compile.rb @@ -0,0 +1,11 @@ +require_relative "helper" +require "rubyx/rubyxc" + +module RubyX + class TestRubyXCliCompile < MiniTest::Test + + def test_compile + assert_output(/compiling/) {RubyXC.start(["compile" , "--preload","test/mains/source/add__4.rb"])} + end + end +end diff --git a/test/rubyx/test_execute.rb b/test/rubyx/test_execute.rb new file mode 100644 index 00000000..df3ada08 --- /dev/null +++ b/test/rubyx/test_execute.rb @@ -0,0 +1,11 @@ +require_relative "helper" +require "rubyx/rubyxc" + +module RubyX + class TestRubyXCliExecute < MiniTest::Test + + def test_execute + assert_output(/Running/) {RubyXC.start(["execute" ,"--preload", "test/mains/source/add__4.rb"])} + end + end +end diff --git a/test/rubyx/test_interpret.rb b/test/rubyx/test_interpret.rb new file mode 100644 index 00000000..f8a3d861 --- /dev/null +++ b/test/rubyx/test_interpret.rb @@ -0,0 +1,11 @@ +require_relative "helper" +require "rubyx/rubyxc" + +module RubyX + class TestRubyXCliInterpret < MiniTest::Test + + def test_interpret + assert_output(/interpreting/) {RubyXC.start(["interpret" ,"--preload", "test/mains/source/add__4.rb"])} + end + end +end diff --git a/test/rubyx/test_rubyxc.rb b/test/rubyx/test_rubyxc.rb index 58034461..3e391f59 100644 --- a/test/rubyx/test_rubyxc.rb +++ b/test/rubyx/test_rubyxc.rb @@ -13,21 +13,5 @@ module RubyX def test_file_fail assert_output(nil , /No such file/) {RubyXC.start(["compile" , "hi"])} end - def test_file_open - assert_output(/compiling/) {RubyXC.start(["compile" , "test/mains/source/add__4.rb"])} - #File.delete "add__4.o" - end - def test_interpret - assert_output(/interpreting/) {RubyXC.start(["interpret" , "test/mains/source/add__4.rb"])} - end - def test_execute - assert_output(/Running/) {RubyXC.start(["execute" , "test/mains/source/add__4.rb"])} - end - def test_stats - out, err = capture_io {RubyXC.start(["stats" , "test/mains/source/add__4.rb"])} - assert out.include?("Space") , out - assert out.include?("Total") , out - assert out.include?("Objects=") , out - end end end diff --git a/test/rubyx/test_stats.rb b/test/rubyx/test_stats.rb new file mode 100644 index 00000000..cfda2e3d --- /dev/null +++ b/test/rubyx/test_stats.rb @@ -0,0 +1,14 @@ +require_relative "helper" +require "rubyx/rubyxc" + +module RubyX + class TestRubyXCliStats < MiniTest::Test + + def test_stats + out, err = capture_io {RubyXC.start(["stats" ,"--preload", "test/mains/source/add__4.rb"])} + assert out.include?("Space") , out + assert out.include?("Total") , out + assert out.include?("Objects=") , out + end + end +end diff --git a/test/vool/test_builtin.rb b/test/vool/test_builtin.rb index 0f284e06..8e7766a7 100644 --- a/test/vool/test_builtin.rb +++ b/test/vool/test_builtin.rb @@ -6,7 +6,7 @@ module Vool def setup Parfait.boot!(Parfait.default_test_options) - @code = Macro.boot_methods({}) + @code = Builtin.boot_methods({}) end def as_ruby @ruby = Ruby::RubyCompiler.compile(@code) diff --git a/test/vool/test_macro_expression.rb b/test/vool/test_macro_expression.rb index 955f9a66..789c6fe8 100644 --- a/test/vool/test_macro_expression.rb +++ b/test/vool/test_macro_expression.rb @@ -7,6 +7,9 @@ module Mom @a = arg @b = b end + def to_risc(compiler) + Risc.label("some" , "thing") + end end end @@ -30,6 +33,10 @@ module Vool assert_equal Vool::IntegerConstant , @ins.b.class assert_equal 1 , @ins.b.value end + def test_to_risc + comp = @compiler.to_risc + assert_equal Risc::MethodCompiler , comp.class + assert_equal :main , comp.callable.name + end end - end