TelluIoT / ThingML

The ThingML modelling language

Home Page:https://github.com/TelluIoT/ThingML

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error with array initialization (if multiple instances of the same thing)

brice-morin opened this issue · comments

Consider the following spec:

thing MyThing {
	
    readonly property N : UInt8
    readonly property ARRAY : UInt8[N]
    ...
}

configuration myConfig {
    instance i0 : MyThing
    set i0.N = 3
    set i0.ARRAY = {50,75,15}

    instance i1 : MyThing
    set i1.N = 1
    set i1.ARRAY = {50}
}

It generates the following erroneous JS code:

...
//init array for i0
var inst_i0_ARRAY = [];
inst_i0_ARRAY[2] = 15;
inst_i0_ARRAY[0] = 50;
inst_i0_ARRAY[0] = 50;
inst_i0_ARRAY[1] = 75;
...
//init array for i1
var inst_i1_ARRAY = [];
inst_i1_ARRAY[2] = 15;
inst_i1_ARRAY[0] = 50;
inst_i1_ARRAY[0] = 50;
inst_i1_ARRAY[1] = 75;
...

Quite obvisouly, this code is wrong, somehow mixing the arrays of different instances of the same thing.

As far as I can see, the problem is not JS-specific (though I haven't tested for other compilers) and probably is somewhere in the inglorious ConfigurationHelper.initExpressionsForInstanceArrays helper method.