OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PyScheme.cc
Go to the documentation of this file.
1 /*
2  * opencog/cython/PyScheme.cc
3  *
4  * Copyright (C) 2013 by OpenCog Foundation
5  * All Rights Reserved
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License v3 as
9  * published by the Free Software Foundation and including the exceptions
10  * at http://opencog.org/wiki/Licenses
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program; if not, write to:
19  * Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 #include "PyScheme.h"
23 
26 
27 using std::string;
28 
29 using namespace opencog;
30 
31 #ifdef HAVE_GUILE
32 
33 static void check_err(SchemeEval* evaluator, const std::string &s)
34 {
35  if (evaluator->eval_error()) {
36  throw RuntimeException(TRACE_INFO,
37  "Scheme: Failed to execute '%s'", s.c_str());
38  }
39 
40  if (evaluator->input_pending()) {
41  throw RuntimeException(TRACE_INFO,
42  "Scheme: Syntax error in input: '%s'", s.c_str());
43  }
44 }
45 #endif // HAVE_GUILE
46 
47 // Convenience wrapper, for stand-alone usage.
48 std::string opencog::eval_scheme(AtomSpace& as, const std::string &s)
49 {
50 #ifdef HAVE_GUILE
51  SchemeEval* evaluator = SchemeEval::get_evaluator(&as);
52  std::string scheme_return_value = evaluator->eval(s);
53  check_err(evaluator, s);
54  return scheme_return_value;
55 #else // HAVE_GUILE
56  return "Error: Compiled without Guile support";
57 #endif // HAVE_GUILE
58 }
59 
60 // Convenience wrapper, for stand-alone usage.
61 Handle opencog::eval_scheme_h(AtomSpace& as, const std::string &s)
62 {
63 #ifdef HAVE_GUILE
64  SchemeEval* evaluator = SchemeEval::get_evaluator(&as);
65  Handle scheme_return_value = evaluator->eval_h(s);
66  check_err(evaluator, s);
67  return scheme_return_value;
68 #else // HAVE_GUILE
69  return "Error: Compiled without Guile support";
70 #endif // HAVE_GUILE
71 }
std::string eval(const std::string &expr)
Definition: SchemeEval.h:155
virtual bool eval_error(void)
Definition: GenericEval.h:75
static SchemeEval * get_evaluator(AtomSpace *=NULL)
Definition: SchemeEval.cc:1135
Handle eval_h(const std::string &)
Definition: SchemeEval.cc:858
static void check_err(SchemeEval *evaluator, const std::string &s)
Definition: PyScheme.cc:33
virtual bool input_pending()
Definition: GenericEval.h:57
Handle eval_scheme_h(AtomSpace &as, const std::string &s)
Definition: PyScheme.cc:61
std::string eval_scheme(AtomSpace &as, const std::string &s)
Definition: PyScheme.cc:48