Skip to content

Casting of PyObject #38

@martinpriestley

Description

@martinpriestley

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions