| 438 | |
| 439 | @dataclass |
| 440 | class Storage: |
| 441 | |
| 442 | stack: Stack |
| 443 | inputs: list[Local] |
| 444 | outputs: list[Local] |
| 445 | peeks: int |
| 446 | check_liveness: bool |
| 447 | spilled: int = 0 |
| 448 | |
| 449 | @staticmethod |
| 450 | def needs_defining(var: Local) -> bool: |
| 451 | return ( |
| 452 | not var.item.peek and |
| 453 | not var.in_local and |
| 454 | not var.is_array() and |
| 455 | var.name != "unused" |
| 456 | ) |
| 457 | |
| 458 | @staticmethod |
| 459 | def is_live(var: Local) -> bool: |
| 460 | return ( |
| 461 | var.name != "unused" and |
| 462 | ( |
| 463 | var.in_local or |
| 464 | var.memory_offset is not None |
| 465 | ) |
| 466 | ) |
| 467 | |
| 468 | def clear_inputs(self, reason:str) -> None: |
| 469 | while len(self.inputs) > self.peeks: |
| 470 | tos = self.inputs.pop() |
| 471 | if self.is_live(tos) and self.check_liveness: |
| 472 | raise StackError( |
| 473 | f"Input '{tos.name}' is still live {reason}" |
| 474 | ) |
| 475 | self.stack.drop(tos.item, self.check_liveness) |
| 476 | |
| 477 | def clear_dead_inputs(self) -> None: |
| 478 | live = "" |
| 479 | while len(self.inputs) > self.peeks: |
| 480 | tos = self.inputs[-1] |
| 481 | if self.is_live(tos): |
| 482 | live = tos.name |
| 483 | break |
| 484 | self.inputs.pop() |
| 485 | self.stack.drop(tos.item, self.check_liveness) |
| 486 | for var in self.inputs[self.peeks:]: |
| 487 | if not self.is_live(var): |
| 488 | raise StackError( |
| 489 | f"Input '{var.name}' is not live, but '{live}' is" |
| 490 | ) |
| 491 | |
| 492 | def _push_defined_outputs(self) -> None: |
| 493 | defined_output = "" |
| 494 | for output in self.outputs: |
| 495 | if output.in_local and not output.memory_offset and not output.item.peek: |
| 496 | defined_output = output.name |
| 497 | if not defined_output: |
no outgoing calls
no test coverage detected
searching dependent graphs…