From 47052f710c094dcf955494b469d630d184319300 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 2 Jul 2009 19:59:40 +0000 Subject: [PATCH] Fix some semantics of operator= to reduce dispatch, etc. Also, add more bootstrapping support for some of the built in types. --- chaiscript/chaiscript_eval.hpp | 26 ++++++-------------------- dispatchkit/bootstrap.hpp | 12 +++++++++--- dispatchkit/bootstrap_stl.hpp | 27 +++++++++++++++++---------- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/chaiscript/chaiscript_eval.hpp b/chaiscript/chaiscript_eval.hpp index 8d374cea..cb909826 100644 --- a/chaiscript/chaiscript_eval.hpp +++ b/chaiscript/chaiscript_eval.hpp @@ -75,7 +75,10 @@ namespace chaiscript dispatchkit::Boxed_Value lhs = eval_token(ss, node->children[i]); if (lhs.is_unknown() || dispatchkit::Bootstrap::type_match(lhs, retval)) { try { - retval = dispatch(ss.get_function("clone"), dispatchkit::Param_List_Builder() << retval); + if (lhs.is_unknown()) + { + retval = dispatch(ss.get_function("clone"), dispatchkit::Param_List_Builder() << retval); + } dispatchkit::Param_List_Builder plb; plb << lhs; plb << retval; @@ -87,16 +90,7 @@ namespace chaiscript } } catch(const dispatchkit::dispatch_error &e){ - //throw EvalError("Can not clone right hand side of equation", node->children[i+1]); - dispatchkit::Param_List_Builder plb; - plb << lhs; - plb << retval; - try { - retval = dispatch(ss.get_function("="), plb); - } - catch(const dispatchkit::dispatch_error &e){ - throw EvalError("Can not find appropriate '" + node->children[i+1]->text + "'", node->children[i+1]); - } + throw EvalError("Can not clone right hand side of equation", node->children[i+1]); } } else { @@ -106,15 +100,7 @@ namespace chaiscript else if (node->children[i+1]->text == ":=") { dispatchkit::Boxed_Value lhs = eval_token(ss, node->children[i]); if (lhs.is_unknown() || dispatchkit::Bootstrap::type_match(lhs, retval)) { - dispatchkit::Param_List_Builder plb; - plb << lhs; - plb << retval; - try { - retval = dispatch(ss.get_function("="), plb); - } - catch(const dispatchkit::dispatch_error &e){ - throw EvalError("Can not find appropriate '" + node->children[i+1]->text + "'", node->children[i+1]); - } + lhs.assign(retval); } else { throw EvalError("Mismatched types in equation", node->children[i+1]); diff --git a/dispatchkit/bootstrap.hpp b/dispatchkit/bootstrap.hpp index a1955d19..28cea4ac 100644 --- a/dispatchkit/bootstrap.hpp +++ b/dispatchkit/bootstrap.hpp @@ -330,12 +330,18 @@ namespace dispatchkit register_function(s, &addsequal_pod, "+="); } + template + void add_copy_constructor(Dispatch_Engine &s, const std::string &type) + { + s.register_function(build_constructor(), type); + s.register_function(build_constructor(), "clone"); + } + template void add_basic_constructors(Dispatch_Engine &s, const std::string &type) { s.register_function(build_constructor(), type); - s.register_function(build_constructor(), type); - s.register_function(build_constructor(), "clone"); + add_copy_constructor(s, type); } template @@ -489,7 +495,7 @@ namespace dispatchkit add_oper_add(s); add_oper_add_equals (s); add_opers_comparison(s); - + s.register_function(build_constructor, const boost::shared_ptr &>(), "clone"); register_function(s, &print, "print_string"); register_function(s, &println, "println_string"); diff --git a/dispatchkit/bootstrap_stl.hpp b/dispatchkit/bootstrap_stl.hpp index 62ed9a5f..02e77e49 100644 --- a/dispatchkit/bootstrap_stl.hpp +++ b/dispatchkit/bootstrap_stl.hpp @@ -65,6 +65,7 @@ namespace dispatchkit register_function(system, &Input_Range::empty, "empty"); register_function(system, &Input_Range::pop_front, "pop_front"); register_function(system, &Input_Range::front, "front"); + system.register_function(build_constructor, const Input_Range &>(), "clone"); } template @@ -92,6 +93,8 @@ namespace dispatchkit { system.register_function( boost::function(&Assignable::operator=), "="); + system.register_function(build_constructor(), type); + system.register_function(build_constructor(), "clone"); } template @@ -153,10 +156,24 @@ namespace dispatchkit bootstrap_default_constructible(system, type); } + template + void bootstrap_pair(Dispatch_Engine &system, const std::string &type) + { + register_member(system, &PairType::first, "first"); + register_member(system, &PairType::second, "second"); + + system.register_function(build_constructor(), type); + system.register_function(build_constructor(), type); + system.register_function(build_constructor(), "clone"); + system.register_function(build_constructor(), type); + } + + template void bootstrap_pair_associative_container(Dispatch_Engine &system, const std::string &type) { bootstrap_associative_container(system, type); + bootstrap_pair(system, type + "_Pair"); } template @@ -166,16 +183,6 @@ namespace dispatchkit register_function(system, &ContainerType::count, "count"); } - template - void bootstrap_pair(Dispatch_Engine &system, const std::string &type) - { - register_member(system, &PairType::first, "first"); - register_member(system, &PairType::second, "second"); - - system.register_function(build_constructor(), type); - system.register_function(build_constructor(), type); - } - template void bootstrap_sorted_associative_container(Dispatch_Engine &system, const std::string &type) {