RTSync Tutorial 3 - Variables and Flow Constraints

Anything outside of an actor or synchronizer block is treated as normal C++ code. As an extension to C++, RTSync tries to keep the functionality of C++ while added something new. Inside the actor/synchonizer blocks however, the code is not exactly the same as in C++. The only types of variables allowed are integers, floating point numbers, strings and arrays.

Variables can either be a member variable of an actor or a local variable in a method. Declarations follow a C-style pattern, where all the variables must be declared at the start of the method. The only difference is that variables may be declared inside a loop or an if statement, so long as the declaration comes before any other lines.

The flow control statements that are allowed in RTSync are while loops and if statements. No for loops or dowhile loops are allowed. Other than that, these statements have the same structure as they normally would in C++. Here is a simple example of a program using loops and variables:

#include <iostream>
using namespace std;

actor A
{
    int i;

    init
    {
        i = 0;
    }

    a(int n)
    {
        if(n < 0)
        {
            n = -n;
        }
        while(i < n)
        {
            cout <<i <<endl;
            i = i + 1;
        }
        i = 0;
    }

    start()
    {
        a(5);
    }
}

int main()
{
    rt_start("A", "start");
}

As can be seen here, there are several new additions. We have a member variable, i, a parameter to a method, and several flow control statements. The program begins by calling the start() method of A, which then calls the method a(). Parameters cannot be passed using the rt_start() function, so a simple method like start() may be used instead to pass the parameters. So in this program we have the method a() that checks the parameter n to see if it is less than zero and if it is, then it inverts it. Then it iterates n times and prints the numbers to the screen. Note that the line:

 i = i + 1;

is used instead of i++. The ++, –, +=, etc. operators are not currently supported in RTSync.