@@ -456,30 +456,7 @@ impl Compiler {
456
456
}
457
457
ast:: Statement :: Delete { targets } => {
458
458
for target in targets {
459
- match target {
460
- ast:: Expression :: Identifier { name } => {
461
- self . emit ( Instruction :: DeleteName {
462
- name : name. to_string ( ) ,
463
- } ) ;
464
- }
465
- ast:: Expression :: Attribute { value, name } => {
466
- self . compile_expression ( value) ?;
467
- self . emit ( Instruction :: DeleteAttr {
468
- name : name. to_string ( ) ,
469
- } ) ;
470
- }
471
- ast:: Expression :: Subscript { a, b } => {
472
- self . compile_expression ( a) ?;
473
- self . compile_expression ( b) ?;
474
- self . emit ( Instruction :: DeleteSubscript ) ;
475
- }
476
- _ => {
477
- return Err ( CompileError {
478
- error : CompileErrorType :: Delete ( target. name ( ) ) ,
479
- location : self . current_source_location . clone ( ) ,
480
- } ) ;
481
- }
482
- }
459
+ self . compile_delete ( target) ?;
483
460
}
484
461
}
485
462
ast:: Statement :: Pass => {
@@ -489,6 +466,39 @@ impl Compiler {
489
466
Ok ( ( ) )
490
467
}
491
468
469
+ fn compile_delete ( & mut self , expression : & ast:: Expression ) -> Result < ( ) , CompileError > {
470
+ match expression {
471
+ ast:: Expression :: Identifier { name } => {
472
+ self . emit ( Instruction :: DeleteName {
473
+ name : name. to_string ( ) ,
474
+ } ) ;
475
+ }
476
+ ast:: Expression :: Attribute { value, name } => {
477
+ self . compile_expression ( value) ?;
478
+ self . emit ( Instruction :: DeleteAttr {
479
+ name : name. to_string ( ) ,
480
+ } ) ;
481
+ }
482
+ ast:: Expression :: Subscript { a, b } => {
483
+ self . compile_expression ( a) ?;
484
+ self . compile_expression ( b) ?;
485
+ self . emit ( Instruction :: DeleteSubscript ) ;
486
+ }
487
+ ast:: Expression :: Tuple { elements } => {
488
+ for element in elements {
489
+ self . compile_delete ( element) ?;
490
+ }
491
+ }
492
+ _ => {
493
+ return Err ( CompileError {
494
+ error : CompileErrorType :: Delete ( expression. name ( ) ) ,
495
+ location : self . current_source_location . clone ( ) ,
496
+ } ) ;
497
+ }
498
+ }
499
+ Ok ( ( ) )
500
+ }
501
+
492
502
fn enter_function (
493
503
& mut self ,
494
504
name : & str ,
0 commit comments