0.0
No commit activity in last 3 years
No release in over 3 years
Linear compiler written in Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 1.4.9
 Project Readme

Citrus¶ ↑

Author:: Mac Malone License:: See LICENSE Copyright:: Copyright © 2011 Mac Malone

Citrus is a simple dynamically typed linear language written in Ruby, Treetop, and LLVM. It is meant to be an example of how to write a basic compiler.

Being linear, it could be called very c-like, but it has been written to have a syntax closer to Ruby. Its current main features are:

  • Dynamically typed

  • Extremely ruby-like syntax

  • Integer, Float, String, Symbol, Boolean, Array, and Range types

  • Easy integration of C functions into the API

It’s prime examples are in the example directory, but here is an excerpt from factorial.ct:

def factorial(num) if num == 0 fac = 1 else fac = num*factorial(num-1) end return fac end

printf(“factorial(%d): %d”, 6, factorial(6)) As you can see, very ruby-like.

Installing & Requirements¶ ↑

Citrus requires the following libraries:

  • LLVM 2.9 compiled with shared libraries

    • On Mac OS X, the quickest way is to use ‘brew install llvm –shared`

    • On Linux, there are usually pre-compiled packages

  • Ruby

  • Treetop

  • Ruby LLVM (currently building the source from Jeremy’s next branch is required)

Everything except LLVM (and presently, ruby-llvm) is installed when running ‘gem install citrus-compiler`

Running¶ ↑

Citrus is a pretty simple thing to run:

$ ruby bin/citrus [options] FILENAME -O Doesn’t run optimization -i Dumps bitcode -c NAME Compiles to the given file name -h Prints help If citrus is run without -c it JIT complies the code, running it in place.

Problems & Todos¶ ↑

Todos:

  • Hashs

  • Create a standard library

  • Better dynamically typed arrays (using structures)

  • Better exception handling (currently only works semi-effectively within begin blocks)

  • Garbage Collection

Known Problems:

  • Array length not retained well

  • #{} string substitution only works with one #{}

  • The resolve_conflicts function only works with one conflict

  • Float manipulation (+, -, *, /, ==, <, <=, =>, >) doesn’t work

  • Variant functions are very target specific (might not currently work on non-osx systems)

  • Very few outcomes are tested (citrus may be very buggy)

NOTE: I believe I have traced some of these problems to the object conversion functions (otos, otoi, otof, etc.), but can not figure out how to fix them. If anyone knowledgable at LLVM or LLVM IR would like to help it would be greatly appreciated (use -i on the compiler to output LLVM IR for a citrus program).