Skip to content

gh-106812: Small stack effect fixes #107759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tools/cases_generator/interpreter_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ and a piece of C code describing its semantics::
NAME [":" type] [ "if" "(" C-expression ")" ]

type:
NAME
NAME ["*"]

stream:
NAME "/" size
Expand Down
4 changes: 3 additions & 1 deletion Tools/cases_generator/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,14 @@ def cache_effect(self) -> CacheEffect | None:

@contextual
def stack_effect(self) -> StackEffect | None:
# IDENTIFIER [':' IDENTIFIER] ['if' '(' expression ')']
# 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 += " *"
cond_text = ""
if self.expect(lx.IF):
self.require(lx.LPAREN)
Expand Down
29 changes: 11 additions & 18 deletions Tools/cases_generator/stacking.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ def as_variable(self, lax: bool = False) -> str:
), f"Push or pop above current stack level: {res}"
return res

def as_stack_effect(self, lax: bool = False) -> StackEffect:
return StackEffect(
self.as_variable(lax=lax),
self.effect.type if self.effect.size else "",
self.effect.cond,
self.effect.size,
)


@dataclasses.dataclass
class CopyEffect:
Expand Down Expand Up @@ -356,24 +364,14 @@ def write_components(
for peek in mgr.peeks:
out.assign(
peek.effect,
StackEffect(
peek.as_variable(),
peek.effect.type,
peek.effect.cond,
peek.effect.size,
),
peek.as_stack_effect(),
)
# Initialize array outputs
for poke in mgr.pokes:
if poke.effect.size and poke.effect.name not in mgr.instr.unmoved_names:
out.assign(
poke.effect,
StackEffect(
poke.as_variable(lax=True),
poke.effect.type,
poke.effect.cond,
poke.effect.size,
),
poke.as_stack_effect(lax=True),
)

if len(parts) == 1:
Expand All @@ -390,11 +388,6 @@ def write_components(
for poke in mgr.pokes:
if not poke.effect.size and poke.effect.name not in mgr.instr.unmoved_names:
out.assign(
StackEffect(
poke.as_variable(),
poke.effect.type,
poke.effect.cond,
poke.effect.size,
),
poke.as_stack_effect(),
poke.effect,
)