Posts tagged WorkshopTools
The RPy compiler backend needs to ‘fill-in’ some data structures, like
CC_B_Protocol – there is one for every
protocol. It contains the name of the protocol, its kind (like Event, as we assume here), and a list of
events. That event list contains the (event) name, it’s sequence-number (see: Modelling the Event Index), and a backlink
to the protocol.
The question is: Should the
Event (dataclass) contain the typedParameters?
This question affects both the runtime (for this backend) –the RPython implementation of
CC.buildin.CC_B_P_EventID– and the (jinja templating) to generate the code to fill those
Before implementing an RPython backend, a short study of RPython is made, including implementing The Sieve demo (start/DRAFT) in RPython. It’s like a hand-compiled RPython variant, following the approach as described in the Jinja rendering study), for the CC2CPy backend.
Writing RPython isn’t too complicated for someone with a C-background. But making the code pass the RPython compiler
can be tricky, however. Both, as just added statements can interfere with existing code – when that isn’t “static
enough”, new code can trigger compile errors in old, tested code! And, because the RPython compiler isn’t that great
in giving helpful info.
It feels like old-style debugging: try-and-error, remove-and-enable-lines, one-at-a-time until one understands and it becomes easy to fix…
This blog is both to share some RPython experience and to study the patterns that are needed to generate RPython code to implement the Castle-Compiler.
Like in QN: Sending Events, we collect here some lines/fragments about connecting two ports in the handCompiled code to find similarities, and to design the (Jinja) templates.
Depending on the The Machinery (ToDo), the generated code to send an events will alter. However, only a little bit as we will see in this study.
Let’s study how those templates can help us.
The handCompiled, generated to send an event is about 4 to 6 lines; depending on the The Machinery (ToDo), with a lot of similarity. It is however buried in lot of other code, notes, ect. And therefore hard to see the difference.
Here, we collect al those pieces, and see which lines/fragments are common – and can go into a template. And which parts we have to fill-in.
When designing a Castle-Compiler with a C-backend, we found some nasty details unrelated to CCastle
but to the C-language. For example, C has no namespaces (see No Name Collisions); we can simulate them, but
that is extra work. Likewise, we need to generate many (data)classes that are very similar. Again, it is
possible, but it takes a lot of work: to write the code that generates those almost codes.
Therefore, I started to think about how we can automate that. Or: who has done it before, and what can we borrow?
PyPy –an alternative Python implementation– has developed a concept for
that! They have built a translator to convert (r)Python into C and
compile that into native machine code.
Can we re-use that? And can it help to realize the “first (bootstrap) compiler” faster?