purpl3F0x / compilers

8th Semesters Compilers' Assignment - Alan Compiler written in Rust

Repository from Github https://github.compurpl3F0x/compilersRepository from Github https://github.compurpl3F0x/compilers

Alan Compiler

build License

Compiler of the Alan programming language, developed for the 8th semester's Compilers course at NTUA.

alt text

Instructions for building in Debian here

Author ✍️

Stavros Avramidis


The project contains 3 subdirectories (sub-crates).

  • alan: The compiler backend for the Alan language
  • alanc: The cli frontend of the compiler
  • stdlib: The Alan standard library, written in C (which at it's current state relies on libc, so we can target every platform &/ architecture)

Build Instructions 🛠️

(Not as detailed as IKEA's)

Pre-build linux binaries are available, in the actions tab.

Requirements

A pre-configured Dockerfile and an image in docker-hub that is (somewhat) tested can be used to easily build and test the project.

Rust - Cargo

The project is tested on rustc 1.82.0-nightly. At the time of writing a nightly version is required.

LLVM - Clang

The project is requires and pre-configured to use LLVM 18.

If llvm is not in the default path LLVM_SYS_180_PREFIX should be set.
If you want to use any other version of llvm, Cargo.toml the build.rs and Makefile should be edited accordingly.

In addition, llvm-sys will try to link llvm statically, (platforms such Arch will be built with dynamic llvm libraries)

In sort, in order to fully build and run the compiler. The following should be available:

  • llvm-config
  • llvm-as or llvm-as-18
  • clang or clang-18

Also (for compiling the stdlib):

  • make

Building

Clone the project

git clone https://github.com/avramidis-stavros-compilers-org/compilers-mirror.git

Go to the project directory

cd compilers

Run with cargo

cargo run alanc --release -- <Program arguments>

Build with cargo

cargo build --release

Warning: By default x86 release builds are build for x86_64_v3 (avx,avx2) with lto

Install 🚀

If you want to install the alanc globally:

cargo install

Usage 💡

Run the program with -h/--help and you'll learn everything you need to know, on how to use it.

Run it with --version, if you want to chase some dragons.

Features ✨

  • Cross Compilation (yes, you can compile for CUDA 🙌)

  • (Ridiculously) fast lexing, using Logos

  • Errors made for humans, thanks to chumsky parser combinator + ariadne

    • alt text
    • alt text
    • alt text
    • alt text

Known Bugs ☠️

  • Parsing lower bound negative integer (f.ex -2147483648 for 32b ints)

ToDo

  • Cross compilation (partially working)

Copyright 2024 Stavros Avramidis

About

8th Semesters Compilers' Assignment - Alan Compiler written in Rust

License:Apache License 2.0


Languages

Language:Rust 95.4%Language:C 3.5%Language:Makefile 0.8%Language:Python 0.3%