<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://www.tcl.tk/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Wed Jun 19 15:25:11 GMT 2013 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='322'>
<header><title>Publish the NRE API</title><author address="mailto:msofer@users.sourceforge.net">Miguel Sofer</author><status type='project' state='final' tclversion="8.6" vote='after'>$Revision: 1.9 $</status><history></history><created day='13' month='jul' year='2008' /></header>
<abstract>This TIP exposes an API to allow extension writers to take advantage of Tcl&apos;s Non-Recursive evaluation Engine.</abstract>
<body><section title="Rationale">
<para>NRE (for <emph style="bold">N</emph>on-<emph style="bold">R</emph>ecursive <emph style="bold">E</emph>ngine) is a trampoline implementation for command evaluation and bytecode execution that massively reduce Tcl&apos;s footprint on the C stack. It is conceptually related to stackless Python.</para>
<para>NRE is fully backwards compatible with script and C extensions and has already been committed to HEAD. Extensions that use the normal Tcl API run properly but cannot take advantage of the non-recursivity.</para>
<para>This TIP proposes to publish a small API for extension writers that will allow them to exploit the new possibilities.</para>
</section>
<section title="Functions to be Exported">
<para>The first two functions permit the creation of NRE-enabled commands. <emph style="bold">Tcl_NRCreateCommand</emph> creates a command that implements an NRE interface <emph style="italic">nreProc</emph>. As every command needs also a regular <emph style="italic">objProc</emph>, the function <emph style="bold">Tcl_NRCallObjProc</emph> is provided as a utility permitting a relatively simple way to generate the <emph style="italic">objProc</emph> from the <emph style="italic">nreProc</emph>.</para>
<itemize><item.i><para>Tcl_Command <emph style="bold">Tcl_NRCreateCommand</emph>(Tcl_Interp *<emph style="italic">interp</emph>, const char *<emph style="italic">cmdName</emph>, Tcl_ObjCmdProc *<emph style="italic">proc</emph>, Tcl_ObjCmdProc *<emph style="italic">nreProc</emph>, ClientData <emph style="italic">clientData</emph>, Tcl_CmdDeleteProc *<emph style="italic">deleteProc</emph>)</para></item.i><item.i><para>int <emph style="bold">Tcl_NRCallObjProc</emph>(Tcl_Interp *<emph style="italic">interp</emph>, Tcl_ObjCmdProc *<emph style="italic">objProc</emph>, ClientData <emph style="italic">clientData</emph>, int <emph style="italic">objc</emph>, Tcl_Obj *const *<emph style="italic">objv</emph>[])</para></item.i></itemize>
<para>The next three functions provide the API to request an evaluation by the trampoline, after the caller returned:</para>
<itemize><item.i><para>int <emph style="bold">Tcl_NREvalObj</emph>(Tcl_Interp *<emph style="italic">interp</emph>, Tcl_Obj *<emph style="italic">objPtr</emph>, int <emph style="italic">flags</emph>)</para></item.i><item.i><para>int <emph style="bold">Tcl_NREvalObjv</emph>(Tcl_Interp *<emph style="italic">interp</emph>, int <emph style="italic">objc</emph>, Tcl_Obj *const <emph style="italic">objv</emph>[], int <emph style="italic">flags</emph>)</para></item.i><item.i><para>int <emph style="bold">Tcl_NRCmdSwap</emph>(Tcl_Interp *<emph style="italic">interp</emph>, Tcl_Command <emph style="italic">cmd</emph>, int <emph style="italic">objc</emph>, Tcl_Obj *const <emph style="italic">objv</emph>[])</para></item.i></itemize>
<para>Finally, there is a function to register a callback that the trampoline has to execute right after a requested evaluation, typically used for cleanup.</para>
<itemize><item.i><para>void <emph style="bold">Tcl_NRAddCallback</emph>(Tcl_Interp *<emph style="italic">interp</emph>, Tcl_NRPostProc *<emph style="italic">postProcPtr</emph>, ClientData <emph style="italic">data0</emph>, ClientData <emph style="italic">data1</emph>, ClientData <emph style="italic">data2</emph>, ClientData <emph style="italic">data3</emph>)</para></item.i></itemize>
</section>
<section title="Documentation">
<para>NRE&apos;s internal functioning is somewhat documented at <url ref="http://msofer.com:8080/wiki?name=NRE"/></para>
<para>An example of how the API is to be used can be found at <url ref="http://msofer.com:8080/wiki?name=Exploiting+NRE"/></para>
<para>The new API will be documented in a manual page <emph style="italic">doc/NRE.3</emph>.</para>
</section>
<section title="Reference Implementation">
<para>The API is already available in HEAD (to become Tcl8.6a2); a high level description is available at <url ref="http://msofer.com:8080/wiki?name=NRE+short+explanation"/></para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>
