Scoped languages tend to store the local variables of a given scope or function together in a data structure known as an activation record. Stack frames are examples of instances of activation records. Not all activation records are part of a stack; for example, in ECMAScript/JavaScript they are garbage collected and you can re-enter a scope through a function object.
Does any strongly-typed language exist with activation records as first-class objects, even with severely limited capabilities? What considerations does this tend to raise? For example, this function:
void f( int i ) {
int j = i + 3;
{
int * q = & j;
}
{
char r = 'z';
}
}
… could map to this data type:
struct f_activation {
int i;
int j;
union {
int * q;
char r;
};
};
This is just an example; an optimizing compiler wouldn't want to nail down such a restrictive mapping.
Assembly language programmers often declare activation records using the same record
directive as other data types. TCL has the uplevel
command which is sufficient to treat the scopes of calling functions as objects. (I have seen this done. No joke.)
Context of the question: The C++ community is trying to add coroutines to a future language revision. C++ already has a popular design pattern, "function objects," and many would like paused coroutines to act like objects too, ideally with serialization and clean forced-termination.
I'm not looking for a laundry list, but for past experience with this language design direction. However, I'm happy just to get references so I can do deeper reading myself.