I'm alive
The transpilation tool, in addition to performing code translation, is used to create new Termina projects. Thus, the tool supports different commands. In particular, the new
command allows you to create a new project containing an initial directory tree and a project configuration file with default parameters.
In our case, we are going to create a new project named alive
. To do this, we will execute the following command from the terminal:
After executing the command, a new directory called alive
containing the following elements will have been generated:
The file termina.yaml
stores the project configuration parameters. The app
directory contains the main Termina source code file of the application. By default, this file is named app.fin
. The src
directory will contain the additional modules that are part of the project. In our case, we will not add any files to this directory. The output
directory will store the files generated by the transpiler from the Termina code.
Next, we are going to modify the app.fin
file, adding the following content:
task class AliveClass {
timer_port : sink TimeVal triggers timeout;
system_port : access SystemAPI;
action timeout(&priv self, _current_time : TimeVal) -> Status<i32> {
let msg : [char; 10] = "I'm alive!";
let ret : Status<i32> = Success;
self->system_port.println(10, &msg);
return ret;
}
};
emitter timer : PeriodicTimer = {
period = {
tv_sec = 1,
tv_usec = 0
}
};
#[priority(10)]
task alive_task : AliveClass = {
timer_port <- timer,
system_port <-> system_entry
};
The next step is to update the termina.yaml
configuration file, where we will need to add the following line at the end:
Finally, we will generate the application code with the following commands:
If the command has been executed successfully, the output directory should contain the modules resulting from the transpilation. In order to compile and run the project, we will have to execute the following commands in the terminal:
The program will print the message “I'm alive!” on the screen every second. To exit, it will be necessary to interrupt the execution of the program by entering the key combination Ctrl+C
in the terminal.