# MeLa: A Programming Language for a New Multidisciplinary Oceanographic Float
## 2 A Programming Language Based on Models
### Code Generation
#### 2.4.3 Benefits of MeLa for Embedded Software Programming  
In MeLa, the functions accept different data types. For example, the max() function that searches the maximum value and index in an array accept integer and floating point arrays. On the contrary, the C language requires specific functions for each data type, for example, maxArrayFloat() and maxArrayInt(). In the MeLa library, the functions are defined by their MeLa name, their parameters types, and their C name. Several functions can have the same MeLa name, but different C names with different parameters types. When a function is called from the MeLa language, the parameter types are used to choose the function with the appropriate C name. For example, if the MeLa code is max(a)  
Figure 5: Code generation mapping.  
with a an array of integers, the corresponding function is the one that accepts arrays of integers and have the C name maxArrayInt(), if a is an array of floats the corresponding function is the one with the C name maxArrayFloat(). This mechanism is also called type inference, it makes programs easier to read and write by reducing the language verbosity [20].  
The verbosity is also reduced for variable declarations. A variable declared in MeLa can have a much more verbose C equivalent. For example, declaring a StaLta variable in MeLa requires only one line, StaLtaFloat stalta(5, 15, 10), but declaring it in C requires three lines, because it corresponds to an array, a circular buffer structure that contains the array, and a _stalta_ structure that contains the circular buffer:  
extram float32_t stalta_cbuff_data[25]; circular_buffer_f32_t stalta_cbuff = {stalta_cbuff_data, 25, 0, 0, true}; stalta_f32_t stalta = {&stalta_cbuff, 5, 15, 10, 0, 0};  
The circular buffer structure contains the pointer to the array of data, the length of the array, the index of the begin and end of the buffer, and a boolean indicating if the buffer is empty or not. An improper initialization or usage of these variables could lead to undefined behavior. In MeLa, these are automatically initialized and they are hidden to the developer such that it prevents an improper usage (encapsulation principle). Additionally, the notion of pointer does not exist in MeLa, avoiding errors of writing to unknown memory addresses. For example, forgetting the & operator when defining the _stalta_ structure would break the software.  
MeLa also hides the mapping of variables that can be stored into the microcontroller SRAM memory (128 kB) or an external SRAM memory that is in a separate chip (8 MB). In the generated C code, each array is mapped to the external memory that has more storage capacity, but small variables are mapped to the internal memory that is faster.  
Thus, writing an application with MeLa allows for programmers that are not expert in embedded software programming to write reliable and efficient applications (challenge 1 and 3). Even for an embedded software expert, writing an application with MeLa instead of C reduces the possibilities of making errors.