Reduce overhead necessary for internal_eval. Desirable due to the use of "eval" during cloning operations
This commit is contained in:
parent
d3cdd6959d
commit
443902f787
@ -201,10 +201,13 @@ namespace chaiscript
|
|||||||
/**
|
/**
|
||||||
* Evaluates the given string in by parsing it and running the results through the evaluator
|
* Evaluates the given string in by parsing it and running the results through the evaluator
|
||||||
*/
|
*/
|
||||||
Boxed_Value do_eval(const std::string &input, const std::string &filename = "__EVAL__") {
|
Boxed_Value do_eval(const std::string &input, const std::string &filename = "__EVAL__", bool internal = false) {
|
||||||
ChaiScript_Parser parser;
|
ChaiScript_Parser parser;
|
||||||
|
|
||||||
|
if (!internal)
|
||||||
|
{
|
||||||
engine.sync_cache();
|
engine.sync_cache();
|
||||||
|
}
|
||||||
|
|
||||||
//debug_print(tokens);
|
//debug_print(tokens);
|
||||||
Boxed_Value value;
|
Boxed_Value value;
|
||||||
@ -213,11 +216,12 @@ namespace chaiscript
|
|||||||
// to the parser. This is so that the parser does not have the overhead of passing
|
// to the parser. This is so that the parser does not have the overhead of passing
|
||||||
// around and copying strings
|
// around and copying strings
|
||||||
//
|
//
|
||||||
|
if (filename != "__EVAL__")
|
||||||
|
{
|
||||||
#ifndef CHAISCRIPT_NO_THREADS
|
#ifndef CHAISCRIPT_NO_THREADS
|
||||||
boost::unique_lock<boost::shared_mutex> l(mutex);
|
boost::unique_lock<boost::shared_mutex> l(mutex);
|
||||||
#endif
|
#endif
|
||||||
loaded_files.insert(filename);
|
loaded_files.insert(filename);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (parser.parse(input, loaded_files.find(filename)->c_str())) {
|
if (parser.parse(input, loaded_files.find(filename)->c_str())) {
|
||||||
#ifndef CHAISCRIPT_NO_THREADS
|
#ifndef CHAISCRIPT_NO_THREADS
|
||||||
@ -230,8 +234,22 @@ namespace chaiscript
|
|||||||
catch (const Return_Value &rv) {
|
catch (const Return_Value &rv) {
|
||||||
value = rv.retval;
|
value = rv.retval;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
if (parser.parse(input, loaded_files.find(filename)->c_str())) {
|
||||||
|
//parser.show_match_stack();
|
||||||
|
value = eval_token<Eval_Engine>(engine, parser.ast());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const Return_Value &rv) {
|
||||||
|
value = rv.retval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!internal)
|
||||||
|
{
|
||||||
engine.sync_cache();
|
engine.sync_cache();
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -240,7 +258,7 @@ namespace chaiscript
|
|||||||
* Evaluates the given boxed string, used during eval() inside of a script
|
* Evaluates the given boxed string, used during eval() inside of a script
|
||||||
*/
|
*/
|
||||||
const Boxed_Value internal_eval(const std::vector<Boxed_Value> &vals) {
|
const Boxed_Value internal_eval(const std::vector<Boxed_Value> &vals) {
|
||||||
return do_eval(boxed_cast<std::string>(vals.at(0)));
|
return do_eval(boxed_cast<std::string>(vals.at(0)), "__EVAL__", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void use(const std::string &filename)
|
void use(const std::string &filename)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user