Skip navigation

Greetings,

it has been requested that I talk about the generation of the reading coroutines in C a bit more. This first post will operate as a roadmap and also as a collection of links to the other posts about this matter, easening the navigation in addition to the categories.

I will overall present the code in the current state and try to elaborate why I implemented things in this way and not in another way. I might sometimes wonder and ramble about some design decisions and my missing knowledge about software design, and I might make up theories about design which might make sense or not. If you disagree, I will be happy, because then we can discuss. :)

The overall presentation will consist of the following steps:

At first, I will present the overall problem we will try to solve. This post should be read by everyone who wants to continue further, I think, because otherwise, terms will become pretty hard to understand.

Second, I will present my take on a DSL to solve this problem. I will present a pretty pragmatic view on this which I presented to the users of the DSL. I am going to keep this view abstract from the actual code really used to implement this, because those classes contain the solution of one or two more problems I encountered which overall add a bit of understanding trouble which I would like to avoid.

Third, I will present one half of the foundation of everything: the datastructures. The datastructures are overall a big composite pattern. I will explain why I implemented this as datastructures with vistors, opposed to, say, regular objects with methods. I will also present some implementation details for immutable classes we discovered as beneficial.

Fourth, I will present the other half of the foundation of this overall layer: The vistor part of the datastructure+visitor-implementation. I will present the general way we chose to implement the visitors, the way we removed a number of redundancy and the way we tested the visitors. The third and the fourth part would overall benefit a reader who sometimes ends up with a lot of operations on few datastructures, because I think that we overall reached a point where our datastructures are strong and usable and implementing visitors is quite easy and painless.

Fifth, I will explain how we solved the issue with variable names. It took around three iterations which I mostly forgot again, but my git log will probably help me on that. Overall, we reached a strong solution, which is a bit arcane, but once you get it, the light is bright (as a teaser: you basically annotate run time values with objects in order to identify value flow in order to add variables). I will also show you a nice way to add extensibility in this DSL.

Sixth, I will explain the abstract, high level plan for the generation, including the structure of the C method we want to generate. For those theoretically inclined, I will also discuss the overall abstract model of this language. This is the point where the theoretical description from part two will become relevant and this is the point where I had some headaches to solve for a day or two, but I managed to solve it :)
Overall, to have some terms handy to explain part seven and eight, we transform the code tree into a code graph and convert this graph into some while-switch-statement in order to implement the state machine, which is the model of the domain specific language.

Seventh, I will explain how the transformation from the code tree into the code graph. This was overall pretty tricky, but manageable. I will also elaborate why I think I need this. This should be a short, but interesting post.

Eigth, I will demonstrate how the code emitting is implemented. This is not exactly difficult, but kind of tricky, because there are all so little nitpicks that can go wrong.

Ninth, I will discuss how I managed to get this entire beast tested. Yes, it is fully unit tested, which is very, very nice. :)

Finally, I will wrap this up and consider if implementing this DSL was worth it, what could have gone better and so on.

Wow, so we got a lot of fun in front of us. Let’s begin. If someone would like to recieve the entire code from me, I will be happy to provide it.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.