-
Notifications
You must be signed in to change notification settings - Fork 7
Tutorial
hsk edited this page Oct 30, 2014
·
5 revisions
sudo pacman -S clang boost llvm
Build and install
For example,
git clone [email protected]:yutopp/rill.git
cd rill
mkdir build
cd build
cmake ../. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
make
sudo make install
rillc helloworld.rill
helloworld
helloworld.rill
def main():int {
printf("Hello World\n")
}
mutable variable.
val a: mutable(int) = 10;
and assign variable.
a = 20
immutable variable and type inference.
val b = 20;
We cannot rewrite a immutable variable.
b = 10 // error
mutable class.
ctor is constructor.
mutable class initialize like mutable(TestClass)()
.
def main(): int
{
val klass1 = mutable(TestClass)();
klass1.a = 1192;
p(klass1.a);
return 0;
}
class TestClass
{
def ctor()
{
this.a = 10;
}
val a: mutable(int);
}
immutable class. immutable class initialize like TestClass()
.
def main(): int
{
val klass2 = TestClass();
p(klass2.a);
return 0;
}
class TestClass
{
def ctor()
{
this.a = 10;
}
val a: mutable(int);
}
overload constructor
def main(): int
{
val klass2 = TestClass(20);
p(klass2.a);
return 0;
}
class TestClass
{
def ctor()
{
this.a = 10;
}
def ctor(val i: int)
{
this.a = i;
}
val a: mutable(int);
}
output
20
def main(): int
{
val a = 20;
val b = f(a);
p(b);
return 0;
}
template(T: type)
def f(val a: T): T
{
val v: mutable(T) = 150;
v = 10;
return a * v;
}