summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/python/eval.hpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-01-11 08:29:31 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-01-11 08:29:31 +0000
commit7d44c7ee8fee7bc6f401c47b5268778500b25558 (patch)
tree94fcb8e978f198e8108c2ba82ff43018e41bd259 /sca-cpp/trunk/modules/python/eval.hpp
parentc2add2e09088fc3640d2ad784ddfd56d1ad75f7b (diff)
Cleaned up python support code, removed unused functions.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@897787 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/python/eval.hpp')
-rw-r--r--sca-cpp/trunk/modules/python/eval.hpp64
1 files changed, 21 insertions, 43 deletions
diff --git a/sca-cpp/trunk/modules/python/eval.hpp b/sca-cpp/trunk/modules/python/eval.hpp
index cb6cdea3e2..1b9392aed7 100644
--- a/sca-cpp/trunk/modules/python/eval.hpp
+++ b/sca-cpp/trunk/modules/python/eval.hpp
@@ -19,8 +19,8 @@
/* $Rev$ $Date$ */
-#ifndef tuscany_python_pyeval_hpp
-#define tuscany_python_pyeval_hpp
+#ifndef tuscany_python_eval_hpp
+#define tuscany_python_eval_hpp
/**
* Python script evaluation logic.
@@ -42,29 +42,14 @@ public:
PythonRuntime() {
Py_Initialize();
- // Import the builtin module
- PyObject* p = PyString_FromString("__builtin__");
- builtin = PyImport_Import(p);
- Py_DECREF(p);
-
setupIO();
}
~PythonRuntime() {
- Py_DECREF(builtin);
}
-private:
- friend PyObject* builtin(const PythonRuntime& r);
-
- PyObject* builtin;
-
} pythonRuntime;
-PyObject* builtin(const PythonRuntime& r) {
- return r.builtin;
-}
-
/**
* Declare conversion functions.
*/
@@ -111,7 +96,7 @@ PyTypeObject pyLambda_type = {
/**
* Create a new python object representing a lambda expression.
*/
-PyObject *mkPyLambda(const lambda<value(const list<value>&)> l) {
+PyObject *mkPyLambda(const lambda<value(const list<value>&)>& l) {
pyLambda* pyl = NULL;
pyl = PyObject_NEW(pyLambda, &pyLambda_type);
if (pyl != NULL)
@@ -160,7 +145,7 @@ PyObject* valueToPyObject(const value& v) {
* Convert a python tuple to a list of values.
*/
-const list<value> pyTupleToValuesHelper(PyObject* o, int i, int size) {
+const list<value> pyTupleToValuesHelper(PyObject* o, const int i, const int size) {
if (i == size)
return list<value>();
return cons(pyObjectToValue(PyTuple_GetItem(o, i)), pyTupleToValuesHelper(o, i + 1, size));
@@ -220,22 +205,6 @@ const value pyObjectToValue(PyObject *o) {
}
/**
- * Read a python script from an input stream.
- */
-const failable<PyObject*> readScript(const string& path, istream& is) {
- const list<string> ls = streamList(is);
- ostringstream os;
- write(ls, os);
- PyObject* code = Py_CompileStringFlags(c_str(str(os)), c_str(path), Py_file_input, NULL);
- if (code == NULL)
- return mkfailure<PyObject*>(string("Couldn't compile script: ") + path + " : " + lastError());
- PyObject* mod = PyImport_ExecCodeModule(const_cast<char*>(c_str(path)), code);
- if (mod == NULL)
- return mkfailure<PyObject*>(string("Couldn't import module: ") + path + " : " + lastError());
- return mod;
-}
-
-/**
* Evaluate an expression against a script provided as a python object.
*/
const failable<value> evalScript(const value& expr, PyObject* script) {
@@ -266,6 +235,22 @@ const failable<value> evalScript(const value& expr, PyObject* script) {
}
/**
+ * Read a python script from an input stream.
+ */
+const failable<PyObject*> readScript(const string& path, istream& is) {
+ const list<string> ls = streamList(is);
+ ostringstream os;
+ write(ls, os);
+ PyObject* code = Py_CompileStringFlags(c_str(str(os)), c_str(path), Py_file_input, NULL);
+ if (code == NULL)
+ return mkfailure<PyObject*>(string("Couldn't compile script: ") + path + " : " + lastError());
+ PyObject* mod = PyImport_ExecCodeModule(const_cast<char*>(c_str(path)), code);
+ if (mod == NULL)
+ return mkfailure<PyObject*>(string("Couldn't import module: ") + path + " : " + lastError());
+ return mod;
+}
+
+/**
* Evaluate an expression against a script provided as an input stream.
*/
const failable<value> evalScript(const value& expr, istream& is) {
@@ -275,13 +260,6 @@ const failable<value> evalScript(const value& expr, istream& is) {
return evalScript(expr, content(script));
}
-/**
- * Evaluate an expression against the python builtin module, no script is provided.
- */
-const failable<value> evalExpr(const value& expr) {
- return evalScript(expr, builtin(pythonRuntime));
-}
-
}
}
-#endif /* tuscany_python_pyeval_hpp */
+#endif /* tuscany_python_eval_hpp */