From 2c4f040654837ef462710309fcaa456714f7aff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Tue, 10 Sep 2019 20:40:41 +0300 Subject: [PATCH] starting to move builtin into parfait single object method for now little framework next --- lib/mom/builtin/get_internal_word.rb | 11 +++++ test/risc/test_collector.rb | 71 +++++++++++++-------------- test/rubyx/builtin/README.md | 24 +++++++++ test/rubyx/builtin/helper.rb | 1 + test/rubyx/builtin/test_object_get.rb | 38 ++++++++++++++ test/rubyx/parfait/README.md | 2 +- 6 files changed, 110 insertions(+), 37 deletions(-) create mode 100644 test/rubyx/builtin/README.md create mode 100644 test/rubyx/builtin/helper.rb create mode 100644 test/rubyx/builtin/test_object_get.rb diff --git a/lib/mom/builtin/get_internal_word.rb b/lib/mom/builtin/get_internal_word.rb index e41cbefb..66df3d5d 100644 --- a/lib/mom/builtin/get_internal_word.rb +++ b/lib/mom/builtin/get_internal_word.rb @@ -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 diff --git a/test/risc/test_collector.rb b/test/risc/test_collector.rb index b184728e..00d6e507 100644 --- a/test/risc/test_collector.rb +++ b/test/risc/test_collector.rb @@ -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 diff --git a/test/rubyx/builtin/README.md b/test/rubyx/builtin/README.md new file mode 100644 index 00000000..98bba947 --- /dev/null +++ b/test/rubyx/builtin/README.md @@ -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.) diff --git a/test/rubyx/builtin/helper.rb b/test/rubyx/builtin/helper.rb new file mode 100644 index 00000000..26258082 --- /dev/null +++ b/test/rubyx/builtin/helper.rb @@ -0,0 +1 @@ +require_relative "../helper" diff --git a/test/rubyx/builtin/test_object_get.rb b/test/rubyx/builtin/test_object_get.rb new file mode 100644 index 00000000..f7742a39 --- /dev/null +++ b/test/rubyx/builtin/test_object_get.rb @@ -0,0 +1,38 @@ +require_relative "helper" +module RubyX + module Builtin + class TestObjectGet < MiniTest::Test + def setup + get = <