Skip to content

Commit

Permalink
fix: allow accumulator override
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Dec 7, 2023
1 parent 3c839a0 commit 493c371
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bolt/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from dataclasses import dataclass, field, fields, replace
from typing import (
Any,
Callable,
Dict,
Generator,
Iterable,
Expand Down Expand Up @@ -466,11 +467,14 @@ def visit_binding(
acc.statement(f"{target} {op} {value}", lineno=node)


@dataclass(eq=False)
class Codegen(Visitor):
"""Code generator."""

accumulator_factory: Callable[[], Accumulator] = Accumulator

def __call__(self, node: AstRoot) -> CodegenResult: # type: ignore
acc = Accumulator()
acc = self.accumulator_factory()
result = self.invoke(node, acc)

if result is None:
Expand Down

0 comments on commit 493c371

Please sign in to comment.