In your example (https://fvutils.github.io/pyhdl-if/sv_api.html#complete-working-example), the result of invokeFunc is implicitly cast to an int:
for (int i = 0; i < 1005; i++) begin
automatic longint val = bridge.invokeFunc("increment", null);
$display("Counter: %0d", val);
end
But the return type of invokeFunc is a PyObject, which is really a chandle.
From my understanding of the LRM, it is not legal SystemVerilog to cast a chandle to an integer type, either implicitly, explicity (using longint'()) or using $cast().
The following seems to be the way to do it:
for (int i = 0; i < 1005; i++) begin
automatic pyhdl_if::py_object obj = new(bridge.invokeFunc("increment", null));
$display("Counter: %0d", obj.to_long());
end
I don't suppose real use cases are intended to make much use of invokeFunc, but I thought it worth raising.
In your example (https://fvutils.github.io/pyhdl-if/sv_api.html#complete-working-example), the result of
invokeFuncis implicitly cast to an int:But the return type of
invokeFuncis a PyObject, which is really achandle.From my understanding of the LRM, it is not legal SystemVerilog to cast a
chandleto an integer type, either implicitly, explicity (usinglongint'()) or using$cast().The following seems to be the way to do it:
I don't suppose real use cases are intended to make much use of
invokeFunc, but I thought it worth raising.