Data types and literals

The current version of ThingML allows defining two kinds of data types: primitive types and enumeration.

Remark: More complex data structures might be supported in future versions.

Primitive types

Primitive types allow defining the data types used in ThingML. Here are some examples:

datatype Boolean<1>;
datatype Integer<2>;
object String;

At compile time these types have to be mapped to types available on the target platform. Typically, the mapping to the platform type is provided by annotating the primitive types:

datatype Boolean<1>	
  @c_type "uint8_t"
  @java_type "boolean";

datatype UInt8<1>	
  @c_type "uint8_t"
  @java_type "short";

datatype Int16<2>	
  @c_type "int"
  @java_type "short";

object String	
  @c_type "char *";
  @c_byte_size "*" // * means that it has the size of a pointer
  @java_type "String";

Enumerations

Enumerations are defined using the "enumerations" keyword.

enumeration AnalogReference 
{
  DEFAULT
  INTERNAL
  EXTERNAL
}

In the same way as for primitive types, annotations are typically used to provide platform types and literal values:

enumeration DigitalState<1> 
  @java_type "byte"
  @c_type "uint8_t"
{
  LOW @enum_val "0"
  HIGH @enum_val "1"
}

Using data types

The data types are used to specify the types of thing properties, state variables and message parameters. For example:

  // definition of a property of type Integer
  property myProperty : Integer

  // definition of a property of type DigitalState
  property state: DigitalState

  // defintion of a message with two parameters
  message sendState(name : String, state : DigitalState );

Literals

ThingML defines literals for booleans, integers and strings. Notations for literals are illustrated on the example below:

  property myBoolean : boolean = true
  property myInteger : Integer = 1000
  property myString : String = "Some Value"

Enumeration literals can also be used directly using the name of the enumeration and the name of the literal separated by the ":" symbol:

  property myDigitalState : DigitalState = DigitalState:LOW