## Tcl9.0.3/Tk9.0.3 Documentation > Tcl C API > NRE

### Tcl/Tk Applications | Tcl Commands | Tk Commands | [incr Tcl] Package Commands | SQLite3 Package Commands | TDBC Package Commands | tdbc::mysql Package Commands | tdbc::odbc Package Commands | tdbc::postgres Package Commands | tdbc::sqlite3 Package Commands | Thread Package Commands | Tcl C API | Tk C API | [incr Tcl] Package C API | TDBC Package C API

  NAME
    Tcl_NRCreateCommand, Tcl_NRCreateCommand2, Tcl_NRCallObjProc, Tcl_NRCallObjProc2, Tcl_NREvalObj, Tcl_NREvalObjv, Tcl_NRCmdSwap, Tcl_NRExprObj, Tcl_NRAddCallback — Tcl 記述譜の非再起呼出し(記憶棚なし)評価　　　 Non-Recursive (stackless) evaluation of Tcl scripts.
  SYNOPSIS
    #include <tcl.h>
    Tcl_Command
    Tcl_NRCreateCommand(interp, cmdName, proc, nreProc, clientData,
    deleteProc)
    Tcl_Command
    Tcl_NRCreateCommand2(interp, cmdName, proc2, nreProc2, clientData,
    deleteProc)
    int
    Tcl_NRCallObjProc(interp, nreProc, clientData, objc, objv)
    int
    Tcl_NRCallObjProc2(interp, nreProc2, clientData, objc, objv)
    int
    Tcl_NREvalObj(interp, objPtr, flags)
    int
    Tcl_NREvalObjv(interp, objc, objv, flags)
    int
    Tcl_NRCmdSwap(interp, cmd, objc, objv, flags)
    int
    Tcl_NRExprObj(interp, objPtr, resultPtr)
    Tcl_NRAddCallback(interp, postProcPtr, data0, data1, data2, data3)
  引数 ARGUMENTS
    Tcl_Interp *interp (入力in)
    const char *cmdName (入力in)
    Tcl_ObjCmdProc *proc (入力in)
    Tcl_ObjCmdProc2 *proc2 (入力in)
    Tcl_ObjCmdProc *nreProc (入力in)
    Tcl_ObjCmdProc2 *nreProc2 (入力in)
    void *clientData (入力in)
    Tcl_CmdDeleteProc *deleteProc (入出力in/out)
    Tcl_Size objc (入力in)
    Tcl_Obj **objv (入力in)
    Tcl_Obj *objPtr (入力in)
    int flags (入力in)
    Tcl_Command cmd (入力in)
    Tcl_Obj *resultPtr (出力out)
    Tcl_NRPostProc *postProcPtr (入力in)
    void *data0 (入力in)
    void *data1 (入力in)
    void *data2 (入力in)
    void *data3 (入力in)
  説明 DESCRIPTION
  EXAMPLE
  参照回数管理 REFERENCE COUNT MANAGEMENT
  SEE ALSO
  KEYWORDS
  COPYRIGHT

### NAME

Tcl_NRCreateCommand, Tcl_NRCreateCommand2, Tcl_NRCallObjProc, Tcl_NRCallObjProc2, Tcl_NREvalObj, Tcl_NREvalObjv, Tcl_NRCmdSwap, Tcl_NRExprObj, Tcl_NRAddCallback — Tcl 記述譜の非再起呼出し(記憶棚なし)評価　　　 Non-Recursive (stackless) evaluation of Tcl scripts.

### SYNOPSIS

#include <tcl.h>
Tcl_Command
Tcl_NRCreateCommand(interp, cmdName, proc, nreProc, clientData,
`` deleteProc)
Tcl_Command
Tcl_NRCreateCommand2(interp, cmdName, proc2, nreProc2, clientData,
`` deleteProc)
int
Tcl_NRCallObjProc(interp, nreProc, clientData, objc, objv)
int
Tcl_NRCallObjProc2(interp, nreProc2, clientData, objc, objv)
int
Tcl_NREvalObj(interp, objPtr, flags)
int
Tcl_NREvalObjv(interp, objc, objv, flags)
int
Tcl_NRCmdSwap(interp, cmd, objc, objv, flags)
int
Tcl_NRExprObj(interp, objPtr, resultPtr)
Tcl_NRAddCallback(interp, postProcPtr, data0, data1, data2, data3)

### 引数 ARGUMENTS

Tcl_Interp *interp (入力in)
  関連する解釈実行機能｡　　　　 The relevant Interpreter.

