Frame
Frame dataclass
Frame(
code: Statement,
*,
parent: Self | None = None,
has_parent_access: bool = False,
lineno_offset: int = 0,
entries: dict[SSAValue, ValueType] = dict()
)
Bases: FrameABC[SSAValue, ValueType]
entries class-attribute
instance-attribute
entries: dict[SSAValue, ValueType] = field(
default_factory=dict, kw_only=True
)
SSA values and their corresponding values.
get
get(key: SSAValue) -> ValueType
Get the value for the given SSAValue
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key(SSAValue) | The key to get the value for. | required |
Returns:
Name | Type | Description |
---|---|---|
ValueType | ValueType | The value. |
Raises:
Type | Description |
---|---|
InterpreterError | If the value is not found. This will be catched by the interpreter. |
Source code in src/kirin/interp/frame.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
get_casted
get_casted(
key: SSAValue, type_: type[ExpectedType]
) -> ExpectedType
Same as get
except it forces the linter to think the value is of the expected type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key(SSAValue) | The key to get the value for. | required | |
type_(type) | The expected type. | required |
Returns:
Name | Type | Description |
---|---|---|
ExpectedType | ExpectedType | The value. |
Source code in src/kirin/interp/frame.py
127 128 129 130 131 132 133 134 135 136 137 138 |
|
get_typed
get_typed(
key: SSAValue, type_: type[ExpectedType]
) -> ExpectedType
Similar to get
but also checks the type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key(SSAValue) | The key to get the value for. | required | |
type_(type) | The expected type. | required |
Returns:
Name | Type | Description |
---|---|---|
ExpectedType | ExpectedType | The value. |
Raises:
Type | Description |
---|---|
InterpreterError | If the value is not of the expected type. |
Source code in src/kirin/interp/frame.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
set
set(key: SSAValue, value: ValueType) -> None
Set the value for the given key. See also set_values
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key(KeyType) | The key to set the value for. | required | |
value(ValueType) | The value. | required |
Source code in src/kirin/interp/frame.py
158 159 |
|
FrameABC dataclass
FrameABC(
code: Statement,
*,
parent: Self | None = None,
has_parent_access: bool = False,
lineno_offset: int = 0
)
Bases: ABC
, Generic[KeyType, ValueType]
Abstract base class for the IR interpreter's call frame.
While the IR is in SSA form which does not have the need of scoping, the frame is still useful to keep track of the current statement being interpreted and the call stack. As well as various other interpreter state based on the specific interpreter implementation.
This base class provides the minimum interface for the interpreter frame.
code instance-attribute
code: Statement
statement whose region is being interpreted, e.g a function.
current_block class-attribute
instance-attribute
current_block: Block | None = field(
default=None, init=False, compare=False, repr=False
)
Current block being interpreted.
current_stmt class-attribute
instance-attribute
current_stmt: Statement | None = field(
default=None, init=False, compare=False, repr=False
)
Current statement being interpreted.
has_parent_access class-attribute
instance-attribute
has_parent_access: bool = field(
default=False, kw_only=True, compare=True
)
If we have access to the entries of the parent frame.
parent class-attribute
instance-attribute
parent: Self | None = field(
default=None, kw_only=True, compare=True, repr=False
)
Parent frame.
get abstractmethod
get(key: KeyType) -> ValueType
Get the value for the given key. See also get_values
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key(KeyType) | The key to get the value for. | required |
Returns:
Name | Type | Description |
---|---|---|
ValueType | ValueType | The value. |
Source code in src/kirin/interp/frame.py
50 51 52 53 54 55 56 57 58 59 60 61 |
|
get_values
get_values(
keys: Iterable[KeyType],
) -> tuple[ValueType, ...]
Get the values of the given keys. See also get
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys(Iterable[KeyType]) | The keys to get the values for. | required |
Returns:
Type | Description |
---|---|
tuple[ValueType, ...] | tuple[ValueType, ...]: The values. |
Source code in src/kirin/interp/frame.py
74 75 76 77 78 79 80 81 82 83 84 |
|
set abstractmethod
set(key: KeyType, value: ValueType) -> None
Set the value for the given key. See also set_values
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key(KeyType) | The key to set the value for. | required | |
value(ValueType) | The value. | required |
Source code in src/kirin/interp/frame.py
63 64 65 66 67 68 69 70 71 72 |
|
set_values
set_values(
keys: Iterable[KeyType], values: Iterable[ValueType]
) -> None
Set the values of the given keys. This is a convenience method to set multiple values at once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys(Iterable[KeyType]) | The keys to set the values for. | required | |
values(Iterable[ValueType]) | The values. | required |
Source code in src/kirin/interp/frame.py
86 87 88 89 90 91 92 93 94 95 |
|