elliptic.Kernel.Context Module¶
-
class
elliptic.Kernel.Context.
Context
[source]¶ Bases:
object
Defines a context for code generation.
A Context is basically a dictionary of stacks. In other words, it defines a stack_name -> stack mapping. Each stack has is semantically defined by its stack_name.
Example
>>> context = Context() >>> context.put_value('current_value', '100') >>> context.put_value('current_value', '200') >>> context.get_value('current_value') # 200 >>> context.pop_value('current_value') >>> context.get_value('current_value') # 100
-
clear_values
(name)[source]¶ Clears the stack named name.
- Parameters
name (
str
) – Stack name.- Return type
None
-
-
class
elliptic.Kernel.Context.
ContextDelegate
(context, unique_id)[source]¶ Bases:
abc.ABC
Delegate class for getting the generated code template file and its kwargs for a given expression.
Also defines the context state changes when the corresponding expression node is visited and exited.
-
context
¶ Context instance.
-
unique_id
¶ A unique id that can be used to identify values that were created from this context delegate.
-
abstract
context_enter
()[source]¶ Modifies the context state. Called when the expression node is visited.
Use this method to prepare the context for expressions that will be visited afterwards. It is preferable to keep most context.put_value calls in this method.
- Return type
None
-
abstract
context_exit
()[source]¶ Modifies the context state. Called when the expression node is exited.
Use this method to clear values from the context and prepare it for the expression nodes that were visited before. It is preferable to keep most context.pop_value calls in this method.
- Return type
None
-