From b54aeb35ad0dfe17ca096d5d39051c51a4f622d5 Mon Sep 17 00:00:00 2001 From: Lekcyjna <309016@uwr.edu.pl> Date: Sat, 28 Oct 2023 12:13:54 +0200 Subject: [PATCH] Fix comments from review. --- test/transactions/test_methods.py | 2 +- transactron/core.py | 43 +++++++++++++++++-------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/test/transactions/test_methods.py b/test/transactions/test_methods.py index a3bad4f67..df05d259f 100644 --- a/test/transactions/test_methods.py +++ b/test/transactions/test_methods.py @@ -550,7 +550,7 @@ def __init__(self, n=2, ready_function=lambda arg: arg.data != 3): def elaborate(self, platform): m = TModule() - @def_method(m, self.method, self.ready, ready_function=self.ready_function) + @def_method(m, self.method, self.ready, validate_arguments=self.ready_function) def _(data): m.d.comb += self.out_m.eq(1) diff --git a/transactron/core.py b/transactron/core.py index 5d8a80eab..aa24f21a7 100644 --- a/transactron/core.py +++ b/transactron/core.py @@ -85,7 +85,7 @@ def rec(transaction: Transaction, source: TransactionBase): raise RuntimeError(f"Method '{method.name}' can't be called twice from the same transaction") self.methods_by_transaction[transaction].append(method) self.transactions_by_method[method].append(transaction) - self.readiness_by_method_and_transaction[(transaction, method)] = method._ready_function(arg_rec) + self.readiness_by_method_and_transaction[(transaction, method)] = method._validate_arguments(arg_rec) rec(transaction, method) for transaction in transactions: @@ -999,7 +999,7 @@ def __init__( self.data_out = Record(o) self.nonexclusive = nonexclusive self.single_caller = single_caller - self.ready_function: Optional[Callable[[Record], ValueLike]] = None + self.validate_arguments: Optional[Callable[..., ValueLike]] = None if nonexclusive: assert len(self.data_in) == 0 @@ -1049,7 +1049,7 @@ def body( *, ready: ValueLike = C(1), out: ValueLike = C(0, 0), - ready_function: Optional[Callable[[Record], ValueLike]] = None, + validate_arguments: Optional[Callable[..., ValueLike]] = None, ) -> Iterator[Record]: """Define method body @@ -1073,11 +1073,12 @@ def body( Data generated by the `Method`, which will be passed to the caller (a `Transaction` or another `Method`). Assigned combinationally to the `data_out` attribute. - ready_function: Optional[Callable[[Record], ValueLike]] - Function to instantiate a combinational circuit for each - method caller. It should take input arguments and return - if the method can be called with those arguments. By default - there is no function, so all arguments are accepted. + validate_arguments: Optional[Callable[..., ValueLike]] + Function that takes input arguments used to call the method + and checks whether the method can be called with those arguments. + It instantiates a combinational circuit for each + method caller. By default, there is no function, so all arguments + are accepted. Returns ------- @@ -1099,7 +1100,7 @@ def body( if self.defined: raise RuntimeError(f"Method '{self.name}' already defined") self.def_order = next(TransactionBase.def_counter) - self.ready_function = ready_function + self.validate_arguments = validate_arguments try: m.d.av_comb += self.ready.eq(ready) @@ -1110,9 +1111,9 @@ def body( finally: self.defined = True - def _ready_function(self, arg_rec: Record) -> ValueLike: - if self.ready_function is not None: - return self.ready & method_def_helper(self, self.ready_function, arg_rec, **arg_rec.fields) + def _validate_arguments(self, arg_rec: Record) -> ValueLike: + if self.validate_arguments is not None: + return self.ready & method_def_helper(self, self.validate_arguments, arg_rec, **arg_rec.fields) return self.ready def __call__( @@ -1187,7 +1188,10 @@ def debug_signals(self) -> SignalBundle: def def_method( - m: TModule, method: Method, ready: ValueLike = C(1), ready_function: Optional[Callable[[Record], ValueLike]] = None + m: TModule, + method: Method, + ready: ValueLike = C(1), + validate_arguments: Optional[Callable[..., ValueLike]] = None, ): """Define a method. @@ -1213,11 +1217,12 @@ def def_method( Signal to indicate if the method is ready to be run. By default it is `Const(1)`, so the method is always ready. Assigned combinationally to the `ready` attribute. - ready_function: Optional[Callable[[Record], ValueLike]] - Function to instantiate a combinational circuit for each - method caller. It should take input arguments and return - if the method can be called with those arguments. By default - there is no function, so all arguments are accepted. + validate_arguments: Optional[Callable[..., ValueLike]] + Function that takes input arguments used to call the method + and checks whether the method can be called with those arguments. + It instantiates a combinational circuit for each + method caller. By default, there is no function, so all arguments + are accepted. Examples -------- @@ -1253,7 +1258,7 @@ def decorator(func: Callable[..., Optional[RecordDict]]): out = Record.like(method.data_out) ret_out = None - with method.body(m, ready=ready, out=out, ready_function=ready_function) as arg: + with method.body(m, ready=ready, out=out, validate_arguments=validate_arguments) as arg: ret_out = method_def_helper(method, func, arg, **arg.fields) if ret_out is not None: