Finish move to dispatchkit/chaiscript
This commit is contained in:
parent
4c08855f64
commit
e1727565e6
@ -1,8 +1,8 @@
|
||||
// This file is distributed under the BSD License.
|
||||
// See LICENSE.TXT for details.
|
||||
|
||||
#ifndef WESLEY_HPP_
|
||||
#define WESLEY_HPP_
|
||||
#ifndef CHAISCRIPT_HPP_
|
||||
#define CHAISCRIPT_HPP_
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
@ -35,7 +35,7 @@ const char *tokentype_to_string(int tokentype) {
|
||||
#include "langkit_lexer.hpp"
|
||||
#include "langkit_parser.hpp"
|
||||
|
||||
#include "wesley_eval.hpp"
|
||||
#include "wesley_engine.hpp"
|
||||
#include "chaiscript_eval.hpp"
|
||||
#include "chaiscript_engine.hpp"
|
||||
|
||||
#endif /* WESLEY_HPP_ */
|
||||
#endif /* CHAISCRIPT_HPP_ */
|
||||
|
@ -1,21 +1,21 @@
|
||||
// This file is distributed under the BSD License.
|
||||
// See LICENSE.TXT for details.
|
||||
|
||||
#ifndef WESLEY_ENGINE_HPP_
|
||||
#define WESLEY_ENGINE_HPP_
|
||||
#ifndef CHAISCRIPT_ENGINE_HPP_
|
||||
#define CHAISCRIPT_ENGINE_HPP_
|
||||
|
||||
#include <exception>
|
||||
|
||||
//A function that prints any string passed to it
|
||||
|
||||
template <typename Eval_Engine>
|
||||
class Wesley_System {
|
||||
class ChaiScript_System {
|
||||
Lexer lexer;
|
||||
Rule parser;
|
||||
Eval_Engine engine;
|
||||
|
||||
public:
|
||||
Wesley_System() : lexer(build_lexer()), parser(build_parser_rules()), engine(build_eval_system(lexer, parser)) {
|
||||
ChaiScript_System() : lexer(build_lexer()), parser(build_parser_rules()), engine(build_eval_system(lexer, parser)) {
|
||||
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ public:
|
||||
//dump_system(ss);
|
||||
|
||||
ss.register_function(boost::shared_ptr<Proxy_Function>(
|
||||
new Dynamic_Proxy_Function(boost::bind(&Wesley_System<Eval_Engine>::eval, boost::ref(*this), _1), 1)), "eval");
|
||||
new Dynamic_Proxy_Function(boost::bind(&ChaiScript_System<Eval_Engine>::eval, boost::ref(*this), _1), 1)), "eval");
|
||||
|
||||
evaluate_string("def print(x) { print_string(x.to_string()) } ");
|
||||
|
||||
@ -262,7 +262,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
typedef Wesley_System<Dispatch_Engine> Wesley_Engine;
|
||||
typedef ChaiScript_System<Dispatch_Engine> ChaiScript_Engine;
|
||||
|
||||
#endif /* WESLEY_ENGINE_HPP_ */
|
||||
#endif /* CHAISCRIPT_ENGINE_HPP_ */
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
// This file is distributed under the BSD License.
|
||||
// See LICENSE.TXT for details.
|
||||
|
||||
#ifndef WESLEY_EVAL_HPP_
|
||||
#define WESLEY_EVAL_HPP_
|
||||
#ifndef CHAISCRIPT_EVAL_HPP_
|
||||
#define CHAISCRIPT_EVAL_HPP_
|
||||
|
||||
#include <map>
|
||||
|
||||
@ -446,4 +446,4 @@ Boxed_Value eval_token(Eval_System &ss, TokenPtr node) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* WESLEY_EVAL_HPP_ */
|
||||
#endif /* CHAISCRIPT_EVAL_HPP_ */
|
||||
|
@ -1,11 +1,11 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "wesley.hpp"
|
||||
#include "chaiscript.hpp"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
std::string input;
|
||||
|
||||
Wesley_Engine we;
|
||||
ChaiScript_Engine chai;
|
||||
|
||||
if (argc < 2) {
|
||||
std::cout << "eval> ";
|
||||
@ -13,13 +13,13 @@ int main(int argc, char *argv[]) {
|
||||
while (input != "quit") {
|
||||
Boxed_Value val;
|
||||
|
||||
val = we.evaluate_string(input);
|
||||
val = chai.evaluate_string(input);
|
||||
|
||||
if (val.get_type_info().m_bare_type_info && *(val.get_type_info().m_bare_type_info) != typeid(void)) {
|
||||
try {
|
||||
Boxed_Value printeval = dispatch(we.get_eval_engine().get_function("to_string"), Param_List_Builder() << val);
|
||||
Boxed_Value printeval = dispatch(chai.get_eval_engine().get_function("to_string"), Param_List_Builder() << val);
|
||||
std::cout << "result: ";
|
||||
dispatch(we.get_eval_engine().get_function("print"), Param_List_Builder() << printeval);
|
||||
dispatch(chai.get_eval_engine().get_function("print"), Param_List_Builder() << printeval);
|
||||
} catch (const std::runtime_error &e) {
|
||||
std::cout << "result: object #" << &val << std::endl;
|
||||
}
|
||||
@ -31,7 +31,7 @@ int main(int argc, char *argv[]) {
|
||||
else {
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
try {
|
||||
Boxed_Value val = we.evaluate_file(argv[i]);
|
||||
Boxed_Value val = chai.evaluate_file(argv[i]);
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
std::cerr << "Could not open: " << argv[i] << std::endl;
|
||||
|
@ -12,12 +12,12 @@ if(Boost_FOUND)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
include_directories(.)
|
||||
|
||||
add_executable(boxedcpp_test test.cpp)
|
||||
add_executable(dispatchkit_test test.cpp)
|
||||
|
||||
add_executable(boxedcpp_unittest unittest.cpp)
|
||||
add_executable(dispatchkit_unittest unittest.cpp)
|
||||
|
||||
target_link_libraries(boxedcpp_unittest ${Boost_LIBRARIES})
|
||||
target_link_libraries(dispatchkit_unittest ${Boost_LIBRARIES})
|
||||
|
||||
endif()
|
||||
|
||||
add_test(boxedcpp_unittest boxedcpp_unittest)
|
||||
add_test(dispatchkit_unittest dispatchkit_unittest)
|
||||
|
Loading…
x
Reference in New Issue
Block a user