const char *cmdName (入力in)
  生成すべき命令の名前｡　　　 Name of the command to create.

Tcl_ObjCmdProc *proc (入力in)
  命令を評価するために呼ばれる｡新しい連走行を使って nreProc を呼出す Tcl_NRCallObjProc を使う小さな包括譜の事が多い｡Tcl_CreateObjCommand(3) (参照されたい) への手続函数引数と同じ方法で振舞う｡ Called in order to evaluate a command. Is often just a small wrapper that uses Tcl_NRCallObjProc to call nreProc using a new trampoline. Behaves in the same way as the proc argument to Tcl_CreateObjCommand(3) (q.v.).

Tcl_ObjCmdProc2 *proc2 (入力in)
  命令を評価するために呼ばれる｡ 新しい連走行を使って nreProc2 を呼出す Tcl_NRCallObjProc2 を使う小さな包括譜の事が多い｡Tcl_CreateObjComman2(3) (参照されたい) への手続函数引数と同じ方法で振舞う｡ Called in order to evaluate a command. Is often just a small wrapper that uses Tcl_NRCallObjProc2 to call nreProc2 using a new trampoline. Behaves in the same way as the proc2 argument to Tcl_CreateObjCommand2(3) (q.v.).

Tcl_ObjCmdProc *nreProc (入力in)
  連走行が既に使われている時にprocの代りに呼出される｡　 Called instead of proc when a trampoline is already in use.

Tcl_ObjCmdProc2 *nreProc2 (入力in)
  連走行が既に使われている時にproc2の代りに呼出される｡　 Called instead of proc2 when a trampoline is already in use.

void *clientData (入力in)
  proc と nreProc と deleteProc と objProc に渡される任意の一語｡　　 Arbitrary one-word value passed to proc, nreProc, deleteProc and objProc.

Tcl_CmdDeleteProc *deleteProc (入出力in/out)
  cmdName が削除される前に解釈実行機能から呼出され､命令固有の清浄化を許容する｡NULL でも好い｡　　　 Called before cmdName is deleted from the interpreter, allowing for command-specific cleanup. May be NULL.

Tcl_Size objc (入力in)
  objv の中の品目の個数｡　　　　 Number of items in objv.

Tcl_Obj **objv (入力in)
  命令の中の語｡　　　　　 Words in the command.

Tcl_Obj *objPtr (入力in)
  評価すべき記述譜か式｡　　　　 A script or expression to evaluate.

int flags (入力in)
  Tcl_EvalObjv に関する記述に従う｡　　　　 As described for Tcl_EvalObjv.

Tcl_Command cmd (入力in)
  命令を評価する為の objv の第1語から誘導された語の代わりに使われる語句｡　　　　　　 Token to use instead of one derived from the first word of objv in order to evaluate a command.

Tcl_Obj *resultPtr (出力out)
  戻り符号が TCL_OK の時に評価の結果が保存される､非共有の Tcl_Obj への指示子｡　　　 Pointer to an unshared Tcl_Obj where the result of the evaluation is stored if the return code is TCL_OK.

Tcl_NRPostProc *postProcPtr (入力in)
  押込むべき函数｡　　　　　 A function to push.

void *data0 (入力in)

void *data1 (入力in)

void *data2 (入力in)

void *data3 (入力in)
  data0 through data3 are four one-word values that will be passed to the function designated by postProcPtr when it is invoked.

### 説明 DESCRIPTION

これらの函数は解釈実行機能が命令を評価する為に反復処理する函数棚への対話機能を提供する｡ 命令の背後の業務譜は初期函数及び､その進行に伴い業務譜が棚の上に押込む追加的な函数のどれでもによって実装される｡ 解釈実行機能そのものは函数を棚に押込み､業務譜の末尾に反応して他の形式の制御､譬えば実行中の棚同志の切替えや他の記述譜を追加的水準で C 棚に枠を追加することなく実践する｡ 業務譜を実行する為に業務譜の為の初期函数が呼出され連走行(trampoline)と呼ばれる小さな符号命令が繰返し棚から機能を取出して呼出し､業務譜の値として最後の呼出しの値を使用する｡(訳註 trampoline.[連走行]は終了条件が満たされる迄､繰返し実行される仕組)　　　　　　 These functions provide an interface to the function stack that an interpreter iterates through to evaluate commands. The routine behind a command is implemented by an initial function and any additional functions that the routine pushes onto the stack as it progresses. The interpreter itself pushes functions onto the stack to react to the end of a routine and to exercise other forms of control such as switching between in-progress stacks and the evaluation of other scripts at additional levels without adding frames to the C stack. To execute a routine, the initial function for the routine is called and then a small bit of code called a trampoline iteratively takes functions off the stack and calls them, using the value of the last call as the value of the routine.

