Skip to content

Commit

Permalink
Support kwargs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lekcyjna committed Oct 24, 2023
1 parent 671cf7e commit fe25ecb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 11 additions & 5 deletions test/transactions/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,9 @@ def process():


class DataDependentConditionalCircuit(Elaboratable):
def __init__(self, n=2, bad_number=3):
self.bad_number = bad_number
def __init__(self, n=2, ready_function = lambda arg: arg.data != 3):
self.method = Method(i=data_layout(n))
self.ready_function = ready_function

self.in_t1 = Record(data_layout(n))
self.in_t2 = Record(data_layout(n))
Expand All @@ -550,7 +550,7 @@ def __init__(self, n=2, bad_number=3):
def elaborate(self, platform):
m = TModule()

@def_method(m, self.method, self.ready, ready_function=lambda rec: rec.data != self.bad_number)
@def_method(m, self.method, self.ready, ready_function=self.ready_function)
def _(data):
m.d.comb += self.out_m.eq(1)

Expand All @@ -570,10 +570,10 @@ def setUp(self):
self.test_number = 200
self.bad_number = 3
self.n = 2
self.circ = DataDependentConditionalCircuit(self.n, self.bad_number)

def test_random(self):
def base_random(self, f):
random.seed(14)
self.circ = DataDependentConditionalCircuit(n = self.n, ready_function = f)

def process():
for _ in range(self.test_number):
Expand Down Expand Up @@ -611,3 +611,9 @@ def process():

with self.run_simulation(self.circ, 100) as sim:
sim.add_process(process)

def test_random_arg(self):
self.base_random(lambda arg: arg.data != self.bad_number)

def test_random_kwarg(self):
self.base_random(lambda data: data != self.bad_number)
6 changes: 3 additions & 3 deletions transactron/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,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._ready_function(arg_rec)
rec(transaction, method)

for transaction in transactions:
Expand Down Expand Up @@ -1090,9 +1090,9 @@ def body(
finally:
self.defined = True

def ready_function(self, arg_rec: Record) -> ValueLike:
def _ready_function(self, arg_rec: Record) -> ValueLike:
if self.user_ready_function is not None:
return self.ready & self.user_ready_function(arg_rec)
return self.ready & method_def_helper(self, self.user_ready_function, arg_rec, **arg_rec.fields)
return self.ready

def __call__(
Expand Down

0 comments on commit fe25ecb

Please sign in to comment.