Minor cleanup, removed unnecessary references to GC pools.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@896327 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
60ef14f12b
commit
3a0eb8a5f2
12 changed files with 96 additions and 98 deletions
|
|
@ -52,30 +52,30 @@ const bool userPrint(const value val, ostream& out) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const value evalDriverLoop(PyObject* script, istream& in, ostream& out, const gc_pool& pool) {
|
const value evalDriverLoop(PyObject* script, istream& in, ostream& out) {
|
||||||
promptForInput(evalInputPrompt, out);
|
promptForInput(evalInputPrompt, out);
|
||||||
value input = readValue(in);
|
value input = readValue(in);
|
||||||
if (isNil(input))
|
if (isNil(input))
|
||||||
return input;
|
return input;
|
||||||
const value output = evalScript(input, script, pool);
|
const value output = evalScript(input, script);
|
||||||
announceOutput(evalOutputPrompt, out);
|
announceOutput(evalOutputPrompt, out);
|
||||||
userPrint(output, out);
|
userPrint(output, out);
|
||||||
return evalDriverLoop(script, in, out, pool);
|
return evalDriverLoop(script, in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool evalDriverRun(istream& in, ostream& out, const gc_pool& pool) {
|
const bool evalDriverRun(istream& in, ostream& out) {
|
||||||
setupDisplay(out);
|
setupDisplay(out);
|
||||||
evalDriverLoop(builtin(pythonRuntime), in, out, pool);
|
evalDriverLoop(builtin(pythonRuntime), in, out);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool evalDriverRun(const char* path, istream& in, ostream& out, const gc_pool& pool) {
|
const bool evalDriverRun(const char* path, istream& in, ostream& out) {
|
||||||
setupDisplay(out);
|
setupDisplay(out);
|
||||||
ifstream is(path);
|
ifstream is(path);
|
||||||
failable<PyObject*> script = readScript(path, is);
|
failable<PyObject*> script = readScript(path, is);
|
||||||
if (!hasContent(script))
|
if (!hasContent(script))
|
||||||
return true;
|
return true;
|
||||||
evalDriverLoop(content(script), in, out, pool);
|
evalDriverLoop(content(script), in, out);
|
||||||
Py_DECREF(content(script));
|
Py_DECREF(content(script));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,7 @@ const failable<PyObject*> readScript(const string& path, istream& is) {
|
||||||
/**
|
/**
|
||||||
* Evaluate an expression against a script provided as a python object.
|
* Evaluate an expression against a script provided as a python object.
|
||||||
*/
|
*/
|
||||||
const failable<value> evalScript(const value& expr, PyObject* script, unused const gc_pool& pool) {
|
const failable<value> evalScript(const value& expr, PyObject* script) {
|
||||||
|
|
||||||
// Get the requested function
|
// Get the requested function
|
||||||
PyObject* func = PyObject_GetAttrString(script, c_str(car<value>(expr)));
|
PyObject* func = PyObject_GetAttrString(script, c_str(car<value>(expr)));
|
||||||
|
|
@ -268,18 +268,18 @@ const failable<value> evalScript(const value& expr, PyObject* script, unused con
|
||||||
/**
|
/**
|
||||||
* Evaluate an expression against a script provided as an input stream.
|
* Evaluate an expression against a script provided as an input stream.
|
||||||
*/
|
*/
|
||||||
const failable<value> evalScript(const value& expr, istream& is, unused const gc_pool& pool) {
|
const failable<value> evalScript(const value& expr, istream& is) {
|
||||||
failable<PyObject*> script = readScript("script", is);
|
failable<PyObject*> script = readScript("script", is);
|
||||||
if (!hasContent(script))
|
if (!hasContent(script))
|
||||||
return mkfailure<value>(reason(script));
|
return mkfailure<value>(reason(script));
|
||||||
return evalScript(expr, content(script), pool);
|
return evalScript(expr, content(script));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate an expression against the python builtin module, no script is provided.
|
* Evaluate an expression against the python builtin module, no script is provided.
|
||||||
*/
|
*/
|
||||||
const failable<value> evalExpr(const value& expr, const gc_pool& pool) {
|
const failable<value> evalExpr(const value& expr) {
|
||||||
return evalScript(expr, builtin(pythonRuntime), pool);
|
return evalScript(expr, builtin(pythonRuntime));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,9 @@
|
||||||
int main(const int argc, char** argv) {
|
int main(const int argc, char** argv) {
|
||||||
tuscany::gc_scoped_pool pool;
|
tuscany::gc_scoped_pool pool;
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
tuscany::python::evalDriverRun(tuscany::cin, tuscany::cout, pool);
|
tuscany::python::evalDriverRun(tuscany::cin, tuscany::cout);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
tuscany::python::evalDriverRun(argv[1], tuscany::cin, tuscany::cout, pool);
|
tuscany::python::evalDriverRun(argv[1], tuscany::cin, tuscany::cout);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@
|
||||||
namespace tuscany {
|
namespace tuscany {
|
||||||
namespace python {
|
namespace python {
|
||||||
|
|
||||||
const value evalBuiltin(const string& py, const gc_pool& pool) {
|
const value evalBuiltin(const string& py) {
|
||||||
istringstream is(py);
|
istringstream is(py);
|
||||||
ostringstream os;
|
ostringstream os;
|
||||||
evalDriverRun(is, os, pool);
|
evalDriverRun(is, os);
|
||||||
return str(os);
|
return str(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ const string testPythonPrint(
|
||||||
|
|
||||||
bool testEval() {
|
bool testEval() {
|
||||||
gc_scoped_pool pool;
|
gc_scoped_pool pool;
|
||||||
assert(contains(evalBuiltin(testPythonPrint, pool), "testPrint ok"));
|
assert(contains(evalBuiltin(testPythonPrint), "testPrint ok"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,7 +55,7 @@ bool testEvalExpr() {
|
||||||
gc_scoped_pool pool;
|
gc_scoped_pool pool;
|
||||||
{
|
{
|
||||||
const value exp = mklist<value>("abs", -5);
|
const value exp = mklist<value>("abs", -5);
|
||||||
const failable<value> r = evalExpr(exp, pool);
|
const failable<value> r = evalExpr(exp);
|
||||||
assert(hasContent(r));
|
assert(hasContent(r));
|
||||||
assert(content(r) == value(5));
|
assert(content(r) == value(5));
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +64,7 @@ bool testEvalExpr() {
|
||||||
failable<PyObject*> script = readScript("script", is);
|
failable<PyObject*> script = readScript("script", is);
|
||||||
assert(hasContent(script));
|
assert(hasContent(script));
|
||||||
const value exp = mklist<value>("add", 2, 3);
|
const value exp = mklist<value>("add", 2, 3);
|
||||||
const failable<value> r = evalScript(exp, content(script), pool);
|
const failable<value> r = evalScript(exp, content(script));
|
||||||
assert(hasContent(r));
|
assert(hasContent(r));
|
||||||
assert(content(r) == value(5));
|
assert(content(r) == value(5));
|
||||||
}
|
}
|
||||||
|
|
@ -73,7 +73,7 @@ bool testEvalExpr() {
|
||||||
|
|
||||||
bool testEvalRun() {
|
bool testEvalRun() {
|
||||||
gc_scoped_pool pool;
|
gc_scoped_pool pool;
|
||||||
evalDriverRun(cin, cout, pool);
|
evalDriverRun(cin, cout);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,7 +99,7 @@ bool testEvalLambda() {
|
||||||
|
|
||||||
const value trl = mklist<value>("testReturnLambda");
|
const value trl = mklist<value>("testReturnLambda");
|
||||||
istringstream trlis(testReturnLambda);
|
istringstream trlis(testReturnLambda);
|
||||||
const failable<value> trlv = evalScript(trl, trlis, pool);
|
const failable<value> trlv = evalScript(trl, trlis);
|
||||||
|
|
||||||
assert(hasContent(trlv));
|
assert(hasContent(trlv));
|
||||||
assert(isLambda(content(trlv)));
|
assert(isLambda(content(trlv)));
|
||||||
|
|
@ -108,13 +108,13 @@ bool testEvalLambda() {
|
||||||
|
|
||||||
istringstream tclis(testCallLambda);
|
istringstream tclis(testCallLambda);
|
||||||
const value tcl = mklist<value>("testCallLambda", content(trlv), 2, 3);
|
const value tcl = mklist<value>("testCallLambda", content(trlv), 2, 3);
|
||||||
const failable<value> tclv = evalScript(tcl, tclis, pool);
|
const failable<value> tclv = evalScript(tcl, tclis);
|
||||||
assert(hasContent(tclv));
|
assert(hasContent(tclv));
|
||||||
assert(content(tclv) == value(6));
|
assert(content(tclv) == value(6));
|
||||||
|
|
||||||
istringstream tcelis(testCallLambda);
|
istringstream tcelis(testCallLambda);
|
||||||
const value tcel = mklist<value>("testCallLambda", lambda<value(const list<value>&)>(mult), 3, 4);
|
const value tcel = mklist<value>("testCallLambda", lambda<value(const list<value>&)>(mult), 3, 4);
|
||||||
const failable<value> tcelv = evalScript(tcel, tcelis, pool);
|
const failable<value> tcelv = evalScript(tcel, tcelis);
|
||||||
assert(hasContent(tcelv));
|
assert(hasContent(tcelv));
|
||||||
assert(content(tcelv) == value(12));
|
assert(content(tcelv) == value(12));
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -53,21 +53,21 @@ const bool userPrint(const value val, ostream& out) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const value evalDriverLoop(istream& in, ostream& out, Env& env, const gc_pool& pool) {
|
const value evalDriverLoop(istream& in, ostream& out, Env& env) {
|
||||||
promptForInput(evalInputPrompt, out);
|
promptForInput(evalInputPrompt, out);
|
||||||
value input = readValue(in);
|
value input = readValue(in);
|
||||||
if (isNil(input))
|
if (isNil(input))
|
||||||
return input;
|
return input;
|
||||||
const value output = evalExpr(input, env, pool);
|
const value output = evalExpr(input, env);
|
||||||
announceOutput(evalOutputPrompt, out);
|
announceOutput(evalOutputPrompt, out);
|
||||||
userPrint(output, out);
|
userPrint(output, out);
|
||||||
return evalDriverLoop(in, out, env, pool);
|
return evalDriverLoop(in, out, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool evalDriverRun(istream& in, ostream& out, const gc_pool& pool) {
|
const bool evalDriverRun(istream& in, ostream& out) {
|
||||||
setupDisplay(out);
|
setupDisplay(out);
|
||||||
Env globalEnv = setupEnvironment(pool);
|
Env env = setupEnvironment();
|
||||||
evalDriverLoop(in, out, globalEnv, pool);
|
evalDriverLoop(in, out, env);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,8 +102,8 @@ const Frame makeBinding(const Frame& frameSoFar, const list<value>& variables, c
|
||||||
return makeBinding(newFrame, cdr(variables), cdr(values));
|
return makeBinding(newFrame, cdr(variables), cdr(values));
|
||||||
}
|
}
|
||||||
|
|
||||||
const gc_ptr<Frame> makeFrame(const list<value>& variables, const list<value> values, const gc_pool& pool) {
|
const gc_ptr<Frame> makeFrame(const list<value>& variables, const list<value> values) {
|
||||||
gc_ptr<Frame> frame = new (gc_new<Frame>(pool)) Frame();
|
gc_ptr<Frame> frame = new (gc_new<Frame>()) Frame();
|
||||||
*frame = value(makeBinding(cons(value(list<value>()), list<value>()), variables, values));
|
*frame = value(makeBinding(cons(value(list<value>()), list<value>()), variables, values));
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
@ -141,12 +141,12 @@ const bool defineVariable(const value& var, const value& val, Env& env) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Env extendEnvironment(const list<value>& vars, const list<value>& vals, const Env& baseEnv, const gc_pool& pool) {
|
const Env extendEnvironment(const list<value>& vars, const list<value>& vals, const Env& baseEnv) {
|
||||||
return cons<value>(makeFrame(vars, vals, pool), baseEnv);
|
return cons<value>(makeFrame(vars, vals), baseEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Env setupEnvironment(const gc_pool& pool) {
|
const Env setupEnvironment() {
|
||||||
Env env = extendEnvironment(primitiveProcedureNames(), primitiveProcedureObjects(), theEmptyEnvironment(), pool);
|
Env env = extendEnvironment(primitiveProcedureNames(), primitiveProcedureObjects(), theEmptyEnvironment());
|
||||||
defineVariable(trueSymbol, true, env);
|
defineVariable(trueSymbol, true, env);
|
||||||
defineVariable(falseSymbol, false, env);
|
defineVariable(falseSymbol, false, env);
|
||||||
return env;
|
return env;
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,6 @@
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
tuscany::gc_scoped_pool pool;
|
tuscany::gc_scoped_pool pool;
|
||||||
tuscany::scheme::evalDriverRun(tuscany::cin, tuscany::cout, pool);
|
tuscany::scheme::evalDriverRun(tuscany::cin, tuscany::cout);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ namespace scheme {
|
||||||
bool testEnv() {
|
bool testEnv() {
|
||||||
gc_scoped_pool pool;
|
gc_scoped_pool pool;
|
||||||
Env globalEnv = list<value>();
|
Env globalEnv = list<value>();
|
||||||
Env env = extendEnvironment(mklist<value>("a"), mklist<value>(1), globalEnv, pool);
|
Env env = extendEnvironment(mklist<value>("a"), mklist<value>(1), globalEnv);
|
||||||
defineVariable("x", env, env);
|
defineVariable("x", env, env);
|
||||||
assert(lookupVariableValue(value("x"), env) == env);
|
assert(lookupVariableValue(value("x"), env) == env);
|
||||||
assert(lookupVariableValue("a", env) == value(1));
|
assert(lookupVariableValue("a", env) == value(1));
|
||||||
|
|
@ -130,39 +130,39 @@ const string testSchemeForward(
|
||||||
"(define sqrt (lambda (x) (* x x))) "
|
"(define sqrt (lambda (x) (* x x))) "
|
||||||
"(testLambda)");
|
"(testLambda)");
|
||||||
|
|
||||||
const string evalOutput(const string& scm, const gc_pool& pool) {
|
const string evalOutput(const string& scm) {
|
||||||
istringstream is(scm);
|
istringstream is(scm);
|
||||||
ostringstream os;
|
ostringstream os;
|
||||||
evalDriverRun(is, os, pool);
|
evalDriverRun(is, os);
|
||||||
return str(os);
|
return str(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testEval() {
|
bool testEval() {
|
||||||
gc_scoped_pool pool;
|
gc_scoped_pool pool;
|
||||||
assert(contains(evalOutput(testSchemeNumber, pool), "testNumber ok"));
|
assert(contains(evalOutput(testSchemeNumber), "testNumber ok"));
|
||||||
assert(contains(evalOutput(testSchemeString, pool), "testString ok"));
|
assert(contains(evalOutput(testSchemeString), "testString ok"));
|
||||||
assert(contains(evalOutput(testSchemeDefinition, pool), "testDefinition ok"));
|
assert(contains(evalOutput(testSchemeDefinition), "testDefinition ok"));
|
||||||
assert(contains(evalOutput(testSchemeIf, pool), "testIf ok"));
|
assert(contains(evalOutput(testSchemeIf), "testIf ok"));
|
||||||
assert(contains(evalOutput(testSchemeCond, pool), "testCond ok"));
|
assert(contains(evalOutput(testSchemeCond), "testCond ok"));
|
||||||
assert(contains(evalOutput(testSchemeBegin, pool), "testBegin1 ok"));
|
assert(contains(evalOutput(testSchemeBegin), "testBegin1 ok"));
|
||||||
assert(contains(evalOutput(testSchemeBegin, pool), "testBegin2 ok"));
|
assert(contains(evalOutput(testSchemeBegin), "testBegin2 ok"));
|
||||||
assert(contains(evalOutput(testSchemeLambda, pool), "testLambda ok"));
|
assert(contains(evalOutput(testSchemeLambda), "testLambda ok"));
|
||||||
assert(contains(evalOutput(testSchemeForward, pool), "testForward ok"));
|
assert(contains(evalOutput(testSchemeForward), "testForward ok"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testEvalExpr() {
|
bool testEvalExpr() {
|
||||||
gc_scoped_pool pool;
|
gc_scoped_pool pool;
|
||||||
const value exp = mklist<value>("+", 2, 3);
|
const value exp = mklist<value>("+", 2, 3);
|
||||||
Env env = setupEnvironment(pool);
|
Env env = setupEnvironment();
|
||||||
const value r = evalExpr(exp, env, pool);
|
const value r = evalExpr(exp, env);
|
||||||
assert(r == value(5));
|
assert(r == value(5));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testEvalRun() {
|
bool testEvalRun() {
|
||||||
gc_scoped_pool pool;
|
gc_scoped_pool pool;
|
||||||
evalDriverRun(cin, cout, pool);
|
evalDriverRun(cin, cout);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,20 +180,20 @@ const string testCallLambda(
|
||||||
|
|
||||||
bool testEvalLambda() {
|
bool testEvalLambda() {
|
||||||
gc_scoped_pool pool;
|
gc_scoped_pool pool;
|
||||||
Env env = setupEnvironment(pool);
|
Env env = setupEnvironment();
|
||||||
|
|
||||||
const value trl = mklist<value>("testReturnLambda");
|
const value trl = mklist<value>("testReturnLambda");
|
||||||
istringstream trlis(testReturnLambda);
|
istringstream trlis(testReturnLambda);
|
||||||
const value trlv = evalScript(trl, trlis, env, pool);
|
const value trlv = evalScript(trl, trlis, env);
|
||||||
|
|
||||||
istringstream tclis(testCallLambda);
|
istringstream tclis(testCallLambda);
|
||||||
const value tcl = cons<value>("testCallLambda", quotedParameters(mklist<value>(trlv, 2, 3)));
|
const value tcl = cons<value>("testCallLambda", quotedParameters(mklist<value>(trlv, 2, 3)));
|
||||||
const value tclv = evalScript(tcl, tclis, env, pool);
|
const value tclv = evalScript(tcl, tclis, env);
|
||||||
assert(tclv == value(6));
|
assert(tclv == value(6));
|
||||||
|
|
||||||
istringstream tcelis(testCallLambda);
|
istringstream tcelis(testCallLambda);
|
||||||
const value tcel = cons<value>("testCallLambda", quotedParameters(mklist<value>(primitiveProcedure(mult), 3, 4)));
|
const value tcel = cons<value>("testCallLambda", quotedParameters(mklist<value>(primitiveProcedure(mult), 3, 4)));
|
||||||
const value tcelv = evalScript(tcel, tcelis, env, pool);
|
const value tcelv = evalScript(tcel, tcelis, env);
|
||||||
assert(tcelv == value(12));
|
assert(tcelv == value(12));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@
|
||||||
namespace tuscany {
|
namespace tuscany {
|
||||||
namespace scheme {
|
namespace scheme {
|
||||||
|
|
||||||
const value evalExpr(const value& exp, Env& env, const gc_pool& pool);
|
const value evalExpr(const value& exp, Env& env);
|
||||||
|
|
||||||
const value compoundProcedureSymbol("compound-procedure");
|
const value compoundProcedureSymbol("compound-procedure");
|
||||||
const value procedureSymbol("procedure");
|
const value procedureSymbol("procedure");
|
||||||
|
|
@ -86,10 +86,10 @@ const list<value> operands(const value& exp) {
|
||||||
return cdr((list<value> )exp);
|
return cdr((list<value> )exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
const list<value> listOfValues(const list<value> exps, Env& env, const gc_pool& pool) {
|
const list<value> listOfValues(const list<value> exps, Env& env) {
|
||||||
if(isNil(exps))
|
if(isNil(exps))
|
||||||
return list<value> ();
|
return list<value> ();
|
||||||
return cons(evalExpr(car(exps), env, pool), listOfValues(cdr(exps), env, pool));
|
return cons(evalExpr(car(exps), env), listOfValues(cdr(exps), env));
|
||||||
}
|
}
|
||||||
|
|
||||||
const value applyOperat(const value& exp) {
|
const value applyOperat(const value& exp) {
|
||||||
|
|
@ -132,19 +132,19 @@ const value makeBegin(const list<value> seq) {
|
||||||
return cons(beginSymbol, seq);
|
return cons(beginSymbol, seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
const value evalSequence(const list<value>& exps, Env& env, const gc_pool& pool) {
|
const value evalSequence(const list<value>& exps, Env& env) {
|
||||||
if(isLastExp(exps))
|
if(isLastExp(exps))
|
||||||
return evalExpr(firstExp(exps), env, pool);
|
return evalExpr(firstExp(exps), env);
|
||||||
evalExpr(firstExp(exps), env, pool);
|
evalExpr(firstExp(exps), env);
|
||||||
return evalSequence(restExp(exps), env, pool);
|
return evalSequence(restExp(exps), env);
|
||||||
}
|
}
|
||||||
|
|
||||||
const value applyProcedure(const value& procedure, list<value>& arguments, const gc_pool& pool) {
|
const value applyProcedure(const value& procedure, list<value>& arguments) {
|
||||||
if(isPrimitiveProcedure(procedure))
|
if(isPrimitiveProcedure(procedure))
|
||||||
return applyPrimitiveProcedure(procedure, arguments);
|
return applyPrimitiveProcedure(procedure, arguments);
|
||||||
if(isCompoundProcedure(procedure)) {
|
if(isCompoundProcedure(procedure)) {
|
||||||
Env env = extendEnvironment(procedureParameters(procedure), arguments, procedureEnvironment(procedure), pool);
|
Env env = extendEnvironment(procedureParameters(procedure), arguments, procedureEnvironment(procedure));
|
||||||
return evalSequence(procedureBody(procedure), env, pool);
|
return evalSequence(procedureBody(procedure), env);
|
||||||
}
|
}
|
||||||
logStream() << "Unknown procedure type " << procedure << endl;
|
logStream() << "Unknown procedure type " << procedure << endl;
|
||||||
return value();
|
return value();
|
||||||
|
|
@ -218,41 +218,41 @@ value condToIf(const value& exp) {
|
||||||
return expandClauses(condClauses(exp));
|
return expandClauses(condClauses(exp));
|
||||||
}
|
}
|
||||||
|
|
||||||
value evalIf(const value& exp, Env& env, const gc_pool& pool) {
|
value evalIf(const value& exp, Env& env) {
|
||||||
if(isTrue(evalExpr(ifPredicate(exp), env, pool)))
|
if(isTrue(evalExpr(ifPredicate(exp), env)))
|
||||||
return evalExpr(ifConsequent(exp), env, pool);
|
return evalExpr(ifConsequent(exp), env);
|
||||||
return evalExpr(ifAlternative(exp), env, pool);
|
return evalExpr(ifAlternative(exp), env);
|
||||||
}
|
}
|
||||||
|
|
||||||
const value evalDefinition(const value& exp, Env& env, const gc_pool& pool) {
|
const value evalDefinition(const value& exp, Env& env) {
|
||||||
defineVariable(definitionVariable(exp), evalExpr(definitionValue(exp), env, pool), env);
|
defineVariable(definitionVariable(exp), evalExpr(definitionValue(exp), env), env);
|
||||||
return definitionVariable(exp);
|
return definitionVariable(exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
const value evalExpr(const value& exp, Env& env, const gc_pool& pool) {
|
const value evalExpr(const value& exp, Env& env) {
|
||||||
if(isSelfEvaluating(exp))
|
if(isSelfEvaluating(exp))
|
||||||
return exp;
|
return exp;
|
||||||
if(isQuoted(exp))
|
if(isQuoted(exp))
|
||||||
return textOfQuotation(exp);
|
return textOfQuotation(exp);
|
||||||
if(isDefinition(exp))
|
if(isDefinition(exp))
|
||||||
return evalDefinition(exp, env, pool);
|
return evalDefinition(exp, env);
|
||||||
if(isIf(exp))
|
if(isIf(exp))
|
||||||
return evalIf(exp, env, pool);
|
return evalIf(exp, env);
|
||||||
if(isBegin(exp))
|
if(isBegin(exp))
|
||||||
return evalSequence(beginActions(exp), env, pool);
|
return evalSequence(beginActions(exp), env);
|
||||||
if(isCond(exp))
|
if(isCond(exp))
|
||||||
return evalExpr(condToIf(exp), env, pool);
|
return evalExpr(condToIf(exp), env);
|
||||||
if(isLambdaExpr(exp))
|
if(isLambdaExpr(exp))
|
||||||
return makeProcedure(lambdaParameters(exp), lambdaBody(exp), env);
|
return makeProcedure(lambdaParameters(exp), lambdaBody(exp), env);
|
||||||
if(isVariable(exp))
|
if(isVariable(exp))
|
||||||
return lookupVariableValue(exp, env);
|
return lookupVariableValue(exp, env);
|
||||||
if(isApply(exp)) {
|
if(isApply(exp)) {
|
||||||
list<value> applyOperandValues = evalExpr(applyOperand(exp), env, pool);
|
list<value> applyOperandValues = evalExpr(applyOperand(exp), env);
|
||||||
return applyProcedure(evalExpr(applyOperat(exp), env, pool), applyOperandValues, pool);
|
return applyProcedure(evalExpr(applyOperat(exp), env), applyOperandValues);
|
||||||
}
|
}
|
||||||
if(isApplication(exp)) {
|
if(isApplication(exp)) {
|
||||||
list<value> operandValues = listOfValues(operands(exp), env, pool);
|
list<value> operandValues = listOfValues(operands(exp), env);
|
||||||
return applyProcedure(evalExpr(operat(exp), env, pool), operandValues, pool);
|
return applyProcedure(evalExpr(operat(exp), env), operandValues);
|
||||||
}
|
}
|
||||||
logStream() << "Unknown expression type " << exp << endl;
|
logStream() << "Unknown expression type " << exp << endl;
|
||||||
return value();
|
return value();
|
||||||
|
|
@ -267,22 +267,22 @@ const list<value> quotedParameters(const list<value>& p) {
|
||||||
/**
|
/**
|
||||||
* Evaluate an expression against a script provided as a list of values.
|
* Evaluate an expression against a script provided as a list of values.
|
||||||
*/
|
*/
|
||||||
const value evalScriptLoop(const value& expr, const list<value>& script, scheme::Env& env, const gc_pool& pool) {
|
const value evalScriptLoop(const value& expr, const list<value>& script, scheme::Env& env) {
|
||||||
if (isNil(script))
|
if (isNil(script))
|
||||||
return scheme::evalExpr(expr, env, pool);
|
return scheme::evalExpr(expr, env);
|
||||||
scheme::evalExpr(car(script), env, pool);
|
scheme::evalExpr(car(script), env);
|
||||||
return evalScriptLoop(expr, cdr(script), env, pool);
|
return evalScriptLoop(expr, cdr(script), env);
|
||||||
}
|
}
|
||||||
|
|
||||||
const value evalScript(const value& expr, const value& script, Env& env, const gc_pool& pool) {
|
const value evalScript(const value& expr, const value& script, Env& env) {
|
||||||
return evalScriptLoop(expr, script, env, pool);
|
return evalScriptLoop(expr, script, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate an expression against a script provided as an input stream.
|
* Evaluate an expression against a script provided as an input stream.
|
||||||
*/
|
*/
|
||||||
const value evalScript(const value& expr, istream& is, Env& env, const gc_pool& pool) {
|
const value evalScript(const value& expr, istream& is, Env& env) {
|
||||||
return evalScript(expr, readScript(is), env, pool);
|
return evalScript(expr, readScript(is), env);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,7 @@ struct evalImplementation {
|
||||||
const value operator()(const list<value>& params) const {
|
const value operator()(const list<value>& params) const {
|
||||||
const value expr = append<value>(params, px);
|
const value expr = append<value>(params, px);
|
||||||
debug(expr, "modeval::python::evalImplementation::input");
|
debug(expr, "modeval::python::evalImplementation::input");
|
||||||
gc_pool pool(gc_current_pool());
|
const failable<value> val = python::evalScript(expr, impl);
|
||||||
const failable<value> val = python::evalScript(expr, impl, pool);
|
|
||||||
debug(val, "modeval::python::evalImplementation::result");
|
debug(val, "modeval::python::evalImplementation::result");
|
||||||
if (!hasContent(val))
|
if (!hasContent(val))
|
||||||
return mklist<value>(value(), reason(val));
|
return mklist<value>(value(), reason(val));
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,8 @@ struct evalImplementation {
|
||||||
const value operator()(const list<value>& params) const {
|
const value operator()(const list<value>& params) const {
|
||||||
const value expr = cons<value>(car(params), append(scheme::quotedParameters(cdr(params)), px));
|
const value expr = cons<value>(car(params), append(scheme::quotedParameters(cdr(params)), px));
|
||||||
debug(expr, "modeval::scheme::evalImplementation::input");
|
debug(expr, "modeval::scheme::evalImplementation::input");
|
||||||
gc_pool pool(gc_current_pool());
|
scheme::Env env = scheme::setupEnvironment();
|
||||||
scheme::Env globalEnv = scheme::setupEnvironment(pool);
|
const value val = scheme::evalScript(expr, impl, env);
|
||||||
const value val = scheme::evalScript(expr, impl, globalEnv, pool);
|
|
||||||
debug(val, "modeval::scheme::evalImplementation::result");
|
debug(val, "modeval::scheme::evalImplementation::result");
|
||||||
if (isNil(val))
|
if (isNil(val))
|
||||||
return mklist<value>(value(), string("Could not evaluate expression"));
|
return mklist<value>(value(), string("Could not evaluate expression"));
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ bool testScript() {
|
||||||
|
|
||||||
ifstream is("store-script-test.scm");
|
ifstream is("store-script-test.scm");
|
||||||
ostringstream os;
|
ostringstream os;
|
||||||
scheme::evalDriverRun(is, os, pool);
|
scheme::evalDriverRun(is, os);
|
||||||
assert(contains(str(os), "(\"Sample Feed\" \""));
|
assert(contains(str(os), "(\"Sample Feed\" \""));
|
||||||
assert(contains(str(os), "\" (\"Item\" \""));
|
assert(contains(str(os), "\" (\"Item\" \""));
|
||||||
assert(contains(str(os), "\" ((javaClass \"services.Item\") (name \"Orange\") (currencyCode \"USD\") (currencySymbol \"$\") (price 3.55))) (\"Item\" \""));
|
assert(contains(str(os), "\" ((javaClass \"services.Item\") (name \"Orange\") (currencyCode \"USD\") (currencySymbol \"$\") (price 3.55))) (\"Item\" \""));
|
||||||
|
|
@ -55,9 +55,9 @@ bool testEval() {
|
||||||
ifstream is("store-script-test.scm");
|
ifstream is("store-script-test.scm");
|
||||||
ostringstream os;
|
ostringstream os;
|
||||||
scheme::setupDisplay(os);
|
scheme::setupDisplay(os);
|
||||||
scheme::Env globalEnv = scheme::setupEnvironment(pool);
|
scheme::Env globalEnv = scheme::setupEnvironment();
|
||||||
const value exp(mklist<value>("storeui_service", string("getcatalog")));
|
const value exp(mklist<value>("storeui_service", string("getcatalog")));
|
||||||
const value val = scheme::evalScript(exp, is, globalEnv, pool);
|
const value val = scheme::evalScript(exp, is, globalEnv);
|
||||||
|
|
||||||
ostringstream vs;
|
ostringstream vs;
|
||||||
vs << val;
|
vs << val;
|
||||||
|
|
@ -70,9 +70,9 @@ bool testEval() {
|
||||||
ostringstream os;
|
ostringstream os;
|
||||||
scheme::setupDisplay(os);
|
scheme::setupDisplay(os);
|
||||||
|
|
||||||
scheme::Env globalEnv = scheme::setupEnvironment(pool);
|
scheme::Env globalEnv = scheme::setupEnvironment();
|
||||||
const value exp(mklist<value>("storeui_service", string("gettotal")));
|
const value exp(mklist<value>("storeui_service", string("gettotal")));
|
||||||
const value res = scheme::evalScript(exp, is, globalEnv, pool);
|
const value res = scheme::evalScript(exp, is, globalEnv);
|
||||||
|
|
||||||
ostringstream rs;
|
ostringstream rs;
|
||||||
rs << res;
|
rs << res;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue