7. Execution context
From Ruby Standard Wiki
7.1 Contextual Attributes
An execution context is a set of attributes which affects an evaluation of a program.
An execution context is not a part of the language. It is defined in this document only for the description of the semantics of a program. A conforming processor shall evaluate a program as if it acted upon an execution context in the manner described in this document.
An execution context consists of a set of attributes as described below. Each attribute of an execution context except [[global-variable-bindings]] forms a logical stack. The names of attributes are enclosed in double square brackets "[[" and ""]]". Attributes of an execution context are changed when a program construct is evaluated.
The following are the attributes of an execution context:
- [[self]]
- A logical stack of objects, the top of which is the object to which the pseudo variable
selfis bound (see §11.4.3.7.3). The object at the top of the stack is called the current self. - [[class-module-list]]
- A logical stack of lists of classes or modules. The class or module at the head of the list which is on the top of the stack is called the current class or module.
- [[default-method-visibility]]
- A logical stack of visibilities of methods, each of which is one of the public, private, and protected visibility. The top of the stack is called the current visibility.
- [[local-variable-bindings]]
- A logical stack of sets of bindings of local variables. The element at the top of the stack is called the current set of local variable bindings. A set of bindings is pushed onto the stack on every entry into a local variable scope (see §9.1.1), and the top element is removed from the stack on every exit from the scope. The scope with which an element in the stack is associated is called the scope of the set of local variable bindings.
- [[invoked-method-name]]
- A logical stack of names by which methods are invoked.
- [[defined-method-name]]
- A logical stack of names with which the invoked methods are defined.
- [[block]]
- A logical stack of blocks passed to method invocations. An element of the stack may be block-not-given, which indicates that no block is passed to a method invocation.
- [[global-variable-bindings]]
- A set of bindings of global variables.
The term unset is used to describe the state of an attribute which is set to nothing.
7.2 The initial state
Immediately prior to an execution of a program, the attributes of the execution context is initialized as follows:
- Create an empty set of variable bindings, and set [[global-variable-bindings]] to the set of variable bindings.
- Create built-in classes and modules as described in §15.
- Create an empty stack for each attribute of the execution context except [[global-variablebindings]].
- Create a direct instance of the class
Objectand push it onto [[self]]. - Create a list containing only the class Object and push the list onto [[class-module-list]].
- Push the private visibility onto [[default-visibility]].
- Push block-not-given onto [[block]].
Previous: 6. Objects Next: 8. Lexical structure