MCPcopy Index your code
hub / github.com/RustPython/RustPython / compile_program_single

Method compile_program_single

crates/codegen/src/compile.rs:1877–1944  ·  view source on GitHub ↗
(
        &mut self,
        body: &[ast::Stmt],
        symbol_table: SymbolTable,
    )

Source from the content-addressed store, hash-verified

1875 }
1876
1877 fn compile_program_single(
1878 &mut self,
1879 body: &[ast::Stmt],
1880 symbol_table: SymbolTable,
1881 ) -> CompileResult<()> {
1882 self.interactive = true;
1883 // Set future_annotations from symbol table (detected during symbol table scan)
1884 self.future_annotations = symbol_table.future_annotations;
1885 self.symbol_table_stack.push(symbol_table);
1886
1887 self.emit_resume_for_scope(CompilerScope::Module, 1);
1888
1889 // Handle annotations based on future_annotations flag
1890 if Self::find_ann(body) {
1891 if self.future_annotations {
1892 // PEP 563: Initialize __annotations__ dict
1893 emit!(self, Instruction::SetupAnnotations);
1894 } else {
1895 // PEP 649: Generate __annotate__ function FIRST (before statements)
1896 self.compile_module_annotate(body)?;
1897
1898 // PEP 649: Initialize __conditional_annotations__ set after __annotate__
1899 if self.current_symbol_table().has_conditional_annotations {
1900 emit!(self, Instruction::BuildSet { count: 0 });
1901 self.store_name("__conditional_annotations__")?;
1902 }
1903 }
1904 }
1905
1906 if let Some((last, body)) = body.split_last() {
1907 for statement in body {
1908 if let ast::Stmt::Expr(ast::StmtExpr { value, .. }) = &statement {
1909 self.compile_expression(value)?;
1910 emit!(
1911 self,
1912 Instruction::CallIntrinsic1 {
1913 func: bytecode::IntrinsicFunction1::Print
1914 }
1915 );
1916
1917 emit!(self, Instruction::PopTop);
1918 } else {
1919 self.compile_statement(statement)?;
1920 }
1921 }
1922
1923 if let ast::Stmt::Expr(ast::StmtExpr { value, .. }) = &last {
1924 self.compile_expression(value)?;
1925 emit!(self, Instruction::Copy { i: 1 });
1926 emit!(
1927 self,
1928 Instruction::CallIntrinsic1 {
1929 func: bytecode::IntrinsicFunction1::Print
1930 }
1931 );
1932
1933 emit!(self, Instruction::PopTop);
1934 } else {

Callers 1

compile_program_singleFunction · 0.80

Calls 9

emit_resume_for_scopeMethod · 0.80
current_symbol_tableMethod · 0.80
store_nameMethod · 0.80
compile_expressionMethod · 0.80
compile_statementMethod · 0.80
emit_load_constMethod · 0.80
emit_return_valueMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected