diff --git a/Cargo.lock b/Cargo.lock index 5ec65d9108..66dd00adfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1967,7 +1967,7 @@ dependencies = [ [[package]] name = "rustpython-ast" version = "0.2.0" -source = "git+https://github.com/RustPython/Parser.git?rev=48920a034e93ae7c737129ea427c068dc30e2da5#48920a034e93ae7c737129ea427c068dc30e2da5" +source = "git+https://github.com/RustPython/Parser.git?rev=7b8844bd3e470d6b835147ecb445202130ec18d8#7b8844bd3e470d6b835147ecb445202130ec18d8" dependencies = [ "num-bigint", "rustpython-compiler-core", @@ -2027,7 +2027,7 @@ dependencies = [ [[package]] name = "rustpython-compiler-core" version = "0.2.0" -source = "git+https://github.com/RustPython/Parser.git?rev=48920a034e93ae7c737129ea427c068dc30e2da5#48920a034e93ae7c737129ea427c068dc30e2da5" +source = "git+https://github.com/RustPython/Parser.git?rev=7b8844bd3e470d6b835147ecb445202130ec18d8#7b8844bd3e470d6b835147ecb445202130ec18d8" dependencies = [ "bitflags", "bstr", @@ -2089,7 +2089,7 @@ dependencies = [ [[package]] name = "rustpython-literal" version = "0.2.0" -source = "git+https://github.com/RustPython/Parser.git?rev=48920a034e93ae7c737129ea427c068dc30e2da5#48920a034e93ae7c737129ea427c068dc30e2da5" +source = "git+https://github.com/RustPython/Parser.git?rev=7b8844bd3e470d6b835147ecb445202130ec18d8#7b8844bd3e470d6b835147ecb445202130ec18d8" dependencies = [ "hexf-parse", "lexical-parse-float", @@ -2100,7 +2100,7 @@ dependencies = [ [[package]] name = "rustpython-parser" version = "0.2.0" -source = "git+https://github.com/RustPython/Parser.git?rev=48920a034e93ae7c737129ea427c068dc30e2da5#48920a034e93ae7c737129ea427c068dc30e2da5" +source = "git+https://github.com/RustPython/Parser.git?rev=7b8844bd3e470d6b835147ecb445202130ec18d8#7b8844bd3e470d6b835147ecb445202130ec18d8" dependencies = [ "ahash", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 98486b1b42..bb7ab3bbf2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,10 +17,10 @@ members = [ ] [workspace.dependencies] -rustpython-literal = { git = "https://github.com/RustPython/Parser.git", rev = "48920a034e93ae7c737129ea427c068dc30e2da5" } -rustpython-compiler-core = { git = "https://github.com/RustPython/Parser.git", rev = "48920a034e93ae7c737129ea427c068dc30e2da5" } -rustpython-parser = { git = "https://github.com/RustPython/Parser.git", rev = "48920a034e93ae7c737129ea427c068dc30e2da5" } -rustpython-ast = { git = "https://github.com/RustPython/Parser.git", rev = "48920a034e93ae7c737129ea427c068dc30e2da5" } +rustpython-literal = { git = "https://github.com/RustPython/Parser.git", rev = "7b8844bd3e470d6b835147ecb445202130ec18d8" } +rustpython-compiler-core = { git = "https://github.com/RustPython/Parser.git", rev = "7b8844bd3e470d6b835147ecb445202130ec18d8" } +rustpython-parser = { git = "https://github.com/RustPython/Parser.git", rev = "7b8844bd3e470d6b835147ecb445202130ec18d8" } +rustpython-ast = { git = "https://github.com/RustPython/Parser.git", rev = "7b8844bd3e470d6b835147ecb445202130ec18d8" } # rustpython-literal = { path = "../RustPython-parser/literal" } # rustpython-compiler-core = { path = "../RustPython-parser/core" } # rustpython-parser = { path = "../RustPython-parser/parser" } diff --git a/compiler/codegen/src/compile.rs b/compiler/codegen/src/compile.rs index 5a8da98586..f88b45d8e9 100644 --- a/compiler/codegen/src/compile.rs +++ b/compiler/codegen/src/compile.rs @@ -96,13 +96,15 @@ pub fn compile_top( opts: CompileOpts, ) -> CompileResult { match ast { - ast::Mod::Module { body, .. } => compile_program(body, source_path, opts), - ast::Mod::Interactive { body } => match mode { + ast::Mod::Module(ast::ModModule { body, .. }) => compile_program(body, source_path, opts), + ast::Mod::Interactive(ast::ModInteractive { body }) => match mode { Mode::Single => compile_program_single(body, source_path, opts), Mode::BlockExpr => compile_block_expression(body, source_path, opts), _ => unreachable!("only Single and BlockExpr parsed to Interactive"), }, - ast::Mod::Expression { body } => compile_expression(body, source_path, opts), + ast::Mod::Expression(ast::ModExpression { body }) => { + compile_expression(body, source_path, opts) + } ast::Mod::FunctionType { .. } => panic!("can't compile a FunctionType"), } } @@ -376,7 +378,7 @@ impl Compiler { if let Some((last, body)) = body.split_last() { for statement in body { - if let ast::StmtKind::Expr { value } = &statement.node { + if let ast::StmtKind::Expr(ast::StmtExpr { value }) = &statement.node { self.compile_expression(value)?; emit!(self, Instruction::PrintExpr); } else { @@ -384,7 +386,7 @@ impl Compiler { } } - if let ast::StmtKind::Expr { value } = &last.node { + if let ast::StmtKind::Expr(ast::StmtExpr { value }) = &last.node { self.compile_expression(value)?; emit!(self, Instruction::Duplicate); emit!(self, Instruction::PrintExpr); @@ -555,12 +557,14 @@ impl Compiler { fn compile_statement(&mut self, statement: &ast::Stmt) -> CompileResult<()> { trace!("Compiling {:?}", statement); self.set_source_location(statement.start()); - use ast::StmtKind::*; + use ast::{StmtKind::*, *}; match &statement.node { // we do this here because `from __future__` still executes that `from` statement at runtime, // we still need to compile the ImportFrom down below - ImportFrom { module, names, .. } if module.as_deref() == Some("__future__") => { + ImportFrom(ast::StmtImportFrom { module, names, .. }) + if module.as_deref() == Some("__future__") => + { self.compile_future_features(names)? } // if we find any other statement, stop accepting future statements @@ -568,7 +572,7 @@ impl Compiler { } match &statement.node { - Import { names } => { + Import(StmtImport { names }) => { // import a, b, c as d for name in names { let name = &name.node; @@ -589,11 +593,11 @@ impl Compiler { } } } - ImportFrom { + ImportFrom(StmtImportFrom { level, module, names, - } => { + }) => { let import_star = names.iter().any(|n| n.node.name == "*"); let from_list = if import_star { @@ -653,16 +657,16 @@ impl Compiler { emit!(self, Instruction::Pop); } } - Expr { value } => { + Expr(StmtExpr { value }) => { self.compile_expression(value)?; // Pop result of stack, since we not use it: emit!(self, Instruction::Pop); } - Global { .. } | Nonlocal { .. } => { + Global(StmtGlobal { .. }) | Nonlocal(StmtNonlocal { .. }) => { // Handled during symbol table construction. } - If { test, body, orelse } => { + If(StmtIf { test, body, orelse }) => { let after_block = self.new_block(); if orelse.is_empty() { // Only if: @@ -686,25 +690,25 @@ impl Compiler { } self.switch_to_block(after_block); } - While { test, body, orelse } => self.compile_while(test, body, orelse)?, - With { items, body, .. } => self.compile_with(items, body, false)?, - AsyncWith { items, body, .. } => self.compile_with(items, body, true)?, - For { + While(StmtWhile { test, body, orelse }) => self.compile_while(test, body, orelse)?, + With(StmtWith { items, body, .. }) => self.compile_with(items, body, false)?, + AsyncWith(StmtAsyncWith { items, body, .. }) => self.compile_with(items, body, true)?, + For(StmtFor { target, iter, body, orelse, .. - } => self.compile_for(target, iter, body, orelse, false)?, - AsyncFor { + }) => self.compile_for(target, iter, body, orelse, false)?, + AsyncFor(StmtAsyncFor { target, iter, body, orelse, .. - } => self.compile_for(target, iter, body, orelse, true)?, - Match { subject, cases } => self.compile_match(subject, cases)?, - Raise { exc, cause } => { + }) => self.compile_for(target, iter, body, orelse, true)?, + Match(StmtMatch { subject, cases }) => self.compile_match(subject, cases)?, + Raise(StmtRaise { exc, cause }) => { let kind = match exc { Some(value) => { self.compile_expression(value)?; @@ -720,26 +724,26 @@ impl Compiler { }; emit!(self, Instruction::Raise { kind }); } - Try { + Try(StmtTry { body, handlers, orelse, finalbody, - } => self.compile_try_statement(body, handlers, orelse, finalbody)?, - TryStar { + }) => self.compile_try_statement(body, handlers, orelse, finalbody)?, + TryStar(StmtTryStar { body, handlers, orelse, finalbody, - } => self.compile_try_star_statement(body, handlers, orelse, finalbody)?, - FunctionDef { + }) => self.compile_try_star_statement(body, handlers, orelse, finalbody)?, + FunctionDef(StmtFunctionDef { name, args, body, decorator_list, returns, .. - } => self.compile_function_def( + }) => self.compile_function_def( name, args, body, @@ -747,14 +751,14 @@ impl Compiler { returns.as_deref(), false, )?, - AsyncFunctionDef { + AsyncFunctionDef(StmtAsyncFunctionDef { name, args, body, decorator_list, returns, .. - } => self.compile_function_def( + }) => self.compile_function_def( name, args, body, @@ -762,14 +766,14 @@ impl Compiler { returns.as_deref(), true, )?, - ClassDef { + ClassDef(StmtClassDef { name, body, bases, keywords, decorator_list, - } => self.compile_class_def(name, body, bases, keywords, decorator_list)?, - Assert { test, msg } => { + }) => self.compile_class_def(name, body, bases, keywords, decorator_list)?, + Assert(StmtAssert { test, msg }) => { // if some flag, ignore all assert statements! if self.opts.optimize == 0 { let after_block = self.new_block(); @@ -814,7 +818,7 @@ impl Compiler { ); } }, - Return { value } => { + Return(StmtReturn { value }) => { if !self.ctx.in_func() { return Err(self.error_loc(CodegenErrorType::InvalidReturn, statement.start())); } @@ -838,7 +842,7 @@ impl Compiler { emit!(self, Instruction::ReturnValue); } - Assign { targets, value, .. } => { + Assign(StmtAssign { targets, value, .. }) => { self.compile_expression(value)?; for (i, target) in targets.iter().enumerate() { @@ -848,14 +852,16 @@ impl Compiler { self.compile_store(target)?; } } - AugAssign { target, op, value } => self.compile_augassign(target, op, value)?, - AnnAssign { + AugAssign(StmtAugAssign { target, op, value }) => { + self.compile_augassign(target, op, value)? + } + AnnAssign(StmtAnnAssign { target, annotation, value, .. - } => self.compile_annotated_assign(target, annotation, value.as_deref())?, - Delete { targets } => { + }) => self.compile_annotated_assign(target, annotation, value.as_deref())?, + Delete(StmtDelete { targets }) => { for target in targets { self.compile_delete(target)?; } @@ -869,24 +875,28 @@ impl Compiler { fn compile_delete(&mut self, expression: &ast::Expr) -> CompileResult<()> { match &expression.node { - ast::ExprKind::Name { id, .. } => self.compile_name(id, NameUsage::Delete)?, - ast::ExprKind::Attribute { value, attr, .. } => { + ast::ExprKind::Name(ast::ExprName { id, .. }) => { + self.compile_name(id, NameUsage::Delete)? + } + ast::ExprKind::Attribute(ast::ExprAttribute { value, attr, .. }) => { self.check_forbidden_name(attr, NameUsage::Delete)?; self.compile_expression(value)?; let idx = self.name(attr); emit!(self, Instruction::DeleteAttr { idx }); } - ast::ExprKind::Subscript { value, slice, .. } => { + ast::ExprKind::Subscript(ast::ExprSubscript { value, slice, .. }) => { self.compile_expression(value)?; self.compile_expression(slice)?; emit!(self, Instruction::DeleteSubscript); } - ast::ExprKind::Tuple { elts, .. } | ast::ExprKind::List { elts, .. } => { + ast::ExprKind::Tuple(ast::ExprTuple { elts, .. }) + | ast::ExprKind::List(ast::ExprList { elts, .. }) => { for element in elts { self.compile_delete(element)?; } } - ast::ExprKind::BinOp { .. } | ast::ExprKind::UnaryOp { .. } => { + ast::ExprKind::BinOp(ast::ExprBinOp { .. }) + | ast::ExprKind::UnaryOp(ast::ExprUnaryOp { .. }) => { return Err(self.error(CodegenErrorType::Delete("expression"))) } _ => return Err(self.error(CodegenErrorType::Delete(expression.node.name()))), @@ -1015,7 +1025,11 @@ impl Compiler { self.switch_to_block(handler_block); // Exception is on top of stack now for handler in handlers { - let ast::ExcepthandlerKind::ExceptHandler { type_, name, body } = &handler.node; + let ast::ExcepthandlerKind::ExceptHandler(ast::ExcepthandlerExceptHandler { + type_, + name, + body, + }) = &handler.node; let next_handler = self.new_block(); // If we gave a typ, @@ -1287,16 +1301,22 @@ impl Compiler { for statement in body { let res = match &statement.node { AnnAssign { .. } => true, - For { body, orelse, .. } => Self::find_ann(body) || Self::find_ann(orelse), - If { body, orelse, .. } => Self::find_ann(body) || Self::find_ann(orelse), - While { body, orelse, .. } => Self::find_ann(body) || Self::find_ann(orelse), - With { body, .. } => Self::find_ann(body), - Try { + For(ast::StmtFor { body, orelse, .. }) => { + Self::find_ann(body) || Self::find_ann(orelse) + } + If(ast::StmtIf { body, orelse, .. }) => { + Self::find_ann(body) || Self::find_ann(orelse) + } + While(ast::StmtWhile { body, orelse, .. }) => { + Self::find_ann(body) || Self::find_ann(orelse) + } + With(ast::StmtWith { body, .. }) => Self::find_ann(body), + Try(ast::StmtTry { body, orelse, finalbody, .. - } => Self::find_ann(body) || Self::find_ann(orelse) || Self::find_ann(finalbody), + }) => Self::find_ann(body) || Self::find_ann(orelse) || Self::find_ann(finalbody), _ => false, }; if res { @@ -1716,7 +1736,7 @@ impl Compiler { // Compile annotation: self.compile_annotation(annotation)?; - if let ast::ExprKind::Name { id, .. } = &target.node { + if let ast::ExprKind::Name(ast::ExprName { id, .. }) = &target.node { // Store as dict entry in __annotations__ dict: let annotations = self.name("__annotations__"); emit!(self, Instruction::LoadNameAny(annotations)); @@ -1734,19 +1754,20 @@ impl Compiler { fn compile_store(&mut self, target: &ast::Expr) -> CompileResult<()> { match &target.node { - ast::ExprKind::Name { id, .. } => self.store_name(id)?, - ast::ExprKind::Subscript { value, slice, .. } => { + ast::ExprKind::Name(ast::ExprName { id, .. }) => self.store_name(id)?, + ast::ExprKind::Subscript(ast::ExprSubscript { value, slice, .. }) => { self.compile_expression(value)?; self.compile_expression(slice)?; emit!(self, Instruction::StoreSubscript); } - ast::ExprKind::Attribute { value, attr, .. } => { + ast::ExprKind::Attribute(ast::ExprAttribute { value, attr, .. }) => { self.check_forbidden_name(attr, NameUsage::Store)?; self.compile_expression(value)?; let idx = self.name(attr); emit!(self, Instruction::StoreAttr { idx }); } - ast::ExprKind::List { elts, .. } | ast::ExprKind::Tuple { elts, .. } => { + ast::ExprKind::List(ast::ExprList { elts, .. }) + | ast::ExprKind::Tuple(ast::ExprTuple { elts, .. }) => { let mut seen_star = false; // Scan for star args: @@ -1781,7 +1802,7 @@ impl Compiler { } for element in elts { - if let ast::ExprKind::Starred { value, .. } = &element.node { + if let ast::ExprKind::Starred(ast::ExprStarred { value, .. }) = &element.node { self.compile_store(value)?; } else { self.compile_store(element)?; @@ -1814,18 +1835,18 @@ impl Compiler { } let kind = match &target.node { - ast::ExprKind::Name { id, .. } => { + ast::ExprKind::Name(ast::ExprName { id, .. }) => { self.compile_name(id, NameUsage::Load)?; AugAssignKind::Name { id } } - ast::ExprKind::Subscript { value, slice, .. } => { + ast::ExprKind::Subscript(ast::ExprSubscript { value, slice, .. }) => { self.compile_expression(value)?; self.compile_expression(slice)?; emit!(self, Instruction::Duplicate2); emit!(self, Instruction::Subscript); AugAssignKind::Subscript } - ast::ExprKind::Attribute { value, attr, .. } => { + ast::ExprKind::Attribute(ast::ExprAttribute { value, attr, .. }) => { self.check_forbidden_name(attr, NameUsage::Store)?; self.compile_expression(value)?; emit!(self, Instruction::Duplicate); @@ -1900,7 +1921,7 @@ impl Compiler { ) -> CompileResult<()> { // Compile expression for test, and jump to label if false match &expression.node { - ast::ExprKind::BoolOp { op, values } => { + ast::ExprKind::BoolOp(ast::ExprBoolOp { op, values }) => { match op { ast::Boolop::And => { if condition { @@ -1946,10 +1967,10 @@ impl Compiler { } } } - ast::ExprKind::UnaryOp { + ast::ExprKind::UnaryOp(ast::ExprUnaryOp { op: ast::Unaryop::Not, operand, - } => { + }) => { self.compile_jump_if(operand, !condition, target_block)?; } _ => { @@ -2041,25 +2062,25 @@ impl Compiler { use ast::ExprKind::*; match &expression.node { - Call { + Call(ast::ExprCall { func, args, keywords, - } => self.compile_call(func, args, keywords)?, - BoolOp { op, values } => self.compile_bool_op(op, values)?, - BinOp { left, op, right } => { + }) => self.compile_call(func, args, keywords)?, + BoolOp(ast::ExprBoolOp { op, values }) => self.compile_bool_op(op, values)?, + BinOp(ast::ExprBinOp { left, op, right }) => { self.compile_expression(left)?; self.compile_expression(right)?; // Perform operation: self.compile_op(op, false); } - Subscript { value, slice, .. } => { + Subscript(ast::ExprSubscript { value, slice, .. }) => { self.compile_expression(value)?; self.compile_expression(slice)?; emit!(self, Instruction::Subscript); } - UnaryOp { op, operand } => { + UnaryOp(ast::ExprUnaryOp { op, operand }) => { self.compile_expression(operand)?; // Perform operation: @@ -2071,22 +2092,22 @@ impl Compiler { }; emit!(self, Instruction::UnaryOperation { op }); } - Attribute { value, attr, .. } => { + Attribute(ast::ExprAttribute { value, attr, .. }) => { self.compile_expression(value)?; let idx = self.name(attr); emit!(self, Instruction::LoadAttr { idx }); } - Compare { + Compare(ast::ExprCompare { left, ops, comparators, - } => { + }) => { self.compile_chained_comparison(left, ops, comparators)?; } - Constant { value, .. } => { + Constant(ast::ExprConstant { value, .. }) => { self.emit_constant(compile_constant(value)); } - List { elts, .. } => { + List(ast::ExprList { elts, .. }) => { let (size, unpack) = self.gather_elements(0, elts)?; if unpack { emit!(self, Instruction::BuildListUnpack { size }); @@ -2094,7 +2115,7 @@ impl Compiler { emit!(self, Instruction::BuildList { size }); } } - Tuple { elts, .. } => { + Tuple(ast::ExprTuple { elts, .. }) => { let (size, unpack) = self.gather_elements(0, elts)?; if unpack { emit!(self, Instruction::BuildTupleUnpack { size }); @@ -2102,7 +2123,7 @@ impl Compiler { emit!(self, Instruction::BuildTuple { size }); } } - Set { elts, .. } => { + Set(ast::ExprSet { elts, .. }) => { let (size, unpack) = self.gather_elements(0, elts)?; if unpack { emit!(self, Instruction::BuildSetUnpack { size }); @@ -2110,10 +2131,10 @@ impl Compiler { emit!(self, Instruction::BuildSet { size }); } } - Dict { keys, values } => { + Dict(ast::ExprDict { keys, values }) => { self.compile_dict(keys, values)?; } - Slice { lower, upper, step } => { + Slice(ast::ExprSlice { lower, upper, step }) => { let mut compile_bound = |bound: Option<&ast::Expr>| match bound { Some(exp) => self.compile_expression(exp), None => { @@ -2129,7 +2150,7 @@ impl Compiler { let step = step.is_some(); emit!(self, Instruction::BuildSlice { step }); } - Yield { value } => { + Yield(ast::ExprYield { value }) => { if !self.ctx.in_func() { return Err(self.error(CodegenErrorType::InvalidYield)); } @@ -2140,7 +2161,7 @@ impl Compiler { }; emit!(self, Instruction::YieldValue); } - Await { value } => { + Await(ast::ExprAwait { value }) => { if self.ctx.func != FunctionContext::AsyncFunction { return Err(self.error(CodegenErrorType::InvalidAwait)); } @@ -2149,7 +2170,7 @@ impl Compiler { self.emit_constant(ConstantData::None); emit!(self, Instruction::YieldFrom); } - YieldFrom { value } => { + YieldFrom(ast::ExprYieldFrom { value }) => { match self.ctx.func { FunctionContext::NoFunction => { return Err(self.error(CodegenErrorType::InvalidYieldFrom)); @@ -2165,7 +2186,7 @@ impl Compiler { self.emit_constant(ConstantData::None); emit!(self, Instruction::YieldFrom); } - ast::ExprKind::JoinedStr { values } => { + ast::ExprKind::JoinedStr(ast::ExprJoinedStr { values }) => { if let Some(value) = try_get_constant_string(values) { self.emit_constant(ConstantData::Str { value }) } else { @@ -2180,11 +2201,11 @@ impl Compiler { ) } } - ast::ExprKind::FormattedValue { + ast::ExprKind::FormattedValue(ast::ExprFormattedValue { value, conversion, format_spec, - } => { + }) => { match format_spec { Some(spec) => self.compile_expression(spec)?, None => self.emit_constant(ConstantData::Str { @@ -2200,8 +2221,8 @@ impl Compiler { }, ); } - Name { id, .. } => self.load_name(id)?, - Lambda { args, body } => { + Name(ast::ExprName { id, .. }) => self.load_name(id)?, + Lambda(ast::ExprLambda { args, body }) => { let prev_ctx = self.ctx; let name = "".to_owned(); @@ -2232,7 +2253,7 @@ impl Compiler { self.ctx = prev_ctx; } - ListComp { elt, generators } => { + ListComp(ast::ExprListComp { elt, generators }) => { self.compile_comprehension( "", Some(Instruction::BuildList { @@ -2251,7 +2272,7 @@ impl Compiler { }, )?; } - SetComp { elt, generators } => { + SetComp(ast::ExprSetComp { elt, generators }) => { self.compile_comprehension( "", Some(Instruction::BuildSet { @@ -2270,11 +2291,11 @@ impl Compiler { }, )?; } - DictComp { + DictComp(ast::ExprDictComp { key, value, generators, - } => { + }) => { self.compile_comprehension( "", Some(Instruction::BuildMap { @@ -2297,7 +2318,7 @@ impl Compiler { }, )?; } - GeneratorExp { elt, generators } => { + GeneratorExp(ast::ExprGeneratorExp { elt, generators }) => { self.compile_comprehension("", None, generators, &|compiler| { compiler.compile_comprehension_element(elt)?; compiler.mark_generator(); @@ -2307,10 +2328,10 @@ impl Compiler { Ok(()) })?; } - Starred { .. } => { + Starred(ast::ExprStarred { .. }) => { return Err(self.error(CodegenErrorType::InvalidStarExpr)); } - IfExp { test, body, orelse } => { + IfExp(ast::ExprIfExp { test, body, orelse }) => { let else_block = self.new_block(); let after_block = self.new_block(); self.compile_jump_if(test, false, else_block)?; @@ -2332,7 +2353,7 @@ impl Compiler { self.switch_to_block(after_block); } - NamedExpr { target, value } => { + NamedExpr(ast::ExprNamedExpr { target, value }) => { self.compile_expression(value)?; emit!(self, Instruction::Duplicate); self.compile_store(target)?; @@ -2377,15 +2398,16 @@ impl Compiler { args: &[ast::Expr], keywords: &[ast::Keyword], ) -> CompileResult<()> { - let method = if let ast::ExprKind::Attribute { value, attr, .. } = &func.node { - self.compile_expression(value)?; - let idx = self.name(attr); - emit!(self, Instruction::LoadMethod { idx }); - true - } else { - self.compile_expression(func)?; - false - }; + let method = + if let ast::ExprKind::Attribute(ast::ExprAttribute { value, attr, .. }) = &func.node { + self.compile_expression(value)?; + let idx = self.name(attr); + emit!(self, Instruction::LoadMethod { idx }); + true + } else { + self.compile_expression(func)?; + false + }; let call = self.compile_call_inner(0, args, keywords)?; if method { self.compile_method_call(call) @@ -2494,7 +2516,7 @@ impl Compiler { let groups = elements .iter() .map(|element| { - if let ast::ExprKind::Starred { value, .. } = &element.node { + if let ast::ExprKind::Starred(ast::ExprStarred { value, .. }) = &element.node { (true, value.as_ref()) } else { (false, element) @@ -2791,7 +2813,7 @@ impl EmitArg for ir::BlockIdx { fn split_doc(body: &[ast::Stmt]) -> (Option, &[ast::Stmt]) { if let Some((val, body_rest)) = body.split_first() { - if let ast::StmtKind::Expr { value } = &val.node { + if let ast::StmtKind::Expr(ast::StmtExpr { value }) = &val.node { if let Some(doc) = try_get_constant_string(std::slice::from_ref(value)) { return (Some(doc), body_rest); } @@ -2803,14 +2825,14 @@ fn split_doc(body: &[ast::Stmt]) -> (Option, &[ast::Stmt]) { fn try_get_constant_string(values: &[ast::Expr]) -> Option { fn get_constant_string_inner(out_string: &mut String, value: &ast::Expr) -> bool { match &value.node { - ast::ExprKind::Constant { + ast::ExprKind::Constant(ast::ExprConstant { value: ast::Constant::Str(s), .. - } => { + }) => { out_string.push_str(s); true } - ast::ExprKind::JoinedStr { values } => values + ast::ExprKind::JoinedStr(ast::ExprJoinedStr { values }) => values .iter() .all(|value| get_constant_string_inner(out_string, value)), _ => false, diff --git a/compiler/codegen/src/symboltable.rs b/compiler/codegen/src/symboltable.rs index 73054272b3..6a86b5f8fd 100644 --- a/compiler/codegen/src/symboltable.rs +++ b/compiler/codegen/src/symboltable.rs @@ -634,9 +634,9 @@ impl SymbolTableBuilder { } fn scan_statement(&mut self, statement: &ast::Stmt) -> SymbolTableResult { - use ast::StmtKind::*; + use ast::{StmtKind::*, *}; let location = statement.start(); - if let ImportFrom { module, names, .. } = &statement.node { + if let ImportFrom(StmtImportFrom { module, names, .. }) = &statement.node { if module.as_deref() == Some("__future__") { for feature in names { if feature.node.name == "annotations" { @@ -646,32 +646,32 @@ impl SymbolTableBuilder { } } match &statement.node { - Global { names } => { + Global(StmtGlobal { names }) => { for name in names { self.register_name(name, SymbolUsage::Global, location)?; } } - Nonlocal { names } => { + Nonlocal(StmtNonlocal { names }) => { for name in names { self.register_name(name, SymbolUsage::Nonlocal, location)?; } } - FunctionDef { + FunctionDef(StmtFunctionDef { name, body, args, decorator_list, returns, .. - } - | AsyncFunctionDef { + }) + | AsyncFunctionDef(StmtAsyncFunctionDef { name, body, args, decorator_list, returns, .. - } => { + }) => { self.scan_expressions(decorator_list, ExpressionContext::Load)?; self.register_name(name, SymbolUsage::Assigned, location)?; if let Some(expression) = returns { @@ -681,13 +681,13 @@ impl SymbolTableBuilder { self.scan_statements(body)?; self.leave_scope(); } - ClassDef { + ClassDef(StmtClassDef { name, body, bases, keywords, decorator_list, - } => { + }) => { self.enter_scope(name, SymbolTableType::Class, location.row()); let prev_class = std::mem::replace(&mut self.class_name, Some(name.to_owned())); self.register_name("__module__", SymbolUsage::Assigned, location)?; @@ -704,32 +704,32 @@ impl SymbolTableBuilder { self.scan_expressions(decorator_list, ExpressionContext::Load)?; self.register_name(name, SymbolUsage::Assigned, location)?; } - Expr { value } => self.scan_expression(value, ExpressionContext::Load)?, - If { test, body, orelse } => { + Expr(StmtExpr { value }) => self.scan_expression(value, ExpressionContext::Load)?, + If(StmtIf { test, body, orelse }) => { self.scan_expression(test, ExpressionContext::Load)?; self.scan_statements(body)?; self.scan_statements(orelse)?; } - For { + For(StmtFor { target, iter, body, orelse, .. - } - | AsyncFor { + }) + | AsyncFor(StmtAsyncFor { target, iter, body, orelse, .. - } => { + }) => { self.scan_expression(target, ExpressionContext::Store)?; self.scan_expression(iter, ExpressionContext::Load)?; self.scan_statements(body)?; self.scan_statements(orelse)?; } - While { test, body, orelse } => { + While(StmtWhile { test, body, orelse }) => { self.scan_expression(test, ExpressionContext::Load)?; self.scan_statements(body)?; self.scan_statements(orelse)?; @@ -737,7 +737,7 @@ impl SymbolTableBuilder { Break | Continue | Pass => { // No symbols here. } - Import { names } | ImportFrom { names, .. } => { + Import(StmtImport { names }) | ImportFrom(StmtImportFrom { names, .. }) => { for name in names { if let Some(alias) = &name.node.asname { // `import my_module as my_alias` @@ -752,37 +752,37 @@ impl SymbolTableBuilder { } } } - Return { value } => { + Return(StmtReturn { value }) => { if let Some(expression) = value { self.scan_expression(expression, ExpressionContext::Load)?; } } - Assert { test, msg } => { + Assert(StmtAssert { test, msg }) => { self.scan_expression(test, ExpressionContext::Load)?; if let Some(expression) = msg { self.scan_expression(expression, ExpressionContext::Load)?; } } - Delete { targets } => { + Delete(StmtDelete { targets }) => { self.scan_expressions(targets, ExpressionContext::Delete)?; } - Assign { targets, value, .. } => { + Assign(StmtAssign { targets, value, .. }) => { self.scan_expressions(targets, ExpressionContext::Store)?; self.scan_expression(value, ExpressionContext::Load)?; } - AugAssign { target, value, .. } => { + AugAssign(StmtAugAssign { target, value, .. }) => { self.scan_expression(target, ExpressionContext::Store)?; self.scan_expression(value, ExpressionContext::Load)?; } - AnnAssign { + AnnAssign(StmtAnnAssign { target, annotation, value, simple, - } => { + }) => { // https://github.com/python/cpython/blob/main/Python/symtable.c#L1233 match &target.node { - ast::ExprKind::Name { id, .. } if *simple > 0 => { + ast::ExprKind::Name(ast::ExprName { id, .. }) if *simple > 0 => { self.register_name(id, SymbolUsage::AnnotationAssigned, location)?; } _ => { @@ -794,7 +794,7 @@ impl SymbolTableBuilder { self.scan_expression(value, ExpressionContext::Load)?; } } - With { items, body, .. } | AsyncWith { items, body, .. } => { + With(StmtWith { items, body, .. }) | AsyncWith(StmtAsyncWith { items, body, .. }) => { for item in items { self.scan_expression(&item.context_expr, ExpressionContext::Load)?; if let Some(expression) = &item.optional_vars { @@ -803,21 +803,25 @@ impl SymbolTableBuilder { } self.scan_statements(body)?; } - Try { + Try(StmtTry { body, handlers, orelse, finalbody, - } - | TryStar { + }) + | TryStar(StmtTryStar { body, handlers, orelse, finalbody, - } => { + }) => { self.scan_statements(body)?; for handler in handlers { - let ast::ExcepthandlerKind::ExceptHandler { type_, name, body } = &handler.node; + let ast::ExcepthandlerKind::ExceptHandler(ast::ExcepthandlerExceptHandler { + type_, + name, + body, + }) = &handler.node; if let Some(expression) = type_ { self.scan_expression(expression, ExpressionContext::Load)?; } @@ -829,16 +833,16 @@ impl SymbolTableBuilder { self.scan_statements(orelse)?; self.scan_statements(finalbody)?; } - Match { + Match(StmtMatch { subject: _, cases: _, - } => { + }) => { return Err(SymbolTableError { error: "match expression is not implemented yet".to_owned(), location: Location::default(), }); } - Raise { exc, cause } => { + Raise(StmtRaise { exc, cause }) => { if let Some(expression) = exc { self.scan_expression(expression, ExpressionContext::Load)?; } @@ -866,30 +870,30 @@ impl SymbolTableBuilder { expression: &ast::Expr, context: ExpressionContext, ) -> SymbolTableResult { - use ast::ExprKind::*; + use ast::{ExprKind::*, *}; let location = expression.start(); match &expression.node { - BinOp { left, right, .. } => { + BinOp(ExprBinOp { left, right, .. }) => { self.scan_expression(left, context)?; self.scan_expression(right, context)?; } - BoolOp { values, .. } => { + BoolOp(ExprBoolOp { values, .. }) => { self.scan_expressions(values, context)?; } - Compare { + Compare(ExprCompare { left, comparators, .. - } => { + }) => { self.scan_expression(left, context)?; self.scan_expressions(comparators, context)?; } - Subscript { value, slice, .. } => { + Subscript(ExprSubscript { value, slice, .. }) => { self.scan_expression(value, ExpressionContext::Load)?; self.scan_expression(slice, ExpressionContext::Load)?; } - Attribute { value, .. } => { + Attribute(ExprAttribute { value, .. }) => { self.scan_expression(value, ExpressionContext::Load)?; } - Dict { keys, values } => { + Dict(ExprDict { keys, values }) => { for (key, value) in keys.iter().zip(values.iter()) { if let Some(key) = key { self.scan_expression(key, context)?; @@ -897,28 +901,30 @@ impl SymbolTableBuilder { self.scan_expression(value, context)?; } } - Await { value } => { + Await(ExprAwait { value }) => { self.scan_expression(value, context)?; } - Yield { value } => { + Yield(ExprYield { value }) => { if let Some(expression) = value { self.scan_expression(expression, context)?; } } - YieldFrom { value } => { + YieldFrom(ExprYieldFrom { value }) => { self.scan_expression(value, context)?; } - UnaryOp { operand, .. } => { + UnaryOp(ExprUnaryOp { operand, .. }) => { self.scan_expression(operand, context)?; } - Constant { .. } => {} - Starred { value, .. } => { + Constant(ExprConstant { .. }) => {} + Starred(ExprStarred { value, .. }) => { self.scan_expression(value, context)?; } - Tuple { elts, .. } | Set { elts, .. } | List { elts, .. } => { + Tuple(ExprTuple { elts, .. }) + | Set(ExprSet { elts, .. }) + | List(ExprList { elts, .. }) => { self.scan_expressions(elts, context)?; } - Slice { lower, upper, step } => { + Slice(ExprSlice { lower, upper, step }) => { if let Some(lower) = lower { self.scan_expression(lower, context)?; } @@ -929,27 +935,27 @@ impl SymbolTableBuilder { self.scan_expression(step, context)?; } } - GeneratorExp { elt, generators } => { + GeneratorExp(ExprGeneratorExp { elt, generators }) => { self.scan_comprehension("genexpr", elt, None, generators, location)?; } - ListComp { elt, generators } => { + ListComp(ExprListComp { elt, generators }) => { self.scan_comprehension("genexpr", elt, None, generators, location)?; } - SetComp { elt, generators } => { + SetComp(ExprSetComp { elt, generators }) => { self.scan_comprehension("genexpr", elt, None, generators, location)?; } - DictComp { + DictComp(ExprDictComp { key, value, generators, - } => { + }) => { self.scan_comprehension("genexpr", key, Some(value), generators, location)?; } - Call { + Call(ExprCall { func, args, keywords, - } => { + }) => { match context { ExpressionContext::IterDefinitionExp => { self.scan_expression(func, ExpressionContext::IterDefinitionExp)?; @@ -964,20 +970,20 @@ impl SymbolTableBuilder { self.scan_expression(&keyword.node.value, ExpressionContext::Load)?; } } - FormattedValue { + FormattedValue(ExprFormattedValue { value, format_spec, .. - } => { + }) => { self.scan_expression(value, ExpressionContext::Load)?; if let Some(spec) = format_spec { self.scan_expression(spec, ExpressionContext::Load)?; } } - JoinedStr { values } => { + JoinedStr(ExprJoinedStr { values }) => { for value in values { self.scan_expression(value, ExpressionContext::Load)?; } } - Name { id, .. } => { + Name(ExprName { id, .. }) => { // Determine the contextual usage of this symbol: match context { ExpressionContext::Delete => { @@ -1003,7 +1009,7 @@ impl SymbolTableBuilder { self.register_name("__class__", SymbolUsage::Used, location)?; } } - Lambda { args, body } => { + Lambda(ExprLambda { args, body }) => { self.enter_function("lambda", args, expression.start().row())?; match context { ExpressionContext::IterDefinitionExp => { @@ -1015,13 +1021,13 @@ impl SymbolTableBuilder { } self.leave_scope(); } - IfExp { test, body, orelse } => { + IfExp(ExprIfExp { test, body, orelse }) => { self.scan_expression(test, ExpressionContext::Load)?; self.scan_expression(body, ExpressionContext::Load)?; self.scan_expression(orelse, ExpressionContext::Load)?; } - NamedExpr { target, value } => { + NamedExpr(ExprNamedExpr { target, value }) => { // named expressions are not allowed in the definition of // comprehension iterator definitions if let ExpressionContext::IterDefinitionExp = context { @@ -1038,7 +1044,7 @@ impl SymbolTableBuilder { // that are used in comprehensions. This required to correctly // propagate the scope of the named assigned named and not to // propagate inner names. - if let Name { id, .. } = &target.node { + if let Name(ExprName { id, .. }) = &target.node { let table = self.tables.last().unwrap(); if table.typ == SymbolTableType::Comprehension { self.register_name( diff --git a/vm/src/stdlib/ast/gen.rs b/vm/src/stdlib/ast/gen.rs index a942a3499d..8f2eced740 100644 --- a/vm/src/stdlib/ast/gen.rs +++ b/vm/src/stdlib/ast/gen.rs @@ -2226,7 +2226,7 @@ impl NamedNode for ast::Mod { impl Node for ast::Mod { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { match self { - ast::Mod::Module { body, type_ignores } => { + ast::Mod::Module(ast::ModModule { body, type_ignores }) => { let _node = AstNode .into_ref_with_type(_vm, NodeModule::static_type().to_owned()) .unwrap(); @@ -2239,7 +2239,7 @@ impl Node for ast::Mod { .unwrap(); _node.into() } - ast::Mod::Interactive { body } => { + ast::Mod::Interactive(ast::ModInteractive { body }) => { let _node = AstNode .into_ref_with_type(_vm, NodeInteractive::static_type().to_owned()) .unwrap(); @@ -2249,7 +2249,7 @@ impl Node for ast::Mod { .unwrap(); _node.into() } - ast::Mod::Expression { body } => { + ast::Mod::Expression(ast::ModExpression { body }) => { let _node = AstNode .into_ref_with_type(_vm, NodeExpression::static_type().to_owned()) .unwrap(); @@ -2259,7 +2259,7 @@ impl Node for ast::Mod { .unwrap(); _node.into() } - ast::Mod::FunctionType { argtypes, returns } => { + ast::Mod::FunctionType(ast::ModFunctionType { argtypes, returns }) => { let _node = AstNode .into_ref_with_type(_vm, NodeFunctionType::static_type().to_owned()) .unwrap(); @@ -2277,23 +2277,23 @@ impl Node for ast::Mod { fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult { let _cls = _object.class(); Ok(if _cls.is(NodeModule::static_type()) { - ast::Mod::Module { + ast::Mod::Module(ast::ModModule { body: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "body", "mod")?)?, type_ignores: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "type_ignores", "mod")?, )?, - } + }) } else if _cls.is(NodeInteractive::static_type()) { - ast::Mod::Interactive { + ast::Mod::Interactive(ast::ModInteractive { body: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "body", "mod")?)?, - } + }) } else if _cls.is(NodeExpression::static_type()) { - ast::Mod::Expression { + ast::Mod::Expression(ast::ModExpression { body: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "body", "mod")?)?, - } + }) } else if _cls.is(NodeFunctionType::static_type()) { - ast::Mod::FunctionType { + ast::Mod::FunctionType(ast::ModFunctionType { argtypes: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "argtypes", "mod")?, @@ -2302,7 +2302,7 @@ impl Node for ast::Mod { _vm, get_node_field(_vm, &_object, "returns", "mod")?, )?, - } + }) } else { return Err(_vm.new_type_error(format!( "expected some sort of mod, but got {}", @@ -2317,14 +2317,14 @@ impl NamedNode for ast::StmtKind { impl Node for ast::StmtKind { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { match self { - ast::StmtKind::FunctionDef { + ast::StmtKind::FunctionDef(ast::StmtFunctionDef { name, args, body, decorator_list, returns, type_comment, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeFunctionDef::static_type().to_owned()) .unwrap(); @@ -2349,14 +2349,14 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::AsyncFunctionDef { + ast::StmtKind::AsyncFunctionDef(ast::StmtAsyncFunctionDef { name, args, body, decorator_list, returns, type_comment, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeAsyncFunctionDef::static_type().to_owned()) .unwrap(); @@ -2381,13 +2381,13 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::ClassDef { + ast::StmtKind::ClassDef(ast::StmtClassDef { name, bases, keywords, body, decorator_list, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeClassDef::static_type().to_owned()) .unwrap(); @@ -2409,7 +2409,7 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::Return { value } => { + ast::StmtKind::Return(ast::StmtReturn { value }) => { let _node = AstNode .into_ref_with_type(_vm, NodeReturn::static_type().to_owned()) .unwrap(); @@ -2419,7 +2419,7 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::Delete { targets } => { + ast::StmtKind::Delete(ast::StmtDelete { targets }) => { let _node = AstNode .into_ref_with_type(_vm, NodeDelete::static_type().to_owned()) .unwrap(); @@ -2429,11 +2429,11 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::Assign { + ast::StmtKind::Assign(ast::StmtAssign { targets, value, type_comment, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeAssign::static_type().to_owned()) .unwrap(); @@ -2449,7 +2449,7 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::AugAssign { target, op, value } => { + ast::StmtKind::AugAssign(ast::StmtAugAssign { target, op, value }) => { let _node = AstNode .into_ref_with_type(_vm, NodeAugAssign::static_type().to_owned()) .unwrap(); @@ -2463,12 +2463,12 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::AnnAssign { + ast::StmtKind::AnnAssign(ast::StmtAnnAssign { target, annotation, value, simple, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeAnnAssign::static_type().to_owned()) .unwrap(); @@ -2487,13 +2487,13 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::For { + ast::StmtKind::For(ast::StmtFor { target, iter, body, orelse, type_comment, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeFor::static_type().to_owned()) .unwrap(); @@ -2515,13 +2515,13 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::AsyncFor { + ast::StmtKind::AsyncFor(ast::StmtAsyncFor { target, iter, body, orelse, type_comment, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeAsyncFor::static_type().to_owned()) .unwrap(); @@ -2543,7 +2543,7 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::While { test, body, orelse } => { + ast::StmtKind::While(ast::StmtWhile { test, body, orelse }) => { let _node = AstNode .into_ref_with_type(_vm, NodeWhile::static_type().to_owned()) .unwrap(); @@ -2559,7 +2559,7 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::If { test, body, orelse } => { + ast::StmtKind::If(ast::StmtIf { test, body, orelse }) => { let _node = AstNode .into_ref_with_type(_vm, NodeIf::static_type().to_owned()) .unwrap(); @@ -2575,11 +2575,11 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::With { + ast::StmtKind::With(ast::StmtWith { items, body, type_comment, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeWith::static_type().to_owned()) .unwrap(); @@ -2595,11 +2595,11 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::AsyncWith { + ast::StmtKind::AsyncWith(ast::StmtAsyncWith { items, body, type_comment, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeAsyncWith::static_type().to_owned()) .unwrap(); @@ -2615,7 +2615,7 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::Match { subject, cases } => { + ast::StmtKind::Match(ast::StmtMatch { subject, cases }) => { let _node = AstNode .into_ref_with_type(_vm, NodeMatch::static_type().to_owned()) .unwrap(); @@ -2628,7 +2628,7 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::Raise { exc, cause } => { + ast::StmtKind::Raise(ast::StmtRaise { exc, cause }) => { let _node = AstNode .into_ref_with_type(_vm, NodeRaise::static_type().to_owned()) .unwrap(); @@ -2639,12 +2639,12 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::Try { + ast::StmtKind::Try(ast::StmtTry { body, handlers, orelse, finalbody, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeTry::static_type().to_owned()) .unwrap(); @@ -2663,12 +2663,12 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::TryStar { + ast::StmtKind::TryStar(ast::StmtTryStar { body, handlers, orelse, finalbody, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeTryStar::static_type().to_owned()) .unwrap(); @@ -2687,7 +2687,7 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::Assert { test, msg } => { + ast::StmtKind::Assert(ast::StmtAssert { test, msg }) => { let _node = AstNode .into_ref_with_type(_vm, NodeAssert::static_type().to_owned()) .unwrap(); @@ -2698,7 +2698,7 @@ impl Node for ast::StmtKind { _dict.set_item("msg", msg.ast_to_object(_vm), _vm).unwrap(); _node.into() } - ast::StmtKind::Import { names } => { + ast::StmtKind::Import(ast::StmtImport { names }) => { let _node = AstNode .into_ref_with_type(_vm, NodeImport::static_type().to_owned()) .unwrap(); @@ -2708,11 +2708,11 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::ImportFrom { + ast::StmtKind::ImportFrom(ast::StmtImportFrom { module, names, level, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeImportFrom::static_type().to_owned()) .unwrap(); @@ -2728,7 +2728,7 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::Global { names } => { + ast::StmtKind::Global(ast::StmtGlobal { names }) => { let _node = AstNode .into_ref_with_type(_vm, NodeGlobal::static_type().to_owned()) .unwrap(); @@ -2738,7 +2738,7 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::Nonlocal { names } => { + ast::StmtKind::Nonlocal(ast::StmtNonlocal { names }) => { let _node = AstNode .into_ref_with_type(_vm, NodeNonlocal::static_type().to_owned()) .unwrap(); @@ -2748,7 +2748,7 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::Expr { value } => { + ast::StmtKind::Expr(ast::StmtExpr { value }) => { let _node = AstNode .into_ref_with_type(_vm, NodeExpr::static_type().to_owned()) .unwrap(); @@ -2758,19 +2758,19 @@ impl Node for ast::StmtKind { .unwrap(); _node.into() } - ast::StmtKind::Pass {} => { + ast::StmtKind::Pass => { let _node = AstNode .into_ref_with_type(_vm, NodePass::static_type().to_owned()) .unwrap(); _node.into() } - ast::StmtKind::Break {} => { + ast::StmtKind::Break => { let _node = AstNode .into_ref_with_type(_vm, NodeBreak::static_type().to_owned()) .unwrap(); _node.into() } - ast::StmtKind::Continue {} => { + ast::StmtKind::Continue => { let _node = AstNode .into_ref_with_type(_vm, NodeContinue::static_type().to_owned()) .unwrap(); @@ -2785,7 +2785,7 @@ impl Node for ast::StmtKind { ); let _cls = _object.class(); Ok(if _cls.is(NodeFunctionDef::static_type()) { - ast::StmtKind::FunctionDef { + ast::StmtKind::FunctionDef(ast::StmtFunctionDef { name: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "name", "stmt")?)?, args: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "args", "stmt")?)?, body: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "body", "stmt")?)?, @@ -2799,9 +2799,9 @@ impl Node for ast::StmtKind { type_comment: get_node_field_opt(_vm, &_object, "type_comment")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeAsyncFunctionDef::static_type()) { - ast::StmtKind::AsyncFunctionDef { + ast::StmtKind::AsyncFunctionDef(ast::StmtAsyncFunctionDef { name: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "name", "stmt")?)?, args: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "args", "stmt")?)?, body: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "body", "stmt")?)?, @@ -2815,9 +2815,9 @@ impl Node for ast::StmtKind { type_comment: get_node_field_opt(_vm, &_object, "type_comment")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeClassDef::static_type()) { - ast::StmtKind::ClassDef { + ast::StmtKind::ClassDef(ast::StmtClassDef { name: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "name", "stmt")?)?, bases: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "bases", "stmt")?)?, keywords: Node::ast_from_object( @@ -2829,22 +2829,22 @@ impl Node for ast::StmtKind { _vm, get_node_field(_vm, &_object, "decorator_list", "stmt")?, )?, - } + }) } else if _cls.is(NodeReturn::static_type()) { - ast::StmtKind::Return { + ast::StmtKind::Return(ast::StmtReturn { value: get_node_field_opt(_vm, &_object, "value")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeDelete::static_type()) { - ast::StmtKind::Delete { + ast::StmtKind::Delete(ast::StmtDelete { targets: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "targets", "stmt")?, )?, - } + }) } else if _cls.is(NodeAssign::static_type()) { - ast::StmtKind::Assign { + ast::StmtKind::Assign(ast::StmtAssign { targets: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "targets", "stmt")?, @@ -2853,18 +2853,18 @@ impl Node for ast::StmtKind { type_comment: get_node_field_opt(_vm, &_object, "type_comment")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeAugAssign::static_type()) { - ast::StmtKind::AugAssign { + ast::StmtKind::AugAssign(ast::StmtAugAssign { target: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "target", "stmt")?, )?, op: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "op", "stmt")?)?, value: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "value", "stmt")?)?, - } + }) } else if _cls.is(NodeAnnAssign::static_type()) { - ast::StmtKind::AnnAssign { + ast::StmtKind::AnnAssign(ast::StmtAnnAssign { target: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "target", "stmt")?, @@ -2880,9 +2880,9 @@ impl Node for ast::StmtKind { _vm, get_node_field(_vm, &_object, "simple", "stmt")?, )?, - } + }) } else if _cls.is(NodeFor::static_type()) { - ast::StmtKind::For { + ast::StmtKind::For(ast::StmtFor { target: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "target", "stmt")?, @@ -2896,9 +2896,9 @@ impl Node for ast::StmtKind { type_comment: get_node_field_opt(_vm, &_object, "type_comment")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeAsyncFor::static_type()) { - ast::StmtKind::AsyncFor { + ast::StmtKind::AsyncFor(ast::StmtAsyncFor { target: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "target", "stmt")?, @@ -2912,60 +2912,60 @@ impl Node for ast::StmtKind { type_comment: get_node_field_opt(_vm, &_object, "type_comment")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeWhile::static_type()) { - ast::StmtKind::While { + ast::StmtKind::While(ast::StmtWhile { test: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "test", "stmt")?)?, body: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "body", "stmt")?)?, orelse: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "orelse", "stmt")?, )?, - } + }) } else if _cls.is(NodeIf::static_type()) { - ast::StmtKind::If { + ast::StmtKind::If(ast::StmtIf { test: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "test", "stmt")?)?, body: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "body", "stmt")?)?, orelse: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "orelse", "stmt")?, )?, - } + }) } else if _cls.is(NodeWith::static_type()) { - ast::StmtKind::With { + ast::StmtKind::With(ast::StmtWith { items: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "items", "stmt")?)?, body: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "body", "stmt")?)?, type_comment: get_node_field_opt(_vm, &_object, "type_comment")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeAsyncWith::static_type()) { - ast::StmtKind::AsyncWith { + ast::StmtKind::AsyncWith(ast::StmtAsyncWith { items: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "items", "stmt")?)?, body: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "body", "stmt")?)?, type_comment: get_node_field_opt(_vm, &_object, "type_comment")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeMatch::static_type()) { - ast::StmtKind::Match { + ast::StmtKind::Match(ast::StmtMatch { subject: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "subject", "stmt")?, )?, cases: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "cases", "stmt")?)?, - } + }) } else if _cls.is(NodeRaise::static_type()) { - ast::StmtKind::Raise { + ast::StmtKind::Raise(ast::StmtRaise { exc: get_node_field_opt(_vm, &_object, "exc")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, cause: get_node_field_opt(_vm, &_object, "cause")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeTry::static_type()) { - ast::StmtKind::Try { + ast::StmtKind::Try(ast::StmtTry { body: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "body", "stmt")?)?, handlers: Node::ast_from_object( _vm, @@ -2979,9 +2979,9 @@ impl Node for ast::StmtKind { _vm, get_node_field(_vm, &_object, "finalbody", "stmt")?, )?, - } + }) } else if _cls.is(NodeTryStar::static_type()) { - ast::StmtKind::TryStar { + ast::StmtKind::TryStar(ast::StmtTryStar { body: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "body", "stmt")?)?, handlers: Node::ast_from_object( _vm, @@ -2995,20 +2995,20 @@ impl Node for ast::StmtKind { _vm, get_node_field(_vm, &_object, "finalbody", "stmt")?, )?, - } + }) } else if _cls.is(NodeAssert::static_type()) { - ast::StmtKind::Assert { + ast::StmtKind::Assert(ast::StmtAssert { test: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "test", "stmt")?)?, msg: get_node_field_opt(_vm, &_object, "msg")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeImport::static_type()) { - ast::StmtKind::Import { + ast::StmtKind::Import(ast::StmtImport { names: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "names", "stmt")?)?, - } + }) } else if _cls.is(NodeImportFrom::static_type()) { - ast::StmtKind::ImportFrom { + ast::StmtKind::ImportFrom(ast::StmtImportFrom { module: get_node_field_opt(_vm, &_object, "module")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, @@ -3016,25 +3016,25 @@ impl Node for ast::StmtKind { level: get_node_field_opt(_vm, &_object, "level")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeGlobal::static_type()) { - ast::StmtKind::Global { + ast::StmtKind::Global(ast::StmtGlobal { names: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "names", "stmt")?)?, - } + }) } else if _cls.is(NodeNonlocal::static_type()) { - ast::StmtKind::Nonlocal { + ast::StmtKind::Nonlocal(ast::StmtNonlocal { names: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "names", "stmt")?)?, - } + }) } else if _cls.is(NodeExpr::static_type()) { - ast::StmtKind::Expr { + ast::StmtKind::Expr(ast::StmtExpr { value: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "value", "stmt")?)?, - } + }) } else if _cls.is(NodePass::static_type()) { - ast::StmtKind::Pass {} + ast::StmtKind::Pass } else if _cls.is(NodeBreak::static_type()) { - ast::StmtKind::Break {} + ast::StmtKind::Break } else if _cls.is(NodeContinue::static_type()) { - ast::StmtKind::Continue {} + ast::StmtKind::Continue } else { return Err(_vm.new_type_error(format!( "expected some sort of stmt, but got {}", @@ -3049,7 +3049,7 @@ impl NamedNode for ast::ExprKind { impl Node for ast::ExprKind { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { match self { - ast::ExprKind::BoolOp { op, values } => { + ast::ExprKind::BoolOp(ast::ExprBoolOp { op, values }) => { let _node = AstNode .into_ref_with_type(_vm, NodeBoolOp::static_type().to_owned()) .unwrap(); @@ -3060,7 +3060,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::NamedExpr { target, value } => { + ast::ExprKind::NamedExpr(ast::ExprNamedExpr { target, value }) => { let _node = AstNode .into_ref_with_type(_vm, NodeNamedExpr::static_type().to_owned()) .unwrap(); @@ -3073,7 +3073,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::BinOp { left, op, right } => { + ast::ExprKind::BinOp(ast::ExprBinOp { left, op, right }) => { let _node = AstNode .into_ref_with_type(_vm, NodeBinOp::static_type().to_owned()) .unwrap(); @@ -3087,7 +3087,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::UnaryOp { op, operand } => { + ast::ExprKind::UnaryOp(ast::ExprUnaryOp { op, operand }) => { let _node = AstNode .into_ref_with_type(_vm, NodeUnaryOp::static_type().to_owned()) .unwrap(); @@ -3098,7 +3098,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::Lambda { args, body } => { + ast::ExprKind::Lambda(ast::ExprLambda { args, body }) => { let _node = AstNode .into_ref_with_type(_vm, NodeLambda::static_type().to_owned()) .unwrap(); @@ -3111,7 +3111,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::IfExp { test, body, orelse } => { + ast::ExprKind::IfExp(ast::ExprIfExp { test, body, orelse }) => { let _node = AstNode .into_ref_with_type(_vm, NodeIfExp::static_type().to_owned()) .unwrap(); @@ -3127,7 +3127,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::Dict { keys, values } => { + ast::ExprKind::Dict(ast::ExprDict { keys, values }) => { let _node = AstNode .into_ref_with_type(_vm, NodeDict::static_type().to_owned()) .unwrap(); @@ -3140,7 +3140,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::Set { elts } => { + ast::ExprKind::Set(ast::ExprSet { elts }) => { let _node = AstNode .into_ref_with_type(_vm, NodeSet::static_type().to_owned()) .unwrap(); @@ -3150,7 +3150,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::ListComp { elt, generators } => { + ast::ExprKind::ListComp(ast::ExprListComp { elt, generators }) => { let _node = AstNode .into_ref_with_type(_vm, NodeListComp::static_type().to_owned()) .unwrap(); @@ -3161,7 +3161,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::SetComp { elt, generators } => { + ast::ExprKind::SetComp(ast::ExprSetComp { elt, generators }) => { let _node = AstNode .into_ref_with_type(_vm, NodeSetComp::static_type().to_owned()) .unwrap(); @@ -3172,11 +3172,11 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::DictComp { + ast::ExprKind::DictComp(ast::ExprDictComp { key, value, generators, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeDictComp::static_type().to_owned()) .unwrap(); @@ -3190,7 +3190,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::GeneratorExp { elt, generators } => { + ast::ExprKind::GeneratorExp(ast::ExprGeneratorExp { elt, generators }) => { let _node = AstNode .into_ref_with_type(_vm, NodeGeneratorExp::static_type().to_owned()) .unwrap(); @@ -3201,7 +3201,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::Await { value } => { + ast::ExprKind::Await(ast::ExprAwait { value }) => { let _node = AstNode .into_ref_with_type(_vm, NodeAwait::static_type().to_owned()) .unwrap(); @@ -3211,7 +3211,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::Yield { value } => { + ast::ExprKind::Yield(ast::ExprYield { value }) => { let _node = AstNode .into_ref_with_type(_vm, NodeYield::static_type().to_owned()) .unwrap(); @@ -3221,7 +3221,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::YieldFrom { value } => { + ast::ExprKind::YieldFrom(ast::ExprYieldFrom { value }) => { let _node = AstNode .into_ref_with_type(_vm, NodeYieldFrom::static_type().to_owned()) .unwrap(); @@ -3231,11 +3231,11 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::Compare { + ast::ExprKind::Compare(ast::ExprCompare { left, ops, comparators, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeCompare::static_type().to_owned()) .unwrap(); @@ -3249,11 +3249,11 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::Call { + ast::ExprKind::Call(ast::ExprCall { func, args, keywords, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeCall::static_type().to_owned()) .unwrap(); @@ -3269,11 +3269,11 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::FormattedValue { + ast::ExprKind::FormattedValue(ast::ExprFormattedValue { value, conversion, format_spec, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeFormattedValue::static_type().to_owned()) .unwrap(); @@ -3289,7 +3289,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::JoinedStr { values } => { + ast::ExprKind::JoinedStr(ast::ExprJoinedStr { values }) => { let _node = AstNode .into_ref_with_type(_vm, NodeJoinedStr::static_type().to_owned()) .unwrap(); @@ -3299,7 +3299,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::Constant { value, kind } => { + ast::ExprKind::Constant(ast::ExprConstant { value, kind }) => { let _node = AstNode .into_ref_with_type(_vm, NodeConstant::static_type().to_owned()) .unwrap(); @@ -3312,7 +3312,7 @@ impl Node for ast::ExprKind { .unwrap(); _node.into() } - ast::ExprKind::Attribute { value, attr, ctx } => { + ast::ExprKind::Attribute(ast::ExprAttribute { value, attr, ctx }) => { let _node = AstNode .into_ref_with_type(_vm, NodeAttribute::static_type().to_owned()) .unwrap(); @@ -3326,7 +3326,7 @@ impl Node for ast::ExprKind { _dict.set_item("ctx", ctx.ast_to_object(_vm), _vm).unwrap(); _node.into() } - ast::ExprKind::Subscript { value, slice, ctx } => { + ast::ExprKind::Subscript(ast::ExprSubscript { value, slice, ctx }) => { let _node = AstNode .into_ref_with_type(_vm, NodeSubscript::static_type().to_owned()) .unwrap(); @@ -3340,7 +3340,7 @@ impl Node for ast::ExprKind { _dict.set_item("ctx", ctx.ast_to_object(_vm), _vm).unwrap(); _node.into() } - ast::ExprKind::Starred { value, ctx } => { + ast::ExprKind::Starred(ast::ExprStarred { value, ctx }) => { let _node = AstNode .into_ref_with_type(_vm, NodeStarred::static_type().to_owned()) .unwrap(); @@ -3351,7 +3351,7 @@ impl Node for ast::ExprKind { _dict.set_item("ctx", ctx.ast_to_object(_vm), _vm).unwrap(); _node.into() } - ast::ExprKind::Name { id, ctx } => { + ast::ExprKind::Name(ast::ExprName { id, ctx }) => { let _node = AstNode .into_ref_with_type(_vm, NodeName::static_type().to_owned()) .unwrap(); @@ -3360,7 +3360,7 @@ impl Node for ast::ExprKind { _dict.set_item("ctx", ctx.ast_to_object(_vm), _vm).unwrap(); _node.into() } - ast::ExprKind::List { elts, ctx } => { + ast::ExprKind::List(ast::ExprList { elts, ctx }) => { let _node = AstNode .into_ref_with_type(_vm, NodeList::static_type().to_owned()) .unwrap(); @@ -3371,7 +3371,7 @@ impl Node for ast::ExprKind { _dict.set_item("ctx", ctx.ast_to_object(_vm), _vm).unwrap(); _node.into() } - ast::ExprKind::Tuple { elts, ctx } => { + ast::ExprKind::Tuple(ast::ExprTuple { elts, ctx }) => { let _node = AstNode .into_ref_with_type(_vm, NodeTuple::static_type().to_owned()) .unwrap(); @@ -3382,7 +3382,7 @@ impl Node for ast::ExprKind { _dict.set_item("ctx", ctx.ast_to_object(_vm), _vm).unwrap(); _node.into() } - ast::ExprKind::Slice { lower, upper, step } => { + ast::ExprKind::Slice(ast::ExprSlice { lower, upper, step }) => { let _node = AstNode .into_ref_with_type(_vm, NodeSlice::static_type().to_owned()) .unwrap(); @@ -3407,128 +3407,128 @@ impl Node for ast::ExprKind { ); let _cls = _object.class(); Ok(if _cls.is(NodeBoolOp::static_type()) { - ast::ExprKind::BoolOp { + ast::ExprKind::BoolOp(ast::ExprBoolOp { op: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "op", "expr")?)?, values: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "values", "expr")?, )?, - } + }) } else if _cls.is(NodeNamedExpr::static_type()) { - ast::ExprKind::NamedExpr { + ast::ExprKind::NamedExpr(ast::ExprNamedExpr { target: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "target", "expr")?, )?, value: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "value", "expr")?)?, - } + }) } else if _cls.is(NodeBinOp::static_type()) { - ast::ExprKind::BinOp { + ast::ExprKind::BinOp(ast::ExprBinOp { left: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "left", "expr")?)?, op: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "op", "expr")?)?, right: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "right", "expr")?)?, - } + }) } else if _cls.is(NodeUnaryOp::static_type()) { - ast::ExprKind::UnaryOp { + ast::ExprKind::UnaryOp(ast::ExprUnaryOp { op: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "op", "expr")?)?, operand: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "operand", "expr")?, )?, - } + }) } else if _cls.is(NodeLambda::static_type()) { - ast::ExprKind::Lambda { + ast::ExprKind::Lambda(ast::ExprLambda { args: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "args", "expr")?)?, body: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "body", "expr")?)?, - } + }) } else if _cls.is(NodeIfExp::static_type()) { - ast::ExprKind::IfExp { + ast::ExprKind::IfExp(ast::ExprIfExp { test: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "test", "expr")?)?, body: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "body", "expr")?)?, orelse: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "orelse", "expr")?, )?, - } + }) } else if _cls.is(NodeDict::static_type()) { - ast::ExprKind::Dict { + ast::ExprKind::Dict(ast::ExprDict { keys: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "keys", "expr")?)?, values: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "values", "expr")?, )?, - } + }) } else if _cls.is(NodeSet::static_type()) { - ast::ExprKind::Set { + ast::ExprKind::Set(ast::ExprSet { elts: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "elts", "expr")?)?, - } + }) } else if _cls.is(NodeListComp::static_type()) { - ast::ExprKind::ListComp { + ast::ExprKind::ListComp(ast::ExprListComp { elt: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "elt", "expr")?)?, generators: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "generators", "expr")?, )?, - } + }) } else if _cls.is(NodeSetComp::static_type()) { - ast::ExprKind::SetComp { + ast::ExprKind::SetComp(ast::ExprSetComp { elt: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "elt", "expr")?)?, generators: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "generators", "expr")?, )?, - } + }) } else if _cls.is(NodeDictComp::static_type()) { - ast::ExprKind::DictComp { + ast::ExprKind::DictComp(ast::ExprDictComp { key: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "key", "expr")?)?, value: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "value", "expr")?)?, generators: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "generators", "expr")?, )?, - } + }) } else if _cls.is(NodeGeneratorExp::static_type()) { - ast::ExprKind::GeneratorExp { + ast::ExprKind::GeneratorExp(ast::ExprGeneratorExp { elt: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "elt", "expr")?)?, generators: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "generators", "expr")?, )?, - } + }) } else if _cls.is(NodeAwait::static_type()) { - ast::ExprKind::Await { + ast::ExprKind::Await(ast::ExprAwait { value: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "value", "expr")?)?, - } + }) } else if _cls.is(NodeYield::static_type()) { - ast::ExprKind::Yield { + ast::ExprKind::Yield(ast::ExprYield { value: get_node_field_opt(_vm, &_object, "value")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeYieldFrom::static_type()) { - ast::ExprKind::YieldFrom { + ast::ExprKind::YieldFrom(ast::ExprYieldFrom { value: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "value", "expr")?)?, - } + }) } else if _cls.is(NodeCompare::static_type()) { - ast::ExprKind::Compare { + ast::ExprKind::Compare(ast::ExprCompare { left: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "left", "expr")?)?, ops: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "ops", "expr")?)?, comparators: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "comparators", "expr")?, )?, - } + }) } else if _cls.is(NodeCall::static_type()) { - ast::ExprKind::Call { + ast::ExprKind::Call(ast::ExprCall { func: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "func", "expr")?)?, args: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "args", "expr")?)?, keywords: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "keywords", "expr")?, )?, - } + }) } else if _cls.is(NodeFormattedValue::static_type()) { - ast::ExprKind::FormattedValue { + ast::ExprKind::FormattedValue(ast::ExprFormattedValue { value: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "value", "expr")?)?, conversion: Node::ast_from_object( _vm, @@ -3537,55 +3537,55 @@ impl Node for ast::ExprKind { format_spec: get_node_field_opt(_vm, &_object, "format_spec")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeJoinedStr::static_type()) { - ast::ExprKind::JoinedStr { + ast::ExprKind::JoinedStr(ast::ExprJoinedStr { values: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "values", "expr")?, )?, - } + }) } else if _cls.is(NodeConstant::static_type()) { - ast::ExprKind::Constant { + ast::ExprKind::Constant(ast::ExprConstant { value: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "value", "expr")?)?, kind: get_node_field_opt(_vm, &_object, "kind")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeAttribute::static_type()) { - ast::ExprKind::Attribute { + ast::ExprKind::Attribute(ast::ExprAttribute { value: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "value", "expr")?)?, attr: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "attr", "expr")?)?, ctx: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "ctx", "expr")?)?, - } + }) } else if _cls.is(NodeSubscript::static_type()) { - ast::ExprKind::Subscript { + ast::ExprKind::Subscript(ast::ExprSubscript { value: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "value", "expr")?)?, slice: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "slice", "expr")?)?, ctx: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "ctx", "expr")?)?, - } + }) } else if _cls.is(NodeStarred::static_type()) { - ast::ExprKind::Starred { + ast::ExprKind::Starred(ast::ExprStarred { value: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "value", "expr")?)?, ctx: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "ctx", "expr")?)?, - } + }) } else if _cls.is(NodeName::static_type()) { - ast::ExprKind::Name { + ast::ExprKind::Name(ast::ExprName { id: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "id", "expr")?)?, ctx: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "ctx", "expr")?)?, - } + }) } else if _cls.is(NodeList::static_type()) { - ast::ExprKind::List { + ast::ExprKind::List(ast::ExprList { elts: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "elts", "expr")?)?, ctx: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "ctx", "expr")?)?, - } + }) } else if _cls.is(NodeTuple::static_type()) { - ast::ExprKind::Tuple { + ast::ExprKind::Tuple(ast::ExprTuple { elts: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "elts", "expr")?)?, ctx: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "ctx", "expr")?)?, - } + }) } else if _cls.is(NodeSlice::static_type()) { - ast::ExprKind::Slice { + ast::ExprKind::Slice(ast::ExprSlice { lower: get_node_field_opt(_vm, &_object, "lower")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, @@ -3595,7 +3595,7 @@ impl Node for ast::ExprKind { step: get_node_field_opt(_vm, &_object, "step")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else { return Err(_vm.new_type_error(format!( "expected some sort of expr, but got {}", @@ -3610,19 +3610,19 @@ impl NamedNode for ast::ExprContext { impl Node for ast::ExprContext { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { match self { - ast::ExprContext::Load {} => { + ast::ExprContext::Load => { let _node = AstNode .into_ref_with_type(_vm, NodeLoad::static_type().to_owned()) .unwrap(); _node.into() } - ast::ExprContext::Store {} => { + ast::ExprContext::Store => { let _node = AstNode .into_ref_with_type(_vm, NodeStore::static_type().to_owned()) .unwrap(); _node.into() } - ast::ExprContext::Del {} => { + ast::ExprContext::Del => { let _node = AstNode .into_ref_with_type(_vm, NodeDel::static_type().to_owned()) .unwrap(); @@ -3633,11 +3633,11 @@ impl Node for ast::ExprContext { fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult { let _cls = _object.class(); Ok(if _cls.is(NodeLoad::static_type()) { - ast::ExprContext::Load {} + ast::ExprContext::Load } else if _cls.is(NodeStore::static_type()) { - ast::ExprContext::Store {} + ast::ExprContext::Store } else if _cls.is(NodeDel::static_type()) { - ast::ExprContext::Del {} + ast::ExprContext::Del } else { return Err(_vm.new_type_error(format!( "expected some sort of expr_context, but got {}", @@ -3652,13 +3652,13 @@ impl NamedNode for ast::Boolop { impl Node for ast::Boolop { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { match self { - ast::Boolop::And {} => { + ast::Boolop::And => { let _node = AstNode .into_ref_with_type(_vm, NodeAnd::static_type().to_owned()) .unwrap(); _node.into() } - ast::Boolop::Or {} => { + ast::Boolop::Or => { let _node = AstNode .into_ref_with_type(_vm, NodeOr::static_type().to_owned()) .unwrap(); @@ -3669,9 +3669,9 @@ impl Node for ast::Boolop { fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult { let _cls = _object.class(); Ok(if _cls.is(NodeAnd::static_type()) { - ast::Boolop::And {} + ast::Boolop::And } else if _cls.is(NodeOr::static_type()) { - ast::Boolop::Or {} + ast::Boolop::Or } else { return Err(_vm.new_type_error(format!( "expected some sort of boolop, but got {}", @@ -3686,79 +3686,79 @@ impl NamedNode for ast::Operator { impl Node for ast::Operator { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { match self { - ast::Operator::Add {} => { + ast::Operator::Add => { let _node = AstNode .into_ref_with_type(_vm, NodeAdd::static_type().to_owned()) .unwrap(); _node.into() } - ast::Operator::Sub {} => { + ast::Operator::Sub => { let _node = AstNode .into_ref_with_type(_vm, NodeSub::static_type().to_owned()) .unwrap(); _node.into() } - ast::Operator::Mult {} => { + ast::Operator::Mult => { let _node = AstNode .into_ref_with_type(_vm, NodeMult::static_type().to_owned()) .unwrap(); _node.into() } - ast::Operator::MatMult {} => { + ast::Operator::MatMult => { let _node = AstNode .into_ref_with_type(_vm, NodeMatMult::static_type().to_owned()) .unwrap(); _node.into() } - ast::Operator::Div {} => { + ast::Operator::Div => { let _node = AstNode .into_ref_with_type(_vm, NodeDiv::static_type().to_owned()) .unwrap(); _node.into() } - ast::Operator::Mod {} => { + ast::Operator::Mod => { let _node = AstNode .into_ref_with_type(_vm, NodeMod::static_type().to_owned()) .unwrap(); _node.into() } - ast::Operator::Pow {} => { + ast::Operator::Pow => { let _node = AstNode .into_ref_with_type(_vm, NodePow::static_type().to_owned()) .unwrap(); _node.into() } - ast::Operator::LShift {} => { + ast::Operator::LShift => { let _node = AstNode .into_ref_with_type(_vm, NodeLShift::static_type().to_owned()) .unwrap(); _node.into() } - ast::Operator::RShift {} => { + ast::Operator::RShift => { let _node = AstNode .into_ref_with_type(_vm, NodeRShift::static_type().to_owned()) .unwrap(); _node.into() } - ast::Operator::BitOr {} => { + ast::Operator::BitOr => { let _node = AstNode .into_ref_with_type(_vm, NodeBitOr::static_type().to_owned()) .unwrap(); _node.into() } - ast::Operator::BitXor {} => { + ast::Operator::BitXor => { let _node = AstNode .into_ref_with_type(_vm, NodeBitXor::static_type().to_owned()) .unwrap(); _node.into() } - ast::Operator::BitAnd {} => { + ast::Operator::BitAnd => { let _node = AstNode .into_ref_with_type(_vm, NodeBitAnd::static_type().to_owned()) .unwrap(); _node.into() } - ast::Operator::FloorDiv {} => { + ast::Operator::FloorDiv => { let _node = AstNode .into_ref_with_type(_vm, NodeFloorDiv::static_type().to_owned()) .unwrap(); @@ -3769,31 +3769,31 @@ impl Node for ast::Operator { fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult { let _cls = _object.class(); Ok(if _cls.is(NodeAdd::static_type()) { - ast::Operator::Add {} + ast::Operator::Add } else if _cls.is(NodeSub::static_type()) { - ast::Operator::Sub {} + ast::Operator::Sub } else if _cls.is(NodeMult::static_type()) { - ast::Operator::Mult {} + ast::Operator::Mult } else if _cls.is(NodeMatMult::static_type()) { - ast::Operator::MatMult {} + ast::Operator::MatMult } else if _cls.is(NodeDiv::static_type()) { - ast::Operator::Div {} + ast::Operator::Div } else if _cls.is(NodeMod::static_type()) { - ast::Operator::Mod {} + ast::Operator::Mod } else if _cls.is(NodePow::static_type()) { - ast::Operator::Pow {} + ast::Operator::Pow } else if _cls.is(NodeLShift::static_type()) { - ast::Operator::LShift {} + ast::Operator::LShift } else if _cls.is(NodeRShift::static_type()) { - ast::Operator::RShift {} + ast::Operator::RShift } else if _cls.is(NodeBitOr::static_type()) { - ast::Operator::BitOr {} + ast::Operator::BitOr } else if _cls.is(NodeBitXor::static_type()) { - ast::Operator::BitXor {} + ast::Operator::BitXor } else if _cls.is(NodeBitAnd::static_type()) { - ast::Operator::BitAnd {} + ast::Operator::BitAnd } else if _cls.is(NodeFloorDiv::static_type()) { - ast::Operator::FloorDiv {} + ast::Operator::FloorDiv } else { return Err(_vm.new_type_error(format!( "expected some sort of operator, but got {}", @@ -3808,25 +3808,25 @@ impl NamedNode for ast::Unaryop { impl Node for ast::Unaryop { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { match self { - ast::Unaryop::Invert {} => { + ast::Unaryop::Invert => { let _node = AstNode .into_ref_with_type(_vm, NodeInvert::static_type().to_owned()) .unwrap(); _node.into() } - ast::Unaryop::Not {} => { + ast::Unaryop::Not => { let _node = AstNode .into_ref_with_type(_vm, NodeNot::static_type().to_owned()) .unwrap(); _node.into() } - ast::Unaryop::UAdd {} => { + ast::Unaryop::UAdd => { let _node = AstNode .into_ref_with_type(_vm, NodeUAdd::static_type().to_owned()) .unwrap(); _node.into() } - ast::Unaryop::USub {} => { + ast::Unaryop::USub => { let _node = AstNode .into_ref_with_type(_vm, NodeUSub::static_type().to_owned()) .unwrap(); @@ -3837,13 +3837,13 @@ impl Node for ast::Unaryop { fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult { let _cls = _object.class(); Ok(if _cls.is(NodeInvert::static_type()) { - ast::Unaryop::Invert {} + ast::Unaryop::Invert } else if _cls.is(NodeNot::static_type()) { - ast::Unaryop::Not {} + ast::Unaryop::Not } else if _cls.is(NodeUAdd::static_type()) { - ast::Unaryop::UAdd {} + ast::Unaryop::UAdd } else if _cls.is(NodeUSub::static_type()) { - ast::Unaryop::USub {} + ast::Unaryop::USub } else { return Err(_vm.new_type_error(format!( "expected some sort of unaryop, but got {}", @@ -3858,61 +3858,61 @@ impl NamedNode for ast::Cmpop { impl Node for ast::Cmpop { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { match self { - ast::Cmpop::Eq {} => { + ast::Cmpop::Eq => { let _node = AstNode .into_ref_with_type(_vm, NodeEq::static_type().to_owned()) .unwrap(); _node.into() } - ast::Cmpop::NotEq {} => { + ast::Cmpop::NotEq => { let _node = AstNode .into_ref_with_type(_vm, NodeNotEq::static_type().to_owned()) .unwrap(); _node.into() } - ast::Cmpop::Lt {} => { + ast::Cmpop::Lt => { let _node = AstNode .into_ref_with_type(_vm, NodeLt::static_type().to_owned()) .unwrap(); _node.into() } - ast::Cmpop::LtE {} => { + ast::Cmpop::LtE => { let _node = AstNode .into_ref_with_type(_vm, NodeLtE::static_type().to_owned()) .unwrap(); _node.into() } - ast::Cmpop::Gt {} => { + ast::Cmpop::Gt => { let _node = AstNode .into_ref_with_type(_vm, NodeGt::static_type().to_owned()) .unwrap(); _node.into() } - ast::Cmpop::GtE {} => { + ast::Cmpop::GtE => { let _node = AstNode .into_ref_with_type(_vm, NodeGtE::static_type().to_owned()) .unwrap(); _node.into() } - ast::Cmpop::Is {} => { + ast::Cmpop::Is => { let _node = AstNode .into_ref_with_type(_vm, NodeIs::static_type().to_owned()) .unwrap(); _node.into() } - ast::Cmpop::IsNot {} => { + ast::Cmpop::IsNot => { let _node = AstNode .into_ref_with_type(_vm, NodeIsNot::static_type().to_owned()) .unwrap(); _node.into() } - ast::Cmpop::In {} => { + ast::Cmpop::In => { let _node = AstNode .into_ref_with_type(_vm, NodeIn::static_type().to_owned()) .unwrap(); _node.into() } - ast::Cmpop::NotIn {} => { + ast::Cmpop::NotIn => { let _node = AstNode .into_ref_with_type(_vm, NodeNotIn::static_type().to_owned()) .unwrap(); @@ -3923,25 +3923,25 @@ impl Node for ast::Cmpop { fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult { let _cls = _object.class(); Ok(if _cls.is(NodeEq::static_type()) { - ast::Cmpop::Eq {} + ast::Cmpop::Eq } else if _cls.is(NodeNotEq::static_type()) { - ast::Cmpop::NotEq {} + ast::Cmpop::NotEq } else if _cls.is(NodeLt::static_type()) { - ast::Cmpop::Lt {} + ast::Cmpop::Lt } else if _cls.is(NodeLtE::static_type()) { - ast::Cmpop::LtE {} + ast::Cmpop::LtE } else if _cls.is(NodeGt::static_type()) { - ast::Cmpop::Gt {} + ast::Cmpop::Gt } else if _cls.is(NodeGtE::static_type()) { - ast::Cmpop::GtE {} + ast::Cmpop::GtE } else if _cls.is(NodeIs::static_type()) { - ast::Cmpop::Is {} + ast::Cmpop::Is } else if _cls.is(NodeIsNot::static_type()) { - ast::Cmpop::IsNot {} + ast::Cmpop::IsNot } else if _cls.is(NodeIn::static_type()) { - ast::Cmpop::In {} + ast::Cmpop::In } else if _cls.is(NodeNotIn::static_type()) { - ast::Cmpop::NotIn {} + ast::Cmpop::NotIn } else { return Err(_vm.new_type_error(format!( "expected some sort of cmpop, but got {}", @@ -4004,7 +4004,11 @@ impl NamedNode for ast::ExcepthandlerKind { impl Node for ast::ExcepthandlerKind { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { match self { - ast::ExcepthandlerKind::ExceptHandler { type_, name, body } => { + ast::ExcepthandlerKind::ExceptHandler(ast::ExcepthandlerExceptHandler { + type_, + name, + body, + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeExceptHandler::static_type().to_owned()) .unwrap(); @@ -4035,7 +4039,7 @@ impl Node for ast::ExcepthandlerKind { ); let _cls = _object.class(); Ok(if _cls.is(NodeExceptHandler::static_type()) { - ast::ExcepthandlerKind::ExceptHandler { + ast::ExcepthandlerKind::ExceptHandler(ast::ExcepthandlerExceptHandler { type_: get_node_field_opt(_vm, &_object, "type")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, @@ -4046,7 +4050,7 @@ impl Node for ast::ExcepthandlerKind { _vm, get_node_field(_vm, &_object, "body", "excepthandler")?, )?, - } + }) } else { return Err(_vm.new_type_error(format!( "expected some sort of excepthandler, but got {}", @@ -4300,7 +4304,7 @@ impl NamedNode for ast::PatternKind { impl Node for ast::PatternKind { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { match self { - ast::PatternKind::MatchValue { value } => { + ast::PatternKind::MatchValue(ast::PatternMatchValue { value }) => { let _node = AstNode .into_ref_with_type(_vm, NodeMatchValue::static_type().to_owned()) .unwrap(); @@ -4310,7 +4314,7 @@ impl Node for ast::PatternKind { .unwrap(); _node.into() } - ast::PatternKind::MatchSingleton { value } => { + ast::PatternKind::MatchSingleton(ast::PatternMatchSingleton { value }) => { let _node = AstNode .into_ref_with_type(_vm, NodeMatchSingleton::static_type().to_owned()) .unwrap(); @@ -4320,7 +4324,7 @@ impl Node for ast::PatternKind { .unwrap(); _node.into() } - ast::PatternKind::MatchSequence { patterns } => { + ast::PatternKind::MatchSequence(ast::PatternMatchSequence { patterns }) => { let _node = AstNode .into_ref_with_type(_vm, NodeMatchSequence::static_type().to_owned()) .unwrap(); @@ -4330,11 +4334,11 @@ impl Node for ast::PatternKind { .unwrap(); _node.into() } - ast::PatternKind::MatchMapping { + ast::PatternKind::MatchMapping(ast::PatternMatchMapping { keys, patterns, rest, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeMatchMapping::static_type().to_owned()) .unwrap(); @@ -4350,12 +4354,12 @@ impl Node for ast::PatternKind { .unwrap(); _node.into() } - ast::PatternKind::MatchClass { + ast::PatternKind::MatchClass(ast::PatternMatchClass { cls, patterns, kwd_attrs, kwd_patterns, - } => { + }) => { let _node = AstNode .into_ref_with_type(_vm, NodeMatchClass::static_type().to_owned()) .unwrap(); @@ -4372,7 +4376,7 @@ impl Node for ast::PatternKind { .unwrap(); _node.into() } - ast::PatternKind::MatchStar { name } => { + ast::PatternKind::MatchStar(ast::PatternMatchStar { name }) => { let _node = AstNode .into_ref_with_type(_vm, NodeMatchStar::static_type().to_owned()) .unwrap(); @@ -4382,7 +4386,7 @@ impl Node for ast::PatternKind { .unwrap(); _node.into() } - ast::PatternKind::MatchAs { pattern, name } => { + ast::PatternKind::MatchAs(ast::PatternMatchAs { pattern, name }) => { let _node = AstNode .into_ref_with_type(_vm, NodeMatchAs::static_type().to_owned()) .unwrap(); @@ -4395,7 +4399,7 @@ impl Node for ast::PatternKind { .unwrap(); _node.into() } - ast::PatternKind::MatchOr { patterns } => { + ast::PatternKind::MatchOr(ast::PatternMatchOr { patterns }) => { let _node = AstNode .into_ref_with_type(_vm, NodeMatchOr::static_type().to_owned()) .unwrap(); @@ -4414,28 +4418,28 @@ impl Node for ast::PatternKind { ); let _cls = _object.class(); Ok(if _cls.is(NodeMatchValue::static_type()) { - ast::PatternKind::MatchValue { + ast::PatternKind::MatchValue(ast::PatternMatchValue { value: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "value", "pattern")?, )?, - } + }) } else if _cls.is(NodeMatchSingleton::static_type()) { - ast::PatternKind::MatchSingleton { + ast::PatternKind::MatchSingleton(ast::PatternMatchSingleton { value: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "value", "pattern")?, )?, - } + }) } else if _cls.is(NodeMatchSequence::static_type()) { - ast::PatternKind::MatchSequence { + ast::PatternKind::MatchSequence(ast::PatternMatchSequence { patterns: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "patterns", "pattern")?, )?, - } + }) } else if _cls.is(NodeMatchMapping::static_type()) { - ast::PatternKind::MatchMapping { + ast::PatternKind::MatchMapping(ast::PatternMatchMapping { keys: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "keys", "pattern")?, @@ -4447,9 +4451,9 @@ impl Node for ast::PatternKind { rest: get_node_field_opt(_vm, &_object, "rest")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeMatchClass::static_type()) { - ast::PatternKind::MatchClass { + ast::PatternKind::MatchClass(ast::PatternMatchClass { cls: Node::ast_from_object(_vm, get_node_field(_vm, &_object, "cls", "pattern")?)?, patterns: Node::ast_from_object( _vm, @@ -4463,29 +4467,29 @@ impl Node for ast::PatternKind { _vm, get_node_field(_vm, &_object, "kwd_patterns", "pattern")?, )?, - } + }) } else if _cls.is(NodeMatchStar::static_type()) { - ast::PatternKind::MatchStar { + ast::PatternKind::MatchStar(ast::PatternMatchStar { name: get_node_field_opt(_vm, &_object, "name")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeMatchAs::static_type()) { - ast::PatternKind::MatchAs { + ast::PatternKind::MatchAs(ast::PatternMatchAs { pattern: get_node_field_opt(_vm, &_object, "pattern")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, name: get_node_field_opt(_vm, &_object, "name")? .map(|obj| Node::ast_from_object(_vm, obj)) .transpose()?, - } + }) } else if _cls.is(NodeMatchOr::static_type()) { - ast::PatternKind::MatchOr { + ast::PatternKind::MatchOr(ast::PatternMatchOr { patterns: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "patterns", "pattern")?, )?, - } + }) } else { return Err(_vm.new_type_error(format!( "expected some sort of pattern, but got {}", @@ -4500,7 +4504,7 @@ impl NamedNode for ast::TypeIgnore { impl Node for ast::TypeIgnore { fn ast_to_object(self, _vm: &VirtualMachine) -> PyObjectRef { match self { - ast::TypeIgnore::TypeIgnore { lineno, tag } => { + ast::TypeIgnore::TypeIgnore(ast::TypeIgnoreTypeIgnore { lineno, tag }) => { let _node = AstNode .into_ref_with_type(_vm, NodeTypeIgnore::static_type().to_owned()) .unwrap(); @@ -4516,7 +4520,7 @@ impl Node for ast::TypeIgnore { fn ast_from_object(_vm: &VirtualMachine, _object: PyObjectRef) -> PyResult { let _cls = _object.class(); Ok(if _cls.is(NodeTypeIgnore::static_type()) { - ast::TypeIgnore::TypeIgnore { + ast::TypeIgnore::TypeIgnore(ast::TypeIgnoreTypeIgnore { lineno: Node::ast_from_object( _vm, get_node_field(_vm, &_object, "lineno", "type_ignore")?, @@ -4525,7 +4529,7 @@ impl Node for ast::TypeIgnore { _vm, get_node_field(_vm, &_object, "tag", "type_ignore")?, )?, - } + }) } else { return Err(_vm.new_type_error(format!( "expected some sort of type_ignore, but got {}",