Basic framework that I code-vomitted out.  Needs refining, but has basic groundwork for tree structure using gates as nodes.