Timber | Implementation | Spar | Overview |
Spar is an experimental language that is part of the Automap project. Its main goals are:
to meet these goals a number of language constructs have been designed. For practical reasons we have chosen to embed them in the programming language Java.
Although not originally intended as such, Spar is almost a superset of Java. See our `sins' page for an overview of the deviations, and the reasons for them.
A native-code compiler is under construction. A working prototype is expected shortly. No attempt is made to use the JVM.
The parallelising constructs have been designed to make them
as safe as possible, while still allowing a compiler
to derive opportunities for parallelism from them.
For this purpose the each
and foreach
commands are provided.
Given a program block such as:
each { s1; s2; }
The statements s1
and s2
are executed in
arbitrary order. It is guaranteed, even for compound statements, that both
s1
and s2
are executed as one state transition.
The foreach
has similar behavior for all its iterations. E.g.
foreach( i :- 0:n ) a[i].init();
Parameterisation of classes, similar to C++ templates, is supported. Interfaces can also be parameterised.
Tuples are light-weight datastructures for groups of elements of fixed size. E.g.
[int,char] x = [1,'c']; int n = x[0]+2; char c = x[1]; x = [12,'z']; [n,c] = x;
If all the elements of the tuple have the same type, the tuple type can be written with a shorthand.
[int^3] x; x[0] = 1; // Fill element x = [1,2,3]; // Fill entire tuple
Such a tuple is sometimes called a vector.
If the operation is defined on the elements of a tuple, it is also defined on an entire tuple. E.g.
x += [1,0,0]; // Vector addition
All array accesses use vectors. E.g., this assigns 4 to a[0,0]
:
[int^2] v = [0,0]; a@v = 4;
Macros are similar to the inline
statement of C++, but
they are always obeyed. Also, macros can be given
types as parameters.
Array
interface enjoys the priviledged notation of arrays.A[3:5,:]
.
elaboration of arrays
elaboration of array expressions
elaboration of the Array
interface
elaboration of the ElasticArray
interface
Dynamic class loading is currently impossible because Spar is a batch compiler. The other restrictions are only determined by the implementation effort, not by a fundamental obstacle.
Last modified Sat May 13 15:50:56 2017 UT by Kees van Reeuwijk.