TraSH is the language used in the Terminal. It is necessary to circumvent the use of 'eval' (necessary to pass the extension store checks) and not have the limitations of JSON. This is my own implementation simply because I felt like doing something like this... but maybe it's not the best of my ideas... at least it seems to work and meet expectations.
- Interpreter: Compile input string into pseudo-bytecode
- VMachine: Runs the pseudo-bytecode
Variables in TraSH do not have a type. Function parameters can be typed. The interpreter will try to convert and validate the types.
To declare a variable: $var = 'value'
To retrieve the value: $var
If the variable is of type 'function', it is used $$
to invoke: $$mifunc paramA paramB
There are three families of functions:
-
Native functions: Are executed entirely by the TraSH vm (ofc js vm is used internally).
- Normal (named):
function myfun(paramA: Number, paramB: String) { print 'Hello World: ' + $paramA + ' -- ' + $paramB }
myfunc 10 'Yo'
- Anonymous:
$myfunc = function(paramA: Number, paramB: String) { print 'Hello World: ' + $paramA + ' -- ' + $paramB }
$$myfunc 10 'Yo'
- Normal (named):
-
Internal functions: Are executed by the JavaScript vm
In JavaScript (flow typed)
async function funcMy(vmachine: VMachine, kwargs: CMDCallbackArgs): Promise<number> { return 42; }
-
Commands: Are executed by the shell and the JavaScript vm
In JavaScript (flow typed)
async function cmdMy(this: Terminal, kwargs: CMDCallbackArgs, ctx: CMDCallbackContext): Promise<number> { ctx.screen.print('O_o 42!'); return 42; }
if ($a > 10) {
print 'a'
} elif ($a > 5) {
print 'b'
} else {
print 'c'
}
Left to Right
- ** Increment/Decrement can be 'Right to Left'
- ** 'Simple assigment' is 'Right to Left'
- POW: ^
- DIVIDE: /
- MULTIPLY: *
- MODULO: %
- SUBSTRACT: -
- ADD: +
- EQUAL: ==
- NOT_EQUAL: !=
- GREATER_THAN_OPEN: >
- LESS_THAN_OPEN: <
- GREATER_THAN_CLOSED: >=
- LESS_THAN_CLOSED: <=
- AND: &&
- OR: ||