Compile a given source code into a bytecode object.
(
source: &str,
mode: Mode,
source_path: &str,
opts: CompileOpts,
)
| 251 | |
| 252 | /// Compile a given source code into a bytecode object. |
| 253 | pub 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 | |
| 285 | fn _compile( |
| 286 | source_file: SourceFile, |