Skip to content
a Racket Compiler built @recursecenter that also answers the ultimate question of the meaning of life, the universe and everything.
Racket Other
  1. Racket 98.2%
  2. Other 1.8%
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
programs
src
testing
.gitignore
LICENSE
README.md
build.py
compiler.rkt
install_dependencies.sh
read_int.c
run
run_tests.sh

README.md

Description

This is a racket to x86 compiler written in racket. It follows the approach outlined by the book Essentials of Compilation by Jeremy Siek and Ryan Newton.

Getting Started

Tools Needed

Dependencies

Run this in your terminal

./install_dependencies.sh

Compiling a file

usage: python3 build.py [-h] [-o OUTPUT] filename

Examples

use echo $? to check output
> cat programs/test-should-exit-code-4.rc
(program () (let ([x 2]) (+ x 2)))
>
> python3 build.py programs/test
> ./a.out
> echo $?
4
Or just ./run
> cat programs/test-should-exit-code-4.rc
(program () (let ([x 2]) (+ x 2)))
>
> ./run programs/test-should-exit-code-4.rc
4
NOTICE how Linux assembly has .global main rather than .global _main
> ./build.py programs/test-should-exit-code-4.rc -o two_plus_two_executable_on_linux
> cat programs/test-should-exit-code-4.s
      .global main
main:
      movq %rsp, %rbp
      movq $2, -8(%rbp)
      movq -8(%rbp), %rax
      movq %rax, -16(%rbp)
      addq $2, -16(%rbp)
      movq -16(%rbp), %rax
      retq

> ./two_plus_two_executable_on_linux
> echo $?
4
NOTICE how macOS assemnbly has .global _main rather than .global main
> ./build.py programs/test-should-exit-code-4.rc -o two_plus_two_executable_on_mac
> cat programs/test-should-exit-code-4.s
      .global _main
_main:
      movq %rsp, %rbp
      movq $2, -8(%rbp)
      movq -8(%rbp), %rax
      movq %rax, -16(%rbp)
      addq $2, -16(%rbp)
      movq -16(%rbp), %rax
      retq

> ./two_plus_two_executable_on_mac
> echo $?
4

Running tests

All tests are in the testing directory.

./run_tests.sh
You can’t perform that action at this time.