-
Notifications
You must be signed in to change notification settings - Fork 1
Programming Language
The native language for the RGE is a custom language similar to C with some BASIC items inside.
It is a simplified language, and it is executed in the main cycles of the engine (Start and Update)
Language is NOT case-sensitive and can have only a single statement per line (with exception of if and else.)
There is no end of statement symbol like C, C++, C#, Java, etc.
C-style single line and multi-line comments are supported:
// single line comment
/* multi
line comment */
intfloatstringnull
There is no specification of types in this language, it is like Javascript.
The values are typed and the type is derived from the operations.
It is possible to cast some values to some other types.
Any sequence of letters and numbers up to 16 characters. It has to start with a letter.
A variable will hold a value and its type is automatic.
[expression] to access to the byte in memory (RAM and ROM) at the address calculated by the expression
[expression@] to access to the int (4 bytes) in memory (RAM and ROM) at the address calculated by the expression
[expression@b] to access to the bytes in memory (RAM and ROM) at the address calculated by the expression (same as [expression])
[expression@i] to access to the int (4 bytes) in memory (RAM and ROM) at the address calculated by the expression (same as [expression@])
[expression@f] to access to the float (4 bytes) in memory (RAM and ROM) at the address calculated by the expression
[expression@s] to access to the string (variable number of bytes) in memory (RAM and ROM) at the address calculated by the expression
Any combination of literal values and variables and memory.
The final type is calculated by the operations. E.g. adding two int will produce an int adding an int and float will result as a float
Supported operators are:
- + add
- - subtract
- * multiply
- / divide
- % modulo
- & and
- | or
- ^ xor
- << left shift
- >> right shift
An expression can be casted to a different native format by adding the _i, _b, _f, _s statements just after the expression.
12.75_i will be transformed to the integer 12 and 12.75_s will be transformed to the string "12.75"
Cast will always work, no errors or exceptions will be raised.
-
_icast expression to int -
_bcast expression to byte (cast first to int and then get only the least significant byte) -
_fcast expression to float -
_scast expression to string
You can assign values (result of expressions) to variables and directly to memory (Ram).
The syntax is: <destination> = <value>
These are valid assignments:
- a = 0
- b = 5 + 3 * 1.5
- c = a + ", " + b
- [256] = 0
- [a + 512] = "string value"
if statements are used to control the execution.
the syntax is:
if (<expression>) { <code> }
or
if (<expression>) <single line>
The expression can be anything, if it evaluates to 0 then the if is not executed, if it evaluates to anything else it will execute.
It is possible to use else statements:\
if (value < 0) {
somecode1
}
else {
somecode2
}
Remember that spaces and newlines are ignored. You can write the same code as:\
if (value < 0)
{
somecode1
}
else
{
somecode2
}
The while statement is used to execute a block of code when and until the expression is true.\
while (expression) {
code
}
The block is executed if the expression is not zero, after the code is evaluated the expression is evaluated again and eventually the code is executed again.
There is a hard limit on the VM that stops the cycles that have more than a thousand (1000) iterations.
write(string, xpos, ypos, color)
write(string, xpos, ypos, color, backgroundColor)
Write is used to write some text on the screen. Only a small subset of ASCII characters are supported.
If the background color is not specified, only foreground pixels will be rendered.
this may change in future, with font sizes and custom fonts*