Exemplo n.º 1
0
static PyCodeObject *
parse_source_module(const char *pathname, FILE *fp)
{
    PyCodeObject *co = NULL;
    mod_ty mod;
    PyCompilerFlags flags;
    PyArena *arena = PyArena_New();
    if (arena == NULL)
        return NULL;
	
    flags.cf_flags = 0;
	
    mod = PyParser_ASTFromFile(
		fp, pathname,
#if PY_MAJOR_VERSION >= 3
		"utf-8",
#endif
		Py_file_input, 0, 0, &flags,
		NULL, arena);
    if (mod) {
        co = PyAST_Compile(mod, pathname, NULL, arena);
    }
    PyArena_Free(arena);
    return co;
}
Exemplo n.º 2
0
/*将源文件编译为字节码文件*/
static PyCodeObject*
compile(FILE *fp)
{
	PyCodeObject *co = NULL;
	mod_ty mod;
	PyCompilerFlags flags;
	PyArena *arena = PyArena_New();
	
	if(arena == NULL)
	{
		Ps_Log("Py arena new failed\n", Ps_LOG_WARING);
		return NULL;
	}
	
	flags.cf_flags = 0;
	mod = PyParser_ASTFromFile(fp, "", Py_file_input, 0, 0, &flags, NULL, arena);
	
	if(mod)
	{
		co = PyAST_Compile(mod, "", NULL, arena);
	}
	
	PyArena_Free(arena);
	
	return co;
}
Exemplo n.º 3
0
static PyObject *
run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals,
	 PyCompilerFlags *flags, PyArena *arena)
{
	PyCodeObject *co;
	PyObject *v;
	co = PyAST_Compile(mod, filename, flags, arena);
	if (co == NULL)
		return NULL;
	v = PyEval_EvalCode(co, globals, locals);
	Py_DECREF(co);
	return v;
}
Exemplo n.º 4
0
static PyObject *
run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals,
	 PyCompilerFlags *flags, PyArena *arena)
{
	STACKLESS_GETARG();
	PyCodeObject *co;
	PyObject *v;
	co = PyAST_Compile(mod, filename, flags, arena);
	if (co == NULL)
		return NULL;
	STACKLESS_PROMOTE_ALL();
	v = PyEval_EvalCode(co, globals, locals);
	STACKLESS_ASSERT();
	Py_DECREF(co);
	return v;
}
Exemplo n.º 5
0
PyObject *
Py_CompileStringFlags(const char *str, const char *filename, int start,
		      PyCompilerFlags *flags)
{
	PyCodeObject *co;
	mod_ty mod;
	PyArena *arena = PyArena_New();
	if (arena == NULL)
		return NULL;

	mod = PyParser_ASTFromString(str, filename, start, flags, arena);
	if (mod == NULL) {
		PyArena_Free(arena);
		return NULL;
	}
	if (flags && (flags->cf_flags & PyCF_ONLY_AST)) {
		PyObject *result = PyAST_mod2obj(mod);
		PyArena_Free(arena);
		return result;
	}
	co = PyAST_Compile(mod, filename, flags, arena);
	PyArena_Free(arena);
	return (PyObject *)co;
}