HPy Eval

enum HPy_SourceKind
[source]

An enumeration of the different kinds of source code strings.

enumerator HPy_SourceKind_Expr = 0
[source]

Parse isolated expressions (e.g. a + b).

enumerator HPy_SourceKind_File = 1
[source]

Parse sequences of statements as read from a file or other source. This is the symbol to use when compiling arbitrarily long Python source code.

enumerator HPy_SourceKind_Single = 2
[source]

Parse a single statement. This is the mode used for the interactive interpreter loop.

HPy HPy_Compile_s(HPyContext *ctx, const char *utf8_source, const char *utf8_filename, HPy_SourceKind kind)
[source]

Parse and compile the Python source code.

Parameters
  • ctx – The execution context.

  • utf8_source – Python source code given as UTF-8 encoded C string (must not be NULL).

  • utf8_filename – The filename (UTF-8 encoded C string) to use for construction of the code object. It may appear in tracebacks or in SyntaxError exception messages.

  • kind – The source kind which tells the parser if a single expression, statement, or a whole file should be parsed (see enum HPy_SourceKind).

Returns

A Python code object resulting from the parsed and compiled Python source code or HPy_NULL in case of errors.

HPy HPy_EvalCode(HPyContext *ctx, HPy code, HPy globals, HPy locals)
[source]

Evaluate a precompiled code object.

Code objects can be compiled from a string using HPy_Compile_s().

Parameters
  • ctx – The execution context.

  • code – The code object to evaluate.

  • globals – A Python dictionary defining the global variables for the evaluation.

  • locals – A mapping object defining the local variables for the evaluation.

Returns

The result produced by the executed code. May be HPy_NULL in case of errors.