Getting Started

The XièXiè langauge – and especially the compiler – is still in it’s first steps. But take a look on the very first getting-started examples, to see how easy it is …

Hello world example:

// Hello world example
void Main() {
    IO.Console.PrintNL("Hello, World!")
}

Using classes:

// Small class example
import IO.Console

class Date {
    init() {
        // We still want the default constructor.
        // Our members will be initialized
        // automatically (following the
        // RAII idiom).
    }
    init(uint day, uint month, uint year) {
        this.day := day
        this.month := month
        this.year := year
    }
    string ToString() readonly {
        ret day + "/" + month + "/" + year
    }
private:
    [[set,get]] uint day := 1, month := 1, year
}
void Main() {
    Date date1
    Date date2 := Date(30, 12, 2013)
    PrintNL("date1 = " + data1.ToString())
    PrintNL("data2 = " + data2.ToString())
}

Writing templates:

// Template example
class Vec3<pattern T> {
    init() {
    }
    init(const T x, const T y, const T z) {
        this.x := x
        this.y := y
        this.z := z
    }

    // Member operator
    Vec3<use T>& op(*=) (const T factor) {
        x *= factor
        y *= factor
        z *= factor
        ret *this
    }

    // Member variables
    T x, y, z
}

// Define a global operator
Vec3<use T> op(+) <pattern T>(
    const Vec3<use T> left,
    const Vec3<use T> right)
{
    Vec3<T> result
    result.x := left.x + right.x
    result.y := left.y + right.y
    result.z := left.z + right.z
    ret result
}
int Main() {
    int x := 5

    Vec3<use float> v1(1.0, 0.0, 0.0)
    v1.x *= 2.0

    // Some type casts
    Vec3<use float> v2((float)x, (float)x*2, 3)

    Vec3<use float> v3 := v1 + v2

    ret 0
}

 

Leave a Reply

A High Level, Meta Language with Trans-Compiler and Virtual Machine.