Home

Awesome

Aki: a compiler for a simple language, built with Python 3.6+ and the LLVM framework by way of the llvmlite library

⚠ This project is currently very unstable and should not be used in production. However, you should always be able to pull from master, run the demos, and pass the test suite. (The test suite compiles the demos internally as well.)

This project is an attempt to create a compiler, language server, and REPL in Python for a simple language that's compiled to native machine code.

Eventually, this might become something useful for real work. Right now, it's strictly proof-of-concept -- a fun toy for me to hack on and to learn about compiler theory and programming language construction in the process.

If you're a fan of Python, LLVM, compilers, or any combination of the above, learn how to contribute.

Features, goals, and ideals

The language's syntax and goals are in heavy flux, but this is the basic idea I want to aim for:

Even if any of these features are only implemented in miniature, the idea would be to polish the implementations as completely as possible, so they could set the best possible example. For instance, if the standard library only had a proof-of-concept number of modules, the way they worked would be refined so that the practices around them could support a larger standard library.

By deliberately keeping the scope of the implementation at PoC level (or, rather, by accepting such a scope as a by-product of the fact that this is a hobby project for now), it ought to be easier to keep a good grasp on the basics, and to avoid conceptual problems that could bite us later. It also makes it easier to tear down and rebuild in the event we find we've written ourselves into a conceptual corner.

Another likely goal would be to make this a language that encourages quick interactive development by way of its workflow. For instance, invoking the compiler with a certain set of command-line switches would fire up an editor for a new or existing project, and preconfigure the REPL to reload-and-run that project whenever you input the .rlr command.

Finally, I'm not looking at this as a "replacement" for any existing language, just something that takes good cues from the galaxy of other languages out there.

"Aki's Way"

Some guidelines about what we want Aki to be, by way of aphorisms (also in flux). These are not dogma, just directions to lean in:

Code examples

Note that these do not work yet. This message will go away when they do.

Hello, world!

def main() {
    
    print('Hello world!')
    # you can use "" or '' to delineate strings as long as they match

    print("こんにちは世界!")
    # Unicode is allowed

    print("Goodbye
world!") # so are multi-line strings, as linebreaks are arbitrary

    0

    # every statement is an expression,
    # and the last statement of a function is an implicit return,
    # but we do have a `return` keyword for early returns,
    # so the last line could also be: `return 0`
}

(Eventually, for quick-and-dirty scripting, we'll ditch the need for a main() function.)

Fibonacci sequence

def main() {
    var a = 0:u64, b = 1:u64, c = 0:u64
    # :u64 = unsigned 64-bit integer
    loop (x = 0, x < 50) {
        # by default loops increment by one
        print (a)
        c = a + b
        a = b
        b = c
    }
    return 0
}

Quickstart

You'll need Python 3.6 and Windows 10 64-bit.

  1. Clone or download the repo.
  2. pip install -r requirements.txt to ensure you have all the requirements.
  3. Run python aki.py to start the REPL.
  4. Enter .l. to load the Conway's Life demo from the examples directory.
  5. Enter .r to run the demo.
  6. Hit q to exit Conway's Life. Enter . to see all commands.
<!-- 7. If you have the Microsoft Visual Studio tools installed, you can enter `.l.` to load the Conway's Life demo, then enter `.cp` to compile it to a standalone binary in the `\output` subdirectory. (Make sure `nt_compiler_path` in `config.ini` points to the correct location for `vcvarsall.bat`. This limitation will be removed in the future.) -->

There's also going to be a standalone binary version of the compiler, most likely by way of pyinstaller.

Limitations

(Apart from the language itself being a minimal affair, that is.)

Derivation and licensing

This project is based (very loosely) on the Pykaleidoscope project by Frédéric Guérin, derived in turn from the Pykaleidoscope project by Eli Bendersky. (An earlier version of this project used their code directly; this version is a complete rewrite from scratch.)

The original Pykaleidoscope project was made available under the Unlicense. This version is distributed under the MIT license.

Licensing for included and to-be-included modules: