Undefined behavior

This document is an exhaustive list of supported syntax. For performance and technical limitations, if any syntax is not listed in this document, then the behavior is undefined. However, compiler errors will be provided as much as possible though the coverage is very limited at the moment.

Numeric Variable Declartion

All variables are created as Float32.

var x;

Numeric Literals

All literals are treated as Float32.

2;
1.0;

Numeric Arithematic Operations

x + 2;
x - y;
x * z;
X / 3;
x % 6;
((y + 2) - (3 * 5));

Numeric Assignment

var x = 1;
y = y + 1;
x += 5;
y -= 1;
z *= 2;
x /= 3;
y %= 2;
y++;
z--;

Special Context Constants

Constants may not be changed.

this.thread.x;
this.thread.y;
this.thread.z;
this.dimensions.x;
this.dimensions.y;
this.dimensions.z;

Argument Array Access

Read-only access to arrays of type Float32. No writing to argument arrays. Array indices are ordered X[z][y][x].

function kernel(A, B, C) {
    // ... blah ...
    x = A[0];
    y = B[42][x];
    z = C[3][2][1];
}

Single Output Array Write

Implicit write to OUTPUT[this.thread.z][this.thread.y][this.thread.x] of type Float32 using return statement.

function kernel() {
    // ... blah ...
    return x;
}

If Statements

if (x > 10) {
    // ... blah ...
}

if (y < 20 && z > -10) {
    // ... blah ...
} else if (y < 20) {
    // ... blah ...
} else {
    // ... blah ...
}

For Loops

Warning: Due to WebGL limitations, for loops should be of fixed length as much as possible. For loops are implicitly broken if run for too many iterations. The break statement will squash future iterations but will not jump to after the for loop (i.e. the loop will always iterate to completion even with no-ops).

for (var i=0; i<10; i++) {
    // ... blah ...
}

for (var i=0; i<200; i++) {
    if (i < 10) {
        // ... blah ...
    } else {
        break;
    }
}

for (var i=0; i<X[10]; i++) {
    // ... blah ...
}

While Loops

Warning: Due to WebGL limitations, while loops are implicitly broken if run for too many iterations. The break statement will squash future iterations but will not jump to after the while loop (i.e. the loop will always iterate to an implicit number of maximum iterations even with no-ops).

var x = 0;
while (x < 10) {
    x++;
}

Internal Functions

Internal functions can only have Float32 as arguments and can only return Float32. However, internal functions have access to the array arguments of a kernel function. Internal functions can only nest a single time (i.e. can only be placed inside the kernel function but not inside other internal functions. Not to be confused with "nested calls").

function kernel(A, B, C) {
    function internal(x, y) {
        return A[x] + B[y] + C[x][y];
    }
    
    return internal(this.thread.x, this.thread.y);
}

Built-in Math Functions

Math.floor(x);
Math.max(y, 100);
Math.min(y, -100);
Math.sin(z);
Math.cos(x);
Math.tan(x);
Math.round(x);
Math.pow(x, 2);
// ... blah ... 

Color function

Note: Only when graphical mode is set. Only the last color call with be the resulting color in the image.

this.color(r, g, b);
this.color(r, g, b, a);