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

Function compile

crates/compiler/src/lib.rs:253–283  ·  view source on GitHub ↗

Compile a given source code into a bytecode object.

(
    source: &str,
    mode: Mode,
    source_path: &str,
    opts: CompileOpts,
)

Source from the content-addressed store, hash-verified

251
252/// Compile a given source code into a bytecode object.
253pub fn compile(
254 source: &str,
255 mode: Mode,
256 source_path: &str,
257 opts: CompileOpts,
258) -> Result<CodeObject, CompileError> {
259 // TODO: do this less hacky; ruff's parser should translate a CRLF line
260 // break in a multiline string into just an LF in the parsed value
261 #[cfg(windows)]
262 let source = source.replace("\r\n", "\n");
263 #[cfg(windows)]
264 let source = source.as_str();
265
266 let source_file = SourceFileBuilder::new(source_path, source).finish();
267 _compile(source_file, mode, opts)
268 // let index = LineIndex::from_source_text(source);
269 // let source_code = SourceCode::new(source, &index);
270 // let mut locator = LinearLocator::new(source);
271 // let mut ast = match parser::parse(source, mode.into(), &source_path) {
272 // Ok(x) => x,
273 // Err(e) => return Err(locator.locate_error(e)),
274 // };
275
276 // TODO:
277 // if opts.optimize > 0 {
278 // ast = ConstantOptimizer::new()
279 // .fold_mod(ast)
280 // .unwrap_or_else(|e| match e {});
281 // }
282 // let ast = locator.fold_mod(ast).unwrap_or_else(|e| match e {});
283}
284
285fn _compile(
286 source_file: SourceFile,

Callers 10

test_compileFunction · 0.70
test_compile_phelloFunction · 0.70
test_compile_lambdaFunction · 0.70
test_compile_lambda2Function · 0.70
test_compile_lambda3Function · 0.70
test_compile_intFunction · 0.70
test_compile_bigintFunction · 0.70
test_compile_fstringFunction · 0.70
test_simple_enumFunction · 0.70

Calls 5

newFunction · 0.85
_compileFunction · 0.70
replaceMethod · 0.45
as_strMethod · 0.45
finishMethod · 0.45

Tested by 10

test_compileFunction · 0.56
test_compile_phelloFunction · 0.56
test_compile_lambdaFunction · 0.56
test_compile_lambda2Function · 0.56
test_compile_lambda3Function · 0.56
test_compile_intFunction · 0.56
test_compile_bigintFunction · 0.56
test_compile_fstringFunction · 0.56
test_simple_enumFunction · 0.56