starting to move builtin into parfait

single object method for now
little framework next
This commit is contained in:
Torsten Rüger 2019-09-10 20:40:41 +03:00
parent feeb9332a2
commit 2c4f040654
6 changed files with 110 additions and 37 deletions

View File

@ -12,4 +12,15 @@ module Mom
end
end
end
class GetInternalWord < Instruction
def to_risc(compiler)
compiler.builder(compiler.source).build do
object! << message[:receiver]
integer! << message[:arg1] #"at" is at index 0
integer.reduce_int
object << object[integer]
message[:return_value] << object
end
end
end
end

View File

@ -1,10 +1,14 @@
require_relative "../helper"
module Risc
class TestCollector < MiniTest::Test
def setup
Parfait.boot!(Parfait.default_test_options)
module CollectT
def boot( num )
opt = Parfait.default_test_options
if(num)
opt[:Integer] = 400
opt[:Message] = 400
end
Parfait.boot!(opt)
Mom.boot!
Risc.boot!
@linker = Mom::MomCollection.new.to_risc.translate(:arm)
@ -12,7 +16,29 @@ module Risc
def test_simple_collect
objects = Collector.collect_space(@linker)
assert_equal 1564 , objects.length , objects.length.to_s
assert_equal len , objects.length , objects.length.to_s
end
def test_integer_positions
objects = Collector.collect_space(@linker)
int = Parfait.object_space.get_next_for(:Integer)
count = 0
while(int)
count += 1
assert Position.set?(int) , "INT #{int.object_id.to_s(16)} , count #{count}"
int = int.next_integer
end
end
end
class TestCollector < MiniTest::Test
include CollectT
def setup
boot(nil)
end
def len
1564
end
def test_collect_all_types
@ -35,43 +61,16 @@ module Risc
assert !position.valid?
end
end
def test_integer_positions
objects = Collector.collect_space(@linker)
int = Parfait.object_space.get_next_for(:Integer)
count = 0
while(int)
count += 1
assert Position.set?(int) , "INT #{int.object_id.to_s(16)} , count #{count}"
int = int.next_integer
end
end
end
class TestBigCollector < MiniTest::Test
include CollectT
def setup
opt = Parfait.default_test_options
opt[:factory] = 400
Parfait.boot!(opt)
Mom.boot!
Risc.boot!
@linker = Mom::MomCollection.new.to_risc.translate(:arm)
boot(400)
end
def test_simple_collect
objects = Collector.collect_space(@linker)
assert_equal 1564, objects.length , objects.length.to_s
def len
3044
end
def test_integer_positions
objects = Collector.collect_space(@linker)
int = Parfait.object_space.get_next_for(:Integer)
count = 0
while(int)
count += 1
assert Position.set?(int) , "INT #{int.object_id.to_s(16)} , count #{count}"
int = int.next_integer
end
end
end
end

View File

@ -0,0 +1,24 @@
## Pre - testing builtin
In the process of moving builtin from mom to parfait. Considering we started at risc, this
is progress.
Builtin methods should (will) use the Macro idea to actually become code and land in
the parfait code.
On the way there, we start by Testing and moving the old ones. Since we want to be able
to test some methods even after the move, without parsing/processing the whole of parfait
we have to have a method of "injecting" the single? methods.
## Mom level
There a re two test levels to every method. Mom being the first, where we basically just
see if the right Mom instruction has been generated
## Risc
Second level is to check the actual risc instructions that are generated.
Current tests test only the length, but there are some tests in interpreter dir that
test actual instructions. Should move those, as they are too detailed in a mains
(make the interpreter tests less brittle while at it.)

View File

@ -0,0 +1 @@
require_relative "../helper"

View File

@ -0,0 +1,38 @@
require_relative "helper"
module RubyX
module Builtin
class TestObjectGet < MiniTest::Test
def setup
get = <<GET
class Object
def get_internal_word(at)
X.get_internal_word
end
end
GET
@mom = RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(get)
end
def compiler
@mom.method_compilers.first
end
def test_mom_col
assert_equal Mom::MomCollection , @mom.class
end
def test_mom_com
assert_equal Mom::MethodCompiler , @mom.method_compilers.first.class
end
def test_mom_meth
assert_equal :get_internal_word , compiler.callable.name
end
def test_instr_len
assert_equal 7 , compiler.mom_instructions.length
end
def test_instr_get
assert_equal Mom::GetInternalWord , compiler.mom_instructions.next.class
end
def test_risc
assert_equal 18 , compiler.to_risc.risc_instructions.length
end
end
end
end

View File

@ -20,6 +20,6 @@ the RubyXCompiler parfait load list.
The next step is to test the compiled parfait. Since we have tests, the best way would
be to parse and execute the tests. This would involve creating a mini MiniTest and some
fancy footwork in the compilation. But it should be possible to create one executable /
interpreted test for each of the exising Parfait test.
interpreted test for each of the existing Parfait test.
Alas, this is for another day.