Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

jonathanhefner/calc__llvm_parslet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Calc

A calculator domain-specific language with both an interpreter and a compiler. Implemented in Ruby using Parslet for parsing and LLVM for JIT compilation.

Installation

First, install LLVM 3.5 from source (this requires Python 2):

$ wget -qO- http://llvm.org/releases/3.5.2/llvm-3.5.2.src.tar.xz | tar -xJ

$ cd llvm-3.5.2.src

$ ./configure --enable-shared --enable-jit --prefix=/usr/lib/llvm-3.5

# This will take a while...
$ make

$ sudo make install

Next, run bundle install with a pointer to LLVM:

$ cd /path/to/calc

$ LLVM_CONFIG=/usr/lib/llvm-3.5/bin/llvm-config bundle install

Finally, run the tests:

$ LD_LIBRARY_PATH=/usr/lib/llvm-3.5/lib bundle exec rake test

Usage

Start the REPL in interpreter mode:

$ LD_LIBRARY_PATH=/usr/lib/llvm-3.5/lib bundle exec rake repl

Or in JIT mode:

$ LD_LIBRARY_PATH=/usr/lib/llvm-3.5/lib bundle exec rake repl[jit]

Then try a few examples:

> 1 + 1
2

> 22.0 / 7
3.142857142857143

> 2 * (5 - 2) * (5 + 2)
42

Exit the REPL with CTRL+D.

Releases

No releases published

Packages

No packages published

Languages