]>
Commit | Line | Data |
---|---|---|
7eb75bcc DM |
1 | #include "Python.h"\r |
2 | \r | |
3 | #include "code.h"\r | |
4 | #include "compile.h"\r | |
5 | #include "Python-ast.h"\r | |
6 | #include "symtable.h"\r | |
7 | \r | |
8 | static PyObject *\r | |
9 | symtable_symtable(PyObject *self, PyObject *args)\r | |
10 | {\r | |
11 | struct symtable *st;\r | |
12 | PyObject *t;\r | |
13 | \r | |
14 | char *str;\r | |
15 | char *filename;\r | |
16 | char *startstr;\r | |
17 | int start;\r | |
18 | \r | |
19 | if (!PyArg_ParseTuple(args, "sss:symtable", &str, &filename,\r | |
20 | &startstr))\r | |
21 | return NULL;\r | |
22 | if (strcmp(startstr, "exec") == 0)\r | |
23 | start = Py_file_input;\r | |
24 | else if (strcmp(startstr, "eval") == 0)\r | |
25 | start = Py_eval_input;\r | |
26 | else if (strcmp(startstr, "single") == 0)\r | |
27 | start = Py_single_input;\r | |
28 | else {\r | |
29 | PyErr_SetString(PyExc_ValueError,\r | |
30 | "symtable() arg 3 must be 'exec' or 'eval' or 'single'");\r | |
31 | return NULL;\r | |
32 | }\r | |
33 | st = Py_SymtableString(str, filename, start);\r | |
34 | if (st == NULL)\r | |
35 | return NULL;\r | |
36 | t = (PyObject *)st->st_top;\r | |
37 | Py_INCREF(t);\r | |
38 | PyMem_Free((void *)st->st_future);\r | |
39 | PySymtable_Free(st);\r | |
40 | return t;\r | |
41 | }\r | |
42 | \r | |
43 | static PyMethodDef symtable_methods[] = {\r | |
44 | {"symtable", symtable_symtable, METH_VARARGS,\r | |
45 | PyDoc_STR("Return symbol and scope dictionaries"\r | |
46 | " used internally by compiler.")},\r | |
47 | {NULL, NULL} /* sentinel */\r | |
48 | };\r | |
49 | \r | |
50 | PyMODINIT_FUNC\r | |
51 | init_symtable(void)\r | |
52 | {\r | |
53 | PyObject *m;\r | |
54 | \r | |
55 | if (PyType_Ready(&PySTEntry_Type) < 0)\r | |
56 | return;\r | |
57 | \r | |
58 | m = Py_InitModule("_symtable", symtable_methods);\r | |
59 | if (m == NULL)\r | |
60 | return;\r | |
61 | PyModule_AddIntConstant(m, "USE", USE);\r | |
62 | PyModule_AddIntConstant(m, "DEF_GLOBAL", DEF_GLOBAL);\r | |
63 | PyModule_AddIntConstant(m, "DEF_LOCAL", DEF_LOCAL);\r | |
64 | PyModule_AddIntConstant(m, "DEF_PARAM", DEF_PARAM);\r | |
65 | PyModule_AddIntConstant(m, "DEF_FREE", DEF_FREE);\r | |
66 | PyModule_AddIntConstant(m, "DEF_FREE_CLASS", DEF_FREE_CLASS);\r | |
67 | PyModule_AddIntConstant(m, "DEF_IMPORT", DEF_IMPORT);\r | |
68 | PyModule_AddIntConstant(m, "DEF_BOUND", DEF_BOUND);\r | |
69 | \r | |
70 | PyModule_AddIntConstant(m, "TYPE_FUNCTION", FunctionBlock);\r | |
71 | PyModule_AddIntConstant(m, "TYPE_CLASS", ClassBlock);\r | |
72 | PyModule_AddIntConstant(m, "TYPE_MODULE", ModuleBlock);\r | |
73 | \r | |
74 | PyModule_AddIntConstant(m, "OPT_IMPORT_STAR", OPT_IMPORT_STAR);\r | |
75 | PyModule_AddIntConstant(m, "OPT_EXEC", OPT_EXEC);\r | |
76 | PyModule_AddIntConstant(m, "OPT_BARE_EXEC", OPT_BARE_EXEC);\r | |
77 | \r | |
78 | PyModule_AddIntConstant(m, "LOCAL", LOCAL);\r | |
79 | PyModule_AddIntConstant(m, "GLOBAL_EXPLICIT", GLOBAL_EXPLICIT);\r | |
80 | PyModule_AddIntConstant(m, "GLOBAL_IMPLICIT", GLOBAL_IMPLICIT);\r | |
81 | PyModule_AddIntConstant(m, "FREE", FREE);\r | |
82 | PyModule_AddIntConstant(m, "CELL", CELL);\r | |
83 | \r | |
84 | PyModule_AddIntConstant(m, "SCOPE_OFF", SCOPE_OFF);\r | |
85 | PyModule_AddIntConstant(m, "SCOPE_MASK", SCOPE_MASK);\r | |
86 | }\r |