(
&mut self,
body: &ast::ModModule,
symbol_table: SymbolTable,
)
| 1808 | } |
| 1809 | |
| 1810 | fn compile_program( |
| 1811 | &mut self, |
| 1812 | body: &ast::ModModule, |
| 1813 | symbol_table: SymbolTable, |
| 1814 | ) -> CompileResult<()> { |
| 1815 | let size_before = self.code_stack.len(); |
| 1816 | // Set future_annotations from symbol table (detected during symbol table scan) |
| 1817 | self.future_annotations = symbol_table.future_annotations; |
| 1818 | |
| 1819 | // Module-level __conditional_annotations__ cell |
| 1820 | let has_module_cond_ann = symbol_table.has_conditional_annotations; |
| 1821 | if has_module_cond_ann { |
| 1822 | self.current_code_info() |
| 1823 | .metadata |
| 1824 | .cellvars |
| 1825 | .insert("__conditional_annotations__".to_string()); |
| 1826 | } |
| 1827 | |
| 1828 | self.symbol_table_stack.push(symbol_table); |
| 1829 | |
| 1830 | // Emit MAKE_CELL for module-level cells (before RESUME) |
| 1831 | if has_module_cond_ann { |
| 1832 | let ncells = self.code_stack.last().unwrap().metadata.cellvars.len(); |
| 1833 | for i in 0..ncells { |
| 1834 | let i_varnum: oparg::VarNum = u32::try_from(i).expect("too many cellvars").into(); |
| 1835 | emit!(self, Instruction::MakeCell { i: i_varnum }); |
| 1836 | } |
| 1837 | } |
| 1838 | |
| 1839 | self.emit_resume_for_scope(CompilerScope::Module, 1); |
| 1840 | |
| 1841 | let (doc, statements) = split_doc(&body.body, &self.opts); |
| 1842 | if let Some(value) = doc { |
| 1843 | self.emit_load_const(ConstantData::Str { |
| 1844 | value: value.into(), |
| 1845 | }); |
| 1846 | let doc = self.name("__doc__"); |
| 1847 | emit!(self, Instruction::StoreName { namei: doc }) |
| 1848 | } |
| 1849 | |
| 1850 | // Handle annotations based on future_annotations flag |
| 1851 | if Self::find_ann(statements) { |
| 1852 | if self.future_annotations { |
| 1853 | // PEP 563: Initialize __annotations__ dict |
| 1854 | emit!(self, Instruction::SetupAnnotations); |
| 1855 | } else { |
| 1856 | // PEP 649: Generate __annotate__ function FIRST (before statements) |
| 1857 | self.compile_module_annotate(statements)?; |
| 1858 | |
| 1859 | // PEP 649: Initialize __conditional_annotations__ set after __annotate__ |
| 1860 | if self.current_symbol_table().has_conditional_annotations { |
| 1861 | emit!(self, Instruction::BuildSet { count: 0 }); |
| 1862 | self.store_name("__conditional_annotations__")?; |
| 1863 | } |
| 1864 | } |
| 1865 | } |
| 1866 | |
| 1867 | // Compile all statements |
no test coverage detected