1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/README.txt Tue Oct 30 01:22:39 2007 +0100
1.3 @@ -0,0 +1,88 @@
1.4 +Data Structures
1.5 +===============
1.6 +
1.7 +Since classes, functions and instances are all "objects", each must support
1.8 +certain features and operations in the same way.
1.9 +
1.10 +The __class__ Attribute
1.11 +-----------------------
1.12 +
1.13 +All objects support the __class__ attribute:
1.14 +
1.15 +Class: refers to the type class (type.__class__ also refers to the type class)
1.16 +Function: refers to the function class
1.17 +Instance: refers to the class instantiated to make the object
1.18 +
1.19 +Invocation
1.20 +----------
1.21 +
1.22 +The following actions need to be supported:
1.23 +
1.24 +Class: create instance, call __init__ with instance, return object
1.25 +Function: call function body, return result
1.26 +Instance: call __call__ method, return result
1.27 +
1.28 +Structure Layout
1.29 +----------------
1.30 +
1.31 +A suitable structure layout might be something like this:
1.32 +
1.33 + 0 1 2 3 4
1.34 + classcode invocation __class__ attribute ...
1.35 + reference reference reference
1.36 +
1.37 +Here, the classcode refers to the attribute lookup table for the object. Since
1.38 +classes and instances share the same classcode, they might resemble the
1.39 +following:
1.40 +
1.41 +Class C:
1.42 +
1.43 + 0 1 2 3 4
1.44 + code for C __new__ class type attribute ...
1.45 + reference reference reference
1.46 +
1.47 +Instance of C:
1.48 +
1.49 + 0 1 2 3 4
1.50 + code for C C.__call__ class C attribute ...
1.51 + reference reference reference
1.52 + (if exists)
1.53 +
1.54 +The __new__ reference would lead to code consisting of the following
1.55 +instructions:
1.56 +
1.57 + create instance for C
1.58 + call C.__init__(instance, ...)
1.59 + return instance
1.60 +
1.61 +If C has a __call__ attribute, the invocation "slot" of C instances would
1.62 +refer to the same thing as C.__call__.
1.63 +
1.64 +For functions, the same general layout applies:
1.65 +
1.66 +Function f:
1.67 +
1.68 + 0 1 2 3 4
1.69 + code for code class attribute ...
1.70 + function reference function reference
1.71 + reference
1.72 +
1.73 +Here, the code reference would lead to code for the function.
1.74 +
1.75 +Invocation Operation
1.76 +--------------------
1.77 +
1.78 +Consequently, regardless of the object an invocation is always done as
1.79 +follows:
1.80 +
1.81 + get invocation reference (at object+1)
1.82 + jump to reference
1.83 +
1.84 +Additional preparation is necessary before the above code: positional
1.85 +arguments must be saved to the parameter stack, and keyword arguments must be
1.86 +resolved and saved to the appropriate position in the parameter stack.
1.87 +
1.88 +Attribute Operations
1.89 +--------------------
1.90 +
1.91 +Attribute access needs to go through the attribute lookup table.