Skip to content

stages

AssemblyKernel

Bases: FTyped, ABC

A callable implementation of an AssemblyKernelFType.

Source code in src/finch/finch_assembly/stages.py
49
50
51
52
53
54
55
56
57
58
59
60
class AssemblyKernel(FTyped, ABC):
    """A callable implementation of an AssemblyKernelFType."""

    def __init__(self, type_: AssemblyKernelFType):
        self._ftype = type_

    @property
    def ftype(self) -> AssemblyKernelFType:
        return self._ftype

    @abstractmethod
    def __call__(self, *args) -> Any: ...

AssemblyKernelFType dataclass

Bases: CallableFType

The identity and signature of a function defined in a Finch module.

Source code in src/finch/finch_assembly/stages.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@dataclass(eq=False, frozen=True)
class AssemblyKernelFType(CallableFType):
    """The identity and signature of a function defined in a Finch module."""

    name: str
    arg_types: tuple[FType, ...]
    result_type: FType
    definition: str = field(default_factory=lambda: uuid4().hex)

    def __eq__(self, other):
        match other:
            case AssemblyKernelFType():
                return (
                    self.name,
                    self.arg_types,
                    self.result_type,
                    self.definition,
                ) == (other.name, other.arg_types, other.result_type, other.definition)
        return NotImplemented

    def __hash__(self):
        return hash((self.name, self.arg_types, self.result_type, self.definition))

    def __call__(self, value):
        if isinstance(value, AssemblyKernel) and value.ftype == self:
            return value
        raise TypeError(f"Expected a kernel of type {self}")

    def return_type(self, *args: FType) -> FType:
        if args != self.arg_types:
            raise TypeError(f"{self.name} expects {self.arg_types}, got {args}")
        return self.result_type

AssemblyLibrary

Bases: ABC

Represents a module containing assembly kernels.

Source code in src/finch/finch_assembly/stages.py
63
64
65
66
67
68
69
70
71
72
73
class AssemblyLibrary(ABC):
    """
    Represents a module containing assembly kernels.
    """

    @abstractmethod
    def __getattr__(self, name: str) -> AssemblyKernel:
        """
        Get the assembly Kernel corresponding to the given name.
        """
        ...

__getattr__(name) abstractmethod

Get the assembly Kernel corresponding to the given name.

Source code in src/finch/finch_assembly/stages.py
68
69
70
71
72
73
@abstractmethod
def __getattr__(self, name: str) -> AssemblyKernel:
    """
    Get the assembly Kernel corresponding to the given name.
    """
    ...

AssemblyLoader

Bases: Stage

Source code in src/finch/finch_assembly/stages.py
76
77
78
79
80
81
82
83
class AssemblyLoader(Stage):
    @abstractmethod
    def lower(
        self, term: asm.Module, *, mode: CompilerMode | None = None
    ) -> AssemblyLibrary:
        """
        Load the given assembly program into a runnable module.
        """

lower(term, *, mode=None) abstractmethod

Load the given assembly program into a runnable module.

Source code in src/finch/finch_assembly/stages.py
77
78
79
80
81
82
83
@abstractmethod
def lower(
    self, term: asm.Module, *, mode: CompilerMode | None = None
) -> AssemblyLibrary:
    """
    Load the given assembly program into a runnable module.
    """

AssemblyTransform

Bases: Stage

Source code in src/finch/finch_assembly/stages.py
86
87
88
89
90
91
class AssemblyTransform(Stage):
    @abstractmethod
    def lower(self, term: asm.Module) -> asm.Module:
        """
        Transform the given assembly term into another assembly term.
        """

lower(term) abstractmethod

Transform the given assembly term into another assembly term.

Source code in src/finch/finch_assembly/stages.py
87
88
89
90
91
@abstractmethod
def lower(self, term: asm.Module) -> asm.Module:
    """
    Transform the given assembly term into another assembly term.
    """