Posts by ALbert Mietus
QuickNote: Jinja Templating for rPY
- 2023/09/17
With a working RPython implementation of The Sieve demo (start/DRAFT), it’s time to find the patterns to automate: generating RPython code from Castle-Code.
Like in QuickNote: Jinja Events (templating), part of the CC2Cpy: CCastle to C compiler in Python backend, we focus on the essential Jinja templates.
QuickNote: The Sieve in RPython
- 2023/09/14
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.
QuickNote: Connecting two ports
- 2023/08/01
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.
QuickNote: Sending Events & Machinery
- 2023/07/27
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.
Admonitions (overview & use)
- 2023/07/27
Sphinx (and RST) support several “admons” or admonitions to make the reader aware of hazard or other parts of text that should stand out. But it hardly tells anything on which to use, in which case.
Therefore, I list them and give some advise when to use them
QuickNote: Jinja Events (templating)
- 2023/07/26
As we have seen in the recent Workshop blog: QuickNotes a lot of code (to send/handle events) is always the same, but for some details. A template engine, like Jinja, can help in that.
Let’s study how those templates can help us.
QuickNote: Sending Events (generated code)
- 2023/07/25
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.
rPY: Use (r)Python as backend
- 2023/06/25
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?
Heisenbugs
- 2023/04/08
In Castle, one can dynamically connect components and send “events” over those connections. Typically this is done as an action on an incoming message (see: The Actor Model). And depending on ‘The Machinery (ToDo)’, those events can be queued. It is this combination that can result in a beautiful Heisenbug.
First, let’s explain the Heisenbug, before we give an example. Then we analyze it, show how to improve the code, and finally formulate a requirement to prevent & detect this kind of bug in Castle.
QuickNote: Arpeggio
- 2022/11/08
In this short QuickNote, we give a bit of info on Arpeggio; a python package to implement a (PEG) parser. Eventually, the parser is written in Castle – like all Workshop Tools. To kickstart, we use python and python-packages. Where arpeggio is one of the options.
As Arpeggio is quite well documented this is a short note. We also describe some differences with the Pegen package.
QuickNote: PEGEN
- 2022/11/03
To implement CCastle we need a parser, as part of the compiler. Eventually, that parser will be written in Castle. For now, we kickstart it in python; which has several packages that can assist us. As we like to use a PEG one, there are a few options. Arpeggio is well known, and has some nice options – but can’t handle left recursion – like most PEG-parsers.
Recently python itself uses a PEG parser, that supports left recursion (which is a recent development). That parser is also available as a package: pegen; but hardly documented.
Concurrent Computing Concepts
- 2022/09/30
Sooner as we realize, even embedded systems will have piles & heaps of cores, as I described in
“Keep those cores busy!”. Castle should make it easy to write code for all of them: not to keep them busy, but to maximize
speed up [useCase: In Castle is easy to use th... (U_ManyCore)]. I also showed that threads do not scale well for CPU-bound (embedded)
systems. Last, I introduced some (more) concurrency abstractions. Some are great, but they often do not fit
nicely in existing languages.
Still, as Castle is a new language, we have the opportunity to select such a concept and incorporate it into the
language.
In this blog, we explore a bit of theory. I will focus on semantics and the possibilities to implement them efficiently. The exact syntax will come later.
Keep those cores busy!
- 2022/07/06
I always claim that most computers will have 1024 or more cores before my retirement. And that most embedded systems will have even more, a decade later. However, it’s not easy to write technical software for those “massive-parallel embedded computers”, not with the current languages – simple because a developer has to put in too many details. Accordingly, the “best, ever” programming language should facilitate and support “natural concurrency”.
In Castle, you can easily write code that can run efficiently on thousands of cores.
FSM syntax, an evaluation
- 2022/06/10
As described in FSMs are needed Finit State Machines are great and needed – even tough no (main) programming
language has syntax support for it. But there are other (computer) language that (more-or-less) support the
corresponding State pattern.
By example plantUML –very populair by mature developers– has a syntax to draw them.
What can we learn from them? That is the topic of this post, before we define the Castle syntax.
FSMs are needed
- 2022/06/04
Finit State Machines (FSMs) are great to model behaviour and control flow. Probably it is one of the most used design patterns; some developers are not even aware they are using it (when using the State pattern). And non of the well-known system-programming-languages does support it directly – it’s a shame;-)
This leads to sub-optimal, often hard to maintain code. In Castle, you can use define a FSM directly. Let’s see why that is essential.
No inline actions
- 2022/05/21
In Grammar is code we have mentioned that many compiler-compilers reuse the Yacc invention “actions”. And we hinted already that Castle prefers an alternative.
Let’s see why the old concept is outdated … And what is easier to use.
Grammar is code
- 2022/05/14
In Compiler Compiler we have seen that we can define a grammar within a Castle-program. And we have argued that each grammars-rule can be considered as a function.
In this post, we look into de details of how this works. And will confirm grammars is code …
Compiler Compiler
- 2022/05/07
In Castle, you can define grammar(s) directly in your code. A Castle compiler will translate them into functions, using the build-in (PEG) compiler-compiler – at least that was it called back in the days of YACC.
How does one use that? And why should you?
All Sphinx Directives
- 2018/05/11
Sphinx comes with a huge number of directives. Some are inherited from RST, others come from the many extensions that are available. But the is no list of all, or the most used directives in Sphinx.
Until now …
Remote MD
- 2018/05/05
I try to create beautiful WebSlides by combining a html-template with md-content. Typically, they have the same filename (but for the extension) in the same directory (and site).
In this blog, we are examining another option: Apparently it is possible to load a remote MD-file. This gives new options. By example: host a (generated) html-file on one cloud-provider and the md-file on another-one.
Unfortunately this setup is unstable: It may work, and sometimes does; but it may fail too….
The html-template
- 2018/04/28
Within the concept as described in Revealjs + Markdown, a “html-template” is needed.
Although such a file is needed for each webslide, most of this html-template is “fixed”. Typically a standard one is composed once, and that one is configured per webslide. Both steps are described in this article.
Revealjs + Markdown
- 2018/04/28
Reveal.js (@gitgub) is a open-source (MIT-Licensed) HTML-Framework for easily creating beautiful presentations using HTML —according to there website. It has a nice live demo too.
I’m going to use it with markdown however…
WebSlides
- 2018/04/27
Sphinx and reStructuredText (RST) are great tools to build and maintain documentation. However, the ability for “slide decks” is limited. In practice, most of my presentation are made by PowerPoint or Keynote – and so, are hard to maintain.
This has to be changed…
kwargs als argument
- 2017/03/29
Elke python-programmeur kent het kwargs concept, waarmee een variabel aantal named- (of ‘keyword’) argumenten ontvangen kan worden in een functie. Soms wordt dit concept echter onhandig gebruikt.