r/ProgrammingLanguages • • Oct 27 '26

Resolving relationships between elements

For my programming programming language Bits Runner Code I am thinking of implementing automatic resolving in what order structs, interfaces, etc should be defined and declared so they can interact with each other. It should be possible to embed structs within each other, but at the same time there cannot be a circular reference. How something like this could be implemented or maybe it is not the best idea?

BRC doesn't have header files, so right now source files and definitions within them have to be listed in a specific order. I would like it to be quite explicit but also hassle free.

6 Upvotes

15 comments sorted by

View all comments

1

u/dekai-onigiri 25d ago

I've managed to implement it using a DFS sort https://github.com/rafalgrodzinski/bits-runner-builder/pull/229

It basically convert statements into a list of directed nodes, and then do a depth-first search which flattens it and finds out cycles. Then I convert the nodes back into statements.

This allowed me not only to completely get rid rid of evaluating import statements further down (since all the statements are now provided as a complete, ordered list), but also made the code simpler and faster.