Files
sics/doc/programmer/macro.tex

50 lines
3.0 KiB
TeX

\subsection{The Macro Interpreter}
This module is responsible for splicing the Tcl macro interpreter into
the SICS framework. In order to achieve this several problems have to be
adressed:
\begin{itemize}
\item How to make Tcl commands available from within SICS.
\item How to call SICS with the correct execution context from Tcl macros.
\end{itemize}
The first problem is solved by overloading Tcl's unknown mechanism. The Tcl
interpreter automatically invokes a procedure {\bf unknown} when it cannot
find a command. The usual procedure in this case searches for Tcl procedures
in libraries and then tries to invoke the command as a shell command. For
SICS the last part has been cut off and replaced by a call to SICSUnknown
which tries to find an appropriate SICS command.
The second problem is solved by maintaing a stack of connection objects.
Before a Tcl command is invoked from SICS the current connection object is
pushed on the stack. If in due course SICSUnknown needs to find a connection
object in order to invoke a SICS object the last object from the stack will
be used. If Tcl finishes, the connection object is popped from the stack.
This is nicely shown in the TclAction code.
All this is implemented in macro.c.
The macro module presents the following interface to the outside world:\begin{itemize}
\item {\bf Tcl\_Interp *MacroInit(SicsInterp *pInter,SConnection *pCon) } initialises a Tcl interpreter with a SICS unknown mechanism. Furthermore deletes some Tcl standard commands which can be harmful in SICS. Returns a pointer to an interpreter on success, NULL else.
\item {\bf void MacroDelete(Tcl\_Interp *pInter) } deletes an interpreter.
\item {\bf int MacroFileEval(SConnection *pCon, SicsInterp *pInter, void *pData, int argc, char *argv) }, the SICS object wrapper function for script processing.
\item {\bf int InternalFileEval(SConnection *pCon, SicsInterp *pInter,
void *pData, int argc, char *argv) }, the SICS object wrapper
function for script processing. This version suppresses output to the
client however. All output goes into the command log only.
\item {\bf int ClientPut(SConnection *pCon, SicsInterp *pInter, void *pData, int argc, char *argv) },
the SICS object wrapper function for writing datato a client from
within a Tcl--script.
\item {\bf int MacroWhere(SConnection *pCon, SicsInterp *pInter,
void *pData, int argc, char *argv) }, the SICS object wrapper
function implementing the filewhere command.
\item {\bf int TclPublish(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])} is the implmentation of the Publish command for the
interpreter which installs a Tcl command into the system.
\item {\bf int TransactAction (SConnection *pCon, SicsInterp *pInter,
void *pData, int argc, char *argv) } This Function implements the
transact command which executes an command and sends a string
``TRANSACTIONFINISHED'' when the command finished executing.
\item {\bf MacroPush} pushes a connection onto the Tcl connection
stack.
\item {\bf MacroPop} removes a connection for the Tcl connection
stack.
\end{itemize}