Language Overview
File Extensions
By convention tscript is written in files using the extension .temu
.
TEMU also recognise .ts
, and .tscript
but that extension may clash with TypeScript.
Comments
tscript supports comments using either of the single line shell style (\#
) or C style (//
).
The shell-style comments has been supported since TEMU 2 while the C-style comments were added in TEMU 3.
C-style comments are the preferred style since TEMU 3.
Commands and Command Methods
Commands are stand alone global commands. This was the only type of command in TEMU 2. TEMU 3 introduces command method, a command that is associated to a specific class and invoked on objects. The difference is that when interacting with objects using a traditional command, the object must be passed explicitly and the command must verify the type or compliance of the object to what the command expects, for a command method, this is not the case since they can only be invoked on objects that are already compliant to whatever rules are imposed on the object.
Meta Classes and Class Objects
In TEMU 3, tscript has been extended with meta classes and class objects.
This primarily means that an object can be created using the class objects new
method.
The new
method does by default only take one argument (the object name) but classes can (in C or C++) customise the new
method by querying for it by name from the class objects meta class and adding named required or optional arguments to the method reference.
Each registered class has a class object with the name of the class, in addition each class object is associated with a meta class, with the name @{CLASS_NAME}
. In addition a root meta class responsible for constructing class and meta class pairs exists, this root class is named @MetaClass
.
You should normally not be interacting with the meta classes directly, but they exist there to maintain property and methods registries for the class objects.
Expressions
Tscript supports expressions. The operators supported depends on the type of the left and right hand sides.
Operator | Kind | Types |
---|---|---|
+ |
Binary |
integer, float |
- |
Binary, Unary |
integer, float |
/ |
Binary |
integer, float, paths |
* |
Binary |
integer, float |
./ |
Unary |
paths |
<< |
Binary |
integers |
>> |
Binary |
integers |
| |
Binary |
integers |
& |
Binary |
integers |
~ |
Unary |
integers |
! |
Unary |
integers |
Conditional Statements
Tscript supports if-statements.
if expr {
// statements
}
The conditional expression does not need to be parenthesised. However, the curly braces are mandatory.
Loops
Not yet implemented. |
To anticipate the future implementation of loops,
the keywords for
, foreach
and while
have been reserved.
Commands and Functions
Commands are entities that can fail. A command halts execution of a script if running non interactivelly. Functions however are expressions and cannot fail.
Commands can be converted to expression values which will prevent non-interactive scripts from terminating by using the try
keyword which converts the result of the command to a 1 for success and 0 for failure.
Command Definitions
It is possible to define commands both using the TEMU API and by defining commands in a tscript file.
defcmd mycmdname(a: string, b: path) {
echo $a
echo $b
}
mycmdname a=hello b=file.txt
A command can be failed using the raise statement.
A common use of a command would be to implement boot software emulation. The following example shows how a LEON3 processor can be booted:
defcmd boot(app: path) {
if try load obj=mem0 file=${app} start-addr-var=startpc {
if defined(startpc) {
cpu0.setPC pc=$startpc
}
// Scaler reload register should be freq in MHz - 1
grTimer0.scalerReload = cpu0.freq / 1e6 - 1
// Prepare stack and frame pointer registers
cpu0.setReg reg="%fp" value=0x40000000 + ram0.size - 4
cpu0.setReg reg="%sp" value=0x40000000 + ram0.size - 4 - 92
} else {
raise "Failed to load file"
}
}
Command Argument Types
The argument list is in the form of name type pairs, the argument name comes first, followed by a colon and then the typename. A number of types are supported at the moment:
-
int: integer type
-
real: double precision floating point
-
string: string type
-
path: string type (path indicates to auto completion to complete paths)
-
object: temu object type
-
iface: interface reference
-
prop: property reference
The arguments are available as scoped variables in the command body.
Exceptions
The raise statement raises an exception in a script and fails the current command. It takes a string as a parameter. This string will be printed out by the CLI as an error.
Exceptions can be caugth using the try expression. This expression converts the exception to a boolean.
if try mem0.load file=foo.elf {
// Success
} else {
raise "Could not load file!"
}