2.1.1.1.1.3. racketinterpreter.classes.stack¶
-
class
ARType
(value)¶ Bases:
enum.Enum
The type of an activation record.
-
PROCEDURE
= 'PROCEDURE'¶
-
PROGRAM
= ('PROGRAM',)¶
-
-
class
ActivationRecord
(name: str, type: racketinterpreter.classes.stack.ARType, nesting_level: int)¶ Bases:
object
A record in the stack.
An activation record is created for subroutines. It is especially useful whenever there is a need to assign values to names temporarily, e.g. assigning actual parameters to formal parameters when calling a procedure, or initializing builtin procedures to the global scope.
- Variables
name (str) – The name of the record, either the procedure name or ‘global’ for the global scope.
type (ARType) – The type of activation record.
nesting_level (int) – The number of activation records below this one.
members (dict) – A mapping of names to values in the record.
-
__setitem__
(name: str, value: Data) → None¶ Define a name within this record.
- Parameters
name (str) – The name to be defined.
value (Data) – The value of the name.
-
__getitem__
(name: str) → Data¶ Retrieve the value assigned to a name within this record.
- Parameters
name (str) – The name whose value to return.
- Returns
The value assigned to the name.
- Return type
- Raises
KeyError – If there is no value assigned to the name.
-
get
(key) → tp.Optional[Data]¶
-
static
log_stack
(msg: str) → None¶ Log messages related to the stack.
If the global constant SHOULD_LOG_STACK is set to True, this method will print out the message.
- Parameters
msg (str) – The message to be displayed.
-
class
CallStack
¶ Bases:
object
A call stack.
A stack data structure that keeps track of a list of activation records. Each activation record represents a subroutine. The stack indicates which subroutine will get control after the current one is finished running.
-
get
(name: str) → Data¶ Retrieves the value assigned to the name.
The activation records are checked starting with the last one. Once an activation is found that contains a value assigned to the name, that value is returned.
- Parameters
name (str) – The name to lookup.
- Returns
The value assigned to the name.
- Return type
- Raises
IllegalStateError – If there is no activation record with a value assigned to the name.
-
peek
(levels: int = 1) → racketinterpreter.classes.stack.ActivationRecord¶ Look at an activation record at the top of the stack without removing it.
- Parameters
levels (int) – The ith activation record from the top.
- Returns
An activation record counting from the top of the stack.
- Return type
-
pop
() → racketinterpreter.classes.stack.ActivationRecord¶ Removes an activation record from the stack.
- Returns
An activation record from the top of the stack.
- Return type
-
push
(ar: racketinterpreter.classes.stack.ActivationRecord) → None¶ Push an activation record onto the stack.
- Parameters
ar – An activation record.
-