On Fri, May 24, 2019 at 10:34 PM Ricky Teachey <ri...@teachey.org> wrote:
>
> You can do things like this with exec():
>
> class SafeDict(dict):
>     curated_keys = {"a", "b", "c"}
>     def __setitem__(self, k, v):
>         if k not i self.curated_keys:
>             raise Exception(f"{k!r} key not allowed")
>         super().__setitem__(k, v)
>
> locals_dict = SafeDict()
> globals_dict = SafeDict()
>
> exec("d=1", locals_dict, globals_dict)  # Exception: 'd' key not allowed
>
> You can do all sorts of things using that technique, including the way 
> assignment to variables is handled.

I see your point now. In this case user will need to write HDLs
probably in below fashion:

class my_module:
    def __init__(self, input, output, ...):
        ...
    def process(self):
        exec("signal = 5", locals, globals)
        # compare this with: signal <== 5

I fully agree this can work, but also it doesn't seem to be any better
looking than signal.next = 5. I think there are two important point
here, first is to make HDL design feels as natural as possible and as
pythonic as possible as well as leaving very little room for mistakes,
second is to make HDL design at least as easy and as intuitive as in
traditional HDLs. And when I see this can actually be achieved easily
with less than 100 lines of CPython code changes I am tempted to give
it a try (I am so in love with python ...).

The other thing I was thinking about is PEP572 assignment expression
(a := b), if it could be modified to allow user override (e.g. via
__assign__()), and allow it to be used without bracket like "y :=
f(x)" if __assign__ is present in y. Then this is even aligned with
Chisel's assignment operation and I'd be completely happy with it.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to