| 586 | |
| 587 | |
| 588 | class _Wire: |
| 589 | __slots__ = ("budget", "gate", "data") |
| 590 | |
| 591 | def __init__(self, budget, gate): |
| 592 | self.budget = budget |
| 593 | self.gate = gate |
| 594 | self.data = bytearray() |
| 595 | |
| 596 | def emit(self, value): |
| 597 | self.budget.output(len(value)) |
| 598 | for char in value: |
| 599 | self.gate.step() |
| 600 | self.data.append(char) |
| 601 | |
| 602 | def hex(self, value): |
| 603 | self.budget.output(len(value) * 2) |
| 604 | for char in value: |
| 605 | self.gate.step() |
| 606 | self.gate.step() |
| 607 | self.data.append(_HEX[char >> 4]) |
| 608 | self.gate.step() |
| 609 | self.data.append(_HEX[char & 15]) |
| 610 | |
| 611 | def decimal(self, value): |
| 612 | # All emitted integers are <= uint64, so conversion is <=20 digits. |
| 613 | self.gate.poll() |
| 614 | self.emit(str(value).encode("ascii")) |
| 615 | |
| 616 | def _values(self): |
| 617 | for char in self.data: |
| 618 | self.gate.step() |
| 619 | yield char |
| 620 | |
| 621 | def finish(self): |
| 622 | self.gate.poll() |
| 623 | result = bytes(self._values()) |
| 624 | self.gate.poll() |
| 625 | return result |
| 626 | |
| 627 | |
| 628 | def _profile_wire(image, universe, budget, gate): |
no outgoing calls
no test coverage detected