From 17023fdeb1ce977c320f6d484cf4a446c33a5d99 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 12 Dec 2016 23:38:55 +0200 Subject: [PATCH] rename method to typed_method --- lib/elf/object_writer.rb | 2 +- lib/register/assembler.rb | 4 ++-- lib/register/boot.rb | 2 +- lib/register/builtin/README.md | 2 +- lib/register/machine.rb | 2 +- lib/typed/compiler.rb | 2 +- lib/typed/compiler/README.md | 2 +- lib/typed/parfait.rb | 2 +- lib/typed/parfait/behaviour.rb | 2 +- lib/typed/parfait/class.rb | 2 +- lib/typed/parfait/meta_class.rb | 2 +- lib/typed/parfait/{method.rb => typed_method.rb} | 13 +++++++++---- test/typed/parfait/test_class.rb | 4 ++-- test/typed/parfait/test_meta.rb | 4 ++-- test/typed/parfait/test_method.rb | 2 +- test/typed/parfait/test_space.rb | 2 +- 16 files changed, 27 insertions(+), 22 deletions(-) rename lib/typed/parfait/{method.rb => typed_method.rb} (80%) diff --git a/lib/elf/object_writer.rb b/lib/elf/object_writer.rb index 09dab7e1..b4844a76 100644 --- a/lib/elf/object_writer.rb +++ b/lib/elf/object_writer.rb @@ -38,7 +38,7 @@ module Elf end label += "=#{slot}" if slot.is_a?(Symbol) or slot.is_a?(String) add_symbol label , slot.position - if slot.is_a?(Parfait::Method) + if slot.is_a?(Parfait::TypedMethod) add_symbol slot.name.to_s , slot.binary.position end end diff --git a/lib/register/assembler.rb b/lib/register/assembler.rb index fc748eb7..f615b711 100644 --- a/lib/register/assembler.rb +++ b/lib/register/assembler.rb @@ -31,7 +31,7 @@ module Register def asseble_code_from( at ) @machine.objects.each do |id , objekt| - next unless objekt.is_a? Parfait::Method + next unless objekt.is_a? Parfait::TypedMethod objekt.binary.position = at objekt.instructions.set_position at + 12 # BinaryCode header len = objekt.instructions.total_byte_length @@ -90,7 +90,7 @@ module Register def try_write_create_binary # first we need to create the binary code for the methods @machine.objects.each do |id , objekt| - next unless objekt.is_a? Parfait::Method + next unless objekt.is_a? Parfait::TypedMethod assemble_binary_method(objekt) end @stream = StringIO.new diff --git a/lib/register/boot.rb b/lib/register/boot.rb index 35d21dd6..f5f8a9bb 100644 --- a/lib/register/boot.rb +++ b/lib/register/boot.rb @@ -128,7 +128,7 @@ module Register :Class => {:instance_methods => :List, :instance_type => :Type, :name => :Word, :super_class_name => :Word}, :Dictionary => {:keys => :List , :values => :List } , - :Method => {:name => :Word, :source => :Object, :instructions => :Object, :binary => :Object, + :TypedMethod => {:name => :Word, :source => :Object, :instructions => :Object, :binary => :Object, :arguments => :List , :for_class => :Class, :locals => :List } , :Value => {}, :Variable => {:value_type => :Class, :name => :Word , :value => :Object} diff --git a/lib/register/builtin/README.md b/lib/register/builtin/README.md index 92660d43..cbed6063 100644 --- a/lib/register/builtin/README.md +++ b/lib/register/builtin/README.md @@ -6,7 +6,7 @@ It is the other side of the parfait coin, part of the runtime. The functions are organized by their respective class and get loaded in boot_classes! , right at the start. (see register/boot.rb) -These functions return their code, ie a Parfait::Method with a MethodSource object, +These functions return their code, ie a Parfait::TypedMethod with a MethodSource object, which can then be called by ruby code as if it were a "normal" function. A normal ruby function is one that is parsed and transformed to code. But not all functionality can diff --git a/lib/register/machine.rb b/lib/register/machine.rb index a6363668..04633354 100644 --- a/lib/register/machine.rb +++ b/lib/register/machine.rb @@ -82,7 +82,7 @@ module Register end -Parfait::Method.class_eval do +Parfait::TypedMethod.class_eval do # for testing we need to reuse the main function (or do we?) # so remove the code that is there def clear_source diff --git a/lib/typed/compiler.rb b/lib/typed/compiler.rb index 547f1184..b0c9f7c1 100644 --- a/lib/typed/compiler.rb +++ b/lib/typed/compiler.rb @@ -17,7 +17,7 @@ module Typed # - an object graph containing all the Methods, their classes and Constants # # Some compile methods just add code, some may add Instructions while - # others instantiate Class and Method objects + # others instantiate Class and TypedMethod objects # # Everything in ruby is an statement, ie returns a value. So the effect of every compile # is that a value is put into the ReturnSlot of the current Message. diff --git a/lib/typed/compiler/README.md b/lib/typed/compiler/README.md index e1369a49..a8377648 100644 --- a/lib/typed/compiler/README.md +++ b/lib/typed/compiler/README.md @@ -51,7 +51,7 @@ basically meaning pinned to a register, the Message. One can think of the Message as an oo replacement of the stack. -When a Method needs to make a call, it creates a NewMessage object. +When a TypedMethod needs to make a call, it creates a NewMessage object. Messages contain return addresses (yes, plural) and arguments. The important thing here is that Messages and Frames are normal objects. diff --git a/lib/typed/parfait.rb b/lib/typed/parfait.rb index 08e0b8d8..4cf1bd2c 100644 --- a/lib/typed/parfait.rb +++ b/lib/typed/parfait.rb @@ -10,7 +10,7 @@ require_relative "parfait/class" require_relative "parfait/list" require_relative "parfait/word" require_relative "parfait/binary_code" -require_relative "parfait/method" +require_relative "parfait/typed_method" require_relative "parfait/meta_class" require_relative "parfait/variable" require_relative "parfait/dictionary" diff --git a/lib/typed/parfait/behaviour.rb b/lib/typed/parfait/behaviour.rb index cab3e5a0..12fb1d9c 100644 --- a/lib/typed/parfait/behaviour.rb +++ b/lib/typed/parfait/behaviour.rb @@ -29,7 +29,7 @@ module Parfait end def add_instance_method method - raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Method + raise "not a method #{method.class} #{method.inspect}" unless method.is_a? TypedMethod raise "syserr #{method.name.class}" unless method.name.is_a? Symbol if self.is_a?(Class) and (method.for_class != self) raise "Adding to wrong class, should be #{method.for_class}" diff --git a/lib/typed/parfait/class.rb b/lib/typed/parfait/class.rb index f8829e36..a4e299ee 100644 --- a/lib/typed/parfait/class.rb +++ b/lib/typed/parfait/class.rb @@ -49,7 +49,7 @@ module Parfait clazz = instance_type().object_class() raise "??? #{method_name}" unless clazz #puts "Self: #{self.class} clazz: #{clazz.name}" - add_instance_method Method.new( clazz , method_name , arguments ) + add_instance_method TypedMethod.new( clazz , method_name , arguments ) end # this needs to be done during booting as we can't have all the classes and superclassses diff --git a/lib/typed/parfait/meta_class.rb b/lib/typed/parfait/meta_class.rb index 65fe3295..aad9b293 100644 --- a/lib/typed/parfait/meta_class.rb +++ b/lib/typed/parfait/meta_class.rb @@ -60,7 +60,7 @@ module Parfait def create_instance_method method_name , arguments raise "create_instance_method #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol) log.debug "Add_method: #{method_name} clazz: #{self.name}" - add_instance_method Method.new( self , method_name , arguments ) + add_instance_method TypedMethod.new( self , method_name , arguments ) end diff --git a/lib/typed/parfait/method.rb b/lib/typed/parfait/typed_method.rb similarity index 80% rename from lib/typed/parfait/method.rb rename to lib/typed/parfait/typed_method.rb index 7473990f..96d99c9b 100644 --- a/lib/typed/parfait/method.rb +++ b/lib/typed/parfait/typed_method.rb @@ -1,5 +1,10 @@ -# A Method (at runtime , sis in Parfait) is static object that primarily holds the executable -# code. +# A TypedMethod is static object that primarily holds the executable code. +# It is called typed, because all arguments and variables it uses are typed. +# (Type means basic type, ie integer or reference) + +# It's relation to the method a ruby programmer knows (called RubyMethod) is many to one, +# meaning one RubyMethod (untyped) has many TypedMethod implementations. +# The RubyMethod only holds ruby code, no binary. # For reflection also holds arguments and such @@ -13,10 +18,10 @@ module Parfait # known local variable names # executable code - # ps, the compiler injects its own info, see Register::MethodSource + # ps, the compiler injects its own info - class Method < Object + class TypedMethod < Object attributes [:name , :source , :instructions , :binary ,:arguments , :for_class, :locals ] # not part of the parfait model, hence ruby accessor diff --git a/test/typed/parfait/test_class.rb b/test/typed/parfait/test_class.rb index 764ea0a8..6d347ffe 100644 --- a/test/typed/parfait/test_class.rb +++ b/test/typed/parfait/test_class.rb @@ -9,7 +9,7 @@ class TestClass < MiniTest::Test def foo_method for_class = :Try args = Parfait.new_list [ Parfait::Variable.new(:Integer , :bar )] - ::Parfait::Method.new @space.get_class_by_name(for_class) , :foo , args + ::Parfait::TypedMethod.new @space.get_class_by_name(for_class) , :foo , args end def test_type_forclass @@ -47,7 +47,7 @@ class TestClass < MiniTest::Test end def test_method_get test_add_method - assert_equal Parfait::Method , @try.get_instance_method(:foo).class + assert_equal Parfait::TypedMethod , @try.get_instance_method(:foo).class end def test_method_get_nothere assert_nil @try.get_instance_method(:foo) diff --git a/test/typed/parfait/test_meta.rb b/test/typed/parfait/test_meta.rb index 03703142..37b98709 100644 --- a/test/typed/parfait/test_meta.rb +++ b/test/typed/parfait/test_meta.rb @@ -9,7 +9,7 @@ class TestMeta < MiniTest::Test def foo_method for_class = :Try args = Parfait.new_list [ Parfait::Variable.new(:Integer , :bar )] - ::Parfait::Method.new @space.get_class_by_name(for_class) , :foo , args + ::Parfait::TypedMethod.new @space.get_class_by_name(for_class) , :foo , args end def test_meta @@ -44,7 +44,7 @@ class TestMeta < MiniTest::Test end def test_method_get test_add_method - assert_equal Parfait::Method , @try.get_instance_method(:foo).class + assert_equal Parfait::TypedMethod , @try.get_instance_method(:foo).class end def test_method_get_nothere assert_nil @try.get_instance_method(:foo) diff --git a/test/typed/parfait/test_method.rb b/test/typed/parfait/test_method.rb index 14f37a7b..e9c603a6 100644 --- a/test/typed/parfait/test_method.rb +++ b/test/typed/parfait/test_method.rb @@ -5,7 +5,7 @@ class TestMethod < MiniTest::Test def setup obj = Register.machine.space.get_class_by_name(:Object) args = Parfait.new_list [ Parfait::Variable.new(:Integer , :bar )] - @method = ::Parfait::Method.new obj , :foo , args + @method = ::Parfait::TypedMethod.new obj , :foo , args end def test_method_name diff --git a/test/typed/parfait/test_space.rb b/test/typed/parfait/test_space.rb index fa5544be..d911736a 100644 --- a/test/typed/parfait/test_space.rb +++ b/test/typed/parfait/test_space.rb @@ -6,7 +6,7 @@ class TestSpace < MiniTest::Test @machine = Register.machine.boot end def classes - [:Kernel,:Word,:List,:Message,:Frame,:Type,:Object,:Class,:Dictionary,:Method , :Integer] + [:Kernel,:Word,:List,:Message,:Frame,:Type,:Object,:Class,:Dictionary,:TypedMethod , :Integer] end def test_booted assert_equal true , @machine.booted