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

Method compile_block_expr

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

Source from the content-addressed store, hash-verified

1944 }
1945
1946 fn compile_block_expr(
1947 &mut self,
1948 body: &[ast::Stmt],
1949 symbol_table: SymbolTable,
1950 ) -> CompileResult<()> {
1951 self.symbol_table_stack.push(symbol_table);
1952 self.emit_resume_for_scope(CompilerScope::Module, 1);
1953
1954 self.compile_statements(body)?;
1955
1956 if let Some(last_statement) = body.last() {
1957 match last_statement {
1958 ast::Stmt::Expr(_) => {
1959 self.current_block().instructions.pop(); // pop Instruction::PopTop
1960 }
1961 ast::Stmt::FunctionDef(_) | ast::Stmt::ClassDef(_) => {
1962 let pop_instructions = self.current_block().instructions.pop();
1963 let store_inst = compiler_unwrap_option(self, pop_instructions); // pop Instruction::Store
1964 emit!(self, Instruction::Copy { i: 1 });
1965 self.current_block().instructions.push(store_inst);
1966 }
1967 _ => self.emit_load_const(ConstantData::None),
1968 }
1969 }
1970 self.emit_return_value();
1971
1972 Ok(())
1973 }
1974
1975 // Compile statement in eval mode:
1976 fn compile_eval(

Callers 1

compile_block_expressionFunction · 0.80

Calls 9

compiler_unwrap_optionFunction · 0.85
emit_resume_for_scopeMethod · 0.80
compile_statementsMethod · 0.80
current_blockMethod · 0.80
emit_load_constMethod · 0.80
emit_return_valueMethod · 0.80
pushMethod · 0.45
lastMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected