mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-02-16 23:29:58 +08:00
Add namespace dispatchkit
This commit is contained in:
parent
416242286a
commit
785263628b
@ -23,11 +23,11 @@ public:
|
|||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Boxed_Value eval(const std::vector<Boxed_Value> &vals) {
|
const dispatchkit::Boxed_Value eval(const std::vector<dispatchkit::Boxed_Value> &vals) {
|
||||||
std::string val;
|
std::string val;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val = Cast_Helper<std::string &>()(vals[0]);
|
val = dispatchkit::Cast_Helper<std::string &>()(vals[0]);
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
catch (std::exception &e) {
|
||||||
throw EvalError("Can not evaluate string: " + val, langkit::TokenPtr());
|
throw EvalError("Can not evaluate string: " + val, langkit::TokenPtr());
|
||||||
@ -191,11 +191,11 @@ public:
|
|||||||
Eval_Engine build_eval_system(langkit::Lexer &lexer, langkit::Rule &parser) {
|
Eval_Engine build_eval_system(langkit::Lexer &lexer, langkit::Rule &parser) {
|
||||||
using namespace langkit;
|
using namespace langkit;
|
||||||
Eval_Engine ss;
|
Eval_Engine ss;
|
||||||
Bootstrap::bootstrap(ss);
|
dispatchkit::Bootstrap::bootstrap(ss);
|
||||||
bootstrap_vector<std::vector<Boxed_Value> >(ss, "Vector");
|
dispatchkit::bootstrap_vector<std::vector<dispatchkit::Boxed_Value> >(ss, "Vector");
|
||||||
|
|
||||||
ss.register_function(boost::shared_ptr<Proxy_Function>(
|
ss.register_function(boost::shared_ptr<dispatchkit::Proxy_Function>(
|
||||||
new Dynamic_Proxy_Function(boost::bind(&ChaiScript_System<Eval_Engine>::eval, boost::ref(*this), _1), 1)), "eval");
|
new dispatchkit::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()) } ");
|
evaluate_string("def print(x) { print_string(x.to_string()) } ");
|
||||||
|
|
||||||
@ -220,10 +220,10 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxed_Value evaluate_string(const std::string &input, const char *filename = "__EVAL__") {
|
dispatchkit::Boxed_Value evaluate_string(const std::string &input, const char *filename = "__EVAL__") {
|
||||||
using namespace langkit;
|
using namespace langkit;
|
||||||
std::vector<TokenPtr> tokens = lexer.lex(input, filename);
|
std::vector<TokenPtr> tokens = lexer.lex(input, filename);
|
||||||
Boxed_Value value;
|
dispatchkit::Boxed_Value value;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < tokens.size(); ++i) {
|
for (unsigned int i = 0; i < tokens.size(); ++i) {
|
||||||
if ((tokens[i]->identifier == TokenType::Quoted_String) || (tokens[i]->identifier == TokenType::Single_Quoted_String)) {
|
if ((tokens[i]->identifier == TokenType::Quoted_String) || (tokens[i]->identifier == TokenType::Single_Quoted_String)) {
|
||||||
@ -262,12 +262,12 @@ public:
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxed_Value evaluate_file(const char *filename) {
|
dispatchkit::Boxed_Value evaluate_file(const char *filename) {
|
||||||
return evaluate_string(load_file(filename), filename);
|
return evaluate_string(load_file(filename), filename);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef ChaiScript_System<Dispatch_Engine> ChaiScript_Engine;
|
typedef ChaiScript_System<dispatchkit::Dispatch_Engine> ChaiScript_Engine;
|
||||||
|
|
||||||
#endif /* CHAISCRIPT_ENGINE_HPP_ */
|
#endif /* CHAISCRIPT_ENGINE_HPP_ */
|
||||||
|
|
||||||
|
|||||||
@ -21,10 +21,10 @@ struct EvalError {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ReturnValue {
|
struct ReturnValue {
|
||||||
Boxed_Value retval;
|
dispatchkit::Boxed_Value retval;
|
||||||
langkit::TokenPtr location;
|
langkit::TokenPtr location;
|
||||||
|
|
||||||
ReturnValue(const Boxed_Value &return_value, const langkit::TokenPtr where) : retval(return_value), location(where) { }
|
ReturnValue(const dispatchkit::Boxed_Value &return_value, const langkit::TokenPtr where) : retval(return_value), location(where) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BreakLoop {
|
struct BreakLoop {
|
||||||
@ -34,21 +34,21 @@ struct BreakLoop {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Eval_System>
|
template <typename Eval_System>
|
||||||
const Boxed_Value eval_function (Eval_System &ss, langkit::TokenPtr node, const std::vector<std::string> ¶m_names, const std::vector<Boxed_Value> &vals) {
|
const dispatchkit::Boxed_Value eval_function (Eval_System &ss, langkit::TokenPtr node, const std::vector<std::string> ¶m_names, const std::vector<dispatchkit::Boxed_Value> &vals) {
|
||||||
ss.new_scope();
|
ss.new_scope();
|
||||||
|
|
||||||
for (unsigned int i = 0; i < param_names.size(); ++i) {
|
for (unsigned int i = 0; i < param_names.size(); ++i) {
|
||||||
ss.add_object(param_names[i], vals[i]);
|
ss.add_object(param_names[i], vals[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxed_Value retval = eval_token(ss, node);
|
dispatchkit::Boxed_Value retval = eval_token(ss, node);
|
||||||
ss.pop_scope();
|
ss.pop_scope();
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Eval_System>
|
template <typename Eval_System>
|
||||||
Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
dispatchkit::Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
||||||
Boxed_Value retval;
|
dispatchkit::Boxed_Value retval;
|
||||||
unsigned int i, j;
|
unsigned int i, j;
|
||||||
|
|
||||||
switch (node->identifier) {
|
switch (node->identifier) {
|
||||||
@ -60,10 +60,10 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
break;
|
break;
|
||||||
case (TokenType::Identifier) :
|
case (TokenType::Identifier) :
|
||||||
if (node->text == "true") {
|
if (node->text == "true") {
|
||||||
retval = Boxed_Value(true);
|
retval = dispatchkit::Boxed_Value(true);
|
||||||
}
|
}
|
||||||
else if (node->text == "false") {
|
else if (node->text == "false") {
|
||||||
retval = Boxed_Value(false);
|
retval = dispatchkit::Boxed_Value(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
@ -75,22 +75,22 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case (TokenType::Real_Number) :
|
case (TokenType::Real_Number) :
|
||||||
retval = Boxed_Value(double(atof(node->text.c_str())));
|
retval = dispatchkit::Boxed_Value(double(atof(node->text.c_str())));
|
||||||
break;
|
break;
|
||||||
case (TokenType::Integer) :
|
case (TokenType::Integer) :
|
||||||
retval = Boxed_Value(atoi(node->text.c_str()));
|
retval = dispatchkit::Boxed_Value(atoi(node->text.c_str()));
|
||||||
break;
|
break;
|
||||||
case (TokenType::Quoted_String) :
|
case (TokenType::Quoted_String) :
|
||||||
retval = Boxed_Value(node->text);
|
retval = dispatchkit::Boxed_Value(node->text);
|
||||||
break;
|
break;
|
||||||
case (TokenType::Single_Quoted_String) :
|
case (TokenType::Single_Quoted_String) :
|
||||||
retval = Boxed_Value(node->text);
|
retval = dispatchkit::Boxed_Value(node->text);
|
||||||
break;
|
break;
|
||||||
case (TokenType::Equation) :
|
case (TokenType::Equation) :
|
||||||
retval = eval_token(ss, node->children.back());
|
retval = eval_token(ss, node->children.back());
|
||||||
if (node->children.size() > 1) {
|
if (node->children.size() > 1) {
|
||||||
for (i = node->children.size()-3; ((int)i) >= 0; i -= 2) {
|
for (i = node->children.size()-3; ((int)i) >= 0; i -= 2) {
|
||||||
Param_List_Builder plb;
|
dispatchkit::Param_List_Builder plb;
|
||||||
plb << eval_token(ss, node->children[i]);
|
plb << eval_token(ss, node->children[i]);
|
||||||
plb << retval;
|
plb << retval;
|
||||||
try {
|
try {
|
||||||
@ -103,7 +103,7 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case (TokenType::Variable_Decl): {
|
case (TokenType::Variable_Decl): {
|
||||||
ss.add_object(node->children[0]->text, Boxed_Value());
|
ss.add_object(node->children[0]->text, dispatchkit::Boxed_Value());
|
||||||
retval = ss.get_object(node->children[0]->text);
|
retval = ss.get_object(node->children[0]->text);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -115,7 +115,7 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
retval = eval_token(ss, node->children[0]);
|
retval = eval_token(ss, node->children[0]);
|
||||||
if (node->children.size() > 1) {
|
if (node->children.size() > 1) {
|
||||||
for (i = 1; i < node->children.size(); i += 2) {
|
for (i = 1; i < node->children.size(); i += 2) {
|
||||||
Param_List_Builder plb;
|
dispatchkit::Param_List_Builder plb;
|
||||||
plb << retval;
|
plb << retval;
|
||||||
plb << eval_token(ss, node->children[i + 1]);
|
plb << eval_token(ss, node->children[i + 1]);
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
case (TokenType::Array_Call) : {
|
case (TokenType::Array_Call) : {
|
||||||
retval = eval_token(ss, node->children[0]);
|
retval = eval_token(ss, node->children[0]);
|
||||||
for (i = 1; i < node->children.size(); ++i) {
|
for (i = 1; i < node->children.size(); ++i) {
|
||||||
Param_List_Builder plb;
|
dispatchkit::Param_List_Builder plb;
|
||||||
plb << retval;
|
plb << retval;
|
||||||
plb << eval_token(ss, node->children[i]);
|
plb << eval_token(ss, node->children[i]);
|
||||||
try {
|
try {
|
||||||
@ -149,9 +149,9 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
break;
|
break;
|
||||||
case (TokenType::Negate) : {
|
case (TokenType::Negate) : {
|
||||||
retval = eval_token(ss, node->children[1]);
|
retval = eval_token(ss, node->children[1]);
|
||||||
Param_List_Builder plb;
|
dispatchkit::Param_List_Builder plb;
|
||||||
plb << retval;
|
plb << retval;
|
||||||
plb << Boxed_Value(-1);
|
plb << dispatchkit::Boxed_Value(-1);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
retval = dispatch(ss.get_function("*"), plb);
|
retval = dispatch(ss.get_function("*"), plb);
|
||||||
@ -165,17 +165,17 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
bool cond;
|
bool cond;
|
||||||
try {
|
try {
|
||||||
retval = eval_token(ss, node->children[1]);
|
retval = eval_token(ss, node->children[1]);
|
||||||
cond = Cast_Helper<bool &>()(retval);
|
cond = dispatchkit::Cast_Helper<bool &>()(retval);
|
||||||
}
|
}
|
||||||
catch (std::exception) {
|
catch (std::exception) {
|
||||||
throw EvalError("Boolean not('!') condition not boolean", node->children[0]);
|
throw EvalError("Boolean not('!') condition not boolean", node->children[0]);
|
||||||
}
|
}
|
||||||
retval = Boxed_Value(!cond);
|
retval = dispatchkit::Boxed_Value(!cond);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case (TokenType::Prefix) : {
|
case (TokenType::Prefix) : {
|
||||||
retval = eval_token(ss, node->children[1]);
|
retval = eval_token(ss, node->children[1]);
|
||||||
Param_List_Builder plb;
|
dispatchkit::Param_List_Builder plb;
|
||||||
plb << retval;
|
plb << retval;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -188,11 +188,11 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
break;
|
break;
|
||||||
case (TokenType::Array_Init) : {
|
case (TokenType::Array_Init) : {
|
||||||
try {
|
try {
|
||||||
retval = dispatch(ss.get_function("Vector"), Param_List_Builder());
|
retval = dispatch(ss.get_function("Vector"), dispatchkit::Param_List_Builder());
|
||||||
for (i = 0; i < node->children.size(); ++i) {
|
for (i = 0; i < node->children.size(); ++i) {
|
||||||
try {
|
try {
|
||||||
Boxed_Value tmp = eval_token(ss, node->children[i]);
|
dispatchkit::Boxed_Value tmp = eval_token(ss, node->children[i]);
|
||||||
dispatch(ss.get_function("push_back"), Param_List_Builder() << retval << tmp);
|
dispatch(ss.get_function("push_back"), dispatchkit::Param_List_Builder() << retval << tmp);
|
||||||
}
|
}
|
||||||
catch (std::exception inner_e) {
|
catch (std::exception inner_e) {
|
||||||
throw EvalError("Can not find appropriate 'push_back'", node->children[i]);
|
throw EvalError("Can not find appropriate 'push_back'", node->children[i]);
|
||||||
@ -206,13 +206,13 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
break;
|
break;
|
||||||
case (TokenType::Fun_Call) : {
|
case (TokenType::Fun_Call) : {
|
||||||
|
|
||||||
std::vector<std::pair<std::string, Dispatch_Engine::Function_Map::mapped_type> > fn;
|
std::vector<std::pair<std::string, dispatchkit::Dispatch_Engine::Function_Map::mapped_type> > fn;
|
||||||
Dispatch_Engine::Stack prev_stack = ss.get_stack();
|
dispatchkit::Dispatch_Engine::Stack prev_stack = ss.get_stack();
|
||||||
|
|
||||||
Dispatch_Engine::Stack new_stack;
|
dispatchkit::Dispatch_Engine::Stack new_stack;
|
||||||
new_stack.push_back(Dispatch_Engine::Scope());
|
new_stack.push_back(dispatchkit::Dispatch_Engine::Scope());
|
||||||
|
|
||||||
Param_List_Builder plb;
|
dispatchkit::Param_List_Builder plb;
|
||||||
for (i = 1; i < node->children.size(); ++i) {
|
for (i = 1; i < node->children.size(); ++i) {
|
||||||
plb << eval_token(ss, node->children[i]);
|
plb << eval_token(ss, node->children[i]);
|
||||||
}
|
}
|
||||||
@ -237,16 +237,16 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case (TokenType::Method_Call) : {
|
case (TokenType::Method_Call) : {
|
||||||
std::vector<std::pair<std::string, Dispatch_Engine::Function_Map::mapped_type> > fn;
|
std::vector<std::pair<std::string, dispatchkit::Dispatch_Engine::Function_Map::mapped_type> > fn;
|
||||||
Dispatch_Engine::Stack prev_stack = ss.get_stack();
|
dispatchkit::Dispatch_Engine::Stack prev_stack = ss.get_stack();
|
||||||
|
|
||||||
Dispatch_Engine::Stack new_stack;
|
dispatchkit::Dispatch_Engine::Stack new_stack;
|
||||||
new_stack.push_back(Dispatch_Engine::Scope());
|
new_stack.push_back(dispatchkit::Dispatch_Engine::Scope());
|
||||||
|
|
||||||
retval = eval_token(ss, node->children[0]);
|
retval = eval_token(ss, node->children[0]);
|
||||||
if (node->children.size() > 1) {
|
if (node->children.size() > 1) {
|
||||||
for (i = 1; i < node->children.size(); ++i) {
|
for (i = 1; i < node->children.size(); ++i) {
|
||||||
Param_List_Builder plb;
|
dispatchkit::Param_List_Builder plb;
|
||||||
plb << retval;
|
plb << retval;
|
||||||
|
|
||||||
for (j = 1; j < node->children[i]->children.size(); ++j) {
|
for (j = 1; j < node->children[i]->children.size(); ++j) {
|
||||||
@ -279,7 +279,7 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
retval = eval_token(ss, node->children[0]);
|
retval = eval_token(ss, node->children[0]);
|
||||||
bool cond;
|
bool cond;
|
||||||
try {
|
try {
|
||||||
cond = Cast_Helper<bool &>()(retval);
|
cond = dispatchkit::Cast_Helper<bool &>()(retval);
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
catch (std::exception &e) {
|
||||||
throw EvalError("If condition not boolean", node->children[0]);
|
throw EvalError("If condition not boolean", node->children[0]);
|
||||||
@ -298,7 +298,7 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
else if (node->children[i]->text == "elseif") {
|
else if (node->children[i]->text == "elseif") {
|
||||||
retval = eval_token(ss, node->children[i+1]);
|
retval = eval_token(ss, node->children[i+1]);
|
||||||
try {
|
try {
|
||||||
cond = Cast_Helper<bool &>()(retval);
|
cond = dispatchkit::Cast_Helper<bool &>()(retval);
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
catch (std::exception &e) {
|
||||||
throw EvalError("Elseif condition not boolean", node->children[i+1]);
|
throw EvalError("Elseif condition not boolean", node->children[i+1]);
|
||||||
@ -317,7 +317,7 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
retval = eval_token(ss, node->children[0]);
|
retval = eval_token(ss, node->children[0]);
|
||||||
bool cond;
|
bool cond;
|
||||||
try {
|
try {
|
||||||
cond = Cast_Helper<bool &>()(retval);
|
cond = dispatchkit::Cast_Helper<bool &>()(retval);
|
||||||
}
|
}
|
||||||
catch (std::exception) {
|
catch (std::exception) {
|
||||||
throw EvalError("While condition not boolean", node->children[0]);
|
throw EvalError("While condition not boolean", node->children[0]);
|
||||||
@ -327,7 +327,7 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
eval_token(ss, node->children[1]);
|
eval_token(ss, node->children[1]);
|
||||||
retval = eval_token(ss, node->children[0]);
|
retval = eval_token(ss, node->children[0]);
|
||||||
try {
|
try {
|
||||||
cond = Cast_Helper<bool &>()(retval);
|
cond = dispatchkit::Cast_Helper<bool &>()(retval);
|
||||||
}
|
}
|
||||||
catch (std::exception) {
|
catch (std::exception) {
|
||||||
throw EvalError("While condition not boolean", node->children[0]);
|
throw EvalError("While condition not boolean", node->children[0]);
|
||||||
@ -337,11 +337,11 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
cond = false;
|
cond = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retval = Boxed_Value();
|
retval = dispatchkit::Boxed_Value();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case(TokenType::For_Block) : {
|
case(TokenType::For_Block) : {
|
||||||
Boxed_Value condition;
|
dispatchkit::Boxed_Value condition;
|
||||||
bool cond;
|
bool cond;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -352,7 +352,7 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
else if (node->children.size() == 3){
|
else if (node->children.size() == 3){
|
||||||
condition = eval_token(ss, node->children[0]);
|
condition = eval_token(ss, node->children[0]);
|
||||||
}
|
}
|
||||||
cond = Cast_Helper<bool &>()(condition);
|
cond = dispatchkit::Cast_Helper<bool &>()(condition);
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
catch (std::exception &e) {
|
||||||
throw EvalError("For condition not boolean", node);
|
throw EvalError("For condition not boolean", node);
|
||||||
@ -369,7 +369,7 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
eval_token(ss, node->children[1]);
|
eval_token(ss, node->children[1]);
|
||||||
condition = eval_token(ss, node->children[0]);
|
condition = eval_token(ss, node->children[0]);
|
||||||
}
|
}
|
||||||
cond = Cast_Helper<bool &>()(condition);
|
cond = dispatchkit::Cast_Helper<bool &>()(condition);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
catch (std::exception &e) {
|
||||||
@ -379,7 +379,7 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
cond = false;
|
cond = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retval = Boxed_Value();
|
retval = dispatchkit::Boxed_Value();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case (TokenType::Function_Def) : {
|
case (TokenType::Function_Def) : {
|
||||||
@ -389,8 +389,8 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
param_names.push_back(node->children[i+1]->text);
|
param_names.push_back(node->children[i+1]->text);
|
||||||
}
|
}
|
||||||
|
|
||||||
ss.register_function(boost::shared_ptr<Proxy_Function>(
|
ss.register_function(boost::shared_ptr<dispatchkit::Proxy_Function>(
|
||||||
new Dynamic_Proxy_Function(boost::bind(&eval_function<Eval_System>, boost::ref(ss), node->children.back(), param_names, _1))), node->children[0]->text);
|
new dispatchkit::Dynamic_Proxy_Function(boost::bind(&eval_function<Eval_System>, boost::ref(ss), node->children.back(), param_names, _1))), node->children[0]->text);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case (TokenType::Lambda_Def) : {
|
case (TokenType::Lambda_Def) : {
|
||||||
@ -400,8 +400,9 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
param_names.push_back(node->children[i]->text);
|
param_names.push_back(node->children[i]->text);
|
||||||
}
|
}
|
||||||
|
|
||||||
//retval = boost::shared_ptr<Proxy_Function>(new Proxy_Function_Impl<boost::function<void (const std::string &)> >(&test));
|
//retval = boost::shared_ptr<dispatchkit::Proxy_Function>(new dispatchkit::Proxy_Function_Impl<boost::function<void (const std::string &)> >(&test));
|
||||||
retval = Boxed_Value(boost::shared_ptr<Proxy_Function>(new Dynamic_Proxy_Function(
|
retval = dispatchkit::Boxed_Value(boost::shared_ptr<dispatchkit::Proxy_Function>(
|
||||||
|
new dispatchkit::Dynamic_Proxy_Function(
|
||||||
boost::bind(&eval_function<Eval_System>, boost::ref(ss), node->children.back(), param_names, _1))));
|
boost::bind(&eval_function<Eval_System>, boost::ref(ss), node->children.back(), param_names, _1))));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -418,7 +419,7 @@ Boxed_Value eval_token(Eval_System &ss, langkit::TokenPtr node) {
|
|||||||
retval = eval_token(ss, node->children[0]);
|
retval = eval_token(ss, node->children[0]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
retval = Boxed_Value();
|
retval = dispatchkit::Boxed_Value();
|
||||||
}
|
}
|
||||||
throw ReturnValue(retval, node);
|
throw ReturnValue(retval, node);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,8 @@
|
|||||||
#include "chaiscript.hpp"
|
#include "chaiscript.hpp"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
using namespace dispatchkit;
|
||||||
|
|
||||||
std::string input;
|
std::string input;
|
||||||
|
|
||||||
ChaiScript_Engine chai;
|
ChaiScript_Engine chai;
|
||||||
|
|||||||
@ -4,6 +4,8 @@
|
|||||||
#include "dispatchkit.hpp"
|
#include "dispatchkit.hpp"
|
||||||
#include "bootstrap_pod.hpp"
|
#include "bootstrap_pod.hpp"
|
||||||
|
|
||||||
|
namespace dispatchkit
|
||||||
|
{
|
||||||
template<typename Ret, typename P1, typename P2>
|
template<typename Ret, typename P1, typename P2>
|
||||||
Ret add(P1 p1, P2 p2)
|
Ret add(P1 p1, P2 p2)
|
||||||
{
|
{
|
||||||
@ -455,5 +457,7 @@ struct Bootstrap
|
|||||||
register_function(s, &bool_or<bool, bool>, "||");
|
register_function(s, &bool_or<bool, bool>, "||");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
#include "register_function.hpp"
|
#include "register_function.hpp"
|
||||||
|
|
||||||
|
namespace dispatchkit
|
||||||
|
{
|
||||||
struct Pod_Bootstrap
|
struct Pod_Bootstrap
|
||||||
{
|
{
|
||||||
static Boxed_Value add(Boxed_POD_Value l, Boxed_POD_Value r)
|
static Boxed_Value add(Boxed_POD_Value l, Boxed_POD_Value r)
|
||||||
@ -75,6 +76,7 @@ struct Pod_Bootstrap
|
|||||||
register_function(s, &multiply, "*");
|
register_function(s, &multiply, "*");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "dispatchkit.hpp"
|
#include "dispatchkit.hpp"
|
||||||
|
|
||||||
|
namespace dispatchkit
|
||||||
|
{
|
||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
void bootstrap_reversible_container(Dispatch_Engine &system, const std::string &type)
|
void bootstrap_reversible_container(Dispatch_Engine &system, const std::string &type)
|
||||||
{
|
{
|
||||||
@ -80,5 +82,6 @@ void bootstrap_vector(Dispatch_Engine &system, const std::string &type)
|
|||||||
bootstrap_random_access_container<VectorType>(system, type);
|
bootstrap_random_access_container<VectorType>(system, type);
|
||||||
bootstrap_back_insertion_sequence<VectorType>(system, type);
|
bootstrap_back_insertion_sequence<VectorType>(system, type);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -8,6 +8,8 @@
|
|||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
|
||||||
|
namespace dispatchkit
|
||||||
|
{
|
||||||
class Boxed_Value
|
class Boxed_Value
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -491,9 +493,7 @@ struct Cast_Helper<Boxed_POD_Value>
|
|||||||
return Boxed_POD_Value(ob);
|
return Boxed_POD_Value(ob);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,8 @@
|
|||||||
#include "proxy_functions.hpp"
|
#include "proxy_functions.hpp"
|
||||||
#include "proxy_constructors.hpp"
|
#include "proxy_constructors.hpp"
|
||||||
|
|
||||||
|
namespace dispatchkit
|
||||||
|
{
|
||||||
class Dispatch_Engine
|
class Dispatch_Engine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -203,7 +205,7 @@ void dump_system(const Dispatch_Engine &s)
|
|||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,8 @@
|
|||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
|
||||||
|
namespace dispatchkit
|
||||||
|
{
|
||||||
template<typename Class>
|
template<typename Class>
|
||||||
boost::shared_ptr<Class> constructor()
|
boost::shared_ptr<Class> constructor()
|
||||||
{
|
{
|
||||||
@ -20,6 +22,7 @@ boost::function<boost::shared_ptr<Class> ()> build_constructor()
|
|||||||
typedef boost::shared_ptr<Class> (*func)();
|
typedef boost::shared_ptr<Class> (*func)();
|
||||||
return boost::function<boost::shared_ptr<Class> ()>(func(&(constructor<Class>)));
|
return boost::function<boost::shared_ptr<Class> ()>(func(&(constructor<Class>)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#define BOOST_PP_ITERATION_LIMITS ( 1, 10 )
|
#define BOOST_PP_ITERATION_LIMITS ( 1, 10 )
|
||||||
#define BOOST_PP_FILENAME_1 "proxy_constructors.hpp"
|
#define BOOST_PP_FILENAME_1 "proxy_constructors.hpp"
|
||||||
@ -28,7 +31,8 @@ boost::function<boost::shared_ptr<Class> ()> build_constructor()
|
|||||||
#else
|
#else
|
||||||
# define n BOOST_PP_ITERATION()
|
# define n BOOST_PP_ITERATION()
|
||||||
|
|
||||||
|
namespace dispatchkit
|
||||||
|
{
|
||||||
template<typename Class, BOOST_PP_ENUM_PARAMS(n, typename Param) >
|
template<typename Class, BOOST_PP_ENUM_PARAMS(n, typename Param) >
|
||||||
boost::shared_ptr<Class> constructor( BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) )
|
boost::shared_ptr<Class> constructor( BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) )
|
||||||
{
|
{
|
||||||
@ -41,6 +45,7 @@ boost::function<boost::shared_ptr<Class> (BOOST_PP_ENUM_PARAMS(n, Param))> build
|
|||||||
typedef boost::shared_ptr<Class> (*func)(BOOST_PP_ENUM_PARAMS(n, Param));
|
typedef boost::shared_ptr<Class> (*func)(BOOST_PP_ENUM_PARAMS(n, Param));
|
||||||
return boost::function<boost::shared_ptr<Class> (BOOST_PP_ENUM_PARAMS(n, Param))>(func(&(constructor<Class, BOOST_PP_ENUM_PARAMS(n, Param)>)));
|
return boost::function<boost::shared_ptr<Class> (BOOST_PP_ENUM_PARAMS(n, Param))>(func(&(constructor<Class, BOOST_PP_ENUM_PARAMS(n, Param)>)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,8 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace dispatchkit
|
||||||
|
{
|
||||||
// handle_return implementations
|
// handle_return implementations
|
||||||
template<typename Ret>
|
template<typename Ret>
|
||||||
struct Handle_Return
|
struct Handle_Return
|
||||||
@ -107,12 +109,14 @@ struct Param_List_Builder
|
|||||||
|
|
||||||
std::vector<Boxed_Value> objects;
|
std::vector<Boxed_Value> objects;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#define BOOST_PP_ITERATION_LIMITS ( 1, 10 )
|
#define BOOST_PP_ITERATION_LIMITS ( 1, 10 )
|
||||||
#define BOOST_PP_FILENAME_1 "proxy_functions.hpp"
|
#define BOOST_PP_FILENAME_1 "proxy_functions.hpp"
|
||||||
#include BOOST_PP_ITERATE()
|
#include BOOST_PP_ITERATE()
|
||||||
|
|
||||||
|
namespace dispatchkit
|
||||||
|
{
|
||||||
class Proxy_Function
|
class Proxy_Function
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -196,11 +200,14 @@ Boxed_Value dispatch(const std::vector<std::pair<std::string, boost::shared_ptr<
|
|||||||
|
|
||||||
throw std::runtime_error("No matching function to dispatch to");
|
throw std::runtime_error("No matching function to dispatch to");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
# define n BOOST_PP_ITERATION()
|
# define n BOOST_PP_ITERATION()
|
||||||
|
|
||||||
|
namespace dispatchkit
|
||||||
|
{
|
||||||
template<typename Ret, BOOST_PP_ENUM_PARAMS(n, typename Param) >
|
template<typename Ret, BOOST_PP_ENUM_PARAMS(n, typename Param) >
|
||||||
std::vector<Type_Info> build_param_type_list(const boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))> &f)
|
std::vector<Type_Info> build_param_type_list(const boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))> &f)
|
||||||
{
|
{
|
||||||
@ -223,6 +230,7 @@ Boxed_Value call_func(const boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))
|
|||||||
return Handle_Return<Ret>()(boost::bind(f BOOST_PP_REPEAT(n, casthelper, ~)));
|
return Handle_Return<Ret>()(boost::bind(f BOOST_PP_REPEAT(n, casthelper, ~)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,8 @@
|
|||||||
#else
|
#else
|
||||||
# define n BOOST_PP_ITERATION()
|
# define n BOOST_PP_ITERATION()
|
||||||
|
|
||||||
|
namespace dispatchkit
|
||||||
|
{
|
||||||
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param)>
|
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param)>
|
||||||
void register_function(Dispatch_Engine &s, Ret (*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const std::string &name)
|
void register_function(Dispatch_Engine &s, Ret (*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const std::string &name)
|
||||||
{
|
{
|
||||||
@ -29,7 +31,7 @@ void register_function(Dispatch_Engine &s, Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(
|
|||||||
{
|
{
|
||||||
s.register_function(boost::function<Ret (Class* BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param))>(f), name);
|
s.register_function(boost::function<Ret (Class* BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, Param))>(f), name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,8 @@
|
|||||||
#include "bootstrap.hpp"
|
#include "bootstrap.hpp"
|
||||||
#include "bootstrap_stl.hpp"
|
#include "bootstrap_stl.hpp"
|
||||||
|
|
||||||
|
using namespace dispatchkit;
|
||||||
|
|
||||||
struct Test
|
struct Test
|
||||||
{
|
{
|
||||||
Test(const std::string &s)
|
Test(const std::string &s)
|
||||||
|
|||||||
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include <boost/type_traits.hpp>
|
#include <boost/type_traits.hpp>
|
||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
|
|
||||||
|
namespace dispatchkit
|
||||||
|
{
|
||||||
struct Type_Info
|
struct Type_Info
|
||||||
{
|
{
|
||||||
Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void,
|
Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void,
|
||||||
@ -76,5 +79,7 @@ struct Get_Type_Info<boost::reference_wrapper<T> >
|
|||||||
&typeid(typename boost::remove_const<typename boost::remove_pointer<typename boost::remove_reference<T>::type>::type>::type));
|
&typeid(typename boost::remove_const<typename boost::remove_pointer<typename boost::remove_reference<T>::type>::type>::type));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( add_operators )
|
BOOST_AUTO_TEST_CASE( add_operators )
|
||||||
{
|
{
|
||||||
|
using namespace dispatchkit;
|
||||||
|
|
||||||
Dispatch_Engine ss;
|
Dispatch_Engine ss;
|
||||||
Bootstrap::bootstrap(ss);
|
Bootstrap::bootstrap(ss);
|
||||||
dump_system(ss);
|
dump_system(ss);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user