超高水準レイヤ
**************

この章の関数を使うとファイルまたはバッファにある Python ソースコードを
実行できますが、より詳細なやり取りをインタプリタとすることはできないで
しょう。

これらの関数のいくつかは引数として文法の開始記号を受け取ります。使用で
きる開始記号は "Py_eval_input" と "Py_file_input" 、 "Py_single_input"
です。開始記号の説明はこれらを引数として取る関数の後にあります。

これらの関数のいくつかが "FILE*" 引数をとることにも注意してください。
注意深く扱う必要がある特別な問題の1つは、異なるCライブラリの "FILE" 構
造体は異なっていて互換性がない可能性があるということです。実際に(少な
くとも)Windowsでは、動的リンクされる拡張が異なるライブラリを使うことが
可能であり、したがって、 "FILE*" 引数がPythonランタイムが使っているラ
イブラリと同じライブラリによって作成されたことが確かならば、単にこれら
の関数へ渡すだけということに注意すべきです。

int Py_Main(int argc, char **argv)

   The main program for the standard interpreter.  This is made
   available for programs which embed Python.  The *argc* and *argv*
   parameters should be prepared exactly as those which are passed to
   a C program’s "main()" function.  It is important to note that the
   argument list may be modified (but the contents of the strings
   pointed to by the argument list are not). The return value will be
   "0" if the interpreter exits normally (ie, without an exception),
   "1" if the interpreter exits due to an exception, or "2" if the
   parameter list does not represent a valid Python command line.

   "Py_InspectFlag" が設定されていない場合、未処理の "SystemExit" 例外
   が発生すると、この関数は "1" を返すのではなくプロセスを exit するこ
   とに気をつけてください。

int PyRun_AnyFile(FILE *fp, const char *filename)

   下記の "PyRun_AnyFileExFlags()" の *closeit* を "0" に、 *flags* を
   *NULL* にして単純化したインタフェースです。

int PyRun_AnyFileFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)

   下記の "PyRun_AnyFileExFlags()" の *closeit* を "0" にして単純化し
   たインタフェースです。

int PyRun_AnyFileEx(FILE *fp, const char *filename, int closeit)

   下記の "PyRun_AnyFileExFlags()" の *flags* を *NULL* にして単純化し
   たインタフェースです。

int PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit, PyCompilerFlags *flags)

   If *fp* refers to a file associated with an interactive device
   (console or terminal input or Unix pseudo-terminal), return the
   value of "PyRun_InteractiveLoop()", otherwise return the result of
   "PyRun_SimpleFile()".  If *filename* is *NULL*, this function uses
   ""???"" as the filename.

int PyRun_SimpleString(const char *command)

   下記の "PyRun_SimpleStringFlags()" の *PyCompilerFlags** を *NULL*
   にして単純化したインタフェースです。

int PyRun_SimpleStringFlags(const char *command, PyCompilerFlags *flags)

   "__main__" モジュールの中で *flags* に従って *command* に含まれる
   Python ソースコードを実行します。 "__main__" がまだ存在しない場合は
   作成されます。正常終了の場合は "0" を返し、また例外が発生した場合は
   "-1" を返します。エラーがあっても、例外情報を得る方法はありません。
   *flags* の意味については、後述します。

   "Py_InspectFlag" が設定されていない場合、未処理の "SystemExit" 例外
   が発生すると、この関数は "1" を返すのではなくプロセスを exit するこ
   とに気をつけてください。

int PyRun_SimpleFile(FILE *fp, const char *filename)

   下記の "PyRun_SimpleFileExFlags()" の *closeit* を "0" に、 *flags*
   を *NULL* にして単純化したインタフェースです。

int PyRun_SimpleFileFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)

   This is a simplified interface to "PyRun_SimpleFileExFlags()"
   below, leaving *closeit* set to "0".

int PyRun_SimpleFileEx(FILE *fp, const char *filename, int closeit)

   下記の "PyRun_SimpleFileExFlags()" の *flags* を *NULL* にして単純
   化したインタフェースです。

int PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, PyCompilerFlags *flags)

   Similar to "PyRun_SimpleStringFlags()", but the Python source code
   is read from *fp* instead of an in-memory string. *filename* should
   be the name of the file.  If *closeit* is true, the file is closed
   before PyRun_SimpleFileExFlags returns.

int PyRun_InteractiveOne(FILE *fp, const char *filename)

   下記の "PyRun_InteractiveOneFlags()" の *flags* を *NULL* にして単
   純化したインタフェースです。

int PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)

   Read and execute a single statement from a file associated with an
   interactive device according to the *flags* argument.  The user
   will be prompted using "sys.ps1" and "sys.ps2".  Returns "0" when
   the input was executed successfully, "-1" if there was an
   exception, or an error code from the "errcode.h" include file
   distributed as part of Python if there was a parse error.  (Note
   that "errcode.h" is not included by "Python.h", so must be included
   specifically if needed.)

int PyRun_InteractiveLoop(FILE *fp, const char *filename)

   下記の "PyRun_InteractiveLoopFlags()" の *flags* を *NULL* にして単
   純化したインタフェースです。

int PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)

   Read and execute statements from a file associated with an
   interactive device until EOF is reached.  The user will be prompted
   using "sys.ps1" and "sys.ps2".  Returns "0" at EOF.

struct _node* PyParser_SimpleParseString(const char *str, int start)

   下記の "PyParser_SimpleParseStringFlagsFilename()" の *filename* を
   *NULL* に、 *flags* を "0" にして単純化したインタフェースです。

struct _node* PyParser_SimpleParseStringFlags(const char *str, int start, int flags)

   下記の "PyParser_SimpleParseStringFlagsFilename()" の *filename* を
   *NULL* にして単純化したインタフェースです。

struct _node* PyParser_SimpleParseStringFlagsFilename(const char *str, const char *filename, int start, int flags)

   Parse Python source code from *str* using the start token *start*
   according to the *flags* argument.  The result can be used to
   create a code object which can be evaluated efficiently. This is
   useful if a code fragment must be evaluated many times.

struct _node* PyParser_SimpleParseFile(FILE *fp, const char *filename, int start)

   下記の "PyRun_SimpleParseFileFlags()" の *flags* を "0" にして単純
   化したインタフェースです。

struct _node* PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int flags)

   "PyParser_SimpleParseStringFlagsFilename()" に似ていますが、 Python
   ソースコードをメモリ内の文字列ではなく *fp* から読み込みます。
   *filename* はそのファイルの名前でなけれななりません。

PyObject* PyRun_String(const char *str, int start, PyObject *globals, PyObject *locals)
    *Return value: New reference.*

   下記の "PyRun_StringFlags()" の *flags* を *NULL* にして単純化した
   インタフェースです。

PyObject* PyRun_StringFlags(const char *str, int start, PyObject *globals, PyObject *locals, PyCompilerFlags *flags)
    *Return value: New reference.*

   Execute Python source code from *str* in the context specified by
   the dictionaries *globals* and *locals* with the compiler flags
   specified by *flags*.  The parameter *start* specifies the start
   token that should be used to parse the source code.

   コードを実行した結果をPythonオブジェクトとして返します。または、例
   外が発生したならば *NULL* を返します。

PyObject* PyRun_File(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals)
    *Return value: New reference.*

   下記の "PyRun_FileExFlags()" の *closeit* を "0" にし、 *flags* を
   *NULL* にして単純化したインタフェースです。

PyObject* PyRun_FileEx(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, int closeit)
    *Return value: New reference.*

   下記の "PyRun_FileExFlags()" の *flags* を *NULL* にして単純化した
   インタフェースです。

PyObject* PyRun_FileFlags(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, PyCompilerFlags *flags)
    *Return value: New reference.*

   下記の "PyRun_FileExFlags()" の *closeit* を "0" にして単純化したイ
   ンタフェースです。

PyObject* PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals, PyObject *locals, int closeit, PyCompilerFlags *flags)
    *Return value: New reference.*

   Similar to "PyRun_StringFlags()", but the Python source code is
   read from *fp* instead of an in-memory string. *filename* should be
   the name of the file. If *closeit* is true, the file is closed
   before "PyRun_FileExFlags()" returns.

PyObject* Py_CompileString(const char *str, const char *filename, int start)
    *Return value: New reference.*

   下記の "Py_CompileStringFlags()" の *flags* を *NULL* にして単純化
   したインタフェースです。

PyObject* Py_CompileStringFlags(const char *str, const char *filename, int start, PyCompilerFlags *flags)
    *Return value: New reference.*

   *str* 内の Python ソースコードをパースしてコンパイルし、作られたコ
   ードオブジェクトを返します。開始トークンは *start* によって与えられ
   ます。これはコンパイル可能なコードを制限するために使うことができ、
   "Py_eval_input" 、 "Py_file_input" もしくは "Py_single_input" であ
   るべきです。 *filename* で指定されるファイル名はコードオブジェクト
   を構築するために使われ、トレースバックあるいは "SyntaxError" 例外メ
   ッセージに出てくる可能性があります。コードがパースできなかったりコ
   ンパイルできなかったりした場合に、これは *NULL* を返します。

PyObject* PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals)
    *Return value: New reference.*

   This is a simplified interface to "PyEval_EvalCodeEx()", with just
   the code object, and the dictionaries of global and local
   variables. The other arguments are set to *NULL*.

PyObject* PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals, PyObject **args, int argcount, PyObject **kws, int kwcount, PyObject **defs, int defcount, PyObject *closure)

   Evaluate a precompiled code object, given a particular environment
   for its evaluation.  This environment consists of dictionaries of
   global and local variables, arrays of arguments, keywords and
   defaults, and a closure tuple of cells.

PyObject* PyEval_EvalFrame(PyFrameObject *f)

   Evaluate an execution frame.  This is a simplified interface to
   PyEval_EvalFrameEx, for backward compatibility.

PyObject* PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)

   Python のインタープリタの主要な、直接的な関数です。 この関数には
   2000 行ほどあります。 実行フレーム *f* に関連付けられたコードオブジ
   ェクトを実行します。 バイトコードを解釈して、必要に応じて呼び出しを
   実行します。 追加の *throwflag* 引数はほとんど無視できます。 - もし
   true なら、 すぐに例外を発生させます。これはジェネレータオブジェク
   トの "throw()" メソッドで利用されます。

int PyEval_MergeCompilerFlags(PyCompilerFlags *cf)

   現在の評価フレームのフラグを変更します。成功したら true を、失敗し
   たら false を返します。

int Py_eval_input

   単独の式に対するPython文法の開始記号で、 "Py_CompileString()" と一
   緒に使います。

int Py_file_input

   ファイルあるいは他のソースから読み込まれた文の並びに対するPython文
   法の開始記号で、 "Py_CompileString()" と一緒に使います。これは任意
   の長さのPythonソースコードをコンパイルするときに使う記号です。

int Py_single_input

   単一の文に対するPython文法の開始記号で、 "Py_CompileString()" と一
   緒に使います。これは対話式のインタプリタループのための記号です。

struct PyCompilerFlags

   コンパイラフラグを収めておくための構造体です。コードをコンパイルす
   るだけの場合、この構造体が "int flags" として渡されます。コードを実
   行する場合には "PyCompilerFlags *flags" として渡されます。この場合
   、"from __future__ import" は *flags* の内容を変更できます。

   "PyCompilerFlags *flags" が *NULL* の場合、 "cf_flags" は "0" とし
   て扱われ、 "from __future__ import" による変更は無視されます。

      struct PyCompilerFlags {
          int cf_flags;
      }

int CO_FUTURE_DIVISION

   このビットを *flags* にセットすると、除算演算子 "/" は **PEP 238**
   による「真の除算 (true division)」として扱われます。
