summaryrefslogtreecommitdiffstats
path: root/cpp/sca/modules/eval/driver.hpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-09-27 20:03:58 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-09-27 20:03:58 +0000
commit49ba52239afa0e6ab295add695a7443633748cfc (patch)
tree6e1d2244ae2ebea2bcec28f77e446e5b3ee9b0eb /cpp/sca/modules/eval/driver.hpp
parent16e2ee1f1cacc9486f328ca7a3d7e2480b7e43db (diff)
Strawman implementation of a mini script evaluation library, which can be used for simple test case components without requiring integration with bigger and more complex 3rd party script engines like Ruby or Python. That way the core test cases should work without requiring the more complex Python or Ruby extensions to work.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@819393 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--cpp/sca/modules/eval/driver.hpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/cpp/sca/modules/eval/driver.hpp b/cpp/sca/modules/eval/driver.hpp
new file mode 100644
index 0000000000..c1b2e1e96f
--- /dev/null
+++ b/cpp/sca/modules/eval/driver.hpp
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+#ifndef tuscany_eval_driver_hpp
+#define tuscany_eval_driver_hpp
+
+/**
+ * Script evaluator main driver loop.
+ */
+
+#include <string>
+#include <iostream>
+#include "eval.hpp"
+
+namespace tuscany
+{
+
+const std::string evalOutputPrompt(";;; Eval value: ");
+const std::string evalInputPrompt(";;; Eval input: ");
+
+const bool promptForInput(std::ostream& out, const std::string str) {
+ out << "\n\n" << str << "\n";
+ return true;
+}
+
+const bool announceOutput(std::ostream& out, const std::string str) {
+ out << "\n" << str << "\n";
+ return true;
+}
+
+const bool userPrint(std::ostream& out, const value object) {
+ if(isCompoundProcedure(object))
+ out << makeList(compoundProcedureSymbol, value(procedureParameters(object)), value(procedureBody(object)), value(
+ "<procedure-env>"));
+ out << object;
+ return true;
+}
+
+const value evalDriverLoop(std::istream& in, std::ostream& out, Env& globalEnv) {
+ promptForInput(out, evalInputPrompt);
+ value input = read(in);
+ if (isNil(input))
+ return input;
+ const value output = eval(input, globalEnv);
+ announceOutput(out, evalOutputPrompt);
+ userPrint(out, output);
+ return evalDriverLoop(in, out, globalEnv);
+}
+
+const bool evalDriverRun(std::istream& in, std::ostream& out) {
+ setupEvalOut(out);
+ Env globalEnv = setupEnvironment();
+ evalDriverLoop(in, out, globalEnv);
+ return true;
+}
+
+}
+#endif /* tuscany_eval_driver_hpp */