davidgiven / cowgol

A self-hosted Ada-inspired programming language for very small systems.
BSD 2-Clause "Simplified" License
248 stars 20 forks source link

Cowgol 2.0

What?

Cowgol is an experimental, Ada-inspired language for very small systems (6502, Z80, etc). It's different because it's intended to be self-hosted on these devices: the end goal is to be able to rebuild the entire compiler on an 8-bit micro, although we're not there yet.

Here's the bullet point list of features:

About the compiler

Right now it's in a state where you can build the cross-compiler on a PC, then use it to compile the compiler for your selected device, and if it's small enough to fit use that to compile and run real programs. Realistically you'll be cross-compiling on a PC.

The following targets are supported. Adding more is easy.

In addition, there's emulator and assembler support for these platforms, but no compiler:

(It used to support the Apollo Guidance Computer used in the Apollo spacecraft, but I had to remove the code generator while rewriting the compiler and I haven't reworked the AGC backend.)

In terms of machines you can run the compiler on:

Many of the other platforms have unfinished system call libraries, so while the compiler tests all pass and the compilers are being built, they won't work if you run them. This should be easy to fix if necessary --- let me know and ask. (I just haven't got round to it yet.) Other platforms have working system call libraries but Cowgol doesn't provide an assembler, so you need to source your own (for example: MS-DOS and Atari ST TOS). So the compiler technically works there; you just can't do anything useful with it.

About the language

Here's a randomly chosen example pulled from the compiler source.

# Free up the node tree rooted in the parameter. This is more exciting than it
# should be because we don't have recursion.
#
# Editorial note: actually this subroutine no longer exists in the compiler
# source code because I replaced it with something simpler and better. No
# matter, the example still stands.
sub Discard(node: [Node]) is
        var pending := node;
        while pending != (0 as [Node]) loop
                node := pending;
                pending := node.dlink;

                # Unlink and push any children.
                if node.left != (0 as [Node]) then
                        node.left.dlink := pending;
                        pending := node.left;
                end if;
                if node.right != (0 as [Node]) then
                        node.right.dlink := pending;
                        pending := node.right;
                end if;

                # Now free this node.
                Free(node as [uint8]);
        end loop;
end sub;

The bullet list set of features is:

There's more about the language in the links below.

Why?

I've always been interested in compilers, and have had various other compiler projects: the Amsterdam Compiler Kit and Cowbel, to name two. (The languages section of my website contains a fair number of entries. The oldest compiler which still exists dates from about 1998.)

Cowgol is based on what I've learnt from all this. It's supposed to be useful, not just a toy. I'm pleasantly surprised by how good the generated code is; not that it's anything up to that of, say, gcc, but the main code generation binary of gcc is 23552kB, and Cowgol's is 65kB...

Where?

How?

We have documentation! Admittedly, not much of it.

Why not?

It's new, it's buggy, it's underdeveloped, and so far only one actual program is written in Cowgol, which is the Cowgol compiler. (And cowlink and cowwrap.)

Apart from actual bugs, there are some unimplemented parts of the language.

Your mileage (or kilometrage, depending) may vary. You Have Been Warned.

Who?

Cowgol was written mostly by me, David Given, with additional contributions from shattered@github. Feel free to contact me by email at dg@cowlark.com. You may also like to visit my website; there may or may not be something interesting there.

License?

Cowgol is open source software available under the 2-clause BSD license. Simplified summary: do what you like with it, just don't claim you wrote it.

The exceptions are the contents of the third_party directory, which were written by other people and are not covered by this license. This directory as a whole contains GPL software, which means that if you redistribute the entire directory, you must conform to the terms of the GPL.

third_party/lib6502 contains a hacked copy of the lib6502 library, which is © 2005 Ian Plumarta and is available under the terms of the MIT license. See third_party/lib6502/COPYING.lib6502 for the full text.

third_party/zmac contains a copy of the venerable zmac 8080 and Z80 assembler. It's in the public domain.

third_party/lemon contains a copy of the lemon parser generator. It's in the public domain.

third_party/apout contains a copy of the apout PDP-11 SysV binary emulator, primarily written by Warren Toomey and Eric A. Edwards. It is distributed under the terms of the MIT license; see third_party/apout/COPYRIGHT for the full text.

third_party/rc2014emu contains a subset of the RC2014 emulator written by Alan Cox. It is distributed under the terms of the GPL 3.0 license; see third_party/rc2014emu/COPYING for the full text.

third_party/emu2 constains a copy of the emu2 DOS emulator written by dmsc@github (and others). It is distributed under the terms of the GPL 2.0 license; see third_party/emu2/LICENSE for the full text.

third_party/djlink contains a copy of the djlink 16-bit linker written by dj@delorie.com. It is distributed under the terms of the GPL 2.0 license; see xthird_party/djlink/copying for the full text, with additional grants described in third_party/djlink/copying.dj.

third_party/musashi contains a copy of the Musashi 68000 emulation library, written by Karl Stenerud. It is distributable under the terms of the MIT license; see third_party/musashi/readme.txt for the full text. It also in turn contains a copy of John R. Hauser's softfloat library, distributable under a custom but MIT-like license; see third_party/musashi/softfloat/README.txt for the text.

third_party/libz80ex contains a copy of the z80ex Z80 emulation library, written bypigmaker57@kahoh57.info. It is distributable under the terms of the GPL GPL 2.0 license; see third_party/z80ex/COPYING for the text.