Skip to content

Programming Language

CPU edited this page Jan 5, 2021 · 15 revisions

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.

Statements

Comments

C-style single line and multi-line comments are supported:
// single line comment
/* multi
line comment */

Native values

  • int
  • float
  • string
  • null

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.

Variables

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.

Memory

[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

Expressions

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

Casting

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.

  • _i cast expression to int
  • _b cast expression to byte (cast first to int and then get only the least significant byte)
  • _f cast expression to float
  • _s cast expression to string

Assignments

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

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
}

While

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.

For

write

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*

Clone this wiki locally