Tcl_NRCallObjProc は nreProc を呼出し､新しい連走行を使う｡ Tcl_NRCallObjProc calls nreProc using a new trampoline.

Tcl_NRCreateCommand は Tcl_CreateObjCommand の代りであって､ 名前空間修飾子を含み現在の名前空間に相対的な cmdName の名前を決定し､その名前で命令を生成し､引続く Tcl_GetCommandName 呼出に使用できる命令に関する語句を返す｡ 少数の場合を除き､下に註意する如く､どの既存の命令であれ同じ名前が最初に削除される｡もし､解釈実行機能が削除される途中であると､Tcl_NRCreateCommand はどの命令も生成せず､どの命令も削除せず､ NULL を返す｡ Tcl_NRCreateCommand, an alternative to Tcl_CreateObjCommand, resolves cmdName, which may contain namespace qualifiers, relative to the current namespace, creates a command by that name, and returns a token for the command which may be used in subsequent calls to Tcl_GetCommandName. Except for a few cases noted below any existing command by the same name is first deleted. If interp is in the process of being deleted Tcl_NRCreateCommand does not create any command, does not delete any command, and returns NULL.

Tcl_NRCreateCommand2は､Tcl_CreateObjCommand2と同じ方法での､ Tcl_NRCreateCommandの替りである｡ Tcl_NRCreateCommand2, is an alternative to Tcl_NRCreateCommand in the same way as Tcl_CreateObjCommand2.

Tcl_NREvalObj は Tcl_EvalObjEx に似て函数を押込むが､ C 言語の棚上の空間を消費しない｡ Tcl_NREvalObj pushes a function that is like Tcl_EvalObjEx but consumes no space on the C stack.

Tcl_NREvalObjv は Tcl_EvalObjv に似て函数を押込むが､ C 言語の棚上の空間を消費しない｡ Tcl_NREvalObjv pushes a function that is like Tcl_EvalObjv but consumes no space on the C stack.

Tcl_NRCmdSwap は Tcl_NREvalObjv に似ているが､ cmd の最初の語を決定する代わりに､予め Tcl_CreateObjCommand か Tcl_GetCommandFromObj から返された objv を使う｡ Tcl_NRCmdSwap is like Tcl_NREvalObjv, but uses cmd, a token previously returned by Tcl_CreateObjCommand or Tcl_GetCommandFromObj, instead of resolving the first word of objv.

Tcl_NRExprObj は C 言語の棚上の空間を消費せずに Tcl_ExprObj と同じ方法で objPtr を式として評価する函数を押込む｡ Tcl_NRExprObj pushes a function that evaluates objPtr as an expression in the same manner as Tcl_ExprObj but without consuming space on the C stack.

もし､記述譜又は命令又は式が成功裡に遂行されると､全ての函数が TCL_OK を返す｡そうでない場合(譬ばもし､命令の名前が決められない) TCL_ERROR を返し解釈実行機能の結果として伝言文を保存する｡　　　　　　 All of the functions return TCL_OK if the evaluation of the script, command, or expression has been scheduled successfully. Otherwise (for example if the command name cannot be resolved), they return TCL_ERROR and store a message as the interpreter's result.

Tcl_NRAddCallback は postProcPtr を押込む｡Tcl_NRPostProc の特徴は次の通り: Tcl_NRAddCallback pushes postProcPtr. The signature for Tcl_NRPostProc is:

    typedef int
    Tcl_NRPostProc(
            void * data[],
            Tcl_Interp *interp,
            int result);

data は data0 から data3 を含む配列への指示子であり､result は 業務譜の役割を実装している先行する函数によって返された値である｡ data is a pointer to an array containing data0 through data3. result is the value returned by the previous function implementing part the routine.

### EXAMPLE

次の命令は､記述譜を評価する為に､C 言語の棚上の空間を消費する Tcl_EvalObjEx を使用する｡　　　　　 The following command uses Tcl_EvalObjEx, which consumes space on the C stack, to evaluate a script:

    int
    TheCmdOldObjProc(
        void *clientData,
        Tcl_Interp *interp,
        int objc,
        Tcl_Obj *const objv[])
    {
        int result;
        Tcl_Obj *objPtr;

        ... preparation ...

        result = Tcl_EvalObjEx(interp, objPtr, 0);

        ... postprocessing ...

        return result;
    }
    Tcl_CreateObjCommand(interp, "theCommand",
            TheCmdOldObjProc, clientData, TheCmdDeleteProc);

