mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 11:14:38 +08:00
* stage1 * compiler pass build * introduce rustpython-compiler-source * stage2 * fixup * pass compile * Fix hello world compiler test * Fix code generation for if-elif-else statement * Fix code generation for lambda expression * Fix code generation for integers * Fix code generation for fstrings * Fix code generation for if statement * Fix code generation for if statement * Fix code generation for if statement * Fix code generation for fstring * Fix code generation for class definition * Replace feature flags * Initialize frozen core modules * Allow __future__ import after module doc comment * Disable ast module * Commit remaining fixes for compile errors in examples * Fix some warnings * Update ast stdlib module * Update ast stdlib module * Update ast stdlib module * Update ast stdlib module * Update ast stdlib module * Split ast stdlib module into files * Fix codegen for positional arguments with defaults * Update ast stdlib module * Update ast stdlib module * Extract string and constant handling from expression.rs * Always add required fields to AST nodes * Compile doc strings correctly again * Enable "ast" Cargo feature by default * Refactor compilation of big integer literal * Update ast stdlib module * Update ast stdlib module * Update ast stdlib module * Reset barebones example * Fix some left-over warnings * Undo accidential change * Adapt shell to ruff parser * Pin parser to v0.4.10 * fix clippy * Add TODO about interactive mode * Fix compilation of complex number expression * Remove moved code * Update test case to ruff v0.4.10 * Apply suggestion Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com> * Apply suggestion Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com> * Fix compilation of fstring expression * Fix compilation of fstring expression * Fix wasm compile errors * Attach correct source locations to ast objects * Fix some more wasm compile errors * Consider compile mode and enable AST stdlib module again * Fix incorrect AST source location end column * Fix compile error if "compiler" feature is not enabled * Fix regrtests * Fix some test_ast tests * Add source range to type ignore * Fix incompatibility with Rust 2024 edition * Fix todos by implementing missing ast conversions and deleting unused code * Appease clippy * Fix remaining ast tests * Fix remaining ast tests * Mark/fix remaining tests * Fix more * Hacky windows fix --------- Co-authored-by: Kangzhi Shi <shikangzhi@gmail.com> Co-authored-by: Jeong YunWon <jeong@youknowone.org> Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com> Co-authored-by: Noa <coolreader18@gmail.com>
109 lines
3.5 KiB
Rust
109 lines
3.5 KiB
Rust
use ruff_source_file::SourceLocation;
|
|
use std::fmt;
|
|
use thiserror::Error;
|
|
|
|
// pub type CodegenError = rustpython_parser_core::source_code::LocatedError<CodegenErrorType>;
|
|
|
|
#[derive(Error, Debug)]
|
|
pub struct CodegenError {
|
|
pub location: Option<SourceLocation>,
|
|
#[source]
|
|
pub error: CodegenErrorType,
|
|
pub source_path: String,
|
|
}
|
|
|
|
impl fmt::Display for CodegenError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
// TODO:
|
|
self.error.fmt(f)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
#[non_exhaustive]
|
|
pub enum CodegenErrorType {
|
|
/// Invalid assignment, cannot store value in target.
|
|
Assign(&'static str),
|
|
/// Invalid delete
|
|
Delete(&'static str),
|
|
SyntaxError(String),
|
|
/// Multiple `*` detected
|
|
MultipleStarArgs,
|
|
/// Misplaced `*` expression
|
|
InvalidStarExpr,
|
|
/// Break statement outside of loop.
|
|
InvalidBreak,
|
|
/// Continue statement outside of loop.
|
|
InvalidContinue,
|
|
InvalidReturn,
|
|
InvalidYield,
|
|
InvalidYieldFrom,
|
|
InvalidAwait,
|
|
AsyncYieldFrom,
|
|
AsyncReturnValue,
|
|
InvalidFuturePlacement,
|
|
InvalidFutureFeature(String),
|
|
FunctionImportStar,
|
|
TooManyStarUnpack,
|
|
EmptyWithItems,
|
|
EmptyWithBody,
|
|
DuplicateStore(String),
|
|
InvalidMatchCase,
|
|
NotImplementedYet, // RustPython marker for unimplemented features
|
|
}
|
|
|
|
impl std::error::Error for CodegenErrorType {}
|
|
|
|
impl fmt::Display for CodegenErrorType {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
use CodegenErrorType::*;
|
|
match self {
|
|
Assign(target) => write!(f, "cannot assign to {target}"),
|
|
Delete(target) => write!(f, "cannot delete {target}"),
|
|
SyntaxError(err) => write!(f, "{}", err.as_str()),
|
|
MultipleStarArgs => {
|
|
write!(f, "two starred expressions in assignment")
|
|
}
|
|
InvalidStarExpr => write!(f, "cannot use starred expression here"),
|
|
InvalidBreak => write!(f, "'break' outside loop"),
|
|
InvalidContinue => write!(f, "'continue' outside loop"),
|
|
InvalidReturn => write!(f, "'return' outside function"),
|
|
InvalidYield => write!(f, "'yield' outside function"),
|
|
InvalidYieldFrom => write!(f, "'yield from' outside function"),
|
|
InvalidAwait => write!(f, "'await' outside async function"),
|
|
AsyncYieldFrom => write!(f, "'yield from' inside async function"),
|
|
AsyncReturnValue => {
|
|
write!(f, "'return' with value inside async generator")
|
|
}
|
|
InvalidFuturePlacement => write!(
|
|
f,
|
|
"from __future__ imports must occur at the beginning of the file"
|
|
),
|
|
InvalidFutureFeature(feat) => {
|
|
write!(f, "future feature {feat} is not defined")
|
|
}
|
|
FunctionImportStar => {
|
|
write!(f, "import * only allowed at module level")
|
|
}
|
|
TooManyStarUnpack => {
|
|
write!(f, "too many expressions in star-unpacking assignment")
|
|
}
|
|
EmptyWithItems => {
|
|
write!(f, "empty items on With")
|
|
}
|
|
EmptyWithBody => {
|
|
write!(f, "empty body on With")
|
|
}
|
|
DuplicateStore(s) => {
|
|
write!(f, "duplicate store {s}")
|
|
}
|
|
InvalidMatchCase => {
|
|
write!(f, "invalid match case")
|
|
}
|
|
NotImplementedYet => {
|
|
write!(f, "RustPython does not implement this feature yet")
|
|
}
|
|
}
|
|
}
|
|
}
|