1.1 --- a/README.txt Tue Dec 11 00:55:23 2007 +0100
1.2 +++ b/README.txt Sun Jan 13 02:14:46 2008 +0100
1.3 @@ -97,3 +97,73 @@
1.4 --------------------
1.5
1.6 Attribute access needs to go through the attribute lookup table.
1.7 +
1.8 +Instruction Evaluation Model
1.9 +============================
1.10 +
1.11 +Programs use a value stack where evaluated instructions may save their
1.12 +results. A value stack pointer indicates the top of this stack. In addition, a
1.13 +separate stack is used to record the invocation frames. All stack pointers
1.14 +refer to the next address to be used by the stack, not the address of the
1.15 +uppermost element.
1.16 +
1.17 + Frame Stack Value Stack
1.18 + ----------- ----------- Address of Callable
1.19 + -------------------
1.20 + previous ...
1.21 + current ------> callable -----> identifier
1.22 + arg1 reference to code
1.23 + arg2
1.24 + arg3
1.25 + local4
1.26 + local5
1.27 + ...
1.28 +
1.29 +Loading local names is a matter of performing frame-relative accesses to the
1.30 +value stack.
1.31 +
1.32 +Invocations and Argument Evaluation
1.33 +-----------------------------------
1.34 +
1.35 +When preparing for an invocation, the caller first sets the invocation frame
1.36 +pointer. Then, positional arguments are added to the stack such that the first
1.37 +argument positions are filled. A number of stack locations for the remaining
1.38 +arguments specified in the program are then reserved. The names of keyword
1.39 +arguments are used (in the form of table index values) to consult the
1.40 +parameter table and to find the location in which such arguments are to be
1.41 +stored.
1.42 +
1.43 + fn(a, b, d=1, e=2, c=3) -> fn(a, b, c, d, e)
1.44 +
1.45 + Value Stack
1.46 + -----------
1.47 +
1.48 + ... ... ... ...
1.49 + fn fn fn fn
1.50 + a a a a
1.51 + b b b b
1.52 + ___ ___ ___ --> 3
1.53 + ___ --> 1 1 | 1
1.54 + ___ | ___ --> 2 | 2
1.55 + 1 ----------- 2 ----------- 3 -----------
1.56 +
1.57 +Conceptually, the frame can be considered as a collection of attributes, as
1.58 +seen in other kinds of structures:
1.59 +
1.60 +Frame for invocation of fn:
1.61 +
1.62 + 0 1 2 3 4 5
1.63 + code a b c d e
1.64 + reference
1.65 +
1.66 +However, where arguments are specified positionally, such "attributes" are not
1.67 +set using a comparable approach to that employed with other structures.
1.68 +Keyword arguments are set using an attribute-like mechanism, though, where the
1.69 +position of each argument discovered using the parameter table.
1.70 +
1.71 +Tuples, Frames and Allocation
1.72 +-----------------------------
1.73 +
1.74 +Using the approach where arguments are treated like attributes in some kind of
1.75 +structure, we could choose to allocate frames in places other than a stack.
1.76 +This would produce something somewhat similar to a plain tuple object.