Remove little used Param_List_Builder

This commit is contained in:
Jason Turner 2011-09-25 18:34:02 -06:00
parent 702b5fdba1
commit db0e342a96
2 changed files with 10 additions and 41 deletions

View File

@ -28,37 +28,6 @@ namespace chaiscript
namespace dispatch namespace dispatch
{ {
/**
* Helper for building a list of parameters for calling a Proxy_Function
* it does automatic conversion to Boxed_Value types via operator<<
*
* example usage:
* Boxed_Value retval = dispatch(dispatchengine.get_function("+"),
* chaiscript::Param_List_Builder() << 5 << 6);
*/
struct Param_List_Builder
{
Param_List_Builder &operator<<(const Boxed_Value &so)
{
objects.push_back(so);
return *this;
}
template<typename T>
Param_List_Builder &operator<<(T t)
{
objects.push_back(Boxed_Value(t));
return *this;
}
operator const std::vector<Boxed_Value> &() const
{
return objects;
}
std::vector<Boxed_Value> objects;
};
/** /**
* Pure virtual base class for all Proxy_Function implementations * Pure virtual base class for all Proxy_Function implementations
* Proxy_Functions are a type erasure of type safe C++ * Proxy_Functions are a type erasure of type safe C++

View File

@ -182,11 +182,11 @@ namespace chaiscript
AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Fun_Call_AST_Node() {} virtual ~Fun_Call_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){
dispatch::Param_List_Builder plb; std::vector<Boxed_Value> params;
if ((this->children.size() > 1) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) { if ((this->children.size() > 1) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) {
for (size_t i = 0; i < this->children[1]->children.size(); ++i) { for (size_t i = 0; i < this->children[1]->children.size(); ++i) {
plb << this->children[1]->children[i]->eval(t_ss); params.push_back(this->children[1]->children[i]->eval(t_ss));
} }
} }
@ -198,7 +198,7 @@ namespace chaiscript
try { try {
t_ss.set_stack(new_stack); t_ss.set_stack(new_stack);
const Boxed_Value &retval = (*boxed_cast<const Const_Proxy_Function &>(fn))(plb); const Boxed_Value &retval = (*boxed_cast<const Const_Proxy_Function &>(fn))(params);
t_ss.set_stack(prev_stack); t_ss.set_stack(prev_stack);
return retval; return retval;
} }
@ -230,16 +230,16 @@ namespace chaiscript
AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { }
virtual ~Inplace_Fun_Call_AST_Node() {} virtual ~Inplace_Fun_Call_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){
dispatch::Param_List_Builder plb; std::vector<Boxed_Value> params;
if ((this->children.size() > 1) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) { if ((this->children.size() > 1) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) {
for (size_t i = 0; i < this->children[1]->children.size(); ++i) { for (size_t i = 0; i < this->children[1]->children.size(); ++i) {
plb << this->children[1]->children[i]->eval(t_ss); params.push_back(this->children[1]->children[i]->eval(t_ss));
} }
} }
try { try {
return (*boxed_cast<const Const_Proxy_Function &>(this->children[0]->eval(t_ss)))(plb); return (*boxed_cast<const Const_Proxy_Function &>(this->children[0]->eval(t_ss)))(params);
} }
catch(const exception::dispatch_error &e){ catch(const exception::dispatch_error &e){
throw exception::eval_error(std::string(e.what()) + " with function '" + this->children[0]->text + "'", e.parameters, t_ss); throw exception::eval_error(std::string(e.what()) + " with function '" + this->children[0]->text + "'", e.parameters, t_ss);
@ -458,12 +458,12 @@ namespace chaiscript
if (this->children.size() > 1) { if (this->children.size() > 1) {
for (size_t i = 2; i < this->children.size(); i+=2) { for (size_t i = 2; i < this->children.size(); i+=2) {
dispatch::Param_List_Builder plb; std::vector<Boxed_Value> params;
plb << retval; params.push_back(retval);
if (this->children[i]->children.size() > 1) { if (this->children[i]->children.size() > 1) {
for (size_t j = 0; j < this->children[i]->children[1]->children.size(); ++j) { for (size_t j = 0; j < this->children[i]->children[1]->children.size(); ++j) {
plb << this->children[i]->children[1]->children[j]->eval(t_ss); params.push_back(this->children[i]->children[1]->children[j]->eval(t_ss));
} }
} }
@ -480,7 +480,7 @@ namespace chaiscript
try { try {
t_ss.set_stack(new_stack); t_ss.set_stack(new_stack);
retval = t_ss.call_function(fun_name, plb); retval = t_ss.call_function(fun_name, params);
t_ss.set_stack(prev_stack); t_ss.set_stack(prev_stack);
} }
catch(const exception::dispatch_error &e){ catch(const exception::dispatch_error &e){