Source

pyd / infrastructure / deimos / python / pythonrun.d

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
/**
  Mirror _pythonrun.h

  Interfaces to parse and execute pieces of python code 

See_Also:
<a href="http://docs.python.org/c-api/veryhigh.html"> The Very High Level Layer </a>
  */
module deimos.python.pythonrun;

import std.c.stdio;
import deimos.python.pyport;
import deimos.python.object;
import deimos.python.code;
import deimos.python.compile;
import deimos.python.pyarena;
import deimos.python.pystate;
import deimos.python.node;
import deimos.python.symtable;

extern(C):
// Python-header-file: Include/pythonrun.h:

version(Python_3_2_Or_Later) {
    /// _
    enum PyCF_MASK = (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | 
            CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | 
            CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL);
}else version(Python_2_6_Or_Later) {
    /// _
    enum PyCF_MASK = (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | 
            CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | 
            CO_FUTURE_UNICODE_LITERALS);
}else version(Python_2_5_Or_Later) {
    /// _
    enum PyCF_MASK = (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | 
            CO_FUTURE_WITH_STATEMENT );
}else {
    /// _
    enum PyCF_MASK = CO_FUTURE_DIVISION;
}

/// _
enum PyCF_SOURCE_IS_UTF8 =  0x0100;
/// _
enum PyCF_DONT_IMPLY_DEDENT = 0x0200;

version(Python_2_5_Or_Later) {
    /// Availability: >= 2.5
    enum PyCF_ONLY_AST = 0x0400;
}
version(Python_3_2_Or_Later) {
    /// Availability: >= 3.2
    enum PyCF_IGNORE_COOKIE = 0x0800;
}

/// _
struct PyCompilerFlags {
    /// _
    int cf_flags;
}

version(Python_3_2_Or_Later) {
    /// Availability: >= 3.2
    void Py_SetProgramName(wchar*);
    /// Availability: >= 3.2
    wchar* Py_GetProgramName();

    /// Availability: >= 3.2
    void Py_SetPythonHome(wchar*);
    /// Availability: >= 3.2
    wchar* Py_GetPythonHome();
}else{
    /// Availability: <= 2.7
    void Py_SetProgramName(char*);
    /// Availability: <= 2.7
    char* Py_GetProgramName();

    /// Availability: <= 2.7
    void Py_SetPythonHome(char*);
    /// Availability: <= 2.7
    char* Py_GetPythonHome();
}

/**
  Initialize the Python interpreter. For embedding python, this should
  be called before accessing other Python/C API functions, with the 
  following exceptions:

  For Python 3, PyImport_AppendInittab and PyImport_ExtendInittab should
  be called before Py_Initialize.
  */
void Py_Initialize();
/// _
void Py_InitializeEx(int);
/// _
void Py_Finalize();
/// _
int Py_IsInitialized();
/// _
PyThreadState* Py_NewInterpreter();
/// _
void Py_EndInterpreter(PyThreadState*);

version(Python_2_5_Or_Later){
    /// _
    int PyRun_AnyFile()(FILE* fp, const(char)* name) {
        return PyRun_AnyFileExFlags(fp, name, 0, null);
    }
    /// _
    int PyRun_AnyFileEx()(FILE* fp, const(char)* name, int closeit) {
        return PyRun_AnyFileExFlags(fp, name, closeit, null);
    }
    /// _
    int PyRun_AnyFileFlags()(FILE* fp, const(char)* name, PyCompilerFlags* flags) {
        return PyRun_AnyFileExFlags(fp, name, 0, flags);
    }
    /// _
    int PyRun_SimpleString()(const(char)* s) {
        return PyRun_SimpleStringFlags(s, null);
    }
    /// _
    int PyRun_SimpleFile()(FILE* f, const(char)* p) {
        return PyRun_SimpleFileExFlags(f, p, 0, null);
    }
    /// _
    int PyRun_SimpleFileEx()(FILE* f, const(char)* p, int c) {
        return PyRun_SimpleFileExFlags(f, p, c, null);
    }
    /// _
    int PyRun_InteractiveOne()(FILE* f, const(char)* p) {
        return PyRun_InteractiveOneFlags(f, p, null);
    }
    /// _
    int PyRun_InteractiveLoop()(FILE* f, const(char)* p) {
        return PyRun_InteractiveLoopFlags(f, p, null);
    }
}else{
    /// _
    int PyRun_AnyFile(FILE*, const(char)*);
    /// _
    int PyRun_AnyFileEx(FILE*, const(char)*,int);

    /// _
    int PyRun_AnyFileFlags(FILE*, const(char)*, PyCompilerFlags *);
    /// _
    int PyRun_SimpleString(const(char)*);
    /// _
    int PyRun_SimpleFile(FILE*, const(char)*);
    /// _
    int PyRun_SimpleFileEx(FILE*, const(char)*, int);
    /// _
    int PyRun_InteractiveOne(FILE*, const(char)*);
    /// _
    int PyRun_InteractiveLoop(FILE*, const(char)*);
}

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

