Eigenstate : Myrddin News - April 2015


The last several months have been pretty productive for Myrddin. There have been 578 commits, support for a new platform has been added, and tons of bugfixes have been pushed.


libstd has grown a huge number of new functions. Examples include fairly basic things like getcwd(), path canonicalization, to string buffers, and much more. Portability fixes between the supported OSes have been added, wrapping differences between the system call interfaces.

Mbld: mature and ready.

Mentioned as new in the last Myrddin release, this tool has matured to the point where it is used for building all myrddin source. The input files and build process have changed quite a bit, and it is now aware of projects and subprojects, knows the top directory of your current build, and is can specify dependencies inside sibling directories.

Tools integrated into repository

One of the biggest changes is that a number formerly separate components for Myrddin have been merged in to the mc/ repository, and are now built and shipped with the compiler. mbld, libregex, and libbio are now all shipped with mc.

It's predecessor, myrbuild, is now gone.

Language strictness.

The compiler now rejects all noncomprehensive matches in match statements, requiring you to either match all values, or throw in a default case. So, for example:

const f = {x
    match x
    | 1:    std.put("one\n")
    | 2:    std.put("two\n")

will fail to compile, since you can pass in values like, for example, 3 into the function. You will need to either match all integers, or more likely in this case, add a pattern that matches anything. So, a working example would be:

const f = {x
    match x
    | 1:    std.put("one\n")
    | 2:    std.put("two\n")
    | other: std.fatal(1, "unexpected other: %i\n", other)

This has caught a number of bugs in libstd/.

Vim support

There were a number of vim scripts for Myrddin support lying around various hard drives, but now they are cleaned up, improved, and in version control. Other support tooling for more pleasant development will be joining them. (Anyone want to write an emacs mode?)

These are available in the git repository

Language Changes

In the last few months, the language has actually remained surprisingly stable, with the bulk of the work being on tooling and libraries. Still, there were two major changes:


Traits have been implemented and made to work. They currently only support specialization over concrete types, and not generic ones, although this is something that I would like to change. They are basically compile time interfaces, which can be implemented over a type at any point in the code. An example is below:

Define a hashable trait. This will allow any type that
has an implementation of this trait to get hashed.
trait hashable @a =
    hash : (val : @a -> uint32)

/* hashing implementation for integers */
impl hash int =
    hash = {val
        -> val * Bigprime

/* hashing implementation for strings */
impl hash byte[:] =
    hash = {str
        var h = 1
        for b in str
            h = 33 * h * (b castto(int32))

/* use the hashing */
const main = {
    std.put("hash of 123: %i\n", hash(123))
    std.put("hash of "abc": %i\n", hash("abc"))
    /* this will error out, saying there's no trait implemented */
    std.put("hash of 'c': \n", hash('c'))

Runtime type information.

The compiler now generates runtime type information, paving the way for intelligent introspection of data, generic printf, automatic struct packing and unpacking and all other sorts of information. The API for accessing this information is still up in the air, but example code for using it can be glanced at here.

The ABI will probably change to more tightly encode integers, and to put a size before each type so that it can be skipped over without fully parsing the data.

Caveat: This is only stubbed in on Plan 9

Platform Support: Plan 9

9front is now a supported platform. This code has also been reported to work on 9atom. There are a few caveats, for example, errno is partly stubbed in and emulated; Error handling within libstd needs to be rethought and cleaned up a little bit.

To bootstrap on plan9, run boostrap9.rc.