> On May 22, 2019, at 10:51 AM, Andre Roberge <andre.robe...@gmail.com> wrote: > > > >> On Wed, May 22, 2019 at 9:57 AM Yanghao Hua <yanghao...@gmail.com> wrote: >> > > And this is something I have in mind for a Python DSL for HDL: > > Perhaps you might be able to do what you want using an import hook. I have > done some experiments with introducing some new operators that way: > https://github.com/aroberge/experimental/blob/master/experimental/transformers/readme.md >
You might also want to look at macropy https://github.com/lihaoyi/macropy/blob/master/readme.rst , although I don’t know if it supports new operators. Eric > > >> > > >> > > def combinational_or_sequential_logic(in: Signal, out: Signal): >> > > local_signal = Signal() >> > > local_signal <- in << 10 # read as: local_signal <- (in << 10) >> > > out <- local_signal + 5 # read as out <- (local_signal + 5) >> > > # new_signal <- 3 will raise exception, as <- does not create new >> > > object. >> > > >> > > And the arrow operators could also be used for bulk connections of a >> > > chain of hardware modules like this: >> > > module_instance1 -> instance2 -> instance3->... to naturally form a >> > > hardware pipeline ... this looks very elegant. >> > >> > >> > I think the largest problem with this idea has to do with where the new >> > operator would be defined, and then where would it be used. At first >> > blush, it seems like you'd want to define the operator in one file >> > (let's call it hdl.py), then import that into another file (circuit.py), >> > which could use the new operator. >> > >> > But Python compiles circuit.py without reading hdl.py at all. It merely >> > compiles "import hdl" to some bytecode to import hdl.py. So how would >> > the operator's definition be used during the compilation of circuit.py? >> > The compiler has no idea that new operators have been defined. >> >> The scala implementation purely relies on the object to provide the >> operator definition, e.g. "a b c" would be interpreted as "a.b(c)". >> With the current implementation of the arrow operators I have, "<-" >> and "->" are part of of the basic python operators pretty much like >> "+" and "-". Where it relies on the object to provide the special >> method "__arrow__". so, this operation could be defined in a separate >> file with a base class e.g. Signal or Module, where other python >> module has to import it to use it or inherit it. >> >> In this case, essentially when python compiler reads circuit.py, it >> reads hdl.py too as it is imported in circuit.py. This is exactly how >> __matmult__ special method works too in PEP465. >> _______________________________________________ >> Python-ideas mailing list >> Python-ideas@python.org >> https://mail.python.org/mailman/listinfo/python-ideas >> Code of Conduct: http://python.org/psf/codeofconduct/ > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/