ViSlang is an intepreted language system for the development and analysis of visual computing programs. ViSlang consists of a runtime that acts as the unified programming interface to the user, several DSLs and an IDE. New DSLs that extend ViSlang are called slangs. The IDE includes a program editor and renderers that are able to visualize results of the computations.

ViSlang Overview

Slangs encapsulate a certain functionality and register it with the ViSlang runtime. The ViSlang runtime implements an embedded interpreter that executes programs in an interactive environment. The user interacts with the integrated program editor to issue ViSlang commands.

Data Types

The ViSlang language employs a dynamic type system (duck typing) to weakly enforce type compatibilities. When a value is assigned to a variable or when a function is called with a certain set of arguments, types are automatically downcasted if possible. Otherwise a run time error is generated. Variables and functions are typed and type compatibility is enforced during run-time. This guarantees the programmer that methods are only called with arguments of compatible types. Therefore, a method does not need to check types but can always assume that correct types are provided. The special type var can be used when run time inference of the actual type is desired. The integral types boolean, string, integer, and float are supported.

boolean foo = true; float bar = 3.0; integer baz = 3; string qux = 'hello';


float [512] foo;

Vector data types:

//TODO float3 foo = ?;

Control Flow

The language supports a small set of instructions including variable declaration and assignment, function declaration and calls, conditionals, loops, as well as boolean and arithmetic expressions. Additionally, it supports syntactic constructs that are specialized to allow the seamless integration into existing user interfaces, and the combination of slangs in novel ways.

Links: The linking (and unlinking) instruction allows to couple (and if desired decouple) two variables. In addition to an assignment, the linking is persistent and updates one variable whenever the value of the other variable changes (and vice versa).

integer a = 0; //decl. and assign. of a integer b = 0; //decl. and assign. of b a <=> b; //linking of a and b b = 1; //assignment of 1 to b a >=< b; //unlinking of a and b

Triggers: A trigger is assigned to a variable to execute a function every time the value of the variable changes. This is useful to trigger execution of functions or update of slangs that depend on values of other variables. If a parameter of object A depends on the parameter of object B, a trigger is assigned to a function call that updates the parameter of object A and if necessary converts the parameters first.

float x -> updateRendering(x); //everytime the value of x is changed the function updateRendering is called.

Objects and Slangs

An object typically encapsulates a set of variables and functions. Each object has its own name-space and can register variables and functions at compile- and run-time. A function call as well as the access to variables of an object are done with the typical "Object.Identifier" syntax.

//vs object vs.declareInteger('radius', 15, 1, 127); //creates a new integer with enforced ranged between 1..127

For convenience the arrays object provides several methods for array manipulation.

Arrays.fill(T[] a, T b); //assigns the specified value to each element of the specified array. Arrays.fillRandom(T[] a, T b); //assigns the a random value between 0 and b to each element of the specified array. Arrays.equal(T[] a, T[] b); //returns true if the two specified arrays are equal to one another.

The Images object provides several methods for image manipulation.

Images.clear(Image a); //sets all color values to 1 of the specified image. Images.clearBlack(Image a); //sets all color values to 0 of the specified image.

A slang additionally offers a programming interface to the user via the ViSlang language. A parser and execution interface are implemented that are called by the main language at run-time. The following example demonstrates the usage of slang that transforms code into an OpenCL kernels.

using Device; //switches to OpenCL kernel length(global float4 in, global float out) { int id = get_global_id(0); out[id] = length(in[id]); } using; // switches back to ViSlang float4[512] in; float[512] out; Arrays.fillRandom(in, 0, 10); Device.setLocalWorkSize(32, 1); Device.setGlobalWorkSize(512, 1); Device.length(in, out); // kernel is called like a normal function

Display Functionality

In ViSlang, each valid statement ends with either a block of code (enclosed by curly brackets) or with one of the terminal symbols ’:’ or ’;’. The semicolon symbol terminates the statement. The colon symbol triggers a call to all registered display functions with compatible signature. The type of the result of a statement is matched against all display functions. For instance the result of an assignment is the assigned value. If called with the colon symbol at the end of the statement the ViSlang system tries to display the result.

integer a = 5; a: //prints: "5"

You can also use the display functionality to print an overview of all existing functions of an object.

vs.functions(): //prints: [compile, declareFloat, declareInteger, functions, signatureOf, slangs, tic, toc, typeOf, variables]

Copyright © 2015-2020