Calculate default argument values and store them. They are stored in statics for top level functions and in the function objects for nested functions (while constants are still stored computed on demand).
(
builder: IRBuilder,
fn_info: FuncInfo,
func_reg: Value | None,
symtable: dict[SymbolNode, SymbolTarget],
)
| 1713 | |
| 1714 | |
| 1715 | def calculate_arg_defaults( |
| 1716 | builder: IRBuilder, |
| 1717 | fn_info: FuncInfo, |
| 1718 | func_reg: Value | None, |
| 1719 | symtable: dict[SymbolNode, SymbolTarget], |
| 1720 | ) -> None: |
| 1721 | """Calculate default argument values and store them. |
| 1722 | |
| 1723 | They are stored in statics for top level functions and in |
| 1724 | the function objects for nested functions (while constants are |
| 1725 | still stored computed on demand). |
| 1726 | """ |
| 1727 | fitem = fn_info.fitem |
| 1728 | for arg in fitem.arguments: |
| 1729 | # Constant values don't get stored but just recomputed |
| 1730 | if arg.initializer and not is_constant(arg.initializer): |
| 1731 | value = builder.coerce( |
| 1732 | builder.accept(arg.initializer), symtable[arg.variable].type, arg.line |
| 1733 | ) |
| 1734 | if not fn_info.is_nested: |
| 1735 | name = fitem.fullname + "." + arg.variable.name |
| 1736 | builder.add(InitStatic(value, name, builder.module_name)) |
| 1737 | else: |
| 1738 | assert func_reg is not None |
| 1739 | builder.add(SetAttr(func_reg, arg.variable.name, value, arg.line)) |
no test coverage detected
searching dependent graphs…