When TclMP is loaded into the interpreter, the MPI type is already registered in the interpreter as a valid Tcl data type.
All calculations within TclMP are based upon LibGMP. The documentation of LibGMP contains detailed information on how to work with the internal data types of it.
These Functions exist to access it (include mpi.h):
void Tcl_SetMPIObj(Tcl_Obj*objptr,mpz_t inmp)
Tcl_NewMPIObj creates a new MPI Tcl Object and copies the MPI from its argument into the new object. Tcl_NewMPINullObject creates a new MPI object and initializes it with 0. Tcl_SetMPIObj changes the Tcl MPI object to reflect the number in its inmp argument.
Tcl_GetMPIFromObj returns a pointer to the internal representation of the Tcl MPI object. If you manipulate the MPI you must make sure the string representation of the object is invalidated, using Tcl_InvalidateStringRep.
All MPI functions that are visible from Tcl are created through a meta-script in the src/mpi subdirectory. Each of these scripts includes mkop.tcl first. This file defines two functions: op and finish.
op name args descr decl code
The arguments to the function you define are automatically converted into MPIs - if an argument is named a, it will be available as mpz_t*mpa. If you do not wish an argument to be interpreted than prefix it with an asterisk (*). If you do so: if the argument can be a number and you convert it using another internal representation (eg. with Tcl_GetIntFromObj), make sure you call Tcl_GetMPIFromObj again for all other MPIs, because Tcl shares Objects between literals and the pointer will be invalid after that transformation.
In the C code you can use two paths of exit: the macro ERR(x) takes a static string, sets it as result and returns with TCL_ERROR. The local variable ret (Tcl_Obj*) must otherwise be set to a valid Tcl Object that you wish to return.
The finish function creates the code to initialize and register all functions that were created with op to the Tcl Interpreter.
After you have written your script you need to:
In the Tcl_Obj structure MPIs are stored in the internalRep.otherValuePtr pointer. The internal functions handle all conversion, allocation, and freeing of this pointer, so you normally don't need to access it directly.