Builtin is no more, final conversions done

All preloading where it needs to be
(some)tests for the preload
split compiler test
remembered binary tests (usually just run on travis)
This commit is contained in:
Torsten Rüger 2019-09-13 20:34:41 +03:00
parent 8af17a69ea
commit 1ee01622c3
15 changed files with 74 additions and 34 deletions

View File

@ -16,7 +16,7 @@ module Mom
# lazily instantiate the compiler for init function # lazily instantiate the compiler for init function
def init_compiler def init_compiler
@init_compilers ||= create_init_compiler @init_compilers ||= MomCollection.create_init_compiler
end end
# Return all compilers, namely the MethodCompilers passed in, plus the # Return all compilers, namely the MethodCompilers passed in, plus the
@ -47,8 +47,8 @@ module Mom
# - load fist message, set up Space as receiver # - load fist message, set up Space as receiver
# - call main, ie set up message for that etc # - call main, ie set up message for that etc
# - exit (exit_sequence) which passes a machine int out to c # - exit (exit_sequence) which passes a machine int out to c
def create_init_compiler def self.create_init_compiler
compiler = self.class.compiler_for(:Object,:__init__ ,{}) compiler = compiler_for(:Object,:__init__ ,{})
compiler._reset_for_init # no return, just for init compiler._reset_for_init # no return, just for init
compiler.add_code Init.new("missing") compiler.add_code Init.new("missing")
return compiler return compiler

View File

@ -24,8 +24,10 @@ class RubyXC < Thor
rescue rescue
fail MalformattedArgumentError , "No such file #{file}" fail MalformattedArgumentError , "No such file #{file}"
end end
code = get_preload + ruby
compiler = RubyX::RubyXCompiler.new(extract_options) compiler = RubyX::RubyXCompiler.new(extract_options)
linker = compiler.ruby_to_binary(ruby, :interpreter) linker = compiler.ruby_to_binary(code, :interpreter)
puts "interpreting #{file}" puts "interpreting #{file}"

View File

@ -105,5 +105,8 @@ module Vool
def ct_type def ct_type
Parfait.object_space.get_type_by_class_name(:Word) Parfait.object_space.get_type_by_class_name(:Word)
end end
def to_s(depth = 0)
":#{@value}"
end
end end
end end

View File

@ -14,7 +14,6 @@ module Vool
{ {
"Object.get" => "def get_internal_word(at); X.get_internal_word;end", "Object.get" => "def get_internal_word(at); X.get_internal_word;end",
"Object.missing" => "def method_missing(at); X.method_missing;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", "Object.exit" => "def exit; X.exit;end",
"Integer.div4" => "def div4; X.div4;end", "Integer.div4" => "def div4; X.div4;end",
"Integer.div10" => "def div10; X.div10;end", "Integer.div10" => "def div10; X.div10;end",
@ -32,7 +31,7 @@ module Vool
"Word.put" => "def putstring(at); X.putstring;end", "Word.put" => "def putstring(at); X.putstring;end",
"Word.set" => "def set_internal_byte(at, val); X.set_internal_byte;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", "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 end
def self.builtin_code def self.builtin_code

View File

@ -3,10 +3,6 @@ require_relative "../helper"
module Elf module Elf
class FullTest < MiniTest::Test class FullTest < MiniTest::Test
DEBUG = false
def setup
end
def in_space(input) def in_space(input)
"class Space; #{input} ; end" "class Space; #{input} ; end"

View File

@ -49,8 +49,9 @@ module Mains
def run_code(input , name ) def run_code(input , name )
puts "Compiling #{name}.o" if DEBUG 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 = Elf::ObjectWriter.new(linker)
writer.save "mains.o" writer.save "mains.o"

View File

@ -4,18 +4,19 @@ module Mom
module Builtin module Builtin
class TestObjectInitRisc < BootTest class TestObjectInitRisc < BootTest
def setup def setup
super Parfait.boot!(Parfait.default_test_options)
@method = get_compiler("Object",:init) get_compiler("Space",:main)
@method = MomCollection.create_init_compiler
end end
def test_mom_length def test_mom_length
assert_equal :__init__ , @method.callable.name assert_equal :__init__ , @method.callable.name
assert_equal 7 , @method.mom_instructions.length assert_equal 2 , @method.mom_instructions.length
end end
def test_compile def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class
end end
def test_risc_length 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 end
end end

View File

@ -99,7 +99,7 @@ module Ruby
assert_equal "'string'" , compile_const( "'string'") assert_equal "'string'" , compile_const( "'string'")
end end
def test_sym def test_sym
assert_equal "'symbol'" , compile_const( ":symbol") assert_equal ":symbol" , compile_const( ":symbol")
end end
def test_nil def test_nil
assert_equal "nil" , compile_const( "nil") assert_equal "nil" , compile_const( "nil")

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -13,21 +13,5 @@ module RubyX
def test_file_fail def test_file_fail
assert_output(nil , /No such file/) {RubyXC.start(["compile" , "hi"])} assert_output(nil , /No such file/) {RubyXC.start(["compile" , "hi"])}
end 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
end end

14
test/rubyx/test_stats.rb Normal file
View File

@ -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

View File

@ -6,7 +6,7 @@ module Vool
def setup def setup
Parfait.boot!(Parfait.default_test_options) Parfait.boot!(Parfait.default_test_options)
@code = Macro.boot_methods({}) @code = Builtin.boot_methods({})
end end
def as_ruby def as_ruby
@ruby = Ruby::RubyCompiler.compile(@code) @ruby = Ruby::RubyCompiler.compile(@code)

View File

@ -7,6 +7,9 @@ module Mom
@a = arg @a = arg
@b = b @b = b
end end
def to_risc(compiler)
Risc.label("some" , "thing")
end
end end
end end
@ -30,6 +33,10 @@ module Vool
assert_equal Vool::IntegerConstant , @ins.b.class assert_equal Vool::IntegerConstant , @ins.b.class
assert_equal 1 , @ins.b.value assert_equal 1 , @ins.b.value
end end
def test_to_risc
comp = @compiler.to_risc
assert_equal Risc::MethodCompiler , comp.class
assert_equal :main , comp.callable.name
end
end end
end end