GH-135379: Remove types from stack items in code generator. (GH-135384)

* Make casts explicit in the instruction definitions
This commit is contained in:
Mark Shannon 2025-06-11 15:52:25 +01:00 committed by GitHub
parent 49d72365cd
commit c87b5b2cb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 257 additions and 255 deletions

View file

@ -247,12 +247,11 @@ def accept(self, visitor: Visitor) -> None:
@dataclass
class StackEffect(Node):
name: str = field(compare=False) # __eq__ only uses type, cond, size
type: str = "" # Optional `:type`
size: str = "" # Optional `[size]`
# Note: size cannot be combined with type or cond
def __repr__(self) -> str:
items = [self.name, self.type, self.size]
items = [self.name, self.size]
while items and items[-1] == "":
del items[-1]
return f"StackEffect({', '.join(repr(item) for item in items)})"
@ -463,20 +462,13 @@ def stack_effect(self) -> StackEffect | None:
# IDENTIFIER [':' IDENTIFIER [TIMES]] ['if' '(' expression ')']
# | IDENTIFIER '[' expression ']'
if tkn := self.expect(lx.IDENTIFIER):
type_text = ""
if self.expect(lx.COLON):
type_text = self.require(lx.IDENTIFIER).text.strip()
if self.expect(lx.TIMES):
type_text += " *"
size_text = ""
if self.expect(lx.LBRACKET):
if type_text:
raise self.make_syntax_error("Unexpected [")
if not (size := self.expression()):
raise self.make_syntax_error("Expected expression")
self.require(lx.RBRACKET)
size_text = size.text.strip()
return StackEffect(tkn.text, type_text, size_text)
return StackEffect(tkn.text, size_text)
return None
@contextual