mirror of
https://github.com/YosysHQ/yosys
synced 2025-11-25 06:59:33 +00:00
pyosys: globals, set operators for opaque types
There is so much templating going on that compiling wrappers.cc now takes 1m1.668s on an Apple M4…
This commit is contained in:
parent
384f7431fd
commit
54799bb8be
9 changed files with 343 additions and 47 deletions
|
|
@ -1,6 +1,12 @@
|
|||
from typing import Mapping
|
||||
from pyosys import libyosys as ys
|
||||
|
||||
my_dict = ys.StringToStringDict()
|
||||
StringToStringDict = ys.StringToStringDict
|
||||
|
||||
my_dict = StringToStringDict()
|
||||
|
||||
assert isinstance(my_dict, Mapping)
|
||||
|
||||
my_dict["foo"] = "bar"
|
||||
my_dict.update([("first", "second")])
|
||||
my_dict.update({"key": "value"})
|
||||
|
|
@ -11,3 +17,13 @@ new_dict = my_dict | {"tomato": "tomato"}
|
|||
del new_dict["foo"]
|
||||
assert set(my_dict.keys()) == {"first", "key", "foo"}
|
||||
assert set(new_dict.keys()) == {"first", "key", "tomato"}
|
||||
|
||||
constructor_test_1 = ys.StringToStringDict(new_dict)
|
||||
constructor_test_2 = ys.StringToStringDict([("tomato", "tomato")])
|
||||
constructor_test_3 = ys.StringToStringDict({ "im running": "out of string ideas" })
|
||||
|
||||
the_great_or = constructor_test_1 | constructor_test_2 | constructor_test_3
|
||||
|
||||
assert set(the_great_or) == {"first", "key", "tomato", "im running"}
|
||||
repr_test = eval(repr(the_great_or))
|
||||
assert repr_test == the_great_or
|
||||
|
|
|
|||
|
|
@ -1,3 +1,20 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
from pyosys import libyosys as ys
|
||||
|
||||
ys.log("Hello, world!")
|
||||
print(ys)
|
||||
|
||||
ys.log("Hello, world!\n")
|
||||
|
||||
from pyosys.libyosys import log
|
||||
|
||||
print(log)
|
||||
|
||||
log("Goodbye, world!\n")
|
||||
|
||||
import pyosys
|
||||
|
||||
if os.path.basename(sys.executable) == "yosys":
|
||||
# make sure it's not importing the directory
|
||||
assert "built-in" in repr(pyosys)
|
||||
|
|
|
|||
42
tests/pyosys/test_set.py
Normal file
42
tests/pyosys/test_set.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from pyosys.libyosys import StringSet, StringPool
|
||||
|
||||
for cls in [StringSet, StringPool]:
|
||||
print(f"Testing {cls.__name__}...")
|
||||
A = cls()
|
||||
A.add("a")
|
||||
|
||||
B = cls()
|
||||
B = A | {"b"}
|
||||
|
||||
assert A < B
|
||||
assert A <= B
|
||||
|
||||
A.add("b")
|
||||
|
||||
assert A == B
|
||||
assert A <= B
|
||||
assert not A < B
|
||||
|
||||
A.add("c")
|
||||
|
||||
assert A > B
|
||||
|
||||
A &= B
|
||||
assert A == B
|
||||
|
||||
Ø = A - B
|
||||
assert len(Ø) == 0
|
||||
|
||||
C = cls({"A", "B", "C"})
|
||||
D = cls()
|
||||
C |= {"A", "B", "C"}
|
||||
D |= {"C", "D", "E"}
|
||||
c_symdiff_d = (C ^ D)
|
||||
assert (c_symdiff_d) == {"A", "B", "D", "E"}
|
||||
|
||||
repr_test = eval(repr(c_symdiff_d))
|
||||
c_symdiff_d == repr_test
|
||||
|
||||
|
||||
print("Done.")
|
||||
Loading…
Add table
Add a link
Reference in a new issue