rubyx/lib/parfait/named_list.rb

43 lines
1.5 KiB
Ruby
Raw Normal View History

2015-04-06 10:38:11 +02:00
# 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:
2015-10-23 13:22:55 +02:00
# A Message (see details there) is created by the caller and control is transferred
# A NamedList is created by the receiver
2016-12-21 17:51:22 +01:00
# 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.
2016-02-25 21:03:11 +01:00
# Ie they have have type and instances and so on.*
# Which resolves the dichotomy of objects on the stack or heap. Sama sama.
2016-02-25 21:03:11 +01:00
#
# *Alas the type for each call instance is unique.
#
module Parfait
class NamedList < Object
2015-07-30 18:18:41 +02:00
def self.memory_size
16
end
2018-07-04 07:28:29 +02:00
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
2015-04-06 10:38:11 +02:00
end