Coder Social home page Coder Social logo

ajinkyakulkarni / rc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mfekadu/rc

0.0 1.0 0.0 333 KB

a Racket Compiler built @RecurseCenter that also answers the ultimate question of the meaning of life, the universe and everything.

License: GNU General Public License v3.0

Shell 0.91% Racket 98.16% Python 0.82% C 0.11%

rc's Introduction

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

rc's People

Contributors

johnvtan avatar mfekadu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.