racklet / electronics-prototyping

Design files for electronic components for use in Racklet
Apache License 2.0
3 stars 0 forks source link

Update the evaluator: DAG schematic support (globals), new CLI and other fixes #25

Closed twelho closed 3 years ago

twelho commented 3 years ago

This PR finally completes the last of the originally planned features for the KiCad evaluator in #14: support for sheet-level global definitions. After some discussions with @chiplet we came to the conclusion that the most native way to support this in KiCad is not to allow parent sheets to update their children (causing potential dependency loops between sheets), but instead treat the schematic hierarchy as a DAG with dedicated sheets for defining global properties at the bottom of the graph. Supporting this model in the evaluator also required minimal changes, this PR just updates the indexing of sub-schematics to use their (proper) filename, and fixes a bug with the dependency loop detection when dealing with diamond inheritance.

Note: Internally the tooling (and our data structures) still treat schematics as a tree, which means that shared child schematics (under diamond inheritance) are processed and saved as many times as they are referred to from different parent schematics. Functionally it doesn't make a big difference right now since parent schematics aren't allowed to update children (to not break the DAG), but especially with complex functions (such as vdiv) in common child schematics processing times might become an issue later on. Tracking issue: #26.

The expression evaluation library we use, evalexpr, is also having a hard time with filenames with dashes (-) as it isn't advanced enough to handle those as complete variable identifiers (trying to apply subtraction instead), so I've updated the KiCad schematics and projects under hat-psu to use dashes in their filenames instead.

Finally this PR also adds in a nicer CLI using clap for the evaluator, which should be easy to port over to the parser and other tooling as well.

chiplet commented 3 years ago

Builds on my machine and seems to be working without any issues. The dependency loop fix is required to run the evaluator in any nontrivial design so I'll merge this to get main back to a working state.