bmourad01 / eoc

A compiler for a subset of Typed Racket.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eoc

Implementation of a compiler from a subset of Typed Racket to AMD64, based on the book Essentials of Compilation by Jeremy Siek.

Requirements

  • OCaml (>= 4.08)
  • nasm (>= 2.15.05)
  • a C99-compatible C compiler
  • a POSIX-compliant shell

Additionally, the following OCaml packages are required:

  • core_kernel (>= 0.14.0)
  • dune (>= 2.8.0)
  • menhir
  • ocamlgraph (>= 2.0.0)
  • ppx_compare
  • ppx_hash
  • ppx_let
  • ppx_sexp_conv

Instructions

For building the project, run dune build. To compile a program, run ./compile <program>.rkt. To execute the compiled program, run ./output/<program>.

Target Machine

First of all, the compiler targets AMD64 (otherwise known as x86-64 to mindless plebians) and follows the System V ABI for the most part (floating-point numbers are handled in a non-standard way).

Given this, the output assembly programs should work fine on a corresponding Linux system. Other systems have not been tested, though BSD should work fine with a normal GNU toolchain. macOS systems will require some adjustments for the handling of symbol names. Windows systems follow a different ABI, so some work would be needed to ensure compatibility.

Features Implemented

  • Integers, booleans, floating-point numbers
  • Basic arithmetic and bitwise operations
  • Let-binding
  • If-then-else expressions
  • Register allocation with move biasing
  • Heap-allocated objects (tuples via vector) and stop-and-copy garbage collection
  • Top-level functions via define
  • Anonymous functions via lambda
  • Loops (via while), sequencing (via begin, when, and unless), and assignment (via set!)

About

A compiler for a subset of Typed Racket.

License:GNU General Public License v3.0


Languages

Language:OCaml 97.2%Language:C 2.6%Language:Shell 0.2%