Fixed repl scope leak after an exception
This commit is contained in:
parent
db9442d5a8
commit
78be32927c
@ -20,11 +20,16 @@ namespace chaiscript
|
||||
|
||||
try {
|
||||
retval = eval_token(ss, node);
|
||||
ss.pop_scope();
|
||||
} catch (const ReturnValue &rv) {
|
||||
retval = rv.retval;
|
||||
ss.pop_scope();
|
||||
} catch (...) {
|
||||
ss.pop_scope();
|
||||
throw;
|
||||
}
|
||||
|
||||
ss.pop_scope();
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -189,7 +194,7 @@ namespace chaiscript
|
||||
throw EvalError("Out of bounds exception", node);
|
||||
}
|
||||
catch(const dispatchkit::dispatch_error &e){
|
||||
throw EvalError("Can not find appropriate array lookup '[]'", node->children[i]);
|
||||
throw EvalError("Can not find appropriate array lookup '[]' " + node->children[i]->text, node->children[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -541,7 +546,17 @@ namespace chaiscript
|
||||
case (Token_Type::Block) : {
|
||||
ss.new_scope();
|
||||
for (i = 0; i < node->children.size(); ++i) {
|
||||
retval = eval_token(ss, node->children[i]);
|
||||
try {
|
||||
retval = eval_token(ss, node->children[i]);
|
||||
}
|
||||
catch (const chaiscript::ReturnValue &rv) {
|
||||
retval = rv.retval;
|
||||
break;
|
||||
}
|
||||
catch (...) {
|
||||
ss.pop_scope();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
ss.pop_scope();
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ def to_string(x) : call_exists(range, x) { \n\
|
||||
\"[\" + x.join(\", \") + \"]\"\n\
|
||||
}\n\
|
||||
def to_string(x) { \n\
|
||||
x.internal_to_string()\n\
|
||||
return internal_to_string(x)\n\
|
||||
}\n\
|
||||
def puts(x) { \n\
|
||||
print_string(x.to_string()) \n\
|
||||
|
@ -2,55 +2,6 @@
|
||||
|
||||
#include "chaiscript.hpp"
|
||||
|
||||
dispatchkit::Boxed_Value evoke_fn(chaiscript::ChaiScript_Engine &chai, std::string name, dispatchkit::Param_List_Builder &plb) {
|
||||
dispatchkit::Dispatch_Engine ss = chai.get_eval_engine();
|
||||
dispatchkit::Dispatch_Engine::Stack prev_stack = ss.get_stack();
|
||||
dispatchkit::Dispatch_Engine::Stack new_stack;
|
||||
new_stack.push_back(dispatchkit::Dispatch_Engine::Scope());
|
||||
ss.set_stack(new_stack);
|
||||
/*
|
||||
try {
|
||||
dispatchkit::Boxed_Value retval = dispatchkit::dispatch(ss.get_function(name), plb);
|
||||
ss.set_stack(prev_stack);
|
||||
return retval;
|
||||
}
|
||||
catch(...) {
|
||||
ss.set_stack(prev_stack);
|
||||
std::cout << "Exception caught" << std::endl;
|
||||
throw;
|
||||
}
|
||||
*/
|
||||
dispatchkit::Boxed_Value retval;
|
||||
try {
|
||||
|
||||
//fn = ss.get_function(node->children[0]->text);
|
||||
ss.set_stack(new_stack);
|
||||
//retval = dispatch(fn, plb);
|
||||
//retval = dispatch
|
||||
//retval = (*dispatchkit::boxed_cast<boost::shared_ptr<dispatchkit::Proxy_Function> >(fn))(plb);
|
||||
retval = dispatchkit::dispatch(ss.get_function(name), plb);
|
||||
ss.set_stack(prev_stack);
|
||||
}
|
||||
catch(chaiscript::EvalError &ee) {
|
||||
ss.set_stack(prev_stack);
|
||||
//throw chaiscript::EvalError(ee.reason, node->children[0]);
|
||||
throw;
|
||||
}
|
||||
catch(const dispatchkit::dispatch_error &e){
|
||||
ss.set_stack(prev_stack);
|
||||
throw;
|
||||
}
|
||||
catch(chaiscript::ReturnValue &rv) {
|
||||
ss.set_stack(prev_stack);
|
||||
retval = rv.retval;
|
||||
}
|
||||
catch(...) {
|
||||
ss.set_stack(prev_stack);
|
||||
throw;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
std::string input;
|
||||
@ -62,6 +13,7 @@ int main(int argc, char *argv[]) {
|
||||
std::cout << "eval> ";
|
||||
std::getline(std::cin, input);
|
||||
while (input != "quit") {
|
||||
|
||||
dispatchkit::Boxed_Value val;
|
||||
|
||||
val = chai.evaluate_string(input);
|
||||
@ -69,11 +21,9 @@ int main(int argc, char *argv[]) {
|
||||
if (val.get_type_info().m_bare_type_info && *(val.get_type_info().m_bare_type_info) != typeid(void)) {
|
||||
|
||||
try {
|
||||
dispatchkit::Boxed_Value printeval = evoke_fn(chai, "to_string", dispatchkit::Param_List_Builder() << val);
|
||||
std::cout << "result: ";
|
||||
evoke_fn(chai, "print", dispatchkit::Param_List_Builder() << printeval);
|
||||
dispatchkit::dispatch(chai.get_eval_engine().get_function("print"), dispatchkit::Param_List_Builder() << val);
|
||||
} catch (const std::runtime_error &e) {
|
||||
std::cout << "result: object #" << &val << " Error: " << e.what() << std::endl;
|
||||
//do nothing for the time being
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user