Interpreter Mode
The interpreter mode enables the programmer to send and execute any valid script statement at runtime, except declaration of new globals.
An internal interpreter thread is created at the start of execution of each primary program. The interpreter socket(30020) accepts complete and valid UR-script statements when a program is running. When Interpreter mode is active it compiles and links the received statements into the running program and executes them in the scope of the interpreter thread. These statements become a part of the running program.
The scope of statements in the interpreter mode is inherited from the scope from which interpreter mode was called. Be aware that declaring new global variables in interpreter mode is not supported.
When statements are sent at a faster rate than what the interpreter can handle, they are queued in an internal buffer before they can be appended to the running program.When the last statement received is executed, the interpreter thread will be idle until new statements are received.
Interpreter mode can be stopped by calling end_interpreter()
over the interpreter mode socket, or by calling it from a thread in the main program. Interpreter mode also stops when the program is stopped.
Each statement should be sent in a single line, so the following statement:
def myFun():
mystring = "Hello Interpreter"
textmsg(mystring)
end
Should be formatted like below: def myFun(): mystring = "Hello Interpreter" textmsg(mystring) end
With a newline character to end the statement. Multiple statements can be sent on a single line, and will only be accepted if all can be compiled.
Interpreter Mode replies
Received valid commands and statements are always acknowledge with a reply on the socket in form of: ack: <id>: <statements>
If a program is not running or the statement results in a compilation or linker error, the interpreter will reply with a discard message: discard: <reason>: <statement>
.
Note: There exists an upper limit to the size of the interpreted statements per interpreter mode. To avoid reaching that limit clear_interpreter()
can be called to clear up everything interpreted into the current interpreter mode.
Important: It is important to remember that every time a statement is interpreted the size and the complexity of the program will grow if interpreter mode is not cleared either on exit or with clear_interpreter()
. Too large programs should be avoided.