Skip to content

Add Python dict support using VUnit dict_t - #11

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

ru551n wants to merge 2 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 <noreply@anthropic.com>
Needs the new_dict fix of VUnit/vunit#1229.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ru551n
ru551n force-pushed the python-dict-support branch from eb80a64 to 066b263 Compare October 4, 2026 10:37

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