Skip to content

finbrein/Cesium

 
 

Repository files navigation

Cesium v 0.2
============

To make, ensure that you have Boehm's GC and the latest LLVM installed on your machine.

You will need to adjust some paths in the makefile and in cs_env. Note that I have Cesium in a directory called cstar2. Simply replace that with whatever directory you have Cesium in.

Type source cs_env.

Now just type make.

To run it just type:

./cs

It accepts:

1) strings: "hello"
2) booleans: true false
3) integers: -12345
4) doubles: 1.23 1.23e-20

You can do computations with: 

1) doubles, integers and booleans
2) +, -, *, /, %, <<, >> and parentheses.
3) &, |, ^|, ~
4) <, >, <=, >=, ==, !=
5) &&, ||, !
6) i++, i--, ++i, --i
7) i+=c, i-=c, i*=c, i/=c, i%=c
8) i&=c, i|=c, i^|=c
9) i<<=c, i>>=c

var i = 1.2, j = 2.2, k = i + j - i*j;

etc.

The following control flow statements are valid:

1) if (bool_expr) stmt1 
2) if (bool_expr) stmt1 ; (useful at the top level)
3) if (bool_expr) stmt1 else stmt2
4) while (bool_expr) stmt1
5) break;
6) { stmt; ... }

The following compound expressions are valid:

1) if expr then expr1 else expr2
2) (expr1, expr2, ...) // tuples whose elements can have arbitrary types 

Functions and applications are as follows:

1) fn fn_name(a, b, c, ....) { stmt; .... return expr; .... }
2) fn_name(1, 2, 3, ....);

Anonymous functions (closures) are expressions which can be defined as:

1) lambda(a, b, c) { expr1; expr2; ...; expr }
2) lambda(a, b, c) expr

Beware that as lambdas are expressions, a statement ending in a lambda must be terminated by a semicolon __even if it already ends in a brace__.

One can assign to tuples:

var (i, (j, k)) = (1, (2, 3));

To define a new datatype:

datatype mytype(a, b, c);
var s = mytype(1, 2, 3);
s.a += 4;

To initialise an array of length 100:
var i = 0, a = array(100);
while (i < 100) {
   a[i] = i;
}

The file "tests" gives a lot of examples of things you can (and can't) do.

Note there are no typeclass checks at the moment. Things like "string"+"more"; typecheck fine, but then just crash. This will be fixed eventually.

Watch this space for updates.

(Greg license: please refer to the greg-0.1 directory.)

Cesium license:

Copyright 2011 William Hart. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:

   1. Redistributions of source code must retain the above copyright notice, this list of
      conditions and the following disclaimer.

   2. Redistributions in binary form must reproduce the above copyright notice, this list
      of conditions and the following disclaimer in the documentation and/or other materials
      provided with the distribution.

THIS SOFTWARE IS PROVIDED BY William Hart ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL William Hart OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the
authors and should not be interpreted as representing official policies, either expressed
or implied, of William Hart.

About

Fast interpreter with LLVM backend.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published