starting to move builtin into parfait
single object method for now little framework next
This commit is contained in:
parent
feeb9332a2
commit
2c4f040654
@ -12,4 +12,15 @@ module Mom
|
|||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
require_relative "../helper"
|
require_relative "../helper"
|
||||||
|
|
||||||
module Risc
|
module Risc
|
||||||
class TestCollector < MiniTest::Test
|
module CollectT
|
||||||
|
def boot( num )
|
||||||
def setup
|
opt = Parfait.default_test_options
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
if(num)
|
||||||
|
opt[:Integer] = 400
|
||||||
|
opt[:Message] = 400
|
||||||
|
end
|
||||||
|
Parfait.boot!(opt)
|
||||||
Mom.boot!
|
Mom.boot!
|
||||||
Risc.boot!
|
Risc.boot!
|
||||||
@linker = Mom::MomCollection.new.to_risc.translate(:arm)
|
@linker = Mom::MomCollection.new.to_risc.translate(:arm)
|
||||||
@ -12,7 +16,29 @@ module Risc
|
|||||||
|
|
||||||
def test_simple_collect
|
def test_simple_collect
|
||||||
objects = Collector.collect_space(@linker)
|
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
|
end
|
||||||
|
|
||||||
def test_collect_all_types
|
def test_collect_all_types
|
||||||
@ -35,43 +61,16 @@ module Risc
|
|||||||
assert !position.valid?
|
assert !position.valid?
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
class TestBigCollector < MiniTest::Test
|
class TestBigCollector < MiniTest::Test
|
||||||
|
include CollectT
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
opt = Parfait.default_test_options
|
boot(400)
|
||||||
opt[:factory] = 400
|
|
||||||
Parfait.boot!(opt)
|
|
||||||
Mom.boot!
|
|
||||||
Risc.boot!
|
|
||||||
@linker = Mom::MomCollection.new.to_risc.translate(:arm)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_simple_collect
|
def len
|
||||||
objects = Collector.collect_space(@linker)
|
3044
|
||||||
assert_equal 1564, objects.length , objects.length.to_s
|
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
24
test/rubyx/builtin/README.md
Normal file
24
test/rubyx/builtin/README.md
Normal 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.)
|
1
test/rubyx/builtin/helper.rb
Normal file
1
test/rubyx/builtin/helper.rb
Normal file
@ -0,0 +1 @@
|
|||||||
|
require_relative "../helper"
|
38
test/rubyx/builtin/test_object_get.rb
Normal file
38
test/rubyx/builtin/test_object_get.rb
Normal 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
|
@ -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
|
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
|
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 /
|
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.
|
Alas, this is for another day.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user