Merge branch 'master' of github.com:ChaiScript/ChaiScript

This commit is contained in:
Jonathan Turner
2011-06-04 11:02:07 -07:00

View File

@@ -45,32 +45,27 @@ namespace chaiscript
virtual ~Binary_Operator_AST_Node() {} virtual ~Binary_Operator_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) { virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) {
Boxed_Value retval = this->children[0]->eval(t_ss); Boxed_Value retval = this->children[0]->eval(t_ss);
Boxed_Value rhs(this->children[2]->eval(t_ss));
// Else loop through all children collecting the retval Operators::Opers oper = Operators::to_operator(children[1]->text);
for (size_t i = 1; i < this->children.size(); i += 2) {
Boxed_Value rhs(this->children[i+1]->eval(t_ss));
Operators::Opers oper = Operators::to_operator(children[i]->text);
try { try {
if (oper != Operators::invalid && retval.get_type_info().is_arithmetic() && rhs.get_type_info().is_arithmetic()) if (oper != Operators::invalid && retval.get_type_info().is_arithmetic() && rhs.get_type_info().is_arithmetic())
{ {
// If it's an arithmetic operation we want to short circuit dispatch // If it's an arithmetic operation we want to short circuit dispatch
try{ try{
retval = Boxed_Numeric::do_oper(oper, retval, rhs); return Boxed_Numeric::do_oper(oper, retval, rhs);
} catch (...) { } catch (...) {
throw exception::eval_error("Error with numeric operator calling: " + children[i]->text); throw exception::eval_error("Error with numeric operator calling: " + children[1]->text);
} }
} else { } else {
retval = t_ss.call_function(this->children[1]->text, retval, rhs); return t_ss.call_function(this->children[1]->text, retval, rhs);
} }
} }
catch(const exception::dispatch_error &){ catch(const exception::dispatch_error &){
throw exception::eval_error("Can not find appropriate '" + this->children[i]->text + "'"); throw exception::eval_error("Can not find appropriate '" + this->children[1]->text + "'");
} }
} }
return retval;
}
}; };