Hello world!
It's the Dear Leader here. It's been $LONG_TIME since anything has
happened, but now things are afoot! Allow me to explain what's going on,
and where the project is headed.
First, if there are any newcomers, or outsiders, a recap. If you already
know all this, feel free to skip to the last section.
## A quick recap ##
Pyjaco is a project that aims to seamlessly compile Python into
JavaScript, allowing (among other use cases) to run Python code directly
in the browser, in an intuitive, user-friendly way with reasonable
performance. Pyjaco itself is a rewrite of the older PyJS project, which
had a good idea, but many shortcomings.
In the beginning, I made a few patches to PyJS to improve these
shortcomings, but it quickly became clear that a more substantial
rewrite was in order. As often happens in the OSS world, I (along with
another PyJS follower, Samuel Ytterbrink) decided to fork the project
into Pyjaco. We re-wrote the standard library and the unit testing
framework. This rewrite is Pyjaco version 1, aka what you know and
dearly love.
## New ideas ##
Pyjaco was still based on the core idea of the PyJS compiler, which is
that it should be a one-pass compiler based on the Python AST (Abstract
Syntax Trees). Ever node in the AST could emit JS code directly, and
this would then combine with the Standard Library written in JS, to
create usable output.
With the help of contributors, we managed to support even quite advanced
python construct, like decorators, modules and generators. However, more
advanced features like optimizations, generic tree rewrite rules and
other forms of code transformation was too difficult in this restricted
code pipeline. It's simply too much of a burden to keep track of the
global state in a single-pass compiler, if you want to do anything serious.
To summarize: Pyjaco works well, but we had reached the limit of the
infrastructure.
Because of this, we had a meeting last year with myself, Samuel and
Alexander Esselink (Dexter). You can see the notes of the meeting here:
https://docs.google.com/document/d/1hVa-Sh3qTkqjIUVfF6FvlIOpSa4ce5p0dMcnszomJt4/edit
We came up with a plan to rewrite the compiler core to a multi-pass
model, which would allow arbitrary syntax rewrites and optimization
passes. This is definitely the way forward, we just needed... you
guessed it.. time. That's always the issue :-)
## Pyjaco Reborn(!) ##
It is the season for vacation days, so I decided to spend the last 2
days hacking away at pyjaco.
Turns out it wasn't as bad as expected!
I have defined all the IST classes, created the AST->IST parser, made a
python printer for IST, and a preliminary JS printer for IST, too.
The compiler + python printer has been tested, and works on _every_ unit
test. In other words, we now support 99% of the Python language. We can
turn python into... Python!
Did I really spend the last 2 days inventing the identify function? It
sure feels like it. But it works! And now we "just" need the
transformation functions that were integrated into the old compiler,
then we will actually have Pyjaco 1 feature parity.
"It shouldn't be too hard", but then again, those are famous last words.
I'll keep you apprised of the progress. If you want to read the latest
code, look here:
https://github.com/chrivers/pyjaco/tree/ist-compiler/pyjaco/compiler
Until next time, stay Awesome.
/Dear leader out.
--
Med venlig hilsen
Christian Iversen