![]() |
Gorgon Game Engine
|
Gorgon Script Intermediate Language (IL) is designed for debugging and disassembling.
It is human readable representation of the underlying data structure. It is not designed to be back compatible. Therefore, it is not advised to do any serious programming with this language. However, it is very usable to see dialect compiler outputs to check for any errors. Its one to one representation makes it very easy to convert from/to internal data structure. Current implementation allows single quotes to be used instead of double quotes. This feature is not guaranteed in the future versions.
Every instruction is in a single line. The structure of IL is very rigid and the rules are enforced. # character at the beginning of the line causes parser to ignore that line. Empty lines are ignored. Additionally, spaces at the beginning and the end of the line are ignored. Tabs are also counted as space. Following is a simple assignment that performs var = 3 + i
Spaces are not significant in terms of parameter separation, so the second parameter could start right after the previous one without any spaces in between.
Value types are directly derived from Gorgon::Scripting::ValueType. However, literal types are also denoted. Every value type has a unique character that identifies it. A double quotes should follow this character, spaces are not allowed.
Variable is denoted with $ symbol. It should be followed by variable name in double quotes. Following is an example for a variable value type:
Since compilation step cannot always differentiate between language constructs, VM accepts identifier type and resolves it on the fly. However, if it is possible, specifying the type is recommended as it will work faster. Identifiers are marked with "?" character.
Temporaries are necessary to break compound statements. There are 255 temporaries in a typical GScript Virtual Machine. Their index starts from 1. Temporary symbol is dot and like other value constructs, temporary index should be in quotes. These values can be reused as soon as the old one is no longer needed. A temporary can be used multiple times and will not be unset automatically. This might cause delayed destruction of reference counted objects. Therefore, compilers are should set an instructor to unset temporaries.
Every literal has a different symbol. Double quoted textual value of the literal should follow the symbol. Currently, literals are parsed without syntax checking. This might be fixed in the future. Following is the list of literal symbols that are currently supported:
IL contains three basic instruction types. Other instruction types that exists in Gorgon::Scripting::InstructionType are variants of these basic types.
Assignment instructions starts with a variable value and can uniquely be identified from the first $ sign. After variable value (see Variable), there should be an equal sign or a column (column denoting assignment will be performed as reference) followed by the value to be assigned. This value could be represented with any value type denoted in Value Types. Assignment to a function result is not possible without using a temporary. Following is an example for assignment:
Saves a value to a temporary. If column is used instead of equal sign, reference assignment is performed. Example:
Saves the value of an instance member to a temporary. Example:
Saves the value of an instance member to a variable.
Saves the value of an instance member to a variable.
A function call is denoted by "f" symbol, while "m" is method call. These symbols are followed by either "n" or "m", "n" meaning namespace function/method where as "m" is member. Please note that GScript supports argument dependent look up over types. This means that even if a function/method is marked as namespace and it does not exists, it is looked from the first argument. This system is consistent with the notion that "this" object is passed as the first parameter to member functions/methods. A value should follow to indicate the function/method identifier. This could be either a string literal, constant (same as string literal) or variable. If it is a variable and its type is string, that function is searched and called, if not, the variable type's () function is called.
After the function identifier, parameters of the function is supplied. Each parameter is a value. Values do not need spaces in between, however, it is possible to separate them with spaces.
Return value of the function can be saved to a temporary.
The following line calls echo function as echo("Result: ", 3+4);
Remove temporary instruction is used to unset temporaries so that if they contain a reference object, it can be destructed. The format for this instruction is an x followed by temporary index in quotes.
There are three jump instructions, ja
: jump always, jf
: jump on false, jt
: jump on true. All jump instructions are followed by the number of lines that should be jumped from the current line. Like others, this value should be in quotes. For jump on false and jump on true, a value should follow the jump distance. Jump instructions are required for keywords.
This instruction will declare a new function overload. Unlike the VM instruction, source code for the function follows this directive until an fns"end" is found.