Sunday, December 12, 2010

Annotations

An exciting new feature for 0.3 (currently working in the latest repository code) is "annotations."  Annotations allow you to extend the compiler with the language.  For example if I have module A:

import crack.compiler CrackContext;

void myann(CrackContext ctx) {
    ctx.inject('import crack.io cout; cout `hello world`;'.buffer);
}
And module B:


@import A myann;
@myann


The code injected from myann()would be injected into the token stream of module B.


There are a number of things that you can do from an annotation, you can read tokens, put them back, set parser callbacks, and create other annotations.  You can't yet do introspection (examine classes or functions or other compile-time objects) but that feature will be coming.


We currently use annotations to implement compiler-level macros:


import crack.exp.ann define;

@define attr(type, name) {
    type name;
    type get_$$name() { return name; }
    void set_$$name(type newVal) { name = newVal; }
} 
class Foo {
@attr(String, bar)
}


To use a macro like this from another module, you need to export it:
import crack.exp.ann define, export, exporter;
@exporter  # import all of the stuff we need to define exporter functions

@define attr(type, name) {
    type name;
    type get_$$name() { return name; }
    void set_$$name(type newVal) { name = newVal; }
}

@export attr

From another module we can import the macro as an annotation:

@import attrmod attr;

class Foo {
    @attr(String, bar);
}

Tuesday, November 16, 2010

Extension API

Crack currently has a bona-fide extension API in the trunk.  See http://code.google.com/p/crack-language/wiki/ModuleExtensionAPI for details.

The short story is: you can now define functions, types and methods from a shared library, and then import that library as if it were a normal Crack module.

Wednesday, October 6, 2010

Crack 0.2.1 Released

In the spirit of "release early, release often," We've just released crack 0.2.1.  This release is mostly 0.2 with the changes necessary for LLVM 2.8.  We also fixed the library distribution rule and made a few minor fixes to the documentation.

Sunday, October 3, 2010

Crack 0.2 Released

We're happy to announce the release of Crack 0.2.  The main change in this release was under the covers: we refactored some significant portions of the code in the interest of streamlining future development.  However, we also fixed a lot of bugs and added a lot of basic enhancements that go a long way towards making Crack a usable language.

With 0.2, Crack now provides the complete set of C operators.  We also added our first map implementation (red-black trees), File IO libraries, and libraries for socket programming.

So please dig in and let us know what you think!