Tree @master (Download .tar.gz)
Castile
Version 0.5 | Entry @ catseye.tc | See also: Eightebed ∘ Dieter
This is the reference distribution for Castile, a simple imperative language with union types.
The design of Castile was influenced (in varying degrees) by C, Rust, Eightebed, Python, Ruby, and Erlang. More information on its roots can be found in doc/Design.md.
The reference implementation can both interpret Castile programs and compile them to a variety of targets — JavaScript, Ruby, C, and a generic stack-based VM (included in this distribution).
A rich test suite in Falderal format, which describes the language with many examples, can be found in tests/Castile.md.
Quick Start
Clone this repository, cd into the repo directory and run
bin/castile eg/hello.castile
Alternately, put the bin subdirectory on your executable search path, so
that you can run castile from any directory on your system. castile
has no dependencies besides Python (either Python 2 or Python 3.)
Motivating Example
Here are some functions for creating linked lists, written in Castile:
struct list {
value: integer;
next: list|void;
}
fun empty() {
return null as list|void
}
fun cons(v: integer, l: list|void) {
make list(value:v, next:l) as list|void
}
In this, list|void is a union type. In this case it is expressing
the fact that the value can be either a list or void — the moral
equivalent of "nullable". In order to access any of the concrete types
of a union type, one must use typecase:
fun max(l: list|void) {
u = l;
v = u;
n = 0;
while true {
typecase u is void {
break;
}
typecase u is list {
if u.value > n {
n = u.value
}
v = u.next;
}
u = v;
}
return n
}
This retains type-safety; the code will never unexpectedly be presented with a null value.
Union types can also encourage the programmer follow a Parse, don't validate
approach (which, despite the impression you might get from reading that article,
is not restricted to Haskell or even to functional programming). In the above
code, cons will never return a void, and max is not defined on empty lists.
So ideally, we'd like to tighten their types to exclude those. And we can:
...
fun cons(v: integer, l: list) {
make list(value:v, next:l as list|void)
}
fun singleton(v: integer) {
make list(value:v, next:null as list|void)
}
fun max(l: list) {
u = l as list|void;
v = u;
...
}
Many more examples of Castile programs can be found in tests/Castile.md.
Commit History
@master
git clone https://git.catseye.tc/Castile/
- Add example file, note after observing the compiled code from it. Chris Pressey 5 years ago
- Merge pull request #1 from catseye/develop-2021 Chris Pressey (commit: GitHub) 5 years ago
- Add a Python 3 test appliance. Chris Pressey 5 years ago
- Use test appliances when running the test suite with Falderal. Chris Pressey 5 years ago
- Rename `.markdown` file extension to `.md`. Chris Pressey 5 years ago
- Mercurial is no longer supported in this repo. Chris Pressey 5 years ago
- Update sources to run under either Python 2 or Python 3. Chris Pressey 5 years ago
- Fix generated Ruby that worked in Ruby 1.8 but fails in Ruby 1.9. Chris Pressey 10 years ago
- Added tag rel_0_3_2015_0101 for changeset 93a9b9b9efde Chris Pressey 11 years ago
- Don't use deprecated Falderal variables. Chris Pressey 11 years ago
- Added tag rel_0_3 for changeset 1a4234975ba8 Chris Pressey 11 years ago
- I don't really care what state it's in, it's 0.3 now. Chris Pressey 11 years ago
- Make test driver more suitable for automated testing. Cat's Eye Technologies 12 years ago
- Make a few more tests of the C backend pass. catseye 13 years ago
- Create function declarations correctly, pass two more tests. catseye 13 years ago
- Use void * for functions in C backend. Add some OO/MM/GC notes. catseye 13 years ago
- More wrestling with C declarations. catseye 13 years ago
- Local function variables are function pointers. catseye 13 years ago
- Come closer to actual C declarations. 4 more tests pass. catseye 13 years ago
- Small C backend fixes, "only" 22 fails now. Update README. catseye 13 years ago
- Tiny improvement to C boilerplate. catseye 13 years ago
- Deal with types in C backend more fully; "only" 30 failures now. catseye 13 years ago
- Fix bugs in function lifter, C boilerplate: 24 more tests pass. catseye 13 years ago
- Beginnings of a C backend. catseye 13 years ago
- Prevent local vars defined inside control blocks. No 'var'. catseye 13 years ago
- Make local variables Python-like. Add failing test cases. catseye 13 years ago
- Remove a little weirdness from the language. catseye 13 years ago
- Clean up checker a bit (no assignable, no struct_fields.) catseye 13 years ago
- Added tag rel_0_2 for changeset ccc418957b63 catseye 13 years ago
- Update README for version 0.2. catseye 13 years ago