@@ -466,23 +466,13 @@ def _emit_stmt(
466466 storage : Storage ,
467467 inst : Instruction | None ,
468468 ) -> tuple [bool , Token | None , Storage ]:
469- if isinstance (stmt , SimpleStmt ):
470- return self ._emit_simple (stmt , uop , storage , inst )
471- elif isinstance (stmt , BlockStmt ):
472- return self ._emit_block (stmt , uop , storage , inst )
473- elif isinstance (stmt , IfStmt ):
474- return self ._emit_if (stmt , uop , storage , inst )
475- elif isinstance (stmt , ForStmt ):
476- return self ._emit_for (stmt , uop , storage , inst )
477- elif isinstance (stmt , WhileStmt ):
478- return self ._emit_while (stmt , uop , storage , inst )
479- elif isinstance (stmt , MacroIfStmt ):
480- return self ._emit_macro_if (stmt , uop , storage , inst )
481- else :
482- raise NotImplementedError ("Unexpected statement" )
483-
469+ method_name = "emit_" + stmt .__class__ .__name__
470+ method = getattr (self , method_name , None )
471+ if method is None :
472+ raise NotImplementedError
473+ return method (stmt , uop , storage , inst ) # type: ignore
484474
485- def _emit_simple (
475+ def emit_SimpleStmt (
486476 self ,
487477 stmt : SimpleStmt ,
488478 uop : CodeSection ,
@@ -536,7 +526,7 @@ def _emit_simple(
536526 raise analysis_error (ex .args [0 ], tkn ) #from None
537527
538528
539- def _emit_macro_if (
529+ def emit_MacroIfStmt (
540530 self ,
541531 stmt : MacroIfStmt ,
542532 uop : CodeSection ,
@@ -568,7 +558,7 @@ def _emit_macro_if(
568558 return reachable , None , storage
569559
570560
571- def _emit_if (
561+ def emit_IfStmt (
572562 self ,
573563 stmt : IfStmt ,
574564 uop : CodeSection ,
@@ -610,7 +600,7 @@ def _emit_if(
610600 assert rbrace is not None
611601 raise analysis_error (ex .args [0 ], rbrace ) from None
612602
613- def _emit_block (
603+ def emit_BlockStmt (
614604 self ,
615605 stmt : BlockStmt ,
616606 uop : CodeSection ,
@@ -635,7 +625,7 @@ def _emit_block(
635625 tkn = stmt .close
636626 raise analysis_error (ex .args [0 ], tkn ) from None
637627
638- def _emit_for (
628+ def emit_ForStmt (
639629 self ,
640630 stmt : ForStmt ,
641631 uop : CodeSection ,
@@ -648,7 +638,7 @@ def _emit_for(
648638 self .out .emit (tkn )
649639 return self ._emit_stmt (stmt .body , uop , storage , inst )
650640
651- def _emit_while (
641+ def emit_WhileStmt (
652642 self ,
653643 stmt : WhileStmt ,
654644 uop : CodeSection ,
@@ -670,7 +660,7 @@ def emit_tokens(
670660 emit_braces : bool = True
671661 ) -> Storage :
672662 self .out .start_line ()
673- reachable , tkn , storage = self ._emit_block (code .body , code , storage , inst , emit_braces )
663+ reachable , tkn , storage = self .emit_BlockStmt (code .body , code , storage , inst , emit_braces )
674664 assert tkn is not None
675665 try :
676666 if reachable :
0 commit comments