manifold-lang / manifold-frontend

Frontend compiler for Manifold high-level language
GNU General Public License v3.0
6 stars 6 forks source link

Implement non-primitive function elaboration #56

Open mtrberzi opened 9 years ago

mtrberzi commented 9 years ago

Here is the specification for a useful function: (this should go in FunctionInvocationVertex.elaborate() or wherever primitive node instantiation is being done)

Function reconnectExpressionGraph

Input: two ExpressionGraphs G1 and G2, and two Map<ExpressionEdge, VariableReferenceVertex>s inputs and outputs

Preconditions: G1 and G2 are distinct. G1 and G2 have no common vertices or edges. Every ExpressionEdge in inputs and outputs is in G1. Every VariableReferenceVertex in inputs and outputs is in G2.

Functionality: This function connects G2 to G1. It first creates G2 as a subgraph inside G1. For each non-VariableReference vertex in G2, an identical vertex is added to G1. For each VariableReferenceVertex in G2, a corresponding new vertex is created in G1, with a newly-generated unique variable name. All edges in G2 that refer to a VariableReferenceVertex are created in G1, with the source or target (as appropriate) changed to refer to the newly created vertex. All other edges in G2 are re-created in G1 with the same (isomorphic) source and target for each. Finally, for each pair in inputs, the target of that edge in G1 is changed to refer to the newly created VariableReferenceVertex that corresponds to the other member of the pair; and similarly, for outputs, the source of that edge in G1 is changed in a similar way.

maxqchen commented 9 years ago

So the 2 maps are (edge in G1) -> (vertex in G2) for inputs and outputs, correct? Also, is subgraph being used afterwards? (if not, I should be able to just add the vertices / edges as-is except for input/output instead of doing copy, right?) 1 more - why do we need to create new reference vertices? Is this because of scoping?

mtrberzi commented 9 years ago

Yes, that's right.

On Sun, Feb 8, 2015 at 8:58 AM, Max Qitian Chen notifications@github.com wrote:

So the 2 maps are (edge in G1) -> (vertex in G2) for inputs and outputs, correct?

— Reply to this email directly or view it on GitHub https://github.com/manifold-lang/manifold-frontend/issues/56#issuecomment-73411851 .