diff --git a/src/pystencils/backend/functions.py b/src/pystencils/backend/functions.py index 7a95c4183fce019db75c3332f14570a4a143fdc6..28c9788d691baec475abf4758490a7617d09f018 100644 --- a/src/pystencils/backend/functions.py +++ b/src/pystencils/backend/functions.py @@ -72,12 +72,24 @@ class PsFunction(ABC): class CFunction(PsFunction): - """A concrete C function.""" + """A concrete C function. + + Instances of this class represent a C function by its name, parameter types, and return type. + + Args: + name: Function name + param_types: Types of the function parameters + return_type: The function's return type + """ __match_args__ = ("name", "argument_types", "return_type") @staticmethod def parse(obj) -> CFunction: + """Parse the signature of a Python callable object to obtain a CFunction object. + + The callable must be fully annotated with type-like objects convertible by `create_type`. + """ import inspect from pystencils.types import create_type @@ -93,14 +105,14 @@ class CFunction(PsFunction): return CFunction(func_name, arg_types, ret_type) - def __init__(self, name: str, arg_types: Sequence[PsType], return_type: PsType): - super().__init__(name, len(arg_types)) + def __init__(self, name: str, param_types: Sequence[PsType], return_type: PsType): + super().__init__(name, len(param_types)) - self._arg_types = tuple(arg_types) + self._arg_types = tuple(param_types) self._return_type = return_type @property - def argument_types(self) -> tuple[PsType, ...]: + def parameter_types(self) -> tuple[PsType, ...]: return self._arg_types @property