33from formatting import Formatter
44import lexer as lx
55import parsing
6+ from typing import AbstractSet
67
78
89@dataclasses .dataclass
@@ -15,6 +16,7 @@ class InstructionFlags:
1516 HAS_JUMP_FLAG : bool
1617 HAS_FREE_FLAG : bool
1718 HAS_LOCAL_FLAG : bool
19+ HAS_EVAL_BREAK_FLAG : bool
1820
1921 def __post_init__ (self ) -> None :
2022 self .bitmask = {name : (1 << i ) for i , name in enumerate (self .names ())}
@@ -37,11 +39,12 @@ def fromInstruction(instr: parsing.Node) -> "InstructionFlags":
3739 variable_used (instr , "GETLOCAL" ) or variable_used (instr , "SETLOCAL" )
3840 )
3941 and not has_free ,
42+ HAS_EVAL_BREAK_FLAG = variable_used (instr , "CHECK_EVAL_BREAKER" ),
4043 )
4144
4245 @staticmethod
4346 def newEmpty () -> "InstructionFlags" :
44- return InstructionFlags (False , False , False , False , False , False )
47+ return InstructionFlags (False , False , False , False , False , False , False )
4548
4649 def add (self , other : "InstructionFlags" ) -> None :
4750 for name , value in dataclasses .asdict (other ).items ():
@@ -53,10 +56,11 @@ def names(self, value: bool | None = None) -> list[str]:
5356 return list (dataclasses .asdict (self ).keys ())
5457 return [n for n , v in dataclasses .asdict (self ).items () if v == value ]
5558
56- def bitmap (self ) -> int :
59+ def bitmap (self , ignore : AbstractSet [ str ] = frozenset () ) -> int :
5760 flags = 0
61+ assert all (hasattr (self , name ) for name in ignore )
5862 for name in self .names ():
59- if getattr (self , name ):
63+ if getattr (self , name ) and name not in ignore :
6064 flags |= self .bitmask [name ]
6165 return flags
6266
0 commit comments