Platinum Partner
java,languages,c & c++,llvm,clay

Clay: A Generic Programming Language With an LLVM Backend

The Clay programming language is a type-safe variant of C/C++ that was developed at Tachyon technologies.  It recently appeared on bitbucket's open source repository to let developers find new, innovative uses for its highly reusable and efficient code.  Clay's runtime overhead and memory footprint are on the same level as C.  The language is perfect for writing embedded systems, garbage collectors, database servers, games, and more.     

Programmers who have written C++ templates know that the longer type names in generic code make the templates verbose, but Clay solves this issue with a whole-program type propagation.  When generic programming is combined with the entire program type propagation, developers can write high-level code that is on par with scripting language conciseness.

These are a few code samples form the 'test' directory:

Factorial
factorial1(n) {
if (n == 0)
return 1;
return n*factorial1(n-1);
}

factorial2(n) {
var p = 1;
again :
if (n == 0)
return p;
p *= n;
n -= 1;
goto again;
}

factorial3(n) {
var p = 1;
while (true) {
if (n == 0) break;
p *= n;
n -= 1;
}
return p;
}

factorial4(n) {
var p = 1;
for (i in range(n))
p *= i+1;
return p;
}

main() {
var n = 7;
n -= 1;
var f = factorial4(n);
println("factorial(", n, ") = ", f);
return 0;
}

Sequences - Lambda, filter
double(x) = 2*x;

main() {
var a = Vector([1, 2, 3, 4, 5, 6]);
var b = map(addressOf, a);
var c = map(dereference, b);
for (x in c)
x += 2;
for (x in map(double, map(double, a)))
println(x);
for (x in map(double, range(5)))
println(x);
}

One feature of Clay that really makes it efficient is the LLVM backend.  The LLVM compiler infrastructure is used to optimize the type-specialized low-level code generated during Clay's compilation.  As mentioned before, this low-level code is equivalent to C in performance, according to the project's developers.  

Here is a more concise list of Clay's primary features and advantages:

  • Machine memory model
  • Value semantics
  • Whole program type propagation
  • Module system
  • Extensible variant types
  • Multiple dispatch
  • Powerful compile time meta-programming
  • Interoperability with C
  • No garbage collection
  • LLVM backend

Clay is a fully functioning compiler available for Mac, Windows, and Linux.  You can learn more about the Clay programming language here
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}