Thursday, March 22, 2012

Indented strings and struct annotations

I've just checked in support for two new features: indented strings and
struct annotations.

Indented strings allow you to write string constants across multiple lines
without breaking indentation:

    string_val := I'here is a document
                    embedded in a string definition
                        - this line will be indented in the output
                    but the rest will not.';

    cout.write(string_val);

This would produce the following output:

    here is a document
    embedded in a string definition
        - this line will be indented in the output
    but the rest will not.

In an indented string, the escaped newline also escapes all following
whitespace:

    # string_val = "this is a single line string!"
    string_val := I"this is a \
                    single line string!";

In an indented string (indicated with a capital "I" prefix) the tokenizer
strips all leading whitespace after a newline up to the minimum level of
indentation following a newline for the entire string. Whitespace after an
escaped newline, though ignored in the string itself, is considered in
determining the minimum indentation level. So if you wanted to define a string
containing a list of indented lines, you could do something like this:

    string_val := I'  a) item 1
                      b) item 2
                      c) item 3\
                    ';

The escaped newline and the whitespace before the final quote will be
ignored, but forces the minimum indentation to two characters before the start
of the previous lines.

This trick also works for i-strings:

    cout I`Hello!
           World!\n`;

Struct annotations essentially allow you to define a class consisting only of
instance variables with a constructor that allows you to initialize all of the
instance variables. So the Coord example from the manual (defining a two
dimensional coordinate) can now be written like this:

    @import crack.ann struct;

    @struct Coord {
        int x, y;
    }

    c := Coord(10, 20);  # create a Coord with x = 10, y = 20

The struct annotation is still very limited: you can't use inheritance or
define methods, and there are no auto-generated formatTo() or comparison
methods. These niceties will eventually be added. But it's still a worthwhile
convenience.

Thursday, March 15, 2012

Virtual Functions in Extensions!

This morning I checked in a big change to allow us to do a better job at wrapping C++ classes with virtual functions.  In summary, you can now create an extension class whose virtual methods call the underlying C++ function by default, but can be overriden in Crack as if they were normal Crack virtual methods.  This magic also works from C++: calling the virtual function on a Crack object from C++ transparently dispatches the call to the Crack override, cleanly solving the problem of C++ callbacks.  To top it all off, the interface is portable - it makes no assumptions about the C++ ABI.

You can read the original design doc at http://code.google.com/p/crack-language/wiki/ExtensionsVirtualFunctions.  At the time of this writing, this is not completely up-to-date, but test/testext.cc includes a complete example.

Happy wrapping!

Friday, January 13, 2012

Crack 0.6.1 released

I'm happy to announce the release of Crack 0.6.1.  The primary feature of this release is that we've ported the system to LLVM 3.0.  There were also a few bug fixes.  Enjoy!

Thursday, December 1, 2011

Crack 0.6 released

I'm pleased to announce the release of Crack version 0.6.  This will almost certainly be the last major release prior to 1.0 (we will release a 0.6.1 version shortly that builds against LLVM 3.0 and may contain bug fixes)

From the release notes:


  • Implemented const folding for integer and float operations.
  • Added support for injecting crack function body code from an extension.
  • Added the foundations of support for module caching.
  • Added functors.
  • Added an 'ascii' module supporting functionality specific to ASCII data.
  • Added a module for dealing with numeric arrays.
  • Migrated modules out of crack.exp, removed obsolete modules.
  • Implemented "const" variables.
  • Implemented access protection.
  •  Implemented abstract methods.
  • Converted all unit tests to "screen"
  • Lots of bug fixes and small enhancements.
So download, compile and enjoy!

Wednesday, August 24, 2011

screen: a new test suite for crack

In the current trunk, and due for inclusion in the next release, is our new test suite "screen".

It replaces the original system built on a simple bash script. The new test suite offers several advantages:

  1. It is template based, and individual tests all have their own templates
  2. It can skip tests based on functionality available on the host system (e.g. skip SDL tests if you don't have that extension)
  3. It runs multiple tests concurrently (see the -j option). The default concurrency is 4.
  4. It can test one or more builders. Currently this means it can run the tests through JIT, Native AOT, or both.
  5. It can compare expected results literally or to a regex
  6. It can test for explicit stderr output (e.g. parse errors)
  7. It can stop on test failure, and show expected vs actual results
  8. It can run a single test template, or recursively import a directory of them
  9. It's written in crack :)

The main test suite is run via "make check", as usual. You can find the source to screen, as well as the test templates themselves, in the screen/ directory. For more advanced testing (including running individual tests), run crack screen.crk --help



Monday, July 18, 2011

Crack 0.5 Released

We're pleased to announce the release of Crack 0.5. 

The main new feature of 0.5 is Generics.  Generics in Crack are somewhere between Java generics and C++ templates.  Like C++ templates, they are essentially generated by re-compiling the original code with parameter substitution.  Unlike C++ templates, parameters are limited to types.  Also, only generic classes are supported at this time.

Other notable changes in 0.5:

  • Support for first class functions and basic functors.  Functions now have types, and user defined classed may now implement an "oper call" method in order to make instances of the class callable using function-call syntax.
  • Implemented Platform Dependent Numeric Types (see http://code.google.com/p/crack-language/wiki/PlatformDependentNumericTypes) and reworked the numeric type system to conform to the specification.
  • Added a command line parsing module.
  • Converted all of the containers to generics, and added a HashMap generic.
  • Added some date manipulation code.
  • Refactored the cmake build.
  • Added the "typeof()" operator.
  • Added full support for "oper to" conversions.
  • Enhancements to extension generation for class methods, constructors,  and C function name specification.
This might be the last release before 1.0.  If you're interested in the language, we encourage you to download it, try it out and give us feedback.  Once 1.0 is out, all changes will have to be backwards compatible until 2.0.

Tuesday, May 3, 2011

Crack 0.4 Released

We are pleased to announce the release of Crack 0.4.  The two major changes for this version are Exceptions (ala C++, Java and Python) and Ahead-of-time compiling (so you can now run "crackc" on your script and produce a nice, ready to run executable in addition to the traditional scripty mode).

There are also a few new smaller features:
  • Sequence initializers ("array[int] a = [1, 2, 3]" or "array[int]![1, 2, 3]")
  • Improved string interpolation (added calls to enter() and leave() methods at the beginning and ending of each expression, allowing us to do things like "String s = FStr() `this is $var`;")
  • Byte and integer string constants ("b'A' == 65", "i'\001\0' == 256")
  • A no-op @encoding annotation allowing scripts to identify their encoding for other tools.
This release has been a long time coming, we hope you like it.