Mitch Pronschinske is the Lead Research Analyst at DZone. Researching and compiling content for DZone's research guides is his primary job. He likes to make his own ringtones, watches cartoons/anime, enjoys card and board games, and plays the accordion. Mitch is a DZone Zone Leader and has posted 2576 posts at DZone. You can read more from them at their website. View Full User Profile

Clay: A Generic Programming Language With an LLVM Backend

09.30.2010
| 13799 views |
  • submit to reddit
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

Comments

Ks Sreeram replied on Fri, 2010/10/01 - 1:21pm

Hi Mitchell

Clay, the language designed for generic programming, was not developed at Dartmouth. There does appear to be a different research language under development at Dartmouth with the same name. These two languages are completely unrelated.

The Clay that you've written about was developed at Tachyon Technologies, and it's website is at http://tachyon.in/clay .

Also the following paragraph doesn't apply to this Clay:

Clay supports singleton and linear types, arithmetic constraints in function pre and post conditions, polymorphism, and type inference. The language can statically detect many errors including buffer overflows, kernel stack overflows, freed memory uses, NULL pointer uses, and aliasing errors. Clay also moves the burden of error checking from runtime to compile time, allowing the programmer to find errors while compiling.

Regards
KS Sreeram
Developer of Clay

Ks Sreeram replied on Sun, 2010/10/03 - 11:11am

Hi Mitchell. Thanks for updating the article.

Raw ThinkTank replied on Sat, 2010/10/02 - 5:24am

Try your luck with Vala

Mitch Pronschinske replied on Sat, 2010/10/02 - 6:27pm

Sorry about that. Obviously, two languages with the same name can be a little confusing.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.