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
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

View File

@ -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

View File

@ -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}

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! ,
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

View File

@ -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

View File

@ -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.

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.
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.

View File

@ -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"

View File

@ -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}"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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