Home

Awesome

Pykaleidoscope

This Python project implements the Kaleidoscope toy language as described on the LLVM tutorial (up to the part and including Mutable Variables). For that purpose, it uses the llvmlite python library. That project code is heavily inspired from the simpler pykaleidoscope project of eliben. The main differences are the followings:

Motivation

I made this project as a way to teach myself the basics of LLVM, and made it public as a way to show others what can be done because there is not much LLVM simple stuff out there on the Internet. And the official LLVM tutorial, being written in C++, is not that easy to follow if your are not acquainted with that language.

Installation and examples

Python needs to be installed first if not already available on your system. I used version 3.5 with miniconda3 under Windows, but any OS should work just fine.

Then install the llvmlite Python package:

conda install llvmlite

There is no need to install LLVM on its own since the llvmlite install includes a subset of LLVM which is just fine for our purposes.

Then download the pykaleidoscope code in its own folder, open a command line in that folder and execute the kal.py file to launch the kaleidoscope jit-compiler/interpreter. A prompt will show up like this K>. At the prompt, type test, to run the tests and make sure everything works well. Then, to get in touch with the power of this very simple language, run the .mandelbrot.kal program by simply entering its name after the prompt. The pykaleidoscope REPL will load the program, compile it in memory and then run it, which will show a very basic Mandelbrot set. Well, I am not the author of that Mandelbrot stuff, since it comes from the original LLVM tutorial, but it is indeed quite a surprising realisation for such a simple language.

K> test
... unit tests stuff showing up ...
K> .mandelbrot.kal
... mandelbrot set showing up ...
K> 2 + 3     # or any other kaleidoscope code
5.0
K> .functions
... shows available functions ...
K> exit
... return to command line from here ...

Limitations

As is, this language and interpreter has many limitations.

History

Version 0.1.3

Version 0.1.2

Version 0.1.1

Version 0.1.0

Enjoy!