What is it?

Calculon is a very simple but very fast programming language designed to be embedded into other programs. It uses LLVM to generate high-quality machine code and is ideal for shaders, user-supplied mathematical formulae, etc.

The Calculon language itself is a pure functional language with support for upvalues, tail recursion, and bindings to the standard maths library. It supports 3-vectors, reals and booleans as first-class values.

What's new?

2014-04-14: Version 0.3 released! Now supporting LLVM 3.3 and Apple OS X; the language supports multiple return values from scripts, and it's all even faster!

Where can I get it?

Calculon's github repository

Send me pull requests!

You will need an installation of LLVM 3.3, which does the heavy lifting. If you're on Debian, install the llvm-3.3-dev package. If you're on OS X, then Calculon should build cleanly under Homebrew with the llvm33 package installed. If you're on Windows... Calculon should still work, but you'll have to install LLVM yourself. (If you make it work on Windows, please get in touch; I'm interested.)

How do I use it?

Why should I use it?

Calculon is really simple, and really fast.

The Calculon library itself is 4000 lines of C++ and ships as a set of headers. It can be invoked with one line of setup and three lines per script you want to load and compile. Then you get a function pointer which you can just run. Don't take my word for it --- look at one of the examples.

The Calculon programming language is very simple and is ideally suited to evaluating mathematical functions, very very quickly. Here is a minimal Calculon script:

let x = 0;
return

Here is a more complicated one:

/* On input, A and B are vectors */
/* On output, ANGLE is a real */
let magnitude(V: vector*3) = sqrt((V*V).sum) in
let nA = A / magnitude(A) in
let nB = B / magnitude(B) in
let dot(V1: vector*3, V2: vector*3) = (V1*V2).sum in
let ANGLE = acos(dot(nA, nB)) in
return

Or if you like, you can do more; one of the sample scripts calculates the Mandelbrot set.

Calculon can be configured to use either doubles or floats as the native real type. (You can use both types of Calculon  script side-by-side in the same program.) Vectors are accelerated using SIMD operations where possible. External functions can be trivially made available to Calculon scripts and you get most of the standard maths library by default.

Any number of input and output values may be returned.

Why shouldn't I use it?

Calculon scripts are pure: they should have no side effects. It's perfectly possible to register a function which does have side effects, but in general Calculon is better suited for calculating things rather than doing things: for example calculating the colour of a pixel, lots of times, rather than rendering an entire image in one go.

Calculon is not a Turing-complete programming language.

In addition, Calculon is very new and is probably riddled with bugs. Find any? Let me know by filing a bug.

Who wrote it?

I, David Given, wrote it. Got any comments, criticism, cake? Send it to dg@cowlark.com. If there's interest, I'll set up a mailing list.

What's the license?

Calculon is distributable under the terms of the Simplified BSD License.

Next page