Fun location caching phase2

This shows ~25% performance over develop
This commit is contained in:
Jason Turner
2015-08-31 11:00:56 -06:00
parent f06e5cdcd6
commit 52e11bf001
2 changed files with 57 additions and 43 deletions

View File

@@ -118,7 +118,7 @@ namespace chaiscript
} else {
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
fpp.save_params({t_lhs, t_rhs});
return t_ss->call_function(t_oper_string, t_lhs, t_rhs);
return t_ss->call_function(t_oper_string, m_loc, {t_lhs, t_rhs});
}
}
catch(const exception::dispatch_error &e){
@@ -128,6 +128,7 @@ namespace chaiscript
private:
Operators::Opers m_oper;
mutable std::atomic_uint_fast32_t m_loc;
};
struct Int_AST_Node : public AST_Node {
@@ -396,6 +397,8 @@ namespace chaiscript
{ assert(children.size() == 3); }
Operators::Opers m_oper;
mutable std::atomic_uint_fast32_t m_loc;
mutable std::atomic_uint_fast32_t m_clone_loc;
virtual ~Equation_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const CHAISCRIPT_OVERRIDE {
@@ -431,14 +434,14 @@ namespace chaiscript
} else {
if (!rhs.is_return_value())
{
rhs = t_ss->call_function("clone", rhs);
rhs = t_ss->call_function("clone", m_clone_loc, {rhs});
}
rhs.reset_return_value();
}
}
try {
return t_ss->call_function(this->children[1]->text, std::move(lhs), rhs);
return t_ss->call_function(this->children[1]->text, m_loc, {std::move(lhs), rhs});
}
catch(const exception::dispatch_error &e){
throw exception::eval_error("Unable to find appropriate'" + this->children[1]->text + "' operator.", e.parameters, e.functions, false, *t_ss);
@@ -458,7 +461,7 @@ namespace chaiscript
}
else {
try {
return t_ss->call_function(this->children[1]->text, std::move(lhs), rhs);
return t_ss->call_function(this->children[1]->text, m_loc, {std::move(lhs), rhs});
} catch(const exception::dispatch_error &e){
throw exception::eval_error("Unable to find appropriate'" + this->children[1]->text + "' operator.", e.parameters, e.functions, false, *t_ss);
}
@@ -541,7 +544,7 @@ namespace chaiscript
try {
fpp.save_params(params);
return t_ss->call_function("[]", params);
return t_ss->call_function("[]", m_loc, params);
}
catch(const exception::dispatch_error &e){
throw exception::eval_error("Can not find appropriate array lookup operator '[]'.", e.parameters, e.functions, false, *t_ss );
@@ -563,6 +566,8 @@ namespace chaiscript
return oss.str();
}
mutable std::atomic_uint_fast32_t m_loc;
};
struct Dot_Access_AST_Node : public AST_Node {
@@ -592,7 +597,7 @@ namespace chaiscript
fpp.save_params(params);
try {
retval = t_ss->call_member(m_fun_name, std::move(params), has_function_params);
retval = t_ss->call_member(m_fun_name, m_loc, std::move(params), has_function_params);
}
catch(const exception::dispatch_error &e){
if (e.functions.empty())
@@ -608,7 +613,7 @@ namespace chaiscript
if (this->children[2]->identifier == AST_Node_Type::Array_Call) {
try {
retval = t_ss->call_function("[]", retval, this->children[2]->children[1]->eval(t_ss));
retval = t_ss->call_function("[]", m_array_loc, {retval, this->children[2]->children[1]->eval(t_ss)});
}
catch(const exception::dispatch_error &e){
throw exception::eval_error("Can not find appropriate array lookup operator '[]'.", e.parameters, e.functions, true, *t_ss);
@@ -619,6 +624,8 @@ namespace chaiscript
}
private:
mutable std::atomic_uint_fast32_t m_loc;
mutable std::atomic_uint_fast32_t m_array_loc;
std::string m_fun_name;
};
@@ -932,7 +939,7 @@ namespace chaiscript
if (this->children[currentCase]->identifier == AST_Node_Type::Case) {
//This is a little odd, but because want to see both the switch and the case simultaneously, I do a downcast here.
try {
if (hasMatched || boxed_cast<bool>(t_ss->call_function("==", match_value, this->children[currentCase]->children[0]->eval(t_ss)))) {
if (hasMatched || boxed_cast<bool>(t_ss->call_function("==", m_loc, {match_value, this->children[currentCase]->children[0]->eval(t_ss)}))) {
this->children[currentCase]->eval(t_ss);
hasMatched = true;
}
@@ -953,6 +960,8 @@ namespace chaiscript
}
return Boxed_Value();
}
mutable std::atomic_uint_fast32_t m_loc;
};
struct Case_AST_Node : public AST_Node {
@@ -999,7 +1008,7 @@ namespace chaiscript
for (const auto &child : children[0]->children) {
auto obj = child->eval(t_ss);
if (!obj.is_return_value()) {
vec.push_back(t_ss->call_function("clone", obj));
vec.push_back(t_ss->call_function("clone", m_loc, {obj}));
} else {
vec.push_back(std::move(obj));
}
@@ -1016,6 +1025,8 @@ namespace chaiscript
{
return "[" + AST_Node::pretty_print() + "]";
}
mutable std::atomic_uint_fast32_t m_loc;
};
struct Inline_Map_AST_Node : public AST_Node {
@@ -1030,7 +1041,7 @@ namespace chaiscript
for (const auto &child : children[0]->children) {
auto obj = child->children[1]->eval(t_ss);
if (!obj.is_return_value()) {
obj = t_ss->call_function("clone", obj);
obj = t_ss->call_function("clone", m_loc, {obj});
}
retval[t_ss->boxed_cast<std::string>(child->children[0]->eval(t_ss))] = std::move(obj);
@@ -1043,6 +1054,7 @@ namespace chaiscript
}
}
mutable std::atomic_uint_fast32_t m_loc;
};
struct Return_AST_Node : public AST_Node {
@@ -1125,7 +1137,7 @@ namespace chaiscript
} else {
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
fpp.save_params({bv});
return t_ss->call_function(children[0]->text, std::move(bv));
return t_ss->call_function(children[0]->text, m_loc, {std::move(bv)});
}
} catch (const exception::dispatch_error &e) {
throw exception::eval_error("Error with prefix operator evaluation: '" + children[0]->text + "'", e.parameters, e.functions, false, *t_ss);
@@ -1134,6 +1146,7 @@ namespace chaiscript
private:
Operators::Opers m_oper;
mutable std::atomic_uint_fast32_t m_loc;
};
struct Break_AST_Node : public AST_Node {
@@ -1196,14 +1209,14 @@ namespace chaiscript
try {
auto oper1 = children[0]->children[0]->children[0]->eval(t_ss);
auto oper2 = children[0]->children[0]->children[1]->eval(t_ss);
return t_ss->call_function("generate_range",
oper1, oper2);
return t_ss->call_function("generate_range", m_loc, {oper1, oper2});
}
catch (const exception::dispatch_error &e) {
throw exception::eval_error("Unable to generate range vector, while calling 'generate_range'", e.parameters, e.functions, false, *t_ss);
}
}
mutable std::atomic_uint_fast32_t m_loc;
};
struct Annotation_AST_Node : public AST_Node {