GH-128914: Remove conditional stack effects from bytecodes.c and the code generators (GH-128918)

This commit is contained in:
Mark Shannon 2025-01-20 17:09:23 +00:00 committed by GitHub
parent 0a6412f9cc
commit ab61d3f430
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
44 changed files with 1460 additions and 1679 deletions

View file

@ -77,12 +77,11 @@ class Block(Node):
class StackEffect(Node):
name: str = field(compare=False) # __eq__ only uses type, cond, size
type: str = "" # Optional `:type`
cond: str = "" # Optional `if (cond)`
size: str = "" # Optional `[size]`
# Note: size cannot be combined with type or cond
def __repr__(self) -> str:
items = [self.name, self.type, self.cond, self.size]
items = [self.name, self.type, self.size]
while items and items[-1] == "":
del items[-1]
return f"StackEffect({', '.join(repr(item) for item in items)})"
@ -278,22 +277,15 @@ class Parser(PLexer):
type_text = self.require(lx.IDENTIFIER).text.strip()
if self.expect(lx.TIMES):
type_text += " *"
cond_text = ""
if self.expect(lx.IF):
self.require(lx.LPAREN)
if not (cond := self.expression()):
raise self.make_syntax_error("Expected condition")
self.require(lx.RPAREN)
cond_text = cond.text.strip()
size_text = ""
if self.expect(lx.LBRACKET):
if type_text or cond_text:
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, cond_text, size_text)
return StackEffect(tkn.text, type_text, size_text)
return None
@contextual