rename method to typed_method

This commit is contained in:
Torsten Ruger 2016-12-12 23:38:55 +02:00
parent 4ff684b6a4
commit 17023fdeb1
16 changed files with 27 additions and 22 deletions

View File

@ -38,7 +38,7 @@ module Elf
end end
label += "=#{slot}" if slot.is_a?(Symbol) or slot.is_a?(String) label += "=#{slot}" if slot.is_a?(Symbol) or slot.is_a?(String)
add_symbol label , slot.position 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 add_symbol slot.name.to_s , slot.binary.position
end end
end end

View File

@ -31,7 +31,7 @@ module Register
def asseble_code_from( at ) def asseble_code_from( at )
@machine.objects.each do |id , objekt| @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.binary.position = at
objekt.instructions.set_position at + 12 # BinaryCode header objekt.instructions.set_position at + 12 # BinaryCode header
len = objekt.instructions.total_byte_length len = objekt.instructions.total_byte_length
@ -90,7 +90,7 @@ module Register
def try_write_create_binary def try_write_create_binary
# first we need to create the binary code for the methods # first we need to create the binary code for the methods
@machine.objects.each do |id , objekt| @machine.objects.each do |id , objekt|
next unless objekt.is_a? Parfait::Method next unless objekt.is_a? Parfait::TypedMethod
assemble_binary_method(objekt) assemble_binary_method(objekt)
end end
@stream = StringIO.new @stream = StringIO.new

View File

@ -128,7 +128,7 @@ module Register
:Class => {:instance_methods => :List, :instance_type => :Type, :name => :Word, :Class => {:instance_methods => :List, :instance_type => :Type, :name => :Word,
:super_class_name => :Word}, :super_class_name => :Word},
:Dictionary => {:keys => :List , :values => :List } , :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 } , :arguments => :List , :for_class => :Class, :locals => :List } ,
:Value => {}, :Value => {},
:Variable => {:value_type => :Class, :name => :Word , :value => :Object} :Variable => {:value_type => :Class, :name => :Word , :value => :Object}

View File

@ -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! , The functions are organized by their respective class and get loaded in boot_classes! ,
right at the start. (see register/boot.rb) 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. 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 A normal ruby function is one that is parsed and transformed to code. But not all functionality can

View File

@ -82,7 +82,7 @@ module Register
end end
Parfait::Method.class_eval do Parfait::TypedMethod.class_eval do
# for testing we need to reuse the main function (or do we?) # for testing we need to reuse the main function (or do we?)
# so remove the code that is there # so remove the code that is there
def clear_source def clear_source

View File

@ -17,7 +17,7 @@ module Typed
# - an object graph containing all the Methods, their classes and Constants # - an object graph containing all the Methods, their classes and Constants
# #
# Some compile methods just add code, some may add Instructions while # 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 # 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. # is that a value is put into the ReturnSlot of the current Message.

View File

@ -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. 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. Messages contain return addresses (yes, plural) and arguments.
The important thing here is that Messages and Frames are normal objects. The important thing here is that Messages and Frames are normal objects.

View File

@ -10,7 +10,7 @@ require_relative "parfait/class"
require_relative "parfait/list" require_relative "parfait/list"
require_relative "parfait/word" require_relative "parfait/word"
require_relative "parfait/binary_code" require_relative "parfait/binary_code"
require_relative "parfait/method" require_relative "parfait/typed_method"
require_relative "parfait/meta_class" require_relative "parfait/meta_class"
require_relative "parfait/variable" require_relative "parfait/variable"
require_relative "parfait/dictionary" require_relative "parfait/dictionary"

View File

@ -29,7 +29,7 @@ module Parfait
end end
def add_instance_method method 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 raise "syserr #{method.name.class}" unless method.name.is_a? Symbol
if self.is_a?(Class) and (method.for_class != self) if self.is_a?(Class) and (method.for_class != self)
raise "Adding to wrong class, should be #{method.for_class}" raise "Adding to wrong class, should be #{method.for_class}"

View File

@ -49,7 +49,7 @@ module Parfait
clazz = instance_type().object_class() clazz = instance_type().object_class()
raise "??? #{method_name}" unless clazz raise "??? #{method_name}" unless clazz
#puts "Self: #{self.class} clazz: #{clazz.name}" #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 end
# this needs to be done during booting as we can't have all the classes and superclassses # this needs to be done during booting as we can't have all the classes and superclassses

View File

@ -60,7 +60,7 @@ module Parfait
def create_instance_method method_name , arguments def create_instance_method method_name , arguments
raise "create_instance_method #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol) raise "create_instance_method #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol)
log.debug "Add_method: #{method_name} clazz: #{self.name}" 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 end

View File

@ -1,5 +1,10 @@
# A Method (at runtime , sis in Parfait) is static object that primarily holds the executable # A TypedMethod is static object that primarily holds the executable code.
# 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 # For reflection also holds arguments and such
@ -13,10 +18,10 @@ module Parfait
# known local variable names # known local variable names
# executable code # 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 ] attributes [:name , :source , :instructions , :binary ,:arguments , :for_class, :locals ]
# not part of the parfait model, hence ruby accessor # not part of the parfait model, hence ruby accessor

View File

@ -9,7 +9,7 @@ class TestClass < MiniTest::Test
def foo_method for_class = :Try def foo_method for_class = :Try
args = Parfait.new_list [ Parfait::Variable.new(:Integer , :bar )] 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 end
def test_type_forclass def test_type_forclass
@ -47,7 +47,7 @@ class TestClass < MiniTest::Test
end end
def test_method_get def test_method_get
test_add_method test_add_method
assert_equal Parfait::Method , @try.get_instance_method(:foo).class assert_equal Parfait::TypedMethod , @try.get_instance_method(:foo).class
end end
def test_method_get_nothere def test_method_get_nothere
assert_nil @try.get_instance_method(:foo) assert_nil @try.get_instance_method(:foo)

View File

@ -9,7 +9,7 @@ class TestMeta < MiniTest::Test
def foo_method for_class = :Try def foo_method for_class = :Try
args = Parfait.new_list [ Parfait::Variable.new(:Integer , :bar )] 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 end
def test_meta def test_meta
@ -44,7 +44,7 @@ class TestMeta < MiniTest::Test
end end
def test_method_get def test_method_get
test_add_method test_add_method
assert_equal Parfait::Method , @try.get_instance_method(:foo).class assert_equal Parfait::TypedMethod , @try.get_instance_method(:foo).class
end end
def test_method_get_nothere def test_method_get_nothere
assert_nil @try.get_instance_method(:foo) assert_nil @try.get_instance_method(:foo)

View File

@ -5,7 +5,7 @@ class TestMethod < MiniTest::Test
def setup def setup
obj = Register.machine.space.get_class_by_name(:Object) obj = Register.machine.space.get_class_by_name(:Object)
args = Parfait.new_list [ Parfait::Variable.new(:Integer , :bar )] args = Parfait.new_list [ Parfait::Variable.new(:Integer , :bar )]
@method = ::Parfait::Method.new obj , :foo , args @method = ::Parfait::TypedMethod.new obj , :foo , args
end end
def test_method_name def test_method_name

View File

@ -6,7 +6,7 @@ class TestSpace < MiniTest::Test
@machine = Register.machine.boot @machine = Register.machine.boot
end end
def classes 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 end
def test_booted def test_booted
assert_equal true , @machine.booted assert_equal true , @machine.booted