The kernel features a simple malloc structure that allocates memor between 0x400000 and 0x800000 (4 MB heap space).
The allocator can be configured to "secure" its allocation list with a magic number by defining `USE_MAGIC_SECURED_MALLOC` in `config.h`.
It also features a surveillance mode that logs all allocations / frees. It can be enabled by defining `USE_VERBOSE_MALLOC` and `USE_VERBOSE_FREE` in `config.h`.
³) A boolean is representet as a 1 bit value but due to architecture limitations it is stored with 32 bits.
### Variable Format
Variables are stored in a `type+pointer` format where `type` stores the type of the variable and `pointer` either a pointer to the variable value or, if `type` is a pointer type, the pointer value of the variable.
trainScript is the language of trainOS. All programs are written in trainScript and are compiled on execution.
trainScript programs are executed in the kernels virtual machine and can be restricted in their feature set.
### Example
This example first prints "Hello World!", then counts to 60 and displays every pair of (n, 60 - n).
OBJ timer : "/sys/timer";
OBJ console : "/sys/console";
PUB main() | i : INT, str : TEXT
BEGIN
0 → i;
"Hello " → str;
console.printStr(str + "World!");
WHILE ((i + 1) → i) <= fun() DO
BEGIN
console.print2Int(i, fun() - i);
timer.sleep(2);
END
END
PUB fun() → i : INT
BEGIN
60 → i;
END
### Features
trainScript is a pure imperative language with strict typing. Operators can only be called on variables of the same type, there is no auto-casting (which means you need to write 0.0 instead of 0 for getting a REAL constant).
It also features the concept of "Modules" and "Objects". Each trainScript file represents a module that exports a set of methods. An object is an imported module instance. So it is possible to use a module multiple times in another module.
### Types
trainScript features 4 base types: `INT`, `REAL`, `BOOL` and `TEXT`. The description of the four types can be found in the section `Virtual Machine Architecture: Type Format`.