/// _
int PyRun_SimpleStringFlags(const(char)*, PyCompilerFlags*);

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

/// _
int PyRun_InteractiveOneFlags(
        FILE* fp, 
        const(char)* filename, 
        PyCompilerFlags* flags);
/// _
int PyRun_InteractiveLoopFlags(
        FILE* fp, 
        const(char)* filename, 
        PyCompilerFlags* flags);

version(Python_2_5_Or_Later) {
    /// Availability: >= 2.5
    _mod* PyParser_ASTFromString(
            const(char)* s, 
            const(char)* filename, 
            int start, 
            PyCompilerFlags* flags, 
            PyArena* arena);
    version(Python_3_2_Or_Later) {
        /// Availability: >= 3.2
        _mod* PyParser_ASTFromFile(
                FILE* fp, 
                const(char)* filename, 
                const(char)* enc, 
                int start, 
                char* ps1, 
                char* ps2, 
                PyCompilerFlags* flags, 
                int* errcode, 
                PyArena* arena);
    }else{
        /// Availability: <= 2.7
        _mod* PyParser_ASTFromFile(
                FILE* fp, 
                const(char)* filename, 
                int start, 
                char* ps1, 
                char* ps2, 
                PyCompilerFlags* flags, 
                int* errcode, 
                PyArena* arena);
    }
    /// _
    node* PyParser_SimpleParseString()(const(char)* s, int b) {
        return PyParser_SimpleParseStringFlags(s, b, 0);
    }
    /// _
    node* PyParser_SimpleParseFile()(FILE* f, const(char)* s, int b) {
        return PyParser_SimpleParseFileFlags(f, s, b, 0);
    }
}else{
    /// _
    node* PyParser_SimpleParseString(const(char)*, int);
    /// _
    node* PyParser_SimpleParseFile(FILE*, const(char)*, int);
    /// Availability: 2.4
    node* PyParser_SimpleParseStringFlagsFilename(const(char)*, const(char)*, int, int);
}

/// _
node* PyParser_SimpleParseStringFlags(const(char)*, int, int);
/// _
node* PyParser_SimpleParseFileFlags(FILE*, const(char)*,int, int);

    /**
Params:
str = python code to run
s = start symbol. one of Py_eval_input, Py_file_input, Py_single_input.
g = globals variables. should be a dict.
l = local variables. should be a dict.
flags = compilation flags (modified by `from __future__ import xx`).

Returns:
result of executing code, or null if an exception was raised.
*/
PyObject* PyRun_StringFlags( 
        const(char)* str, 
        int s, 
        PyObject* g, 
        PyObject* g, 
        PyCompilerFlags* flags);

version(Python_2_5_Or_Later){
    /**
Params:
str = python code to run
s = start symbol. one of Py_eval_input, Py_file_input, Py_single_input.
g = globals variables. should be a dict.
l = local variables. should be a dict.

Returns:
result of executing code, or null if an exception was raised.
     */
    PyObject* PyRun_String()(
            const(char)* str, 
            int s, 
            PyObject* g, 
            PyObject* l) {
        return PyRun_StringFlags(str, s, g, l, null);
    }
    /// _
    PyObject* PyRun_File()(FILE* fp, const(char)* p, int s, PyObject* g, PyObject* l) {
        return PyRun_FileExFlags(fp, p, s, g, l, 0, null);
    }
    /// _
    PyObject* PyRun_FileEx()(FILE* fp, const(char)* p, int s, PyObject* g, PyObject* l, int c) {
        return PyRun_FileExFlags(fp, p, s, g, l, c, null);
    }
    /// _
    PyObject* PyRun_FileFlags()(FILE* fp, const(char)* p, int s, PyObject* g, 
            PyObject* l, PyCompilerFlags *flags) {
        return PyRun_FileExFlags(fp, p, s, g, l, 0, flags);
    }
    /// _
    PyObject* Py_CompileString()(const(char)* str, const(char)* p, int s) {
        return Py_CompileStringFlags(str, p, s, null);
    }
}else{
    /**
Params:
str = python code to run
s = start symbol. one of Py_eval_input, Py_file_input, Py_single_input.
g = globals variables. should be a dict.
l = local variables. should be a dict.

Returns:
result of executing code, or null if an exception was raised.
*/
    PyObject* PyRun_String(const(char)* str, int s, PyObject* g, PyObject* l);
    /// _
    PyObject* PyRun_File(FILE*, const(char)*, int, PyObject*, PyObject*);
    /// _
    PyObject* PyRun_FileEx(FILE*, const(char)*, int, PyObject*, PyObject*, int);
    /// _
    PyObject* PyRun_FileFlags(FILE*, const(char)*, int, PyObject*, PyObject*, 
            PyCompilerFlags *);
    /// _
    PyObject* Py_CompileString(const(char)*, const(char)*, int);
}

