Load the environment class for a given base into a register. Additionally, iterates through all of the SymbolNode and AssignmentTarget instances of the environment at the given index's symtable, and adds those instances to the environment of the current environment. This is done so
(
builder: IRBuilder, base: Value, outer_env: dict[SymbolNode, SymbolTarget]
)
| 141 | |
| 142 | |
| 143 | def load_outer_env( |
| 144 | builder: IRBuilder, base: Value, outer_env: dict[SymbolNode, SymbolTarget] |
| 145 | ) -> Value: |
| 146 | """Load the environment class for a given base into a register. |
| 147 | |
| 148 | Additionally, iterates through all of the SymbolNode and |
| 149 | AssignmentTarget instances of the environment at the given index's |
| 150 | symtable, and adds those instances to the environment of the |
| 151 | current environment. This is done so that the current environment |
| 152 | can access outer environment variables without having to reload |
| 153 | all of the environment registers. |
| 154 | |
| 155 | Returns the register where the environment class was loaded. |
| 156 | """ |
| 157 | env = builder.add(GetAttr(base, ENV_ATTR_NAME, builder.fn_info.fitem.line)) |
| 158 | assert isinstance(env.type, RInstance), f"{env} must be of type RInstance" |
| 159 | |
| 160 | for symbol, target in outer_env.items(): |
| 161 | attr_name = symbol.name |
| 162 | if isinstance(target, AssignmentTargetAttr): |
| 163 | attr_name = target.attr |
| 164 | env.type.class_ir.attributes[attr_name] = target.type |
| 165 | symbol_target = AssignmentTargetAttr(env, attr_name) |
| 166 | builder.add_target(symbol, symbol_target) |
| 167 | |
| 168 | return env |
| 169 | |
| 170 | |
| 171 | def load_outer_envs(builder: IRBuilder, base: ImplicitClass) -> None: |
no test coverage detected
searching dependent graphs…