As others have mentioned, SPICE is the traditional answer to that question. But SPICE feels more like a macro-assembler for circuits.
One project that comes to mind for high-level programming style circuits-as-code:
https://github.com/atopile/atopile
Show HN: https://news.ycombinator.com/item?id=39263854 More recent HN thread: https://news.ycombinator.com/item?id=44548449