From 85ddf534295557f859457e20716181318aa79df0 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 28 Mar 2018 12:49:17 +0300 Subject: [PATCH] create methods with binaries and extend them later Binary is new jump target for function call --- lib/parfait/binary_code.rb | 7 +++++-- lib/parfait/typed_method.rb | 3 ++- test/parfait/test_binary_code.rb | 5 +++++ test/parfait/test_typed_method.rb | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/parfait/binary_code.rb b/lib/parfait/binary_code.rb index ec655dbc..ae66dbe1 100644 --- a/lib/parfait/binary_code.rb +++ b/lib/parfait/binary_code.rb @@ -11,11 +11,14 @@ module Parfait def initialize(total_size) super() + extend_to(total_size) + #puts "Init with #{total_size} for #{object_id}" + (1..(data_length+1)).each{ |index| set_word(index , 0) } + end + def extend_to(total_size) if total_size > self.data_length @next = BinaryCode.new(total_size - data_length) end - #puts "Init with #{total_size} for #{object_id}" - (1..(data_length+1)).each{ |index| set_word(index , 0) } end def to_s "BinaryCode #{}" diff --git a/lib/parfait/typed_method.rb b/lib/parfait/typed_method.rb index 963d56f9..b8979d47 100644 --- a/lib/parfait/typed_method.rb +++ b/lib/parfait/typed_method.rb @@ -43,6 +43,7 @@ module Parfait raise "Wrong frame type, expect Type not #{frame.class}" unless frame.is_a? Type @arguments = arguments @frame = frame + @binary = BinaryCode.new(0) source = "_init_method" name = "#{@for_type.name}.#{@name}" @risc_instructions = Risc.label(source, name) @@ -58,7 +59,7 @@ module Parfait nekst = nekst.next end total = @cpu_instructions.total_byte_length / 4 + 1 - @binary = BinaryCode.new( total ) + @binary.extend_to( total ) @cpu_instructions end diff --git a/test/parfait/test_binary_code.rb b/test/parfait/test_binary_code.rb index 7c72be72..f571efd8 100644 --- a/test/parfait/test_binary_code.rb +++ b/test/parfait/test_binary_code.rb @@ -64,5 +64,10 @@ module Parfait @code.set_word(20,1) assert_equal 1 , @code.get_word(20) end + def test_extend + @code.extend_to(20) + assert @code.next + assert_nil @code.next.next + end end end diff --git a/test/parfait/test_typed_method.rb b/test/parfait/test_typed_method.rb index 90da3e9d..e36a98fd 100644 --- a/test/parfait/test_typed_method.rb +++ b/test/parfait/test_typed_method.rb @@ -3,6 +3,7 @@ require_relative "../helper" class TestMethod < MiniTest::Test def setup + Risc.machine.boot obj = Parfait.object_space.get_class_by_name(:Object).instance_type args = Parfait::Type.for_hash( obj.object_class , { bar: :Integer , foo: :Type}) frame = Parfait::Type.for_hash( obj.object_class , { local_bar: :Integer , local_foo: :Type}) @@ -90,5 +91,7 @@ class TestMethod < MiniTest::Test index = @method.has_local(:local_bar) assert_equal :Integer , @method.frame_type(index) end - + def test_created_with_binary + assert @method.binary + end end