removed unused NamedList
args and locals got inlined into message, forgot to delete then ripples out due to type creation small type class api change, more ripples, but also more consistent
This commit is contained in:
@ -1,42 +0,0 @@
|
||||
|
||||
# A NamedList is used to store local variables and arguments when calling methods.
|
||||
# Also temporary variables, which are local variables named by the system
|
||||
|
||||
# The items are named (and typed) by the objects type instance. In effect the
|
||||
# variables are like instance variables
|
||||
|
||||
# A Message with is arguments, and a NamedList make up the two sides of message passing:
|
||||
# A Message (see details there) is created by the caller and control is transferred
|
||||
# A NamedList is created by the receiver
|
||||
# PS: it turns out that both messages and named_lists are created at compile, not run-time, and
|
||||
# just constantly reused. Each message has two named_list object ready and is also linked
|
||||
# to the next message.
|
||||
# The better way to say above is that a message is *used* by the caller, and a named_list
|
||||
# by the callee.
|
||||
|
||||
# Also at runtime Messages and NamedLists remain completely "normal" objects.
|
||||
# Ie they have have type and instances and so on.*
|
||||
# Which resolves the dichotomy of objects on the stack or heap. Sama sama.
|
||||
#
|
||||
# *Alas the type for each call instance is unique.
|
||||
#
|
||||
module Parfait
|
||||
class NamedList < Object
|
||||
|
||||
def self.memory_size
|
||||
16
|
||||
end
|
||||
|
||||
def to_s
|
||||
str = "NamedList len= #{get_length}"
|
||||
str += " at #{Risc::Position.get(self)}" if Risc::Position.set?(self)
|
||||
end
|
||||
def get_length
|
||||
get_type.get_length - 1
|
||||
end
|
||||
def self.type_for( arguments )
|
||||
my_class = Parfait.object_space.classes[:NamedList]
|
||||
Type.for_hash( my_class , {type: my_class.instance_type}.merge(arguments))
|
||||
end
|
||||
end
|
||||
end
|
@ -151,10 +151,17 @@ module Parfait
|
||||
|
||||
# this is the way to instantiate classes (not Parfait::Class.new)
|
||||
# so we get and keep exactly one per name
|
||||
#
|
||||
# The superclass must be known when the class is created, or it raises an error.
|
||||
# The class is initiated with the type of the superclass (hence above)
|
||||
#
|
||||
# Only Vool::ClassExpression really ever creates classes and "grows" the type
|
||||
# according to the instances it finds, see there
|
||||
#
|
||||
def create_class( name , superclass = nil )
|
||||
raise "create_class #{name.class}" unless name.is_a? Symbol
|
||||
superclass = :Object unless superclass
|
||||
raise "create_class #{superclass.class}" unless superclass.is_a? Symbol
|
||||
raise "create_class failed for #{name}:#{superclass.class}" unless superclass.is_a? Symbol
|
||||
type = get_type_by_class_name(superclass)
|
||||
c = Class.new(name , superclass , type )
|
||||
@classes[name] = c
|
||||
|
@ -42,12 +42,19 @@ module Parfait
|
||||
5
|
||||
end
|
||||
|
||||
def self.for_hash( object_class , hash)
|
||||
def self.for_hash( hash , object_class = :Object)
|
||||
name = object_class
|
||||
if(object_class.is_a?(Symbol))
|
||||
object_class = Parfait.object_space.get_class_by_name(object_class)
|
||||
end
|
||||
raise "No such class #{name}" unless object_class
|
||||
hash = {type: object_class.name }.merge(hash) unless hash[:type]
|
||||
new_type = Type.new( object_class , hash)
|
||||
Parfait.object_space.add_type(new_type)
|
||||
end
|
||||
|
||||
# should not be called directly. Use Type.for_hash instead, that adds the
|
||||
# type to the global list
|
||||
def initialize( object_class , hash )
|
||||
super()
|
||||
set_object_class( object_class)
|
||||
@ -185,7 +192,7 @@ module Parfait
|
||||
raise "No nil type" unless type
|
||||
hash = to_hash
|
||||
hash[name] = type
|
||||
return Type.for_hash( object_class , hash)
|
||||
return Type.for_hash( hash , object_class)
|
||||
end
|
||||
|
||||
def set_object_class(oc)
|
||||
|
@ -156,7 +156,7 @@ module Parfait
|
||||
attribute_name: :Word , page_size: :Integer },
|
||||
Integer: {next_integer: :Integer},
|
||||
List: {indexed_length: :Integer , next_list: :List} ,
|
||||
Message: { next_message: :Message, receiver: :Object, frame: :NamedList ,
|
||||
Message: { next_message: :Message, receiver: :Object, frame: :Object ,
|
||||
return_address: :Integer, return_value: :Object,
|
||||
caller: :Message , method: :TypedMethod ,
|
||||
arguments_given: :Integer ,
|
||||
@ -168,7 +168,6 @@ module Parfait
|
||||
local9: :Object ,local10: :Object, local11: :Object , local12: :Object,
|
||||
local13: :Object, local14: :Object, local15: :Object},
|
||||
MetaClass: {instance_methods: :List, instance_type: :Type, clazz: :Class },
|
||||
NamedList: {},
|
||||
NilClass: {},
|
||||
Object: {},
|
||||
ReturnAddress: {next_integer: :ReturnAddress},
|
||||
|
@ -60,20 +60,24 @@ module Vool
|
||||
#FIXME super class check with "sup"
|
||||
#existing class, don't overwrite type (parfait only?)
|
||||
else
|
||||
@clazz = Parfait.object_space.create_class(@name , @super_class_name )
|
||||
#TODO this should start from Object Type and add one name at a time.
|
||||
# So the "trail" of types leading to this one exists.
|
||||
# Also the Class always has a valid type.
|
||||
ivar_hash = {}
|
||||
self.each do |node|
|
||||
next unless node.is_a?(InstanceVariable) or node.is_a?(IvarAssignment)
|
||||
ivar_hash[node.name] = :Object
|
||||
end
|
||||
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
|
||||
create_new_class
|
||||
end
|
||||
@clazz
|
||||
end
|
||||
|
||||
def create_new_class
|
||||
@clazz = Parfait.object_space.create_class(@name , @super_class_name )
|
||||
#TODO this should start from Object Type and add one name at a time.
|
||||
# So the "trail" of types leading to this one exists.
|
||||
# Also the Class always has a valid type.
|
||||
ivar_hash = {}
|
||||
self.each do |node|
|
||||
next unless node.is_a?(InstanceVariable) or node.is_a?(IvarAssignment)
|
||||
ivar_hash[node.name] = :Object
|
||||
end
|
||||
@clazz.set_instance_type( Parfait::Type.for_hash( ivar_hash , @clazz ) )
|
||||
end
|
||||
|
||||
def to_s(depth = 0)
|
||||
at_depth(depth , "class #{name}" , @body.to_s(depth + 1) , "end")
|
||||
end
|
||||
|
@ -25,7 +25,7 @@ module Vool
|
||||
def make_arg_type( )
|
||||
type_hash = {}
|
||||
@args.each {|arg| type_hash[arg] = :Object }
|
||||
Parfait::NamedList.type_for( type_hash )
|
||||
Parfait::Type.for_hash( type_hash )
|
||||
end
|
||||
|
||||
def to_s(depth = 0)
|
||||
@ -43,7 +43,7 @@ module Vool
|
||||
next unless node.is_a?(LocalVariable) or node.is_a?(LocalAssignment)
|
||||
type_hash[node.name] = :Object
|
||||
end
|
||||
Parfait::NamedList.type_for( type_hash )
|
||||
Parfait::Type.for_hash( type_hash )
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -48,7 +48,7 @@ module Vool
|
||||
def make_arg_type( )
|
||||
type_hash = {}
|
||||
@args.each {|arg| type_hash[arg] = :Object }
|
||||
Parfait::NamedList.type_for( type_hash )
|
||||
Parfait::Type.for_hash( type_hash )
|
||||
end
|
||||
def make_frame(compiler)
|
||||
type_hash = {}
|
||||
@ -57,7 +57,7 @@ module Vool
|
||||
next if compiler.in_scope?(node.name)
|
||||
type_hash[node.name] = :Object
|
||||
end
|
||||
Parfait::NamedList.type_for( type_hash )
|
||||
Parfait::Type.for_hash( type_hash )
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -38,7 +38,7 @@ module Vool
|
||||
type_hash = {}
|
||||
@args.each {|arg| type_hash[arg] = :Object }
|
||||
type_hash[:implicit_block] = :Block if has_yield?
|
||||
Parfait::NamedList.type_for( type_hash )
|
||||
Parfait::Type.for_hash( type_hash )
|
||||
end
|
||||
|
||||
def to_s(depth = 0)
|
||||
@ -60,7 +60,7 @@ module Vool
|
||||
next unless node.is_a?(LocalVariable) or node.is_a?(LocalAssignment)
|
||||
type_hash[node.name] = :Object
|
||||
end
|
||||
Parfait::NamedList.type_for( type_hash )
|
||||
Parfait::Type.for_hash( type_hash )
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user