-
Notifications
You must be signed in to change notification settings - Fork 26
Manual
The mylittlepony
language and compiler are the UU-team's shot at getting a base language up and running. We want a compiler that is small and clear, allowing us to implement more interesting type systems as the Upscale work progresses.
The obligatory hello-world program, hello.enc
, looks like this:
-- hello.enc
class Main
def main() : void {
print "Hello, World"
}
You can compile this program by running encorec -clang hello.enc
It is important to know that every legal mylittlepony
program needs to have a class called Main
, with a method called main
. The runtime will begin execution in this method.
Mylittlepony
implements active and passive classes. Allocating an object from those classes gives active or passive objects, resp. To make a class active, no special keyword is necessary, as classes are active by default: class A
. To make a class passive, use passive class P
.
Calling a method on an active object will have that method execute concurrently (also in parallel, if enough cores are available). The return type of an active method is a future, not a value. Active classes are the default in mylittlepony
.
Calling a method on a passive object will execute that method synchronously, in the calling thread. Passive objects are similar to what you'd expect in a Java-like language.
We write an active class Foo
. A foo has an ID string, calling the printID
method will print that string 5 times to stdout
. In the main method, we create two Foo
instances, and have them print their IDs
-- ex_active.enc
class Main
def main() : void {
let obj1 = new Foo in {
let obj2 = new Foo in {
obj1.setID("obj1");
obj2.setID("obj2");
obj1.printID();
obj2.printID();
()
}
}
}
class Foo
id : string
def setID(new_id : string) : void {
this.id = new_id;
()
}
def printID() : void {
let i = 0 in {
while i < 5 {
i = i + 1;
print this.id
}
}
}
Executing this program gives nondeterministic output:
$ ./ex_active
obj2
obj1
obj2
obj1
obj2
obj1
obj2
obj1
obj2
obj1
A passive class is declared using the passive
keyword:
passive class Location
x : int
y : int
label : string
def init(new_x:int, new_y:int, new_label:string) : void {
this.x = new_x;
this.y = new_y;
this.label = new_label;
()
}
class Main
loc : Location
def main() : void {
this.loc = new Location;
this.loc.init(1,2,"a place");
print this.loc.x;
print this.loc.y;
print this.loc.label
}
The syntax is documented in source code in Parser.hs.