Skip to content

Add Python dict support using VUnit dict_t - #11

Open
ru551n wants to merge 3 commits into
VUnit:mainfrom
ru551n:python-dict-support
Open

ru551n wants to merge 3 commits into
VUnit:mainfrom
ru551n:python-dict-support

Conversation

@ru551n

@ru551n ru551n commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

Depends on: VUnit/vunit#1229

Motivation

Python code naturally exchanges configuration and results as dicts. VUnit's dict_t (string keys, mixed-type values) is the VHDL counterpart, but the bridge could not pass one in either direction.

API

  • eval_dict / call_dict return a new dict_t (aliased as eval / call; no ambiguity with the existing eval/call overloads). The caller owns and deallocates it. Values: int -> integer, float -> real (bit exact), str -> string, bool -> boolean, list of int -> integer_vector_ptr_t ref, nested dict -> nested dict_t ref. None, out-of-range ints, non-str keys and other values are errors; after a reported failure an empty dict is returned. NVC, GHDL and Questa only (Riviera-PRO/Active-HDL report that they require them), like integer_array_t results.
  • arg(dict_t) / kwarg(kw, dict_t) write a Python literal {"key": value, ...} using only the public dict_pkg API (num_keys, get_key, get_value_type, getters). Values: integer, real, string, boolean, std_ulogic, integer_vector, real_vector, integer_vector_ptr_t, nested dict. Other types fail like other unconvertible arguments. Text only, so it works on all simulators.

Python side: KIND_DICT and _dict_result in runtime.py serialise the dict into the existing byte-result path (no native changes). The generated python_pkg.vhd is regenerated from the template.

Tests

New cases in tests/tb_python_pkg_bridge.vhd: every value type and nested dicts, exact reals, error cases, arg/kwarg, a round trip VHDL dict -> Python -> VHDL, an unconvertible value, and a group & with a dict kwarg. Full suite: 113 of 113 pass on NVC and on GHDL, pytest tests/test_python_bridge.py 85 passed.

Notes: tests do not deallocate multi-key dicts because new_dict after deallocate of a grown dict fails in VUnit's dict_pkg (recycled pool arrays are longer than requested). Reals are sent as an exact mantissa/exponent because NVC's real'value misparses multi-digit exponents.

🤖 Generated with Claude Code

@ru551n

ru551n commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

Added a test that deallocates returned multi-key dicts. It needs the new_dict fix now included in VUnit/vunit#1229.

ru551n and others added 2 commits October 4, 2026 12:37
eval_dict/call_dict (aliased eval/call) return a new dict_t from a Python
dict with str keys: int, float, str, bool, list of int and nested dict
values. arg/kwarg accept a dict_t and write it as a Python dict literal.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Needs the new_dict fix of VUnit/vunit#1229.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@ru551n
ru551n force-pushed the python-dict-support branch from eb80a64 to 066b263 Compare October 4, 2026 10:37
The dict_t argument needs get_key and get_value_type of dict_pkg. Revert
before merging, once a VUnit release has them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ru551n

ru551n commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

CI note, must be undone before merging.

The dict_t argument uses get_key and get_value_type from dict_pkg. They are added by VUnit/vunit#1229 and are not in any VUnit release on PyPI yet. Until they are, CI installs VUnit from the head of that PR. Commit eee29c3 adds the step to python_bridge.yml (Linux/macOS and Windows) and to wheel_tests.yml, and each step is marked TEMPORARY.

Once VUnit/vunit#1229 is merged and released:

  1. Revert eee29c3 to remove the temporary install steps.
  2. Raise vunit_hdl>= in pyproject.toml to that release.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant