This file explains how the interpretor uses standard lower-level data types to support functions and function contexts.

The term 'function', as used by programmers, might mean one of three different things:

a 'function body'
a compile time entity -- the source code
a 'function value'
a run time entity -- what is passed for a function argument and what gets called at run time. These include the context that the function will run in.
a 'function activation'
a run time entity -- the temporary data needed during a specific execution of the function

Global Context

A global context is stored in a vector of length 3 with the following fields:
0. name (string)
1. variables (hash_table: name (string) => Mini_obj)
2. parent global context (vector)

Function Body

Since function bodies are not function values, they may not be called (directly). (see Function Values, below).

A function body is stored in a vector of length 13 with the following fields:

0. name (string)
1. literal_table (vector)
2. global context (vector)
3. required #args (integer) (space required in far for args)
4. rest args? (nil or 't')
5. argument regions (vector of integer, each code is: 4 * unnesting-level +
0. global
1. ret
2. first_arg (self)
3. local_far
6. local names (vector of strings -- locals and min args)
7. bytecodes (string)
8. nested functions (vector of function bodies (vectors))
9. min #args (integer) (min args to pass in call)
10. #ret values (integer)
11. keyword table (maps keyword arg name to region) (hash: symbol => integer)
12. number of local variables before first argument (integer)

Top-level function bodies have an 14th field:

13. compiler function (function value?)

Function Values

Function values are built-in types and may not be extended by the programmer.

All function values must support a 'prepare_send' operation and a 'store_arg' operation. In addition, non-member function values must support a 'prepare_call' operation.

The built-in function values are:

FAR (Function Activation Record):

A far is a vector with its local variables and arguments as elements. All fars use the following reserved indexes:
0. for the function body
1. for the return continuation (continuation)
2. for the return continuation offset (integer)
3. for the free wait list
4. for the free std_cont list
5. for the number of positional arguments passed (including self or parent far)
6. for the keyword argument names passed (vector of symbols)
The local variables start at index 7, followed by the positional argument values, and finally the keyword argument values. The theory is that there are always a fixed number of local variables, but there may be a variable number of positional arguments and keyword arguments.

Continuation

A continuation is a built-in type. It takes care of wait counts and far scheduling. It also knows where to allocate return data and where to store the pointer to the return data.

There are two kinds of continuations: standard continuations and argument continuations.

The standard continuations are allocated and reused by the code as it runs. Each far keeps a list of free standard continuations available for reuse. These are linked together through 'next' pointers in the continuation objects. The list head pointers are kept in index 4 of the far vector.

The continuation objects point to a wait object to do the actual wait processing.

Wait

A Wait is a built-in type. It takes care of wait counts and far scheduling.

Waits are allocated and reused by the interpretor code as it runs. Each far keeps a list of free waits available for reuse. These are linked together through 'next' pointers in the wait objects. The list head pointer is kept in index 3 of the far vector.

SourceForge.net Logo