[pymtl.tools.sim] add fix for CPython crash (details)
[pymtl.tools.sim] add fix for CPython crash (details)

In order to check for missing .value and .next accesses on Signal objects
(InPort, OutPort, Wire), we analyze the AST of each @tick/@combinational
annotated logic block. This works in the following way:

- look for any assignment nodes
- extract the left-hand side of any assignment node
- for each targets on the left-hand side (there can be multiple):

  - check if the target is missing a .value/.next attribute
  - if so, check get the type of the attribute: if it's a Signal, it
    should really have a .value/.next so raise an Exception

To get the value of the the attribute, we do some scary-Python-magic:

- get the AST subtree for the target (not the whole line of source)
- this subtree will be marked as an ast.Store operation, change it to be
  an ast.Load operation
- wrap this subtree in an ast.Expression object so we can eval it
- compile our rewritten AST subtree
- call eval on the resulting code object, this will (hopefully) return the
  object referenced by the AST subtree

Unfortunately, rewriting ASTs and executing can be a bit dangerous: Chris
found a bug that caused CPython to crash.

The source of this problem was a LHS that was a tuple::

  s.result,s.counter = gcd( req_msg.a, req_msg.b )

I had assumed the LHS would be encoded in the ast as multiple targets in
the ast.Assign.targets list, but instead ast.Assign.targets contains a
single node which is an ast.Tuple object. For some reason, trying to
evaluate this resulted in a CPython crash.

I added a bunch of tests to catch these problems in the future, and added
a fix which recursively visits each LHS target node and returns a
flattened list of targets. The flattened list should all contain ast.Name
or ast.Attribute nodes, if not we throw an Exception.

12yujim/pymtl,Glyfina-Fernando/pymtl,jck/pymtl,cornell-brg/pymtl,jjffryan/pymtl,cfelton/pymtl,cfelton/pymtl,12yujim/pymtl,tj93/pymtl,jjffryan/pymtl,Glyfina-Fernando/pymtl,jck/pymtl,tj93/pymtl,jjffryan/pymtl,tj93/pymtl,cornell-brg/pymtl,12yujim/pymtl,cfelton/pymtl,jck/pymtl,Glyfina-Fernando/pymtl,cornell-brg/pymtl