mirror of
https://github.com/YosysHQ/yosys
synced 2025-11-24 14:41:31 +00:00
pyosys: __getitem__ for supported classes
- functions that have a const `[]` operator method now support `__getitem__` in Python - fields of a pointer type now return a `reference_internal` instead of a `copy` because classes referenced to by pointers typically aren't copyable (e.g. RTLIL::Wire, RTLIL::Module, etc) - removed duplicate of test_script.py
This commit is contained in:
parent
9aa2dde7ef
commit
58e831486d
4 changed files with 36 additions and 24 deletions
|
|
@ -193,7 +193,7 @@ pyosys_headers = [
|
|||
),
|
||||
PyosysClass("SigChunk"),
|
||||
PyosysClass("SigBit", hash_expr="s"),
|
||||
PyosysClass("SigSpec", hash_expr="s", denylist={"chunks"}),
|
||||
PyosysClass("SigSpec", hash_expr="s", denylist=frozenset({"chunks"})),
|
||||
PyosysClass(
|
||||
"Cell",
|
||||
ref_only=True,
|
||||
|
|
@ -539,6 +539,8 @@ class PyosysWrapperGenerator(object):
|
|||
python_name_override = "__ne__"
|
||||
elif function.operator == "<":
|
||||
python_name_override = "__lt__"
|
||||
elif function.operator == "[]" and function.const:
|
||||
python_name_override = "__getitem__"
|
||||
else:
|
||||
return
|
||||
|
||||
|
|
@ -592,7 +594,10 @@ class PyosysWrapperGenerator(object):
|
|||
# care
|
||||
return
|
||||
|
||||
has_containers = self.register_containers(field)
|
||||
self.register_containers(field)
|
||||
rvp = "py::return_value_policy::copy"
|
||||
if isinstance(field.type, Pointer):
|
||||
rvp = "py::return_value_policy::reference_internal"
|
||||
|
||||
definition_fn = f"def_{'readonly' if field.type.const else 'readwrite'}"
|
||||
if field.static:
|
||||
|
|
@ -604,7 +609,7 @@ class PyosysWrapperGenerator(object):
|
|||
f'"{field_python_basename}"',
|
||||
f"&{metadata.name}::{field.name}",
|
||||
]
|
||||
def_args.append("py::return_value_policy::copy")
|
||||
def_args.append(rvp)
|
||||
print(
|
||||
f"\t\t\t.{definition_fn}({', '.join(def_args)})",
|
||||
file=self.f,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue