Skip to content

MarkMizzi/pixel-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

386 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pixel Language Compiler and Playground

This is an implementation of a compiler for the Pixel Language undertaken for the CPS2000 Compilers course at the University of Malta.

A specification for the assignment (and partial specification of the langauge implemented) can be found here. A report on the work carried out for the assignment can be found here.

Building the compiler

THe compiler can be built using CMake. Run:

cmake .

to obtain a build file for the project.

Then run

make

to actually build the compiler. A binary called pixelc will be produced.

Using the compiler

./pixelc [-o <outfile>] [-xml <outfile>] {<options>} [src]
Options:
    -o                  Specify output file. By default stdout is used.
    -xml                Generate XML from the AST produced. An output 
                        file for the XML must also be specified.
    -frotate-loops      Rotates while/for loops when generating code.
    -felim-dead-code    Eliminate dead code.
    -fpeephole-optimize Enable the peephole optimizer.
    -h                  Print this help message and exit immediately.
Args:
    src                 Specifies source file to compile.

Running the playground locally

If you want to run the playground locally, you can do so by running

./scripts/run.bash

This will build and start the Docker image for the playground, which will be available at http://localhost:8080.

Hosting your own copy of the playground

Hosting a copy of the playground is more work intensive unless you own the domain pixel.markmizzi.dev (which at the time of writing belongs to me).

Change the hardcoded references to pixel.markmizzi.dev in nginx.conf and scripts/deploy.bash to a domain name you own (a simple search and replace will do). Also remember to change my email mizzimark2001@gmail.com to one of your own in the call to certbot within scripts/deploy.bash.

Once all this is done, simply run

./scripts/deploy.bash

on the machine where you want to host the playground.

Showcase

The Pixel playgrond has a code editor with syntax highlighting, and is also capable of displaying the compiled bytecode of a program: image

In addition, you can also view the parsed syntax tree for a program: image

A compiled program can be executed in the virtual machine: Screenshot from 2026-01-12 22-56-43

Below you can see execution of some sample programs.

Double Pendulum

double-pendulum

This one was quite challenging to implement as it required programming $\sin(x)$ and $\cos(x)$ functions from scratch: Screenshot from 2026-01-12 22-56-02

Quicksort

quicksort

Game of Life

gameoflife

Lorentz Attractor

lorentz

Releases

No releases published

Packages

 
 
 

Contributors