C 言語の棚上の空間の消費を避ける為､TheCmdOldObjProc は TheCmdNRObjProc に名前変更され､処理の段階は別の函数に分離された｡TheCmdPostProc は函数棚上に押込められる｡Tcl_EvalObjEx は C 言語の棚消費の代わりに連走行を使う Tcl_NREvalObj によって置換えられる｡新しい TheCmdOldObjProc の版は Tcl_NRCallObjProc を呼出す為の TheCmdNRObjProc を使う帯封譜である｡　　　　　　　 To avoid consuming space on the C stack, TheCmdOldObjProc is renamed to TheCmdNRObjProc and the postprocessing step is split into a separate function, TheCmdPostProc, which is pushed onto the function stack. Tcl_EvalObjEx is replaced with Tcl_NREvalObj, which uses a trampoline instead of consuming space on the C stack. A new version of TheCmdOldObjProc is just a a wrapper that uses Tcl_NRCallObjProc to call TheCmdNRObjProc:

    int
    TheCmdOldObjProc(
        void *clientData,
        Tcl_Interp *interp,
        int objc,
        Tcl_Obj *const objv[])
    {
        return Tcl_NRCallObjProc(interp, TheCmdNRObjProc,
                clientData, objc, objv);
    }

    int
    TheCmdNRObjProc
        void *clientData,
        Tcl_Interp *interp,
        int objc,
        Tcl_Obj *const objv[])
    {
        Tcl_Obj *objPtr;

        ... preparation ...

        Tcl_NRAddCallback(interp, TheCmdPostProc,
                data0, data1, data2, data3);
        /* data0 .. data3 are up to four one-word items to
         * pass to the postprocessing procedure */

        return Tcl_NREvalObj(interp, objPtr, 0);
    }

    int
    TheCmdNRPostProc(
        void *data[],
        Tcl_Interp *interp,
        int result)
    {
        /* data[0] .. data[3] are the four words of data
         * passed to Tcl_NRAddCallback */

        ... postprocessing ...

        return result;
    }

他の函数を押込むことができる業務譜で構成されているどのような函数も､巡回と､函数棚を使用して構成する連続と､を実装することを可能にする｡　　　　　　 Any function comprising a routine can push other functions, making it possible implement looping and sequencing constructs using the function stack.

### 参照回数管理 REFERENCE COUNT MANAGEMENT

函数Tcl_NRCallObjProcとTcl_NREvalObjvとTcl_NRCmdSwapに渡されたobjv配列内の最初のobjc値は､少なく共､参照回数1を有すべき; それらは実行中に追加の参照を取り得る｡　　　　　　　　 The first objc values in the objv array passed to the functions Tcl_NRCallObjProc, Tcl_NREvalObjv, and Tcl_NRCmdSwap should have a reference count of at least 1; they may have additional references taken during the execution.

Tcl_NREvalObjとTcl_NRExprObjへの objPtr引数は､少なく共､参照回数1を有すべき､それらは実行中にそれへの追加の参照を取り得る｡ 　　 The objPtr argument to Tcl_NREvalObj and Tcl_NRExprObj should have a reference count of at least 1, and may have additional references taken to it during execution.

Tcl_NRExprObjへのresultObj引数は､非共有対象である筈｡ The resultObj argument to Tcl_NRExprObj should be an unshared object.

この頁上のどの様な他の函数への引数の参照回数の､どの様な要求された最終の減少､の計画にも､非再帰的な実行処理譜内のどの様な後-処理段階と同じ様に､Tcl_NRAddCallbackを使うべし｡ Use Tcl_NRAddCallback to schedule any required final decrementing of the reference counts of arguments to any of the other functions on this page, as with any other post-processing step in the non-recursive execution engine.

The

### SEE ALSO

Tcl_CreateCommand, Tcl_CreateObjCommand, Tcl_EvalObjEx, Tcl_GetCommandFromObj, Tcl_ExprObj

### KEYWORDS

stackless, nonrecursive, execute, command, global, value, result, script

### COPYRIGHT

Copyright © 2008 Kevin B. Kenny. Copyright © 2018 Nathan Coulter.