TXR supports various primitive expressions:
- Numbers: 4, 4.5, and -4 are all good. No hexadecimals at this time.
- Strings: "hello" or 'hello'. GMS1-style (no escape characters)
- Constants: true, false You can add custom ones in txr_parse.
- Parentheses: (...) Overwhelmingly optional.
TXR supports a verity of common operators.
Binary operators, grouped by priority:
- *, /, %, div
- +, - (ECMAScript-style "a" + 4 -> "a4" is allowed)
- <<, >>
- &, |, ^
- ==, !=, <, >, <=, >=
- && (ES-style (4 && 5) -> 5 is allowed)
- || (ES-style (4 || 5) -> 4 is allowed)
Short circuiting is supported for both && and ||.
Unary operators:
- ! (unary NOT)
- - (negation)
- ~ (bit inversion)
- + (does nothing, but lets you do a = +4)
- ++ (prefix and postfix)
- -- (prefix and postfix)
Functions are exposed to TXR via txr_function_add;
Both fixed and variable-argument-count functions are supported.
Up to 16 arguments can be passed (if you need more, add them in txr_thread_resume, in txr_action.call)
Starting with part 2, TXR allows for statements.
Statements can be:
- Assignments
- Variable declarations
- Bracketed statements ({...})
- Branching
- Function calls
- Prefix/postfix increment/decrement (v++, --v, etc.)
You may declare local variables via GML-style var syntax
var i; var k = 0; var z = true, s = "hi";
Access to anything that is not a local variable will by default map to calling instance's
variables. You may customize this in txr_thread_resume (ident, set_ident).
You may assign variables via the conventional name = value syntax.
Assignment operators (+=, etc.) are also supported.
TXR supports a number of common branching statements:
Parentheses are optional.
break/continue are supported.
break/continue are supported.
break/continue are supported.
Semicolons and parentheses are optional, but maybe don't abuse that.
Common-case switch block.
cases are to be terminated with break.
Much like in GML VM, supporting arbitrary case expressions means that this is a slightly more optimized pile of if-statements.
Declares a label that you can later jump to.
Note that TXR expects some sort of a statement after the label.
Transfers the program to the specified label.
Transfer to the specified label while pushing the original location to stack.
This allows to use labels as makeshift sub-routines.
You can strip out this feature in txr_parse (see case "call", case "back").