Skip to content

Commit 257ff85

Browse files
committed
.
1 parent d4bc1e5 commit 257ff85

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

ir.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,15 @@ def has_value(self) -> bool:
802802

803803

804804
@dataclasses.dataclass
805-
class CBool(ConstantLattice):
805+
class CCInt(ConstantLattice):
806+
value: Optional[int] = None
807+
808+
def has_value(self) -> bool:
809+
return self.value is not None
810+
811+
812+
@dataclasses.dataclass
813+
class CCBool(ConstantLattice):
806814
value: Optional[bool] = None
807815

808816

@@ -820,8 +828,8 @@ def union(self: ConstantLattice, other: ConstantLattice) -> ConstantLattice:
820828
return self
821829
if isinstance(self, CInt) and isinstance(other, CInt):
822830
return self if self.value == other.value else CInt()
823-
if isinstance(self, CBool) and isinstance(other, CBool):
824-
return self if self.value == other.value else CBool()
831+
if isinstance(self, CCBool) and isinstance(other, CCBool):
832+
return self if self.value == other.value else CCBool()
825833
return CBottom()
826834

827835

@@ -863,9 +871,9 @@ def run(self) -> dict[Instr, ConstantLattice]:
863871
pass
864872
elif isinstance(instr, CondBranch):
865873
match self.type_of(instr.operands[0]):
866-
case CBool(True):
874+
case CCBool(True):
867875
block_worklist.append(instr.conseq)
868-
case CBool(False):
876+
case CCBool(False):
869877
block_worklist.append(instr.alt)
870878
case CBottom():
871879
pass
@@ -906,29 +914,29 @@ def run(self) -> dict[Instr, ConstantLattice]:
906914
elif isinstance(instr, IsIntEqualWord):
907915
match self.type_of(instr.operands[0]):
908916
case CInt(int(i)) if i == instr.expected:
909-
new_type = CBool(True)
917+
new_type = CCBool(True)
910918
case _:
911-
new_type = CBool()
919+
new_type = CCBool()
912920
elif isinstance(instr, IsList):
913921
match self.type_of(instr.operands[0]):
914922
case CList():
915-
new_type = CBool(True)
923+
new_type = CCBool(True)
916924
case _:
917-
new_type = CBool()
925+
new_type = CCBool()
918926
elif isinstance(instr, IsEmptyList):
919-
new_type = CBool()
927+
new_type = CCBool()
920928
elif isinstance(instr, ListFirst):
921929
new_type = CTop()
922930
elif isinstance(instr, ListRest):
923931
new_type = CTop()
924932
elif isinstance(instr, IsRecord):
925-
new_type = CTop()
933+
new_type = CCBool()
926934
elif isinstance(instr, CConst):
927935
new_type = CTop()
928936
elif isinstance(instr, CEqual):
929-
new_type = CTop()
937+
new_type = CCBool()
930938
elif isinstance(instr, RecordNumFields):
931-
new_type = CTop()
939+
new_type = CCInt()
932940
else:
933941
raise NotImplementedError(f"SCCP {instr}")
934942
old_type = self.type_of(instr)

0 commit comments

Comments
 (0)