Repository navigation
Add Python dict support using VUnit dict_t - #11
Merged
Merged
Conversation
Collaborator
Author
|
Added a test that deallocates returned multi-key dicts. It needs the |
ru551n
force-pushed
the
python-dict-support
branch
from
October 4, 2026 10:37
eb80a64 to
066b263
Compare
This was referenced Oct 14, 2026
ru551n
force-pushed
the
python-dict-support
branch
3 times, most recently
from
October 15, 2026 15:21
0b0d241 to
e86efb7
Compare
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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The dict_t support needs get_key and get_value_type of dict_pkg, which VUnit 5.0.0.dev15 is the first release to have (VUnit/vunit#1229). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ru551n
force-pushed
the
python-dict-support
branch
from
October 16, 2026 12:12
d13aff3 to
9b6b9c5
Compare
VUnit's dict_pkg stores integer_array_t refs, so the bridge converts them in both directions. In a dict_t argument the array is transferred like an integer_array_t argument and becomes a NumPy array. A NumPy array in a returned dict becomes an integer_array_t with the word size of an eval_integer_array result: from the dtype, or that of the array VHDL passed in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ru551n
commented
Oct 16, 2026
Which simulators the Python bridge supports is documented for the whole package. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A dict result was one string of text records that VHDL parsed, with reals written as an exact mantissa and exponent and arrays as comma separated integers. Python now converts the dict and keeps its entries, and VHDL fetches each value with the eval of its type: integer, real, boolean, string, integer_vector_ptr_t and integer_array_t over their binary results, a nested dict by its handle. The text parsing functions are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requires VUnit 5.0.0.dev15 (
vunit_hdl>=5.0.0.dev15), the first release withget_keyandget_value_typeofdict_pkg(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_dictreturn a newdict_t(aliased aseval/call; no ambiguity with the existingeval/calloverloads). The caller owns and deallocates it. Values:int-> integer,float-> real,str-> string,bool-> boolean, list ofint->integer_vector_ptr_tref, NumPy array of integers ->integer_array_tref (bit width and signedness as foreval_integer_array: from the dtype, or kept from an array VHDL passed in), nesteddict-> nesteddict_tref.None, out-of-range ints, non-strkeys and other values are errors; after a reported failure an empty dict is returned. Python converts and checks the whole dict, then VHDL fetches each value over the typed results of the bridge (binary integers, reals and arrays; a nested dict by its handle), so there is no text parsing.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, integer_array_t (becomes a NumPy array), nested dict. Other types fail like other unconvertible arguments. An integer_array_t value is transferred like aninteger_array_targument.Python side:
KIND_DICTand_dict_resultinruntime.pyserialise the dict into the existing byte-result path (no native changes). The generatedpython_pkg.vhdis 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.py85 passed.Notes: tests do not deallocate multi-key dicts because
new_dictafterdeallocateof a grown dict fails in VUnit's dict_pkg (recycled pool arrays are longer than requested).🤖 Generated with Claude Code