3
3
from formatting import Formatter
4
4
import lexer as lx
5
5
import parsing
6
+ from typing import AbstractSet
6
7
7
8
8
9
@dataclasses .dataclass
@@ -15,6 +16,7 @@ class InstructionFlags:
15
16
HAS_JUMP_FLAG : bool
16
17
HAS_FREE_FLAG : bool
17
18
HAS_LOCAL_FLAG : bool
19
+ HAS_EVAL_BREAK_FLAG : bool
18
20
19
21
def __post_init__ (self ) -> None :
20
22
self .bitmask = {name : (1 << i ) for i , name in enumerate (self .names ())}
@@ -37,11 +39,12 @@ def fromInstruction(instr: parsing.Node) -> "InstructionFlags":
37
39
variable_used (instr , "GETLOCAL" ) or variable_used (instr , "SETLOCAL" )
38
40
)
39
41
and not has_free ,
42
+ HAS_EVAL_BREAK_FLAG = variable_used (instr , "CHECK_EVAL_BREAKER" ),
40
43
)
41
44
42
45
@staticmethod
43
46
def newEmpty () -> "InstructionFlags" :
44
- return InstructionFlags (False , False , False , False , False , False )
47
+ return InstructionFlags (False , False , False , False , False , False , False )
45
48
46
49
def add (self , other : "InstructionFlags" ) -> None :
47
50
for name , value in dataclasses .asdict (other ).items ():
@@ -53,10 +56,11 @@ def names(self, value: bool | None = None) -> list[str]:
53
56
return list (dataclasses .asdict (self ).keys ())
54
57
return [n for n , v in dataclasses .asdict (self ).items () if v == value ]
55
58
56
- def bitmap (self ) -> int :
59
+ def bitmap (self , ignore : AbstractSet [ str ] = frozenset () ) -> int :
57
60
flags = 0
61
+ assert all (hasattr (self , name ) for name in ignore )
58
62
for name in self .names ():
59
- if getattr (self , name ):
63
+ if getattr (self , name ) and name not in ignore :
60
64
flags |= self .bitmask [name ]
61
65
return flags
62
66
0 commit comments