cornell-brg / pymtl

Python-based hardware modeling framework
BSD 3-Clause "New" or "Revised" License
234 stars 83 forks source link

[dynamic-ast] Add support for dynamically generated AST #175

Closed ptpan closed 5 years ago

ptpan commented 5 years ago

The following changes are made:

  1. When inspect.getsourcelines() fails to retrieve the source code of a block, this block is treated as a dynamically generated block and therefore has no available source code and line number.
  2. When PyMTL tries to extract AST from a dynamically generated AST, it consults the .ast attribute of this function and uses this field as the dynamically generated AST.
  3. The user execute the dynamically generated block in the environment of globals().update( locals() ) to capture all free variables in the global and closure space.
jsn1993 commented 5 years ago

The changes look good to me. Can you also add a test case/example to show how you compile the ast use global()/local() variables?

jsn1993 commented 5 years ago

looks good to me!