/// _
PyObject* PyRun_FileExFlags(
        FILE* fp, 
        const(char)* filename, 
        int start, 
        PyObject* globals, 
        PyObject* locals, 
        int closeit, 
        PyCompilerFlags* flags);

version(Python_3_2_Or_Later) {
    /// _
    auto Py_CompileStringFlags()(const(char)* str, const(char)* p, 
            int s, PyCompilerFlags* f) {
        return Py_CompileStringExFlags(str, p, s, f, -1);
    }
    /// Availability: >= 3.2
    PyObject* Py_CompileStringExFlags(
            const(char)* str,
            const(char)* filename,
            int start,
            PyCompilerFlags* flags,
            int optimize);
}else{
    /// _
    PyObject* Py_CompileStringFlags(
            const(char)* str, 
            const(char)* filename, 
            int, 
            PyCompilerFlags* flags);
}

/// _
symtable* Py_SymtableString(
    const(char)* str,
    const(char)* filename,
    int start);

/// _
void PyErr_Print();
/// _
void PyErr_PrintEx(int);
/// _
void PyErr_Display(PyObject*, PyObject*, PyObject*);
version(Python_3_2_Or_Later) {
    /// Availability: >= 3.2
    void _Py_PyAtExit(void function() func);
}

/// _
int Py_AtExit(void function() func);

/// _
void Py_Exit(int);

version(Python_3_2_Or_Later) {
    /// Availability: >= 3.2
    void _Py_RestoreSignals();
}

/// _
int Py_FdIsInteractive(FILE*, const(char)*);

version(Python_3_2_Or_Later) {
    /// Availability: >= 3.2
    int Py_Main(int argc, wchar** argv);
}else{
    /// Availability: <= 2.7
    int Py_Main(int argc, char** argv);
}

/* In getpath.c */
version(Python_3_0_Or_Later) {
    /// Availability: >= 3.0
    wchar* Py_GetProgramFullPath();
    /// Availability: >= 3.0
    wchar* Py_GetPrefix();
    /// Availability: >= 3.0
    wchar* Py_GetExecPrefix();
    /// Availability: >= 3.0
    wchar* Py_GetPath();
    version(Python_3_2_Or_Later) {
        /// Availability: >= 3.2
        void Py_SetPath(const(wchar)*);
    }
    version(Windows) {
        /// Availability: >= 3.0, Windows only
        int _Py_CheckPython3();
    }
}else{
    char* Py_GetProgramFullPath();
    char* Py_GetPrefix();
    char* Py_GetExecPrefix();
    char* Py_GetPath();
}

/* In their own files */
/// _
const(char)* Py_GetVersion();
/// _
const(char)* Py_GetPlatform();
/// _
const(char)* Py_GetCopyright();
/// _
const(char)* Py_GetCompiler();
/// _
const(char)* Py_GetBuildInfo();

/* Various internal finalizers */
/// _
void _PyExc_Fini();
/// _
void _PyImport_Fini();
/// _
void PyMethod_Fini();
/// _
void PyFrame_Fini();
/// _
void PyCFunction_Fini();
/// _
void PyDict_Fini();
/// _
void PyTuple_Fini();
/// _
void PyList_Fini();
/// _
void PySet_Fini();
version(Python_3_0_Or_Later) {
    /// Availability: 3.*
    void PyBytes_Fini();
    /// Availability: 3.*
    void PyByteArray_Fini();
}else{
    /// Availability: 2.*
    void PyString_Fini();
    /// Availability: 2.*
    void PyInt_Fini();
}
/// _
void PyFloat_Fini();
/// _
void PyOS_FiniInterrupts();
/// _
void PyByteArray_Fini();


/// _
char* PyOS_Readline(FILE*, FILE*, char*);

/// _
__gshared int function() PyOS_InputHook;
/// _
__gshared char* function(FILE*, FILE*, char*) PyOS_ReadlineFunctionPointer;
/// _
__gshared PyThreadState* _PyOS_ReadlineTState;