From afa96ecbf98379a9d2007ac7d11cd1e29a8ca307 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 10 Sep 2011 06:55:27 -0600 Subject: [PATCH 001/108] Begin port to C++11 --- CMakeLists.txt | 2 +- include/chaiscript/chaiscript.hpp | 12 +- include/chaiscript/dispatchkit/bootstrap.hpp | 18 +-- include/chaiscript/dispatchkit/boxed_cast.hpp | 10 +- .../dispatchkit/boxed_cast_helper.hpp | 42 +++---- .../chaiscript/dispatchkit/boxed_value.hpp | 38 +++--- .../chaiscript/dispatchkit/dispatchkit.hpp | 12 +- .../dispatchkit/dynamic_cast_conversion.hpp | 16 +-- .../dispatchkit/exception_specification.hpp | 2 +- .../dispatchkit/function_call_detail.hpp | 4 +- .../chaiscript/dispatchkit/handle_return.hpp | 12 +- .../dispatchkit/proxy_constructors.hpp | 6 +- .../dispatchkit/proxy_functions.hpp | 12 +- include/chaiscript/dispatchkit/type_info.hpp | 8 +- .../chaiscript/language/chaiscript_common.hpp | 8 +- .../chaiscript/language/chaiscript_engine.hpp | 2 +- .../chaiscript/language/chaiscript_eval.hpp | 112 +++++++++--------- .../chaiscript/language/chaiscript_parser.hpp | 4 +- samples/example.cpp | 4 +- src/multithreaded.cpp | 4 +- src/reflection.cpp | 10 +- unittests/boxed_cast_test.cpp | 20 ++-- unittests/multifile_test_chai.cpp | 2 +- unittests/multifile_test_chai.hpp | 4 +- unittests/multifile_test_main.cpp | 2 +- 25 files changed, 183 insertions(+), 183 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d6ffca27..d6c77af2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,7 @@ if(MSVC) add_definitions(/bigobj) endif() else() - add_definitions(-Wall -Wextra -Wshadow -pedantic) + add_definitions(-Wall -Wextra -Wshadow -pedantic -std=c++0x) if (APPLE) # -Wno-missing-field-initializers is for boost on macos diff --git a/include/chaiscript/chaiscript.hpp b/include/chaiscript/chaiscript.hpp index 0f17284c..56611f38 100644 --- a/include/chaiscript/chaiscript.hpp +++ b/include/chaiscript/chaiscript.hpp @@ -297,8 +297,8 @@ ///
/// \subsection pointerconversions Pointer / Object Conversions /// -/// As much as possible, ChaiScript attempts to convert between &, *, const &, const *, boost::shared_ptr, -/// boost::shared_ptr, boost::reference_wrapper, boost::reference_wrapper and value types automatically. +/// As much as possible, ChaiScript attempts to convert between &, *, const &, const *, std::shared_ptr, +/// std::shared_ptr, boost::reference_wrapper, boost::reference_wrapper and value types automatically. /// /// If a chaiscript::var object was created in C++ from a pointer, it cannot be convered to a shared_ptr (this would add invalid reference counting). /// Const may be added, but never removed. @@ -311,10 +311,10 @@ /// void fun3(int); /// void fun4(int &); /// void fun5(const int &); -/// void fun5(boost::shared_ptr); -/// void fun6(boost::shared_ptr); -/// void fun7(const boost::shared_ptr &); -/// void fun8(const boost::shared_ptr &); +/// void fun5(std::shared_ptr); +/// void fun6(std::shared_ptr); +/// void fun7(const std::shared_ptr &); +/// void fun8(const std::shared_ptr &); /// void fun9(boost::reference_wrapper); /// void fun10(boost::reference_wrapper); /// diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index d61f338e..5427ac8c 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -25,9 +25,9 @@ namespace chaiscript /// \param[in] v Boxed_Number to copy into the new object /// \returns The newly created object. template - boost::shared_ptr construct_pod(Boxed_Number v) + std::shared_ptr construct_pod(Boxed_Number v) { - boost::shared_ptr p(new P1()); + std::shared_ptr p(new P1()); Boxed_Value bv(p); Boxed_Number nb(bv); nb = v; @@ -139,7 +139,7 @@ namespace chaiscript * function variables. */ template - boost::shared_ptr shared_ptr_clone(const boost::shared_ptr &p) + std::shared_ptr shared_ptr_clone(const std::shared_ptr &p) { return p; } @@ -148,8 +148,8 @@ namespace chaiscript * Specific version of shared_ptr_clone just for Proxy_Functions */ template - boost::shared_ptr::type> - shared_ptr_unconst_clone(const boost::shared_ptr::type> &p) + std::shared_ptr::type> + shared_ptr_unconst_clone(const std::shared_ptr::type> &p) { return boost::const_pointer_cast::type>(p); } @@ -162,7 +162,7 @@ namespace chaiscript * Similar to shared_ptr_clone. Used for Proxy_Function. */ template - Boxed_Value ptr_assign(Boxed_Value lhs, const boost::shared_ptr &rhs) + Boxed_Value ptr_assign(Boxed_Value lhs, const std::shared_ptr &rhs) { if (lhs.is_undef() || (!lhs.get_type_info().is_const() && lhs.get_type_info().bare_equal(chaiscript::detail::Get_Type_Info::get()))) @@ -283,7 +283,7 @@ namespace chaiscript static bool has_guard(const Const_Proxy_Function &t_pf) { - boost::shared_ptr pf = boost::dynamic_pointer_cast(t_pf); + std::shared_ptr pf = std::dynamic_pointer_cast(t_pf); if (pf) { return pf->get_guard(); @@ -294,7 +294,7 @@ namespace chaiscript static Const_Proxy_Function get_guard(const Const_Proxy_Function &t_pf) { - boost::shared_ptr pf = boost::dynamic_pointer_cast(t_pf); + std::shared_ptr pf = std::dynamic_pointer_cast(t_pf); if (pf) { if (pf->get_guard()) @@ -312,7 +312,7 @@ namespace chaiscript throw bv; } - static boost::shared_ptr bootstrap2(boost::shared_ptr e = boost::shared_ptr (new chaiscript::detail::Dispatch_Engine())) + static std::shared_ptr bootstrap2(std::shared_ptr e = std::shared_ptr (new chaiscript::detail::Dispatch_Engine())) { e->add(user_type(), "void"); return e; diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index e082ce36..ea188bb6 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -31,7 +31,7 @@ namespace chaiscript /// \returns Type equivalent to the requested type /// \throws exception::bad_boxed_cast If the requested conversion is not possible /// - /// boxed_cast will attempt to make conversions between value, &, *, boost::shared_ptr, boost::reference_wrapper, + /// boxed_cast will attempt to make conversions between value, &, *, std::shared_ptr, boost::reference_wrapper, /// and boost::function (const and non-const) where possible. boxed_cast is used internally during function /// dispatch. This means that all of these conversions will be attempted automatically for you during /// ChaiScript function calls. @@ -40,8 +40,8 @@ namespace chaiscript /// \li const values can be extracted only as const /// \li Boxed_Value constructed from pointer or boost::reference_wrapper can be extracted as reference, /// pointer or value types - /// \li Boxed_Value constructed from boost::shared_ptr or value types can be extracted as reference, - /// pointer, value, or boost::shared_ptr types + /// \li Boxed_Value constructed from std::shared_ptr or value types can be extracted as reference, + /// pointer, value, or std::shared_ptr types /// /// Conversions to boost::function objects are attempted as well /// @@ -49,11 +49,11 @@ namespace chaiscript /// \code /// // All of the following should succeed /// chaiscript::Boxed_Value bv(1); - /// boost::shared_ptr spi = chaiscript::boxed_cast >(bv); + /// std::shared_ptr spi = chaiscript::boxed_cast >(bv); /// int i = chaiscript::boxed_cast(bv); /// int *ip = chaiscript::boxed_cast(bv); /// int &ir = chaiscript::boxed_cast(bv); - /// boost::shared_ptr cspi = chaiscript::boxed_cast >(bv); + /// std::shared_ptr cspi = chaiscript::boxed_cast >(bv); /// const int ci = chaiscript::boxed_cast(bv); /// const int *cip = chaiscript::boxed_cast(bv); /// const int &cir = chaiscript::boxed_cast(bv); diff --git a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp index ceb01780..c6e83389 100644 --- a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp @@ -42,9 +42,9 @@ namespace chaiscript } else { if (!ob.get_type_info().is_const()) { - return boost::cref(*(boost::any_cast >(ob.get()))); + return boost::cref(*(boost::any_cast >(ob.get()))); } else { - return boost::cref(*(boost::any_cast >(ob.get()))); + return boost::cref(*(boost::any_cast >(ob.get()))); } } } @@ -84,9 +84,9 @@ namespace chaiscript } else { if (!ob.get_type_info().is_const()) { - return (boost::any_cast >(ob.get())).get(); + return (boost::any_cast >(ob.get())).get(); } else { - return (boost::any_cast >(ob.get())).get(); + return (boost::any_cast >(ob.get())).get(); } } } @@ -106,7 +106,7 @@ namespace chaiscript { return (boost::any_cast >(ob.get())).get_pointer(); } else { - return (boost::any_cast >(ob.get())).get(); + return (boost::any_cast >(ob.get())).get(); } } }; @@ -125,68 +125,68 @@ namespace chaiscript { return boost::any_cast >(ob.get()); } else { - return boost::ref(*(boost::any_cast >(ob.get()))); + return boost::ref(*(boost::any_cast >(ob.get()))); } } }; /** - * Cast_Helper_Inner for casting to a boost::shared_ptr<> type + * Cast_Helper_Inner for casting to a std::shared_ptr<> type */ template - struct Cast_Helper_Inner > + struct Cast_Helper_Inner > { - typedef typename boost::shared_ptr Result_Type; + typedef typename std::shared_ptr Result_Type; static Result_Type cast(const Boxed_Value &ob) { - return boost::any_cast >(ob.get()); + return boost::any_cast >(ob.get()); } }; /** - * Cast_Helper_Inner for casting to a boost::shared_ptr type + * Cast_Helper_Inner for casting to a std::shared_ptr type */ template - struct Cast_Helper_Inner > + struct Cast_Helper_Inner > { - typedef typename boost::shared_ptr Result_Type; + typedef typename std::shared_ptr Result_Type; static Result_Type cast(const Boxed_Value &ob) { if (!ob.get_type_info().is_const()) { - return boost::const_pointer_cast(boost::any_cast >(ob.get())); + return boost::const_pointer_cast(boost::any_cast >(ob.get())); } else { - return boost::any_cast >(ob.get()); + return boost::any_cast >(ob.get()); } } }; /** - * Cast_Helper_Inner for casting to a const boost::shared_ptr<> & type + * Cast_Helper_Inner for casting to a const std::shared_ptr<> & type */ template - struct Cast_Helper_Inner > : Cast_Helper_Inner > + struct Cast_Helper_Inner > : Cast_Helper_Inner > { }; template - struct Cast_Helper_Inner &> : Cast_Helper_Inner > + struct Cast_Helper_Inner &> : Cast_Helper_Inner > { }; /** - * Cast_Helper_Inner for casting to a const boost::shared_ptr & type + * Cast_Helper_Inner for casting to a const std::shared_ptr & type */ template - struct Cast_Helper_Inner > : Cast_Helper_Inner > + struct Cast_Helper_Inner > : Cast_Helper_Inner > { }; template - struct Cast_Helper_Inner &> : Cast_Helper_Inner > + struct Cast_Helper_Inner &> : Cast_Helper_Inner > { }; diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index d49931fa..6eb1eac5 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -71,14 +71,14 @@ namespace chaiscript void *m_data_ptr; const void *m_const_data_ptr; bool m_is_ref; - std::vector > m_dependencies; + std::vector > m_dependencies; }; struct Object_Data { - static boost::shared_ptr get(Boxed_Value::Void_Type) + static std::shared_ptr get(Boxed_Value::Void_Type) { - return boost::shared_ptr (new Data( + return std::shared_ptr (new Data( detail::Get_Type_Info::get(), boost::any(), false, @@ -87,15 +87,15 @@ namespace chaiscript } template - static boost::shared_ptr get(const boost::shared_ptr *obj) + static std::shared_ptr get(const std::shared_ptr *obj) { return get(*obj); } template - static boost::shared_ptr get(const boost::shared_ptr &obj) + static std::shared_ptr get(const std::shared_ptr &obj) { - return boost::shared_ptr(new Data( + return std::shared_ptr(new Data( detail::Get_Type_Info::get(), boost::any(obj), false, @@ -104,15 +104,15 @@ namespace chaiscript } template - static boost::shared_ptr get(T *t) + static std::shared_ptr get(T *t) { return get(boost::ref(*t)); } template - static boost::shared_ptr get(boost::reference_wrapper obj) + static std::shared_ptr get(boost::reference_wrapper obj) { - return boost::shared_ptr(new Data( + return std::shared_ptr(new Data( detail::Get_Type_Info::get(), boost::any(obj), true, @@ -121,10 +121,10 @@ namespace chaiscript } template - static boost::shared_ptr get(const T& t) + static std::shared_ptr get(const T& t) { - boost::shared_ptr p(new T(t)); - return boost::shared_ptr(new Data( + std::shared_ptr p(new T(t)); + return std::shared_ptr(new Data( detail::Get_Type_Info::get(), boost::any(p), false, @@ -132,9 +132,9 @@ namespace chaiscript ); } - static boost::shared_ptr get() + static std::shared_ptr get() { - return boost::shared_ptr (new Data( + return std::shared_ptr (new Data( Type_Info(), boost::any(), false, @@ -271,10 +271,10 @@ namespace chaiscript } private: - boost::shared_ptr m_data; + std::shared_ptr m_data; }; - /// \brief Creates a Boxed_Value. If the object passed in is a value type, it is copied. If it is a pointer, boost::shared_ptr, or boost::reference_type + /// \brief Creates a Boxed_Value. If the object passed in is a value type, it is copied. If it is a pointer, std::shared_ptr, or boost::reference_type /// a copy is not made. /// \param t The value to box /// @@ -301,7 +301,7 @@ namespace chaiscript template Boxed_Value const_var_impl(const T &t) { - return Boxed_Value(boost::shared_ptr::type >(new T(t))); + return Boxed_Value(std::shared_ptr::type >(new T(t))); } /// \brief Takes a pointer to a value, adds const to the pointed to type and returns an immutable Boxed_Value. @@ -315,13 +315,13 @@ namespace chaiscript return Boxed_Value( const_cast::type *>(t) ); } - /// \brief Takes a boost::shared_ptr to a value, adds const to the pointed to type and returns an immutable Boxed_Value. + /// \brief Takes a std::shared_ptr to a value, adds const to the pointed to type and returns an immutable Boxed_Value. /// Does not copy the pointed to value. /// \param[in] t Pointer to make immutable /// \returns Immutable Boxed_Value /// \sa Boxed_Value::is_const template - Boxed_Value const_var_impl(const boost::shared_ptr &t) + Boxed_Value const_var_impl(const std::shared_ptr &t) { return Boxed_Value( boost::const_pointer_cast::type>(t) ); } diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index b96d53aa..0dd657ac 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -118,7 +118,7 @@ namespace chaiscript return *this; } - Module &add(const boost::shared_ptr &m) + Module &add(const std::shared_ptr &m) { m->apply(*this, *this); return *m; @@ -183,7 +183,7 @@ namespace chaiscript }; /// Convenience typedef for Module objects to be added to the ChaiScript runtime - typedef boost::shared_ptr ModulePtr; + typedef std::shared_ptr ModulePtr; namespace detail { @@ -346,7 +346,7 @@ namespace chaiscript typedef std::map Type_Name_Map; typedef std::map Scope; typedef std::deque StackData; - typedef boost::shared_ptr Stack; + typedef std::shared_ptr Stack; struct State { @@ -357,7 +357,7 @@ namespace chaiscript }; Dispatch_Engine() - : m_place_holder(boost::shared_ptr(new dispatch::Placeholder_Object())) + : m_place_holder(std::shared_ptr(new dispatch::Placeholder_Object())) { } @@ -838,8 +838,8 @@ namespace chaiscript const Type_Info boxed_type = user_type(); const Type_Info boxed_pod_type = user_type(); - boost::shared_ptr dynamic_lhs(boost::dynamic_pointer_cast(lhs)); - boost::shared_ptr dynamic_rhs(boost::dynamic_pointer_cast(rhs)); + std::shared_ptr dynamic_lhs(std::dynamic_pointer_cast(lhs)); + std::shared_ptr dynamic_rhs(std::dynamic_pointer_cast(rhs)); if (dynamic_lhs && dynamic_rhs) { diff --git a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp index dd14ff8f..5d66f296 100644 --- a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp +++ b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp @@ -87,8 +87,8 @@ namespace chaiscript // Dynamic cast out the contained boxed value, which we know is the type we want if (t_derived.is_const()) { - boost::shared_ptr data - = boost::dynamic_pointer_cast(detail::Cast_Helper >::cast(t_derived)); + std::shared_ptr data + = std::dynamic_pointer_cast(detail::Cast_Helper >::cast(t_derived)); if (!data) { throw std::bad_cast(); @@ -96,8 +96,8 @@ namespace chaiscript return Boxed_Value(data); } else { - boost::shared_ptr data - = boost::dynamic_pointer_cast(detail::Cast_Helper >::cast(t_derived)); + std::shared_ptr data + = std::dynamic_pointer_cast(detail::Cast_Helper >::cast(t_derived)); if (!data) { @@ -136,9 +136,9 @@ namespace chaiscript } template - static boost::shared_ptr create() + static std::shared_ptr create() { - boost::shared_ptr conversion(new Dynamic_Conversion_Impl()); + std::shared_ptr conversion(new Dynamic_Conversion_Impl()); /// \todo this is a hack and a kludge. The idea is to make sure that /// the conversion is registered both in the module's notion of the static conversion object @@ -165,7 +165,7 @@ namespace chaiscript } } - void add_conversion(const boost::shared_ptr &conversion) + void add_conversion(const std::shared_ptr &conversion) { chaiscript::detail::threading::unique_lock l(m_mutex); @@ -219,7 +219,7 @@ namespace chaiscript }; } - typedef boost::shared_ptr Dynamic_Cast_Conversion; + typedef std::shared_ptr Dynamic_Cast_Conversion; /// \brief Used to register a base / parent class relationship with ChaiScript. Necessary if you /// want automatic conversions up your inheritance hierarchy. diff --git a/include/chaiscript/dispatchkit/exception_specification.hpp b/include/chaiscript/dispatchkit/exception_specification.hpp index 4c0d19a8..ff169c37 100644 --- a/include/chaiscript/dispatchkit/exception_specification.hpp +++ b/include/chaiscript/dispatchkit/exception_specification.hpp @@ -128,7 +128,7 @@ namespace chaiscript /// /// \sa chaiscript::exception_specification for creation of chaiscript::Exception_Handler objects /// \sa \ref exceptions - typedef boost::shared_ptr Exception_Handler; + typedef std::shared_ptr Exception_Handler; /// \brief creates a chaiscript::Exception_Handler which handles one type of exception unboxing /// \sa \ref exceptions diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index 49a877ae..e7e7b91f 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -95,8 +95,8 @@ namespace chaiscript { if (funcs.size() == 1) { - boost::shared_ptr > pfi = - boost::dynamic_pointer_cast > + std::shared_ptr > pfi = + std::dynamic_pointer_cast > (funcs[0]); if (pfi) diff --git a/include/chaiscript/dispatchkit/handle_return.hpp b/include/chaiscript/dispatchkit/handle_return.hpp index e9c3261e..70cc02ee 100644 --- a/include/chaiscript/dispatchkit/handle_return.hpp +++ b/include/chaiscript/dispatchkit/handle_return.hpp @@ -44,27 +44,27 @@ namespace chaiscript }; template - struct Handle_Return &> + struct Handle_Return &> { - static Boxed_Value handle(const boost::shared_ptr &r) + static Boxed_Value handle(const std::shared_ptr &r) { return Boxed_Value(r); } }; template - struct Handle_Return > + struct Handle_Return > { - static Boxed_Value handle(const boost::shared_ptr &r) + static Boxed_Value handle(const std::shared_ptr &r) { return Boxed_Value(r); } }; template - struct Handle_Return &> + struct Handle_Return &> { - static Boxed_Value handle(const boost::shared_ptr &r) + static Boxed_Value handle(const std::shared_ptr &r) { return Boxed_Value(r); } diff --git a/include/chaiscript/dispatchkit/proxy_constructors.hpp b/include/chaiscript/dispatchkit/proxy_constructors.hpp index fcd019be..6c6e542c 100644 --- a/include/chaiscript/dispatchkit/proxy_constructors.hpp +++ b/include/chaiscript/dispatchkit/proxy_constructors.hpp @@ -55,9 +55,9 @@ namespace chaiscript * of a given type with a given set of params */ template - boost::shared_ptr constructor_( BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) ) + std::shared_ptr constructor_( BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) ) { - return boost::shared_ptr(new Class( BOOST_PP_ENUM_PARAMS(n, p) )); + return std::shared_ptr(new Class( BOOST_PP_ENUM_PARAMS(n, p) )); } /** @@ -69,7 +69,7 @@ namespace chaiscript template Proxy_Function build_constructor_(Class (*)(BOOST_PP_ENUM_PARAMS(n, Param))) { - typedef boost::shared_ptr (sig)(BOOST_PP_ENUM_PARAMS(n, Param)); + typedef std::shared_ptr (sig)(BOOST_PP_ENUM_PARAMS(n, Param)); return Proxy_Function(new Proxy_Function_Impl(boost::function(&(constructor_)))); } } diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index b6bb7e0a..300a021a 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -23,7 +23,7 @@ namespace chaiscript class Boxed_Number; struct AST_Node; - typedef boost::shared_ptr AST_NodePtr; + typedef std::shared_ptr AST_NodePtr; namespace dispatch @@ -87,9 +87,9 @@ namespace chaiscript virtual bool operator==(const Proxy_Function_Base &) const = 0; virtual bool call_match(const std::vector &vals) const = 0; - virtual std::vector > get_contained_functions() const + virtual std::vector > get_contained_functions() const { - return std::vector >(); + return std::vector >(); } @@ -142,7 +142,7 @@ namespace chaiscript && (ti.bare_equal(user_type()) || ti.bare_equal(bv.get_type_info()) || chaiscript::detail::dynamic_cast_converts(ti, bv.get_type_info()) - || bv.get_type_info().bare_equal(user_type >()) + || bv.get_type_info().bare_equal(user_type >()) ) ) ) @@ -176,11 +176,11 @@ namespace chaiscript } /// \brief Common typedef used for passing of any registered function in ChaiScript - typedef boost::shared_ptr Proxy_Function; + typedef std::shared_ptr Proxy_Function; /// \brief Const version of Proxy_Function chaiscript. Points to a const Proxy_Function. This is how most registered functions /// are handled internally. - typedef boost::shared_ptr Const_Proxy_Function; + typedef std::shared_ptr Const_Proxy_Function; namespace exception { diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index 8bd0b9a7..d1f7be52 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -157,7 +157,7 @@ namespace chaiscript }; template - struct Get_Type_Info > + struct Get_Type_Info > { typedef T type; @@ -166,13 +166,13 @@ namespace chaiscript return Type_Info(boost::is_const::value, boost::is_reference::value, boost::is_pointer::value, boost::is_void::value, boost::is_arithmetic::value && !boost::is_same::type, bool>::value, - &typeid(boost::shared_ptr ), + &typeid(std::shared_ptr ), &typeid(typename Bare_Type::type)); } }; template - struct Get_Type_Info &> + struct Get_Type_Info &> { typedef T type; @@ -181,7 +181,7 @@ namespace chaiscript return Type_Info(boost::is_const::value, boost::is_reference::value, boost::is_pointer::value, boost::is_void::value, boost::is_arithmetic::value && !boost::is_same::type, bool>::value, - &typeid(const boost::shared_ptr &), + &typeid(const std::shared_ptr &), &typeid(typename Bare_Type::type)); } }; diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 7b21f52a..40c4e8ee 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -55,7 +55,7 @@ namespace chaiscript }; /// \brief Typedef for pointers to AST_Node objects. Used in building of the AST_Node tree - typedef boost::shared_ptr AST_NodePtr; + typedef std::shared_ptr AST_NodePtr; /// \brief Classes which may be thrown during error cases when ChaiScript is executing. @@ -106,7 +106,7 @@ namespace chaiscript public: const std::string text; const int identifier; - boost::shared_ptr filename; + std::shared_ptr filename; File_Position start, end; std::vector children; AST_NodePtr annotation; @@ -147,14 +147,14 @@ namespace chaiscript } protected: - AST_Node(const std::string &t_ast_node_text, int t_id, const boost::shared_ptr &t_fname, + AST_Node(const std::string &t_ast_node_text, int t_id, const std::shared_ptr &t_fname, int t_start_line, int t_start_col, int t_end_line, int t_end_col) : text(t_ast_node_text), identifier(t_id), filename(t_fname), start(t_start_line, t_start_col), end(t_end_line, t_end_col) { } - AST_Node(const std::string &t_ast_node_text, int t_id, const boost::shared_ptr &t_fname) : + AST_Node(const std::string &t_ast_node_text, int t_id, const std::shared_ptr &t_fname) : text(t_ast_node_text), identifier(t_id), filename(t_fname) {} virtual ~AST_Node() {} diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 86246db4..1b866d87 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -231,7 +231,7 @@ namespace chaiscript #endif #endif - typedef boost::shared_ptr Loadable_Module_Ptr; + typedef std::shared_ptr Loadable_Module_Ptr; } diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index bd2ee1ae..15cc6e7a 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -38,7 +38,7 @@ namespace chaiscript struct Binary_Operator_AST_Node : public AST_Node { public: - Binary_Operator_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_Xor, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Binary_Operator_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_Xor, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } @@ -75,7 +75,7 @@ namespace chaiscript struct Error_AST_Node : public AST_Node { public: - Error_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Error, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Error_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Error, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Error_AST_Node() {} @@ -83,7 +83,7 @@ namespace chaiscript struct Int_AST_Node : public AST_Node { public: - Int_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Int, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Int_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Int, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col), m_value(const_var(int(atoi(t_ast_node_text.c_str())))) { } virtual ~Int_AST_Node() {} @@ -98,7 +98,7 @@ namespace chaiscript struct Float_AST_Node : public AST_Node { public: - Float_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Float, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Float_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Float, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col), m_value(const_var(double(atof(t_ast_node_text.c_str())))) { } virtual ~Float_AST_Node() {} @@ -113,7 +113,7 @@ namespace chaiscript struct Id_AST_Node : public AST_Node { public: - Id_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Id, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Id_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Id, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col), m_value(get_value(t_ast_node_text)) { } @@ -157,28 +157,28 @@ namespace chaiscript struct Char_AST_Node : public AST_Node { public: - Char_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Char, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Char_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Char, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Char_AST_Node() {} }; struct Str_AST_Node : public AST_Node { public: - Str_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Str, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Str_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Str, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Str_AST_Node() {} }; struct Eol_AST_Node : public AST_Node { public: - Eol_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Eol, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Eol_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Eol, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Eol_AST_Node() {} }; struct Fun_Call_AST_Node : public AST_Node { public: - Fun_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Fun_Call, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Fun_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Fun_Call, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Fun_Call_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -226,7 +226,7 @@ namespace chaiscript struct Inplace_Fun_Call_AST_Node : public AST_Node { public: - Inplace_Fun_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inplace_Fun_Call, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Inplace_Fun_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inplace_Fun_Call, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Inplace_Fun_Call_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -256,21 +256,21 @@ namespace chaiscript struct Arg_List_AST_Node : public AST_Node { public: - Arg_List_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Arg_List, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Arg_List_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Arg_List, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Arg_List_AST_Node() {} }; struct Variable_AST_Node : public AST_Node { public: - Variable_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Variable, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Variable_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Variable, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Variable_AST_Node() {} }; struct Equation_AST_Node : public AST_Node { public: - Equation_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Equation, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Equation_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Equation, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) {} @@ -331,7 +331,7 @@ namespace chaiscript struct Var_Decl_AST_Node : public AST_Node { public: - Var_Decl_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Var_Decl, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Var_Decl_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Var_Decl, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Var_Decl_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -348,7 +348,7 @@ namespace chaiscript struct Comparison_AST_Node : public Binary_Operator_AST_Node { public: - Comparison_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Comparison, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Comparison_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Comparison, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Comparison_AST_Node() {} }; @@ -356,7 +356,7 @@ namespace chaiscript struct Addition_AST_Node : public Binary_Operator_AST_Node { public: Addition_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Addition, - const boost::shared_ptr &t_fname=boost::shared_ptr(), + const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Addition_AST_Node() {} @@ -368,7 +368,7 @@ namespace chaiscript struct Subtraction_AST_Node : public Binary_Operator_AST_Node { public: Subtraction_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Subtraction, - const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, + const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Subtraction_AST_Node() {} @@ -380,7 +380,7 @@ namespace chaiscript struct Multiplication_AST_Node : public Binary_Operator_AST_Node { public: Multiplication_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Multiplication, - const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, + const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Multiplication_AST_Node() {} @@ -392,7 +392,7 @@ namespace chaiscript struct Division_AST_Node : public Binary_Operator_AST_Node { public: Division_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Division, - const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, + const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Division_AST_Node() {} @@ -404,7 +404,7 @@ namespace chaiscript struct Modulus_AST_Node : public Binary_Operator_AST_Node { public: Modulus_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Modulus, - const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, + const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Modulus_AST_Node() {} @@ -415,7 +415,7 @@ namespace chaiscript struct Array_Call_AST_Node : public AST_Node { public: - Array_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Array_Call, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Array_Call_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Array_Call, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Array_Call_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -439,7 +439,7 @@ namespace chaiscript struct Dot_Access_AST_Node : public AST_Node { public: - Dot_Access_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Dot_Access, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Dot_Access_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Dot_Access, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Dot_Access_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -507,7 +507,7 @@ namespace chaiscript struct Quoted_String_AST_Node : public AST_Node { public: - Quoted_String_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Quoted_String, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Quoted_String_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Quoted_String, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col), m_value(const_var(t_ast_node_text)) { } virtual ~Quoted_String_AST_Node() {} @@ -522,7 +522,7 @@ namespace chaiscript struct Single_Quoted_String_AST_Node : public AST_Node { public: - Single_Quoted_String_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Single_Quoted_String, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Single_Quoted_String_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Single_Quoted_String, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col), m_value(const_var(char(t_ast_node_text.at(0)))) { } virtual ~Single_Quoted_String_AST_Node() {} @@ -536,7 +536,7 @@ namespace chaiscript struct Lambda_AST_Node : public AST_Node { public: - Lambda_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Lambda, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Lambda_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Lambda, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Lambda_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -564,7 +564,7 @@ namespace chaiscript struct Block_AST_Node : public AST_Node { public: - Block_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Block, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Block_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Block, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Block_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -593,7 +593,7 @@ namespace chaiscript struct Def_AST_Node : public AST_Node { public: - Def_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Def, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Def_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Def, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Def_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -620,9 +620,9 @@ namespace chaiscript } } - boost::shared_ptr guard; + std::shared_ptr guard; if (guardnode) { - guard = boost::shared_ptr + guard = std::shared_ptr (new dispatch::Dynamic_Proxy_Function(boost::bind(chaiscript::eval::detail::eval_function, boost::ref(t_ss), guardnode, t_param_names, _1), static_cast(numparams), guardnode)); @@ -647,7 +647,7 @@ namespace chaiscript struct While_AST_Node : public AST_Node { public: - While_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::While, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + While_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::While, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~While_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) { @@ -683,7 +683,7 @@ namespace chaiscript struct If_AST_Node : public AST_Node { public: - If_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::If, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + If_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::If, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~If_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -728,7 +728,7 @@ namespace chaiscript struct For_AST_Node : public AST_Node { public: - For_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::For, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + For_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::For, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~For_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -778,7 +778,7 @@ namespace chaiscript struct Inline_Array_AST_Node : public AST_Node { public: - Inline_Array_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Array, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Inline_Array_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Array, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Inline_Array_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -796,7 +796,7 @@ namespace chaiscript struct Inline_Map_AST_Node : public AST_Node { public: - Inline_Map_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Map, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Inline_Map_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Map, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Inline_Map_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -817,7 +817,7 @@ namespace chaiscript struct Return_AST_Node : public AST_Node { public: - Return_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Return, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Return_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Return, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Return_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -833,7 +833,7 @@ namespace chaiscript struct File_AST_Node : public AST_Node { public: - File_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::File, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + File_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::File, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~File_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) { @@ -850,7 +850,7 @@ namespace chaiscript struct Prefix_AST_Node : public AST_Node { public: - Prefix_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Prefix, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Prefix_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Prefix, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } @@ -875,7 +875,7 @@ namespace chaiscript struct Break_AST_Node : public AST_Node { public: - Break_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Break, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Break_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Break, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Break_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &){ @@ -885,21 +885,21 @@ namespace chaiscript struct Map_Pair_AST_Node : public AST_Node { public: - Map_Pair_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Map_Pair, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Map_Pair_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Map_Pair, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Map_Pair_AST_Node() {} }; struct Value_Range_AST_Node : public AST_Node { public: - Value_Range_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Value_Range, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Value_Range_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Value_Range, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Value_Range_AST_Node() {} }; struct Inline_Range_AST_Node : public AST_Node { public: - Inline_Range_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Range, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Inline_Range_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Range, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Inline_Range_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -917,14 +917,14 @@ namespace chaiscript struct Annotation_AST_Node : public AST_Node { public: - Annotation_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Annotation, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Annotation_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Annotation, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Annotation_AST_Node() {} }; struct Try_AST_Node : public AST_Node { public: - Try_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Try, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Try_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Try, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Try_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -1051,21 +1051,21 @@ namespace chaiscript struct Catch_AST_Node : public AST_Node { public: - Catch_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Catch, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Catch_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Catch, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Catch_AST_Node() {} }; struct Finally_AST_Node : public AST_Node { public: - Finally_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Finally, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Finally_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Finally, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Finally_AST_Node() {} }; struct Method_AST_Node : public AST_Node { public: - Method_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Method, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Method_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Method, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Method_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -1095,9 +1095,9 @@ namespace chaiscript size_t numparams = t_param_names.size(); - boost::shared_ptr guard; + std::shared_ptr guard; if (guardnode) { - guard = boost::shared_ptr + guard = std::shared_ptr (new dispatch::Dynamic_Proxy_Function(boost::bind(chaiscript::eval::detail::eval_function, boost::ref(t_ss), guardnode, t_param_names, _1), static_cast(numparams), guardnode)); @@ -1142,7 +1142,7 @@ namespace chaiscript struct Attr_Decl_AST_Node : public AST_Node { public: - Attr_Decl_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Attr_Decl, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Attr_Decl_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Attr_Decl, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Attr_Decl_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -1161,42 +1161,42 @@ namespace chaiscript struct Shift_AST_Node : public Binary_Operator_AST_Node { public: - Shift_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Shift, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Shift_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Shift, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Shift_AST_Node() {} }; struct Equality_AST_Node : public Binary_Operator_AST_Node { public: - Equality_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Equality, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Equality_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Equality, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Equality_AST_Node() {} }; struct Bitwise_And_AST_Node : public Binary_Operator_AST_Node { public: - Bitwise_And_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_And, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Bitwise_And_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_And, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Bitwise_And_AST_Node() {} }; struct Bitwise_Xor_AST_Node : public Binary_Operator_AST_Node { public: - Bitwise_Xor_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_Xor, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Bitwise_Xor_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_Xor, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Bitwise_Xor_AST_Node() {} }; struct Bitwise_Or_AST_Node : public Binary_Operator_AST_Node { public: - Bitwise_Or_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_Or, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Bitwise_Or_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Bitwise_Or, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Binary_Operator_AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Bitwise_Or_AST_Node() {} }; struct Logical_And_AST_Node : public AST_Node { public: - Logical_And_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Logical_And, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Logical_And_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Logical_And, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Logical_And_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ @@ -1225,7 +1225,7 @@ namespace chaiscript struct Logical_Or_AST_Node : public AST_Node { public: - Logical_Or_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Logical_Or, const boost::shared_ptr &t_fname=boost::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Logical_Or_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Logical_Or, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Logical_Or_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 8db4b2e9..aa10437d 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -45,7 +45,7 @@ namespace chaiscript std::string m_multiline_comment_begin; std::string m_multiline_comment_end; std::string m_singleline_comment; - boost::shared_ptr m_filename; + std::shared_ptr m_filename; std::vector m_match_stack; bool m_alphabet[detail::max_alphabet][detail::lengthof_alphabet]; @@ -1978,7 +1978,7 @@ namespace chaiscript m_input_end = t_input.end(); m_line = 1; m_col = 1; - m_filename = boost::shared_ptr(new std::string(t_fname)); + m_filename = std::shared_ptr(new std::string(t_fname)); if ((t_input.size() > 1) && (t_input[0] == '#') && (t_input[1] == '!')) { while ((m_input_pos != m_input_end) && (!Eol())) { diff --git a/samples/example.cpp b/samples/example.cpp index 51ef10aa..5b3cbbf0 100644 --- a/samples/example.cpp +++ b/samples/example.cpp @@ -61,7 +61,7 @@ struct System } }; -void take_shared_ptr(const boost::shared_ptr &p) +void take_shared_ptr(const std::shared_ptr &p) { std::cout << *p << std::endl; } @@ -143,7 +143,7 @@ int main(int /*argc*/, char * /*argv*/[]) { log("Functor test output", boost::lexical_cast(x)); - chai.add(var(boost::shared_ptr()), "nullvar"); + chai.add(var(std::shared_ptr()), "nullvar"); chai("print(\"This should be true.\"); print(nullvar.is_var_null())"); // test the global const action diff --git a/src/multithreaded.cpp b/src/multithreaded.cpp index 52c9fbe0..03e18b50 100644 --- a/src/multithreaded.cpp +++ b/src/multithreaded.cpp @@ -25,11 +25,11 @@ int main(int argc, char *argv[]) { //chai.add_shared_object(chaiscript::Boxed_Value(10000), "num_iterations"); - std::vector > threads; + std::vector > threads; for (int i = 0; i < argc - 1; ++i) { - threads.push_back(boost::shared_ptr(new boost::thread(boost::bind(do_work, boost::ref(chai))))); + threads.push_back(std::shared_ptr(new boost::thread(boost::bind(do_work, boost::ref(chai))))); } for (int i = 0; i < argc - 1; ++i) diff --git a/src/reflection.cpp b/src/reflection.cpp index 813362f1..d4657877 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -14,8 +14,8 @@ bool has_parse_tree(const chaiscript::Const_Proxy_Function &t_pf) { - boost::shared_ptr pf - = boost::dynamic_pointer_cast(t_pf); + std::shared_ptr pf + = std::dynamic_pointer_cast(t_pf); if (pf) { return pf->get_parse_tree(); @@ -26,8 +26,8 @@ bool has_parse_tree(const chaiscript::Const_Proxy_Function &t_pf) chaiscript::AST_NodePtr get_parse_tree(const chaiscript::Const_Proxy_Function &t_pf) { - boost::shared_ptr pf - = boost::dynamic_pointer_cast(t_pf); + std::shared_ptr pf + = std::dynamic_pointer_cast(t_pf); if (pf) { if (pf->get_parse_tree()) @@ -50,7 +50,7 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect m->add(chaiscript::fun(&get_parse_tree), "get_parse_tree"); - chaiscript::bootstrap::standard_library::vector_type > >("AST_NodeVector", m); + chaiscript::bootstrap::standard_library::vector_type > >("AST_NodeVector", m); CHAISCRIPT_CLASS_NO_CONSTRUCTOR( m, chaiscript::exception::eval_error, diff --git a/unittests/boxed_cast_test.cpp b/unittests/boxed_cast_test.cpp index 2e6edd9f..5d5a5db3 100644 --- a/unittests/boxed_cast_test.cpp +++ b/unittests/boxed_cast_test.cpp @@ -70,14 +70,14 @@ bool do_test(const Boxed_Value &bv, bool T, bool ConstT, bool TRef, bool ConstTR passed &= test_type_conversion(bv, ConstTPtr); passed &= test_type_conversion(bv, TPtrConst); passed &= test_type_conversion(bv, ConstTPtrConst); - passed &= test_type_conversion >(bv, SharedPtrT); - passed &= test_type_conversion >(bv, SharedConstPtrT); - passed &= test_type_conversion &>(bv, false); - passed &= test_type_conversion &>(bv, false); - passed &= test_type_conversion >(bv, ConstSharedPtrT); - passed &= test_type_conversion >(bv, ConstSharedConstPtrT); - passed &= test_type_conversion &>(bv, ConstSharedPtrTRef); - passed &= test_type_conversion &>(bv, ConstSharedPtrTConstRef); + passed &= test_type_conversion >(bv, SharedPtrT); + passed &= test_type_conversion >(bv, SharedConstPtrT); + passed &= test_type_conversion &>(bv, false); + passed &= test_type_conversion &>(bv, false); + passed &= test_type_conversion >(bv, ConstSharedPtrT); + passed &= test_type_conversion >(bv, ConstSharedConstPtrT); + passed &= test_type_conversion &>(bv, ConstSharedPtrTRef); + passed &= test_type_conversion &>(bv, ConstSharedPtrTConstRef); passed &= test_type_conversion >(bv, BoostRef); passed &= test_type_conversion >(bv, BoostConstRef); passed &= test_type_conversion &>(bv, false); @@ -205,7 +205,7 @@ bool built_in_type_test(const T &initial, bool ispod) /** shared_ptr tests **/ - boost::shared_ptr ip(new T(initial)); + std::shared_ptr ip(new T(initial)); passed &= do_test(var(ip), true, true, true, true, true, true, true, true, true, true, @@ -220,7 +220,7 @@ bool built_in_type_test(const T &initial, bool ispod) ispod && true, ispod && true, ispod && true, false, true); /** const shared_ptr tests **/ - boost::shared_ptr ipc(new T(initial)); + std::shared_ptr ipc(new T(initial)); passed &= do_test(var(ipc), true, true, false, true, false, true, false, true, false, true, diff --git a/unittests/multifile_test_chai.cpp b/unittests/multifile_test_chai.cpp index 57b89528..154062c9 100644 --- a/unittests/multifile_test_chai.cpp +++ b/unittests/multifile_test_chai.cpp @@ -6,7 +6,7 @@ Multi_Test_Chai::Multi_Test_Chai() } -boost::shared_ptr Multi_Test_Chai::get_chai() +std::shared_ptr Multi_Test_Chai::get_chai() { return m_chai; } diff --git a/unittests/multifile_test_chai.hpp b/unittests/multifile_test_chai.hpp index 430b6bc5..c2e306d5 100644 --- a/unittests/multifile_test_chai.hpp +++ b/unittests/multifile_test_chai.hpp @@ -5,10 +5,10 @@ class Multi_Test_Chai public: Multi_Test_Chai(); - boost::shared_ptr get_chai(); + std::shared_ptr get_chai(); private: - boost::shared_ptr m_chai; + std::shared_ptr m_chai; }; diff --git a/unittests/multifile_test_main.cpp b/unittests/multifile_test_main.cpp index 8352ec8b..94bbb6f9 100644 --- a/unittests/multifile_test_main.cpp +++ b/unittests/multifile_test_main.cpp @@ -8,7 +8,7 @@ int main() Multi_Test_Chai chaitest; Multi_Test_Module chaimodule; - boost::shared_ptr chai = chaitest.get_chai(); + std::shared_ptr chai = chaitest.get_chai(); chai->add(chaimodule.get_module()); return chai->eval("get_module_value()"); } From e2da56f19979a25cea8d884b6604dadac078e625 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 10 Sep 2011 07:24:46 -0600 Subject: [PATCH 002/108] Eliminate use of boost::shared_ptr --- include/chaiscript/dispatchkit/bootstrap.hpp | 4 ++-- include/chaiscript/dispatchkit/boxed_cast_helper.hpp | 2 +- include/chaiscript/dispatchkit/boxed_value.hpp | 2 +- include/chaiscript/language/chaiscript_common.hpp | 2 +- src/reflection.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 5427ac8c..0129471a 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -151,7 +151,7 @@ namespace chaiscript std::shared_ptr::type> shared_ptr_unconst_clone(const std::shared_ptr::type> &p) { - return boost::const_pointer_cast::type>(p); + return std::const_pointer_cast::type>(p); } @@ -286,7 +286,7 @@ namespace chaiscript std::shared_ptr pf = std::dynamic_pointer_cast(t_pf); if (pf) { - return pf->get_guard(); + return bool(pf->get_guard()); } else { return false; } diff --git a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp index c6e83389..3a618621 100644 --- a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp @@ -156,7 +156,7 @@ namespace chaiscript { if (!ob.get_type_info().is_const()) { - return boost::const_pointer_cast(boost::any_cast >(ob.get())); + return std::const_pointer_cast(boost::any_cast >(ob.get())); } else { return boost::any_cast >(ob.get()); } diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 6eb1eac5..087ecf50 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -323,7 +323,7 @@ namespace chaiscript template Boxed_Value const_var_impl(const std::shared_ptr &t) { - return Boxed_Value( boost::const_pointer_cast::type>(t) ); + return Boxed_Value( std::const_pointer_cast::type>(t) ); } /// \brief Takes a boost::reference_wrapper value, adds const to the referenced type and returns an immutable Boxed_Value. diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 40c4e8ee..727c242d 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -102,7 +102,7 @@ namespace chaiscript /// \brief Struct that doubles as both a parser ast_node and an AST node. - struct AST_Node : boost::enable_shared_from_this { + struct AST_Node : std::enable_shared_from_this { public: const std::string text; const int identifier; diff --git a/src/reflection.cpp b/src/reflection.cpp index d4657877..d38c0b09 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -18,7 +18,7 @@ bool has_parse_tree(const chaiscript::Const_Proxy_Function &t_pf) = std::dynamic_pointer_cast(t_pf); if (pf) { - return pf->get_parse_tree(); + return bool(pf->get_parse_tree()); } else { return false; } From c842bf14c10f2f2fba7d6d836972ac9ce3c995d2 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 10 Sep 2011 09:37:40 -0600 Subject: [PATCH 003/108] Move from boost::function to std::function --- include/chaiscript/chaiscript.hpp | 8 ++-- include/chaiscript/dispatchkit/bind_first.hpp | 20 +++++----- include/chaiscript/dispatchkit/bootstrap.hpp | 4 +- .../chaiscript/dispatchkit/bootstrap_stl.hpp | 10 ++--- include/chaiscript/dispatchkit/boxed_cast.hpp | 8 ++-- .../chaiscript/dispatchkit/function_call.hpp | 38 +++++++++---------- .../dispatchkit/function_call_detail.hpp | 2 +- .../dispatchkit/proxy_constructors.hpp | 2 +- .../dispatchkit/proxy_functions.hpp | 14 +++---- .../dispatchkit/proxy_functions_detail.hpp | 6 +-- .../dispatchkit/register_function.hpp | 12 +++--- .../chaiscript/language/chaiscript_eval.hpp | 2 +- samples/example.cpp | 14 +++---- src/main.cpp | 6 +-- unittests/functor_cast_test.cpp | 2 +- unittests/functor_creation_test.cpp | 6 +-- 16 files changed, 77 insertions(+), 77 deletions(-) diff --git a/include/chaiscript/chaiscript.hpp b/include/chaiscript/chaiscript.hpp index 56611f38..3e225b79 100644 --- a/include/chaiscript/chaiscript.hpp +++ b/include/chaiscript/chaiscript.hpp @@ -377,10 +377,10 @@ /// \subsection functionobjects Function Objects /// /// Functions are first class objects in Chaiscript and ChaiScript supports automatic conversion -/// between ChaiScript functions and boost::function objects. +/// between ChaiScript functions and std::function objects. /// /// \code -/// void callafunc(const boost::function &t_func) +/// void callafunc(const std::function &t_func) /// { /// t_func("bob"); /// } @@ -390,9 +390,9 @@ /// chaiscript::ChaiScript chai; /// chai.add(chaiscript::fun(&callafunc), "callafunc"); /// chai("callafunc(fun(x) { print(x); })"); // pass a lambda function to the registered function -/// // which expects a typed boost::function +/// // which expects a typed std::function /// -/// boost::function f = chai.eval >("dump_system"); +/// std::function f = chai.eval >("dump_system"); /// f(); // call the ChaiScript function dump_system, from C++ /// } /// \endcode diff --git a/include/chaiscript/dispatchkit/bind_first.hpp b/include/chaiscript/dispatchkit/bind_first.hpp index ae468f1a..12c09a00 100644 --- a/include/chaiscript/dispatchkit/bind_first.hpp +++ b/include/chaiscript/dispatchkit/bind_first.hpp @@ -37,9 +37,9 @@ namespace chaiscript /// /// \param[in] f method pointer to bind /// \param[in] o object to bind as first parameter - /// \returns a new boost::function object with one fewer parameters than the function passed in. + /// \returns a new std::function object with one fewer parameters than the function passed in. template - boost::function + std::function bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const O &o) { return boost::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); @@ -50,9 +50,9 @@ namespace chaiscript /// /// \param[in] f method pointer to bind /// \param[in] o object to bind as first parameter - /// \returns a new boost::function object with one fewer parameters than the function passed in. + /// \returns a new std::function object with one fewer parameters than the function passed in. template - boost::function + std::function bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)) const, const O &o) { return boost::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); @@ -63,23 +63,23 @@ namespace chaiscript /// /// \param[in] f method pointer to bind /// \param[in] o object to bind as first parameter - /// \returns a new boost::function object with one fewer parameters than the function passed in. + /// \returns a new std::function object with one fewer parameters than the function passed in. template - boost::function + std::function bind_first(Ret (*f)(BOOST_PP_ENUM_PARAMS(m, Param)), const O &o) { return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); } - /// \brief Helper function for binding the first parameter of a boost::function object. Used in chaiscript::fun overloads + /// \brief Helper function for binding the first parameter of a std::function object. Used in chaiscript::fun overloads /// that take 1 or 2 parameters to pre-bind to the function. /// /// \param[in] f method pointer to bind /// \param[in] o object to bind as first parameter - /// \returns a new boost::function object with one fewer parameters than the function passed in. + /// \returns a new std::function object with one fewer parameters than the function passed in. template - boost::function - bind_first(const boost::function &f, const O &o) + std::function + bind_first(const std::function &f, const O &o) { return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); } diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 0129471a..5aafd1b6 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -355,7 +355,7 @@ namespace chaiscript } template - static boost::function (const dispatch::Proxy_Function_Base*)> return_boxed_value_vector(const Function &f) + static std::function (const dispatch::Proxy_Function_Base*)> return_boxed_value_vector(const Function &f) { return boost::bind(&do_return_boxed_value_vector, f, _1); } @@ -388,7 +388,7 @@ namespace chaiscript m->add(constructor(), "runtime_error"); - m->add(fun(boost::function(&what)), "what"); + m->add(fun(std::function(&what)), "what"); m->add(user_type(), "Dynamic_Object"); m->add(constructor(), "Dynamic_Object"); diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 96710c09..0bb93b67 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -227,10 +227,10 @@ namespace chaiscript //In the interest of runtime safety for the m, we prefer the at() method for [] access, //to throw an exception in an out of bounds condition. m->add( - fun(boost::function + fun(std::function (boost::mem_fn(static_cast(&ContainerType::at)))), "[]"); m->add( - fun(boost::function + fun(std::function (boost::mem_fn(static_cast(&ContainerType::at)))), "[]"); return m; @@ -255,7 +255,7 @@ namespace chaiscript template ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { - m->add(fun(boost::function(boost::mem_fn(&ContainerType::size))), "size"); + m->add(fun(std::function(boost::mem_fn(&ContainerType::size))), "size"); m->add(fun(&ContainerType::empty), "empty"); m->add(fun(&ContainerType::clear), "clear"); @@ -390,7 +390,7 @@ namespace chaiscript template ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { - m->add(fun(boost::function(boost::mem_fn(&ContainerType::count))), "count"); + m->add(fun(std::function(boost::mem_fn(&ContainerType::count))), "count"); return m; } @@ -513,7 +513,7 @@ namespace chaiscript typedef typename String::size_type (String::*find_func_ptr)(const String &, typename String::size_type) const; - typedef boost::function find_func; + typedef std::function find_func; m->add(fun(find_func(boost::mem_fn(static_cast(&String::find)))), "find"); m->add(fun(find_func(boost::mem_fn(static_cast(&String::rfind)))), "rfind"); diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index ea188bb6..de4ccc30 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -32,7 +32,7 @@ namespace chaiscript /// \throws exception::bad_boxed_cast If the requested conversion is not possible /// /// boxed_cast will attempt to make conversions between value, &, *, std::shared_ptr, boost::reference_wrapper, - /// and boost::function (const and non-const) where possible. boxed_cast is used internally during function + /// and std::function (const and non-const) where possible. boxed_cast is used internally during function /// dispatch. This means that all of these conversions will be attempted automatically for you during /// ChaiScript function calls. /// @@ -43,7 +43,7 @@ namespace chaiscript /// \li Boxed_Value constructed from std::shared_ptr or value types can be extracted as reference, /// pointer, value, or std::shared_ptr types /// - /// Conversions to boost::function objects are attempted as well + /// Conversions to std::function objects are attempted as well /// /// Example: /// \code @@ -59,11 +59,11 @@ namespace chaiscript /// const int &cir = chaiscript::boxed_cast(bv); /// \endcode /// - /// boost::function conversion example + /// std::function conversion example /// \code /// chaiscript::ChaiScript chai; /// Boxed_Value bv = chai.eval("`+`"); // Get the functor for the + operator which is built in - /// boost::function f = chaiscript::boxed_cast >(bv); + /// std::function f = chaiscript::boxed_cast >(bv); /// int i = f(2,3); /// assert(i == 5); /// \endcode diff --git a/include/chaiscript/dispatchkit/function_call.hpp b/include/chaiscript/dispatchkit/function_call.hpp index 9dea81cf..ec62c4cf 100644 --- a/include/chaiscript/dispatchkit/function_call.hpp +++ b/include/chaiscript/dispatchkit/function_call.hpp @@ -25,13 +25,13 @@ namespace chaiscript /** * Build a function caller that knows how to dispatch on a set of functions * example: - * boost::function f = + * std::function f = * build_function_caller(dispatchkit.get_function("print")); - * \returns A boost::function object for dispatching + * \returns A std::function object for dispatching * \param[in] funcs the set of functions to dispatch on. */ template - boost::function + std::function functor(const std::vector &funcs) { FunctionType *p=0; @@ -45,14 +45,14 @@ namespace chaiscript * example: * void my_function(Proxy_Function f) * { - * boost::function local_f = + * std::function local_f = * build_function_caller(f); * } - * \returns A boost::function object for dispatching + * \returns A std::function object for dispatching * \param[in] func A function to execute. */ template - boost::function + std::function functor(Const_Proxy_Function func) { std::vector funcs; @@ -65,7 +65,7 @@ namespace chaiscript * and creating a typesafe C++ function caller from it. */ template - boost::function + std::function functor(const Boxed_Value &bv) { return functor(boxed_cast(bv)); @@ -74,12 +74,12 @@ namespace chaiscript namespace detail{ /** - * Cast helper to handle automatic casting to const boost::function & + * Cast helper to handle automatic casting to const std::function & */ template - struct Cast_Helper &> + struct Cast_Helper &> { - typedef boost::function Result_Type; + typedef std::function Result_Type; static Result_Type cast(const Boxed_Value &ob) { @@ -87,18 +87,18 @@ namespace chaiscript { return dispatch::functor(ob); } else { - return Cast_Helper_Inner &>::cast(ob); + return Cast_Helper_Inner &>::cast(ob); } } }; /** - * Cast helper to handle automatic casting to boost::function + * Cast helper to handle automatic casting to std::function */ template - struct Cast_Helper > + struct Cast_Helper > { - typedef boost::function Result_Type; + typedef std::function Result_Type; static Result_Type cast(const Boxed_Value &ob) { @@ -106,18 +106,18 @@ namespace chaiscript { return dispatch::functor(ob); } else { - return Cast_Helper_Inner >::cast(ob); + return Cast_Helper_Inner >::cast(ob); } } }; /** - * Cast helper to handle automatic casting to const boost::function + * Cast helper to handle automatic casting to const std::function */ template - struct Cast_Helper > + struct Cast_Helper > { - typedef boost::function Result_Type; + typedef std::function Result_Type; static Result_Type cast(const Boxed_Value &ob) { @@ -125,7 +125,7 @@ namespace chaiscript { return dispatch::functor(ob); } else { - return Cast_Helper_Inner >::cast(ob); + return Cast_Helper_Inner >::cast(ob); } } }; diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index e7e7b91f..23c4d20a 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -90,7 +90,7 @@ namespace chaiscript * used internally for unwrapping a function call's types */ template - boost::function + std::function build_function_caller_helper(Ret (BOOST_PP_ENUM_PARAMS(n, Param)), const std::vector &funcs) { if (funcs.size() == 1) diff --git a/include/chaiscript/dispatchkit/proxy_constructors.hpp b/include/chaiscript/dispatchkit/proxy_constructors.hpp index 6c6e542c..9fabd516 100644 --- a/include/chaiscript/dispatchkit/proxy_constructors.hpp +++ b/include/chaiscript/dispatchkit/proxy_constructors.hpp @@ -70,7 +70,7 @@ namespace chaiscript Proxy_Function build_constructor_(Class (*)(BOOST_PP_ENUM_PARAMS(n, Param))) { typedef std::shared_ptr (sig)(BOOST_PP_ENUM_PARAMS(n, Param)); - return Proxy_Function(new Proxy_Function_Impl(boost::function(&(constructor_)))); + return Proxy_Function(new Proxy_Function_Impl(std::function(&(constructor_)))); } } } diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 300a021a..e6f0e1a0 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -207,7 +207,7 @@ namespace chaiscript { public: Dynamic_Proxy_Function( - const boost::function &)> &t_f, + const std::function &)> &t_f, int t_arity=-1, const AST_NodePtr &t_parsenode = AST_NodePtr(), const std::string &t_description = "", @@ -304,7 +304,7 @@ namespace chaiscript return types; } - boost::function &)> m_f; + std::function &)> m_f; int m_arity; std::string m_description; Proxy_Function m_guard; @@ -440,14 +440,14 @@ namespace chaiscript /** * The standard typesafe function call implementation of Proxy_Function - * It takes a boost::function<> object and performs runtime + * It takes a std::function<> object and performs runtime * type checking of Boxed_Value parameters, in a type safe manner */ template class Proxy_Function_Impl : public Proxy_Function_Base { public: - Proxy_Function_Impl(const boost::function &f) + Proxy_Function_Impl(const std::function &f) : Proxy_Function_Base(detail::build_param_type_list(static_cast(0))), m_f(f), m_dummy_func(0) { @@ -483,7 +483,7 @@ namespace chaiscript return ""; } - boost::function internal_function() const + std::function internal_function() const { return m_f; } @@ -491,11 +491,11 @@ namespace chaiscript protected: virtual Boxed_Value do_call(const std::vector ¶ms) const { - return detail::Do_Call::result_type>::go(m_f, params); + return detail::Do_Call::result_type>::go(m_f, params); } private: - boost::function m_f; + std::function m_f; Func *m_dummy_func; }; diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index acd85d2b..235a9354 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -88,7 +88,7 @@ namespace chaiscript * the bad_boxed_cast is passed up to the caller. */ template - Ret call_func(const boost::function &f, + Ret call_func(const std::function &f, const std::vector ¶ms) { if (params.size() != n) @@ -137,7 +137,7 @@ namespace chaiscript struct Do_Call { template - static Boxed_Value go(const boost::function &fun, const std::vector ¶ms) + static Boxed_Value go(const std::function &fun, const std::vector ¶ms) { return Handle_Return::handle(call_func(fun, params)); } @@ -147,7 +147,7 @@ namespace chaiscript struct Do_Call { template - static Boxed_Value go(const boost::function &fun, const std::vector ¶ms) + static Boxed_Value go(const std::function &fun, const std::vector ¶ms) { call_func(fun, params); return Handle_Return::handle(); diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index 83e5687c..65a83ee9 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -31,7 +31,7 @@ namespace chaiscript return Proxy_Function( new Proxy_Function_Impl< typename boost::function_types::function_type >::type> ( - boost::function< + std::function< typename boost::function_types::function_type >::type >(t))); } @@ -46,7 +46,7 @@ namespace chaiscript return Proxy_Function( new Proxy_Function_Impl< typename boost::function_types::function_type >::type> ( - boost::function< + std::function< typename boost::function_types::function_type >::type >(boost::mem_fn(t)))); } @@ -65,19 +65,19 @@ namespace chaiscript } } - /// \brief Creates a new Proxy_Function object from a boost::function object - /// \param[in] f boost::function to expose to ChaiScript + /// \brief Creates a new Proxy_Function object from a std::function object + /// \param[in] f std::function to expose to ChaiScript /// /// \b Example: /// \code - /// boost::function f = get_some_function(); + /// std::function f = get_some_function(); /// chaiscript::ChaiScript chai; /// chai.add(fun(f), "some_function"); /// \endcode /// /// \sa \ref addingfunctions template - Proxy_Function fun(const boost::function &f) + Proxy_Function fun(const std::function &f) { return Proxy_Function(new dispatch::Proxy_Function_Impl(f)); } diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 15cc6e7a..7cef971c 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -1147,7 +1147,7 @@ namespace chaiscript virtual ~Attr_Decl_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ try { - t_ss.add(fun(boost::function(boost::bind(&dispatch::detail::Dynamic_Object_Attribute::func, this->children[0]->text, + t_ss.add(fun(std::function(boost::bind(&dispatch::detail::Dynamic_Object_Attribute::func, this->children[0]->text, this->children[1]->text, _1))), this->children[1]->text); } diff --git a/samples/example.cpp b/samples/example.cpp index 5b3cbbf0..2ea6e8be 100644 --- a/samples/example.cpp +++ b/samples/example.cpp @@ -40,7 +40,7 @@ void hello_constructor(const chaiscript::Boxed_Value & /*o*/) struct System { - std::map > m_callbacks; + std::map > m_callbacks; void add_callback(const std::string &t_name, const chaiscript::Proxy_Function &t_func) @@ -52,7 +52,7 @@ struct System void do_callbacks(const std::string &inp) { log("Running Callbacks: " + inp); - for (std::map >::iterator itr = m_callbacks.begin(); + for (std::map >::iterator itr = m_callbacks.begin(); itr != m_callbacks.end(); ++itr) { @@ -87,7 +87,7 @@ int main(int /*argc*/, char * /*argv*/[]) { // Let's use chaiscript to add a new lambda callback to our system. // The function "{ 'Callback1' + x }" is created in chaiscript and passed into our C++ application // in the "add_callback" function of struct System the chaiscript function is converted into a - // boost::function, so it can be handled and called easily and type-safely + // std::function, so it can be handled and called easily and type-safely chai.eval("system.add_callback(\"#1\", fun(x) { \"Callback1 \" + x });"); // Because we are sharing the "system" object with the chaiscript engine we have equal @@ -108,14 +108,14 @@ int main(int /*argc*/, char * /*argv*/[]) { // A shortcut to using eval is just to use the chai operator() chai("log(\"Test Module\", \"Test Message\");"); - //Finally, it is possible to register any boost::function as a system function, in this + //Finally, it is possible to register any std::function as a system function, in this //way, we can, for instance add a bound member function to the system chai.add(fun(&System::do_callbacks, boost::ref(system), std::string("Bound Test")), "do_callbacks"); //Call bound version of do_callbacks chai("do_callbacks()"); - boost::function caller = chai.eval >("fun() { system.do_callbacks(\"From Functor\"); }"); + std::function caller = chai.eval >("fun() { system.do_callbacks(\"From Functor\"); }"); caller(); @@ -139,7 +139,7 @@ int main(int /*argc*/, char * /*argv*/[]) { //To do: Add examples of handling Boxed_Values directly when needed //Creating a functor on the stack and using it immediatly - int x = chai.eval >("fun (x, y) { return x + y; }")(5, 6); + int x = chai.eval >("fun (x, y) { return x + y; }")(5, 6); log("Functor test output", boost::lexical_cast(x)); @@ -165,7 +165,7 @@ int main(int /*argc*/, char * /*argv*/[]) { //Dynamic objects test chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Function("TestType", fun(&hello_world))), "hello_world"); chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Constructor("TestType", fun(&hello_constructor))), "TestType"); - chai.add(fun(boost::function(boost::bind(&dispatch::detail::Dynamic_Object_Attribute::func, "TestType", "attr", _1))), "attr"); + chai.add(fun(std::function(boost::bind(&dispatch::detail::Dynamic_Object_Attribute::func, "TestType", "attr", _1))), "attr"); chai.eval("var x = TestType()"); // chai.eval("x.attr = \"hi\""); diff --git a/src/main.cpp b/src/main.cpp index bc833322..b1ca5390 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,7 +52,7 @@ void version(int){ std::cout << "chai: compiled " << __TIME__ << " " << __DATE__ << std::endl; } -bool throws_exception(const boost::function &f) +bool throws_exception(const std::function &f) { try { f(); @@ -63,7 +63,7 @@ bool throws_exception(const boost::function &f) return false; } -chaiscript::exception::eval_error get_eval_error(const boost::function &f) +chaiscript::exception::eval_error get_eval_error(const std::function &f) { try { f(); @@ -113,7 +113,7 @@ void interactive(chaiscript::ChaiScript& chai) //Then, we try to print the result of the evaluation to the user if (!val.get_type_info().bare_equal(chaiscript::user_type())) { try { - std::cout << chai.eval >("to_string")(val) << std::endl; + std::cout << chai.eval >("to_string")(val) << std::endl; } catch (...) {} //If we can't, do nothing } diff --git a/unittests/functor_cast_test.cpp b/unittests/functor_cast_test.cpp index 1f6f7ec1..7c76ca20 100644 --- a/unittests/functor_cast_test.cpp +++ b/unittests/functor_cast_test.cpp @@ -1,6 +1,6 @@ #include -double test_call(const boost::function &f, int val) +double test_call(const std::function &f, int val) { return f(val); } diff --git a/unittests/functor_creation_test.cpp b/unittests/functor_creation_test.cpp index 6578a6d5..6a78feef 100644 --- a/unittests/functor_creation_test.cpp +++ b/unittests/functor_creation_test.cpp @@ -7,15 +7,15 @@ int main() chai.eval("def func() { print(\"Hello World\"); } "); - boost::function f = chai.eval >("func"); + std::function f = chai.eval >("func"); f(); - if (chai.eval >("to_string")(6) != "6") + if (chai.eval >("to_string")(6) != "6") { return EXIT_FAILURE; } - if (chai.eval >("to_string")(chaiscript::var(6)) == "6") + if (chai.eval >("to_string")(chaiscript::var(6)) == "6") { return EXIT_SUCCESS; } else { From 53108463dfc4541901253d5d7ff938c6a2a7612d Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 10 Sep 2011 10:19:55 -0600 Subject: [PATCH 004/108] Move from boost::bind to std::bind --- include/chaiscript/dispatchkit/bind_first.hpp | 10 +++---- include/chaiscript/dispatchkit/bootstrap.hpp | 6 ++--- include/chaiscript/dispatchkit/boxed_cast.hpp | 6 ++--- .../dispatchkit/boxed_cast_helper.hpp | 1 - .../chaiscript/dispatchkit/boxed_value.hpp | 3 --- .../chaiscript/dispatchkit/dispatchkit.hpp | 1 - .../chaiscript/dispatchkit/function_call.hpp | 3 --- .../dispatchkit/function_call_detail.hpp | 7 ++--- .../dispatchkit/proxy_constructors.hpp | 3 --- .../dispatchkit/proxy_functions.hpp | 1 - .../dispatchkit/proxy_functions_detail.hpp | 2 -- .../dispatchkit/register_function.hpp | 2 -- include/chaiscript/dispatchkit/type_info.hpp | 2 +- .../language/chaiscript_algebraic.hpp | 1 - .../chaiscript/language/chaiscript_common.hpp | 1 - .../chaiscript/language/chaiscript_eval.hpp | 26 +++++++++---------- samples/example.cpp | 3 +-- src/multithreaded.cpp | 2 +- 18 files changed, 27 insertions(+), 53 deletions(-) diff --git a/include/chaiscript/dispatchkit/bind_first.hpp b/include/chaiscript/dispatchkit/bind_first.hpp index 12c09a00..06a64119 100644 --- a/include/chaiscript/dispatchkit/bind_first.hpp +++ b/include/chaiscript/dispatchkit/bind_first.hpp @@ -13,8 +13,6 @@ #ifndef CHAISCRIPT_BIND_FIRST_HPP_ #define CHAISCRIPT_BIND_FIRST_HPP_ -#include -#include #include #define BOOST_PP_ITERATION_LIMITS ( 0, 8 ) @@ -42,7 +40,7 @@ namespace chaiscript std::function bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const O &o) { - return boost::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); + return std::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, std::placeholders::_)); } /// \brief Helper function for binding the first parameter of a const class method pointer. Used in chaiscript::fun overloads @@ -55,7 +53,7 @@ namespace chaiscript std::function bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)) const, const O &o) { - return boost::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); + return std::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, std::placeholders::_)); } /// \brief Helper function for binding the first parameter of a function pointer. Used in chaiscript::fun overloads @@ -68,7 +66,7 @@ namespace chaiscript std::function bind_first(Ret (*f)(BOOST_PP_ENUM_PARAMS(m, Param)), const O &o) { - return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); + return std::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, std::placeholders::_)); } /// \brief Helper function for binding the first parameter of a std::function object. Used in chaiscript::fun overloads @@ -81,7 +79,7 @@ namespace chaiscript std::function bind_first(const std::function &f, const O &o) { - return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); + return std::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, std::placeholders::_)); } } diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 5aafd1b6..43da17dd 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -357,7 +357,7 @@ namespace chaiscript template static std::function (const dispatch::Proxy_Function_Base*)> return_boxed_value_vector(const Function &f) { - return boost::bind(&do_return_boxed_value_vector, f, _1); + return std::bind(&do_return_boxed_value_vector, f, std::placeholders::_1); } public: @@ -462,14 +462,14 @@ namespace chaiscript m->add(fun(&print), "print_string"); m->add(fun(&println), "println_string"); - m->add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(boost::bind(&bind_function, _1))), + m->add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(std::bind(&bind_function, std::placeholders::_1))), "bind"); m->add(fun(&shared_ptr_unconst_clone), "clone"); m->add(fun(&ptr_assign::type>), "="); m->add(fun(&ptr_assign::type>), "="); - m->add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(boost::bind(&call_exists, _1))), + m->add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(std::bind(&call_exists, std::placeholders::_1))), "call_exists"); m->add(fun(&type_match), "type_match"); diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index de4ccc30..be13422d 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -4,8 +4,8 @@ // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com -#ifndef __boxed_cast_hpp__ -#define __boxed_cast_hpp__ +#ifndef CHAISCRIPT_BOXED_CAST_HPP_ +#define CHAISCRIPT_BOXED_CAST_HPP_ #include "type_info.hpp" #include "boxed_value.hpp" @@ -13,9 +13,7 @@ #include "dynamic_cast_conversion.hpp" #include "../chaiscript_threading.hpp" -#include #include -#include #include #include #include diff --git a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp index 3a618621..2800c745 100644 --- a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp @@ -10,7 +10,6 @@ #include "type_info.hpp" #include "boxed_value.hpp" -#include #include #include #include diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 087ecf50..6d9a8f0a 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -12,11 +12,8 @@ #include "../chaiscript_threading.hpp" #include -#include #include -#include #include -#include #include #include #include diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index 0dd657ac..b9afa54a 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include diff --git a/include/chaiscript/dispatchkit/function_call.hpp b/include/chaiscript/dispatchkit/function_call.hpp index ec62c4cf..d98698a9 100644 --- a/include/chaiscript/dispatchkit/function_call.hpp +++ b/include/chaiscript/dispatchkit/function_call.hpp @@ -7,9 +7,6 @@ #ifndef CHAISCRIPT_FUNCTION_CALL_HPP_ #define CHAISCRIPT_FUNCTION_CALL_HPP_ -#include -#include -#include #include #include #include "proxy_functions.hpp" diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index 23c4d20a..c20049f7 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -7,16 +7,13 @@ #include #define addparam(z,n,text) params.push_back((boost::is_reference::value&&!(boost::is_same::type>::type>::value))?Boxed_Value(boost::ref(BOOST_PP_CAT(p, n))):Boxed_Value(BOOST_PP_CAT(p, n) )); -#define curry(z,n,text) BOOST_PP_CAT(_, BOOST_PP_INC(n)) +#define curry(z,n,text) BOOST_PP_CAT(std::placeholders::_, BOOST_PP_INC(n)) #ifndef BOOST_PP_IS_ITERATING #ifndef CHAISCRIPT_FUNCTION_CALL_DETAIL_HPP_ #define CHAISCRIPT_FUNCTION_CALL_DETAIL_HPP_ -#include -#include -#include #include #include #include "proxy_functions.hpp" @@ -107,7 +104,7 @@ namespace chaiscript // we cannot make any other guesses or assumptions really, so continuing } - return boost::bind(&function_caller, funcs + return std::bind(&function_caller, funcs BOOST_PP_ENUM_TRAILING(n, curry, ~)); } } diff --git a/include/chaiscript/dispatchkit/proxy_constructors.hpp b/include/chaiscript/dispatchkit/proxy_constructors.hpp index 9fabd516..b555489c 100644 --- a/include/chaiscript/dispatchkit/proxy_constructors.hpp +++ b/include/chaiscript/dispatchkit/proxy_constructors.hpp @@ -10,9 +10,6 @@ #ifndef CHAISCRIPT_PROXY_CONSTRUCTORS_HPP_ #define CHAISCRIPT_PROXY_CONSTRUCTORS_HPP_ -#include -#include -#include #define BOOST_PP_ITERATION_LIMITS ( 0, 10 ) diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index e6f0e1a0..df153723 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -12,7 +12,6 @@ #include "boxed_value.hpp" #include "type_info.hpp" #include -#include #include #include #include diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index 235a9354..ae697d2c 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -19,8 +19,6 @@ #include "type_info.hpp" #include "handle_return.hpp" #include -#include -#include #include #include diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index 65a83ee9..0c1f8e80 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -9,8 +9,6 @@ #include "dispatchkit.hpp" #include "bind_first.hpp" -#include -#include #include #include #include diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index d1f7be52..aed318cd 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include diff --git a/include/chaiscript/language/chaiscript_algebraic.hpp b/include/chaiscript/language/chaiscript_algebraic.hpp index 37cc0bac..fe76359a 100644 --- a/include/chaiscript/language/chaiscript_algebraic.hpp +++ b/include/chaiscript/language/chaiscript_algebraic.hpp @@ -8,7 +8,6 @@ #define CHAISCRIPT_ALGEBRAIC_HPP_ #include -#include namespace chaiscript { diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 727c242d..55d0203e 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -8,7 +8,6 @@ #define CHAISCRIPT_COMMON_HPP_ #include -#include namespace chaiscript { diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 7cef971c..55ed3737 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -556,7 +556,7 @@ namespace chaiscript } return Boxed_Value(Proxy_Function(new dispatch::Dynamic_Proxy_Function - (boost::bind(chaiscript::eval::detail::eval_function, boost::ref(t_ss), this->children.back(), t_param_names, _1), + (std::bind(chaiscript::eval::detail::eval_function, boost::ref(t_ss), this->children.back(), t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back()))); } @@ -623,18 +623,18 @@ namespace chaiscript std::shared_ptr guard; if (guardnode) { guard = std::shared_ptr - (new dispatch::Dynamic_Proxy_Function(boost::bind(chaiscript::eval::detail::eval_function, + (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, boost::ref(t_ss), guardnode, - t_param_names, _1), static_cast(numparams), guardnode)); + t_param_names, std::placeholders::_1), static_cast(numparams), guardnode)); } try { const std::string & l_function_name = this->children[0]->text; const std::string & l_annotation = this->annotation?this->annotation->text:""; t_ss.add(Proxy_Function - (new dispatch::Dynamic_Proxy_Function(boost::bind(chaiscript::eval::detail::eval_function, + (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, boost::ref(t_ss), this->children.back(), - t_param_names, _1), static_cast(numparams), this->children.back(), + t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back(), l_annotation, guard)), l_function_name); } catch (const exception::reserved_word_error &e) { @@ -1098,9 +1098,9 @@ namespace chaiscript std::shared_ptr guard; if (guardnode) { guard = std::shared_ptr - (new dispatch::Dynamic_Proxy_Function(boost::bind(chaiscript::eval::detail::eval_function, + (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, boost::ref(t_ss), guardnode, - t_param_names, _1), static_cast(numparams), guardnode)); + t_param_names, std::placeholders::_1), static_cast(numparams), guardnode)); } try { @@ -1110,9 +1110,9 @@ namespace chaiscript if (function_name == class_name) { t_ss.add(Proxy_Function (new dispatch::detail::Dynamic_Object_Constructor(class_name, Proxy_Function - (new dispatch::Dynamic_Proxy_Function(boost::bind(chaiscript::eval::detail::eval_function, + (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, boost::ref(t_ss), this->children.back(), - t_param_names, _1), static_cast(numparams), this->children.back(), + t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back(), l_annotation, guard)))), function_name); } @@ -1125,9 +1125,9 @@ namespace chaiscript } t_ss.add(Proxy_Function (new dispatch::detail::Dynamic_Object_Function(class_name, Proxy_Function - (new dispatch::Dynamic_Proxy_Function(boost::bind(chaiscript::eval::detail::eval_function, + (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, boost::ref(t_ss), this->children.back(), - t_param_names, _1), static_cast(numparams), this->children.back(), + t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back(), l_annotation, guard)), ti)), function_name); } @@ -1147,8 +1147,8 @@ namespace chaiscript virtual ~Attr_Decl_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ try { - t_ss.add(fun(std::function(boost::bind(&dispatch::detail::Dynamic_Object_Attribute::func, this->children[0]->text, - this->children[1]->text, _1))), this->children[1]->text); + t_ss.add(fun(std::function(std::bind(&dispatch::detail::Dynamic_Object_Attribute::func, this->children[0]->text, + this->children[1]->text, std::placeholders::_1))), this->children[1]->text); } catch (const exception::reserved_word_error &) { diff --git a/samples/example.cpp b/samples/example.cpp index 2ea6e8be..33d02343 100644 --- a/samples/example.cpp +++ b/samples/example.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include @@ -165,7 +164,7 @@ int main(int /*argc*/, char * /*argv*/[]) { //Dynamic objects test chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Function("TestType", fun(&hello_world))), "hello_world"); chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Constructor("TestType", fun(&hello_constructor))), "TestType"); - chai.add(fun(std::function(boost::bind(&dispatch::detail::Dynamic_Object_Attribute::func, "TestType", "attr", _1))), "attr"); + chai.add(fun(std::function(std::bind(&dispatch::detail::Dynamic_Object_Attribute::func, "TestType", "attr", std::placeholders::_1))), "attr"); chai.eval("var x = TestType()"); // chai.eval("x.attr = \"hi\""); diff --git a/src/multithreaded.cpp b/src/multithreaded.cpp index 03e18b50..c1eddd4e 100644 --- a/src/multithreaded.cpp +++ b/src/multithreaded.cpp @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) { for (int i = 0; i < argc - 1; ++i) { - threads.push_back(std::shared_ptr(new boost::thread(boost::bind(do_work, boost::ref(chai))))); + threads.push_back(std::shared_ptr(new boost::thread(std::bind(do_work, boost::ref(chai))))); } for (int i = 0; i < argc - 1; ++i) From aa402fdfdefe6501ee4cfae492075dd3ebfee886 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 10 Sep 2011 10:52:59 -0600 Subject: [PATCH 005/108] swap boost::reference_wrapper for std::reference_wrapper --- include/chaiscript/chaiscript.hpp | 6 +-- include/chaiscript/dispatchkit/boxed_cast.hpp | 4 +- .../dispatchkit/boxed_cast_helper.hpp | 39 ++++++++++--------- .../chaiscript/dispatchkit/boxed_value.hpp | 16 ++++---- .../dispatchkit/dynamic_cast_conversion.hpp | 4 +- .../dispatchkit/function_call_detail.hpp | 2 +- .../chaiscript/dispatchkit/handle_return.hpp | 6 +-- .../dispatchkit/register_function.hpp | 4 +- include/chaiscript/dispatchkit/type_info.hpp | 8 ++-- .../chaiscript/language/chaiscript_engine.hpp | 12 +++--- .../chaiscript/language/chaiscript_eval.hpp | 14 +++---- samples/example.cpp | 2 +- src/multithreaded.cpp | 2 +- unittests/boxed_cast_test.cpp | 24 ++++++------ 14 files changed, 72 insertions(+), 71 deletions(-) diff --git a/include/chaiscript/chaiscript.hpp b/include/chaiscript/chaiscript.hpp index 3e225b79..497c9c44 100644 --- a/include/chaiscript/chaiscript.hpp +++ b/include/chaiscript/chaiscript.hpp @@ -298,7 +298,7 @@ /// \subsection pointerconversions Pointer / Object Conversions /// /// As much as possible, ChaiScript attempts to convert between &, *, const &, const *, std::shared_ptr, -/// std::shared_ptr, boost::reference_wrapper, boost::reference_wrapper and value types automatically. +/// std::shared_ptr, std::reference_wrapper, std::reference_wrapper and value types automatically. /// /// If a chaiscript::var object was created in C++ from a pointer, it cannot be convered to a shared_ptr (this would add invalid reference counting). /// Const may be added, but never removed. @@ -315,8 +315,8 @@ /// void fun6(std::shared_ptr); /// void fun7(const std::shared_ptr &); /// void fun8(const std::shared_ptr &); -/// void fun9(boost::reference_wrapper); -/// void fun10(boost::reference_wrapper); +/// void fun9(std::reference_wrapper); +/// void fun10(std::reference_wrapper); /// /// int main() /// { diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index be13422d..59ccbfa8 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -29,14 +29,14 @@ namespace chaiscript /// \returns Type equivalent to the requested type /// \throws exception::bad_boxed_cast If the requested conversion is not possible /// - /// boxed_cast will attempt to make conversions between value, &, *, std::shared_ptr, boost::reference_wrapper, + /// boxed_cast will attempt to make conversions between value, &, *, std::shared_ptr, std::reference_wrapper, /// and std::function (const and non-const) where possible. boxed_cast is used internally during function /// dispatch. This means that all of these conversions will be attempted automatically for you during /// ChaiScript function calls. /// /// \li non-const values can be extracted as const or non-const /// \li const values can be extracted only as const - /// \li Boxed_Value constructed from pointer or boost::reference_wrapper can be extracted as reference, + /// \li Boxed_Value constructed from pointer or std::reference_wrapper can be extracted as reference, /// pointer or value types /// \li Boxed_Value constructed from std::shared_ptr or value types can be extracted as reference, /// pointer, value, or std::shared_ptr types diff --git a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp index 2800c745..15c237d7 100644 --- a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp @@ -26,7 +26,7 @@ namespace chaiscript template struct Cast_Helper_Inner { - typedef typename boost::reference_wrapper::type > Result_Type; + typedef typename std::reference_wrapper::type > Result_Type; static Result_Type cast(const Boxed_Value &ob) { @@ -34,16 +34,16 @@ namespace chaiscript { if (!ob.get_type_info().is_const()) { - return boost::cref((boost::any_cast >(ob.get())).get()); + return std::cref((boost::any_cast >(ob.get())).get()); } else { - return boost::any_cast >(ob.get()); + return boost::any_cast >(ob.get()); } } else { if (!ob.get_type_info().is_const()) { - return boost::cref(*(boost::any_cast >(ob.get()))); + return std::cref(*(boost::any_cast >(ob.get()))); } else { - return boost::cref(*(boost::any_cast >(ob.get()))); + return std::cref(*(boost::any_cast >(ob.get()))); } } } @@ -76,9 +76,9 @@ namespace chaiscript { if (!ob.get_type_info().is_const()) { - return (boost::any_cast >(ob.get())).get_pointer(); + return &(boost::any_cast >(ob.get())).get(); } else { - return (boost::any_cast >(ob.get())).get_pointer(); + return &(boost::any_cast >(ob.get())).get(); } } else { if (!ob.get_type_info().is_const()) @@ -103,7 +103,7 @@ namespace chaiscript { if (ob.is_ref()) { - return (boost::any_cast >(ob.get())).get_pointer(); + return &(boost::any_cast >(ob.get())).get(); } else { return (boost::any_cast >(ob.get())).get(); } @@ -116,15 +116,16 @@ namespace chaiscript template struct Cast_Helper_Inner { - typedef typename boost::reference_wrapper Result_Type; + typedef Result& Result_Type; - static Result_Type cast(const Boxed_Value &ob) + static Result &cast(const Boxed_Value &ob) { if (ob.is_ref()) { - return boost::any_cast >(ob.get()); + return boost::any_cast >(ob.get()); } else { - return boost::ref(*(boost::any_cast >(ob.get()))); + Result &r = *(boost::any_cast >(ob.get())); + return r; } } }; @@ -220,35 +221,35 @@ namespace chaiscript /** - * Cast_Helper_Inner for casting to a boost::reference_wrapper type + * Cast_Helper_Inner for casting to a std::reference_wrapper type */ template - struct Cast_Helper_Inner > : Cast_Helper_Inner + struct Cast_Helper_Inner > : Cast_Helper_Inner { }; template - struct Cast_Helper_Inner > : Cast_Helper_Inner + struct Cast_Helper_Inner > : Cast_Helper_Inner { }; template - struct Cast_Helper_Inner &> : Cast_Helper_Inner + struct Cast_Helper_Inner &> : Cast_Helper_Inner { }; template - struct Cast_Helper_Inner > : Cast_Helper_Inner + struct Cast_Helper_Inner > : Cast_Helper_Inner { }; template - struct Cast_Helper_Inner > : Cast_Helper_Inner + struct Cast_Helper_Inner > : Cast_Helper_Inner { }; template - struct Cast_Helper_Inner & > : Cast_Helper_Inner + struct Cast_Helper_Inner & > : Cast_Helper_Inner { }; diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 6d9a8f0a..8026fe6f 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -103,17 +103,17 @@ namespace chaiscript template static std::shared_ptr get(T *t) { - return get(boost::ref(*t)); + return get(std::ref(*t)); } template - static std::shared_ptr get(boost::reference_wrapper obj) + static std::shared_ptr get(std::reference_wrapper obj) { return std::shared_ptr(new Data( detail::Get_Type_Info::get(), boost::any(obj), true, - obj.get_pointer()) + &obj.get()) ); } @@ -271,7 +271,7 @@ namespace chaiscript std::shared_ptr m_data; }; - /// \brief Creates a Boxed_Value. If the object passed in is a value type, it is copied. If it is a pointer, std::shared_ptr, or boost::reference_type + /// \brief Creates a Boxed_Value. If the object passed in is a value type, it is copied. If it is a pointer, std::shared_ptr, or std::reference_type /// a copy is not made. /// \param t The value to box /// @@ -323,19 +323,19 @@ namespace chaiscript return Boxed_Value( std::const_pointer_cast::type>(t) ); } - /// \brief Takes a boost::reference_wrapper value, adds const to the referenced type and returns an immutable Boxed_Value. + /// \brief Takes a std::reference_wrapper value, adds const to the referenced type and returns an immutable Boxed_Value. /// Does not copy the referenced value. /// \param[in] t Reference object to make immutable /// \returns Immutable Boxed_Value /// \sa Boxed_Value::is_const template - Boxed_Value const_var_impl(const boost::reference_wrapper &t) + Boxed_Value const_var_impl(const std::reference_wrapper &t) { - return Boxed_Value( boost::cref(t.get()) ); + return Boxed_Value( std::cref(t.get()) ); } } - /// \brief Takes an object and returns an immutable Boxed_Value. If the object is a boost::reference or pointer type + /// \brief Takes an object and returns an immutable Boxed_Value. If the object is a std::reference or pointer type /// the value is not copied. If it is an object type, it is copied. /// \param[in] t Object to make immutable /// \returns Immutable Boxed_Value diff --git a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp index 5d66f296..6b888c3f 100644 --- a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp +++ b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp @@ -112,11 +112,11 @@ namespace chaiscript { const Derived &d = detail::Cast_Helper::cast(t_derived); const Base &data = dynamic_cast(d); - return Boxed_Value(boost::cref(data)); + return Boxed_Value(std::cref(data)); } else { Derived &d = detail::Cast_Helper::cast(t_derived); Base &data = dynamic_cast(d); - return Boxed_Value(boost::ref(data)); + return Boxed_Value(std::ref(data)); } } } else { diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index c20049f7..5c9d9e13 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -6,7 +6,7 @@ #include -#define addparam(z,n,text) params.push_back((boost::is_reference::value&&!(boost::is_same::type>::type>::value))?Boxed_Value(boost::ref(BOOST_PP_CAT(p, n))):Boxed_Value(BOOST_PP_CAT(p, n) )); +#define addparam(z,n,text) params.push_back((boost::is_reference::value&&!(boost::is_same::type>::type>::value))?Boxed_Value(std::ref(BOOST_PP_CAT(p, n))):Boxed_Value(BOOST_PP_CAT(p, n) )); #define curry(z,n,text) BOOST_PP_CAT(std::placeholders::_, BOOST_PP_INC(n)) diff --git a/include/chaiscript/dispatchkit/handle_return.hpp b/include/chaiscript/dispatchkit/handle_return.hpp index 70cc02ee..828d01e7 100644 --- a/include/chaiscript/dispatchkit/handle_return.hpp +++ b/include/chaiscript/dispatchkit/handle_return.hpp @@ -75,7 +75,7 @@ namespace chaiscript { static Boxed_Value handle(const Ret &r) { - return Boxed_Value(boost::cref(r)); + return Boxed_Value(std::cref(r)); } }; @@ -88,12 +88,12 @@ namespace chaiscript { static Boxed_Value handle(Ret &r) { - return Boxed_Value(boost::ref(r)); + return Boxed_Value(std::ref(r)); } static Boxed_Value handle(const Ret &r) { - return Boxed_Value(boost::cref(r)); + return Boxed_Value(std::cref(r)); } }; diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index 0c1f8e80..ad88586c 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -120,7 +120,7 @@ namespace chaiscript /// MyClass obj; /// chaiscript::ChaiScript chai; /// // Add function taking only one argument, an int, and permanently bound to "obj" - /// chai.add(fun(&MyClass::memberfunction, boost::ref(obj)), "memberfunction"); + /// chai.add(fun(&MyClass::memberfunction, std::ref(obj)), "memberfunction"); /// \endcode /// /// \sa \ref addingfunctions @@ -146,7 +146,7 @@ namespace chaiscript /// chaiscript::ChaiScript chai; /// // Add function taking only no arguments, and permanently bound to "obj" and "1" /// // memberfunction() will be equivalent to obj.memberfunction(1) - /// chai.add(fun(&MyClass::memberfunction, boost::ref(obj), 1), "memberfunction"); + /// chai.add(fun(&MyClass::memberfunction, std::ref(obj), 1), "memberfunction"); /// \endcode /// /// \sa \ref addingfunctions diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index aed318cd..2a79765f 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -187,7 +187,7 @@ namespace chaiscript }; template - struct Get_Type_Info > + struct Get_Type_Info > { typedef T type; @@ -196,13 +196,13 @@ namespace chaiscript return Type_Info(boost::is_const::value, boost::is_reference::value, boost::is_pointer::value, boost::is_void::value, boost::is_arithmetic::value && !boost::is_same::type, bool>::value, - &typeid(boost::reference_wrapper ), + &typeid(std::reference_wrapper ), &typeid(typename Bare_Type::type)); } }; template - struct Get_Type_Info &> + struct Get_Type_Info &> { typedef T type; @@ -211,7 +211,7 @@ namespace chaiscript return Type_Info(boost::is_const::value, boost::is_reference::value, boost::is_pointer::value, boost::is_void::value, boost::is_arithmetic::value && !boost::is_same::type, bool>::value, - &typeid(const boost::reference_wrapper &), + &typeid(const std::reference_wrapper &), &typeid(typename Bare_Type::type)); } }; diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 1b866d87..4b912398 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -344,13 +344,13 @@ namespace chaiscript add(Bootstrap::bootstrap()); - m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::dump_system, boost::ref(m_engine)), "dump_system"); - m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::dump_object, boost::ref(m_engine)), "dump_object"); - m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::is_type, boost::ref(m_engine)), "is_type"); - m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::type_name, boost::ref(m_engine)), "type_name"); - m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::function_exists, boost::ref(m_engine)), "function_exists"); + m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::dump_system, std::ref(m_engine)), "dump_system"); + m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::dump_object, std::ref(m_engine)), "dump_object"); + m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::is_type, std::ref(m_engine)), "is_type"); + m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::type_name, std::ref(m_engine)), "type_name"); + m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::function_exists, std::ref(m_engine)), "function_exists"); - m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_type_name, boost::ref(m_engine)), "name"); + m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_type_name, std::ref(m_engine)), "name"); typedef void (ChaiScript::*load_mod_1)(const std::string&); diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 55ed3737..356299ad 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -556,7 +556,7 @@ namespace chaiscript } return Boxed_Value(Proxy_Function(new dispatch::Dynamic_Proxy_Function - (std::bind(chaiscript::eval::detail::eval_function, boost::ref(t_ss), this->children.back(), t_param_names, std::placeholders::_1), + (std::bind(chaiscript::eval::detail::eval_function, std::ref(t_ss), this->children.back(), t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back()))); } @@ -624,7 +624,7 @@ namespace chaiscript if (guardnode) { guard = std::shared_ptr (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, - boost::ref(t_ss), guardnode, + std::ref(t_ss), guardnode, t_param_names, std::placeholders::_1), static_cast(numparams), guardnode)); } @@ -633,7 +633,7 @@ namespace chaiscript const std::string & l_annotation = this->annotation?this->annotation->text:""; t_ss.add(Proxy_Function (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, - boost::ref(t_ss), this->children.back(), + std::ref(t_ss), this->children.back(), t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back(), l_annotation, guard)), l_function_name); } @@ -942,7 +942,7 @@ namespace chaiscript throw; } catch (const std::exception &e) { - Boxed_Value except = Boxed_Value(boost::ref(e)); + Boxed_Value except = Boxed_Value(std::ref(e)); size_t end_point = this->children.size(); if (this->children.back()->identifier == AST_Node_Type::Finally) { @@ -1099,7 +1099,7 @@ namespace chaiscript if (guardnode) { guard = std::shared_ptr (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, - boost::ref(t_ss), guardnode, + std::ref(t_ss), guardnode, t_param_names, std::placeholders::_1), static_cast(numparams), guardnode)); } @@ -1111,7 +1111,7 @@ namespace chaiscript t_ss.add(Proxy_Function (new dispatch::detail::Dynamic_Object_Constructor(class_name, Proxy_Function (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, - boost::ref(t_ss), this->children.back(), + std::ref(t_ss), this->children.back(), t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back(), l_annotation, guard)))), function_name); @@ -1126,7 +1126,7 @@ namespace chaiscript t_ss.add(Proxy_Function (new dispatch::detail::Dynamic_Object_Function(class_name, Proxy_Function (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, - boost::ref(t_ss), this->children.back(), + std::ref(t_ss), this->children.back(), t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back(), l_annotation, guard)), ti)), function_name); diff --git a/samples/example.cpp b/samples/example.cpp index 33d02343..5a706f04 100644 --- a/samples/example.cpp +++ b/samples/example.cpp @@ -109,7 +109,7 @@ int main(int /*argc*/, char * /*argv*/[]) { //Finally, it is possible to register any std::function as a system function, in this //way, we can, for instance add a bound member function to the system - chai.add(fun(&System::do_callbacks, boost::ref(system), std::string("Bound Test")), "do_callbacks"); + chai.add(fun(&System::do_callbacks, std::ref(system), std::string("Bound Test")), "do_callbacks"); //Call bound version of do_callbacks chai("do_callbacks()"); diff --git a/src/multithreaded.cpp b/src/multithreaded.cpp index c1eddd4e..e0d77671 100644 --- a/src/multithreaded.cpp +++ b/src/multithreaded.cpp @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) { for (int i = 0; i < argc - 1; ++i) { - threads.push_back(std::shared_ptr(new boost::thread(std::bind(do_work, boost::ref(chai))))); + threads.push_back(std::shared_ptr(new boost::thread(std::bind(do_work, std::ref(chai))))); } for (int i = 0; i < argc - 1; ++i) diff --git a/unittests/boxed_cast_test.cpp b/unittests/boxed_cast_test.cpp index 5d5a5db3..c1837314 100644 --- a/unittests/boxed_cast_test.cpp +++ b/unittests/boxed_cast_test.cpp @@ -78,14 +78,14 @@ bool do_test(const Boxed_Value &bv, bool T, bool ConstT, bool TRef, bool ConstTR passed &= test_type_conversion >(bv, ConstSharedConstPtrT); passed &= test_type_conversion &>(bv, ConstSharedPtrTRef); passed &= test_type_conversion &>(bv, ConstSharedPtrTConstRef); - passed &= test_type_conversion >(bv, BoostRef); - passed &= test_type_conversion >(bv, BoostConstRef); - passed &= test_type_conversion &>(bv, false); - passed &= test_type_conversion &>(bv, false); - passed &= test_type_conversion >(bv, ConstBoostRef); - passed &= test_type_conversion >(bv, ConstBoostConstRef); - passed &= test_type_conversion &>(bv, ConstBoostRefRef); - passed &= test_type_conversion &>(bv, ConstBoostConstRefRef); + passed &= test_type_conversion >(bv, BoostRef); + passed &= test_type_conversion >(bv, BoostConstRef); + passed &= test_type_conversion &>(bv, false); + passed &= test_type_conversion &>(bv, false); + passed &= test_type_conversion >(bv, ConstBoostRef); + passed &= test_type_conversion >(bv, ConstBoostConstRef); + passed &= test_type_conversion &>(bv, ConstBoostRefRef); + passed &= test_type_conversion &>(bv, ConstBoostConstRefRef); passed &= test_type_conversion(bv, Number); passed &= test_type_conversion(bv, ConstNumber); passed &= test_type_conversion(bv, false); @@ -137,13 +137,13 @@ bool built_in_type_test(const T &initial, bool ispod) true, false, true, false, true, ispod && true, ispod && true, ispod && true, ispod && false, true); - passed &= do_test(var(boost::ref(i)), true, true, true, true, true, + passed &= do_test(var(std::ref(i)), true, true, true, true, true, true, true, true, false, false, false, false, false, false, true, true, true, true, true, true, ispod && true, ispod && true, ispod && true, true, true); - passed &= do_test(var(boost::cref(i)), true, true, false, true, false, + passed &= do_test(var(std::cref(i)), true, true, false, true, false, true, false, true, false, false, false, false, false, false, false, true, false, true, false, true, @@ -167,7 +167,7 @@ bool built_in_type_test(const T &initial, bool ispod) true, false, true, false, true, ispod && true, ispod && true, ispod && true, false, true); - passed &= do_test(var(boost::ref(ir)), true, true, false, true, false, + passed &= do_test(var(std::ref(ir)), true, true, false, true, false, true, false, true, false, false, false, false, false, false, false, true, false, true, false, true, @@ -180,7 +180,7 @@ bool built_in_type_test(const T &initial, bool ispod) true, false, true, false, true, ispod && true, ispod && true, ispod && true, false, true); - passed &= do_test(const_var(boost::ref(ir)), true, true, false, true, false, + passed &= do_test(const_var(std::ref(ir)), true, true, false, true, false, true, false, true, false, false, false, false, false, false, false, true, false, true, false, true, From 6bb2678d18b6efdeb5baec1cda3243990db1e756 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 10 Sep 2011 11:10:14 -0600 Subject: [PATCH 006/108] GO from boost::int64_t to std::int64_t, etc. --- include/chaiscript/dispatchkit/bind_first.hpp | 1 - include/chaiscript/dispatchkit/bootstrap.hpp | 8 ++--- include/chaiscript/dispatchkit/boxed_cast.hpp | 2 -- .../dispatchkit/boxed_cast_helper.hpp | 1 - .../chaiscript/dispatchkit/boxed_number.hpp | 33 +++++++++---------- .../chaiscript/dispatchkit/boxed_value.hpp | 2 -- include/chaiscript/dispatchkit/type_info.hpp | 1 - 7 files changed, 20 insertions(+), 28 deletions(-) diff --git a/include/chaiscript/dispatchkit/bind_first.hpp b/include/chaiscript/dispatchkit/bind_first.hpp index 06a64119..f5064392 100644 --- a/include/chaiscript/dispatchkit/bind_first.hpp +++ b/include/chaiscript/dispatchkit/bind_first.hpp @@ -13,7 +13,6 @@ #ifndef CHAISCRIPT_BIND_FIRST_HPP_ #define CHAISCRIPT_BIND_FIRST_HPP_ -#include #define BOOST_PP_ITERATION_LIMITS ( 0, 8 ) #define BOOST_PP_FILENAME_1 diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 43da17dd..de709915 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -445,10 +445,10 @@ namespace chaiscript bootstrap_pod_type("unsigned_long", m); bootstrap_pod_type("size_t", m); bootstrap_pod_type("char", m); - bootstrap_pod_type("int8_t", m); - bootstrap_pod_type("int16_t", m); - bootstrap_pod_type("int32_t", m); - bootstrap_pod_type("int64_t", m); + bootstrap_pod_type("int8_t", m); + bootstrap_pod_type("int16_t", m); + bootstrap_pod_type("int32_t", m); + bootstrap_pod_type("int64_t", m); bootstrap_pod_type("uint8_t", m); bootstrap_pod_type("uint16_t", m); bootstrap_pod_type("uint32_t", m); diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index 59ccbfa8..98c85e12 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -14,8 +14,6 @@ #include "../chaiscript_threading.hpp" #include -#include -#include #include #include #include diff --git a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp index 15c237d7..899011a2 100644 --- a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp @@ -11,7 +11,6 @@ #include "boxed_value.hpp" #include -#include #include namespace chaiscript diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index a5f6b50f..e71beefa 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -9,7 +9,6 @@ #include "boxed_value.hpp" #include "../language/chaiscript_algebraic.hpp" -#include namespace chaiscript { @@ -232,14 +231,14 @@ namespace chaiscript return Go::go(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(unsigned long)) { return Go::go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::int8_t)) { - return Go::go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::int16_t)) { - return Go::go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::int32_t)) { - return Go::go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::int64_t)) { - return Go::go(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::int8_t)) { + return Go::go(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::int16_t)) { + return Go::go(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::int32_t)) { + return Go::go(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::int64_t)) { + return Go::go(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(boost::uint8_t)) { return Go::go(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(boost::uint16_t)) { @@ -273,14 +272,14 @@ namespace chaiscript return oper_rhs(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(unsigned long)) { return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::int8_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::int16_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::int32_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::int64_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::int8_t)) { + return oper_rhs(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::int16_t)) { + return oper_rhs(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::int32_t)) { + return oper_rhs(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::int64_t)) { + return oper_rhs(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(boost::uint8_t)) { return oper_rhs(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(boost::uint16_t)) { diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 8026fe6f..a8503403 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -13,8 +13,6 @@ #include #include -#include -#include #include #include diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index 2a79765f..363549a2 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -19,7 +19,6 @@ #include #include #include -#include namespace chaiscript { From 62cf6293e8bc49139280ff7d7e8ca014bb0504fd Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 10 Sep 2011 12:26:31 -0600 Subject: [PATCH 007/108] Move from boost::uint* to std::uint* --- include/chaiscript/dispatchkit/bootstrap.hpp | 8 ++--- .../chaiscript/dispatchkit/boxed_number.hpp | 32 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index de709915..1173d220 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -449,10 +449,10 @@ namespace chaiscript bootstrap_pod_type("int16_t", m); bootstrap_pod_type("int32_t", m); bootstrap_pod_type("int64_t", m); - bootstrap_pod_type("uint8_t", m); - bootstrap_pod_type("uint16_t", m); - bootstrap_pod_type("uint32_t", m); - bootstrap_pod_type("uint64_t", m); + bootstrap_pod_type("uint8_t", m); + bootstrap_pod_type("uint16_t", m); + bootstrap_pod_type("uint32_t", m); + bootstrap_pod_type("uint64_t", m); operators::logical_compliment(m); diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index e71beefa..f593e624 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -239,14 +239,14 @@ namespace chaiscript return Go::go(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(std::int64_t)) { return Go::go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::uint8_t)) { - return Go::go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::uint16_t)) { - return Go::go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::uint32_t)) { - return Go::go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::uint64_t)) { - return Go::go(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::uint8_t)) { + return Go::go(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::uint16_t)) { + return Go::go(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::uint32_t)) { + return Go::go(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::uint64_t)) { + return Go::go(t_oper, t_lhs, t_rhs); } else { throw boost::bad_any_cast(); } @@ -280,14 +280,14 @@ namespace chaiscript return oper_rhs(t_oper, t_lhs, t_rhs); } else if (inp_ == typeid(std::int64_t)) { return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::uint8_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::uint16_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::uint32_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(boost::uint64_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::uint8_t)) { + return oper_rhs(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::uint16_t)) { + return oper_rhs(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::uint32_t)) { + return oper_rhs(t_oper, t_lhs, t_rhs); + } else if (inp_ == typeid(std::uint64_t)) { + return oper_rhs(t_oper, t_lhs, t_rhs); } else { throw boost::bad_any_cast(); } From b297162d13dda1cddc4fb786fd1e6967ae4f292c Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 10 Sep 2011 13:18:29 -0600 Subject: [PATCH 008/108] Move from boost::type_traits to std::type_traits --- include/chaiscript/dispatchkit/bootstrap.hpp | 10 ++--- include/chaiscript/dispatchkit/boxed_cast.hpp | 5 +-- .../dispatchkit/boxed_cast_helper.hpp | 3 +- .../chaiscript/dispatchkit/boxed_value.hpp | 8 ++-- .../dispatchkit/dynamic_cast_conversion.hpp | 8 ++-- .../dispatchkit/function_call_detail.hpp | 2 +- .../dispatchkit/proxy_functions.hpp | 6 +-- include/chaiscript/dispatchkit/type_info.hpp | 42 ++++++++----------- src/main.cpp | 2 +- unittests/boxed_cast_test.cpp | 2 +- 10 files changed, 36 insertions(+), 52 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 1173d220..f6c24837 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -148,10 +148,10 @@ namespace chaiscript * Specific version of shared_ptr_clone just for Proxy_Functions */ template - std::shared_ptr::type> - shared_ptr_unconst_clone(const std::shared_ptr::type> &p) + std::shared_ptr::type> + shared_ptr_unconst_clone(const std::shared_ptr::type> &p) { - return std::const_pointer_cast::type>(p); + return std::const_pointer_cast::type>(p); } @@ -466,8 +466,8 @@ namespace chaiscript "bind"); m->add(fun(&shared_ptr_unconst_clone), "clone"); - m->add(fun(&ptr_assign::type>), "="); - m->add(fun(&ptr_assign::type>), "="); + m->add(fun(&ptr_assign::type>), "="); + m->add(fun(&ptr_assign::type>), "="); m->add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(std::bind(&call_exists, std::placeholders::_1))), "call_exists"); diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index 98c85e12..c10aa724 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -14,9 +14,6 @@ #include "../chaiscript_threading.hpp" #include -#include -#include -#include namespace chaiscript { @@ -77,7 +74,7 @@ namespace chaiscript #pragma warning(disable : 4127) #endif - if (boost::is_polymorphic::type>::value) + if (std::is_polymorphic::type>::value) { try { // We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it diff --git a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp index 899011a2..ae235564 100644 --- a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp @@ -11,7 +11,6 @@ #include "boxed_value.hpp" #include -#include namespace chaiscript { @@ -25,7 +24,7 @@ namespace chaiscript template struct Cast_Helper_Inner { - typedef typename std::reference_wrapper::type > Result_Type; + typedef typename std::reference_wrapper::type > Result_Type; static Result_Type cast(const Boxed_Value &ob) { diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index a8503403..76a785fc 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -13,8 +13,6 @@ #include #include -#include -#include namespace chaiscript { @@ -296,7 +294,7 @@ namespace chaiscript template Boxed_Value const_var_impl(const T &t) { - return Boxed_Value(std::shared_ptr::type >(new T(t))); + return Boxed_Value(std::shared_ptr::type >(new T(t))); } /// \brief Takes a pointer to a value, adds const to the pointed to type and returns an immutable Boxed_Value. @@ -307,7 +305,7 @@ namespace chaiscript template Boxed_Value const_var_impl(T *t) { - return Boxed_Value( const_cast::type *>(t) ); + return Boxed_Value( const_cast::type *>(t) ); } /// \brief Takes a std::shared_ptr to a value, adds const to the pointed to type and returns an immutable Boxed_Value. @@ -318,7 +316,7 @@ namespace chaiscript template Boxed_Value const_var_impl(const std::shared_ptr &t) { - return Boxed_Value( std::const_pointer_cast::type>(t) ); + return Boxed_Value( std::const_pointer_cast::type>(t) ); } /// \brief Takes a std::reference_wrapper value, adds const to the referenced type and returns an immutable Boxed_Value. diff --git a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp index 6b888c3f..054dcd44 100644 --- a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp +++ b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp @@ -12,8 +12,6 @@ #include "boxed_cast_helper.hpp" #include "bad_boxed_cast.hpp" #include -#include -#include namespace chaiscript { @@ -249,9 +247,9 @@ namespace chaiscript { //Can only be used with related polymorphic types //may be expanded some day to support conversions other than child -> parent - BOOST_STATIC_ASSERT((boost::is_base_of::value)); - BOOST_STATIC_ASSERT(boost::is_polymorphic::value); - BOOST_STATIC_ASSERT(boost::is_polymorphic::value); + BOOST_STATIC_ASSERT((std::is_base_of::value)); + BOOST_STATIC_ASSERT(std::is_polymorphic::value); + BOOST_STATIC_ASSERT(std::is_polymorphic::value); return detail::Dynamic_Conversions::create(); } diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index 5c9d9e13..e5312055 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -6,7 +6,7 @@ #include -#define addparam(z,n,text) params.push_back((boost::is_reference::value&&!(boost::is_same::type>::type>::value))?Boxed_Value(std::ref(BOOST_PP_CAT(p, n))):Boxed_Value(BOOST_PP_CAT(p, n) )); +#define addparam(z,n,text) params.push_back((std::is_reference::value&&!(std::is_same::type>::type>::value))?Boxed_Value(std::ref(BOOST_PP_CAT(p, n))):Boxed_Value(BOOST_PP_CAT(p, n) )); #define curry(z,n,text) BOOST_PP_CAT(std::placeholders::_, BOOST_PP_INC(n)) diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index df153723..f25b43b2 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -12,7 +12,7 @@ #include "boxed_value.hpp" #include "type_info.hpp" #include -#include +#include #include #include #include "proxy_functions_detail.hpp" @@ -554,10 +554,10 @@ namespace chaiscript if (bv.is_const()) { const Class *o = boxed_cast(bv); - return detail::Handle_Return::type>::handle(o->*m_attr); + return detail::Handle_Return::type>::handle(o->*m_attr); } else { Class *o = boxed_cast(bv); - return detail::Handle_Return::type>::handle(o->*m_attr); + return detail::Handle_Return::type>::handle(o->*m_attr); } } else { throw exception::arity_error(static_cast(params.size()), 1); diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index 363549a2..87eddea0 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -10,15 +10,7 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include namespace chaiscript { @@ -28,7 +20,7 @@ namespace chaiscript template struct Bare_Type { - typedef typename boost::remove_const::type>::type>::type type; + typedef typename std::remove_const::type>::type>::type type; }; } @@ -147,9 +139,9 @@ namespace chaiscript static Type_Info get() { - return Type_Info(boost::is_const::type>::type>::value, boost::is_reference::value, boost::is_pointer::value, - boost::is_void::value, - boost::is_arithmetic::value && !boost::is_same::type, bool>::value, + return Type_Info(std::is_const::type>::type>::value, std::is_reference::value, std::is_pointer::value, + std::is_void::value, + std::is_arithmetic::value && !std::is_same::type, bool>::value, &typeid(T), &typeid(typename Bare_Type::type)); } @@ -162,9 +154,9 @@ namespace chaiscript static Type_Info get() { - return Type_Info(boost::is_const::value, boost::is_reference::value, boost::is_pointer::value, - boost::is_void::value, - boost::is_arithmetic::value && !boost::is_same::type, bool>::value, + return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, + std::is_void::value, + std::is_arithmetic::value && !std::is_same::type, bool>::value, &typeid(std::shared_ptr ), &typeid(typename Bare_Type::type)); } @@ -177,9 +169,9 @@ namespace chaiscript static Type_Info get() { - return Type_Info(boost::is_const::value, boost::is_reference::value, boost::is_pointer::value, - boost::is_void::value, - boost::is_arithmetic::value && !boost::is_same::type, bool>::value, + return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, + std::is_void::value, + std::is_arithmetic::value && !std::is_same::type, bool>::value, &typeid(const std::shared_ptr &), &typeid(typename Bare_Type::type)); } @@ -192,9 +184,9 @@ namespace chaiscript static Type_Info get() { - return Type_Info(boost::is_const::value, boost::is_reference::value, boost::is_pointer::value, - boost::is_void::value, - boost::is_arithmetic::value && !boost::is_same::type, bool>::value, + return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, + std::is_void::value, + std::is_arithmetic::value && !std::is_same::type, bool>::value, &typeid(std::reference_wrapper ), &typeid(typename Bare_Type::type)); } @@ -207,9 +199,9 @@ namespace chaiscript static Type_Info get() { - return Type_Info(boost::is_const::value, boost::is_reference::value, boost::is_pointer::value, - boost::is_void::value, - boost::is_arithmetic::value && !boost::is_same::type, bool>::value, + return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, + std::is_void::value, + std::is_arithmetic::value && !std::is_same::type, bool>::value, &typeid(const std::reference_wrapper &), &typeid(typename Bare_Type::type)); } diff --git a/src/main.cpp b/src/main.cpp index b1ca5390..9cec2dbf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,7 +80,7 @@ std::string get_next_command() { char *input_raw = readline("eval> "); if ( input_raw ) { add_history(input_raw); - retval = boost::trim_copy_if(std::string(input_raw),boost::is_any_of(" \t")); + retval = boost::trim_copy_if(std::string(input_raw),boost::algorithm::is_any_of(" \t")); ::free(input_raw); } } diff --git a/unittests/boxed_cast_test.cpp b/unittests/boxed_cast_test.cpp index c1837314..4a328463 100644 --- a/unittests/boxed_cast_test.cpp +++ b/unittests/boxed_cast_test.cpp @@ -46,7 +46,7 @@ bool test_type_conversion(const Boxed_Value &bv, bool expectedpass) std::cerr << "Error with type conversion test. From: " << (bv.is_const()?(std::string("const ")):(std::string())) << bv.get_type_info().name() << " To: " - << (boost::is_const::value?(std::string("const ")):(std::string())) << typeid(To).name() + << (std::is_const::value?(std::string("const ")):(std::string())) << typeid(To).name() << " test was expected to " << ((expectedpass)?(std::string("succeed")):(std::string("fail"))) << " but did not" << std::endl; } From 4522ff0732983e826d7ce68a4469884cfd4b8d14 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 10 Sep 2011 13:49:29 -0600 Subject: [PATCH 009/108] Remove various other boost libraries --- include/chaiscript/dispatchkit/bootstrap.hpp | 9 +++++++-- include/chaiscript/dispatchkit/dispatchkit.hpp | 2 -- .../dispatchkit/dynamic_cast_conversion.hpp | 1 - include/chaiscript/dispatchkit/handle_return.hpp | 1 - .../dispatchkit/proxy_functions_detail.hpp | 1 - .../chaiscript/dispatchkit/register_function.hpp | 4 +--- .../chaiscript/language/chaiscript_common.hpp | 16 ++++++++++++---- 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index f6c24837..59eb1c5f 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -98,7 +98,9 @@ namespace chaiscript template std::string to_string(Input i) { - return boost::lexical_cast(i); + std::stringstream ss; + ss << i; + return ss.str(); } @@ -109,7 +111,10 @@ namespace chaiscript template Input parse_string(const std::string &i) { - return boost::lexical_cast(i); + std::stringstream ss(i); + Input t; + ss >> t; + return t; } diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index b9afa54a..ecb4de43 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -11,8 +11,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp index 054dcd44..1bb5447a 100644 --- a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp +++ b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp @@ -11,7 +11,6 @@ #include "boxed_value.hpp" #include "boxed_cast_helper.hpp" #include "bad_boxed_cast.hpp" -#include namespace chaiscript { diff --git a/include/chaiscript/dispatchkit/handle_return.hpp b/include/chaiscript/dispatchkit/handle_return.hpp index 828d01e7..18f63cc9 100644 --- a/include/chaiscript/dispatchkit/handle_return.hpp +++ b/include/chaiscript/dispatchkit/handle_return.hpp @@ -11,7 +11,6 @@ #include "boxed_number.hpp" #include "type_info.hpp" #include -#include #include #include diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index ae697d2c..7d93393e 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -19,7 +19,6 @@ #include "type_info.hpp" #include "handle_return.hpp" #include -#include #include #include diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index ad88586c..8d7efae4 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -11,8 +11,6 @@ #include "bind_first.hpp" #include #include -#include -#include namespace chaiscript { @@ -103,7 +101,7 @@ namespace chaiscript template Proxy_Function fun(T t) { - return dispatch::detail::Fun_Helper::value, boost::function_types::is_member_function_pointer::value>::go(t); + return dispatch::detail::Fun_Helper::value, std::is_member_function_pointer::value>::go(t); } /// \brief Creates a new Proxy_Function object from a free function, member function or data member and binds the first parameter of it diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 55d0203e..bc00f5cc 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -71,10 +71,7 @@ namespace chaiscript std::vector call_stack; eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) throw() : - std::runtime_error("Error: \"" + t_why + "\" " + - (t_fname != "__EVAL__" ? ("in '" + t_fname + "' ") : "during evaluation ") + - + "at (" + boost::lexical_cast(t_where.line) + ", " + - boost::lexical_cast(t_where.column) + ")"), + std::runtime_error(format(t_why, t_where, t_fname)), reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname) { } @@ -84,6 +81,17 @@ namespace chaiscript {} virtual ~eval_error() throw() {} + + private: + static std::string format(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) + { + std::stringstream ss; + ss << "Error: \"" << t_why << "\" " << + (t_fname != "__EVAL__" ? ("in '" + t_fname + "' ") : "during evaluation ") << + "at (" << t_where.line << ", " << + t_where.column + ")"; + return ss.str(); + } }; /** From f4080c4c759b07a8fecd01ad5aa7c3fe67279822 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 10 Sep 2011 14:01:05 -0600 Subject: [PATCH 010/108] Move from boost::mem_fn to std::mem_fn --- include/chaiscript/dispatchkit/bind_first.hpp | 4 ++-- .../chaiscript/dispatchkit/bootstrap_stl.hpp | 20 +++++++++---------- .../dispatchkit/register_function.hpp | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/chaiscript/dispatchkit/bind_first.hpp b/include/chaiscript/dispatchkit/bind_first.hpp index f5064392..27927249 100644 --- a/include/chaiscript/dispatchkit/bind_first.hpp +++ b/include/chaiscript/dispatchkit/bind_first.hpp @@ -39,7 +39,7 @@ namespace chaiscript std::function bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const O &o) { - return std::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, std::placeholders::_)); + return std::bind(std::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, std::placeholders::_)); } /// \brief Helper function for binding the first parameter of a const class method pointer. Used in chaiscript::fun overloads @@ -52,7 +52,7 @@ namespace chaiscript std::function bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)) const, const O &o) { - return std::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, std::placeholders::_)); + return std::bind(std::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, std::placeholders::_)); } /// \brief Helper function for binding the first parameter of a function pointer. Used in chaiscript::fun overloads diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 0bb93b67..a98534a8 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -228,10 +228,10 @@ namespace chaiscript //to throw an exception in an out of bounds condition. m->add( fun(std::function - (boost::mem_fn(static_cast(&ContainerType::at)))), "[]"); + (std::mem_fn(static_cast(&ContainerType::at)))), "[]"); m->add( fun(std::function - (boost::mem_fn(static_cast(&ContainerType::at)))), "[]"); + (std::mem_fn(static_cast(&ContainerType::at)))), "[]"); return m; } @@ -255,7 +255,7 @@ namespace chaiscript template ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { - m->add(fun(std::function(boost::mem_fn(&ContainerType::size))), "size"); + m->add(fun(std::function(std::mem_fn(&ContainerType::size))), "size"); m->add(fun(&ContainerType::empty), "empty"); m->add(fun(&ContainerType::clear), "clear"); @@ -390,7 +390,7 @@ namespace chaiscript template ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { - m->add(fun(std::function(boost::mem_fn(&ContainerType::count))), "count"); + m->add(fun(std::function(std::mem_fn(&ContainerType::count))), "count"); return m; } @@ -515,12 +515,12 @@ namespace chaiscript typedef std::function find_func; - m->add(fun(find_func(boost::mem_fn(static_cast(&String::find)))), "find"); - m->add(fun(find_func(boost::mem_fn(static_cast(&String::rfind)))), "rfind"); - m->add(fun(find_func(boost::mem_fn(static_cast(&String::find_first_of)))), "find_first_of"); - m->add(fun(find_func(boost::mem_fn(static_cast(&String::find_last_of)))), "find_last_of"); - m->add(fun(find_func(boost::mem_fn(static_cast(&String::find_first_not_of)))), "find_first_not_of"); - m->add(fun(find_func(boost::mem_fn(static_cast(&String::find_last_not_of)))), "find_last_not_of"); + m->add(fun(find_func(std::mem_fn(static_cast(&String::find)))), "find"); + m->add(fun(find_func(std::mem_fn(static_cast(&String::rfind)))), "rfind"); + m->add(fun(find_func(std::mem_fn(static_cast(&String::find_first_of)))), "find_first_of"); + m->add(fun(find_func(std::mem_fn(static_cast(&String::find_last_of)))), "find_last_of"); + m->add(fun(find_func(std::mem_fn(static_cast(&String::find_first_not_of)))), "find_first_not_of"); + m->add(fun(find_func(std::mem_fn(static_cast(&String::find_last_not_of)))), "find_last_not_of"); m->add(fun(&String::c_str), "c_str"); m->add(fun(&String::data), "data"); diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index 8d7efae4..e62064a7 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -44,7 +44,7 @@ namespace chaiscript typename boost::function_types::function_type >::type> ( std::function< typename boost::function_types::function_type >::type - >(boost::mem_fn(t)))); + >(std::mem_fn(t)))); } }; From 99aaa079a40f5ea6cd8db49c7faf6a6c63ef90b1 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 10 Sep 2011 14:58:19 -0600 Subject: [PATCH 011/108] Add missing include for stringstream --- include/chaiscript/dispatchkit/bootstrap.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 59eb1c5f..575803e2 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -13,6 +13,7 @@ #include "operators.hpp" #include "boxed_number.hpp" #include +#include namespace chaiscript { From 0a9cb0cbe90e77a9396b02f8d65ddc8632f9b527 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 10 Sep 2011 14:58:59 -0600 Subject: [PATCH 012/108] Move to std::threading from boost::thread. Still need to sort out thread local storage --- include/chaiscript/chaiscript_threading.hpp | 36 +++++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/include/chaiscript/chaiscript_threading.hpp b/include/chaiscript/chaiscript_threading.hpp index f4f75e5a..a8d8d8c9 100644 --- a/include/chaiscript/chaiscript_threading.hpp +++ b/include/chaiscript/chaiscript_threading.hpp @@ -8,7 +8,9 @@ #define CHAISCRIPT_THREADING_HPP_ #ifndef CHAISCRIPT_NO_THREADS -#include +#include +#include +#include #else #pragma message ("ChaiScript is compiling without thread safety.") #endif @@ -32,11 +34,33 @@ namespace chaiscript { #ifndef CHAISCRIPT_NO_THREADS - using boost::unique_lock; - using boost::shared_lock; - using boost::lock_guard; - using boost::shared_mutex; - using boost::recursive_mutex; + + template + class unique_lock : public std::unique_lock + { + public: + unique_lock(T &t) : std::unique_lock(t) {} + }; + + template + class shared_lock : public std::unique_lock + { + public: + shared_lock(T &t) : std::unique_lock(t) {} + void unlock() {} + }; + + template + class lock_guard : public std::lock_guard + { + public: + lock_guard(T &t) : std::lock_guard(t) {} + }; + + class shared_mutex : public std::mutex { }; + + using std::recursive_mutex; + /// Typesafe thread specific storage. If threading is enabled, this class uses boost::thread_specific_ptr. If From cd97880d70f9a62d9e8bb6434ba6451e15d3533d Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 11 Sep 2011 06:56:15 -0600 Subject: [PATCH 013/108] Drop boost::optional requirement --- .../chaiscript/dispatchkit/dynamic_object.hpp | 54 ++++++++++--------- .../chaiscript/language/chaiscript_eval.hpp | 24 +++++---- src/multithreaded.cpp | 26 ++++----- 3 files changed, 56 insertions(+), 48 deletions(-) diff --git a/include/chaiscript/dispatchkit/dynamic_object.hpp b/include/chaiscript/dispatchkit/dynamic_object.hpp index 02690888..e94e893f 100644 --- a/include/chaiscript/dispatchkit/dynamic_object.hpp +++ b/include/chaiscript/dispatchkit/dynamic_object.hpp @@ -7,7 +7,6 @@ #ifndef CHAISCRIPT_DYNAMIC_OBJECT_HPP_ #define CHAISCRIPT_DYNAMIC_OBJECT_HPP_ -#include namespace chaiscript { @@ -66,16 +65,26 @@ namespace chaiscript class Dynamic_Object_Function : public Proxy_Function_Base { public: + Dynamic_Object_Function( + const std::string &t_type_name, + const Proxy_Function &t_func) + : Proxy_Function_Base(t_func->get_param_types()), + m_type_name(t_type_name), m_func(t_func) + { + assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) + && "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); + } + Dynamic_Object_Function( const std::string &t_type_name, const Proxy_Function &t_func, - const boost::optional &t_ti = boost::optional()) + const Type_Info &t_ti) : Proxy_Function_Base(build_param_types(t_func->get_param_types(), t_ti)), - m_type_name(t_type_name), m_func(t_func), m_ti(t_ti) - { - assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) - && "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); - } + m_type_name(t_type_name), m_func(t_func), m_ti(new Type_Info(t_ti)) + { + assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) + && "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); + } virtual ~Dynamic_Object_Function() {} @@ -137,23 +146,18 @@ namespace chaiscript private: static std::vector build_param_types( - const std::vector &t_inner_types, boost::optional t_objectti) + const std::vector &t_inner_types, const Type_Info& t_objectti) { - if (t_objectti) - { - std::vector types(t_inner_types); + std::vector types(t_inner_types); - assert(types.size() > 1); - assert(types[1].bare_equal(user_type())); - types[1] = *t_objectti; - return types; - } else { - return t_inner_types; - } + assert(types.size() > 1); + assert(types[1].bare_equal(user_type())); + types[1] = t_objectti; + return types; } static bool dynamic_object_typename_match(const Boxed_Value &bv, const std::string &name, - const boost::optional &ti) + const std::shared_ptr &ti) { static Type_Info doti = user_type(); if (bv.get_type_info().bare_equal(doti)) @@ -176,7 +180,7 @@ namespace chaiscript } static bool dynamic_object_typename_match(const std::vector &bvs, const std::string &name, - const boost::optional &ti) + const std::shared_ptr &ti) { if (bvs.size() > 0) { @@ -188,7 +192,7 @@ namespace chaiscript std::string m_type_name; Proxy_Function m_func; - boost::optional m_ti; + std::shared_ptr m_ti; }; @@ -207,10 +211,10 @@ namespace chaiscript const Proxy_Function &t_func) : Proxy_Function_Base(build_type_list(t_func->get_param_types())), m_type_name(t_type_name), m_func(t_func) - { - assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) - && "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); - } + { + assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) + && "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); + } static std::vector build_type_list(const std::vector &tl) { diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 356299ad..b3b4b0c0 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -1117,19 +1117,23 @@ namespace chaiscript } else { - boost::optional ti; try { - ti = t_ss.get_type(class_name); + // Do know type name + t_ss.add(Proxy_Function + (new dispatch::detail::Dynamic_Object_Function(class_name, Proxy_Function + (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, + std::ref(t_ss), this->children.back(), + t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back(), + l_annotation, guard)), t_ss.get_type(class_name))), function_name); } catch (const std::range_error &) { - // No biggie, the type name is just not known + // Do not know type name + t_ss.add(Proxy_Function + (new dispatch::detail::Dynamic_Object_Function(class_name, Proxy_Function + (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, + std::ref(t_ss), this->children.back(), + t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back(), + l_annotation, guard)))), function_name); } - t_ss.add(Proxy_Function - (new dispatch::detail::Dynamic_Object_Function(class_name, Proxy_Function - (new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function, - std::ref(t_ss), this->children.back(), - t_param_names, std::placeholders::_1), static_cast(numparams), this->children.back(), - l_annotation, guard)), ti)), function_name); - } } catch (const exception::reserved_word_error &e) { diff --git a/src/multithreaded.cpp b/src/multithreaded.cpp index e0d77671..27e3e66f 100644 --- a/src/multithreaded.cpp +++ b/src/multithreaded.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include void do_work(chaiscript::ChaiScript &c) { @@ -20,21 +20,21 @@ void do_work(chaiscript::ChaiScript &c) } int main(int argc, char *argv[]) { - std::string input; - chaiscript::ChaiScript chai; + std::string input; + chaiscript::ChaiScript chai; - //chai.add_shared_object(chaiscript::Boxed_Value(10000), "num_iterations"); + //chai.add_shared_object(chaiscript::Boxed_Value(10000), "num_iterations"); - std::vector > threads; + std::vector > threads; - for (int i = 0; i < argc - 1; ++i) - { - threads.push_back(std::shared_ptr(new boost::thread(std::bind(do_work, std::ref(chai))))); - } + for (int i = 0; i < argc - 1; ++i) + { + threads.push_back(std::shared_ptr(new std::thread(std::bind(do_work, std::ref(chai))))); + } - for (int i = 0; i < argc - 1; ++i) - { - threads[i]->join(); - } + for (int i = 0; i < argc - 1; ++i) + { + threads[i]->join(); + } } From 5efdcdff99729587e90454b51d492359aea538e1 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 11 Sep 2011 09:19:06 -0600 Subject: [PATCH 014/108] Remove need for boost::thread_local_ptr --- include/chaiscript/chaiscript_threading.hpp | 32 +++++++++++++------ .../dispatchkit/proxy_functions.hpp | 1 + 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/include/chaiscript/chaiscript_threading.hpp b/include/chaiscript/chaiscript_threading.hpp index a8d8d8c9..bc7ae3cd 100644 --- a/include/chaiscript/chaiscript_threading.hpp +++ b/include/chaiscript/chaiscript_threading.hpp @@ -10,7 +10,6 @@ #ifndef CHAISCRIPT_NO_THREADS #include #include -#include #else #pragma message ("ChaiScript is compiling without thread safety.") #endif @@ -59,6 +58,8 @@ namespace chaiscript class shared_mutex : public std::mutex { }; + using std::mutex; + using std::recursive_mutex; @@ -71,26 +72,37 @@ namespace chaiscript public: ~Thread_Storage() { - m_thread_storage.reset(); } inline T *operator->() const { - if (!m_thread_storage.get()) - { - m_thread_storage.reset(new T()); - } - - return m_thread_storage.get(); + return get_tls().get(); } inline T &operator*() const { - return *(this->operator->()); + return *get_tls(); } + private: - mutable boost::thread_specific_ptr m_thread_storage; + std::shared_ptr get_tls() const + { + unique_lock lock(m_mutex); + + typename std::map >::iterator itr = m_instances.find(std::this_thread::get_id()); + + if (itr != m_instances.end()) { return itr->second; } + + std::shared_ptr new_instance(new T()); + + m_instances.insert(std::make_pair(std::this_thread::get_id(), new_instance)); + + return new_instance; + } + + mutable mutex m_mutex; + mutable std::map > m_instances; }; #else diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index f25b43b2..5225121d 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "proxy_functions_detail.hpp" namespace chaiscript From a3c3b8683b1602237d1179c459447b9024bead1e Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 11 Sep 2011 09:22:44 -0600 Subject: [PATCH 015/108] Rename variables to reflect removal of boost --- unittests/boxed_cast_test.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/unittests/boxed_cast_test.cpp b/unittests/boxed_cast_test.cpp index 4a328463..c3c8931d 100644 --- a/unittests/boxed_cast_test.cpp +++ b/unittests/boxed_cast_test.cpp @@ -57,8 +57,8 @@ template bool do_test(const Boxed_Value &bv, bool T, bool ConstT, bool TRef, bool ConstTRef, bool TPtr, bool ConstTPtr, bool TPtrConst, bool ConstTPtrConst, bool SharedPtrT, bool SharedConstPtrT, bool ConstSharedPtrT, bool ConstSharedConstPtrT, bool ConstSharedPtrTRef, bool ConstSharedPtrTConstRef, - bool BoostRef, bool BoostConstRef, bool ConstBoostRef, bool ConstBoostConstRef, - bool ConstBoostRefRef, bool ConstBoostConstRefRef, bool Number, + bool WrappedRef, bool WrappedConstRef, bool ConstWrappedRef, bool ConstWrappedConstRef, + bool ConstWrappedRefRef, bool ConstWrappedConstRefRef, bool Number, bool ConstNumber, bool ConstNumberRef, bool TPtrConstRef, bool ConstTPtrConstRef) { bool passed = true; @@ -78,14 +78,14 @@ bool do_test(const Boxed_Value &bv, bool T, bool ConstT, bool TRef, bool ConstTR passed &= test_type_conversion >(bv, ConstSharedConstPtrT); passed &= test_type_conversion &>(bv, ConstSharedPtrTRef); passed &= test_type_conversion &>(bv, ConstSharedPtrTConstRef); - passed &= test_type_conversion >(bv, BoostRef); - passed &= test_type_conversion >(bv, BoostConstRef); + passed &= test_type_conversion >(bv, WrappedRef); + passed &= test_type_conversion >(bv, WrappedConstRef); passed &= test_type_conversion &>(bv, false); passed &= test_type_conversion &>(bv, false); - passed &= test_type_conversion >(bv, ConstBoostRef); - passed &= test_type_conversion >(bv, ConstBoostConstRef); - passed &= test_type_conversion &>(bv, ConstBoostRefRef); - passed &= test_type_conversion &>(bv, ConstBoostConstRefRef); + passed &= test_type_conversion >(bv, ConstWrappedRef); + passed &= test_type_conversion >(bv, ConstWrappedConstRef); + passed &= test_type_conversion &>(bv, ConstWrappedRefRef); + passed &= test_type_conversion &>(bv, ConstWrappedConstRefRef); passed &= test_type_conversion(bv, Number); passed &= test_type_conversion(bv, ConstNumber); passed &= test_type_conversion(bv, false); @@ -293,8 +293,8 @@ int main() /* bool T, bool ConstT, bool TRef, bool ConstTRef, bool TPtr, bool ConstTPtr, bool TPtrConst, bool ConstTPtrConst, bool SharedPtrT, bool SharedConstPtrT, - bool ConstSharedPtrT, bool ConstSharedConstPtrT, bool ConstSharedPtrTRef, bool ConstSharedPtrTConstRef, bool BoostRef, - bool BoostConstRef, bool ConstBoostRef, bool ConstBoostConstRef, bool ConstBoostRefRef, bool ConstBoostConstRefRef, + bool ConstSharedPtrT, bool ConstSharedConstPtrT, bool ConstSharedPtrTRef, bool ConstSharedPtrTConstRef, bool WrappedRef, + bool WrappedConstRef, bool ConstWrappedRef, bool ConstWrappedConstRef, bool ConstWrappedRefRef, bool ConstWrappedConstRefRef, bool Number, bool ConstNumber, bool ConstNumberRef */ From 194001f9a1114d4492465615d7f4c9049191e9f1 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 11 Sep 2011 19:51:37 -0600 Subject: [PATCH 016/108] Remove boost::any requirement by providing our own implementation --- include/chaiscript/dispatchkit/any.hpp | 162 ++++++++++++++++++ include/chaiscript/dispatchkit/boxed_cast.hpp | 5 +- .../dispatchkit/boxed_cast_helper.hpp | 31 ++-- .../chaiscript/dispatchkit/boxed_number.hpp | 32 ++-- .../chaiscript/dispatchkit/boxed_value.hpp | 18 +- .../chaiscript/dispatchkit/dispatchkit.hpp | 6 +- .../dispatchkit/dynamic_cast_conversion.hpp | 6 +- .../dispatchkit/exception_specification.hpp | 2 +- .../chaiscript/language/chaiscript_engine.hpp | 38 ++-- 9 files changed, 230 insertions(+), 70 deletions(-) create mode 100644 include/chaiscript/dispatchkit/any.hpp diff --git a/include/chaiscript/dispatchkit/any.hpp b/include/chaiscript/dispatchkit/any.hpp new file mode 100644 index 00000000..a6cce3d3 --- /dev/null +++ b/include/chaiscript/dispatchkit/any.hpp @@ -0,0 +1,162 @@ +// This file is distributed under the BSD License. +// See "license.txt" for details. +// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// and Jason Turner (jason@emptycrate.com) +// http://www.chaiscript.com + +#ifndef CHAISCRIPT_ANY_HPP_ +#define CHAISCRIPT_ANY_HPP_ + +namespace chaiscript { + namespace detail { + namespace exception + { + /// \brief Thrown in the event that an Any cannot be cast to the desired type + /// + /// It is used internally during function dispatch. + /// + /// \sa chaiscript::detail::Any + class bad_any_cast : public std::bad_cast + { + public: + bad_any_cast() throw() + : m_what("bad any cast") + { + } + + virtual ~bad_any_cast() throw() {} + + /// \brief Description of what error occured + virtual const char * what() const throw() + { + return m_what.c_str(); + } + + private: + std::string m_what; + }; + } + + + class Any { + private: + struct Data + { + virtual void *data() = 0; + virtual const std::type_info &type() const = 0; + virtual std::shared_ptr clone() const = 0; + }; + + template + struct Data_Impl : Data + { + Data_Impl(const T &t_type) + : m_type(typeid(T)), + m_data(t_type) + { + } + + virtual void *data() + { + return &m_data; + } + + const std::type_info &type() const + { + return m_type; + } + + std::shared_ptr clone() const + { + return std::shared_ptr(new Data_Impl(m_data)); + } + + const std::type_info &m_type; + T m_data; + }; + + std::shared_ptr m_data; + + public: + // construct/copy/destruct + Any() {} + + Any(const Any &t_any) + { + if (!t_any.empty()) + { + m_data = t_any.m_data->clone(); + } else { + m_data.reset(); + } + } + + template + Any(const ValueType &t_value) + { + m_data = std::shared_ptr(new Data_Impl(t_value)); + } + + Any & operator=(const Any &t_any) + { + Any copy(t_any); + swap(copy); + return *this; + } + + template + Any & operator=(const ValueType &t_value) + { + m_data = std::shared_ptr(new Data_Impl(t_value)); + return *this; + } + + template + ToType &cast() const + { + if (typeid(ToType) == m_data->type()) + { + return *static_cast(m_data->data()); + } else { + throw chaiscript::detail::exception::bad_any_cast(); + } + + } + + + ~Any() + { + } + + // modifiers + Any & swap(Any &t_other) + { + std::shared_ptr data = t_other.m_data; + t_other.m_data = m_data; + m_data = data; + return *this; + } + + // queries + bool empty() const + { + return !bool(m_data); + } + + const std::type_info & type() const + { + if (m_data) + { + return m_data->type(); + } else { + return typeid(void); + } + } + }; + + } +} + +#endif + + diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index c10aa724..c8b8e767 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -13,7 +13,6 @@ #include "dynamic_cast_conversion.hpp" #include "../chaiscript_threading.hpp" -#include namespace chaiscript { @@ -65,7 +64,7 @@ namespace chaiscript { try { return detail::Cast_Helper::cast(bv); - } catch (const boost::bad_any_cast &) { + } catch (const chaiscript::detail::exception::bad_any_cast &) { #ifdef BOOST_MSVC //Thank you MSVC, yes we know that a constant value is being used in the if @@ -80,7 +79,7 @@ namespace chaiscript // We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it // either way, we are not responsible if it doesn't work return detail::Cast_Helper::cast(detail::boxed_dynamic_cast(bv)); - } catch (const boost::bad_any_cast &) { + } catch (const chaiscript::detail::exception::bad_any_cast &) { throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type)); } } else { diff --git a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp index ae235564..aec80df1 100644 --- a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp @@ -10,7 +10,6 @@ #include "type_info.hpp" #include "boxed_value.hpp" -#include namespace chaiscript { @@ -32,16 +31,16 @@ namespace chaiscript { if (!ob.get_type_info().is_const()) { - return std::cref((boost::any_cast >(ob.get())).get()); + return std::cref((ob.get().cast >()).get()); } else { - return boost::any_cast >(ob.get()); + return ob.get().cast >(); } } else { if (!ob.get_type_info().is_const()) { - return std::cref(*(boost::any_cast >(ob.get()))); + return std::cref(*(ob.get().cast >())); } else { - return std::cref(*(boost::any_cast >(ob.get()))); + return std::cref(*(ob.get().cast >())); } } } @@ -74,16 +73,16 @@ namespace chaiscript { if (!ob.get_type_info().is_const()) { - return &(boost::any_cast >(ob.get())).get(); + return &(ob.get().cast >()).get(); } else { - return &(boost::any_cast >(ob.get())).get(); + return &(ob.get().cast >()).get(); } } else { if (!ob.get_type_info().is_const()) { - return (boost::any_cast >(ob.get())).get(); + return (ob.get().cast >()).get(); } else { - return (boost::any_cast >(ob.get())).get(); + return (ob.get().cast >()).get(); } } } @@ -101,9 +100,9 @@ namespace chaiscript { if (ob.is_ref()) { - return &(boost::any_cast >(ob.get())).get(); + return &(ob.get().cast >()).get(); } else { - return (boost::any_cast >(ob.get())).get(); + return (ob.get().cast >()).get(); } } }; @@ -120,9 +119,9 @@ namespace chaiscript { if (ob.is_ref()) { - return boost::any_cast >(ob.get()); + return ob.get().cast >(); } else { - Result &r = *(boost::any_cast >(ob.get())); + Result &r = *(ob.get().cast >()); return r; } } @@ -138,7 +137,7 @@ namespace chaiscript static Result_Type cast(const Boxed_Value &ob) { - return boost::any_cast >(ob.get()); + return ob.get().cast >(); } }; @@ -154,9 +153,9 @@ namespace chaiscript { if (!ob.get_type_info().is_const()) { - return std::const_pointer_cast(boost::any_cast >(ob.get())); + return std::const_pointer_cast(ob.get().cast >()); } else { - return boost::any_cast >(ob.get()); + return ob.get().cast >(); } } }; diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index f593e624..0241c5b3 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -38,9 +38,9 @@ namespace chaiscript case Operators::not_equal: return const_var(t != u); default: - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } }; @@ -73,7 +73,7 @@ namespace chaiscript t -= u; break; default: - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } return t_lhs; @@ -106,7 +106,7 @@ namespace chaiscript t ^= u; break; default: - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } return t_lhs; } @@ -134,9 +134,9 @@ namespace chaiscript case Operators::bitwise_complement: return const_var(~t); default: - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } }; @@ -160,9 +160,9 @@ namespace chaiscript case Operators::unary_plus: return const_var(+t); default: - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } }; @@ -183,7 +183,7 @@ namespace chaiscript } else if (t_oper > Operators::const_flag) { return const_binary::go(t_oper, *static_cast(t_lhs.get_const_ptr()), *static_cast(t_rhs.get_const_ptr()), t_lhs); } else { - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } } }; @@ -199,13 +199,13 @@ namespace chaiscript } else if (t_oper > Operators::non_const_flag && t_oper < Operators::non_const_int_flag && !t_lhs.is_const()) { return binary::go(t_oper, *static_cast(t_lhs.get_ptr()), *static_cast(t_rhs.get_const_ptr()), t_lhs); } else if (t_oper > Operators::non_const_int_flag && t_oper < Operators::const_int_flag) { - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } else if (t_oper > Operators::const_int_flag && t_oper < Operators::const_flag) { - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } else if (t_oper > Operators::const_flag) { return const_binary::go(t_oper, *static_cast(t_lhs.get_const_ptr()), *static_cast(t_rhs.get_const_ptr()), t_lhs); } else { - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } } }; @@ -248,7 +248,7 @@ namespace chaiscript } else if (inp_ == typeid(std::uint64_t)) { return Go::go(t_oper, t_lhs, t_rhs); } else { - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } } @@ -289,7 +289,7 @@ namespace chaiscript } else if (inp_ == typeid(std::uint64_t)) { return oper_rhs(t_oper, t_lhs, t_rhs); } else { - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } } @@ -302,12 +302,12 @@ namespace chaiscript const Type_Info &inp_ = v.get_type_info(); if (inp_ == typeid(bool)) { - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } if (!inp_.is_arithmetic()) { - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } } diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 76a785fc..c7b6ca71 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -12,7 +12,7 @@ #include "../chaiscript_threading.hpp" #include -#include +#include "any.hpp" namespace chaiscript { @@ -36,7 +36,7 @@ namespace chaiscript struct Data { Data(const Type_Info &ti, - const boost::any &to, + const chaiscript::detail::Any &to, bool tr, const void *t_void_ptr) : m_type_info(ti), m_obj(to), m_data_ptr(ti.is_const()?0:const_cast(t_void_ptr)), m_const_data_ptr(t_void_ptr), @@ -60,7 +60,7 @@ namespace chaiscript } Type_Info m_type_info; - boost::any m_obj; + chaiscript::detail::Any m_obj; void *m_data_ptr; const void *m_const_data_ptr; bool m_is_ref; @@ -73,7 +73,7 @@ namespace chaiscript { return std::shared_ptr (new Data( detail::Get_Type_Info::get(), - boost::any(), + chaiscript::detail::Any(), false, 0) ); @@ -90,7 +90,7 @@ namespace chaiscript { return std::shared_ptr(new Data( detail::Get_Type_Info::get(), - boost::any(obj), + chaiscript::detail::Any(obj), false, obj.get()) ); @@ -107,7 +107,7 @@ namespace chaiscript { return std::shared_ptr(new Data( detail::Get_Type_Info::get(), - boost::any(obj), + chaiscript::detail::Any(obj), true, &obj.get()) ); @@ -119,7 +119,7 @@ namespace chaiscript std::shared_ptr p(new T(t)); return std::shared_ptr(new Data( detail::Get_Type_Info::get(), - boost::any(p), + chaiscript::detail::Any(p), false, p.get()) ); @@ -129,7 +129,7 @@ namespace chaiscript { return std::shared_ptr (new Data( Type_Info(), - boost::any(), + chaiscript::detail::Any(), false, 0) ); @@ -220,7 +220,7 @@ namespace chaiscript return (m_data->m_data_ptr == 0 && m_data->m_const_data_ptr == 0); } - const boost::any & get() const + const chaiscript::detail::Any & get() const { return m_data->m_obj; } diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index ecb4de43..04936be2 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -100,7 +100,7 @@ namespace chaiscript { if (!t_bv.is_const()) { - throw exception::global_non_const(); + throw chaiscript::exception::global_non_const(); } m_globals.push_back(std::make_pair(t_bv, t_name)); @@ -421,7 +421,7 @@ namespace chaiscript validate_object_name(name); if (!obj.is_const()) { - throw exception::global_non_const(); + throw chaiscript::exception::global_non_const(); } chaiscript::detail::threading::unique_lock l(m_global_object_mutex); @@ -928,7 +928,7 @@ namespace chaiscript if (m_state.m_reserved_words.find(name) != m_state.m_reserved_words.end()) { - throw exception::reserved_word_error(name); + throw chaiscript::exception::reserved_word_error(name); } } diff --git a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp index 1bb5447a..c0245639 100644 --- a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp +++ b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp @@ -117,7 +117,7 @@ namespace chaiscript } } } else { - throw exception::bad_boxed_dynamic_cast(t_derived.get_type_info(), typeid(Base), "Unknown dynamic_cast_conversion"); + throw chaiscript::exception::bad_boxed_dynamic_cast(t_derived.get_type_info(), typeid(Base), "Unknown dynamic_cast_conversion"); } } }; @@ -272,9 +272,9 @@ namespace chaiscript try { return detail::Dynamic_Conversions::get().get_conversion(user_type(), derived.get_type_info())->convert(derived); } catch (const std::out_of_range &) { - throw exception::bad_boxed_dynamic_cast(derived.get_type_info(), typeid(Base), "No known conversion"); + throw chaiscript::exception::bad_boxed_dynamic_cast(derived.get_type_info(), typeid(Base), "No known conversion"); } catch (const std::bad_cast &) { - throw exception::bad_boxed_dynamic_cast(derived.get_type_info(), typeid(Base), "Unable to perform dynamic_cast operation"); + throw chaiscript::exception::bad_boxed_dynamic_cast(derived.get_type_info(), typeid(Base), "Unable to perform dynamic_cast operation"); } } } diff --git a/include/chaiscript/dispatchkit/exception_specification.hpp b/include/chaiscript/dispatchkit/exception_specification.hpp index ff169c37..0f08cdc0 100644 --- a/include/chaiscript/dispatchkit/exception_specification.hpp +++ b/include/chaiscript/dispatchkit/exception_specification.hpp @@ -21,7 +21,7 @@ namespace chaiscript template void throw_type(const Boxed_Value &bv) { - try { T t = boxed_cast(bv); throw t; } catch (const exception::bad_boxed_cast &) {} + try { T t = boxed_cast(bv); throw t; } catch (const chaiscript::exception::bad_boxed_cast &) {} } }; diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 4b912398..e0816b78 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -57,7 +57,7 @@ namespace chaiscript { if (!m_data) { - throw exception::load_module_error(dlerror()); + throw chaiscript::exception::load_module_error(dlerror()); } } @@ -80,7 +80,7 @@ namespace chaiscript { if (!m_symbol) { - throw exception::load_module_error(dlerror()); + throw chaiscript::exception::load_module_error(dlerror()); } } @@ -180,7 +180,7 @@ namespace chaiscript { if (!m_data) { - throw exception::load_module_error(GetErrorMessage(GetLastError())); + throw chaiscript::exception::load_module_error(GetErrorMessage(GetLastError())); } } @@ -200,7 +200,7 @@ namespace chaiscript { if (!m_symbol) { - throw exception::load_module_error(GetErrorMessage(GetLastError())); + throw chaiscript::exception::load_module_error(GetErrorMessage(GetLastError())); } } @@ -223,7 +223,7 @@ namespace chaiscript { Loadable_Module(const std::string &, const std::string &) { - throw exception::load_module_error("Loadable module support not available for your platform"); + throw chaiscript::exception::load_module_error("Loadable module support not available for your platform"); } ModulePtr m_moduleptr; @@ -302,10 +302,10 @@ namespace chaiscript l2.unlock(); eval_file(appendedpath); } - } catch (const exception::file_not_found_error &) { + } catch (const chaiscript::exception::file_not_found_error &) { if (i == m_usepaths.size() - 1) { - throw exception::file_not_found_error(t_filename); + throw chaiscript::exception::file_not_found_error(t_filename); } // failed to load, try the next path @@ -378,7 +378,7 @@ namespace chaiscript std::ifstream infile(t_filename.c_str(), std::ios::in | std::ios::ate | std::ios::binary ); if (!infile.is_open()) { - throw exception::file_not_found_error(t_filename); + throw chaiscript::exception::file_not_found_error(t_filename); } std::streampos size = infile.tellg(); @@ -420,7 +420,7 @@ namespace chaiscript /// \brief Adds a constant object that is available in all contexts and to all threads /// \param[in] t_bv Boxed_Value to add as a global /// \param[in] t_name Name of the value to add - /// \throw exception::global_non_const If t_bv is not a constant object + /// \throw chaiscript::exception::global_non_const If t_bv is not a constant object /// \sa Boxed_Value::is_const ChaiScript &add_global_const(const Boxed_Value &t_bv, const std::string &t_name) { @@ -536,7 +536,7 @@ namespace chaiscript /// If no file can be found matching the search criteria and containing the appropriate entry point /// (the symbol mentioned above), an exception is thrown. /// - /// \throw exception::load_module_error In the event that no matching module can be found. + /// \throw chaiscript::exception::load_module_error In the event that no matching module can be found. void load_module(const std::string &t_module_name) { std::vector errors; @@ -560,7 +560,7 @@ namespace chaiscript std::string name = m_modulepaths[i] + prefixes[j] + t_module_name + postfixes[k]; load_module(t_module_name, name); return; - } catch (const exception::load_module_error &e) { + } catch (const chaiscript::exception::load_module_error &e) { errors.push_back(e); // Try next set } @@ -582,7 +582,7 @@ namespace chaiscript errstring += itr->what(); } - throw exception::load_module_error("Unable to find module: " + t_module_name + " Errors: " + errstring); + throw chaiscript::exception::load_module_error("Unable to find module: " + t_module_name + " Errors: " + errstring); } /// \brief Load a binary module from a dynamic library. Works on platforms that support @@ -616,7 +616,7 @@ namespace chaiscript /// /// \return result of the script execution /// - /// \throw exception::eval_error In the case that evaluation fails. + /// \throw chaiscript::exception::eval_error In the case that evaluation fails. Boxed_Value operator()(const std::string &t_script, const Exception_Handler &t_handler = Exception_Handler()) { try { @@ -637,8 +637,8 @@ namespace chaiscript /// /// \return result of the script execution /// - /// \throw exception::eval_error In the case that evaluation fails. - /// \throw exception::bad_boxed_cast In the case that evaluation succeeds but the result value cannot be converted + /// \throw chaiscript::exception::eval_error In the case that evaluation fails. + /// \throw chaiscript::exception::bad_boxed_cast In the case that evaluation succeeds but the result value cannot be converted /// to the requested type. template T eval(const std::string &t_input, const Exception_Handler &t_handler = Exception_Handler()) @@ -660,7 +660,7 @@ namespace chaiscript /// /// \return result of the script execution /// - /// \throw exception::eval_error In the case that evaluation fails. + /// \throw chaiscript::exception::eval_error In the case that evaluation fails. Boxed_Value eval(const std::string &t_input, const Exception_Handler &t_handler = Exception_Handler()) { try { @@ -677,7 +677,7 @@ namespace chaiscript /// \param[in] t_filename File to load and parse. /// \param[in] t_handler Optional Exception_Handler used for automatic unboxing of script thrown exceptions /// \return result of the script execution - /// \throw exception::eval_error In the case that evaluation fails. + /// \throw chaiscript::exception::eval_error In the case that evaluation fails. Boxed_Value eval_file(const std::string &t_filename, const Exception_Handler &t_handler = Exception_Handler()) { try { return do_eval(load_file(t_filename), t_filename); @@ -694,8 +694,8 @@ namespace chaiscript /// \param[in] t_filename File to load and parse. /// \param[in] t_handler Optional Exception_Handler used for automatic unboxing of script thrown exceptions /// \return result of the script execution - /// \throw exception::eval_error In the case that evaluation fails. - /// \throw exception::bad_boxed_cast In the case that evaluation succeeds but the result value cannot be converted + /// \throw chaiscript::exception::eval_error In the case that evaluation fails. + /// \throw chaiscript::exception::bad_boxed_cast In the case that evaluation succeeds but the result value cannot be converted /// to the requested type. template T eval_file(const std::string &t_filename, const Exception_Handler &t_handler = Exception_Handler()) { From 6f282b6a5677682065f264578983a8f259b34f67 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 12 Sep 2011 08:18:51 -0600 Subject: [PATCH 017/108] Remove need for boost::function_types library --- include/chaiscript/dispatchkit/bootstrap.hpp | 6 +- .../chaiscript/dispatchkit/dispatchkit.hpp | 1 + .../dispatchkit/dynamic_cast_conversion.hpp | 6 +- .../dispatchkit/register_function.hpp | 59 +++++++++++-------- .../chaiscript/language/chaiscript_parser.hpp | 1 + 5 files changed, 42 insertions(+), 31 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 575803e2..ca430849 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -12,8 +12,8 @@ #include "register_function.hpp" #include "operators.hpp" #include "boxed_number.hpp" -#include #include +#include namespace chaiscript { @@ -346,7 +346,9 @@ namespace chaiscript static std::vector do_return_boxed_value_vector(FunctionType f, const dispatch::Proxy_Function_Base *b) { - typedef typename boost::function_types::result_type::type Vector; + typedef decltype(std::mem_fn(f)) MemFunType; + typedef typename MemFunType::result_type Vector; + Vector v = (b->*f)(); std::vector vbv; diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index 04936be2..1d51639a 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "boxed_value.hpp" #include "type_info.hpp" diff --git a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp index c0245639..f6fb7bf1 100644 --- a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp +++ b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp @@ -246,9 +246,9 @@ namespace chaiscript { //Can only be used with related polymorphic types //may be expanded some day to support conversions other than child -> parent - BOOST_STATIC_ASSERT((std::is_base_of::value)); - BOOST_STATIC_ASSERT(std::is_polymorphic::value); - BOOST_STATIC_ASSERT(std::is_polymorphic::value); + static_assert(std::is_base_of::value, "Classes are not related by inheritance"); + static_assert(std::is_polymorphic::value, "Base class must be polymorphic"); + static_assert(std::is_polymorphic::value, "Derived class must be polymorphic"); return detail::Dynamic_Conversions::create(); } diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index e62064a7..2bb4cfe4 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -9,8 +9,6 @@ #include "dispatchkit.hpp" #include "bind_first.hpp" -#include -#include namespace chaiscript { @@ -18,39 +16,48 @@ namespace chaiscript { namespace detail { - template + template + struct FunctionSignature + { + }; + + template + struct FunctionSignature > + { + typedef Sig Signature; + }; + + template + std::function to_function(Ret (*func)(Args...)) + { + return std::function(func); + } + + template + std::function to_function(Ret (Class::*func)(Args...)) + { + return std::function(func); + } + + template + std::function to_function(Ret (Class::*func)(Args...) const) + { + return std::function(func); + } + + template struct Fun_Helper { template static Proxy_Function go(T t) { return Proxy_Function( - new Proxy_Function_Impl< - typename boost::function_types::function_type >::type> ( - std::function< - typename boost::function_types::function_type >::type - >(t))); + new Proxy_Function_Impl::Signature>(to_function(t))); } }; template<> - struct Fun_Helper - { - template - static Proxy_Function go(T t) - { - return Proxy_Function( - new Proxy_Function_Impl< - typename boost::function_types::function_type >::type> ( - std::function< - typename boost::function_types::function_type >::type - >(std::mem_fn(t)))); - } - }; - - - template<> - struct Fun_Helper + struct Fun_Helper { template static Proxy_Function go(T Class::* m) @@ -101,7 +108,7 @@ namespace chaiscript template Proxy_Function fun(T t) { - return dispatch::detail::Fun_Helper::value, std::is_member_function_pointer::value>::go(t); + return dispatch::detail::Fun_Helper::value>::go(t); } /// \brief Creates a new Proxy_Function object from a free function, member function or data member and binds the first parameter of it diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index aa10437d..67a5ddce 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "chaiscript_prelude.hpp" #include "chaiscript_common.hpp" From cc927fc6bc0734c013a54ad8311ed12528b720c8 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 12 Sep 2011 11:09:57 -0600 Subject: [PATCH 018/108] Remove remaining non-boost_pp libraries as requirements. --- samples/example.cpp | 10 +++++----- src/main.cpp | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/samples/example.cpp b/samples/example.cpp index 5a706f04..cd3ad9bd 100644 --- a/samples/example.cpp +++ b/samples/example.cpp @@ -8,17 +8,15 @@ #include #include -#include -#include void log(const std::string &msg) { - std::cout << "[" << boost::posix_time::microsec_clock::local_time() << "] " << msg << std::endl; + std::cout << "[" << time(nullptr) << "] " << msg << std::endl; } void log(const std::string &module, const std::string &msg) { - std::cout << "[" << boost::posix_time::microsec_clock::local_time() << "] <" << module << "> " << msg << std::endl; + std::cout << "[" << time(nullptr) << "] <" << module << "> " << msg << std::endl; } void bound_log(const std::string &msg) @@ -140,7 +138,9 @@ int main(int /*argc*/, char * /*argv*/[]) { //Creating a functor on the stack and using it immediatly int x = chai.eval >("fun (x, y) { return x + y; }")(5, 6); - log("Functor test output", boost::lexical_cast(x)); + std::stringstream ss; + ss << x; + log("Functor test output", ss.str()); chai.add(var(std::shared_ptr()), "nullvar"); chai("print(\"This should be true.\"); print(nullvar.is_var_null())"); diff --git a/src/main.cpp b/src/main.cpp index 9cec2dbf..50cb43a4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #define _CRT_SECURE_NO_WARNINGS #include @@ -80,7 +80,21 @@ std::string get_next_command() { char *input_raw = readline("eval> "); if ( input_raw ) { add_history(input_raw); - retval = boost::trim_copy_if(std::string(input_raw),boost::algorithm::is_any_of(" \t")); + + std::string val(input_raw); + size_t pos = val.find_first_not_of("\t \n"); + if (pos != std::string::npos) + { + val.erase(0, pos); + } + pos = val.find_last_not_of("\t \n"); + if (pos != std::string::npos) + { + val.erase(pos+1, std::string::npos); + } + + retval = val; + ::free(input_raw); } } From d5e1650167eac88ea9f68b0a8a97956b96c3d93e Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 12 Sep 2011 23:08:27 -0600 Subject: [PATCH 019/108] First file to eliminate need for boost_pp. 2 more to go --- .../dispatchkit/proxy_functions_detail.hpp | 137 ++++++++++-------- 1 file changed, 80 insertions(+), 57 deletions(-) diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index 7d93393e..6900f146 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -4,13 +4,6 @@ // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com -#include - -#define gettypeinfo(z,n,text) ti.push_back(chaiscript::detail::Get_Type_Info::get()); -#define casthelper(z,n,text) BOOST_PP_COMMA_IF(n) chaiscript::boxed_cast< Param ## n >(params[n]) -#define trycast(z,n,text) chaiscript::boxed_cast(params[n]); - -#ifndef BOOST_PP_IS_ITERATING #ifndef CHAISCRIPT_PROXY_FUNCTIONS_DETAIL_HPP_ #define CHAISCRIPT_PROXY_FUNCTIONS_DETAIL_HPP_ @@ -46,19 +39,6 @@ namespace chaiscript }; } -} - -#define BOOST_PP_ITERATION_LIMITS ( 0, 10 ) -#define BOOST_PP_FILENAME_1 -#include BOOST_PP_ITERATE() - - -# endif -#else -# define n BOOST_PP_ITERATION() - -namespace chaiscript -{ namespace dispatch { namespace detail @@ -67,62 +47,105 @@ namespace chaiscript * Used by Proxy_Function_Impl to return a list of all param types * it contains. */ - template - std::vector build_param_type_list(Ret (*)(BOOST_PP_ENUM_PARAMS(n, Param))) + template + std::vector build_param_type_list(Ret (*)(Params...)) { - std::vector ti; - ti.push_back(chaiscript::detail::Get_Type_Info::get()); - - BOOST_PP_REPEAT(n, gettypeinfo, ~) - - return ti; + return std::vector { chaiscript::detail::Get_Type_Info::get(), + chaiscript::detail::Get_Type_Info::get()... }; } + + // Forward declaration + template + struct Try_Cast; + + // implementation + template + struct Try_Cast + { + static void do_try(const std::vector ¶ms, int generation) + { + boxed_cast(params[generation]); + Try_Cast::do_try(params, generation+1); + } + }; + + // 0th case + template<> + struct Try_Cast<> + { + static void do_try(const std::vector &, int) + { + } + }; + + + + /** + * Used by Proxy_Function_Impl to determine if it is equivalent to another + * Proxy_Function_Impl object. This function is primarly used to prevent + * registration of two functions with the exact same signatures + */ + template + bool compare_types_cast(Ret (*)(Params...), + const std::vector ¶ms) + { + try { + Try_Cast::do_try(params, 0); + } catch (const exception::bad_boxed_cast &) { + return false; + } + + return true; + } + + template + struct Call_Func + { + + template + static Ret do_call(const std::function &f, + const std::vector ¶ms, InnerParams ... innerparams) + { + return Call_Func::do_call(f, params, innerparams..., params[sizeof...(Params) - count]); + } + }; + + template + struct Call_Func + { + template + static Ret do_call(const std::function &f, + const std::vector &, InnerParams ... innerparams) + { + return f(boxed_cast(innerparams)...); + } + }; + /** * Used by Proxy_Function_Impl to perform typesafe execution of a function. * The function attempts to unbox each paramter to the expected type. * if any unboxing fails the execution of the function fails and * the bad_boxed_cast is passed up to the caller. */ - template - Ret call_func(const std::function &f, + template + Ret call_func(const std::function &f, const std::vector ¶ms) { - if (params.size() != n) + if (params.size() == sizeof...(Params)) { - throw exception::arity_error(static_cast(params.size()), n); - } else { - return f(BOOST_PP_REPEAT(n, casthelper, ~)); - } - } - - /** - * Used by Proxy_Function_Impl to determine if it is equivalent to another - * Proxy_Function_Impl object. This function is primarly used to prevent - * registration of two functions with the exact same signatures - */ - template - bool compare_types_cast(Ret (*)(BOOST_PP_ENUM_PARAMS(n, Param)), - const std::vector & BOOST_PP_IF(n, params, )) - { - try { - BOOST_PP_REPEAT(n, trycast, ~); - } catch (const exception::bad_boxed_cast &) { - return false; + return Call_Func::do_call(f, params); } - return true; + throw exception::arity_error(static_cast(params.size()), sizeof...(Params)); } + } } + + } -#undef n - -#endif - - -#ifndef BOOST_PP_IS_ITERATING namespace chaiscript { From f996c0df37876dfce7ba4ee46a3b9edc24cf3a8b Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 13 Sep 2011 09:40:10 -0600 Subject: [PATCH 020/108] One more file no longer using boost_pp --- .../dispatchkit/proxy_constructors.hpp | 70 +++++++------------ 1 file changed, 25 insertions(+), 45 deletions(-) diff --git a/include/chaiscript/dispatchkit/proxy_constructors.hpp b/include/chaiscript/dispatchkit/proxy_constructors.hpp index b555489c..32bae3e6 100644 --- a/include/chaiscript/dispatchkit/proxy_constructors.hpp +++ b/include/chaiscript/dispatchkit/proxy_constructors.hpp @@ -4,21 +4,36 @@ // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com -#include -#ifndef BOOST_PP_IS_ITERATING #ifndef CHAISCRIPT_PROXY_CONSTRUCTORS_HPP_ #define CHAISCRIPT_PROXY_CONSTRUCTORS_HPP_ - - -#define BOOST_PP_ITERATION_LIMITS ( 0, 10 ) -#define BOOST_PP_FILENAME_1 -#include BOOST_PP_ITERATE() -# endif - namespace chaiscript { + namespace dispatch + { + namespace detail + { + /** + * A constructor function, used for creating a new object + * of a given type with a given set of params + */ + template + std::shared_ptr constructor_(Params ... params) + { + return std::shared_ptr(new Class(params...)); + } + + template + Proxy_Function build_constructor_(Class (*)(Params...)) + { + typedef std::shared_ptr (sig)(Params...); + return Proxy_Function(new Proxy_Function_Impl(std::function(&(constructor_)))); + } + } + } + + /// \brief Generates a constructor function for use with ChaiScript /// /// \tparam T The signature of the constructor to generate. In the form of: ClassType (ParamType1, ParamType2, ...) @@ -36,43 +51,8 @@ namespace chaiscript T *f = 0; return (dispatch::detail::build_constructor_(f)); } + } -#else -# define n BOOST_PP_ITERATION() - -namespace chaiscript -{ - namespace dispatch - { - namespace detail - { - /** - * A constructor function, used for creating a new object - * of a given type with a given set of params - */ - template - std::shared_ptr constructor_( BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) ) - { - return std::shared_ptr(new Class( BOOST_PP_ENUM_PARAMS(n, p) )); - } - - /** - * Helper function for build a constructor function - * example: - * dispatchengine.register_function(build_constructor, "MyClass"); - * \todo See if it is possible to make this not be a variadic function - */ - template - Proxy_Function build_constructor_(Class (*)(BOOST_PP_ENUM_PARAMS(n, Param))) - { - typedef std::shared_ptr (sig)(BOOST_PP_ENUM_PARAMS(n, Param)); - return Proxy_Function(new Proxy_Function_Impl(std::function(&(constructor_)))); - } - } - } -} -#undef n - #endif From 64382a23995a9d5a189ae42c0bd804f9011ab615 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 13 Sep 2011 12:26:20 -0600 Subject: [PATCH 021/108] One more file with boost_pp removed --- .../dispatchkit/function_call_detail.hpp | 68 +++++++------------ 1 file changed, 25 insertions(+), 43 deletions(-) diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index e5312055..15ffaf34 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -4,13 +4,6 @@ // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com -#include - -#define addparam(z,n,text) params.push_back((std::is_reference::value&&!(std::is_same::type>::type>::value))?Boxed_Value(std::ref(BOOST_PP_CAT(p, n))):Boxed_Value(BOOST_PP_CAT(p, n) )); -#define curry(z,n,text) BOOST_PP_CAT(std::placeholders::_, BOOST_PP_INC(n)) - - -#ifndef BOOST_PP_IS_ITERATING #ifndef CHAISCRIPT_FUNCTION_CALL_DETAIL_HPP_ #define CHAISCRIPT_FUNCTION_CALL_DETAIL_HPP_ @@ -51,50 +44,41 @@ namespace chaiscript dispatch::dispatch(t_funcs, params); } }; - } - } -} -#define BOOST_PP_ITERATION_LIMITS ( 0, 9 ) -#define BOOST_PP_FILENAME_1 -#include BOOST_PP_ITERATE() - -# endif -#else -# define n BOOST_PP_ITERATION() - -namespace chaiscript -{ - namespace dispatch - { - namespace detail - { /** * used internally for unwrapping a function call's types */ - template - Ret function_caller(const std::vector &funcs - BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_BINARY_PARAMS(n, Param, p) ) + template + struct Build_Function_Caller_Helper { - std::vector params; + Build_Function_Caller_Helper(const std::vector &t_funcs) + : m_funcs(t_funcs) + { + } - BOOST_PP_REPEAT(n, addparam, ~) + Ret operator()(Param...param) + { + return Function_Caller_Ret::call(m_funcs, { +(std::is_reference::value&&!(std::is_same::type>::type>::value))?Boxed_Value(std::ref(param)):Boxed_Value(param)... + } + + ); - return Function_Caller_Ret::call(funcs, params); - } + } - /** - * used internally for unwrapping a function call's types - */ - template - std::function - build_function_caller_helper(Ret (BOOST_PP_ENUM_PARAMS(n, Param)), const std::vector &funcs) + std::vector m_funcs; + }; + + + + template + std::function build_function_caller_helper(Ret (Params...), const std::vector &funcs) { if (funcs.size() == 1) { - std::shared_ptr > pfi = - std::dynamic_pointer_cast > - (funcs[0]); + std::shared_ptr> pfi = + std::dynamic_pointer_cast > + (funcs[0]); if (pfi) { @@ -104,13 +88,11 @@ namespace chaiscript // we cannot make any other guesses or assumptions really, so continuing } - return std::bind(&function_caller, funcs - BOOST_PP_ENUM_TRAILING(n, curry, ~)); + return std::function(Build_Function_Caller_Helper(funcs)); } } } } -#undef n #endif From 6f1bffda3af58c6fb6892baba38974711464b1d2 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 15 Sep 2011 17:38:46 -0600 Subject: [PATCH 022/108] Remove boost from bind_first utility. --- include/chaiscript/dispatchkit/bind_first.hpp | 163 +++++++++++------- 1 file changed, 103 insertions(+), 60 deletions(-) diff --git a/include/chaiscript/dispatchkit/bind_first.hpp b/include/chaiscript/dispatchkit/bind_first.hpp index 27927249..a00d7ee3 100644 --- a/include/chaiscript/dispatchkit/bind_first.hpp +++ b/include/chaiscript/dispatchkit/bind_first.hpp @@ -4,87 +4,130 @@ // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com -#include -#include - -#define param(z,n,text) BOOST_PP_CAT(text, BOOST_PP_INC(n)) - -#ifndef BOOST_PP_IS_ITERATING #ifndef CHAISCRIPT_BIND_FIRST_HPP_ #define CHAISCRIPT_BIND_FIRST_HPP_ - -#define BOOST_PP_ITERATION_LIMITS ( 0, 8 ) -#define BOOST_PP_FILENAME_1 - -#include BOOST_PP_ITERATE() - - -# endif -#else -# define n BOOST_PP_ITERATION() -# define m BOOST_PP_INC(n) +#include namespace chaiscript { namespace detail - { - /// \brief Helper function for binding the first parameter of a class method pointer. Used in chaiscript::fun overloads - /// that take 1 or 2 parameters to pre-bind to the function. - /// - /// \param[in] f method pointer to bind - /// \param[in] o object to bind as first parameter - /// \returns a new std::function object with one fewer parameters than the function passed in. - template - std::function - bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const O &o) + { + + template + struct Placeholder { - return std::bind(std::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, std::placeholders::_)); + }; + + template<> + struct Placeholder<1> + { + static decltype(std::placeholders::_1) value() { return std::placeholders::_1; } + }; + + template<> + struct Placeholder<2> + { + static decltype(std::placeholders::_2) value() { return std::placeholders::_2; } + }; + + template<> + struct Placeholder<3> + { + static decltype(std::placeholders::_3) value() { return std::placeholders::_3; } + }; + + template<> + struct Placeholder<4> + { + static decltype(std::placeholders::_4) value() { return std::placeholders::_4; } + }; + + template<> + struct Placeholder<5> + { + static decltype(std::placeholders::_5) value() { return std::placeholders::_5; } + }; + + template<> + struct Placeholder<6> + { + static decltype(std::placeholders::_6) value() { return std::placeholders::_6; } + }; + + template<> + struct Placeholder<7> + { + static decltype(std::placeholders::_7) value() { return std::placeholders::_7; } + }; + + template<> + struct Placeholder<8> + { + static decltype(std::placeholders::_8) value() { return std::placeholders::_8; } + }; + + template<> + struct Placeholder<9> + { + static decltype(std::placeholders::_9) value() { return std::placeholders::_9; } + }; + + template<> + struct Placeholder<10> + { + static decltype(std::placeholders::_10) value() { return std::placeholders::_10; } + }; + + + template + struct Bind_First + { + template + static std::function bind(F f, InnerParams ... innerparams) + { + return Bind_First::bind(f, innerparams..., Placeholder::value()); + } + }; + + template + struct Bind_First<0, maxcount, Sig> + { + template + static std::function bind(F f, InnerParams ... innerparams) + { + return std::bind(f, innerparams...); + } + }; + + + template + std::function bind_first(Ret (*f)(P1, Param...), O o) + { + return Bind_First::bind(f, o); } - /// \brief Helper function for binding the first parameter of a const class method pointer. Used in chaiscript::fun overloads - /// that take 1 or 2 parameters to pre-bind to the function. - /// - /// \param[in] f method pointer to bind - /// \param[in] o object to bind as first parameter - /// \returns a new std::function object with one fewer parameters than the function passed in. - template - std::function - bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)) const, const O &o) + template + std::function bind_first(Ret (Class::*f)(Param...), O o) { - return std::bind(std::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, std::placeholders::_)); + return Bind_First::bind(f, o); } - /// \brief Helper function for binding the first parameter of a function pointer. Used in chaiscript::fun overloads - /// that take 1 or 2 parameters to pre-bind to the function. - /// - /// \param[in] f method pointer to bind - /// \param[in] o object to bind as first parameter - /// \returns a new std::function object with one fewer parameters than the function passed in. - template - std::function - bind_first(Ret (*f)(BOOST_PP_ENUM_PARAMS(m, Param)), const O &o) + template + std::function bind_first(Ret (Class::*f)(Param...) const, O o) { - return std::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, std::placeholders::_)); + return Bind_First::bind(f, o); } - /// \brief Helper function for binding the first parameter of a std::function object. Used in chaiscript::fun overloads - /// that take 1 or 2 parameters to pre-bind to the function. - /// - /// \param[in] f method pointer to bind - /// \param[in] o object to bind as first parameter - /// \returns a new std::function object with one fewer parameters than the function passed in. - template - std::function - bind_first(const std::function &f, const O &o) + template + std::function bind_first(const std::function &f, O o) { - return std::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, std::placeholders::_)); + return Bind_First::bind(f, o); } + } } -#undef n -#undef m #endif From d6b475239a839ab63b5ff132fe77507638780737 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 21 Sep 2011 00:04:15 -0600 Subject: [PATCH 023/108] Remove boost from utility and associated module tests --- CMakeLists.txt | 24 +------ include/chaiscript/utility/utility.hpp | 93 +++++--------------------- src/reflection.cpp | 64 ++++++++++-------- unittests/object_lifetime_test.cpp | 12 ++-- unittests/utility_test.cpp | 28 +++++--- 5 files changed, 78 insertions(+), 143 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d6c77af2..f2f2bcd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,13 +24,11 @@ set(CPACK_PACKAGE_VENDOR "ChaiScript.com") set(CPACK_PACKAGE_CONTACT "contact@chaiscript.com") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "An embedded scripting language for C++") -set(CPACK_DEBIAN_PACKAGE_DEPENDS "libboost-dev (>=1.36.0)") set(CPACK_DEBIAN_PACKAGE_SECTION "devel") set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") set(CPACK_RPM_PACKAGE_LICENSE "BSD") set(CPACK_RPM_PACKAGE_GROUP "Programming") -set(CPACK_RPM_PACKAGE_REQUIRES "boost-devel >= 1.36.0, boost-thread >= 1.36.0") set(CHAI_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}) @@ -64,24 +62,13 @@ else() add_definitions(-Wall -Wextra -Wshadow -pedantic -std=c++0x) if (APPLE) - # -Wno-missing-field-initializers is for boost on macos - add_definitions(-Wno-missing-field-initializers -Wno-sign-compare) + add_definitions(-Wno-sign-compare) endif() endif() include_directories(include) -set(Boost_ADDITIONAL_VERSIONS "1.44" "1.44.0" "1.43" "1.43.0" "1.42" "1.42.0" "1.41") -set(Boost_USE_MULTITHREADED ON) - if (MULTITHREAD_SUPPORT_ENABLED) - find_package(Boost 1.36.0 COMPONENTS thread) - - if (Boost_FOUND) - link_directories( ${Boost_LIBRARY_DIRS} ) - else() - message(FATAL_ERROR "Can not find Boost") - endif(Boost_FOUND) else() add_definitions(-DCHAISCRIPT_NO_THREADS) endif() @@ -90,20 +77,13 @@ if (CMAKE_HOST_UNIX) set(DYNAMIC_LOADER "dl") endif(CMAKE_HOST_UNIX) -if (MSVC) - # Boost on MSVC does automatic linking - set(LIBS ${DYNAMIC_LOADER} ${READLINE_LIB}) -else() - set(LIBS ${DYNAMIC_LOADER} ${Boost_LIBRARIES} ${READLINE_LIB}) -endif() +set(LIBS ${DYNAMIC_LOADER} ${READLINE_LIB}) if (CMAKE_COMPILER_2005) # vs2005 is a bit too loud about possible loss of data warnings # ADD_DEFINITIONS(/wd4244) endif() -include_directories(${Boost_INCLUDE_DIRS}) -include_directories(${Boost_INCLUDE_DIR}) add_executable(chai src/main.cpp) target_link_libraries(chai ${LIBS}) diff --git a/include/chaiscript/utility/utility.hpp b/include/chaiscript/utility/utility.hpp index a87bbaf5..47bd9b3b 100644 --- a/include/chaiscript/utility/utility.hpp +++ b/include/chaiscript/utility/utility.hpp @@ -8,90 +8,33 @@ #define CHAISCRIPT_UTILITY_UTILITY_HPP_ #include "../chaiscript.hpp" -#include #include -#define CHAISCRIPT_MODULE(_info) BOOST_PP_SEQ_ELEM(0, _info) - -#define CHAISCRIPT_CLASS_ELEM(_info) BOOST_PP_SEQ_ELEM(1, _info) - -#define CHAISCRIPT_METHOD(_info, _method) & CHAISCRIPT_CLASS_ELEM(_info) :: BOOST_PP_SEQ_ELEM(0, _method) - -#define CHAISCRIPT_METHOD_NAME(_info, _method) \ - BOOST_PP_SEQ_ELEM(3, _info) (BOOST_PP_STRINGIZE(BOOST_PP_SEQ_ELEM(0, _method ) ) ) - -#define CHAISCRIPT_CLASS_NAME(_info) \ - BOOST_PP_SEQ_ELEM(2, _info) (BOOST_PP_STRINGIZE(CHAISCRIPT_CLASS_ELEM(_info) ) ) - -#define CHAISCRIPT_METHOD_SIGNATURE_PART(_r, _info, _i, _method_part) \ - BOOST_PP_EXPR_IF(BOOST_PP_EQUAL(_i, 1), < _method_part > ) - -#define CHAISCRIPT_METHOD_SIGNATURE(_info, _method) \ - BOOST_PP_SEQ_FOR_EACH_I(CHAISCRIPT_METHOD_SIGNATURE_PART, _info, _method) - -#define CHAISCRIPT_CLASS_CONSTRUCTOR(_r, _info, _constructor) \ - CHAISCRIPT_MODULE(_info) ->add BOOST_PP_LPAREN() chaiscript::constructor<_constructor>() BOOST_PP_COMMA() CHAISCRIPT_CLASS_NAME(_info) BOOST_PP_RPAREN() ; - -#define CHAISCRIPT_CLASS_METHOD(_r, _info, _method) \ - CHAISCRIPT_MODULE(_info) ->add BOOST_PP_LPAREN() chaiscript::fun CHAISCRIPT_METHOD_SIGNATURE(_info, _method) \ - BOOST_PP_LPAREN() CHAISCRIPT_METHOD(_info, _method) BOOST_PP_RPAREN() BOOST_PP_COMMA() CHAISCRIPT_METHOD_NAME(_info, _method)BOOST_PP_RPAREN() ; - -#define CHAISCRIPT_CLASS_CONSTRUCTORS(_info, _constructors) \ - BOOST_PP_SEQ_FOR_EACH(CHAISCRIPT_CLASS_CONSTRUCTOR, _info, _constructors) - -#define CHAISCRIPT_CLASS_METHODS(_info, _methods) \ - BOOST_PP_SEQ_FOR_EACH(CHAISCRIPT_CLASS_METHOD, _info, _methods) - -#define CHAISCRIPT_CLASS_EX(_module, _class_name, _class_name_translator, _method_name_translator, _constructors, _methods) \ - { \ - _module->add(chaiscript::user_type<_class_name>(), _class_name_translator (BOOST_PP_STRINGIZE(_class_name))); \ - CHAISCRIPT_CLASS_CONSTRUCTORS((_module)(_class_name)(_class_name_translator), _constructors) \ - CHAISCRIPT_CLASS_METHODS((_module)(_class_name)(_class_name_translator)(_method_name_translator), _methods) \ - } - -#define CHAISCRIPT_CLASS_NO_CONSTRUCTOR_EX(_module, _class_name, _class_name_translator, _method_name_translator, _methods) \ - { \ - _module->add(chaiscript::user_type<_class_name>(), _class_name_translator (BOOST_PP_STRINGIZE(_class_name))); \ - CHAISCRIPT_CLASS_METHODS((_module)(_class_name)(_class_name_translator)(_method_name_translator), _methods) \ - } - -#define CHAISCRIPT_CLASS(_module, _class_name, _constructors, _methods) \ - CHAISCRIPT_CLASS_EX(_module, _class_name, chaiscript::utility::class_name_translator, \ - chaiscript::utility::method_name_translator, _constructors, _methods) - -#define CHAISCRIPT_CLASS_NO_CONSTRUCTOR(_module, _class_name, _methods) \ - CHAISCRIPT_CLASS_NO_CONSTRUCTOR_EX(_module, _class_name, chaiscript::utility::class_name_translator, \ - chaiscript::utility::method_name_translator, _methods) namespace chaiscript { - /// \brief Classes and functions which provide general utility to the end user. namespace utility { - inline std::string class_name_translator(const std::string &t_name) - { - size_t colon = t_name.rfind("::"); - if (colon != std::string::npos) + + template + void add_class(ModuleType &t_module, + const std::string &t_classname, + const std::vector &t_constructors, + const std::vector> &t_funcs) { - return t_name.substr(colon+2, std::string::npos); - } else { - return t_name; + t_module.add(chaiscript::user_type(), t_classname); + + for(const chaiscript::Proxy_Function &ctor: t_constructors) + { + t_module.add(ctor, t_classname); + } + + for(auto fun: t_funcs) + { + t_module.add(fun.first, fun.second); + } + } - } - - inline std::string method_name_translator(const std::string &t_name) - { - size_t namestart = t_name.rfind("operator"); - namestart = (namestart == std::string::npos)?0:namestart+strlen("operator"); - - if (namestart == 0) - { - namestart = t_name.rfind("::"); - namestart = (namestart == std::string::npos)?0:namestart+strlen("::"); - } - - return t_name.substr(namestart, std::string::npos); - } } } diff --git a/src/reflection.cpp b/src/reflection.cpp index d38c0b09..fe8bc3a0 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -52,38 +52,44 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect chaiscript::bootstrap::standard_library::vector_type > >("AST_NodeVector", m); - CHAISCRIPT_CLASS_NO_CONSTRUCTOR( m, - chaiscript::exception::eval_error, - ((reason)) - ((call_stack)) + using namespace chaiscript; + + chaiscript::utility::add_class(*m, + "eval_error", + { }, + { {fun(&chaiscript::exception::eval_error::reason), "reason"}, + {fun(&chaiscript::exception::eval_error::call_stack), "call_stack"} } + ); + + chaiscript::utility::add_class(*m, + "File_Position", + { constructor(), + constructor() }, + { {fun(&File_Position::line), "line"}, + {fun(&File_Position::column), "column"} } + ); + + chaiscript::utility::add_class(*m, + "AST_Node", + { }, + { {fun(&AST_Node::text), "text"}, + {fun(&AST_Node::identifier), "identifier"}, + {fun(&AST_Node::filename), "filename"}, + {fun(&AST_Node::start), "start"}, + {fun(&AST_Node::end), "end"}, + {fun(&AST_Node::internal_to_string), "internal_to_string"}, + {fun(&AST_Node::children), "children"}, + {fun(&AST_Node::replace_child), "replace_child"} + } ); - CHAISCRIPT_CLASS( m, - chaiscript::File_Position, - (chaiscript::File_Position()) - (chaiscript::File_Position(int,int)), - ((line)) - ((column)) - ); + chaiscript::utility::add_class(*m, + "ChaiScript_Parser", + { constructor() }, + { {fun(&parser::ChaiScript_Parser::parse), "parse"}, + {fun(&parser::ChaiScript_Parser::ast), "ast"} } + ); - CHAISCRIPT_CLASS_NO_CONSTRUCTOR( m, - chaiscript::AST_Node, - ((text)) - ((identifier)) - ((filename)) - ((start)) - ((end)) - ((internal_to_string)) - ((children)) - ((replace_child)) - ); - - CHAISCRIPT_CLASS( m, - chaiscript::parser::ChaiScript_Parser, - (chaiscript::parser::ChaiScript_Parser ()), - ((parse)) - ((ast)) - ); return m; diff --git a/unittests/object_lifetime_test.cpp b/unittests/object_lifetime_test.cpp index d59957b0..8d700fdc 100644 --- a/unittests/object_lifetime_test.cpp +++ b/unittests/object_lifetime_test.cpp @@ -29,12 +29,12 @@ int main() { chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module()); - CHAISCRIPT_CLASS( m, - Test, - (Test ()) - (Test (const Test &)), - ((count)) - ); + chaiscript::utility::add_class(*m, + "Test", + { chaiscript::constructor(), + chaiscript::constructor() }, + { {chaiscript::fun(&Test::count), "count"} } + ); chaiscript::ChaiScript chai; chai.add(m); diff --git a/unittests/utility_test.cpp b/unittests/utility_test.cpp index bcd3240b..40ee4dff 100644 --- a/unittests/utility_test.cpp +++ b/unittests/utility_test.cpp @@ -15,17 +15,23 @@ int main() chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module()); - CHAISCRIPT_CLASS( m, - Test, - (Test ()) - (Test (const Test &)), - ((function)) - ((function2)) - ((function3)) - ((functionOverload)(std::string (Test::*)(double))) - ((functionOverload)(std::string (Test::*)(int))) - ((operator=)) - ); + using namespace chaiscript; + + chaiscript::utility::add_class(*m, + "Test", + { constructor(), + constructor() }, + { {fun(&Test::function), "function"}, + {fun(&Test::function2), "function2"}, + {fun(&Test::function3), "function3"}, + {fun(&Test::functionOverload), "functionOverload"}, + {fun(&Test::functionOverload), "functionOverload"}, + {fun(&Test::operator=), "="} + + } + ); + + chaiscript::ChaiScript chai; chai.add(m); From 12bd5b0af5d07cc6546c4b5bd1159220bfcbc972 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 21 Sep 2011 08:36:46 -0600 Subject: [PATCH 024/108] Boost eradicated from ChaiScript --- contrib/codeanalysis/codeanalysis.sh | 2 +- include/chaiscript/chaiscript.hpp | 16 +++++++++------ include/chaiscript/chaiscript_defines.hpp | 20 +++++++++++++++++++ include/chaiscript/chaiscript_threading.hpp | 6 ++++-- include/chaiscript/dispatchkit/boxed_cast.hpp | 6 ++++-- include/chaiscript/dispatchkit/operators.hpp | 4 +++- .../language/chaiscript_algebraic.hpp | 2 +- .../chaiscript/language/chaiscript_common.hpp | 2 +- .../chaiscript/language/chaiscript_engine.hpp | 9 +++++---- .../chaiscript/language/chaiscript_eval.hpp | 2 +- readme.txt | 2 +- src/main.cpp | 6 +++--- src/multithreaded.cpp | 5 +++-- src/reflection.cpp | 4 ++-- src/stl_extra.cpp | 4 ++-- src/test_module.cpp | 4 ++-- 16 files changed, 63 insertions(+), 31 deletions(-) create mode 100644 include/chaiscript/chaiscript_defines.hpp diff --git a/contrib/codeanalysis/codeanalysis.sh b/contrib/codeanalysis/codeanalysis.sh index 6a322104..3da80b43 100755 --- a/contrib/codeanalysis/codeanalysis.sh +++ b/contrib/codeanalysis/codeanalysis.sh @@ -50,7 +50,7 @@ function run_test # Run multithreaded tests echo "****Building multithreaded test" pushd src - g++ multithreaded.cpp -lboost_thread-mt -ldl -omultithreaded -I../include -O3 + g++ multithreaded.cpp -ldl -omultithreaded -I../include -O3 echo "****Testing 1 thread runtime" /usr/bin/time -p ./multithreaded 1 2> ../../r$1-1threadruntime.out echo "****Testing 2 thread runtime" diff --git a/include/chaiscript/chaiscript.hpp b/include/chaiscript/chaiscript.hpp index 497c9c44..33cf6db0 100644 --- a/include/chaiscript/chaiscript.hpp +++ b/include/chaiscript/chaiscript.hpp @@ -74,16 +74,16 @@ ///
/// \subsection compiling Compiling ChaiScript Applications /// -/// ChaiScript is a header only library with only two dependecies. boost::threads (optional) and the +/// ChaiScript is a header only library with only one dependecy: The /// operating system provided dynamic library loader, which has to be specified on some platforms. /// /// \subsubsection compilinggcc Compiling with GCC /// /// To compile the above application on a Unix like operating system (MacOS, Linux) with GCC you need to link -/// both boost::threads and the dynamic loader. For example: +/// the dynamic loader. For example: /// /// \code -/// gcc main.cpp -I/path/to/chaiscript/headers -ldl -lboost_threads +/// gcc main.cpp -I/path/to/chaiscript/headers -ldl /// \endcode /// /// Alternatively, you may compile without threading support. @@ -245,7 +245,9 @@ /// /// std::string append_string_int(const std::string &t_lhs, int t_rhs) /// { -/// return t_lhs + boost::lexical_cast(t_rhs); +/// std::stringstream ss; +/// ss << t_lhs << t_rhs; +/// return ss.str(); /// } /// /// chai.add(fun(append_string_int), "+"); @@ -407,7 +409,7 @@ /// /// Thread safety can be disabled by defining CHAISCRIPT_NO_THREADS when using the library. /// -/// Disabling thread safety increases performance and removes the requirement for boost_threads. +/// Disabling thread safety increases performance in many cases. /// ///
/// @@ -743,6 +745,8 @@ /// \namespace chaiscript::detail /// \brief Classes and functions reserved for internal use. Items in this namespace are not supported. +#include "chaiscript_defines.hpp" + #include "dispatchkit/dispatchkit.hpp" #include "dispatchkit/bootstrap.hpp" #include "dispatchkit/bootstrap_stl.hpp" @@ -750,7 +754,7 @@ #include "dispatchkit/dynamic_object.hpp" #include "dispatchkit/boxed_number.hpp" -#ifdef BOOST_HAS_DECLSPEC +#ifdef CHAISCRIPT_HAS_DECLSPEC #define CHAISCRIPT_MODULE_EXPORT extern "C" __declspec(dllexport) #else #define CHAISCRIPT_MODULE_EXPORT extern "C" diff --git a/include/chaiscript/chaiscript_defines.hpp b/include/chaiscript/chaiscript_defines.hpp new file mode 100644 index 00000000..38cd72b5 --- /dev/null +++ b/include/chaiscript/chaiscript_defines.hpp @@ -0,0 +1,20 @@ +// This file is distributed under the BSD License. +// See "license.txt" for details. +// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// and Jason Turner (jason@emptycrate.com) +// http://www.chaiscript.com + +#ifndef CHAISCRIPT_DEFINES_HPP_ +#define CHAISCRIPT_DEFINES_HPP_ + +#ifdef _MSC_VER +#define CHAISCRIPT_MSVC _MSC_VER +#define CHAISCRIPT_HAS_DECLSPEc +#endif + +#ifdef _WIN32 +#define CHAISCRIPT_WINDOWS +#endif + +#endif + diff --git a/include/chaiscript/chaiscript_threading.hpp b/include/chaiscript/chaiscript_threading.hpp index bc7ae3cd..bce2c3e9 100644 --- a/include/chaiscript/chaiscript_threading.hpp +++ b/include/chaiscript/chaiscript_threading.hpp @@ -26,7 +26,7 @@ namespace chaiscript { namespace detail { - /// If threading is enabled, then this namespace contains boost::thread classes. + /// If threading is enabled, then this namespace contains std thread classes. /// If threading is not enabled, then stubbed in wrappers that do nothing are provided. /// This allows us to avoid \#ifdef code in the sections that need thread safety. namespace threading @@ -64,8 +64,10 @@ namespace chaiscript - /// Typesafe thread specific storage. If threading is enabled, this class uses boost::thread_specific_ptr. If + /// Typesafe thread specific storage. If threading is enabled, this class uses a mutex protected map. If /// threading is not enabled, the class always returns the same data, regardless of which thread it is called from. + /// + /// \todo move to thread_local when it exists template class Thread_Storage { diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index c8b8e767..b75e06f1 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -7,6 +7,8 @@ #ifndef CHAISCRIPT_BOXED_CAST_HPP_ #define CHAISCRIPT_BOXED_CAST_HPP_ +#include "../chaiscript_defines.hpp" + #include "type_info.hpp" #include "boxed_value.hpp" #include "boxed_cast_helper.hpp" @@ -66,7 +68,7 @@ namespace chaiscript return detail::Cast_Helper::cast(bv); } catch (const chaiscript::detail::exception::bad_any_cast &) { -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC //Thank you MSVC, yes we know that a constant value is being used in the if // statment in THIS VERSION of the template instantiation #pragma warning(push) @@ -88,7 +90,7 @@ namespace chaiscript throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type)); } -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC #pragma warning(pop) #endif diff --git a/include/chaiscript/dispatchkit/operators.hpp b/include/chaiscript/dispatchkit/operators.hpp index 343da1e0..26869767 100644 --- a/include/chaiscript/dispatchkit/operators.hpp +++ b/include/chaiscript/dispatchkit/operators.hpp @@ -7,6 +7,8 @@ #ifndef CHAISCRIPT_OPERATORS_HPP_ #define CHAISCRIPT_OPERATORS_HPP_ +#include "../chaiscript_defines.hpp" + namespace chaiscript { namespace bootstrap @@ -154,7 +156,7 @@ namespace chaiscript template Ret unary_minus(L l) { -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC #pragma warning(push) #pragma warning(disable : 4146) return (-l); diff --git a/include/chaiscript/language/chaiscript_algebraic.hpp b/include/chaiscript/language/chaiscript_algebraic.hpp index fe76359a..3d363ce9 100644 --- a/include/chaiscript/language/chaiscript_algebraic.hpp +++ b/include/chaiscript/language/chaiscript_algebraic.hpp @@ -7,7 +7,7 @@ #ifndef CHAISCRIPT_ALGEBRAIC_HPP_ #define CHAISCRIPT_ALGEBRAIC_HPP_ -#include +#include "../dispatchkit/dispatchkit.hpp" namespace chaiscript { diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index bc00f5cc..5fbb2099 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -7,7 +7,7 @@ #ifndef CHAISCRIPT_COMMON_HPP_ #define CHAISCRIPT_COMMON_HPP_ -#include +#include "../dispatchkit/dispatchkit.hpp" namespace chaiscript { diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index e0816b78..c7ec0bf7 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -10,12 +10,13 @@ #include #include -#include +#include "../chaiscript_defines.hpp" +#include "chaiscript_common.hpp" #ifdef _POSIX_VERSION #include #else -#ifdef BOOST_WINDOWS +#ifdef CHAISCRIPT_WINDOWS #define VC_EXTRA_LEAN #define WIN32_LEAN_AND_MEAN #include @@ -23,8 +24,8 @@ #endif -#include -#include +#include "chaiscript_prelude.hpp" +#include "chaiscript_parser.hpp" #include "../dispatchkit/exception_specification.hpp" namespace chaiscript diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index b3b4b0c0..2e15afdf 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -9,7 +9,7 @@ #include -#include +#include "chaiscript_common.hpp" namespace chaiscript { diff --git a/readme.txt b/readme.txt index bddc7035..6c73989b 100644 --- a/readme.txt +++ b/readme.txt @@ -13,7 +13,7 @@ ChaiScript is one of the only embedded scripting language designed from the grou [Requirements] -ChaiScript requires a recent version of Boost (http://www.boost.org) to build. +ChaiScript requires a C++11 compiler to build with support for variadic templates. [Usage] diff --git a/src/main.cpp b/src/main.cpp index 50cb43a4..240418cd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,7 +20,7 @@ char* readline(const char* p) std::string retval; std::cout << p ; std::getline(std::cin, retval); -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC return std::cin.eof() ? NULL : _strdup(retval.c_str()); #else return std::cin.eof() ? NULL : strdup(retval.c_str()); @@ -152,7 +152,7 @@ int main(int argc, char *argv[]) std::vector modulepaths; // Disable deprecation warning for getenv call. -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC #pragma warning(push) #pragma warning(disable : 4996) #endif @@ -160,7 +160,7 @@ int main(int argc, char *argv[]) const char *usepath = getenv("CHAI_USE_PATH"); const char *modulepath = getenv("CHAI_MODULE_PATH"); -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC #pragma warning(pop) #endif diff --git a/src/multithreaded.cpp b/src/multithreaded.cpp index 27e3e66f..95c827af 100644 --- a/src/multithreaded.cpp +++ b/src/multithreaded.cpp @@ -14,8 +14,9 @@ void do_work(chaiscript::ChaiScript &c) { // c("use(\"work.chai\"); do_chai_work(num_iterations);"); - std::string name = "MyVar" + boost::lexical_cast(rand()); - c.add(chaiscript::var(5), name); + std::stringstream ss; + ss << "MyVar" << rand(); + c.add(chaiscript::var(5), ss.str()); c("use(\"work.chai\"); do_chai_work(10000);"); } diff --git a/src/reflection.cpp b/src/reflection.cpp index fe8bc3a0..2bff5284 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -6,7 +6,7 @@ // MSVC doesn't like that we are using C++ return types from our C declared module // but this is the best way to do it for cross platform compatibility -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC #pragma warning(push) #pragma warning(disable : 4190) #endif @@ -96,6 +96,6 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect } -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC #pragma warning(pop) #endif diff --git a/src/stl_extra.cpp b/src/stl_extra.cpp index 59a542a8..67e6c27a 100644 --- a/src/stl_extra.cpp +++ b/src/stl_extra.cpp @@ -5,7 +5,7 @@ // MSVC doesn't like that we are using C++ return types from our C declared module // but this is the best way to do it for cross platform compatibility -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC #pragma warning(push) #pragma warning(disable : 4190) #endif @@ -16,6 +16,6 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_stl_extr } -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC #pragma warning(pop) #endif diff --git a/src/test_module.cpp b/src/test_module.cpp index 633b9de0..b5b5084c 100644 --- a/src/test_module.cpp +++ b/src/test_module.cpp @@ -42,7 +42,7 @@ int *get_new_int() // MSVC doesn't like that we are using C++ return types from our C declared module // but this is the best way to do it for cross platform compatibility -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC #pragma warning(push) #pragma warning(disable : 4190) #endif @@ -82,6 +82,6 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo } -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC #pragma warning(pop) #endif From d04960bc4a9357665d0d566426383db5588c1834 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 21 Sep 2011 10:01:21 -0600 Subject: [PATCH 025/108] Update for C++11 features --- include/chaiscript/chaiscript_threading.hpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/chaiscript/chaiscript_threading.hpp b/include/chaiscript/chaiscript_threading.hpp index bce2c3e9..bd34ef36 100644 --- a/include/chaiscript/chaiscript_threading.hpp +++ b/include/chaiscript/chaiscript_threading.hpp @@ -72,10 +72,6 @@ namespace chaiscript class Thread_Storage { public: - ~Thread_Storage() - { - } - inline T *operator->() const { return get_tls().get(); @@ -92,7 +88,7 @@ namespace chaiscript { unique_lock lock(m_mutex); - typename std::map >::iterator itr = m_instances.find(std::this_thread::get_id()); + auto itr = m_instances.find(std::this_thread::get_id()); if (itr != m_instances.end()) { return itr->second; } From 535adce298c551bf16e0499c820fe3c5b6847624 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 21 Sep 2011 12:22:52 -0600 Subject: [PATCH 026/108] Remove exception specifications in favor of noexcept keyword --- include/chaiscript/dispatchkit/any.hpp | 8 ++++---- include/chaiscript/dispatchkit/bad_boxed_cast.hpp | 10 +++++----- include/chaiscript/dispatchkit/dispatchkit.hpp | 8 ++++---- .../chaiscript/dispatchkit/dynamic_cast_conversion.hpp | 8 ++++---- include/chaiscript/dispatchkit/proxy_functions.hpp | 10 +++++----- .../chaiscript/dispatchkit/proxy_functions_detail.hpp | 2 +- include/chaiscript/language/chaiscript_common.hpp | 10 +++++----- include/chaiscript/language/chaiscript_engine.hpp | 4 ++-- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/chaiscript/dispatchkit/any.hpp b/include/chaiscript/dispatchkit/any.hpp index a6cce3d3..90b6336f 100644 --- a/include/chaiscript/dispatchkit/any.hpp +++ b/include/chaiscript/dispatchkit/any.hpp @@ -19,15 +19,15 @@ namespace chaiscript { class bad_any_cast : public std::bad_cast { public: - bad_any_cast() throw() + bad_any_cast() noexcept : m_what("bad any cast") { } - virtual ~bad_any_cast() throw() {} + virtual ~bad_any_cast() noexcept {} /// \brief Description of what error occured - virtual const char * what() const throw() + virtual const char * what() const noexcept { return m_what.c_str(); } @@ -79,7 +79,7 @@ namespace chaiscript { public: // construct/copy/destruct - Any() {} + Any() = default; Any(const Any &t_any) { diff --git a/include/chaiscript/dispatchkit/bad_boxed_cast.hpp b/include/chaiscript/dispatchkit/bad_boxed_cast.hpp index ef26d0b3..53200c01 100644 --- a/include/chaiscript/dispatchkit/bad_boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/bad_boxed_cast.hpp @@ -22,25 +22,25 @@ namespace chaiscript { public: bad_boxed_cast(const Type_Info &t_from, const std::type_info &t_to, - const std::string &t_what) throw() + const std::string &t_what) noexcept : from(t_from), to(&t_to), m_what(t_what) { } - bad_boxed_cast(const Type_Info &t_from, const std::type_info &t_to) throw() + bad_boxed_cast(const Type_Info &t_from, const std::type_info &t_to) noexcept : from(t_from), to(&t_to), m_what("Cannot perform boxed_cast") { } - bad_boxed_cast(const std::string &t_what) throw() + bad_boxed_cast(const std::string &t_what) noexcept : m_what(t_what) { } - virtual ~bad_boxed_cast() throw() {} + virtual ~bad_boxed_cast() noexcept {} /// \brief Description of what error occured - virtual const char * what() const throw() + virtual const char * what() const noexcept { return m_what.c_str(); } diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index 1d51639a..257379e8 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -41,12 +41,12 @@ namespace chaiscript class reserved_word_error : public std::runtime_error { public: - reserved_word_error(const std::string &t_word) throw() + reserved_word_error(const std::string &t_word) noexcept : std::runtime_error("Reserved word not allowed in object name: " + t_word), m_word(t_word) { } - virtual ~reserved_word_error() throw() {} + virtual ~reserved_word_error() noexcept {} std::string word() const { @@ -64,12 +64,12 @@ namespace chaiscript class global_non_const : public std::runtime_error { public: - global_non_const() throw() + global_non_const() noexcept : std::runtime_error("a global object must be const") { } - virtual ~global_non_const() throw() {} + virtual ~global_non_const() noexcept {} }; } diff --git a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp index f6fb7bf1..9fce9cf7 100644 --- a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp +++ b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp @@ -20,22 +20,22 @@ namespace chaiscript { public: bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to, - const std::string &t_what) throw() + const std::string &t_what) noexcept : bad_boxed_cast(t_from, t_to, t_what) { } - bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to) throw() + bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to) noexcept : bad_boxed_cast(t_from, t_to) { } - bad_boxed_dynamic_cast(const std::string &w) throw() + bad_boxed_dynamic_cast(const std::string &w) noexcept : bad_boxed_cast(w) { } - virtual ~bad_boxed_dynamic_cast() throw() {} + virtual ~bad_boxed_dynamic_cast() noexcept {} }; } diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 5225121d..aa5ba0ef 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -188,11 +188,11 @@ namespace chaiscript class guard_error : public std::runtime_error { public: - guard_error() throw() + guard_error() noexcept : std::runtime_error("Guard evaluation failed") { } - virtual ~guard_error() throw() + virtual ~guard_error() noexcept { } }; } @@ -587,17 +587,17 @@ namespace chaiscript class dispatch_error : public std::runtime_error { public: - dispatch_error() throw() + dispatch_error() noexcept : std::runtime_error("No matching function to dispatch to") { } - dispatch_error(bool is_const) throw() + dispatch_error(bool is_const) noexcept : std::runtime_error(std::string("No matching function to dispatch to") + (is_const?", parameter is const":"")) { } - virtual ~dispatch_error() throw() {} + virtual ~dispatch_error() noexcept {} }; } diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index 6900f146..f8901e39 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -32,7 +32,7 @@ namespace chaiscript { } - virtual ~arity_error() throw() {} + virtual ~arity_error() noexcept {} int got; int expected; diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 5fbb2099..84b1f800 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -70,17 +70,17 @@ namespace chaiscript std::string filename; std::vector call_stack; - eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) throw() : + eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) noexcept : std::runtime_error(format(t_why, t_where, t_fname)), reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname) { } - eval_error(const std::string &t_why) throw() + eval_error(const std::string &t_why) noexcept : std::runtime_error("Error: \"" + t_why + "\" "), reason(t_why) {} - virtual ~eval_error() throw() {} + virtual ~eval_error() noexcept {} private: static std::string format(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) @@ -98,11 +98,11 @@ namespace chaiscript * Errors generated when loading a file */ struct file_not_found_error : public std::runtime_error { - file_not_found_error(const std::string &t_filename) throw() + file_not_found_error(const std::string &t_filename) noexcept : std::runtime_error("File Not Found: " + t_filename) { } - virtual ~file_not_found_error() throw() {} + virtual ~file_not_found_error() noexcept {} }; } diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index c7ec0bf7..ecc82b6a 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -35,12 +35,12 @@ namespace chaiscript /// \brief Thrown if an error occurs while attempting to load a binary module struct load_module_error : std::runtime_error { - load_module_error(const std::string &t_reason) throw() + load_module_error(const std::string &t_reason) noexcept : std::runtime_error(t_reason) { } - virtual ~load_module_error() throw() + virtual ~load_module_error() noexcept { } }; From ac4bb95dfb0458f91d71723955f242dfedc7fb2a Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 24 Sep 2011 11:50:17 -0600 Subject: [PATCH 027/108] Rename var->auto. --- include/chaiscript/dispatchkit/bootstrap.hpp | 2 +- .../chaiscript/dispatchkit/bootstrap_stl.hpp | 4 +- .../chaiscript/language/chaiscript_engine.hpp | 2 +- .../chaiscript/language/chaiscript_parser.hpp | 2 +- .../language/chaiscript_prelude.hpp | 66 +++++++++---------- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index ca430849..3269809b 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -404,7 +404,7 @@ namespace chaiscript m->add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs"); m->add(fun(&dispatch::Dynamic_Object::get_attr), "get_attr"); - m->eval("def Dynamic_Object::clone() { var new_o := Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind(fun(new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }"); + m->eval("def Dynamic_Object::clone() { auto new_o := Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind(fun(new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }"); m->add(fun(&has_guard), "has_guard"); m->add(fun(&get_guard), "get_guard"); diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index a98534a8..f2f7e515 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -464,8 +464,8 @@ namespace chaiscript if ( rhs.size() != this.size() ) { \ return false; \ } else { \ - var r1 = range(this); \ - var r2 = range(rhs); \ + auto r1 = range(this); \ + auto r2 = range(rhs); \ while (!r1.empty()) \ { \ if (!eq(r1.front(), r2.front())) \ diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index c7ec0bf7..6ea22fb6 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -336,7 +336,7 @@ namespace chaiscript m_engine.add_reserved_word("||"); m_engine.add_reserved_word(","); m_engine.add_reserved_word(":="); - m_engine.add_reserved_word("var"); + m_engine.add_reserved_word("auto"); m_engine.add_reserved_word("return"); m_engine.add_reserved_word("break"); m_engine.add_reserved_word("true"); diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 67a5ddce..e0f35d72 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -1542,7 +1542,7 @@ namespace chaiscript size_t prev_stack_top = m_match_stack.size(); - if (Keyword("var")) { + if (Keyword("auto")) { retval = true; if (!Id(true)) { diff --git a/include/chaiscript/language/chaiscript_prelude.hpp b/include/chaiscript/language/chaiscript_prelude.hpp index 04a4178f..86cb6d2f 100644 --- a/include/chaiscript/language/chaiscript_prelude.hpp +++ b/include/chaiscript/language/chaiscript_prelude.hpp @@ -54,8 +54,8 @@ def push_front(container, x) : call_exists(push_front_ref, container, x) { conta def insert_at(container, pos, x) { container.insert_ref_at(pos, clone(x)); } \n\ # Returns the reverse of the given container\n\ def reverse(container) {\n\ - var retval = new(container); \n\ - var r = range(container); \n\ + auto retval = new(container); \n\ + auto r = range(container); \n\ while (!r.empty()) { \n\ retval.push_back(r.back()); \n\ r.pop_back(); \n\ @@ -82,7 +82,7 @@ def retro::pop_front() { pop_back(this.m_range) } \n\ def retro::empty() { empty(this.m_range); } \n\ # Performs the second value function over the container first value\n\ def for_each(container, func) : call_exists(range, container) { \n\ - var t_range = range(container); \n\ + auto t_range = range(container); \n\ while (!t_range.empty()) { \n\ func(t_range.front()); \n\ t_range.pop_front(); \n\ @@ -93,7 +93,7 @@ def back_inserter(container) { \n\ }\n\ \n\ def contains(container, item, compare_func) : call_exists(range, container) { \n\ - var t_range = range(container); \n\ + auto t_range = range(container); \n\ while (!t_range.empty()) { \n\ if ( compare_func(t_range.front(), item) ) { return true; } \n\ t_range.pop_front(); \n\ @@ -102,7 +102,7 @@ def contains(container, item, compare_func) : call_exists(range, container) { \n } \n\ def contains(container, item) { return contains(container, item, eq) } \n\ def map(container, func, inserter) : call_exists(range, container) { \n\ - var range = range(container); \n\ + auto range = range(container); \n\ while (!range.empty()) { \n\ inserter(func(range.front())); \n\ range.pop_front(); \n\ @@ -110,14 +110,14 @@ def map(container, func, inserter) : call_exists(range, container) { \n\ } \n\ # Performs the second value function over the container first value. Creates a new container with the results\n\ def map(container, func) { \n\ - var retval = new(container); \n\ + auto retval = new(container); \n\ map(container, func, back_inserter(retval));\n\ retval;\n\ }\n\ # Performs the second value function over the container first value. Starts with initial and continues with each element.\n\ def foldl(container, func, initial) : call_exists(range, container){ \n\ - var retval = initial; \n\ - var range = range(container); \n\ + auto retval = initial; \n\ + auto range = range(container); \n\ while (!range.empty()) { \n\ retval = (func(range.front(), retval)); \n\ range.pop_front(); \n\ @@ -130,9 +130,9 @@ def sum(container) { foldl(container, `+`, 0.0) } \n\ def product(container) { foldl(container, `*`, 1.0) } \n\ # Returns a new container with the elements of the first value concatenated with the elements of the second value\n\ def concat(x, y) : call_exists(clone, x) { \n\ - var retval = x; \n\ - var inserter = back_inserter(retval); \n\ - var range = range(y); \n\ + auto retval = x; \n\ + auto inserter = back_inserter(retval); \n\ + auto range = range(y); \n\ while (!range.empty()) { \n\ inserter(range.front()); \n\ range.pop_front(); \n\ @@ -140,8 +140,8 @@ def concat(x, y) : call_exists(clone, x) { \n\ retval; \n\ } \n\ def take(container, num, inserter) : call_exists(range, container) { \n\ - var r = range(container); \n\ - var i = num; \n\ + auto r = range(container); \n\ + auto i = num; \n\ while ((i > 0) && (!r.empty())) { \n\ inserter(r.front()); \n\ r.pop_front(); \n\ @@ -150,12 +150,12 @@ def take(container, num, inserter) : call_exists(range, container) { \n\ } \n\ # Returns a new container with the given number of elements taken from the container\n\ def take(container, num) {\n\ - var retval = new(container); \n\ + auto retval = new(container); \n\ take(container, num, back_inserter(retval)); \n\ retval; \n\ }\n\ def take_while(container, f, inserter) : call_exists(range, container) { \n\ - var r = range(container); \n\ + auto r = range(container); \n\ while ((!r.empty()) && f(r.front())) { \n\ inserter(r.front()); \n\ r.pop_front(); \n\ @@ -163,13 +163,13 @@ def take_while(container, f, inserter) : call_exists(range, container) { \n\ } \n\ # Returns a new container with the given elements match the second value function\n\ def take_while(container, f) {\n\ - var retval = new(container); \n\ + auto retval = new(container); \n\ take_while(container, f, back_inserter(retval)); \n\ retval;\n\ }\n\ def drop(container, num, inserter) : call_exists(range, container) { \n\ - var r = range(container); \n\ - var i = num; \n\ + auto r = range(container); \n\ + auto i = num; \n\ while ((i > 0) && (!r.empty())) { \n\ r.pop_front(); \n\ --i; \n\ @@ -181,12 +181,12 @@ def drop(container, num, inserter) : call_exists(range, container) { \n\ } \n\ # Returns a new container with the given number of elements dropped from the given container \n\ def drop(container, num) {\n\ - var retval = new(container); \n\ + auto retval = new(container); \n\ drop(container, num, back_inserter(retval)); \n\ retval; \n\ }\n\ def drop_while(container, f, inserter) : call_exists(range, container) { \n\ - var r = range(container); \n\ + auto r = range(container); \n\ while ((!r.empty())&& f(r.front())) { \n\ r.pop_front(); \n\ } \n\ @@ -197,14 +197,14 @@ def drop_while(container, f, inserter) : call_exists(range, container) { \n\ } \n\ # Returns a new container with the given elements dropped that match the second value function\n\ def drop_while(container, f) {\n\ - var retval = new(container); \n\ + auto retval = new(container); \n\ drop_while(container, f, back_inserter(retval)); \n\ retval; \n\ }\n\ # Applies the second value function to the container. Starts with the first two elements. Expects at least 2 elements.\n\ def reduce(container, func) : container.size() >= 2 && call_exists(range, container) { \n\ - var r = range(container); \n\ - var retval = r.front(); \n\ + auto r = range(container); \n\ + auto retval = r.front(); \n\ r.pop_front(); \n\ retval = func(retval, r.front()); \n\ r.pop_front(); \n\ @@ -216,8 +216,8 @@ def reduce(container, func) : container.size() >= 2 && call_exists(range, contai } \n\ # Returns a string of the elements in container delimited by the second value string\n\ def join(container, delim) { \n\ - var retval = ""; \n\ - var range = range(container); \n\ + auto retval = ""; \n\ + auto range = range(container); \n\ if (!range.empty()) { \n\ retval += to_string(range.front()); \n\ range.pop_front(); \n\ @@ -230,7 +230,7 @@ def join(container, delim) { \n\ retval; \n\ } \n\ def filter(container, f, inserter) : call_exists(range, container) { \n\ - var r = range(container); \n\ + auto r = range(container); \n\ while (!r.empty()) { \n\ if (f(r.front())) { \n\ inserter(r.front()); \n\ @@ -240,12 +240,12 @@ def filter(container, f, inserter) : call_exists(range, container) { \n\ } \n\ # Returns a new Vector which match the second value function\n\ def filter(container, f) { \n\ - var retval = new(container); \n\ + auto retval = new(container); \n\ filter(container, f, back_inserter(retval));\n\ retval;\n\ }\n\ def generate_range(x, y, inserter) { \n\ - var i = x; \n\ + auto i = x; \n\ while (i <= y) { \n\ inserter(i); \n\ ++i; \n\ @@ -253,7 +253,7 @@ def generate_range(x, y, inserter) { \n\ } \n\ # Returns a new Vector which represents the range from the first value to the second value\n\ def generate_range(x, y) { \n\ - var retval = Vector(); \n\ + auto retval = Vector(); \n\ generate_range(x,y,back_inserter(retval)); \n\ retval; \n\ }\n\ @@ -262,8 +262,8 @@ def collate(x, y) { \n\ [x, y]; \n\ } \n\ def zip_with(f, x, y, inserter) : call_exists(range, x) && call_exists(range, y) { \n\ - var r_x = range(x); \n\ - var r_y = range(y); \n\ + auto r_x = range(x); \n\ + auto r_y = range(y); \n\ while (!r_x.empty() && !r_y.empty()) { \n\ inserter(f(r_x.front(), r_y.front())); \n\ r_x.pop_front(); \n\ @@ -272,7 +272,7 @@ def zip_with(f, x, y, inserter) : call_exists(range, x) && call_exists(range, y) } \n\ # Returns a new Vector which joins matching elements of the second and third value with the first value function\n\ def zip_with(f, x, y) { \n\ - var retval = Vector(); \n\ + auto retval = Vector(); \n\ zip_with(f,x,y,back_inserter(retval)); \n\ retval;\n\ }\n\ @@ -314,7 +314,7 @@ def string::trim() { \n\ ltrim(rtrim(this)); \n\ } \n\ def find(container, value, compare_func) : call_exists(range, container) && is_type(compare_func, "Function") { \n\ - var range = range(container); \n\ + auto range = range(container); \n\ while (!range.empty()) { \n\ if (compare_func(range.front(), value)) { \n\ return range; \n\ From 2ca7a7d7da9867ea5d1e935daf7b3e23c33d6128 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 24 Sep 2011 11:54:40 -0600 Subject: [PATCH 028/108] Some C++11 cleaner usage updates --- include/chaiscript/dispatchkit/bootstrap.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index ca430849..2928bf6c 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -289,7 +289,7 @@ namespace chaiscript static bool has_guard(const Const_Proxy_Function &t_pf) { - std::shared_ptr pf = std::dynamic_pointer_cast(t_pf); + auto pf = std::dynamic_pointer_cast(t_pf); if (pf) { return bool(pf->get_guard()); @@ -300,7 +300,7 @@ namespace chaiscript static Const_Proxy_Function get_guard(const Const_Proxy_Function &t_pf) { - std::shared_ptr pf = std::dynamic_pointer_cast(t_pf); + auto pf = std::dynamic_pointer_cast(t_pf); if (pf) { if (pf->get_guard()) @@ -318,7 +318,9 @@ namespace chaiscript throw bv; } - static std::shared_ptr bootstrap2(std::shared_ptr e = std::shared_ptr (new chaiscript::detail::Dispatch_Engine())) + static std::shared_ptr bootstrap2( + std::shared_ptr e + = std::shared_ptr (new chaiscript::detail::Dispatch_Engine())) { e->add(user_type(), "void"); return e; From 92de42e42b0beb234c27cea8d2e020bd542894a7 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 24 Sep 2011 12:05:08 -0600 Subject: [PATCH 029/108] Modify "var" to "auto" for unit tests. --- unittests/bind.chai | 2 +- unittests/bind2.chai | 10 +++++----- unittests/break_while.chai | 2 +- unittests/classification.chai | 2 +- unittests/collate.chai | 2 +- unittests/concat.chai | 2 +- unittests/deep_array_lookup.chai | 4 ++-- unittests/dispatch_functions.chai | 2 +- unittests/dynamic_object_test.cpp | 2 +- unittests/equ_shortform.chai | 4 ++-- unittests/eval_error.chai | 4 ++-- unittests/exception.chai | 2 +- unittests/exception_finally.chai | 8 ++++---- unittests/exception_guards.chai | 4 ++-- unittests/for.chai | 4 ++-- unittests/for_each_range.chai | 4 ++-- unittests/for_each_retro.chai | 4 ++-- unittests/function_introspection.chai | 8 ++++---- unittests/function_ordering_test.cpp | 2 +- unittests/function_reassignment.chai | 2 +- unittests/if.chai | 2 +- unittests/if_else.chai | 6 +++--- unittests/if_elseif.chai | 8 ++++---- unittests/if_elseif_else.chai | 4 ++-- unittests/index_operator.chai | 2 +- unittests/inheritance.chai | 4 ++-- unittests/instring_eval.chai | 2 +- unittests/invalid_function_reassignment.chai | 2 +- unittests/is_undef.chai | 2 +- unittests/lambda.chai | 2 +- unittests/list_push_back.chai | 2 +- unittests/list_push_front.chai | 2 +- unittests/loop_inner_outer.chai | 6 +++--- unittests/map_access.chai | 2 +- unittests/map_inplace_init.chai | 2 +- unittests/math_dec.chai | 2 +- unittests/math_inc.chai | 2 +- unittests/memberscope.chai | 2 +- unittests/multiline.chai | 4 ++-- unittests/object_attr.chai | 2 +- unittests/object_clone.chai | 4 ++-- unittests/object_constructor_guards.chai | 4 ++-- unittests/object_lifetime_test.cpp | 10 +++++----- unittests/object_method_guards.chai | 2 +- unittests/operator_overload.chai | 4 ++-- unittests/operator_overload2.chai | 4 ++-- unittests/operators_float.chai | 6 +++--- unittests/operators_int.chai | 6 +++--- unittests/pair.chai | 2 +- unittests/pointer_passed_to_constructor.chai | 6 +++--- unittests/precedence_eq.chai | 2 +- unittests/range.chai | 4 ++-- unittests/range_back.chai | 4 ++-- unittests/range_contains.chai | 2 +- unittests/range_find.chai | 6 +++--- unittests/ref_equal.chai | 4 ++-- unittests/reflection_test.chai | 14 +++++++------- unittests/retro.chai | 4 ++-- unittests/retroretro.chai | 6 +++--- unittests/runtime_error.chai | 2 +- unittests/utility_test.cpp | 6 +++--- unittests/vector_access.chai | 2 +- unittests/vector_erase_at.chai | 2 +- unittests/vector_inplace_init.chai | 2 +- unittests/vector_insert_at.chai | 2 +- unittests/vector_of_one.chai | 2 +- unittests/vector_push_back.chai | 2 +- unittests/vector_push_empty.chai | 2 +- unittests/zip.chai | 2 +- unittests/zip_with.chai | 2 +- 70 files changed, 127 insertions(+), 127 deletions(-) diff --git a/unittests/bind.chai b/unittests/bind.chai index 3c72673f..a3af3004 100644 --- a/unittests/bind.chai +++ b/unittests/bind.chai @@ -1,2 +1,2 @@ -var prod = bind(foldl, _, `*`, 1.0) +auto prod = bind(foldl, _, `*`, 1.0) assert_equal(60, prod([3, 4, 5])) diff --git a/unittests/bind2.chai b/unittests/bind2.chai index 0b8ddde3..1adf6b8e 100644 --- a/unittests/bind2.chai +++ b/unittests/bind2.chai @@ -6,11 +6,11 @@ def add(x, y) assert_equal(2, add.get_arity()); -var b = bind(add, 2, _); +auto b = bind(add, 2, _); assert_equal(1, b.get_arity()); -var c = bind(b, 3); +auto c = bind(b, 3); assert_equal(0, c.get_arity()); @@ -22,13 +22,13 @@ def concat2(a,b,c,d) return to_string(a) + to_string(b) + to_string(c) + to_string(d); } -var d = bind(concat2, _, " Hello ", _, " World"); +auto d = bind(concat2, _, " Hello ", _, " World"); assert_equal(2, d.get_arity()); assert_equal("1 Hello 3 World", d(1,3)); -var e = bind(`<`, _, 5); -var types = e.get_param_types(); +auto e = bind(`<`, _, 5); +auto types = e.get_param_types(); assert_equal(2, types.size()); assert_equal(true, types[0].bare_equal(bool_type)); diff --git a/unittests/break_while.chai b/unittests/break_while.chai index d54a3dd9..bfede2ce 100644 --- a/unittests/break_while.chai +++ b/unittests/break_while.chai @@ -1,4 +1,4 @@ -var i = 0 +auto i = 0 while (i < 10) { if (++i == 5) { break diff --git a/unittests/classification.chai b/unittests/classification.chai index 8c2cca94..cc56fbee 100644 --- a/unittests/classification.chai +++ b/unittests/classification.chai @@ -3,5 +3,5 @@ assert_equal(false, 1.is_var_reference()); assert_equal(true, 1.is_var_pointer()); assert_equal(false, 1.is_var_null()); assert_equal(false, 1.is_var_undef()); -var i; +auto i; assert_equal(true, i.is_var_undef()); diff --git a/unittests/collate.chai b/unittests/collate.chai index 12632e59..3a32973c 100644 --- a/unittests/collate.chai +++ b/unittests/collate.chai @@ -1,3 +1,3 @@ -var v = collate(1, 2) +auto v = collate(1, 2) assert_equal(1, v[0]) assert_equal(2, v[1]) diff --git a/unittests/concat.chai b/unittests/concat.chai index 3d285a5b..53950a6e 100644 --- a/unittests/concat.chai +++ b/unittests/concat.chai @@ -1,4 +1,4 @@ -var v = concat([1, 2], [3, 4]); +auto v = concat([1, 2], [3, 4]); assert_equal(4, v.size()); assert_equal(1, v[0]); diff --git a/unittests/deep_array_lookup.chai b/unittests/deep_array_lookup.chai index c405302d..8a86eaa3 100644 --- a/unittests/deep_array_lookup.chai +++ b/unittests/deep_array_lookup.chai @@ -1,4 +1,4 @@ -var a = [1,2,3, [4,5,6] ] +auto a = [1,2,3, [4,5,6] ] assert_equal(a[3][0], 4) @@ -6,6 +6,6 @@ assert_equal(a[3][0], 4) def Test::Test() { this.a = [1,2,3]; } attr Test::a; -var t = Test(); +auto t = Test(); assert_equal(t.a[0], 1) diff --git a/unittests/dispatch_functions.chai b/unittests/dispatch_functions.chai index 528d5b30..1887844e 100644 --- a/unittests/dispatch_functions.chai +++ b/unittests/dispatch_functions.chai @@ -6,6 +6,6 @@ assert_equal(get_arity.get_contained_functions().size(), 0); assert_equal(get_arity.get_arity(), 1); assert_equal(get_arity.get_param_types().size(), 2); -var paramtypes = get_arity.get_param_types(); +auto paramtypes = get_arity.get_param_types(); assert_equal(true, paramtypes[1].bare_equal(Function_type)); diff --git a/unittests/dynamic_object_test.cpp b/unittests/dynamic_object_test.cpp index 8383e039..ca0ffaec 100644 --- a/unittests/dynamic_object_test.cpp +++ b/unittests/dynamic_object_test.cpp @@ -17,7 +17,7 @@ int main() chaiscript::ChaiScript chai; - chai("attr bob::z; def bob::bob() { this.z = 10 }; var x = bob()"); + chai("attr bob::z; def bob::bob() { this.z = 10 }; auto x = bob()"); chaiscript::dispatch::Dynamic_Object &mydo = chai.eval("x"); diff --git a/unittests/equ_shortform.chai b/unittests/equ_shortform.chai index 41c8e1de..b7ec906a 100644 --- a/unittests/equ_shortform.chai +++ b/unittests/equ_shortform.chai @@ -1,4 +1,4 @@ -var x=.5 +auto x=.5 assert_equal(.5, x) -var y=-.5 +auto y=-.5 assert_equal(-.5, y) diff --git a/unittests/eval_error.chai b/unittests/eval_error.chai index d63ad759..b2737a11 100644 --- a/unittests/eval_error.chai +++ b/unittests/eval_error.chai @@ -20,7 +20,7 @@ def func() def doing() { - for (var i = 0; i < 10; ++i) + for (auto i = 0; i < 10; ++i) { func(); } @@ -34,6 +34,6 @@ def while_doing() } } -var f = fun() { while_doing(); } +auto f = fun() { while_doing(); } assert_equal(get_eval_error(f).call_stack.size(), 16) diff --git a/unittests/exception.chai b/unittests/exception.chai index 50df6a80..94e82d83 100644 --- a/unittests/exception.chai +++ b/unittests/exception.chai @@ -1,4 +1,4 @@ -var x = 1 +auto x = 1 try { throw(x) x = 2 diff --git a/unittests/exception_finally.chai b/unittests/exception_finally.chai index d6fd834a..76003c60 100644 --- a/unittests/exception_finally.chai +++ b/unittests/exception_finally.chai @@ -1,4 +1,4 @@ -var finallyone = false; +auto finallyone = false; try { throw(3) @@ -12,9 +12,9 @@ finally { assert_equal(true, finallyone); -var try2 = false; -var catch2 = false; -var finally2 = false; +auto try2 = false; +auto catch2 = false; +auto finally2 = false; try { diff --git a/unittests/exception_guards.chai b/unittests/exception_guards.chai index 99cd9018..12792985 100644 --- a/unittests/exception_guards.chai +++ b/unittests/exception_guards.chai @@ -1,6 +1,6 @@ -var results = []; +auto results = []; -for (var i = 2; i < 6; ++i) { +for (auto i = 2; i < 6; ++i) { try { throw(i) } diff --git a/unittests/for.chai b/unittests/for.chai index 9799be24..c5769992 100644 --- a/unittests/for.chai +++ b/unittests/for.chai @@ -1,6 +1,6 @@ -var ret = [] +auto ret = [] -for (var i = 0; i < 5; ++i) { +for (auto i = 0; i < 5; ++i) { ret.push_back(i); } diff --git a/unittests/for_each_range.chai b/unittests/for_each_range.chai index 43191bfb..3a92641d 100644 --- a/unittests/for_each_range.chai +++ b/unittests/for_each_range.chai @@ -1,3 +1,3 @@ -var v = [1,2,3]; -var r = range(v); +auto v = [1,2,3]; +auto r = range(v); for_each(r, fun(x) { assert_equal(true, x>0); } ) diff --git a/unittests/for_each_retro.chai b/unittests/for_each_retro.chai index cc27a580..4cd0ff51 100644 --- a/unittests/for_each_retro.chai +++ b/unittests/for_each_retro.chai @@ -1,4 +1,4 @@ // Don't bother checking the output from this one, just makes sure it executes -var v = [1,2,3]; -var r = retro(range(v)); +auto v = [1,2,3]; +auto r = retro(range(v)); for_each(r, print) diff --git a/unittests/function_introspection.chai b/unittests/function_introspection.chai index 5ad76fc7..6d808dfe 100644 --- a/unittests/function_introspection.chai +++ b/unittests/function_introspection.chai @@ -31,7 +31,7 @@ assert_equal(test_fun.get_arity(), 1); assert_equal(test_fun.get_contained_functions.size(), 1); assert_equal(test_fun.get_param_types().size(), 2); assert_equal(test_fun, test_fun); -var test_fun_types = test_fun.get_param_types(); +auto test_fun_types = test_fun.get_param_types(); assert_equal(true, test_fun_types[0].bare_equal(Object_type)); assert_equal(true, test_fun_types[1].bare_equal(int_type)); @@ -42,7 +42,7 @@ assert_equal(2, `==`.get_arity()); // < should be the merging of two functions bool <(PODObject, PODObject) and bool <(string, string) // we want to peel it apart and make sure that's true -var types = `<`.get_param_types(); +auto types = `<`.get_param_types(); assert_equal(3, types.size()); assert_equal(true, types[0].bare_equal(bool_type)); assert_equal(true, types[1].bare_equal(Object_type)); @@ -62,7 +62,7 @@ assert_equal(true, with_guard.has_guard()); assert_equal(false, without_guard.has_guard()); assert_equal(2, group_guard.get_contained_functions().size()); -var group = group_guard.get_contained_functions(); +auto group = group_guard.get_contained_functions(); assert_equal(true, group[0].has_guard()) assert_equal(false, group[1].has_guard()) @@ -70,7 +70,7 @@ assert_equal(false, group[1].has_guard()) assert_throws("Function does not have a guard", fun() { group[0].get_guard(); } ); assert_throws("Function does not have a guard", fun() { without_guard.get_guard(); } ); -var guard = with_guard.get_guard(); +auto guard = with_guard.get_guard(); assert_equal(false, guard.has_guard()); assert_throws("Function does not have a guard", fun() { guard.get_guard(); } ); diff --git a/unittests/function_ordering_test.cpp b/unittests/function_ordering_test.cpp index 0a9652c6..e80f4d32 100644 --- a/unittests/function_ordering_test.cpp +++ b/unittests/function_ordering_test.cpp @@ -22,7 +22,7 @@ int main() chai.add(chaiscript::fun(&test_two), "test_fun"); int res1 = chai.eval("test_fun(1)"); - int res2 = chai.eval("var i = 1; test_fun(i)"); + int res2 = chai.eval("auto i = 1; test_fun(i)"); int res3 = chai.eval("test_fun(\"bob\")"); int res4 = chai.eval("test_fun(\"hi\")"); diff --git a/unittests/function_reassignment.chai b/unittests/function_reassignment.chai index 2a885fdc..6ddbce3a 100644 --- a/unittests/function_reassignment.chai +++ b/unittests/function_reassignment.chai @@ -1,3 +1,3 @@ -var x = `+` +auto x = `+` x = `-` assert_equal(1, x(5,4)) diff --git a/unittests/if.chai b/unittests/if.chai index 3ec7321b..c4249291 100644 --- a/unittests/if.chai +++ b/unittests/if.chai @@ -1,4 +1,4 @@ -var t = false; +auto t = false; if (true) { t = true; diff --git a/unittests/if_else.chai b/unittests/if_else.chai index 8cb42db9..611ee911 100644 --- a/unittests/if_else.chai +++ b/unittests/if_else.chai @@ -1,6 +1,6 @@ -var i = 3 -var b1 = false; -var b2 = false; +auto i = 3 +auto b1 = false; +auto b2 = false; if (i == 2) { b1 = true; diff --git a/unittests/if_elseif.chai b/unittests/if_elseif.chai index 75b85b5f..7e4b5d58 100644 --- a/unittests/if_elseif.chai +++ b/unittests/if_elseif.chai @@ -1,8 +1,8 @@ -var b1 = false; -var b2 = false; -var b3 = false; +auto b1 = false; +auto b2 = false; +auto b3 = false; -var i = 3 +auto i = 3 if (i == 2) { b1 = true; } diff --git a/unittests/if_elseif_else.chai b/unittests/if_elseif_else.chai index 26ed0d26..0f96df7c 100644 --- a/unittests/if_elseif_else.chai +++ b/unittests/if_elseif_else.chai @@ -1,5 +1,5 @@ -var i = 3 -var b = false +auto i = 3 +auto b = false if (i == 2) { assert_equal(false, true) } diff --git a/unittests/index_operator.chai b/unittests/index_operator.chai index e8af5cf6..f8074042 100644 --- a/unittests/index_operator.chai +++ b/unittests/index_operator.chai @@ -3,7 +3,7 @@ def Bob::bob3() { return [1,2,3]; } def Bob::Bob() {} -var b = Bob(); +auto b = Bob(); assert_equal(b.bob3()[0], 1); diff --git a/unittests/inheritance.chai b/unittests/inheritance.chai index 1fcd346b..d5c49055 100644 --- a/unittests/inheritance.chai +++ b/unittests/inheritance.chai @@ -1,7 +1,7 @@ load_module("test_module") -var t0 = TestBaseType() -var t = TestDerivedType(); +auto t0 = TestBaseType() +auto t = TestDerivedType(); assert_equal(t0.func(), 0); assert_equal(t.func(), 1); diff --git a/unittests/instring_eval.chai b/unittests/instring_eval.chai index a72b2fc4..32eb2b91 100644 --- a/unittests/instring_eval.chai +++ b/unittests/instring_eval.chai @@ -1,3 +1,3 @@ -var bob = 5.5 +auto bob = 5.5 assert_equal("5.5", "${bob}") assert_equal("val: 8 and 8", "val: ${5.5 + 2.5} and ${bob + 2.5}") diff --git a/unittests/invalid_function_reassignment.chai b/unittests/invalid_function_reassignment.chai index cc7cb5af..784372ac 100644 --- a/unittests/invalid_function_reassignment.chai +++ b/unittests/invalid_function_reassignment.chai @@ -1 +1 @@ -assert_throws("Invalid function reassignment", fun() { var x = 5; x = `-`; } ); +assert_throws("Invalid function reassignment", fun() { auto x = 5; x = `-`; } ); diff --git a/unittests/is_undef.chai b/unittests/is_undef.chai index 38572f0f..894bd3fc 100644 --- a/unittests/is_undef.chai +++ b/unittests/is_undef.chai @@ -1,4 +1,4 @@ -var i; +auto i; assert_equal(true, i.is_var_undef()); i = 5; assert_equal(false, i.is_var_undef()); diff --git a/unittests/lambda.chai b/unittests/lambda.chai index 6b65a1ba..9b717ec5 100644 --- a/unittests/lambda.chai +++ b/unittests/lambda.chai @@ -1,2 +1,2 @@ -var bob = fun(x) { x + 1 } +auto bob = fun(x) { x + 1 } assert_equal(4, bob(3)); diff --git a/unittests/list_push_back.chai b/unittests/list_push_back.chai index 4d88deb8..19d17e13 100644 --- a/unittests/list_push_back.chai +++ b/unittests/list_push_back.chai @@ -1,6 +1,6 @@ load_module("stl_extra") -var x = List() +auto x = List() x.push_back(3) x.push_back("A") diff --git a/unittests/list_push_front.chai b/unittests/list_push_front.chai index 86e28329..fe318216 100644 --- a/unittests/list_push_front.chai +++ b/unittests/list_push_front.chai @@ -1,6 +1,6 @@ load_module("stl_extra") -var x = List() +auto x = List() x.push_front(3) x.push_front("A") diff --git a/unittests/loop_inner_outer.chai b/unittests/loop_inner_outer.chai index 64a25e6e..bda275ff 100644 --- a/unittests/loop_inner_outer.chai +++ b/unittests/loop_inner_outer.chai @@ -1,7 +1,7 @@ -var total = 0 +auto total = 0 -for (var i = 0; i < 10; ++i) { - for (var j = 0; j < 10; ++j) { +for (auto i = 0; i < 10; ++i) { + for (auto j = 0; j < 10; ++j) { total += 1 } } diff --git a/unittests/map_access.chai b/unittests/map_access.chai index 19ebc1ad..d544036d 100644 --- a/unittests/map_access.chai +++ b/unittests/map_access.chai @@ -1,2 +1,2 @@ -var x = ["bob":2, "fred":3] +auto x = ["bob":2, "fred":3] assert_equal(3, x["fred"]) diff --git a/unittests/map_inplace_init.chai b/unittests/map_inplace_init.chai index b1d8221b..1d88494f 100644 --- a/unittests/map_inplace_init.chai +++ b/unittests/map_inplace_init.chai @@ -1,3 +1,3 @@ -var x = ["bob":1, "fred":2] +auto x = ["bob":1, "fred":2] assert_equal(2, x.size()); diff --git a/unittests/math_dec.chai b/unittests/math_dec.chai index e746f298..58a24e2f 100644 --- a/unittests/math_dec.chai +++ b/unittests/math_dec.chai @@ -1,3 +1,3 @@ -var i = 3 +auto i = 3 assert_equal(2, --i) assert_equal(2, i) diff --git a/unittests/math_inc.chai b/unittests/math_inc.chai index ec317c03..a5953a5c 100644 --- a/unittests/math_inc.chai +++ b/unittests/math_inc.chai @@ -1,3 +1,3 @@ -var i = 3 +auto i = 3 assert_equal(4, ++i) assert_equal(4, i) diff --git a/unittests/memberscope.chai b/unittests/memberscope.chai index fe46810a..f1cf7c15 100644 --- a/unittests/memberscope.chai +++ b/unittests/memberscope.chai @@ -8,5 +8,5 @@ def Vector3::Vector3(x, y, z) { this.z = z } -var v = Vector3(1,2,3); +auto v = Vector3(1,2,3); assert_equal(1, v.x); diff --git a/unittests/multiline.chai b/unittests/multiline.chai index f13be4e6..dfa213c3 100644 --- a/unittests/multiline.chai +++ b/unittests/multiline.chai @@ -1,9 +1,9 @@ -var x = [1, 2, +auto x = [1, 2, 3, 4] assert_equal(1, x[0]) -var y = map(x, +auto y = map(x, fun(x) { x + 1 }) assert_equal(2, y[0]) diff --git a/unittests/object_attr.chai b/unittests/object_attr.chai index c2da08ea..7076345f 100644 --- a/unittests/object_attr.chai +++ b/unittests/object_attr.chai @@ -1,6 +1,6 @@ attr bob::z def bob::bob() { this.z = 10 } -var x = bob() +auto x = bob() def bob::fred(x) { this.z - x } assert_equal(7, x.fred(3)) diff --git a/unittests/object_clone.chai b/unittests/object_clone.chai index 4659f41a..d1673e83 100644 --- a/unittests/object_clone.chai +++ b/unittests/object_clone.chai @@ -1,10 +1,10 @@ attr bob::z def bob::bob() { } -var x = bob(); +auto x = bob(); x.z = 10; -var y = clone(x); +auto y = clone(x); y.z = 20; assert_equal(10, x.z) diff --git a/unittests/object_constructor_guards.chai b/unittests/object_constructor_guards.chai index f48c00a1..d574eaa5 100644 --- a/unittests/object_constructor_guards.chai +++ b/unittests/object_constructor_guards.chai @@ -3,8 +3,8 @@ attr bob::val def bob::bob(x) : x < 10 { this.val = "Less Than Ten: " + x.to_string(); } def bob::bob(x) { this.val = "Any Other Value: " + x.to_string(); } -var b = bob(12) -var c = bob(3) +auto b = bob(12) +auto c = bob(3) assert_equal("Any Other Value: 12", b.val ) assert_equal("Less Than Ten: 3", c.val ) diff --git a/unittests/object_lifetime_test.cpp b/unittests/object_lifetime_test.cpp index 8d700fdc..07f0c139 100644 --- a/unittests/object_lifetime_test.cpp +++ b/unittests/object_lifetime_test.cpp @@ -42,15 +42,15 @@ int main() int count = chai.eval("count()"); - int count2 = chai.eval("var i = 0; { var t = Test(); } return i;"); + int count2 = chai.eval("auto i = 0; { auto t = Test(); } return i;"); - int count3 = chai.eval("var i = 0; { var t = Test(); i = count(); } return i;"); + int count3 = chai.eval("auto i = 0; { auto t = Test(); i = count(); } return i;"); - int count4 = chai.eval("var i = 0; { var t = Test(); { var t2 = Test(); i = count(); } } return i;"); + int count4 = chai.eval("auto i = 0; { auto t = Test(); { auto t2 = Test(); i = count(); } } return i;"); - int count5 = chai.eval("var i = 0; { var t = Test(); { var t2 = Test(); } i = count(); } return i;"); + int count5 = chai.eval("auto i = 0; { auto t = Test(); { auto t2 = Test(); } i = count(); } return i;"); - int count6 = chai.eval("var i = 0; { var t = Test(); { var t2 = Test(); } } i = count(); return i;"); + int count6 = chai.eval("auto i = 0; { auto t = Test(); { auto t2 = Test(); } } i = count(); return i;"); if (count == 0 && count2 == 0 diff --git a/unittests/object_method_guards.chai b/unittests/object_method_guards.chai index addc8508..5199c04f 100644 --- a/unittests/object_method_guards.chai +++ b/unittests/object_method_guards.chai @@ -2,6 +2,6 @@ def bob::bob() { } def bob::fred(e) : e < 10 { assert_equal(true, e<10) } def bob::fred(e) { assert_equal(true, e >= 10) } -var b = bob() +auto b = bob() b.fred(3) b.fred(12) diff --git a/unittests/operator_overload.chai b/unittests/operator_overload.chai index 9bd2eb79..387209be 100644 --- a/unittests/operator_overload.chai +++ b/unittests/operator_overload.chai @@ -1,8 +1,8 @@ def Bob::`+`(y) { this.x + y.x } def Bob::Bob() { } attr Bob::x -var b = Bob() -var c = Bob() +auto b = Bob() +auto c = Bob() b.x = 4 c.x = 5 diff --git a/unittests/operator_overload2.chai b/unittests/operator_overload2.chai index b4afbe7b..a992dc7d 100644 --- a/unittests/operator_overload2.chai +++ b/unittests/operator_overload2.chai @@ -1,8 +1,8 @@ def Bob::Bob() { } attr Bob::x def `-`(a, b) : is_type(a, "Bob") && is_type(b, "Bob") { a.x - b.x } -var b = Bob() -var c = Bob() +auto b = Bob() +auto c = Bob() b.x = 4 c.x = 5 diff --git a/unittests/operators_float.chai b/unittests/operators_float.chai index 9a61d905..3f693786 100644 --- a/unittests/operators_float.chai +++ b/unittests/operators_float.chai @@ -1,6 +1,6 @@ -var i = 1.0; -var j = 2.0; -var k = 3.0; +auto i = 1.0; +auto j = 2.0; +auto k = 3.0; assert_equal(3, i + j) assert_equal(1.0, +i) diff --git a/unittests/operators_int.chai b/unittests/operators_int.chai index 4627b552..395ce27d 100644 --- a/unittests/operators_int.chai +++ b/unittests/operators_int.chai @@ -1,6 +1,6 @@ -var i = 1; -var j = 2; -var k = 3; +auto i = 1; +auto j = 2; +auto k = 3; assert_equal(3, i + j); assert_equal(1, +i); diff --git a/unittests/pair.chai b/unittests/pair.chai index 9b3c8049..2e30f666 100644 --- a/unittests/pair.chai +++ b/unittests/pair.chai @@ -1,4 +1,4 @@ -var p = Pair("Hello", "World") +auto p = Pair("Hello", "World") assert_equal(p.first, "Hello") assert_equal(p.second, "World") diff --git a/unittests/pointer_passed_to_constructor.chai b/unittests/pointer_passed_to_constructor.chai index 6495ee38..988a2382 100644 --- a/unittests/pointer_passed_to_constructor.chai +++ b/unittests/pointer_passed_to_constructor.chai @@ -1,8 +1,8 @@ load_module("test_module") -var i = 1; -var t0 = TestBaseType(i); +auto i = 1; +auto t0 = TestBaseType(i); -var t1 = TestBaseType(get_new_int()) +auto t1 = TestBaseType(get_new_int()) diff --git a/unittests/precedence_eq.chai b/unittests/precedence_eq.chai index 325d667e..39f2944e 100644 --- a/unittests/precedence_eq.chai +++ b/unittests/precedence_eq.chai @@ -1,3 +1,3 @@ -var x = var y = 4 +auto x = auto y = 4 assert_equal(4, x); assert_equal(4, y); diff --git a/unittests/range.chai b/unittests/range.chai index ddef4f2a..97a430b1 100644 --- a/unittests/range.chai +++ b/unittests/range.chai @@ -1,4 +1,4 @@ -var x = [1, 2, 3, 4] -var r = range(x) +auto x = [1, 2, 3, 4] +auto r = range(x) r.pop_front() assert_equal(2, r.front()); diff --git a/unittests/range_back.chai b/unittests/range_back.chai index 6bf56721..b572f944 100644 --- a/unittests/range_back.chai +++ b/unittests/range_back.chai @@ -1,4 +1,4 @@ -var x = [1, 2, 3, 4] -var r = range(x) +auto x = [1, 2, 3, 4] +auto r = range(x) r.pop_back() assert_equal(3, r.back()) diff --git a/unittests/range_contains.chai b/unittests/range_contains.chai index 28a99b12..e79051e9 100644 --- a/unittests/range_contains.chai +++ b/unittests/range_contains.chai @@ -1,4 +1,4 @@ -var v = [1,2,"hi", "world", 5.5] +auto v = [1,2,"hi", "world", 5.5] assert_equal(true, v.contains(5.5)) assert_equal(false, v.contains(0)) assert_equal(false, v.contains(1, lt)) diff --git a/unittests/range_find.chai b/unittests/range_find.chai index 08045e5a..1bdb1ba9 100644 --- a/unittests/range_find.chai +++ b/unittests/range_find.chai @@ -1,6 +1,6 @@ -var v = [2, 1, "Hi", 5.5] -var r = v.find("Hi"); +auto v = [2, 1, "Hi", 5.5] +auto r = v.find("Hi"); assert_equal("Hi", r.front()) -var r2 = v.find(2, `<`); +auto r2 = v.find(2, `<`); assert_equal(1, r2.front()); diff --git a/unittests/ref_equal.chai b/unittests/ref_equal.chai index 1dbb90e1..200991e0 100644 --- a/unittests/ref_equal.chai +++ b/unittests/ref_equal.chai @@ -1,5 +1,5 @@ -var i = 3 -var j := i +auto i = 3 +auto j := i j = 4 assert_equal(4, i) diff --git a/unittests/reflection_test.chai b/unittests/reflection_test.chai index 88b39ccc..a35649e1 100644 --- a/unittests/reflection_test.chai +++ b/unittests/reflection_test.chai @@ -1,14 +1,14 @@ load_module("reflection") -var parser := ChaiScript_Parser() -var parse_success = parser.parse("3 + 4", "INPUT") -var a := parser.ast() +auto parser := ChaiScript_Parser() +auto parse_success = parser.parse("3 + 4", "INPUT") +auto a := parser.ast() assert_equal(eval(a), 7) -var childs := a.children.front().children -var node := childs[0] +auto childs := a.children.front().children +auto node := childs[0] -var parser2 := ChaiScript_Parser() +auto parser2 := ChaiScript_Parser() parser2.parse("9", "INPUT") @@ -30,7 +30,7 @@ assert_equal(false, `+`.has_parse_tree()); assert_throws("Function does not have a parse tree", fun() { `+`.get_parse_tree(); } ); -var parsetree := my_fun.get_parse_tree(); +auto parsetree := my_fun.get_parse_tree(); assert_equal(1, eval(parsetree)); diff --git a/unittests/retro.chai b/unittests/retro.chai index d7f6818d..780a06d9 100644 --- a/unittests/retro.chai +++ b/unittests/retro.chai @@ -1,4 +1,4 @@ -var x = [1, 2, 3, 4] -var r = retro(range(x)) +auto x = [1, 2, 3, 4] +auto r = retro(range(x)) r.pop_front() assert_equal(3, r.front()) diff --git a/unittests/retroretro.chai b/unittests/retroretro.chai index 09af3ca7..36c568c9 100644 --- a/unittests/retroretro.chai +++ b/unittests/retroretro.chai @@ -1,7 +1,7 @@ -var x = [1, 2, 3, 4] -var r = retro(range(x)) +auto x = [1, 2, 3, 4] +auto r = retro(range(x)) r.pop_back() -var r2 = retro(r) +auto r2 = retro(r) r2.pop_front() assert_equal(2, r.back()) assert_equal(3, r2.front()) diff --git a/unittests/runtime_error.chai b/unittests/runtime_error.chai index e1e2fc10..b20c2c8b 100644 --- a/unittests/runtime_error.chai +++ b/unittests/runtime_error.chai @@ -1,4 +1,4 @@ -var caught = false +auto caught = false try { throw(runtime_error("error")) diff --git a/unittests/utility_test.cpp b/unittests/utility_test.cpp index 40ee4dff..9dbb52af 100644 --- a/unittests/utility_test.cpp +++ b/unittests/utility_test.cpp @@ -35,9 +35,9 @@ int main() chaiscript::ChaiScript chai; chai.add(m); - if (chai.eval("var t = Test(); t.function2(); ") == "Function2" - && chai.eval("var t = Test(); t.functionOverload(1); ") == "int" - && chai.eval("var t = Test(); t.functionOverload(1.1); ") == "double") + if (chai.eval("auto t = Test(); t.function2(); ") == "Function2" + && chai.eval("auto t = Test(); t.functionOverload(1); ") == "int" + && chai.eval("auto t = Test(); t.functionOverload(1.1); ") == "double") { chai.eval("t = Test();"); return EXIT_SUCCESS; diff --git a/unittests/vector_access.chai b/unittests/vector_access.chai index 34d483cd..58269a25 100644 --- a/unittests/vector_access.chai +++ b/unittests/vector_access.chai @@ -1,2 +1,2 @@ -var x = [1, 2, 3] +auto x = [1, 2, 3] assert_equal(3, x[2]) diff --git a/unittests/vector_erase_at.chai b/unittests/vector_erase_at.chai index 9a96218f..348cd819 100644 --- a/unittests/vector_erase_at.chai +++ b/unittests/vector_erase_at.chai @@ -1,3 +1,3 @@ -var x = [1, 2, 3] +auto x = [1, 2, 3] x.erase_at(1) assert_equal([1,3], x); diff --git a/unittests/vector_inplace_init.chai b/unittests/vector_inplace_init.chai index f16c15b3..7b01cb9d 100644 --- a/unittests/vector_inplace_init.chai +++ b/unittests/vector_inplace_init.chai @@ -1,2 +1,2 @@ -var x = [1, 2, 3] +auto x = [1, 2, 3] assert_equal(3, x.size()) diff --git a/unittests/vector_insert_at.chai b/unittests/vector_insert_at.chai index 4f6ec45b..1b42e1cf 100644 --- a/unittests/vector_insert_at.chai +++ b/unittests/vector_insert_at.chai @@ -1,3 +1,3 @@ -var x = [1, 2, 3] +auto x = [1, 2, 3] x.insert_at(1, 6) assert_equal([1,6,2,3], x); diff --git a/unittests/vector_of_one.chai b/unittests/vector_of_one.chai index f4bb01bf..2763fc19 100644 --- a/unittests/vector_of_one.chai +++ b/unittests/vector_of_one.chai @@ -1,2 +1,2 @@ -var x = [1] +auto x = [1] assert_equal(1, x[0]) diff --git a/unittests/vector_push_back.chai b/unittests/vector_push_back.chai index 715082bd..82ba4b44 100644 --- a/unittests/vector_push_back.chai +++ b/unittests/vector_push_back.chai @@ -1,4 +1,4 @@ -var x = [1, 2] +auto x = [1, 2] x.push_back(3) assert_equal(3, x.size()) assert_equal(3, x.back()) diff --git a/unittests/vector_push_empty.chai b/unittests/vector_push_empty.chai index 29c568d1..4cb7afea 100644 --- a/unittests/vector_push_empty.chai +++ b/unittests/vector_push_empty.chai @@ -1,4 +1,4 @@ -var bob = [] +auto bob = [] bob.push_back(3) assert_equal(1, bob.size()) assert_equal(3, bob.front()) diff --git a/unittests/zip.chai b/unittests/zip.chai index d39583f2..6aa5b36c 100644 --- a/unittests/zip.chai +++ b/unittests/zip.chai @@ -1,4 +1,4 @@ -var z = zip([1, 2, 3], [4, 5, 6]) +auto z = zip([1, 2, 3], [4, 5, 6]) assert_equal([1,4], z[0]) assert_equal([2,5], z[1]) diff --git a/unittests/zip_with.chai b/unittests/zip_with.chai index 1fe3dd90..ca2665ac 100644 --- a/unittests/zip_with.chai +++ b/unittests/zip_with.chai @@ -1,3 +1,3 @@ -var z = zip_with(`+`, [1, 2, 3], [4, 5, 6]) +auto z = zip_with(`+`, [1, 2, 3], [4, 5, 6]) assert_equal([5,7,9], z) From e0d7977f8a32abf8ac48a7bd32d4138ff5bf4f6d Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 24 Sep 2011 12:25:55 -0600 Subject: [PATCH 030/108] Adding reference parsing at a var decl. --- .../chaiscript/language/chaiscript_common.hpp | 4 +-- .../chaiscript/language/chaiscript_eval.hpp | 12 +++++++++ .../chaiscript/language/chaiscript_parser.hpp | 27 ++++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 5fbb2099..dec27544 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -22,7 +22,7 @@ namespace chaiscript Comparison, Addition, Subtraction, Multiplication, Division, Modulus, Array_Call, Dot_Access, Quoted_String, Single_Quoted_String, Lambda, Block, Def, While, If, For, Inline_Array, Inline_Map, Return, File, Prefix, Break, Map_Pair, Value_Range, Inline_Range, Annotation, Try, Catch, Finally, Method, Attr_Decl, Shift, Equality, Bitwise_And, Bitwise_Xor, Bitwise_Or, - Logical_And, Logical_Or + Logical_And, Logical_Or, Reference }; }; @@ -36,7 +36,7 @@ namespace chaiscript "Comparison", "Addition", "Subtraction", "Multiplication", "Division", "Modulus", "Array_Call", "Dot_Access", "Quoted_String", "Single_Quoted_String", "Lambda", "Block", "Def", "While", "If", "For", "Inline_Array", "Inline_Map", "Return", "File", "Prefix", "Break", "Map_Pair", "Value_Range", "Inline_Range", "Annotation", "Try", "Catch", "Finally", "Method", "Attr_Decl", "Shift", "Equality", "Bitwise_And", "Bitwise_Xor", "Bitwise_Or", - "Logical_And", "Logical_Or"}; + "Logical_And", "Logical_Or", "Reference"}; return ast_node_types[ast_node_type]; } diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 2e15afdf..e4d4d5a3 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -848,6 +848,18 @@ namespace chaiscript } }; + struct Reference_Node : public AST_Node { + public: + Reference_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Prefix, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) + { } + + virtual ~Reference_Node() {} + virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ + return Boxed_Value(); + } + }; + struct Prefix_AST_Node : public AST_Node { public: Prefix_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Prefix, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index e0f35d72..797bb357 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -1545,7 +1545,7 @@ namespace chaiscript if (Keyword("auto")) { retval = true; - if (!Id(true)) { + if (!(Reference() || Id(true))) { throw exception::eval_error("Incomplete variable declaration", File_Position(m_line, m_col), *m_filename); } @@ -1622,6 +1622,22 @@ namespace chaiscript return retval; } + bool Reference() { + bool retval = false; + + size_t prev_stack_top = m_match_stack.size(); + + if (Symbol("&", false)) { + retval = true; + + if (!Id(true)) { + throw exception::eval_error("Incomplete '&' expression", File_Position(m_line, m_col), *m_filename); + } + + build_match(AST_NodePtr(new eval::Reference_Node()), prev_stack_top); + } + } + /** * Reads a unary prefixed expression from input */ @@ -1684,6 +1700,15 @@ namespace chaiscript build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top); } + else if (Char('&', true)) { + retval = true; + + if (!Operator(m_operators.size()-1)) { + throw exception::eval_error("Incomplete '~' expression", File_Position(m_line, m_col), *m_filename); + } + + build_match(AST_NodePtr(new eval::Prefix_AST_Node()), prev_stack_top); + } return retval; } From 4bf3783d0b7d1be1e9b4cabcb52ac2d110ffdef3 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 24 Sep 2011 12:26:45 -0600 Subject: [PATCH 031/108] Adding new test that is just a var decl. --- unittests/var_decl.chai | 1 + 1 file changed, 1 insertion(+) create mode 100644 unittests/var_decl.chai diff --git a/unittests/var_decl.chai b/unittests/var_decl.chai new file mode 100644 index 00000000..a896e6ec --- /dev/null +++ b/unittests/var_decl.chai @@ -0,0 +1 @@ +auto x From abfd37644e792ea3cfcf4fa1f3fa17700b4c9889 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 24 Sep 2011 12:30:43 -0600 Subject: [PATCH 032/108] Fix "any" for unknown types --- include/chaiscript/dispatchkit/any.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/chaiscript/dispatchkit/any.hpp b/include/chaiscript/dispatchkit/any.hpp index 90b6336f..23f18034 100644 --- a/include/chaiscript/dispatchkit/any.hpp +++ b/include/chaiscript/dispatchkit/any.hpp @@ -114,7 +114,7 @@ namespace chaiscript { template ToType &cast() const { - if (typeid(ToType) == m_data->type()) + if (m_data && typeid(ToType) == m_data->type()) { return *static_cast(m_data->data()); } else { From 784ca412704b7de108c292238a96dd7d7e7ac611 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 24 Sep 2011 13:15:12 -0600 Subject: [PATCH 033/108] Switch vectors and maps over to curly braces from square braces to line up with C++11. --- include/chaiscript/language/chaiscript_parser.hpp | 4 ++-- include/chaiscript/language/chaiscript_prelude.hpp | 6 +++--- unittests/bind.chai | 2 +- unittests/concat.chai | 2 +- unittests/deep_array_lookup.chai | 4 ++-- unittests/drop.chai | 2 +- unittests/drop_while.chai | 2 +- unittests/exception_guards.chai | 4 ++-- unittests/filter.chai | 2 +- unittests/foldl.chai | 2 +- unittests/for.chai | 4 ++-- unittests/for_each.chai | 2 +- unittests/for_each_range.chai | 2 +- unittests/for_each_retro.chai | 2 +- unittests/function_introspection.chai | 2 +- unittests/generate_range.chai | 2 +- unittests/index_operator.chai | 2 +- unittests/join.chai | 2 +- unittests/malformed_inline_map.chai | 2 +- unittests/map.chai | 2 +- unittests/map_access.chai | 2 +- unittests/map_inplace_init.chai | 2 +- unittests/method_sugar.chai | 2 +- unittests/multiline.chai | 4 ++-- unittests/product.chai | 2 +- unittests/range.chai | 2 +- unittests/range_back.chai | 2 +- unittests/range_contains.chai | 2 +- unittests/range_find.chai | 2 +- unittests/range_inplace.chai | 2 +- unittests/reduce.chai | 2 +- unittests/retro.chai | 2 +- unittests/retroretro.chai | 2 +- unittests/sum.chai | 2 +- unittests/take.chai | 2 +- unittests/take_while.chai | 2 +- unittests/vector_access.chai | 2 +- unittests/vector_erase_at.chai | 4 ++-- unittests/vector_inplace_init.chai | 2 +- unittests/vector_insert_at.chai | 4 ++-- unittests/vector_literal_acccess.chai | 2 +- unittests/vector_of_one.chai | 2 +- unittests/vector_paren_literal_access.chai | 2 +- unittests/vector_push_back.chai | 2 +- unittests/vector_push_empty.chai | 2 +- unittests/zip.chai | 8 ++++---- unittests/zip_with.chai | 4 ++-- 47 files changed, 60 insertions(+), 60 deletions(-) diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 797bb357..f8452ff5 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -1597,10 +1597,10 @@ namespace chaiscript size_t prev_stack_top = m_match_stack.size(); - if (Char('[')) { + if (Char('{')) { retval = true; Container_Arg_List(); - if (!Char(']')) { + if (!Char('}')) { throw exception::eval_error("Missing closing square bracket", File_Position(m_line, m_col), *m_filename); } if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) { diff --git a/include/chaiscript/language/chaiscript_prelude.hpp b/include/chaiscript/language/chaiscript_prelude.hpp index 86cb6d2f..ca0a5853 100644 --- a/include/chaiscript/language/chaiscript_prelude.hpp +++ b/include/chaiscript/language/chaiscript_prelude.hpp @@ -7,7 +7,7 @@ #ifndef CHAISCRIPT_PRELUDE_HPP_ #define CHAISCRIPT_PRELUDE_HPP_ -//Note, the expression "[x,y]" in "collate" is parsed as two separate expressions +//Note, the expression "{x,y}" in "collate" is parsed as two separate expressions //by C++, so CODE_STRING, takes two expressions and adds in the missing comma #define CODE_STRING(x, y) #x ", " #y @@ -23,7 +23,7 @@ def to_string(x) : call_exists(first, x) && call_exists(second, x) { \n\ }\n\ # to_string for containers\n\ def to_string(x) : call_exists(range, x) && !x.is_type("string"){ \n\ - "[" + x.join(", ") + "]"; \n\ + "{" + x.join(", ") + "}"; \n\ }\n\ # Basic to_string function\n\ def to_string(x) { \n\ @@ -259,7 +259,7 @@ def generate_range(x, y) { \n\ }\n\ # Returns a new Vector with the first value to the second value as its elements\n\ def collate(x, y) { \n\ - [x, y]; \n\ + {x, y}; \n\ } \n\ def zip_with(f, x, y, inserter) : call_exists(range, x) && call_exists(range, y) { \n\ auto r_x = range(x); \n\ diff --git a/unittests/bind.chai b/unittests/bind.chai index a3af3004..d89d66de 100644 --- a/unittests/bind.chai +++ b/unittests/bind.chai @@ -1,2 +1,2 @@ auto prod = bind(foldl, _, `*`, 1.0) -assert_equal(60, prod([3, 4, 5])) +assert_equal(60, prod({3, 4, 5})) diff --git a/unittests/concat.chai b/unittests/concat.chai index 53950a6e..4b897b78 100644 --- a/unittests/concat.chai +++ b/unittests/concat.chai @@ -1,4 +1,4 @@ -auto v = concat([1, 2], [3, 4]); +auto v = concat({1, 2}, {3, 4}); assert_equal(4, v.size()); assert_equal(1, v[0]); diff --git a/unittests/deep_array_lookup.chai b/unittests/deep_array_lookup.chai index 8a86eaa3..d94cb8f6 100644 --- a/unittests/deep_array_lookup.chai +++ b/unittests/deep_array_lookup.chai @@ -1,9 +1,9 @@ -auto a = [1,2,3, [4,5,6] ] +auto a = {1,2,3, {4,5,6} } assert_equal(a[3][0], 4) -def Test::Test() { this.a = [1,2,3]; } +def Test::Test() { this.a = {1,2,3}; } attr Test::a; auto t = Test(); diff --git a/unittests/drop.chai b/unittests/drop.chai index c64b431e..9758c8fd 100644 --- a/unittests/drop.chai +++ b/unittests/drop.chai @@ -1 +1 @@ -assert_equal([3,4], drop([1, 2, 3, 4], 2)) +assert_equal({3,4}, drop({1, 2, 3, 4}, 2)) diff --git a/unittests/drop_while.chai b/unittests/drop_while.chai index 08e19f2f..6912cf27 100644 --- a/unittests/drop_while.chai +++ b/unittests/drop_while.chai @@ -1 +1 @@ -assert_equal([2, 3], drop_while([1, 2, 3], odd)) +assert_equal({2, 3}, drop_while({1, 2, 3}, odd)) diff --git a/unittests/exception_guards.chai b/unittests/exception_guards.chai index 12792985..2c2ec093 100644 --- a/unittests/exception_guards.chai +++ b/unittests/exception_guards.chai @@ -1,4 +1,4 @@ -auto results = []; +auto results = {}; for (auto i = 2; i < 6; ++i) { try { @@ -31,4 +31,4 @@ catch { results.push_back("defaultcatch"); } -assert_equal(["c2: 2", "c2: 3", "c3: 4", "c3: 5", "defaultcatch"], results); +assert_equal({"c2: 2", "c2: 3", "c3: 4", "c3: 5", "defaultcatch"}, results); diff --git a/unittests/filter.chai b/unittests/filter.chai index 6d805fee..2b8b43ac 100644 --- a/unittests/filter.chai +++ b/unittests/filter.chai @@ -1 +1 @@ -assert_equal([1,3], filter([1, 2, 3, 4], odd)) +assert_equal({1,3}, filter({1, 2, 3, 4}, odd)) diff --git a/unittests/foldl.chai b/unittests/foldl.chai index 7e9db51f..25de4f3d 100644 --- a/unittests/foldl.chai +++ b/unittests/foldl.chai @@ -1 +1 @@ -assert_equal(10, foldl([1, 2, 3, 4], `+`, 0)) +assert_equal(10, foldl({1, 2, 3, 4}, `+`, 0)) diff --git a/unittests/for.chai b/unittests/for.chai index c5769992..e4ae118e 100644 --- a/unittests/for.chai +++ b/unittests/for.chai @@ -1,7 +1,7 @@ -auto ret = [] +auto ret = {} for (auto i = 0; i < 5; ++i) { ret.push_back(i); } -assert_equal([0,1,2,3,4], ret); +assert_equal({0,1,2,3,4}, ret); diff --git a/unittests/for_each.chai b/unittests/for_each.chai index 242a1baf..0a8d7370 100644 --- a/unittests/for_each.chai +++ b/unittests/for_each.chai @@ -1 +1 @@ -for_each([1, 2, 3], print) +for_each({1, 2, 3}, print) diff --git a/unittests/for_each_range.chai b/unittests/for_each_range.chai index 3a92641d..3a31fc02 100644 --- a/unittests/for_each_range.chai +++ b/unittests/for_each_range.chai @@ -1,3 +1,3 @@ -auto v = [1,2,3]; +auto v = {1,2,3}; auto r = range(v); for_each(r, fun(x) { assert_equal(true, x>0); } ) diff --git a/unittests/for_each_retro.chai b/unittests/for_each_retro.chai index 4cd0ff51..816d30f4 100644 --- a/unittests/for_each_retro.chai +++ b/unittests/for_each_retro.chai @@ -1,4 +1,4 @@ // Don't bother checking the output from this one, just makes sure it executes -auto v = [1,2,3]; +auto v = {1,2,3}; auto r = retro(range(v)); for_each(r, print) diff --git a/unittests/function_introspection.chai b/unittests/function_introspection.chai index 6d808dfe..335dc1af 100644 --- a/unittests/function_introspection.chai +++ b/unittests/function_introspection.chai @@ -18,7 +18,7 @@ assert_equal(test_function, test_function); assert_not_equal(test_function, `+`); -assert_equal(test_function.call([1]), 1); +assert_equal(test_function.call({1}), 1); // dynamic object function tests diff --git a/unittests/generate_range.chai b/unittests/generate_range.chai index 9e25970a..9f729eda 100644 --- a/unittests/generate_range.chai +++ b/unittests/generate_range.chai @@ -1 +1 @@ -assert_equal([1,2,3,4,5,6,7,8,9,10], generate_range(1, 10)) +assert_equal({1,2,3,4,5,6,7,8,9,10}, generate_range(1, 10)) diff --git a/unittests/index_operator.chai b/unittests/index_operator.chai index f8074042..0b7d7706 100644 --- a/unittests/index_operator.chai +++ b/unittests/index_operator.chai @@ -1,7 +1,7 @@ // tests more complex parses of the index operator -def Bob::bob3() { return [1,2,3]; } +def Bob::bob3() { return {1,2,3}; } def Bob::Bob() {} auto b = Bob(); diff --git a/unittests/join.chai b/unittests/join.chai index 1891c468..4ae6665e 100644 --- a/unittests/join.chai +++ b/unittests/join.chai @@ -1 +1 @@ -assert_equal("1*2*3", join([1, 2, 3], "*")) +assert_equal("1*2*3", join({1, 2, 3}, "*")) diff --git a/unittests/malformed_inline_map.chai b/unittests/malformed_inline_map.chai index d267bcfe..618033d5 100644 --- a/unittests/malformed_inline_map.chai +++ b/unittests/malformed_inline_map.chai @@ -1,2 +1,2 @@ -assert_throws("Parse failure", fun() { eval("[\"hello\":5,\"j\",\"k\"]") } ); +assert_throws("Parse failure", fun() { eval("{\"hello\":5,\"j\",\"k\"}") } ); diff --git a/unittests/map.chai b/unittests/map.chai index a0a31ee1..7344f809 100644 --- a/unittests/map.chai +++ b/unittests/map.chai @@ -1 +1 @@ -assert_equal([true, false, true], map([1,2,3], odd)) +assert_equal({true, false, true}, map({1,2,3}, odd)) diff --git a/unittests/map_access.chai b/unittests/map_access.chai index d544036d..1d291237 100644 --- a/unittests/map_access.chai +++ b/unittests/map_access.chai @@ -1,2 +1,2 @@ -auto x = ["bob":2, "fred":3] +auto x = {"bob":2, "fred":3} assert_equal(3, x["fred"]) diff --git a/unittests/map_inplace_init.chai b/unittests/map_inplace_init.chai index 1d88494f..5806292b 100644 --- a/unittests/map_inplace_init.chai +++ b/unittests/map_inplace_init.chai @@ -1,3 +1,3 @@ -auto x = ["bob":1, "fred":2] +auto x = {"bob":1, "fred":2} assert_equal(2, x.size()); diff --git a/unittests/method_sugar.chai b/unittests/method_sugar.chai index 521400bc..97598f90 100644 --- a/unittests/method_sugar.chai +++ b/unittests/method_sugar.chai @@ -1 +1 @@ -assert_equal(6, [1, 2, 3].sum()) +assert_equal(6, {1, 2, 3}.sum()) diff --git a/unittests/multiline.chai b/unittests/multiline.chai index dfa213c3..0676d0c7 100644 --- a/unittests/multiline.chai +++ b/unittests/multiline.chai @@ -1,5 +1,5 @@ -auto x = [1, 2, - 3, 4] +auto x = {1, 2, + 3, 4} assert_equal(1, x[0]) diff --git a/unittests/product.chai b/unittests/product.chai index 03ba3cfa..f0b9d0a1 100644 --- a/unittests/product.chai +++ b/unittests/product.chai @@ -1 +1 @@ -assert_equal(24, product([1, 2, 3, 4])) +assert_equal(24, product({1, 2, 3, 4})) diff --git a/unittests/range.chai b/unittests/range.chai index 97a430b1..cdc5689e 100644 --- a/unittests/range.chai +++ b/unittests/range.chai @@ -1,4 +1,4 @@ -auto x = [1, 2, 3, 4] +auto x = {1, 2, 3, 4} auto r = range(x) r.pop_front() assert_equal(2, r.front()); diff --git a/unittests/range_back.chai b/unittests/range_back.chai index b572f944..a4936559 100644 --- a/unittests/range_back.chai +++ b/unittests/range_back.chai @@ -1,4 +1,4 @@ -auto x = [1, 2, 3, 4] +auto x = {1, 2, 3, 4} auto r = range(x) r.pop_back() assert_equal(3, r.back()) diff --git a/unittests/range_contains.chai b/unittests/range_contains.chai index e79051e9..a5b7705e 100644 --- a/unittests/range_contains.chai +++ b/unittests/range_contains.chai @@ -1,4 +1,4 @@ -auto v = [1,2,"hi", "world", 5.5] +auto v = {1,2,"hi", "world", 5.5} assert_equal(true, v.contains(5.5)) assert_equal(false, v.contains(0)) assert_equal(false, v.contains(1, lt)) diff --git a/unittests/range_find.chai b/unittests/range_find.chai index 1bdb1ba9..e51bc719 100644 --- a/unittests/range_find.chai +++ b/unittests/range_find.chai @@ -1,4 +1,4 @@ -auto v = [2, 1, "Hi", 5.5] +auto v = {2, 1, "Hi", 5.5} auto r = v.find("Hi"); assert_equal("Hi", r.front()) diff --git a/unittests/range_inplace.chai b/unittests/range_inplace.chai index d661f5de..ff90a0e3 100644 --- a/unittests/range_inplace.chai +++ b/unittests/range_inplace.chai @@ -1 +1 @@ -assert_equal([3,4,5,6], [3..6]) +assert_equal({3,4,5,6}, {3..6}) diff --git a/unittests/reduce.chai b/unittests/reduce.chai index 3b255b31..fb347e80 100644 --- a/unittests/reduce.chai +++ b/unittests/reduce.chai @@ -1 +1 @@ -assert_equal(10, reduce([1, 2, 3, 4], `+`)) +assert_equal(10, reduce({1, 2, 3, 4}, `+`)) diff --git a/unittests/retro.chai b/unittests/retro.chai index 780a06d9..1e8359f2 100644 --- a/unittests/retro.chai +++ b/unittests/retro.chai @@ -1,4 +1,4 @@ -auto x = [1, 2, 3, 4] +auto x = {1, 2, 3, 4} auto r = retro(range(x)) r.pop_front() assert_equal(3, r.front()) diff --git a/unittests/retroretro.chai b/unittests/retroretro.chai index 36c568c9..8e203cb9 100644 --- a/unittests/retroretro.chai +++ b/unittests/retroretro.chai @@ -1,4 +1,4 @@ -auto x = [1, 2, 3, 4] +auto x = {1, 2, 3, 4} auto r = retro(range(x)) r.pop_back() auto r2 = retro(r) diff --git a/unittests/sum.chai b/unittests/sum.chai index 7502ae7e..55885931 100644 --- a/unittests/sum.chai +++ b/unittests/sum.chai @@ -1 +1 @@ -assert_equal(10, sum([1, 2, 3, 4])) +assert_equal(10, sum({1, 2, 3, 4})) diff --git a/unittests/take.chai b/unittests/take.chai index 5110392e..06df1cb2 100644 --- a/unittests/take.chai +++ b/unittests/take.chai @@ -1 +1 @@ -assert_equal(2, take([1, 2, 3, 4], 2).back()) +assert_equal(2, take({1, 2, 3, 4}, 2).back()) diff --git a/unittests/take_while.chai b/unittests/take_while.chai index 56a4ba22..3bfc1b0b 100644 --- a/unittests/take_while.chai +++ b/unittests/take_while.chai @@ -1 +1 @@ -assert_equal([1], take_while([1, 2, 3, 4], odd)) +assert_equal({1}, take_while({1, 2, 3, 4}, odd)) diff --git a/unittests/vector_access.chai b/unittests/vector_access.chai index 58269a25..7eaa4946 100644 --- a/unittests/vector_access.chai +++ b/unittests/vector_access.chai @@ -1,2 +1,2 @@ -auto x = [1, 2, 3] +auto x = {1, 2, 3} assert_equal(3, x[2]) diff --git a/unittests/vector_erase_at.chai b/unittests/vector_erase_at.chai index 348cd819..3bb77b67 100644 --- a/unittests/vector_erase_at.chai +++ b/unittests/vector_erase_at.chai @@ -1,3 +1,3 @@ -auto x = [1, 2, 3] +auto x = {1, 2, 3} x.erase_at(1) -assert_equal([1,3], x); +assert_equal({1,3}, x); diff --git a/unittests/vector_inplace_init.chai b/unittests/vector_inplace_init.chai index 7b01cb9d..04e0593d 100644 --- a/unittests/vector_inplace_init.chai +++ b/unittests/vector_inplace_init.chai @@ -1,2 +1,2 @@ -auto x = [1, 2, 3] +auto x = {1, 2, 3} assert_equal(3, x.size()) diff --git a/unittests/vector_insert_at.chai b/unittests/vector_insert_at.chai index 1b42e1cf..9a7fd2b4 100644 --- a/unittests/vector_insert_at.chai +++ b/unittests/vector_insert_at.chai @@ -1,3 +1,3 @@ -auto x = [1, 2, 3] +auto x = {1, 2, 3} x.insert_at(1, 6) -assert_equal([1,6,2,3], x); +assert_equal({1,6,2,3}, x); diff --git a/unittests/vector_literal_acccess.chai b/unittests/vector_literal_acccess.chai index 29a7c05f..a33a5525 100644 --- a/unittests/vector_literal_acccess.chai +++ b/unittests/vector_literal_acccess.chai @@ -1 +1 @@ -assert_equal(1, [1,2,3][0]) +assert_equal(1, {1,2,3}[0]) diff --git a/unittests/vector_of_one.chai b/unittests/vector_of_one.chai index 2763fc19..a046e316 100644 --- a/unittests/vector_of_one.chai +++ b/unittests/vector_of_one.chai @@ -1,2 +1,2 @@ -auto x = [1] +auto x = {1} assert_equal(1, x[0]) diff --git a/unittests/vector_paren_literal_access.chai b/unittests/vector_paren_literal_access.chai index a0c6b966..f96194e2 100644 --- a/unittests/vector_paren_literal_access.chai +++ b/unittests/vector_paren_literal_access.chai @@ -1 +1 @@ -assert_equal(1, ([1,2,3])[0]) +assert_equal(1, ({1,2,3})[0]) diff --git a/unittests/vector_push_back.chai b/unittests/vector_push_back.chai index 82ba4b44..f5d81bf5 100644 --- a/unittests/vector_push_back.chai +++ b/unittests/vector_push_back.chai @@ -1,4 +1,4 @@ -auto x = [1, 2] +auto x = {1, 2} x.push_back(3) assert_equal(3, x.size()) assert_equal(3, x.back()) diff --git a/unittests/vector_push_empty.chai b/unittests/vector_push_empty.chai index 4cb7afea..a279eeab 100644 --- a/unittests/vector_push_empty.chai +++ b/unittests/vector_push_empty.chai @@ -1,4 +1,4 @@ -auto bob = [] +auto bob = {} bob.push_back(3) assert_equal(1, bob.size()) assert_equal(3, bob.front()) diff --git a/unittests/zip.chai b/unittests/zip.chai index 6aa5b36c..a6a83270 100644 --- a/unittests/zip.chai +++ b/unittests/zip.chai @@ -1,5 +1,5 @@ -auto z = zip([1, 2, 3], [4, 5, 6]) +auto z = zip({1, 2, 3}, {4, 5, 6}) -assert_equal([1,4], z[0]) -assert_equal([2,5], z[1]) -assert_equal([3,6], z[2]) +assert_equal({1,4}, z[0]) +assert_equal({2,5}, z[1]) +assert_equal({3,6}, z[2]) diff --git a/unittests/zip_with.chai b/unittests/zip_with.chai index ca2665ac..9b232226 100644 --- a/unittests/zip_with.chai +++ b/unittests/zip_with.chai @@ -1,3 +1,3 @@ -auto z = zip_with(`+`, [1, 2, 3], [4, 5, 6]) +auto z = zip_with(`+`, {1, 2, 3}, {4, 5, 6}) -assert_equal([5,7,9], z) +assert_equal({5,7,9}, z) From 3765c23598f1ad813497c32a1da0461b3924f497 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 24 Sep 2011 13:31:24 -0600 Subject: [PATCH 034/108] Switch lambda syntax over to [](){} format, to line up with C++11. --- include/chaiscript/dispatchkit/bootstrap.hpp | 2 +- include/chaiscript/language/chaiscript_parser.hpp | 6 +++++- include/chaiscript/language/chaiscript_prelude.hpp | 4 ++-- unittests/assign_const.chai | 4 ++-- unittests/const_range_test.chai | 2 +- unittests/eval_error.chai | 2 +- unittests/for_each_range.chai | 2 +- unittests/function_introspection.chai | 6 +++--- unittests/invalid_function_assignment.chai | 2 +- unittests/invalid_function_reassignment.chai | 2 +- unittests/lambda.chai | 2 +- unittests/malformed_inline_map.chai | 2 +- unittests/multiline.chai | 2 +- unittests/operators_float.chai | 2 +- unittests/reflection_test.chai | 2 +- 15 files changed, 23 insertions(+), 19 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 6be8a1bf..5156050c 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -406,7 +406,7 @@ namespace chaiscript m->add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs"); m->add(fun(&dispatch::Dynamic_Object::get_attr), "get_attr"); - m->eval("def Dynamic_Object::clone() { auto new_o := Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind(fun(new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }"); + m->eval("def Dynamic_Object::clone() { auto new_o := Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind([](new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }"); m->add(fun(&has_guard), "has_guard"); m->add(fun(&get_guard), "get_guard"); diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index f8452ff5..dbf3631b 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -1119,7 +1119,11 @@ namespace chaiscript size_t prev_stack_top = m_match_stack.size(); - if (Keyword("fun")) { + //if (Keyword("fun")) { + if (Char('[')) { + if (!Char(']')) { + throw exception::eval_error("Closure list not currently supported", File_Position(m_line, m_col), *m_filename); + } retval = true; if (Char('(')) { diff --git a/include/chaiscript/language/chaiscript_prelude.hpp b/include/chaiscript/language/chaiscript_prelude.hpp index ca0a5853..b96aba41 100644 --- a/include/chaiscript/language/chaiscript_prelude.hpp +++ b/include/chaiscript/language/chaiscript_prelude.hpp @@ -305,10 +305,10 @@ def string::find_last_not_of(list) : is_type(list, "string") { \n\ int(find_last_not_of(this, list, -1)); \n\ } \n\ def string::ltrim() { \n\ - drop_while(this, fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'}); \n\ + drop_while(this, [](x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'}); \n\ } \n\ def string::rtrim() { \n\ - reverse(drop_while(reverse(this), fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'})); \n\ + reverse(drop_while(reverse(this), [](x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'})); \n\ } \n\ def string::trim() { \n\ ltrim(rtrim(this)); \n\ diff --git a/unittests/assign_const.chai b/unittests/assign_const.chai index ff6a8c3d..7b2ede58 100644 --- a/unittests/assign_const.chai +++ b/unittests/assign_const.chai @@ -1,2 +1,2 @@ -assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 = 2 } ); -assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 + 2 = 2 } ); +assert_throws("Mismatched types in equation, lhs is const.", []() { 1 = 2 } ); +assert_throws("Mismatched types in equation, lhs is const.", []() { 1 + 2 = 2 } ); diff --git a/unittests/const_range_test.chai b/unittests/const_range_test.chai index 5ebb5808..d8840f36 100644 --- a/unittests/const_range_test.chai +++ b/unittests/const_range_test.chai @@ -1,4 +1,4 @@ //If the following succeeds, the test passes -"Hello World".for_each(fun(x) { print(x) } ) +"Hello World".for_each([](x) { print(x) } ) diff --git a/unittests/eval_error.chai b/unittests/eval_error.chai index b2737a11..54eef2c4 100644 --- a/unittests/eval_error.chai +++ b/unittests/eval_error.chai @@ -34,6 +34,6 @@ def while_doing() } } -auto f = fun() { while_doing(); } +auto f = []() { while_doing(); } assert_equal(get_eval_error(f).call_stack.size(), 16) diff --git a/unittests/for_each_range.chai b/unittests/for_each_range.chai index 3a31fc02..7af3025d 100644 --- a/unittests/for_each_range.chai +++ b/unittests/for_each_range.chai @@ -1,3 +1,3 @@ auto v = {1,2,3}; auto r = range(v); -for_each(r, fun(x) { assert_equal(true, x>0); } ) +for_each(r, [](x) { assert_equal(true, x>0); } ) diff --git a/unittests/function_introspection.chai b/unittests/function_introspection.chai index 335dc1af..e58beb6e 100644 --- a/unittests/function_introspection.chai +++ b/unittests/function_introspection.chai @@ -67,10 +67,10 @@ auto group = group_guard.get_contained_functions(); assert_equal(true, group[0].has_guard()) assert_equal(false, group[1].has_guard()) -assert_throws("Function does not have a guard", fun() { group[0].get_guard(); } ); -assert_throws("Function does not have a guard", fun() { without_guard.get_guard(); } ); +assert_throws("Function does not have a guard", []() { group[0].get_guard(); } ); +assert_throws("Function does not have a guard", []() { without_guard.get_guard(); } ); auto guard = with_guard.get_guard(); assert_equal(false, guard.has_guard()); -assert_throws("Function does not have a guard", fun() { guard.get_guard(); } ); +assert_throws("Function does not have a guard", []() { guard.get_guard(); } ); diff --git a/unittests/invalid_function_assignment.chai b/unittests/invalid_function_assignment.chai index 99b098db..69ff5cab 100644 --- a/unittests/invalid_function_assignment.chai +++ b/unittests/invalid_function_assignment.chai @@ -1 +1 @@ -assert_throws("Illegal const function assignment", fun() { clone = `-` } ); +assert_throws("Illegal const function assignment", []() { clone = `-` } ); diff --git a/unittests/invalid_function_reassignment.chai b/unittests/invalid_function_reassignment.chai index 784372ac..d688a2a9 100644 --- a/unittests/invalid_function_reassignment.chai +++ b/unittests/invalid_function_reassignment.chai @@ -1 +1 @@ -assert_throws("Invalid function reassignment", fun() { auto x = 5; x = `-`; } ); +assert_throws("Invalid function reassignment", []() { auto x = 5; x = `-`; } ); diff --git a/unittests/lambda.chai b/unittests/lambda.chai index 9b717ec5..f2bd3db1 100644 --- a/unittests/lambda.chai +++ b/unittests/lambda.chai @@ -1,2 +1,2 @@ -auto bob = fun(x) { x + 1 } +auto bob = [](x) { x + 1 } assert_equal(4, bob(3)); diff --git a/unittests/malformed_inline_map.chai b/unittests/malformed_inline_map.chai index 618033d5..1cd8acf5 100644 --- a/unittests/malformed_inline_map.chai +++ b/unittests/malformed_inline_map.chai @@ -1,2 +1,2 @@ -assert_throws("Parse failure", fun() { eval("{\"hello\":5,\"j\",\"k\"}") } ); +assert_throws("Parse failure", []() { eval("{\"hello\":5,\"j\",\"k\"}") } ); diff --git a/unittests/multiline.chai b/unittests/multiline.chai index 0676d0c7..52a29122 100644 --- a/unittests/multiline.chai +++ b/unittests/multiline.chai @@ -4,6 +4,6 @@ auto x = {1, 2, assert_equal(1, x[0]) auto y = map(x, - fun(x) { x + 1 }) + [](x) { x + 1 }) assert_equal(2, y[0]) diff --git a/unittests/operators_float.chai b/unittests/operators_float.chai index 3f693786..7dcf6293 100644 --- a/unittests/operators_float.chai +++ b/unittests/operators_float.chai @@ -13,4 +13,4 @@ assert_equal(0, i -= i) assert_equal(3, j *= 1.5) assert_equal(1.5, j /= 2) assert_equal(2.5, j += 1) -assert_throws("No modulous for float", fun() { k % 2 } ); +assert_throws("No modulous for float", []() { k % 2 } ); diff --git a/unittests/reflection_test.chai b/unittests/reflection_test.chai index a35649e1..9db37a92 100644 --- a/unittests/reflection_test.chai +++ b/unittests/reflection_test.chai @@ -28,7 +28,7 @@ def my_fun() assert_equal(true, my_fun.has_parse_tree()); assert_equal(false, `+`.has_parse_tree()); -assert_throws("Function does not have a parse tree", fun() { `+`.get_parse_tree(); } ); +assert_throws("Function does not have a parse tree", []() { `+`.get_parse_tree(); } ); auto parsetree := my_fun.get_parse_tree(); From 1eb402e47472d68ed7e1409f9df9e811e913518d Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 24 Sep 2011 14:14:37 -0600 Subject: [PATCH 035/108] Adding an access to a map literal which doesn't seem to be working (though it's vector counterpart does) --- unittests/map_literal_access.chai | 1 + 1 file changed, 1 insertion(+) create mode 100644 unittests/map_literal_access.chai diff --git a/unittests/map_literal_access.chai b/unittests/map_literal_access.chai new file mode 100644 index 00000000..d4a26236 --- /dev/null +++ b/unittests/map_literal_access.chai @@ -0,0 +1 @@ +assert_equal(1, {"bob":1,"fred":2}["bob"]) From a28dfd8695812122c1dc6648535bd35e4166af64 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 24 Sep 2011 14:21:21 -0600 Subject: [PATCH 036/108] Get & variable declarations working --- .../chaiscript/language/chaiscript_common.hpp | 2 +- .../chaiscript/language/chaiscript_eval.hpp | 46 ++++++++++++++----- .../chaiscript/language/chaiscript_parser.hpp | 5 +- unittests/var_ref_decl.chai | 19 ++++++++ 4 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 unittests/var_ref_decl.chai diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 74fb410b..f8af5e16 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -112,7 +112,7 @@ namespace chaiscript struct AST_Node : std::enable_shared_from_this { public: const std::string text; - const int identifier; + const int identifier; //< \todo shouldn't this be a strongly typed enum value? std::shared_ptr filename; File_Position start, end; std::vector children; diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index e4d4d5a3..aaad2c82 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -295,7 +295,16 @@ namespace chaiscript } else if (this->children[1]->text == "=") { try { if (lhs.is_undef()) { - retval = t_ss.call_function("clone", retval); + if (!this->children.empty() && + !this->children[0]->children.empty() + && this->children[0]->children[0]->identifier == AST_Node_Type::Reference) + { + /// \todo This does not handle the case of an unassigned reference variable + /// being assigned outside of its declaration + lhs.assign(retval); + } else { + retval = t_ss.call_function("clone", retval); + } retval.clear_dependencies(); } @@ -335,13 +344,21 @@ namespace chaiscript AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Var_Decl_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ - try { - t_ss.add_object(this->children[0]->text, Boxed_Value()); + if (this->children[0]->identifier == AST_Node_Type::Reference) + { + return this->children[0]->eval(t_ss); + } else { + std::string idname = this->children[0]->text; + + try { + t_ss.add_object(idname, Boxed_Value()); + } + catch (const exception::reserved_word_error &) { + throw exception::eval_error("Reserved word used as variable '" + idname + "'"); + } + return t_ss.get_object(idname); } - catch (const exception::reserved_word_error &) { - throw exception::eval_error("Reserved word used as variable '" + this->children[0]->text + "'"); - } - return t_ss.get_object(this->children[0]->text); + } }; @@ -848,16 +865,23 @@ namespace chaiscript } }; - struct Reference_Node : public AST_Node { + struct Reference_AST_Node : public AST_Node { public: - Reference_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Prefix, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + Reference_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Reference, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } - virtual ~Reference_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ - return Boxed_Value(); + try { + t_ss.add_object(this->children[0]->text, Boxed_Value()); + } + catch (const exception::reserved_word_error &) { + throw exception::eval_error("Reserved word used as variable '" + this->children[0]->text + "'"); + } + return t_ss.get_object(this->children[0]->text); } + + virtual ~Reference_AST_Node() {} }; struct Prefix_AST_Node : public AST_Node { diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 797bb357..eb4eda62 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -1634,8 +1634,11 @@ namespace chaiscript throw exception::eval_error("Incomplete '&' expression", File_Position(m_line, m_col), *m_filename); } - build_match(AST_NodePtr(new eval::Reference_Node()), prev_stack_top); + build_match(AST_NodePtr( + new eval::Reference_AST_Node()), prev_stack_top); } + + return retval; } /** diff --git a/unittests/var_ref_decl.chai b/unittests/var_ref_decl.chai new file mode 100644 index 00000000..58bfa241 --- /dev/null +++ b/unittests/var_ref_decl.chai @@ -0,0 +1,19 @@ +auto l = 5 +auto & k = l; + + +assert_equal(l, k) + +l = 10 + +assert_equal(10, l) +assert_equal(k, l) + +auto & j +j = l // assignment outside of declaration does *not* result in reference assignment +j = 15 + +assert_equal(15, j) +assert_equal(k, l) +assert_equal(10, l) + From 52d9e1e87114b818dd460b72408f0045366a9c26 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 24 Sep 2011 15:06:31 -0600 Subject: [PATCH 037/108] Remove := operator and fix & usage. --- include/chaiscript/dispatchkit/bootstrap.hpp | 2 +- include/chaiscript/language/chaiscript_engine.hpp | 1 - include/chaiscript/language/chaiscript_eval.hpp | 10 ++-------- include/chaiscript/language/chaiscript_parser.hpp | 2 +- unittests/ref_equal.chai | 5 ----- unittests/reflection_test.chai | 12 ++++++------ 6 files changed, 10 insertions(+), 22 deletions(-) delete mode 100644 unittests/ref_equal.chai diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 6be8a1bf..8abca9ab 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -406,7 +406,7 @@ namespace chaiscript m->add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs"); m->add(fun(&dispatch::Dynamic_Object::get_attr), "get_attr"); - m->eval("def Dynamic_Object::clone() { auto new_o := Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind(fun(new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }"); + m->eval("def Dynamic_Object::clone() { auto &new_o = Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind(fun(new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }"); m->add(fun(&has_guard), "has_guard"); m->add(fun(&get_guard), "get_guard"); diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index aeeba9eb..1b7cda1e 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -335,7 +335,6 @@ namespace chaiscript m_engine.add_reserved_word("&&"); m_engine.add_reserved_word("||"); m_engine.add_reserved_word(","); - m_engine.add_reserved_word(":="); m_engine.add_reserved_word("auto"); m_engine.add_reserved_word("return"); m_engine.add_reserved_word("break"); diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index aaad2c82..3c7cd21b 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -302,10 +302,11 @@ namespace chaiscript /// \todo This does not handle the case of an unassigned reference variable /// being assigned outside of its declaration lhs.assign(retval); + return retval; } else { retval = t_ss.call_function("clone", retval); + retval.clear_dependencies(); } - retval.clear_dependencies(); } try { @@ -319,13 +320,6 @@ namespace chaiscript throw exception::eval_error("Can not clone right hand side of equation"); } } - else if (this->children[1]->text == ":=") { - if (lhs.is_undef() || type_match(lhs, retval)) { - lhs.assign(retval); - } else { - throw exception::eval_error("Mismatched types in equation"); - } - } else { try { retval = t_ss.call_function(this->children[1]->text, lhs, retval); diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index eb4eda62..edd3f77d 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -1889,7 +1889,7 @@ namespace chaiscript if (Operator()) { retval = true; - if (Symbol("=", true, true) || Symbol(":=", true, true) || Symbol("+=", true, true) || + if (Symbol("=", true, true) || Symbol("+=", true, true) || Symbol("-=", true, true) || Symbol("*=", true, true) || Symbol("/=", true, true) || Symbol("%=", true, true) || Symbol("<<=", true, true) || Symbol(">>=", true, true) || Symbol("&=", true, true) || Symbol("^=", true, true) || Symbol("|=", true, true)) { diff --git a/unittests/ref_equal.chai b/unittests/ref_equal.chai deleted file mode 100644 index 200991e0..00000000 --- a/unittests/ref_equal.chai +++ /dev/null @@ -1,5 +0,0 @@ -auto i = 3 -auto j := i -j = 4 - -assert_equal(4, i) diff --git a/unittests/reflection_test.chai b/unittests/reflection_test.chai index a35649e1..42566bc1 100644 --- a/unittests/reflection_test.chai +++ b/unittests/reflection_test.chai @@ -1,14 +1,14 @@ load_module("reflection") -auto parser := ChaiScript_Parser() +auto& parser = ChaiScript_Parser() auto parse_success = parser.parse("3 + 4", "INPUT") -auto a := parser.ast() +auto& a = parser.ast() assert_equal(eval(a), 7) -auto childs := a.children.front().children -auto node := childs[0] +auto& childs = a.children.front().children +auto& node = childs[0] -auto parser2 := ChaiScript_Parser() +auto& parser2 = ChaiScript_Parser() parser2.parse("9", "INPUT") @@ -30,7 +30,7 @@ assert_equal(false, `+`.has_parse_tree()); assert_throws("Function does not have a parse tree", fun() { `+`.get_parse_tree(); } ); -auto parsetree := my_fun.get_parse_tree(); +auto& parsetree = my_fun.get_parse_tree(); assert_equal(1, eval(parsetree)); From 3329732cebd3d12907da5218d5484275e652f3f5 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 24 Sep 2011 15:21:15 -0600 Subject: [PATCH 038/108] Add scoping test --- unittests/scoping.chai | 1 + unittests/unit_test.inc | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 unittests/scoping.chai diff --git a/unittests/scoping.chai b/unittests/scoping.chai new file mode 100644 index 00000000..e0121005 --- /dev/null +++ b/unittests/scoping.chai @@ -0,0 +1 @@ +{ { { { assert_true(true); assert_true(true); } } } } diff --git a/unittests/unit_test.inc b/unittests/unit_test.inc index d746e7bf..9d2fb91f 100644 --- a/unittests/unit_test.inc +++ b/unittests/unit_test.inc @@ -23,7 +23,7 @@ def assert_true(f) { if (!f) { - print("assert_false failure"); + print("assert_true failure"); exit(-1); } } From 702b5fdba120a77f75cfd0d059a017e5d23458b8 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 25 Sep 2011 16:46:05 -0600 Subject: [PATCH 039/108] Enhance and correct error messages --- .../chaiscript/dispatchkit/dispatchkit.hpp | 7 +- .../dispatchkit/proxy_functions.hpp | 13 +- .../chaiscript/language/chaiscript_common.hpp | 111 +++++++++++++++++- .../chaiscript/language/chaiscript_eval.hpp | 42 +++---- .../chaiscript/language/chaiscript_parser.hpp | 4 +- 5 files changed, 137 insertions(+), 40 deletions(-) diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index 257379e8..f6c68e2b 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -688,10 +688,9 @@ namespace chaiscript /** * Dump object info to stdout */ - void dump_object(Boxed_Value o) const + void dump_object(const Boxed_Value &o) const { - Type_Info ti = o.get_type_info(); - std::cout << (ti.is_const()?"const ":"") << get_type_name(ti) << std::endl; + std::cout << (o.is_const()?"const ":"") << type_name(o) << std::endl; } /** @@ -783,7 +782,7 @@ namespace chaiscript return false; } - std::string type_name(Boxed_Value obj) const + std::string type_name(const Boxed_Value &obj) const { return get_type_name(obj.get_type_info()); } diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index aa5ba0ef..e04f0006 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -587,17 +587,14 @@ namespace chaiscript class dispatch_error : public std::runtime_error { public: - dispatch_error() noexcept - : std::runtime_error("No matching function to dispatch to") + dispatch_error(const std::vector &t_bvs) + : std::runtime_error("Error with function dispatch"), parameters(t_bvs) { } - dispatch_error(bool is_const) noexcept - : std::runtime_error(std::string("No matching function to dispatch to") + (is_const?", parameter is const":"")) - { - } - virtual ~dispatch_error() noexcept {} + + std::vector parameters; }; } @@ -631,7 +628,7 @@ namespace chaiscript ++begin; } - throw exception::dispatch_error(plist.empty()?false:plist[0].is_const()); + throw exception::dispatch_error(plist); } /** diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index f8af5e16..7b5e5ee0 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -70,10 +70,23 @@ namespace chaiscript std::string filename; std::vector call_stack; + eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname, + const std::vector &t_parameters, const chaiscript::detail::Dispatch_Engine &t_ss) noexcept : + std::runtime_error(format(t_why, t_where, t_fname, t_parameters, t_ss)), + reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname) + {} + + eval_error(const std::string &t_why, + const std::vector &t_parameters, const chaiscript::detail::Dispatch_Engine &t_ss) noexcept : + std::runtime_error(format(t_why, t_parameters, t_ss)), + reason(t_why) + {} + + eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) noexcept : std::runtime_error(format(t_why, t_where, t_fname)), reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname) - { } + {} eval_error(const std::string &t_why) noexcept : std::runtime_error("Error: \"" + t_why + "\" "), @@ -83,13 +96,101 @@ namespace chaiscript virtual ~eval_error() noexcept {} private: + static std::string format_why(const std::string &t_why) + { + return "Error: \"" + t_why + "\""; + } + + static std::string format_parameters(const std::vector &t_parameters, + const chaiscript::detail::Dispatch_Engine &t_ss) + { + std::stringstream ss; + ss << "With parameters: ("; + + if (!t_parameters.empty()) + { + std::string paramstr; + + for (const Boxed_Value &bv: t_parameters) + { + paramstr += (bv.is_const()?"const ":""); + paramstr += t_ss.type_name(bv); + paramstr += ", "; + } + + ss << paramstr.substr(0, paramstr.size() - 2); + } + ss << ")"; + + return ss.str(); + } + + static std::string format_filename(const std::string &t_fname) + { + std::stringstream ss; + + if (t_fname != "__EVAL__") + { + ss << "in '" << t_fname << "' "; + } else { + ss << "during evaluation "; + } + + return ss.str(); + } + + static std::string format_location(const File_Position &t_where) + { + std::stringstream ss; + ss << "at (" << t_where.line << ", " << t_where.column << ")"; + return ss.str(); + } + + static std::string format(const std::string &t_why, const File_Position &t_where, const std::string &t_fname, + const std::vector &t_parameters, const chaiscript::detail::Dispatch_Engine &t_ss) + { + std::stringstream ss; + + ss << format_why(t_why); + ss << " "; + + ss << format_parameters(t_parameters, t_ss); + ss << " "; + + ss << format_filename(t_fname); + ss << " "; + + ss << format_location(t_where); + + return ss.str(); + } + + static std::string format(const std::string &t_why, + const std::vector &t_parameters, const chaiscript::detail::Dispatch_Engine &t_ss) + { + std::stringstream ss; + + ss << format_why(t_why); + ss << " "; + + ss << format_parameters(t_parameters, t_ss); + ss << " "; + + return ss.str(); + } + static std::string format(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) { std::stringstream ss; - ss << "Error: \"" << t_why << "\" " << - (t_fname != "__EVAL__" ? ("in '" + t_fname + "' ") : "during evaluation ") << - "at (" << t_where.line << ", " << - t_where.column + ")"; + + ss << format_why(t_why); + ss << " "; + + ss << format_filename(t_fname); + ss << " "; + + ss << format_location(t_where); + return ss.str(); } }; diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 3c7cd21b..8e2b9634 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -67,8 +67,8 @@ namespace chaiscript return t_ss.call_function(t_oper_string, t_lhs, t_rhs); } } - catch(const exception::dispatch_error &){ - throw exception::eval_error("Can not find appropriate '" + t_oper_string + "'"); + catch(const exception::dispatch_error &e){ + throw exception::eval_error("Can not find appropriate '" + t_oper_string + "' operator.", e.parameters, t_ss); } } }; @@ -204,7 +204,7 @@ namespace chaiscript } catch(const exception::dispatch_error &e){ t_ss.set_stack(prev_stack); - throw exception::eval_error(std::string(e.what()) + " with function '" + this->children[0]->text + "'"); + throw exception::eval_error(std::string(e.what()) + " with function '" + this->children[0]->text + "'", e.parameters, t_ss); } catch(detail::Return_Value &rv) { t_ss.set_stack(prev_stack); @@ -242,7 +242,7 @@ namespace chaiscript return (*boxed_cast(this->children[0]->eval(t_ss)))(plb); } catch(const exception::dispatch_error &e){ - throw exception::eval_error(std::string(e.what()) + " with function '" + this->children[0]->text + "'"); + throw exception::eval_error(std::string(e.what()) + " with function '" + this->children[0]->text + "'", e.parameters, t_ss); } catch(detail::Return_Value &rv) { return rv.retval; @@ -312,19 +312,19 @@ namespace chaiscript try { retval = t_ss.call_function(this->children[1]->text, lhs, retval); } - catch(const exception::dispatch_error &){ - throw exception::eval_error(std::string("Mismatched types in equation") + (lhs.is_const()?", lhs is const.":".")); + catch(const exception::dispatch_error &e){ + throw exception::eval_error("Unable to find appropriate'" + this->children[1]->text + "' operator.", e.parameters, t_ss); } } - catch(const exception::dispatch_error &){ - throw exception::eval_error("Can not clone right hand side of equation"); + catch(const exception::dispatch_error &e){ + throw exception::eval_error("Missing clone or copy constructor for right hand side of equation", e.parameters, t_ss); } } else { try { retval = t_ss.call_function(this->children[1]->text, lhs, retval); - } catch(const exception::dispatch_error &){ - throw exception::eval_error("Can not find appropriate '" + this->children[1]->text + "'"); + } catch(const exception::dispatch_error &e){ + throw exception::eval_error("Unable to find appropriate'" + this->children[1]->text + "' operator.", e.parameters, t_ss); } } } @@ -439,8 +439,8 @@ namespace chaiscript catch(std::out_of_range &) { throw exception::eval_error("Out of bounds exception"); } - catch(const exception::dispatch_error &){ - throw exception::eval_error("Can not find appropriate array lookup '[]' "); + catch(const exception::dispatch_error &e){ + throw exception::eval_error("Can not find appropriate array lookup operator '[]'.", e.parameters, t_ss ); } } @@ -485,7 +485,7 @@ namespace chaiscript } catch(const exception::dispatch_error &e){ t_ss.set_stack(prev_stack); - throw exception::eval_error(std::string(e.what()) + " for function: " + fun_name); + throw exception::eval_error(std::string(e.what()) + " for function: " + fun_name, e.parameters, t_ss); } catch(detail::Return_Value &rv) { t_ss.set_stack(prev_stack); @@ -503,8 +503,8 @@ namespace chaiscript catch(std::out_of_range &) { throw exception::eval_error("Out of bounds exception"); } - catch(const exception::dispatch_error &){ - throw exception::eval_error("Can not find appropriate array lookup '[]' "); + catch(const exception::dispatch_error &e){ + throw exception::eval_error("Can not find appropriate array lookup operator '[]'.", e.parameters, t_ss); } } } @@ -819,8 +819,8 @@ namespace chaiscript } return const_var(retval); } - catch (const exception::dispatch_error &) { - throw exception::eval_error("Can not find appropriate 'Map()'"); + catch (const exception::dispatch_error &e) { + throw exception::eval_error("Can not find appropriate copy constructor or clone while inserting into Map.", e.parameters, t_ss); } } @@ -896,8 +896,8 @@ namespace chaiscript } else { return t_ss.call_function(this->children[0]->text, bv); } - } catch (const exception::dispatch_error &) { - throw exception::eval_error("Error with prefix operator evaluation: " + children[0]->text); + } catch (const exception::dispatch_error &e) { + throw exception::eval_error("Error with prefix operator evaluation: '" + children[0]->text + "'", e.parameters, t_ss); } } @@ -938,8 +938,8 @@ namespace chaiscript this->children[0]->children[0]->children[0]->eval(t_ss), this->children[0]->children[0]->children[1]->eval(t_ss)); } - catch (const exception::dispatch_error &) { - throw exception::eval_error("Unable to generate range vector"); + catch (const exception::dispatch_error &e) { + throw exception::eval_error("Unable to generate range vector, while calling 'generate_range'", e.parameters, t_ss); } } diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index c176f6e6..32aded34 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -1587,7 +1587,7 @@ namespace chaiscript throw exception::eval_error("Incomplete expression", File_Position(m_line, m_col), *m_filename); } if (!Char(')')) { - throw exception::eval_error("Missing closing parenthesis", File_Position(m_line, m_col), *m_filename); + throw exception::eval_error("Missing closing parenthesis ')'", File_Position(m_line, m_col), *m_filename); } } return retval; @@ -1605,7 +1605,7 @@ namespace chaiscript retval = true; Container_Arg_List(); if (!Char('}')) { - throw exception::eval_error("Missing closing square bracket", File_Position(m_line, m_col), *m_filename); + throw exception::eval_error("Missing closing brace '}' in container initializer", File_Position(m_line, m_col), *m_filename); } if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) { if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Value_Range) { From db0e342a9632fa0e82be1f8002e1e8ac565d0fcd Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 25 Sep 2011 18:34:02 -0600 Subject: [PATCH 040/108] Remove little used Param_List_Builder --- .../dispatchkit/proxy_functions.hpp | 31 ------------------- .../chaiscript/language/chaiscript_eval.hpp | 20 ++++++------ 2 files changed, 10 insertions(+), 41 deletions(-) diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index e04f0006..c14e1e79 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -28,37 +28,6 @@ namespace chaiscript namespace dispatch { - /** - * Helper for building a list of parameters for calling a Proxy_Function - * it does automatic conversion to Boxed_Value types via operator<< - * - * example usage: - * Boxed_Value retval = dispatch(dispatchengine.get_function("+"), - * chaiscript::Param_List_Builder() << 5 << 6); - */ - struct Param_List_Builder - { - Param_List_Builder &operator<<(const Boxed_Value &so) - { - objects.push_back(so); - return *this; - } - - template - Param_List_Builder &operator<<(T t) - { - objects.push_back(Boxed_Value(t)); - return *this; - } - - operator const std::vector &() const - { - return objects; - } - - std::vector objects; - }; - /** * Pure virtual base class for all Proxy_Function implementations * Proxy_Functions are a type erasure of type safe C++ diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 8e2b9634..4337e694 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -182,11 +182,11 @@ namespace chaiscript AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Fun_Call_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ - dispatch::Param_List_Builder plb; + std::vector params; if ((this->children.size() > 1) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) { for (size_t i = 0; i < this->children[1]->children.size(); ++i) { - plb << this->children[1]->children[i]->eval(t_ss); + params.push_back(this->children[1]->children[i]->eval(t_ss)); } } @@ -198,7 +198,7 @@ namespace chaiscript try { t_ss.set_stack(new_stack); - const Boxed_Value &retval = (*boxed_cast(fn))(plb); + const Boxed_Value &retval = (*boxed_cast(fn))(params); t_ss.set_stack(prev_stack); return retval; } @@ -230,16 +230,16 @@ namespace chaiscript AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } virtual ~Inplace_Fun_Call_AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss){ - dispatch::Param_List_Builder plb; + std::vector params; if ((this->children.size() > 1) && (this->children[1]->identifier == AST_Node_Type::Arg_List)) { for (size_t i = 0; i < this->children[1]->children.size(); ++i) { - plb << this->children[1]->children[i]->eval(t_ss); + params.push_back(this->children[1]->children[i]->eval(t_ss)); } } try { - return (*boxed_cast(this->children[0]->eval(t_ss)))(plb); + return (*boxed_cast(this->children[0]->eval(t_ss)))(params); } catch(const exception::dispatch_error &e){ throw exception::eval_error(std::string(e.what()) + " with function '" + this->children[0]->text + "'", e.parameters, t_ss); @@ -458,12 +458,12 @@ namespace chaiscript if (this->children.size() > 1) { for (size_t i = 2; i < this->children.size(); i+=2) { - dispatch::Param_List_Builder plb; - plb << retval; + std::vector params; + params.push_back(retval); if (this->children[i]->children.size() > 1) { for (size_t j = 0; j < this->children[i]->children[1]->children.size(); ++j) { - plb << this->children[i]->children[1]->children[j]->eval(t_ss); + params.push_back(this->children[i]->children[1]->children[j]->eval(t_ss)); } } @@ -480,7 +480,7 @@ namespace chaiscript try { t_ss.set_stack(new_stack); - retval = t_ss.call_function(fun_name, plb); + retval = t_ss.call_function(fun_name, params); t_ss.set_stack(prev_stack); } catch(const exception::dispatch_error &e){ From 488f2ea39371f2036b6ea6a1d742f940a6410d84 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 26 Sep 2011 07:14:24 -0600 Subject: [PATCH 041/108] C++11 cleanups --- include/chaiscript/dispatchkit/bootstrap.hpp | 12 ++++------ .../chaiscript/dispatchkit/dynamic_object.hpp | 4 +--- .../dispatchkit/proxy_functions.hpp | 24 +++++++++---------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index f4067806..f557aab0 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -348,17 +348,13 @@ namespace chaiscript static std::vector do_return_boxed_value_vector(FunctionType f, const dispatch::Proxy_Function_Base *b) { - typedef decltype(std::mem_fn(f)) MemFunType; - typedef typename MemFunType::result_type Vector; - - Vector v = (b->*f)(); + auto v = (b->*f)(); std::vector vbv; - for (typename Vector::const_iterator itr = v.begin(); - itr != v.end(); - ++itr) + + for (const auto &o: v) { - vbv.push_back(const_var(*itr)); + vbv.push_back(const_var(o)); } return vbv; diff --git a/include/chaiscript/dispatchkit/dynamic_object.hpp b/include/chaiscript/dispatchkit/dynamic_object.hpp index e94e893f..1126f28e 100644 --- a/include/chaiscript/dispatchkit/dynamic_object.hpp +++ b/include/chaiscript/dispatchkit/dynamic_object.hpp @@ -111,9 +111,7 @@ namespace chaiscript virtual std::vector get_contained_functions() const { - std::vector fs; - fs.push_back(m_func); - return fs; + return {m_func}; } diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index c14e1e79..e3ab3dc1 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -51,7 +51,7 @@ namespace chaiscript /// if the function is variadic or takes no arguments (arity of 0 or -1), the returned /// value containes exactly 1 Type_Info object: the return type /// \returns the types of all parameters. - std::vector get_param_types() const { return m_types; } + const std::vector &get_param_types() const { return m_types; } virtual bool operator==(const Proxy_Function_Base &) const = 0; virtual bool call_match(const std::vector &vals) const = 0; @@ -262,7 +262,7 @@ namespace chaiscript // For the return type types.push_back(chaiscript::detail::Get_Type_Info::get()); - if (arity >= 0) + if (arity > 0) { for (int i = 0; i < arity; ++i) { @@ -378,6 +378,7 @@ namespace chaiscript const std::vector &t_args) { assert(t_f->get_arity() < 0 || t_f->get_arity() == static_cast(t_args.size())); + if (t_f->get_arity() < 0) { return std::vector(); } std::vector types = t_f->get_param_types(); @@ -419,8 +420,8 @@ namespace chaiscript Proxy_Function_Impl(const std::function &f) : Proxy_Function_Base(detail::build_param_type_list(static_cast(0))), m_f(f), m_dummy_func(0) - { - } + { + } virtual ~Proxy_Function_Impl() {} @@ -430,13 +431,11 @@ namespace chaiscript return pimpl != 0; } - virtual int get_arity() const { return static_cast(m_types.size()) - 1; } - virtual bool call_match(const std::vector &vals) const { if (int(vals.size()) != get_arity()) @@ -478,8 +477,8 @@ namespace chaiscript Attribute_Access(T Class::* t_attr) : Proxy_Function_Base(param_types()), m_attr(t_attr) - { - } + { + } virtual ~Attribute_Access() {} @@ -487,6 +486,7 @@ namespace chaiscript { const Attribute_Access * aa = dynamic_cast *>(&t_func); + if (aa) { return m_attr == aa->m_attr; } else { @@ -537,11 +537,9 @@ namespace chaiscript private: static std::vector param_types() { - std::vector v; - v.push_back(user_type()); - v.push_back(user_type()); - return v; + return {user_type(), user_type()}; } + T Class::* m_attr; }; } @@ -576,7 +574,7 @@ namespace chaiscript * function is found or throw dispatch_error if no matching function is found */ template - Boxed_Value dispatch(InItr begin, InItr end, + Boxed_Value dispatch(InItr begin, const InItr &end, const std::vector &plist) { while (begin != end) From b27aa50d6a8ad0d1cfa82decd2b8ee4062afc2af Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 26 Sep 2011 07:51:32 -0600 Subject: [PATCH 042/108] Minor cleanups in cv qualification removal --- include/chaiscript/dispatchkit/boxed_cast.hpp | 1 + include/chaiscript/dispatchkit/type_info.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index b75e06f1..c4d820f5 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -68,6 +68,7 @@ namespace chaiscript return detail::Cast_Helper::cast(bv); } catch (const chaiscript::detail::exception::bad_any_cast &) { + #ifdef CHAISCRIPT_MSVC //Thank you MSVC, yes we know that a constant value is being used in the if // statment in THIS VERSION of the template instantiation diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index 87eddea0..3c2fb20d 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -20,7 +20,7 @@ namespace chaiscript template struct Bare_Type { - typedef typename std::remove_const::type>::type>::type type; + typedef typename std::remove_cv::type>::type>::type type; }; } From bc75df4d582ba64e4809ea082337a3a0a5de9684 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 1 Oct 2011 10:19:45 -0600 Subject: [PATCH 043/108] Fixed parsing of block statements vs initializer expressions. --- include/chaiscript/language/chaiscript_parser.hpp | 12 ++++++------ include/chaiscript/language/chaiscript_prelude.hpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index c176f6e6..5b165c56 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -1605,7 +1605,7 @@ namespace chaiscript retval = true; Container_Arg_List(); if (!Char('}')) { - throw exception::eval_error("Missing closing square bracket", File_Position(m_line, m_col), *m_filename); + throw exception::eval_error("Missing closing curly bracket", File_Position(m_line, m_col), *m_filename); } if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) { if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Value_Range) { @@ -1977,6 +1977,11 @@ namespace chaiscript retval = true; saw_eol = false; } + else if (Block()) { + has_more = true; + retval = true; + saw_eol = true; + } else if (Equation()) { if (!saw_eol) { throw exception::eval_error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename); @@ -1990,11 +1995,6 @@ namespace chaiscript retval = true; saw_eol = true; } - else if (Block()) { - has_more = true; - retval = true; - saw_eol = true; - } else { has_more = false; } diff --git a/include/chaiscript/language/chaiscript_prelude.hpp b/include/chaiscript/language/chaiscript_prelude.hpp index b96aba41..9cdecaf5 100644 --- a/include/chaiscript/language/chaiscript_prelude.hpp +++ b/include/chaiscript/language/chaiscript_prelude.hpp @@ -259,7 +259,7 @@ def generate_range(x, y) { \n\ }\n\ # Returns a new Vector with the first value to the second value as its elements\n\ def collate(x, y) { \n\ - {x, y}; \n\ + return {x, y}; \n\ } \n\ def zip_with(f, x, y, inserter) : call_exists(range, x) && call_exists(range, y) { \n\ auto r_x = range(x); \n\ From 5dc0931ca29b3c56200317b14162c5fd11855a62 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 1 Oct 2011 11:03:03 -0600 Subject: [PATCH 044/108] Update is_prime analysis for new syntax --- contrib/codeanalysis/is_prime.chai | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/contrib/codeanalysis/is_prime.chai b/contrib/codeanalysis/is_prime.chai index d34bad25..9e5fe38b 100644 --- a/contrib/codeanalysis/is_prime.chai +++ b/contrib/codeanalysis/is_prime.chai @@ -1,6 +1,6 @@ def isprime(n) { - for (var i = 2; i < n; ++i) + for (auto i = 2; i < n; ++i) { if (n % i == 0) {return false} } @@ -11,8 +11,8 @@ def isprime(n) def primes(n) { - var count = 0 - for (var i = 2; i <= n; ++i) + auto count = 0 + for (auto i = 2; i <= n; ++i) { if (isprime(i)) {++count} } @@ -21,5 +21,6 @@ def primes(n) } -var N = 5000 +auto N = 5000 + print("primes: " + primes(N).to_string()) From 9a9d4e1ae091ac602c86d91e858acf9b15f83d27 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 1 Oct 2011 11:15:56 -0600 Subject: [PATCH 045/108] Remove map_literal_access test, it's invalid as there is no const [] on maps --- unittests/map_literal_access.chai | 1 - 1 file changed, 1 deletion(-) delete mode 100644 unittests/map_literal_access.chai diff --git a/unittests/map_literal_access.chai b/unittests/map_literal_access.chai deleted file mode 100644 index d4a26236..00000000 --- a/unittests/map_literal_access.chai +++ /dev/null @@ -1 +0,0 @@ -assert_equal(1, {"bob":1,"fred":2}["bob"]) From 136b877afa615b3b9e4363d31b38ed09d52e133c Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 27 Dec 2011 21:37:00 -0700 Subject: [PATCH 046/108] Reduce cost of including chaiscript.hpp - ChaiScript no longer includes or automatically instantiates std lib - ChaiScript constructor now requires an std lib instance in the form of a ModulePtr object - This new layout facilitates better usage of compilation firewalls and factories for reducing the overall impact of ChaiScript on a project --- include/chaiscript/chaiscript.hpp | 2 - include/chaiscript/dispatchkit/bootstrap.hpp | 2 +- .../chaiscript/dispatchkit/bootstrap_stl.hpp | 1 + .../chaiscript/dispatchkit/boxed_value.hpp | 11 +++-- .../chaiscript/language/chaiscript_common.hpp | 1 + .../chaiscript/language/chaiscript_engine.hpp | 16 +++--- .../chaiscript/language/chaiscript_eval.hpp | 1 + samples/example.cpp | 3 +- samples/memory_leak_test.cpp | 49 ++++++++++--------- src/main.cpp | 3 +- src/reflection.cpp | 2 + src/stl_extra.cpp | 1 + unittests/dynamic_object_test.cpp | 5 +- unittests/eval_catch_exception_test.cpp | 11 +++-- unittests/function_ordering_test.cpp | 3 +- unittests/functor_cast_test.cpp | 3 +- unittests/functor_creation_test.cpp | 4 +- unittests/multifile_test_chai.cpp | 4 +- unittests/object_lifetime_test.cpp | 3 +- unittests/utility_test.cpp | 3 +- 20 files changed, 72 insertions(+), 56 deletions(-) diff --git a/include/chaiscript/chaiscript.hpp b/include/chaiscript/chaiscript.hpp index 33cf6db0..8644f8f1 100644 --- a/include/chaiscript/chaiscript.hpp +++ b/include/chaiscript/chaiscript.hpp @@ -748,8 +748,6 @@ #include "chaiscript_defines.hpp" #include "dispatchkit/dispatchkit.hpp" -#include "dispatchkit/bootstrap.hpp" -#include "dispatchkit/bootstrap_stl.hpp" #include "dispatchkit/function_call.hpp" #include "dispatchkit/dynamic_object.hpp" #include "dispatchkit/boxed_number.hpp" diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index f557aab0..5e5bdbed 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -478,7 +478,7 @@ namespace chaiscript m->add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(std::bind(&call_exists, std::placeholders::_1))), "call_exists"); - m->add(fun(&type_match), "type_match"); + m->add(fun(&Boxed_Value::type_match), "type_match"); return m; } diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index f2f7e515..1316970d 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -17,6 +17,7 @@ #define CHAISCRIPT_BOOTSTRAP_STL_HPP_ #include "dispatchkit.hpp" +#include "bootstrap.hpp" #include "register_function.hpp" namespace chaiscript diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index c7b6ca71..a987e2c1 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -263,6 +263,12 @@ namespace chaiscript return m_data->m_const_data_ptr; } + /// \returns true if the two Boxed_Values share the same internal type + static bool type_match(Boxed_Value l, Boxed_Value r) + { + return l.get_type_info() == r.get_type_info(); + } + private: std::shared_ptr m_data; }; @@ -361,11 +367,6 @@ namespace chaiscript - /// \returns true if the two Boxed_Values share the same internal type - static bool type_match(Boxed_Value l, Boxed_Value r) - { - return l.get_type_info() == r.get_type_info(); - } } #endif diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 7b5e5ee0..08786034 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -7,6 +7,7 @@ #ifndef CHAISCRIPT_COMMON_HPP_ #define CHAISCRIPT_COMMON_HPP_ +#include #include "../dispatchkit/dispatchkit.hpp" namespace chaiscript diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 1b7cda1e..210661bf 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -324,8 +324,7 @@ namespace chaiscript /** * Builds all the requirements for ChaiScript, including its evaluator and a run of its prelude. */ - void build_eval_system() { - using namespace bootstrap; + void build_eval_system(const ModulePtr &t_lib) { m_engine.add_reserved_word("def"); m_engine.add_reserved_word("fun"); m_engine.add_reserved_word("while"); @@ -342,7 +341,7 @@ namespace chaiscript m_engine.add_reserved_word("false"); m_engine.add_reserved_word("_"); - add(Bootstrap::bootstrap()); + add(t_lib); m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::dump_system, std::ref(m_engine)), "dump_system"); m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::dump_object, std::ref(m_engine)), "dump_object"); @@ -359,11 +358,6 @@ namespace chaiscript m_engine.add(fun(static_cast(&ChaiScript::load_module), this), "load_module"); m_engine.add(fun(static_cast(&ChaiScript::load_module), this), "load_module"); - add(standard_library::vector_type >("Vector")); - add(standard_library::string_type("string")); - add(standard_library::map_type >("Map")); - add(standard_library::pair_type >("Pair")); - m_engine.add(fun(&ChaiScript::use, this), "use"); m_engine.add(fun(&ChaiScript::internal_eval, this), "eval"); m_engine.add(fun(&ChaiScript::internal_eval_ast, this), "eval"); @@ -398,9 +392,11 @@ namespace chaiscript public: /// \brief Constructor for ChaiScript + /// \param[in] t_lib Standard library to apply to this ChaiScript instance /// \param[in] t_modulepaths Vector of paths to search when attempting to load a binary module /// \param[in] t_usepaths Vector of paths to search when attempting to "use" an included ChaiScript file - ChaiScript(const std::vector &t_modulepaths = std::vector(), + ChaiScript(const ModulePtr &t_lib, + const std::vector &t_modulepaths = std::vector(), const std::vector &t_usepaths = std::vector()) : m_modulepaths(t_modulepaths), m_usepaths(t_usepaths) { @@ -414,7 +410,7 @@ namespace chaiscript m_usepaths.push_back(""); } - build_eval_system(); + build_eval_system(t_lib); } /// \brief Adds a constant object that is available in all contexts and to all threads diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 4337e694..684a29fb 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -10,6 +10,7 @@ #include #include "chaiscript_common.hpp" +#include "../dispatchkit/register_function.hpp" namespace chaiscript { diff --git a/samples/example.cpp b/samples/example.cpp index cd3ad9bd..9319d187 100644 --- a/samples/example.cpp +++ b/samples/example.cpp @@ -7,6 +7,7 @@ #include #include +#include #include void log(const std::string &msg) @@ -66,7 +67,7 @@ void take_shared_ptr(const std::shared_ptr &p) int main(int /*argc*/, char * /*argv*/[]) { using namespace chaiscript; - ChaiScript chai; + ChaiScript chai(Std_Lib::library()); //Create a new system object and share it with the chaiscript engine System system; diff --git a/samples/memory_leak_test.cpp b/samples/memory_leak_test.cpp index bbd8a5fe..7129da21 100644 --- a/samples/memory_leak_test.cpp +++ b/samples/memory_leak_test.cpp @@ -1,13 +1,14 @@ #include -#include "chaiscript/chaiscript.hpp" +#include +#include + #ifdef READLINE_AVAILABLE #include #include #endif -using namespace chaiscript; std::string get_next_command() { #ifdef READLINE_AVAILABLE @@ -30,30 +31,32 @@ void fuction(void) class test { - ChaiScript chai; - ChaiScript::State backupState; + chaiscript::ChaiScript chai; + chaiscript::ChaiScript::State backupState; + public: - test() - { - backupState = chai.get_state(); - } - ~test(){} - - void ResetState() - { - chai.set_state(backupState); - chai.add(fun(&fuction),"Whatever()"); - } - - void RunFile(std::string sFile) - { - try { - chaiscript::Boxed_Value val = chai.eval_file(sFile); + test() + : chai(chaiscript::Std_Lib::library()) + { + backupState = chai.get_state(); } - catch (std::exception &e) { - std::cout << e.what() << std::endl; + ~test(){} + + void ResetState() + { + chai.set_state(backupState); + chai.add(chaiscript::fun(&fuction),"Whatever()"); + } + + void RunFile(std::string sFile) + { + try { + chaiscript::Boxed_Value val = chai.eval_file(sFile); + } + catch (std::exception &e) { + std::cout << e.what() << std::endl; + } } - } }; diff --git a/src/main.cpp b/src/main.cpp index 240418cd..096f857f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,7 @@ #define _CRT_SECURE_NO_WARNINGS #include +#include #ifdef READLINE_AVAILABLE #include @@ -176,7 +177,7 @@ int main(int argc, char *argv[]) modulepaths.push_back(modulepath); } - chaiscript::ChaiScript chai(modulepaths,usepaths); + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library(), modulepaths,usepaths); chai.add(chaiscript::fun(&myexit), "exit"); chai.add(chaiscript::fun(&myexit), "quit"); diff --git a/src/reflection.cpp b/src/reflection.cpp index 2bff5284..80ee906b 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -1,5 +1,7 @@ #include +#include +#include #include #include diff --git a/src/stl_extra.cpp b/src/stl_extra.cpp index 67e6c27a..98683661 100644 --- a/src/stl_extra.cpp +++ b/src/stl_extra.cpp @@ -1,5 +1,6 @@ #include +#include #include #include diff --git a/unittests/dynamic_object_test.cpp b/unittests/dynamic_object_test.cpp index ca0ffaec..60c1e5e9 100644 --- a/unittests/dynamic_object_test.cpp +++ b/unittests/dynamic_object_test.cpp @@ -1,3 +1,5 @@ + +#include #include template @@ -14,8 +16,7 @@ void assert_equal(const LHS &lhs, const RHS &rhs) int main() { - - chaiscript::ChaiScript chai; + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); chai("attr bob::z; def bob::bob() { this.z = 10 }; auto x = bob()"); diff --git a/unittests/eval_catch_exception_test.cpp b/unittests/eval_catch_exception_test.cpp index c599c091..b92021ff 100644 --- a/unittests/eval_catch_exception_test.cpp +++ b/unittests/eval_catch_exception_test.cpp @@ -1,10 +1,11 @@ // Tests to make sure that the order in which function dispatches occur is correct #include +#include int test_generic() { - chaiscript::ChaiScript chai; + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); try { chai.eval("throw(runtime_error(\"error\"));"); @@ -22,7 +23,7 @@ int test_generic() int test_1() { - chaiscript::ChaiScript chai; + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); try { chai.eval("throw(1)", chaiscript::exception_specification()); @@ -39,7 +40,7 @@ int test_1() int test_2() { - chaiscript::ChaiScript chai; + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); try { chai.eval("throw(1.0)", chaiscript::exception_specification()); @@ -56,7 +57,7 @@ int test_2() int test_5() { - chaiscript::ChaiScript chai; + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); try { chai.eval("throw(runtime_error(\"error\"))", chaiscript::exception_specification()); @@ -82,7 +83,7 @@ int test_5() int test_unhandled() { - chaiscript::ChaiScript chai; + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); try { chai.eval("throw(\"error\")", chaiscript::exception_specification()); diff --git a/unittests/function_ordering_test.cpp b/unittests/function_ordering_test.cpp index e80f4d32..92907b03 100644 --- a/unittests/function_ordering_test.cpp +++ b/unittests/function_ordering_test.cpp @@ -1,6 +1,7 @@ // Tests to make sure that the order in which function dispatches occur is correct #include +#include int test_one(const int &) { @@ -14,7 +15,7 @@ int test_two(int &) int main() { - chaiscript::ChaiScript chai; + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); chai.eval("def test_fun(x) { return 3; }"); chai.eval("def test_fun(x) : x == \"hi\" { return 4; }"); chai.eval("def test_fun(x) { return 5; }"); diff --git a/unittests/functor_cast_test.cpp b/unittests/functor_cast_test.cpp index 7c76ca20..33250c90 100644 --- a/unittests/functor_cast_test.cpp +++ b/unittests/functor_cast_test.cpp @@ -1,4 +1,5 @@ #include +#include double test_call(const std::function &f, int val) { @@ -8,7 +9,7 @@ double test_call(const std::function &f, int val) int main() { - chaiscript::ChaiScript chai; + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); chai.add(chaiscript::fun(&test_call), "test_call"); diff --git a/unittests/functor_creation_test.cpp b/unittests/functor_creation_test.cpp index 6a78feef..d5289cbc 100644 --- a/unittests/functor_creation_test.cpp +++ b/unittests/functor_creation_test.cpp @@ -1,9 +1,11 @@ #include +#include + int main() { - chaiscript::ChaiScript chai; + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); chai.eval("def func() { print(\"Hello World\"); } "); diff --git a/unittests/multifile_test_chai.cpp b/unittests/multifile_test_chai.cpp index 154062c9..ac288ffc 100644 --- a/unittests/multifile_test_chai.cpp +++ b/unittests/multifile_test_chai.cpp @@ -1,7 +1,9 @@ #include "multifile_test_chai.hpp" +#include + Multi_Test_Chai::Multi_Test_Chai() - : m_chai(new chaiscript::ChaiScript()) + : m_chai(new chaiscript::ChaiScript(chaiscript::Std_Lib::library())) { } diff --git a/unittests/object_lifetime_test.cpp b/unittests/object_lifetime_test.cpp index 07f0c139..80bc52b1 100644 --- a/unittests/object_lifetime_test.cpp +++ b/unittests/object_lifetime_test.cpp @@ -1,4 +1,5 @@ #include +#include class Test { @@ -36,7 +37,7 @@ int main() { {chaiscript::fun(&Test::count), "count"} } ); - chaiscript::ChaiScript chai; + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); chai.add(m); chai.add(chaiscript::fun(&Test::count), "count"); diff --git a/unittests/utility_test.cpp b/unittests/utility_test.cpp index 9dbb52af..0145265a 100644 --- a/unittests/utility_test.cpp +++ b/unittests/utility_test.cpp @@ -1,3 +1,4 @@ +#include #include class Test @@ -33,7 +34,7 @@ int main() - chaiscript::ChaiScript chai; + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library());; chai.add(m); if (chai.eval("auto t = Test(); t.function2(); ") == "Function2" && chai.eval("auto t = Test(); t.functionOverload(1); ") == "int" From dc6998259ee9fe4fe54fe85ba605c5f4020261cd Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 30 Jan 2012 09:05:21 -0700 Subject: [PATCH 047/108] Add missing chaiscript_stdlib.hpp file --- include/chaiscript/chaiscript_stdlib.hpp | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 include/chaiscript/chaiscript_stdlib.hpp diff --git a/include/chaiscript/chaiscript_stdlib.hpp b/include/chaiscript/chaiscript_stdlib.hpp new file mode 100644 index 00000000..18cb5695 --- /dev/null +++ b/include/chaiscript/chaiscript_stdlib.hpp @@ -0,0 +1,43 @@ +// This file is distributed under the BSD License. +// See "license.txt" for details. +// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// and Jason Turner (jason@emptycrate.com) +// http://www.chaiscript.com + +#ifndef CHAISCRIPT_STDLIB_HPP_ +#define CHAISCRIPT_STDLIB_HPP_ + +#include "dispatchkit/bootstrap.hpp" +#include "dispatchkit/bootstrap_stl.hpp" + +/// \file +/// +/// This file generates the standard library that normal ChaiScript usage requires. + +namespace chaiscript +{ + class Std_Lib + { + public: + + static ModulePtr library() + { + using namespace bootstrap; + + ModulePtr lib = Bootstrap::bootstrap(); + + lib->add(standard_library::vector_type >("Vector")); + lib->add(standard_library::string_type("string")); + lib->add(standard_library::map_type >("Map")); + lib->add(standard_library::pair_type >("Pair")); + + return lib; + } + + }; +} + + + +#endif + From 179a674b00e9b1b7014b831a77239f24e1fbcf77 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 30 Jan 2012 09:16:20 -0700 Subject: [PATCH 048/108] Fix fix for duplication attribute name errors --- unittests/object_attr_same_name.chai | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittests/object_attr_same_name.chai b/unittests/object_attr_same_name.chai index fa20bac4..11315675 100644 --- a/unittests/object_attr_same_name.chai +++ b/unittests/object_attr_same_name.chai @@ -4,6 +4,6 @@ def bob::bob() { this.z = 10 } attr bob2::z def bob2::bob2() { this.z = 12 } -var b = bob(); -var b2 = bob2(); +auto b = bob(); +auto b2 = bob2(); From 927619bf471b1a8edaecacfff9d8b73829ce37bd Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 14 May 2012 08:56:33 -0600 Subject: [PATCH 049/108] Switch to using make_sharec --- .../chaiscript/dispatchkit/boxed_value.hpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index a987e2c1..660db0c2 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -71,12 +71,12 @@ namespace chaiscript { static std::shared_ptr get(Boxed_Value::Void_Type) { - return std::shared_ptr (new Data( + return std::make_shared( detail::Get_Type_Info::get(), chaiscript::detail::Any(), false, - 0) - ); + nullptr) + ; } template @@ -88,11 +88,11 @@ namespace chaiscript template static std::shared_ptr get(const std::shared_ptr &obj) { - return std::shared_ptr(new Data( + return std::make_shared( detail::Get_Type_Info::get(), chaiscript::detail::Any(obj), false, - obj.get()) + obj.get() ); } @@ -105,33 +105,33 @@ namespace chaiscript template static std::shared_ptr get(std::reference_wrapper obj) { - return std::shared_ptr(new Data( + return std::make_shared( detail::Get_Type_Info::get(), chaiscript::detail::Any(obj), true, - &obj.get()) + &obj.get() ); } template static std::shared_ptr get(const T& t) { - std::shared_ptr p(new T(t)); - return std::shared_ptr(new Data( + auto p = std::make_shared(t); + return std::make_shared( detail::Get_Type_Info::get(), chaiscript::detail::Any(p), false, - p.get()) + p.get() ); } static std::shared_ptr get() { - return std::shared_ptr (new Data( + return std::make_shared( Type_Info(), chaiscript::detail::Any(), false, - 0) + nullptr ); } From 98d2eadde2874139aec0bf95e8fcc2d525302729 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 14 May 2012 10:15:38 -0600 Subject: [PATCH 050/108] Explicitly default the copy assignment operator for clang's benefit --- include/chaiscript/dispatchkit/dispatchkit.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index f6c68e2b..0fa0439f 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -352,6 +352,8 @@ namespace chaiscript std::map m_global_objects; Type_Name_Map m_types; std::set m_reserved_words; + + State &operator=(const State &) = default; }; Dispatch_Engine() From 48ecb3e2b4bb4e4d28ded17e5082fda00863af7c Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 14 May 2012 17:45:30 -0600 Subject: [PATCH 051/108] Some performance improvements by using perfect argument forwarding --- include/chaiscript/dispatchkit/function_call_detail.hpp | 2 +- include/chaiscript/dispatchkit/proxy_functions_detail.hpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index 15ffaf34..e41e85cd 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -59,7 +59,7 @@ namespace chaiscript Ret operator()(Param...param) { return Function_Caller_Ret::call(m_funcs, { -(std::is_reference::value&&!(std::is_same::type>::type>::value))?Boxed_Value(std::ref(param)):Boxed_Value(param)... +(std::is_reference::value&&!(std::is_same::type>::type>::value))?Boxed_Value(std::ref(param)):Boxed_Value(param)... } ); diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index f8901e39..579074b6 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -105,9 +105,9 @@ namespace chaiscript template static Ret do_call(const std::function &f, - const std::vector ¶ms, InnerParams ... innerparams) + const std::vector ¶ms, InnerParams &&... innerparams) { - return Call_Func::do_call(f, params, innerparams..., params[sizeof...(Params) - count]); + return Call_Func::do_call(f, params, std::forward(innerparams)..., params[sizeof...(Params) - count]); } }; @@ -116,9 +116,9 @@ namespace chaiscript { template static Ret do_call(const std::function &f, - const std::vector &, InnerParams ... innerparams) + const std::vector &, InnerParams &&... innerparams) { - return f(boxed_cast(innerparams)...); + return f(boxed_cast(std::forward(innerparams))...); } }; From 974c903d1cdd206562d247a44a45d815c9603fc8 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 15 May 2012 13:25:13 -0600 Subject: [PATCH 052/108] Get compiling with broken clang++ / libc++ implementation libc++ will not let you get a pointer to a string member --- .../chaiscript/dispatchkit/bootstrap_stl.hpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 1316970d..03c56f13 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -256,9 +256,9 @@ namespace chaiscript template ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { - m->add(fun(std::function(std::mem_fn(&ContainerType::size))), "size"); - m->add(fun(&ContainerType::empty), "empty"); - m->add(fun(&ContainerType::clear), "clear"); + m->add(fun( std::function( [](const ContainerType *a) { return a->size(); } ) ), "size"); + m->add(fun( std::function( [](const ContainerType *a) { return a->empty(); } ) ), "empty"); + m->add(fun( std::function( [](ContainerType *a) { a->clear(); } ) ), "clear"); return m; } @@ -516,15 +516,15 @@ namespace chaiscript typedef std::function find_func; - m->add(fun(find_func(std::mem_fn(static_cast(&String::find)))), "find"); - m->add(fun(find_func(std::mem_fn(static_cast(&String::rfind)))), "rfind"); - m->add(fun(find_func(std::mem_fn(static_cast(&String::find_first_of)))), "find_first_of"); - m->add(fun(find_func(std::mem_fn(static_cast(&String::find_last_of)))), "find_last_of"); - m->add(fun(find_func(std::mem_fn(static_cast(&String::find_first_not_of)))), "find_first_not_of"); - m->add(fun(find_func(std::mem_fn(static_cast(&String::find_last_not_of)))), "find_last_not_of"); + m->add(fun( std::function( [](const String *s, const String &f, int pos) { return s->find(f, pos); } ) ), "find"); + m->add(fun( std::function( [](const String *s, const String &f, int pos) { return s->rfind(f, pos); } ) ), "rfind"); + m->add(fun( std::function( [](const String *s, const String &f, int pos) { return s->find_first_of(f, pos); } ) ), "find_first_of"); + m->add(fun( std::function( [](const String *s, const String &f, int pos) { return s->find_last_of(f, pos); } ) ), "find_last_of"); + m->add(fun( std::function( [](const String *s, const String &f, int pos) { return s->find_last_not_of(f, pos); } ) ), "find_last_not_of"); + m->add(fun( std::function( [](const String *s, const String &f, int pos) { return s->find_first_not_of(f, pos); } ) ), "find_first_not_of"); - m->add(fun(&String::c_str), "c_str"); - m->add(fun(&String::data), "data"); + m->add(fun( std::function( [](const String *s) { return s->c_str(); } ) ), "c_str"); + m->add(fun( std::function( [](const String *s) { return s->data(); } ) ), "data"); return m; From 8e24eef26596aaf1bf9044dd878a106f7f5cc5f3 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 15 May 2012 13:56:59 -0600 Subject: [PATCH 053/108] Tweaks to clang support and fix for clang/module support --- include/chaiscript/dispatchkit/bootstrap_stl.hpp | 14 ++++++-------- include/chaiscript/language/chaiscript_engine.hpp | 4 ++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 03c56f13..9bfc66a7 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -512,16 +512,14 @@ namespace chaiscript } m->add(fun(&String::push_back), push_back_name); - typedef typename String::size_type (String::*find_func_ptr)(const String &, typename String::size_type) const; - typedef std::function find_func; - m->add(fun( std::function( [](const String *s, const String &f, int pos) { return s->find(f, pos); } ) ), "find"); - m->add(fun( std::function( [](const String *s, const String &f, int pos) { return s->rfind(f, pos); } ) ), "rfind"); - m->add(fun( std::function( [](const String *s, const String &f, int pos) { return s->find_first_of(f, pos); } ) ), "find_first_of"); - m->add(fun( std::function( [](const String *s, const String &f, int pos) { return s->find_last_of(f, pos); } ) ), "find_last_of"); - m->add(fun( std::function( [](const String *s, const String &f, int pos) { return s->find_last_not_of(f, pos); } ) ), "find_last_not_of"); - m->add(fun( std::function( [](const String *s, const String &f, int pos) { return s->find_first_not_of(f, pos); } ) ), "find_first_not_of"); + m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find(f, pos); } )), "find"); + m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->rfind(f, pos); } ) ), "rfind"); + m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_first_of(f, pos); } ) ), "find_first_of"); + m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_last_of(f, pos); } ) ), "find_last_of"); + m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_last_not_of(f, pos); } ) ), "find_last_not_of"); + m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_first_not_of(f, pos); } ) ), "find_first_not_of"); m->add(fun( std::function( [](const String *s) { return s->c_str(); } ) ), "c_str"); m->add(fun( std::function( [](const String *s) { return s->data(); } ) ), "data"); diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 8d0cd0ef..26faa16f 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -13,6 +13,10 @@ #include "../chaiscript_defines.hpp" #include "chaiscript_common.hpp" +#if defined(__linux__) || defined(__unix__) || defined(__APPLE__) +#include +#endif + #ifdef _POSIX_VERSION #include #else From 1f4900c363f57cd4c1b9b8545711af2c6e700ce9 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Tue, 15 May 2012 14:50:56 -0700 Subject: [PATCH 054/108] Add support for building with clang/libcxx. --- CMakeLists.txt | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19dce000..17ea7b3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,14 @@ else() endif() endif() +if (CMAKE_CXX_COMPILER MATCHES ".*clang") + message(STATUS "Using clang's libcxx") + add_definitions(-stdlib=libc++) + set (EXTRA_LINKER_FLAGS -std=c++0x -stdlib=libc++) +else() + set (EXTRA_LINKER_FLAGS ) +endif() + include_directories(include) @@ -90,22 +98,22 @@ if (CMAKE_COMPILER_2005) endif() add_executable(chai src/main.cpp ${Chai_INCLUDES}) -target_link_libraries(chai ${LIBS}) +target_link_libraries(chai ${LIBS} ${EXTRA_LINKER_FLAGS}) if (BUILD_SAMPLES) add_executable(example samples/example.cpp) - target_link_libraries(example ${LIBS}) + target_link_libraries(example ${LIBS} ${EXTRA_LINKER_FLAGS}) add_executable(memory_leak_test samples/memory_leak_test.cpp) - target_link_libraries(memory_leak_test ${LIBS}) + target_link_libraries(memory_leak_test ${LIBS} ${EXTRA_LINKER_FLAGS}) endif() if (BUILD_MODULES) add_library(stl_extra MODULE src/stl_extra.cpp) - target_link_libraries(stl_extra ${LIBS}) + target_link_libraries(stl_extra ${LIBS} ${EXTRA_LINKER_FLAGS}) add_library(reflection MODULE src/reflection.cpp) - target_link_libraries(reflection ${LIBS}) + target_link_libraries(reflection ${LIBS} ${EXTRA_LINKER_FLAGS}) set(MODULES stl_extra reflection) endif() @@ -129,53 +137,53 @@ if(BUILD_TESTING) if (NOT UNIT_TEST_LIGHT) add_executable(utility_test unittests/utility_test.cpp) - target_link_libraries(utility_test ${LIBS}) + target_link_libraries(utility_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Utility_Test COMMAND utility_test) add_executable(dynamic_object_test unittests/dynamic_object_test.cpp) - target_link_libraries(dynamic_object_test ${LIBS}) + target_link_libraries(dynamic_object_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Dynamic_Object_Test COMMAND dynamic_object_test) add_executable(functor_creation_test unittests/functor_creation_test.cpp) - target_link_libraries(functor_creation_test ${LIBS}) + target_link_libraries(functor_creation_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Functor_Creation_Test COMMAND functor_creation_test) add_executable(functor_cast_test unittests/functor_cast_test.cpp) - target_link_libraries(functor_cast_test ${LIBS}) + target_link_libraries(functor_cast_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Functor_Cast_Test COMMAND functor_cast_test) add_executable(boxed_cast_test unittests/boxed_cast_test.cpp) - target_link_libraries(boxed_cast_test ${LIBS}) + target_link_libraries(boxed_cast_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Boxed_Cast_Test COMMAND boxed_cast_test) add_executable(object_lifetime_test unittests/object_lifetime_test.cpp) - target_link_libraries(object_lifetime_test ${LIBS}) + target_link_libraries(object_lifetime_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Object_Lifetime_Test COMMAND object_lifetime_test) add_executable(function_ordering_test unittests/function_ordering_test.cpp) - target_link_libraries(function_ordering_test ${LIBS}) + target_link_libraries(function_ordering_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Function_Ordering_Test COMMAND function_ordering_test) add_executable(type_info_test unittests/type_info_test.cpp) - target_link_libraries(type_info_test ${LIBS}) + target_link_libraries(type_info_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Type_Info_Test COMMAND type_info_test) add_executable(eval_catch_exception_test unittests/eval_catch_exception_test.cpp) - target_link_libraries(eval_catch_exception_test ${LIBS}) + target_link_libraries(eval_catch_exception_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Eval_Catch_Exception_Test COMMAND eval_catch_exception_test) add_executable(short_comparison_test unittests/short_comparison_test.cpp) - target_link_libraries(short_comparison_test ${LIBS}) + target_link_libraries(short_comparison_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME short_comparison_test COMMAND short_comparison_test) add_executable(multifile_test unittests/multifile_test_main.cpp unittests/multifile_test_chai.cpp unittests/multifile_test_module.cpp) - target_link_libraries(multifile_test ${LIBS}) + target_link_libraries(multifile_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME MultiFile_Test COMMAND multifile_test) add_library(test_module MODULE src/test_module.cpp) - target_link_libraries(test_module ${LIBS}) + target_link_libraries(test_module ${LIBS} ${EXTRA_LINKER_FLAGS}) install(TARGETS test_module RUNTIME DESTINATION bin LIBRARY DESTINATION lib/chaiscript) endif() From 4674594ee755d445ab46ef2a945fde5567c5fa57 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 15 May 2012 19:30:17 -0600 Subject: [PATCH 055/108] Make libcxx a default option when using clang --- CMakeLists.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 17ea7b3a..d4480952 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,9 +67,15 @@ else() endif() if (CMAKE_CXX_COMPILER MATCHES ".*clang") - message(STATUS "Using clang's libcxx") - add_definitions(-stdlib=libc++) - set (EXTRA_LINKER_FLAGS -std=c++0x -stdlib=libc++) + + option(USE_LIBCXX "Use clang's libcxx" TRUE) + + if (USE_LIBCXX) + add_definitions(-stdlib=libc++) + set (EXTRA_LINKER_FLAGS -std=c++0x -stdlib=libc++) + else () + set (EXTRA_LINKER_FLAGS -std=c++0x ) + endif() else() set (EXTRA_LINKER_FLAGS ) endif() From bca86c87e128cb8235b7124e63cf6806fc6d6114 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 16 May 2012 11:54:46 -0600 Subject: [PATCH 056/108] Update copyrights to 2012 #23 --- include/chaiscript/chaiscript.hpp | 2 +- include/chaiscript/chaiscript_defines.hpp | 2 +- include/chaiscript/chaiscript_stdlib.hpp | 2 +- include/chaiscript/chaiscript_threading.hpp | 2 +- include/chaiscript/dispatchkit/any.hpp | 2 +- include/chaiscript/dispatchkit/bad_boxed_cast.hpp | 2 +- include/chaiscript/dispatchkit/bind_first.hpp | 2 +- include/chaiscript/dispatchkit/bootstrap.hpp | 2 +- include/chaiscript/dispatchkit/bootstrap_stl.hpp | 2 +- include/chaiscript/dispatchkit/boxed_cast.hpp | 2 +- include/chaiscript/dispatchkit/boxed_cast_helper.hpp | 2 +- include/chaiscript/dispatchkit/boxed_number.hpp | 2 +- include/chaiscript/dispatchkit/boxed_value.hpp | 2 +- include/chaiscript/dispatchkit/dispatchkit.hpp | 2 +- include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp | 2 +- include/chaiscript/dispatchkit/dynamic_object.hpp | 2 +- include/chaiscript/dispatchkit/exception_specification.hpp | 2 +- include/chaiscript/dispatchkit/function_call_detail.hpp | 2 +- include/chaiscript/dispatchkit/handle_return.hpp | 2 +- include/chaiscript/dispatchkit/operators.hpp | 2 +- include/chaiscript/dispatchkit/proxy_constructors.hpp | 2 +- include/chaiscript/dispatchkit/proxy_functions.hpp | 2 +- include/chaiscript/dispatchkit/proxy_functions_detail.hpp | 2 +- include/chaiscript/dispatchkit/register_function.hpp | 2 +- include/chaiscript/dispatchkit/type_info.hpp | 2 +- include/chaiscript/language/chaiscript_algebraic.hpp | 2 +- include/chaiscript/language/chaiscript_common.hpp | 2 +- include/chaiscript/language/chaiscript_engine.hpp | 2 +- include/chaiscript/language/chaiscript_eval.hpp | 2 +- include/chaiscript/language/chaiscript_parser.hpp | 2 +- include/chaiscript/language/chaiscript_prelude.hpp | 2 +- include/chaiscript/utility/utility.hpp | 2 +- license.txt | 2 +- readme.txt | 2 +- 34 files changed, 34 insertions(+), 34 deletions(-) diff --git a/include/chaiscript/chaiscript.hpp b/include/chaiscript/chaiscript.hpp index 13f53395..11a013a5 100644 --- a/include/chaiscript/chaiscript.hpp +++ b/include/chaiscript/chaiscript.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/chaiscript_defines.hpp b/include/chaiscript/chaiscript_defines.hpp index 38cd72b5..162454ce 100644 --- a/include/chaiscript/chaiscript_defines.hpp +++ b/include/chaiscript/chaiscript_defines.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/chaiscript_stdlib.hpp b/include/chaiscript/chaiscript_stdlib.hpp index 18cb5695..8f4bafa0 100644 --- a/include/chaiscript/chaiscript_stdlib.hpp +++ b/include/chaiscript/chaiscript_stdlib.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/chaiscript_threading.hpp b/include/chaiscript/chaiscript_threading.hpp index bd34ef36..a955e2bc 100644 --- a/include/chaiscript/chaiscript_threading.hpp +++ b/include/chaiscript/chaiscript_threading.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/any.hpp b/include/chaiscript/dispatchkit/any.hpp index 23f18034..e8dcfb8d 100644 --- a/include/chaiscript/dispatchkit/any.hpp +++ b/include/chaiscript/dispatchkit/any.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/bad_boxed_cast.hpp b/include/chaiscript/dispatchkit/bad_boxed_cast.hpp index 53200c01..c8933653 100644 --- a/include/chaiscript/dispatchkit/bad_boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/bad_boxed_cast.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/bind_first.hpp b/include/chaiscript/dispatchkit/bind_first.hpp index a00d7ee3..5bd4348e 100644 --- a/include/chaiscript/dispatchkit/bind_first.hpp +++ b/include/chaiscript/dispatchkit/bind_first.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 1a8bf930..004076cd 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 9bfc66a7..85178b15 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index c4d820f5..b110391d 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp index aec80df1..ac70b3b9 100644 --- a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index 4c082d63..0c92fcb7 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 660db0c2..8428265e 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index 93a640d7..111e3c1d 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp index 9fce9cf7..f33b5207 100644 --- a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp +++ b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/dynamic_object.hpp b/include/chaiscript/dispatchkit/dynamic_object.hpp index 6a95127f..16e15dbd 100644 --- a/include/chaiscript/dispatchkit/dynamic_object.hpp +++ b/include/chaiscript/dispatchkit/dynamic_object.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/exception_specification.hpp b/include/chaiscript/dispatchkit/exception_specification.hpp index 0f08cdc0..4863a7aa 100644 --- a/include/chaiscript/dispatchkit/exception_specification.hpp +++ b/include/chaiscript/dispatchkit/exception_specification.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index e41e85cd..48b76b7c 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/handle_return.hpp b/include/chaiscript/dispatchkit/handle_return.hpp index 18f63cc9..8f07248d 100644 --- a/include/chaiscript/dispatchkit/handle_return.hpp +++ b/include/chaiscript/dispatchkit/handle_return.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/operators.hpp b/include/chaiscript/dispatchkit/operators.hpp index 26869767..7863130b 100644 --- a/include/chaiscript/dispatchkit/operators.hpp +++ b/include/chaiscript/dispatchkit/operators.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/proxy_constructors.hpp b/include/chaiscript/dispatchkit/proxy_constructors.hpp index 32bae3e6..cff94e15 100644 --- a/include/chaiscript/dispatchkit/proxy_constructors.hpp +++ b/include/chaiscript/dispatchkit/proxy_constructors.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index b1cf0521..4f65510a 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index 579074b6..686db78d 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index 2bb4cfe4..109208cb 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index 3c2fb20d..b6d0dead 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/language/chaiscript_algebraic.hpp b/include/chaiscript/language/chaiscript_algebraic.hpp index 3d363ce9..7729bc81 100644 --- a/include/chaiscript/language/chaiscript_algebraic.hpp +++ b/include/chaiscript/language/chaiscript_algebraic.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 08786034..7579a61b 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 26faa16f..b4a57080 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index b6d24d24..45cc0022 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index f21c7b9a..8e7c0622 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/language/chaiscript_prelude.hpp b/include/chaiscript/language/chaiscript_prelude.hpp index 9cdecaf5..ba427d86 100644 --- a/include/chaiscript/language/chaiscript_prelude.hpp +++ b/include/chaiscript/language/chaiscript_prelude.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/include/chaiscript/utility/utility.hpp b/include/chaiscript/utility/utility.hpp index 47bd9b3b..63c5a239 100644 --- a/include/chaiscript/utility/utility.hpp +++ b/include/chaiscript/utility/utility.hpp @@ -1,6 +1,6 @@ // This file is distributed under the BSD License. // See "license.txt" for details. -// Copyright 2009-2011, Jonathan Turner (jonathan@emptycrate.com) +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // and Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com diff --git a/license.txt b/license.txt index 57cd72b6..0601f2fb 100644 --- a/license.txt +++ b/license.txt @@ -1,4 +1,4 @@ -Copyright 2009-2011 Jason Turner and Jonathan Turner. All Rights Reserved. +Copyright 2009-2012 Jason Turner and Jonathan Turner. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/readme.txt b/readme.txt index 6c73989b..b211c394 100644 --- a/readme.txt +++ b/readme.txt @@ -1,6 +1,6 @@ ChaiScript http://www.chaiscript.com -(c) 2009-2011 Jason Turner and Jonathan Turner +(c) 2009-2012 Jason Turner and Jonathan Turner Release under the BSD license, see "license.txt" for details. [Introduction] From 68df78a2a6defcdb7f6677e8abb31bb558ed7674 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 16 May 2012 15:55:03 -0600 Subject: [PATCH 057/108] Add examples for using C++ lambdas with chaiscript. #32 --- CMakeLists.txt | 4 ++++ unittests/cpp_lambda_test.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 unittests/cpp_lambda_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d4480952..8d60975a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,6 +182,10 @@ if(BUILD_TESTING) target_link_libraries(short_comparison_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME short_comparison_test COMMAND short_comparison_test) + add_executable(cpp_lambda_test unittests/cpp_lambda_test.cpp) + target_link_libraries(cpp_lambda_test ${LIBS} ${EXTRA_LINKER_FLAGS}) + add_test(NAME cpp_lambda_test COMMAND cpp_lambda_test) + add_executable(multifile_test unittests/multifile_test_main.cpp unittests/multifile_test_chai.cpp unittests/multifile_test_module.cpp) diff --git a/unittests/cpp_lambda_test.cpp b/unittests/cpp_lambda_test.cpp new file mode 100644 index 00000000..ec5a0ff0 --- /dev/null +++ b/unittests/cpp_lambda_test.cpp @@ -0,0 +1,30 @@ +#include + +#include + +int main() +{ + + // We cannot deduce the type of a lambda expression, you must either wrap it + // in an std::function or provide the signature + + + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + + // provide the signature + chai.add(chaiscript::fun([] { return "hello"; } ), "f1"); + + // wrap + chai.add(chaiscript::fun(std::function([] { return "world"; } )), "f2"); + + if (chai.eval("f1()") == "hello" + && chai.eval("f2()") == "world") + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } + + + +} From c73f16fdfe4fe7845af718ff14b1dcb5d326f789 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 17 May 2012 10:14:50 -0700 Subject: [PATCH 058/108] Fixing 4.x grammar to be backward compatible. Added 3.x unit tests back to show this. --- CMakeLists.txt | 2 +- include/chaiscript/dispatchkit/bootstrap.hpp | 2 +- .../chaiscript/language/chaiscript_eval.hpp | 7 + .../chaiscript/language/chaiscript_parser.hpp | 14 +- .../language/chaiscript_prelude.hpp | 10 +- unittests/3.x/assign_const.chai | 2 + unittests/3.x/bind.chai | 2 + unittests/3.x/bind2.chai | 34 ++ unittests/3.x/block_start.chai | 1 + unittests/3.x/bool_not.chai | 1 + unittests/3.x/boxed_cast_test.cpp | 319 ++++++++++++++++++ unittests/3.x/break_while.chai | 7 + unittests/3.x/char_init.chai | 1 + unittests/3.x/classification.chai | 7 + unittests/3.x/collate.chai | 3 + unittests/3.x/compare_gt.chai | 1 + unittests/3.x/compare_lt.chai | 1 + unittests/3.x/concat.chai | 5 + unittests/3.x/const_range_test.chai | 4 + unittests/3.x/convert_double_string.chai | 1 + unittests/3.x/convert_int_string.chai | 1 + unittests/3.x/convert_string_double.chai | 1 + unittests/3.x/convert_string_int.chai | 1 + unittests/3.x/deep_array_lookup.chai | 11 + unittests/3.x/dispatch_functions.chai | 11 + unittests/3.x/drop.chai | 1 + unittests/3.x/drop_while.chai | 1 + unittests/3.x/dynamic_object_test.cpp | 44 +++ unittests/3.x/empty.chai | 0 unittests/3.x/equ_shortform.chai | 4 + unittests/3.x/eval.chai | 1 + unittests/3.x/eval_catch_exception_test.cpp | 122 +++++++ unittests/3.x/eval_error.chai | 39 +++ unittests/3.x/even.chai | 1 + unittests/3.x/exception.chai | 9 + unittests/3.x/exception_finally.chai | 32 ++ unittests/3.x/exception_guards.chai | 34 ++ unittests/3.x/filter.chai | 1 + unittests/3.x/float.chai | 7 + unittests/3.x/foldl.chai | 1 + unittests/3.x/for.chai | 7 + unittests/3.x/for_each.chai | 1 + unittests/3.x/for_each_range.chai | 3 + unittests/3.x/for_each_retro.chai | 4 + unittests/3.x/function_array_adjacent.chai | 1 + unittests/3.x/function_introspection.chai | 76 +++++ unittests/3.x/function_ordering_test.cpp | 38 +++ unittests/3.x/function_reassignment.chai | 3 + unittests/3.x/functor_cast_test.cpp | 25 ++ unittests/3.x/functor_creation_test.cpp | 26 ++ unittests/3.x/generate_range.chai | 1 + unittests/3.x/global_const_in_module.chai | 7 + unittests/3.x/if.chai | 7 + unittests/3.x/if_else.chai | 13 + unittests/3.x/if_elseif.chai | 18 + unittests/3.x/if_elseif_else.chai | 14 + unittests/3.x/index_operator.chai | 10 + unittests/3.x/inheritance.chai | 8 + unittests/3.x/instring_eval.chai | 3 + unittests/3.x/instring_eval_more.chai | 4 + .../3.x/invalid_function_assignment.chai | 1 + .../3.x/invalid_function_reassignment.chai | 1 + unittests/3.x/is_undef.chai | 4 + unittests/3.x/join.chai | 1 + unittests/3.x/lambda.chai | 2 + unittests/3.x/list_push_back.chai | 8 + unittests/3.x/list_push_front.chai | 8 + unittests/3.x/load_module.chai | 2 + unittests/3.x/loop_inner_outer.chai | 9 + unittests/3.x/malformed_inline_map.chai | 2 + unittests/3.x/map.chai | 1 + unittests/3.x/map_access.chai | 2 + unittests/3.x/map_inplace_init.chai | 3 + unittests/3.x/math_add.chai | 1 + unittests/3.x/math_add_mixed.chai | 1 + unittests/3.x/math_dec.chai | 3 + unittests/3.x/math_div.chai | 1 + unittests/3.x/math_inc.chai | 3 + unittests/3.x/math_mod.chai | 1 + unittests/3.x/math_mult.chai | 1 + unittests/3.x/math_negate.chai | 1 + unittests/3.x/math_paren.chai | 1 + unittests/3.x/math_sub.chai | 1 + unittests/3.x/max.chai | 1 + unittests/3.x/memberscope.chai | 12 + unittests/3.x/method_sugar.chai | 1 + unittests/3.x/min.chai | 1 + unittests/3.x/mmd1.chai | 20 ++ unittests/3.x/mmd2.chai | 9 + unittests/3.x/multifile_test_chai.cpp | 12 + unittests/3.x/multifile_test_chai.hpp | 14 + unittests/3.x/multifile_test_main.cpp | 14 + unittests/3.x/multifile_test_module.cpp | 21 ++ unittests/3.x/multifile_test_module.hpp | 11 + unittests/3.x/multiline.chai | 9 + unittests/3.x/number_formats.chai | 3 + unittests/3.x/object_attr.chai | 6 + unittests/3.x/object_attr_same_name.chai | 9 + unittests/3.x/object_clone.chai | 11 + unittests/3.x/object_constructor_guards.chai | 10 + unittests/3.x/object_lifetime_test.cpp | 66 ++++ unittests/3.x/object_method_guards.chai | 7 + unittests/3.x/odd.chai | 1 + unittests/3.x/operator_overload.chai | 9 + unittests/3.x/operator_overload2.chai | 9 + unittests/3.x/operators_float.chai | 16 + unittests/3.x/operators_int.chai | 31 ++ unittests/3.x/pair.chai | 5 + .../3.x/pointer_passed_to_constructor.chai | 8 + unittests/3.x/precedence_1.chai | 1 + unittests/3.x/precedence_2.chai | 1 + unittests/3.x/precedence_3.chai | 1 + unittests/3.x/precedence_eq.chai | 3 + unittests/3.x/product.chai | 1 + unittests/3.x/range.chai | 4 + unittests/3.x/range_back.chai | 4 + unittests/3.x/range_contains.chai | 5 + unittests/3.x/range_find.chai | 6 + unittests/3.x/range_inplace.chai | 1 + unittests/3.x/reduce.chai | 1 + unittests/3.x/ref_equal.chai | 5 + unittests/3.x/reflection_test.chai | 37 ++ unittests/3.x/retro.chai | 4 + unittests/3.x/retroretro.chai | 7 + unittests/3.x/return.chai | 5 + unittests/3.x/runtime_error.chai | 11 + unittests/3.x/shift.chai | 1 + unittests/3.x/short_comparison_test.cpp | 29 ++ unittests/3.x/string_charptr.chai | 6 + unittests/3.x/string_concat.chai | 1 + unittests/3.x/string_find.chai | 1 + unittests/3.x/string_find_first_not_of.chai | 1 + unittests/3.x/string_find_first_of.chai | 1 + unittests/3.x/string_find_last_not_of.chai | 1 + unittests/3.x/string_find_last_of.chai | 1 + unittests/3.x/string_init.chai | 1 + unittests/3.x/string_literal_access.chai | 1 + unittests/3.x/string_rfind.chai | 1 + unittests/3.x/sum.chai | 1 + unittests/3.x/take.chai | 1 + unittests/3.x/take_while.chai | 1 + unittests/3.x/type_info.chai | 11 + unittests/3.x/type_info_test.cpp | 32 ++ unittests/3.x/unit_test.inc | 53 +++ unittests/3.x/use.chai | 9 + unittests/3.x/use.inc | 4 + unittests/3.x/utility_test.cpp | 42 +++ unittests/3.x/vector_access.chai | 2 + unittests/3.x/vector_erase_at.chai | 3 + unittests/3.x/vector_inplace_init.chai | 2 + unittests/3.x/vector_insert_at.chai | 3 + unittests/3.x/vector_literal_acccess.chai | 1 + unittests/3.x/vector_of_one.chai | 2 + .../3.x/vector_paren_literal_access.chai | 1 + unittests/3.x/vector_push_back.chai | 5 + unittests/3.x/vector_push_empty.chai | 4 + unittests/3.x/zip.chai | 5 + unittests/3.x/zip_with.chai | 3 + unittests/assign_const.chai | 4 +- unittests/bind.chai | 2 +- unittests/concat.chai | 2 +- unittests/const_range_test.chai | 3 +- unittests/deep_array_lookup.chai | 4 +- unittests/drop.chai | 2 +- unittests/drop_while.chai | 2 +- unittests/eval_error.chai | 2 +- unittests/exception_guards.chai | 4 +- unittests/filter.chai | 2 +- unittests/foldl.chai | 2 +- unittests/for.chai | 4 +- unittests/for_each.chai | 2 +- unittests/for_each_range.chai | 4 +- unittests/for_each_retro.chai | 2 +- unittests/function_introspection.chai | 8 +- unittests/generate_range.chai | 2 +- unittests/index_operator.chai | 2 +- unittests/invalid_function_assignment.chai | 2 +- unittests/invalid_function_reassignment.chai | 2 +- unittests/join.chai | 2 +- unittests/lambda.chai | 2 +- unittests/malformed_inline_map.chai | 2 +- unittests/map.chai | 2 +- unittests/map_access.chai | 2 +- unittests/map_inplace_init.chai | 2 +- unittests/method_sugar.chai | 2 +- unittests/multiline.chai | 6 +- unittests/operators_float.chai | 2 +- unittests/product.chai | 2 +- unittests/range.chai | 2 +- unittests/range_back.chai | 2 +- unittests/range_contains.chai | 2 +- unittests/range_find.chai | 2 +- unittests/range_inplace.chai | 2 +- unittests/reduce.chai | 2 +- unittests/reflection_test.chai | 2 +- unittests/retro.chai | 2 +- unittests/retroretro.chai | 2 +- unittests/sum.chai | 2 +- unittests/take.chai | 2 +- unittests/take_while.chai | 2 +- unittests/vector_access.chai | 2 +- unittests/vector_erase_at.chai | 4 +- unittests/vector_inplace_init.chai | 2 +- unittests/vector_insert_at.chai | 4 +- unittests/vector_literal_acccess.chai | 2 +- unittests/vector_of_one.chai | 2 +- unittests/vector_paren_literal_access.chai | 2 +- unittests/vector_push_back.chai | 2 +- unittests/vector_push_empty.chai | 2 +- unittests/zip.chai | 8 +- unittests/zip_with.chai | 4 +- 211 files changed, 1769 insertions(+), 86 deletions(-) create mode 100644 unittests/3.x/assign_const.chai create mode 100644 unittests/3.x/bind.chai create mode 100644 unittests/3.x/bind2.chai create mode 100644 unittests/3.x/block_start.chai create mode 100644 unittests/3.x/bool_not.chai create mode 100644 unittests/3.x/boxed_cast_test.cpp create mode 100644 unittests/3.x/break_while.chai create mode 100644 unittests/3.x/char_init.chai create mode 100644 unittests/3.x/classification.chai create mode 100644 unittests/3.x/collate.chai create mode 100644 unittests/3.x/compare_gt.chai create mode 100644 unittests/3.x/compare_lt.chai create mode 100644 unittests/3.x/concat.chai create mode 100644 unittests/3.x/const_range_test.chai create mode 100644 unittests/3.x/convert_double_string.chai create mode 100644 unittests/3.x/convert_int_string.chai create mode 100644 unittests/3.x/convert_string_double.chai create mode 100644 unittests/3.x/convert_string_int.chai create mode 100644 unittests/3.x/deep_array_lookup.chai create mode 100644 unittests/3.x/dispatch_functions.chai create mode 100644 unittests/3.x/drop.chai create mode 100644 unittests/3.x/drop_while.chai create mode 100644 unittests/3.x/dynamic_object_test.cpp create mode 100644 unittests/3.x/empty.chai create mode 100644 unittests/3.x/equ_shortform.chai create mode 100644 unittests/3.x/eval.chai create mode 100644 unittests/3.x/eval_catch_exception_test.cpp create mode 100644 unittests/3.x/eval_error.chai create mode 100644 unittests/3.x/even.chai create mode 100644 unittests/3.x/exception.chai create mode 100644 unittests/3.x/exception_finally.chai create mode 100644 unittests/3.x/exception_guards.chai create mode 100644 unittests/3.x/filter.chai create mode 100644 unittests/3.x/float.chai create mode 100644 unittests/3.x/foldl.chai create mode 100644 unittests/3.x/for.chai create mode 100644 unittests/3.x/for_each.chai create mode 100644 unittests/3.x/for_each_range.chai create mode 100644 unittests/3.x/for_each_retro.chai create mode 100644 unittests/3.x/function_array_adjacent.chai create mode 100644 unittests/3.x/function_introspection.chai create mode 100644 unittests/3.x/function_ordering_test.cpp create mode 100644 unittests/3.x/function_reassignment.chai create mode 100644 unittests/3.x/functor_cast_test.cpp create mode 100644 unittests/3.x/functor_creation_test.cpp create mode 100644 unittests/3.x/generate_range.chai create mode 100644 unittests/3.x/global_const_in_module.chai create mode 100644 unittests/3.x/if.chai create mode 100644 unittests/3.x/if_else.chai create mode 100644 unittests/3.x/if_elseif.chai create mode 100644 unittests/3.x/if_elseif_else.chai create mode 100644 unittests/3.x/index_operator.chai create mode 100644 unittests/3.x/inheritance.chai create mode 100644 unittests/3.x/instring_eval.chai create mode 100644 unittests/3.x/instring_eval_more.chai create mode 100644 unittests/3.x/invalid_function_assignment.chai create mode 100644 unittests/3.x/invalid_function_reassignment.chai create mode 100644 unittests/3.x/is_undef.chai create mode 100644 unittests/3.x/join.chai create mode 100644 unittests/3.x/lambda.chai create mode 100644 unittests/3.x/list_push_back.chai create mode 100644 unittests/3.x/list_push_front.chai create mode 100644 unittests/3.x/load_module.chai create mode 100644 unittests/3.x/loop_inner_outer.chai create mode 100644 unittests/3.x/malformed_inline_map.chai create mode 100644 unittests/3.x/map.chai create mode 100644 unittests/3.x/map_access.chai create mode 100644 unittests/3.x/map_inplace_init.chai create mode 100644 unittests/3.x/math_add.chai create mode 100644 unittests/3.x/math_add_mixed.chai create mode 100644 unittests/3.x/math_dec.chai create mode 100644 unittests/3.x/math_div.chai create mode 100644 unittests/3.x/math_inc.chai create mode 100644 unittests/3.x/math_mod.chai create mode 100644 unittests/3.x/math_mult.chai create mode 100644 unittests/3.x/math_negate.chai create mode 100644 unittests/3.x/math_paren.chai create mode 100644 unittests/3.x/math_sub.chai create mode 100644 unittests/3.x/max.chai create mode 100644 unittests/3.x/memberscope.chai create mode 100644 unittests/3.x/method_sugar.chai create mode 100644 unittests/3.x/min.chai create mode 100644 unittests/3.x/mmd1.chai create mode 100644 unittests/3.x/mmd2.chai create mode 100644 unittests/3.x/multifile_test_chai.cpp create mode 100644 unittests/3.x/multifile_test_chai.hpp create mode 100644 unittests/3.x/multifile_test_main.cpp create mode 100644 unittests/3.x/multifile_test_module.cpp create mode 100644 unittests/3.x/multifile_test_module.hpp create mode 100644 unittests/3.x/multiline.chai create mode 100644 unittests/3.x/number_formats.chai create mode 100644 unittests/3.x/object_attr.chai create mode 100644 unittests/3.x/object_attr_same_name.chai create mode 100644 unittests/3.x/object_clone.chai create mode 100644 unittests/3.x/object_constructor_guards.chai create mode 100644 unittests/3.x/object_lifetime_test.cpp create mode 100644 unittests/3.x/object_method_guards.chai create mode 100644 unittests/3.x/odd.chai create mode 100644 unittests/3.x/operator_overload.chai create mode 100644 unittests/3.x/operator_overload2.chai create mode 100644 unittests/3.x/operators_float.chai create mode 100644 unittests/3.x/operators_int.chai create mode 100644 unittests/3.x/pair.chai create mode 100644 unittests/3.x/pointer_passed_to_constructor.chai create mode 100644 unittests/3.x/precedence_1.chai create mode 100644 unittests/3.x/precedence_2.chai create mode 100644 unittests/3.x/precedence_3.chai create mode 100644 unittests/3.x/precedence_eq.chai create mode 100644 unittests/3.x/product.chai create mode 100644 unittests/3.x/range.chai create mode 100644 unittests/3.x/range_back.chai create mode 100644 unittests/3.x/range_contains.chai create mode 100644 unittests/3.x/range_find.chai create mode 100644 unittests/3.x/range_inplace.chai create mode 100644 unittests/3.x/reduce.chai create mode 100644 unittests/3.x/ref_equal.chai create mode 100644 unittests/3.x/reflection_test.chai create mode 100644 unittests/3.x/retro.chai create mode 100644 unittests/3.x/retroretro.chai create mode 100644 unittests/3.x/return.chai create mode 100644 unittests/3.x/runtime_error.chai create mode 100644 unittests/3.x/shift.chai create mode 100644 unittests/3.x/short_comparison_test.cpp create mode 100644 unittests/3.x/string_charptr.chai create mode 100644 unittests/3.x/string_concat.chai create mode 100644 unittests/3.x/string_find.chai create mode 100644 unittests/3.x/string_find_first_not_of.chai create mode 100644 unittests/3.x/string_find_first_of.chai create mode 100644 unittests/3.x/string_find_last_not_of.chai create mode 100644 unittests/3.x/string_find_last_of.chai create mode 100644 unittests/3.x/string_init.chai create mode 100644 unittests/3.x/string_literal_access.chai create mode 100644 unittests/3.x/string_rfind.chai create mode 100644 unittests/3.x/sum.chai create mode 100644 unittests/3.x/take.chai create mode 100644 unittests/3.x/take_while.chai create mode 100644 unittests/3.x/type_info.chai create mode 100644 unittests/3.x/type_info_test.cpp create mode 100644 unittests/3.x/unit_test.inc create mode 100644 unittests/3.x/use.chai create mode 100644 unittests/3.x/use.inc create mode 100644 unittests/3.x/utility_test.cpp create mode 100644 unittests/3.x/vector_access.chai create mode 100644 unittests/3.x/vector_erase_at.chai create mode 100644 unittests/3.x/vector_inplace_init.chai create mode 100644 unittests/3.x/vector_insert_at.chai create mode 100644 unittests/3.x/vector_literal_acccess.chai create mode 100644 unittests/3.x/vector_of_one.chai create mode 100644 unittests/3.x/vector_paren_literal_access.chai create mode 100644 unittests/3.x/vector_push_back.chai create mode 100644 unittests/3.x/vector_push_empty.chai create mode 100644 unittests/3.x/zip.chai create mode 100644 unittests/3.x/zip_with.chai diff --git a/CMakeLists.txt b/CMakeLists.txt index d4480952..279a53cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,7 +123,7 @@ if (BUILD_MODULES) set(MODULES stl_extra reflection) endif() -file(GLOB UNIT_TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/unittests/ ${CMAKE_CURRENT_SOURCE_DIR}/unittests/*.chai) +file(GLOB UNIT_TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/unittests/ ${CMAKE_CURRENT_SOURCE_DIR}/unittests/*.chai ${CMAKE_CURRENT_SOURCE_DIR}/unittests/3.x/*.chai) list(SORT UNIT_TESTS) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 5e5bdbed..577a3109 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -402,7 +402,7 @@ namespace chaiscript m->add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs"); m->add(fun(&dispatch::Dynamic_Object::get_attr), "get_attr"); - m->eval("def Dynamic_Object::clone() { auto &new_o = Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind([](new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }"); + m->eval("def Dynamic_Object::clone() { auto &new_o = Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind(fun(new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }"); m->add(fun(&has_guard), "has_guard"); m->add(fun(&get_guard), "get_guard"); diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 1bb296db..040ec967 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -321,6 +321,13 @@ namespace chaiscript throw exception::eval_error("Missing clone or copy constructor for right hand side of equation", e.parameters, t_ss); } } + else if (this->children[1]->text == ":=") { + if (lhs.is_undef() || Boxed_Value::type_match(lhs, retval)) { + lhs.assign(retval); + } else { + throw exception::eval_error("Mismatched types in equation"); + } + } else { try { retval = t_ss.call_function(this->children[1]->text, lhs, retval); diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index f21c7b9a..fa7644d5 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -1119,11 +1119,7 @@ namespace chaiscript size_t prev_stack_top = m_match_stack.size(); - //if (Keyword("fun")) { - if (Char('[')) { - if (!Char(']')) { - throw exception::eval_error("Closure list not currently supported", File_Position(m_line, m_col), *m_filename); - } + if (Keyword("fun")) { retval = true; if (Char('(')) { @@ -1546,7 +1542,7 @@ namespace chaiscript size_t prev_stack_top = m_match_stack.size(); - if (Keyword("auto")) { + if (Keyword("auto") || Keyword("var")) { retval = true; if (!(Reference() || Id(true))) { @@ -1601,10 +1597,10 @@ namespace chaiscript size_t prev_stack_top = m_match_stack.size(); - if (Char('{')) { + if (Char('[')) { retval = true; Container_Arg_List(); - if (!Char('}')) { + if (!Char(']')) { throw exception::eval_error("Missing closing brace '}' in container initializer", File_Position(m_line, m_col), *m_filename); } if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) { @@ -1893,7 +1889,7 @@ namespace chaiscript if (Operator()) { retval = true; - if (Symbol("=", true, true) || Symbol("+=", true, true) || + if (Symbol("=", true, true) || Symbol(":=", true, true) || Symbol("+=", true, true) || Symbol("-=", true, true) || Symbol("*=", true, true) || Symbol("/=", true, true) || Symbol("%=", true, true) || Symbol("<<=", true, true) || Symbol(">>=", true, true) || Symbol("&=", true, true) || Symbol("^=", true, true) || Symbol("|=", true, true)) { diff --git a/include/chaiscript/language/chaiscript_prelude.hpp b/include/chaiscript/language/chaiscript_prelude.hpp index 9cdecaf5..b75c475f 100644 --- a/include/chaiscript/language/chaiscript_prelude.hpp +++ b/include/chaiscript/language/chaiscript_prelude.hpp @@ -7,7 +7,7 @@ #ifndef CHAISCRIPT_PRELUDE_HPP_ #define CHAISCRIPT_PRELUDE_HPP_ -//Note, the expression "{x,y}" in "collate" is parsed as two separate expressions +//Note, the expression "[x,y]" in "collate" is parsed as two separate expressions //by C++, so CODE_STRING, takes two expressions and adds in the missing comma #define CODE_STRING(x, y) #x ", " #y @@ -23,7 +23,7 @@ def to_string(x) : call_exists(first, x) && call_exists(second, x) { \n\ }\n\ # to_string for containers\n\ def to_string(x) : call_exists(range, x) && !x.is_type("string"){ \n\ - "{" + x.join(", ") + "}"; \n\ + "[" + x.join(", ") + "]"; \n\ }\n\ # Basic to_string function\n\ def to_string(x) { \n\ @@ -259,7 +259,7 @@ def generate_range(x, y) { \n\ }\n\ # Returns a new Vector with the first value to the second value as its elements\n\ def collate(x, y) { \n\ - return {x, y}; \n\ + return [x, y]; \n\ } \n\ def zip_with(f, x, y, inserter) : call_exists(range, x) && call_exists(range, y) { \n\ auto r_x = range(x); \n\ @@ -305,10 +305,10 @@ def string::find_last_not_of(list) : is_type(list, "string") { \n\ int(find_last_not_of(this, list, -1)); \n\ } \n\ def string::ltrim() { \n\ - drop_while(this, [](x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'}); \n\ + drop_while(this, fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'}); \n\ } \n\ def string::rtrim() { \n\ - reverse(drop_while(reverse(this), [](x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'})); \n\ + reverse(drop_while(reverse(this), fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'})); \n\ } \n\ def string::trim() { \n\ ltrim(rtrim(this)); \n\ diff --git a/unittests/3.x/assign_const.chai b/unittests/3.x/assign_const.chai new file mode 100644 index 00000000..ff6a8c3d --- /dev/null +++ b/unittests/3.x/assign_const.chai @@ -0,0 +1,2 @@ +assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 = 2 } ); +assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 + 2 = 2 } ); diff --git a/unittests/3.x/bind.chai b/unittests/3.x/bind.chai new file mode 100644 index 00000000..3c72673f --- /dev/null +++ b/unittests/3.x/bind.chai @@ -0,0 +1,2 @@ +var prod = bind(foldl, _, `*`, 1.0) +assert_equal(60, prod([3, 4, 5])) diff --git a/unittests/3.x/bind2.chai b/unittests/3.x/bind2.chai new file mode 100644 index 00000000..0b8ddde3 --- /dev/null +++ b/unittests/3.x/bind2.chai @@ -0,0 +1,34 @@ + +def add(x, y) +{ + return x + y; +} + +assert_equal(2, add.get_arity()); + +var b = bind(add, 2, _); + +assert_equal(1, b.get_arity()); + +var c = bind(b, 3); + +assert_equal(0, c.get_arity()); + +assert_equal(6, b(4)); +assert_equal(5, c()); + +def concat2(a,b,c,d) +{ + return to_string(a) + to_string(b) + to_string(c) + to_string(d); +} + +var d = bind(concat2, _, " Hello ", _, " World"); +assert_equal(2, d.get_arity()); + +assert_equal("1 Hello 3 World", d(1,3)); + +var e = bind(`<`, _, 5); +var types = e.get_param_types(); +assert_equal(2, types.size()); +assert_equal(true, types[0].bare_equal(bool_type)); + diff --git a/unittests/3.x/block_start.chai b/unittests/3.x/block_start.chai new file mode 100644 index 00000000..4830af1f --- /dev/null +++ b/unittests/3.x/block_start.chai @@ -0,0 +1 @@ +{print("hello")} diff --git a/unittests/3.x/bool_not.chai b/unittests/3.x/bool_not.chai new file mode 100644 index 00000000..fe4d0f77 --- /dev/null +++ b/unittests/3.x/bool_not.chai @@ -0,0 +1 @@ +assert_equal(false, !true) diff --git a/unittests/3.x/boxed_cast_test.cpp b/unittests/3.x/boxed_cast_test.cpp new file mode 100644 index 00000000..2e6edd9f --- /dev/null +++ b/unittests/3.x/boxed_cast_test.cpp @@ -0,0 +1,319 @@ +#include + + +using namespace chaiscript; + + +template +void use(T){} + +template +bool run_test_type_conversion(const Boxed_Value &bv, bool expectedpass) +{ + try { + To ret = chaiscript::boxed_cast(bv); + use(ret); + } catch (const chaiscript::exception::bad_boxed_cast &/*e*/) { + if (expectedpass) { +// std::cerr << "Failure in run_test_type_conversion: " << e.what() << std::endl; + return false; + } else { + return true; + } + } catch (const std::exception &e) { + std::cerr << "Unexpected standard exception when attempting cast_conversion: " << e.what() << std::endl; + return false; + } catch (...) { + std::cerr << "Unexpected unknown exception when attempting cast_conversion." << std::endl; + return false; + } + + if (expectedpass) + { + return true; + } else { + return false; + } +} + +template +bool test_type_conversion(const Boxed_Value &bv, bool expectedpass) +{ + bool ret = run_test_type_conversion(bv, expectedpass); + + if (!ret) + { + std::cerr << "Error with type conversion test. From: " + << (bv.is_const()?(std::string("const ")):(std::string())) << bv.get_type_info().name() + << " To: " + << (boost::is_const::value?(std::string("const ")):(std::string())) << typeid(To).name() + << " test was expected to " << ((expectedpass)?(std::string("succeed")):(std::string("fail"))) << " but did not" << std::endl; + } + + return ret; +} + +template +bool do_test(const Boxed_Value &bv, bool T, bool ConstT, bool TRef, bool ConstTRef, bool TPtr, bool ConstTPtr, bool TPtrConst, + bool ConstTPtrConst, bool SharedPtrT, bool SharedConstPtrT, + bool ConstSharedPtrT, bool ConstSharedConstPtrT, bool ConstSharedPtrTRef, bool ConstSharedPtrTConstRef, + bool BoostRef, bool BoostConstRef, bool ConstBoostRef, bool ConstBoostConstRef, + bool ConstBoostRefRef, bool ConstBoostConstRefRef, bool Number, + bool ConstNumber, bool ConstNumberRef, bool TPtrConstRef, bool ConstTPtrConstRef) +{ + bool passed = true; + passed &= test_type_conversion(bv, T); + passed &= test_type_conversion(bv, ConstT); + passed &= test_type_conversion(bv, TRef); + passed &= test_type_conversion(bv, ConstTRef); + passed &= test_type_conversion(bv, TPtr); + passed &= test_type_conversion(bv, ConstTPtr); + passed &= test_type_conversion(bv, TPtrConst); + passed &= test_type_conversion(bv, ConstTPtrConst); + passed &= test_type_conversion >(bv, SharedPtrT); + passed &= test_type_conversion >(bv, SharedConstPtrT); + passed &= test_type_conversion &>(bv, false); + passed &= test_type_conversion &>(bv, false); + passed &= test_type_conversion >(bv, ConstSharedPtrT); + passed &= test_type_conversion >(bv, ConstSharedConstPtrT); + passed &= test_type_conversion &>(bv, ConstSharedPtrTRef); + passed &= test_type_conversion &>(bv, ConstSharedPtrTConstRef); + passed &= test_type_conversion >(bv, BoostRef); + passed &= test_type_conversion >(bv, BoostConstRef); + passed &= test_type_conversion &>(bv, false); + passed &= test_type_conversion &>(bv, false); + passed &= test_type_conversion >(bv, ConstBoostRef); + passed &= test_type_conversion >(bv, ConstBoostConstRef); + passed &= test_type_conversion &>(bv, ConstBoostRefRef); + passed &= test_type_conversion &>(bv, ConstBoostConstRefRef); + passed &= test_type_conversion(bv, Number); + passed &= test_type_conversion(bv, ConstNumber); + passed &= test_type_conversion(bv, false); + passed &= test_type_conversion(bv, ConstNumberRef); + passed &= test_type_conversion(bv, false); + passed &= test_type_conversion(bv, false); + passed &= test_type_conversion(bv, false); + passed &= test_type_conversion(bv, false); + passed &= test_type_conversion(bv, false); + passed &= test_type_conversion(bv, false); + passed &= test_type_conversion(bv, TPtrConstRef); + passed &= test_type_conversion(bv, ConstTPtrConstRef); + passed &= test_type_conversion(bv, true); + passed &= test_type_conversion(bv, true); + passed &= test_type_conversion(bv, true); + + return passed; +} + +/** Tests intended for built int types **/ +template +bool built_in_type_test(const T &initial, bool ispod) +{ + bool passed = true; + + /** value tests **/ + T i = T(initial); + passed &= do_test(var(i), true, true, true, true, true, + true, true, true, true, true, + true, true, true, true, true, + true, true, true, true, true, + ispod && true, ispod && true, ispod && true, true, true); + + passed &= do_test(const_var(i), true, true, false, true, false, + true, false, true, false, true, + false, true, false, true, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + passed &= do_test(var(&i), true, true, true, true, true, + true, true, true, false, false, + false, false, false, false, true, + true, true, true, true, true, + ispod && true, ispod && true, ispod && true, true, true); + + passed &= do_test(const_var(&i), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, ispod && false, true); + + passed &= do_test(var(boost::ref(i)), true, true, true, true, true, + true, true, true, false, false, + false, false, false, false, true, + true, true, true, true, true, + ispod && true, ispod && true, ispod && true, true, true); + + passed &= do_test(var(boost::cref(i)), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + /** Const Reference Variable tests */ + + // This reference will be copied on input, which is expected + const T &ir = i; + + passed &= do_test(var(i), true, true, true, true, true, + true, true, true, true, true, + true, true, true, true, true, + true, true, true, true, true, + ispod && true, ispod && true, ispod && true, true, true); + + // But a pointer or reference to it should be necessarily const + passed &= do_test(var(&ir), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + passed &= do_test(var(boost::ref(ir)), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + // Make sure const of const works too + passed &= do_test(const_var(&ir), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + passed &= do_test(const_var(boost::ref(ir)), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + /** Const Reference Variable tests */ + + // This will always be seen as a const + const T*cip = &i; + passed &= do_test(var(cip), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + // make sure const of const works + passed &= do_test(const_var(cip), true, true, false, true, false, + true, false, true, false, false, + false, false, false, false, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + /** shared_ptr tests **/ + + boost::shared_ptr ip(new T(initial)); + + passed &= do_test(var(ip), true, true, true, true, true, + true, true, true, true, true, + true, true, true, true, true, + true, true, true, true, true, + ispod && true, ispod && true, ispod && true, true, true); + + passed &= do_test(const_var(ip), true, true, false, true, false, + true, false, true, false, true, + false, true, false, true, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + /** const shared_ptr tests **/ + boost::shared_ptr ipc(new T(initial)); + + passed &= do_test(var(ipc), true, true, false, true, false, + true, false, true, false, true, + false, true, false, true, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + // const of this should be the same, making sure it compiles + passed &= do_test(const_var(ipc), true, true, false, true, false, + true, false, true, false, true, + false, true, false, true, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); + + + /** Double ptr tests **/ + + /* + T **doublep; + + passed &= do_test(var(doublep), true, true, false, true, false, + true, false, true, false, true, + false, true, false, true, false, + true, false, true, false, true, + ispod && true, ispod && true, ispod && true, false, true); +*/ + + return passed; +} + + +template +bool pointer_test(const T& default_value, const T& new_value) +{ + T *p = new T(default_value); + + // we store a pointer to a pointer, so we can get a pointer to a pointer + try { + T **result = boxed_cast(var(&p)); + *(*result) = new_value; + + + if (p != (*result) ) { + std::cerr << "Pointer passed in different than one returned" << std::endl; + return false; + } + + if (*p != *(*result) ) { + std::cerr << "Somehow dereferenced pointer values are not the same?" << std::endl; + return false; + } + + return true; + } catch (const exception::bad_boxed_cast &) { + std::cerr << "Bad boxed cast performing ** to ** test" << std::endl; + return false; + } catch (...) { + std::cerr << "Unknown exception performing ** to ** test" << std::endl; + return false; + } + + +} + + +int main() +{ + bool passed = true; + + /* + bool T, bool ConstT, bool TRef, bool ConstTRef, bool TPtr, + bool ConstTPtr, bool TPtrConst, bool ConstTPtrConst, bool SharedPtrT, bool SharedConstPtrT, + bool ConstSharedPtrT, bool ConstSharedConstPtrT, bool ConstSharedPtrTRef, bool ConstSharedPtrTConstRef, bool BoostRef, + bool BoostConstRef, bool ConstBoostRef, bool ConstBoostConstRef, bool ConstBoostRefRef, bool ConstBoostConstRefRef, + bool Number, bool ConstNumber, bool ConstNumberRef + */ + + passed &= built_in_type_test(5, true); + passed &= built_in_type_test(1.1, true); + passed &= built_in_type_test('a', true); + passed &= built_in_type_test('a', true); + passed &= built_in_type_test('a', true); + passed &= built_in_type_test(false, false); + passed &= built_in_type_test("Hello World", false); + + // storing a pointer + passed &= pointer_test(1, 0); + + if (passed) + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } + +} diff --git a/unittests/3.x/break_while.chai b/unittests/3.x/break_while.chai new file mode 100644 index 00000000..d54a3dd9 --- /dev/null +++ b/unittests/3.x/break_while.chai @@ -0,0 +1,7 @@ +var i = 0 +while (i < 10) { + if (++i == 5) { + break + } +} +assert_equal(5, i); diff --git a/unittests/3.x/char_init.chai b/unittests/3.x/char_init.chai new file mode 100644 index 00000000..ce764774 --- /dev/null +++ b/unittests/3.x/char_init.chai @@ -0,0 +1 @@ +assert_equal("b", to_string('b')) diff --git a/unittests/3.x/classification.chai b/unittests/3.x/classification.chai new file mode 100644 index 00000000..8c2cca94 --- /dev/null +++ b/unittests/3.x/classification.chai @@ -0,0 +1,7 @@ +assert_equal(true, 1.is_var_const()); +assert_equal(false, 1.is_var_reference()); +assert_equal(true, 1.is_var_pointer()); +assert_equal(false, 1.is_var_null()); +assert_equal(false, 1.is_var_undef()); +var i; +assert_equal(true, i.is_var_undef()); diff --git a/unittests/3.x/collate.chai b/unittests/3.x/collate.chai new file mode 100644 index 00000000..12632e59 --- /dev/null +++ b/unittests/3.x/collate.chai @@ -0,0 +1,3 @@ +var v = collate(1, 2) +assert_equal(1, v[0]) +assert_equal(2, v[1]) diff --git a/unittests/3.x/compare_gt.chai b/unittests/3.x/compare_gt.chai new file mode 100644 index 00000000..9a6ea456 --- /dev/null +++ b/unittests/3.x/compare_gt.chai @@ -0,0 +1 @@ +assert_equal(false, 1 > 2); diff --git a/unittests/3.x/compare_lt.chai b/unittests/3.x/compare_lt.chai new file mode 100644 index 00000000..60641103 --- /dev/null +++ b/unittests/3.x/compare_lt.chai @@ -0,0 +1 @@ +assert_equal(true, 1 < 2) diff --git a/unittests/3.x/concat.chai b/unittests/3.x/concat.chai new file mode 100644 index 00000000..3d285a5b --- /dev/null +++ b/unittests/3.x/concat.chai @@ -0,0 +1,5 @@ +var v = concat([1, 2], [3, 4]); + +assert_equal(4, v.size()); +assert_equal(1, v[0]); +assert_equal(4, v[3]); diff --git a/unittests/3.x/const_range_test.chai b/unittests/3.x/const_range_test.chai new file mode 100644 index 00000000..5ebb5808 --- /dev/null +++ b/unittests/3.x/const_range_test.chai @@ -0,0 +1,4 @@ +//If the following succeeds, the test passes + + +"Hello World".for_each(fun(x) { print(x) } ) diff --git a/unittests/3.x/convert_double_string.chai b/unittests/3.x/convert_double_string.chai new file mode 100644 index 00000000..e12b90f2 --- /dev/null +++ b/unittests/3.x/convert_double_string.chai @@ -0,0 +1 @@ +assert_equal("3.5bob", 3.5.to_string() + "bob"); diff --git a/unittests/3.x/convert_int_string.chai b/unittests/3.x/convert_int_string.chai new file mode 100644 index 00000000..0fcda326 --- /dev/null +++ b/unittests/3.x/convert_int_string.chai @@ -0,0 +1 @@ +assert_equal("3bob", 3.to_string + "bob") diff --git a/unittests/3.x/convert_string_double.chai b/unittests/3.x/convert_string_double.chai new file mode 100644 index 00000000..b7b0b6ef --- /dev/null +++ b/unittests/3.x/convert_string_double.chai @@ -0,0 +1 @@ +assert_equal(6.8, "3.5".to_double() + 3.3) diff --git a/unittests/3.x/convert_string_int.chai b/unittests/3.x/convert_string_int.chai new file mode 100644 index 00000000..e62eec95 --- /dev/null +++ b/unittests/3.x/convert_string_int.chai @@ -0,0 +1 @@ +assert_equal(8, "4".to_int() + 4) diff --git a/unittests/3.x/deep_array_lookup.chai b/unittests/3.x/deep_array_lookup.chai new file mode 100644 index 00000000..c405302d --- /dev/null +++ b/unittests/3.x/deep_array_lookup.chai @@ -0,0 +1,11 @@ +var a = [1,2,3, [4,5,6] ] + +assert_equal(a[3][0], 4) + + +def Test::Test() { this.a = [1,2,3]; } +attr Test::a; + +var t = Test(); + +assert_equal(t.a[0], 1) diff --git a/unittests/3.x/dispatch_functions.chai b/unittests/3.x/dispatch_functions.chai new file mode 100644 index 00000000..528d5b30 --- /dev/null +++ b/unittests/3.x/dispatch_functions.chai @@ -0,0 +1,11 @@ +assert_equal(`==`, `==`); +assert_not_equal(`==`, `<`); +assert_equal(`<`.get_arity(), 2); +assert_equal(`+`.get_annotation(), "Multiple method dispatch function wrapper."); +assert_equal(get_arity.get_contained_functions().size(), 0); +assert_equal(get_arity.get_arity(), 1); +assert_equal(get_arity.get_param_types().size(), 2); + +var paramtypes = get_arity.get_param_types(); + +assert_equal(true, paramtypes[1].bare_equal(Function_type)); diff --git a/unittests/3.x/drop.chai b/unittests/3.x/drop.chai new file mode 100644 index 00000000..c64b431e --- /dev/null +++ b/unittests/3.x/drop.chai @@ -0,0 +1 @@ +assert_equal([3,4], drop([1, 2, 3, 4], 2)) diff --git a/unittests/3.x/drop_while.chai b/unittests/3.x/drop_while.chai new file mode 100644 index 00000000..08e19f2f --- /dev/null +++ b/unittests/3.x/drop_while.chai @@ -0,0 +1 @@ +assert_equal([2, 3], drop_while([1, 2, 3], odd)) diff --git a/unittests/3.x/dynamic_object_test.cpp b/unittests/3.x/dynamic_object_test.cpp new file mode 100644 index 00000000..8383e039 --- /dev/null +++ b/unittests/3.x/dynamic_object_test.cpp @@ -0,0 +1,44 @@ +#include + +template +void assert_equal(const LHS &lhs, const RHS &rhs) +{ + if (lhs==rhs) + { + return; + } else { + std::cout << "Got: " << lhs << " expected " << rhs << std::endl; + exit(EXIT_FAILURE); + } +} + +int main() +{ + + chaiscript::ChaiScript chai; + + chai("attr bob::z; def bob::bob() { this.z = 10 }; var x = bob()"); + + chaiscript::dispatch::Dynamic_Object &mydo = chai.eval("x"); + + assert_equal(mydo.get_type_name(), "bob"); + + assert_equal(chaiscript::boxed_cast(mydo.get_attr("z")), 10); + + chai("x.z = 15"); + + assert_equal(chaiscript::boxed_cast(mydo.get_attr("z")), 15); + + int &z = chaiscript::boxed_cast(mydo.get_attr("z")); + + assert_equal(z, 15); + + z = 20; + + assert_equal(z, 20); + + assert_equal(chaiscript::boxed_cast(chai("x.z")), 20); + + return EXIT_SUCCESS; + +} diff --git a/unittests/3.x/empty.chai b/unittests/3.x/empty.chai new file mode 100644 index 00000000..e69de29b diff --git a/unittests/3.x/equ_shortform.chai b/unittests/3.x/equ_shortform.chai new file mode 100644 index 00000000..41c8e1de --- /dev/null +++ b/unittests/3.x/equ_shortform.chai @@ -0,0 +1,4 @@ +var x=.5 +assert_equal(.5, x) +var y=-.5 +assert_equal(-.5, y) diff --git a/unittests/3.x/eval.chai b/unittests/3.x/eval.chai new file mode 100644 index 00000000..2f18aa41 --- /dev/null +++ b/unittests/3.x/eval.chai @@ -0,0 +1 @@ +assert_equal(7, eval("3 + 4")) diff --git a/unittests/3.x/eval_catch_exception_test.cpp b/unittests/3.x/eval_catch_exception_test.cpp new file mode 100644 index 00000000..c599c091 --- /dev/null +++ b/unittests/3.x/eval_catch_exception_test.cpp @@ -0,0 +1,122 @@ +// Tests to make sure that the order in which function dispatches occur is correct + +#include + +int test_generic() +{ + chaiscript::ChaiScript chai; + + try { + chai.eval("throw(runtime_error(\"error\"));"); + } catch (const chaiscript::Boxed_Value &bv) { + const std::exception &e = chaiscript::boxed_cast(bv); + if (e.what() == std::string("error")) + { + return EXIT_SUCCESS; + } + } + + std::cout << "test_generic failed" << std::endl; + return EXIT_FAILURE; +} + +int test_1() +{ + chaiscript::ChaiScript chai; + + try { + chai.eval("throw(1)", chaiscript::exception_specification()); + } catch (int e) { + if (e == 1) + { + return EXIT_SUCCESS; + } + } + + std::cout << "test_1 failed" << std::endl; + return EXIT_FAILURE; +} + +int test_2() +{ + chaiscript::ChaiScript chai; + + try { + chai.eval("throw(1.0)", chaiscript::exception_specification()); + } catch (const double e) { + if (e == 1.0) + { + return EXIT_SUCCESS; + } + } + + std::cout << "test_2 failed" << std::endl; + return EXIT_FAILURE; +} + +int test_5() +{ + chaiscript::ChaiScript chai; + + try { + chai.eval("throw(runtime_error(\"error\"))", chaiscript::exception_specification()); + } catch (const double e) { + std::cout << "test_5 failed with double" << std::endl; + return EXIT_FAILURE; + } catch (int) { + std::cout << "test_5 failed with int" << std::endl; + return EXIT_FAILURE; + } catch (float) { + std::cout << "test_5 failed with float" << std::endl; + return EXIT_FAILURE; + } catch (const std::string &) { + std::cout << "test_5 failed with string" << std::endl; + return EXIT_FAILURE; + } catch (const std::exception &e) { + return EXIT_SUCCESS; + } + + std::cout << "test_5 failed" << std::endl; + return EXIT_FAILURE; +} + +int test_unhandled() +{ + chaiscript::ChaiScript chai; + + try { + chai.eval("throw(\"error\")", chaiscript::exception_specification()); + } catch (double) { + std::cout << "test_unhandled failed with double" << std::endl; + return EXIT_FAILURE; + } catch (int) { + std::cout << "test_unhandled failed with int" << std::endl; + return EXIT_FAILURE; + } catch (float) { + std::cout << "test_unhandled failed with float" << std::endl; + return EXIT_FAILURE; + } catch (const std::exception &e) { + std::cout << "test_unhandled failed with std::exception" << std::endl; + return EXIT_FAILURE; + } catch (const chaiscript::Boxed_Value &bv) { + return EXIT_SUCCESS; + } + + std::cout << "test_unhandled failed" << std::endl; + return EXIT_FAILURE; +} + + +int main() +{ + if (test_generic() == EXIT_SUCCESS + && test_1() == EXIT_SUCCESS + && test_2() == EXIT_SUCCESS + && test_5() == EXIT_SUCCESS + && test_unhandled() == EXIT_SUCCESS) + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } +} diff --git a/unittests/3.x/eval_error.chai b/unittests/3.x/eval_error.chai new file mode 100644 index 00000000..d63ad759 --- /dev/null +++ b/unittests/3.x/eval_error.chai @@ -0,0 +1,39 @@ +load_module("reflection") + +def deep() +{ + try { + } catch { + + } finally { + if (2) + { + } + + } +} + +def func() +{ + deep(); +} + +def doing() +{ + for (var i = 0; i < 10; ++i) + { + func(); + } +} + +def while_doing() +{ + while (true) + { + doing(); + } +} + +var f = fun() { while_doing(); } + +assert_equal(get_eval_error(f).call_stack.size(), 16) diff --git a/unittests/3.x/even.chai b/unittests/3.x/even.chai new file mode 100644 index 00000000..5a9a9aea --- /dev/null +++ b/unittests/3.x/even.chai @@ -0,0 +1 @@ +assert_equal(true, even(4)) diff --git a/unittests/3.x/exception.chai b/unittests/3.x/exception.chai new file mode 100644 index 00000000..50df6a80 --- /dev/null +++ b/unittests/3.x/exception.chai @@ -0,0 +1,9 @@ +var x = 1 +try { + throw(x) + x = 2 +} +catch(e) { + x = e + 3 +} +assert_equal(4, x); diff --git a/unittests/3.x/exception_finally.chai b/unittests/3.x/exception_finally.chai new file mode 100644 index 00000000..d6fd834a --- /dev/null +++ b/unittests/3.x/exception_finally.chai @@ -0,0 +1,32 @@ +var finallyone = false; + +try { + throw(3) +} +catch(x) { + assert_equal(3, x) +} +finally { + finallyone = true; +} + +assert_equal(true, finallyone); + +var try2 = false; +var catch2 = false; +var finally2 = false; + + +try { + try2 = true; +} +catch { + catch2 = true; +} +finally { + finally2 = true; +} + +assert_equal(true, try2); +assert_equal(false, catch2); +assert_equal(true, finally2); diff --git a/unittests/3.x/exception_guards.chai b/unittests/3.x/exception_guards.chai new file mode 100644 index 00000000..99cd9018 --- /dev/null +++ b/unittests/3.x/exception_guards.chai @@ -0,0 +1,34 @@ +var results = []; + +for (var i = 2; i < 6; ++i) { + try { + throw(i) + } + catch(e) : e < 2 { + results.push_back("c1: " + e.to_string()); + } + catch(e) : e < 4 { + results.push_back("c2: " + e.to_string()); + } + catch(e) { + results.push_back("c3: " + e.to_string()); + } + catch { + // Should never get called + assert_equal(false, true) + } +} + +try { + throw(3) +} +catch(e) : e < 3 +{ + // Should never get called + assert_equal(false, true); +} +catch { + results.push_back("defaultcatch"); +} + +assert_equal(["c2: 2", "c2: 3", "c3: 4", "c3: 5", "defaultcatch"], results); diff --git a/unittests/3.x/filter.chai b/unittests/3.x/filter.chai new file mode 100644 index 00000000..6d805fee --- /dev/null +++ b/unittests/3.x/filter.chai @@ -0,0 +1 @@ +assert_equal([1,3], filter([1, 2, 3, 4], odd)) diff --git a/unittests/3.x/float.chai b/unittests/3.x/float.chai new file mode 100644 index 00000000..b1bdf299 --- /dev/null +++ b/unittests/3.x/float.chai @@ -0,0 +1,7 @@ +assert_equal(true, 1.2 < 2) +assert_equal(true, 1.2 > 1) +assert_equal(1.2, 1.2) + +assert_equal(true, .5 > 0) +assert_equal(true, .5 < 1) +assert_equal(0.5, .5) diff --git a/unittests/3.x/foldl.chai b/unittests/3.x/foldl.chai new file mode 100644 index 00000000..7e9db51f --- /dev/null +++ b/unittests/3.x/foldl.chai @@ -0,0 +1 @@ +assert_equal(10, foldl([1, 2, 3, 4], `+`, 0)) diff --git a/unittests/3.x/for.chai b/unittests/3.x/for.chai new file mode 100644 index 00000000..9799be24 --- /dev/null +++ b/unittests/3.x/for.chai @@ -0,0 +1,7 @@ +var ret = [] + +for (var i = 0; i < 5; ++i) { + ret.push_back(i); +} + +assert_equal([0,1,2,3,4], ret); diff --git a/unittests/3.x/for_each.chai b/unittests/3.x/for_each.chai new file mode 100644 index 00000000..242a1baf --- /dev/null +++ b/unittests/3.x/for_each.chai @@ -0,0 +1 @@ +for_each([1, 2, 3], print) diff --git a/unittests/3.x/for_each_range.chai b/unittests/3.x/for_each_range.chai new file mode 100644 index 00000000..43191bfb --- /dev/null +++ b/unittests/3.x/for_each_range.chai @@ -0,0 +1,3 @@ +var v = [1,2,3]; +var r = range(v); +for_each(r, fun(x) { assert_equal(true, x>0); } ) diff --git a/unittests/3.x/for_each_retro.chai b/unittests/3.x/for_each_retro.chai new file mode 100644 index 00000000..cc27a580 --- /dev/null +++ b/unittests/3.x/for_each_retro.chai @@ -0,0 +1,4 @@ +// Don't bother checking the output from this one, just makes sure it executes +var v = [1,2,3]; +var r = retro(range(v)); +for_each(r, print) diff --git a/unittests/3.x/function_array_adjacent.chai b/unittests/3.x/function_array_adjacent.chai new file mode 100644 index 00000000..c34e2be9 --- /dev/null +++ b/unittests/3.x/function_array_adjacent.chai @@ -0,0 +1 @@ +assert_equal(2, `+`.get_contained_functions()[0].get_arity()) diff --git a/unittests/3.x/function_introspection.chai b/unittests/3.x/function_introspection.chai new file mode 100644 index 00000000..5ad76fc7 --- /dev/null +++ b/unittests/3.x/function_introspection.chai @@ -0,0 +1,76 @@ + +#Test Function Description +def test_function(a) +{ + return a; +} + + + + +// test_function tests +assert_equal(test_function.get_arity(), 1); +assert_equal(trim(test_function.get_annotation()), "#Test Function Description"); +assert_equal(test_function.get_contained_functions().size(), 0); +assert_equal(test_function.get_param_types().size(), 2); + +assert_equal(test_function, test_function); + +assert_not_equal(test_function, `+`); + +assert_equal(test_function.call([1]), 1); + +// dynamic object function tests + +def int::test_fun() +{ + return this; +} + +assert_equal(test_fun.get_arity(), 1); +assert_equal(test_fun.get_contained_functions.size(), 1); +assert_equal(test_fun.get_param_types().size(), 2); +assert_equal(test_fun, test_fun); +var test_fun_types = test_fun.get_param_types(); +assert_equal(true, test_fun_types[0].bare_equal(Object_type)); +assert_equal(true, test_fun_types[1].bare_equal(int_type)); + + +// built-ins tests + +assert_equal(2, `==`.get_arity()); + +// < should be the merging of two functions bool <(PODObject, PODObject) and bool <(string, string) +// we want to peel it apart and make sure that's true +var types = `<`.get_param_types(); +assert_equal(3, types.size()); +assert_equal(true, types[0].bare_equal(bool_type)); +assert_equal(true, types[1].bare_equal(Object_type)); +assert_equal(true, types[2].bare_equal(Object_type)); +assert_equal(2, `<`.get_contained_functions().size()); + + +// guard existence tests + +def with_guard(x) : x > 3 {} +def without_guard(x) {} + +def group_guard(x) {} +def group_guard(x) : x > 3 {} + +assert_equal(true, with_guard.has_guard()); +assert_equal(false, without_guard.has_guard()); + +assert_equal(2, group_guard.get_contained_functions().size()); +var group = group_guard.get_contained_functions(); + +assert_equal(true, group[0].has_guard()) +assert_equal(false, group[1].has_guard()) + +assert_throws("Function does not have a guard", fun() { group[0].get_guard(); } ); +assert_throws("Function does not have a guard", fun() { without_guard.get_guard(); } ); + +var guard = with_guard.get_guard(); + +assert_equal(false, guard.has_guard()); +assert_throws("Function does not have a guard", fun() { guard.get_guard(); } ); diff --git a/unittests/3.x/function_ordering_test.cpp b/unittests/3.x/function_ordering_test.cpp new file mode 100644 index 00000000..0a9652c6 --- /dev/null +++ b/unittests/3.x/function_ordering_test.cpp @@ -0,0 +1,38 @@ +// Tests to make sure that the order in which function dispatches occur is correct + +#include + +int test_one(const int &) +{ + return 1; +} + +int test_two(int &) +{ + return 2; +} + +int main() +{ + chaiscript::ChaiScript chai; + chai.eval("def test_fun(x) { return 3; }"); + chai.eval("def test_fun(x) : x == \"hi\" { return 4; }"); + chai.eval("def test_fun(x) { return 5; }"); + chai.add(chaiscript::fun(&test_one), "test_fun"); + chai.add(chaiscript::fun(&test_two), "test_fun"); + + int res1 = chai.eval("test_fun(1)"); + int res2 = chai.eval("var i = 1; test_fun(i)"); + int res3 = chai.eval("test_fun(\"bob\")"); + int res4 = chai.eval("test_fun(\"hi\")"); + + if (res1 == 1 + && res2 == 2 + && res3 == 3 + && res4 == 4 ) + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } +} diff --git a/unittests/3.x/function_reassignment.chai b/unittests/3.x/function_reassignment.chai new file mode 100644 index 00000000..2a885fdc --- /dev/null +++ b/unittests/3.x/function_reassignment.chai @@ -0,0 +1,3 @@ +var x = `+` +x = `-` +assert_equal(1, x(5,4)) diff --git a/unittests/3.x/functor_cast_test.cpp b/unittests/3.x/functor_cast_test.cpp new file mode 100644 index 00000000..1f6f7ec1 --- /dev/null +++ b/unittests/3.x/functor_cast_test.cpp @@ -0,0 +1,25 @@ +#include + +double test_call(const boost::function &f, int val) +{ + return f(val); +} + +int main() +{ + + chaiscript::ChaiScript chai; + + chai.add(chaiscript::fun(&test_call), "test_call"); + + chai.eval("def func(i) { return i * 3.5; };"); + double d = chai.eval("test_call(func, 3)"); + + if (d == 3 * 3.5) + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } + +} diff --git a/unittests/3.x/functor_creation_test.cpp b/unittests/3.x/functor_creation_test.cpp new file mode 100644 index 00000000..6578a6d5 --- /dev/null +++ b/unittests/3.x/functor_creation_test.cpp @@ -0,0 +1,26 @@ +#include + +int main() +{ + + chaiscript::ChaiScript chai; + + chai.eval("def func() { print(\"Hello World\"); } "); + + boost::function f = chai.eval >("func"); + f(); + + if (chai.eval >("to_string")(6) != "6") + { + return EXIT_FAILURE; + } + + if (chai.eval >("to_string")(chaiscript::var(6)) == "6") + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } + + +} diff --git a/unittests/3.x/generate_range.chai b/unittests/3.x/generate_range.chai new file mode 100644 index 00000000..9e25970a --- /dev/null +++ b/unittests/3.x/generate_range.chai @@ -0,0 +1 @@ +assert_equal([1,2,3,4,5,6,7,8,9,10], generate_range(1, 10)) diff --git a/unittests/3.x/global_const_in_module.chai b/unittests/3.x/global_const_in_module.chai new file mode 100644 index 00000000..c9ca65a6 --- /dev/null +++ b/unittests/3.x/global_const_in_module.chai @@ -0,0 +1,7 @@ +load_module("test_module") + + +assert_equal(to_int(TestValue1), 1) + +assert_equal(TestValue1.type_name(), "TestEnum") + diff --git a/unittests/3.x/if.chai b/unittests/3.x/if.chai new file mode 100644 index 00000000..3ec7321b --- /dev/null +++ b/unittests/3.x/if.chai @@ -0,0 +1,7 @@ +var t = false; + +if (true) { + t = true; +} + +assert_equal(true, t); diff --git a/unittests/3.x/if_else.chai b/unittests/3.x/if_else.chai new file mode 100644 index 00000000..8cb42db9 --- /dev/null +++ b/unittests/3.x/if_else.chai @@ -0,0 +1,13 @@ +var i = 3 +var b1 = false; +var b2 = false; + +if (i == 2) { + b1 = true; +} +else { + b2 = true; +} + +assert_equal(false, b1); +assert_equal(true, b2); diff --git a/unittests/3.x/if_elseif.chai b/unittests/3.x/if_elseif.chai new file mode 100644 index 00000000..75b85b5f --- /dev/null +++ b/unittests/3.x/if_elseif.chai @@ -0,0 +1,18 @@ +var b1 = false; +var b2 = false; +var b3 = false; + +var i = 3 +if (i == 2) { + b1 = true; +} +else if (i == 4) { + b2 = true; +} +else if (i == 3) { + b3 = true; +} + +assert_equal(false, b1); +assert_equal(false, b2); +assert_equal(true, b3); diff --git a/unittests/3.x/if_elseif_else.chai b/unittests/3.x/if_elseif_else.chai new file mode 100644 index 00000000..26ed0d26 --- /dev/null +++ b/unittests/3.x/if_elseif_else.chai @@ -0,0 +1,14 @@ +var i = 3 +var b = false +if (i == 2) { + assert_equal(false, true) +} +else if (i == 4) { + assert_equal(false, true) +} +else { + assert_equal(true, true) + b = true +} + +assert_equal(true, b) diff --git a/unittests/3.x/index_operator.chai b/unittests/3.x/index_operator.chai new file mode 100644 index 00000000..e8af5cf6 --- /dev/null +++ b/unittests/3.x/index_operator.chai @@ -0,0 +1,10 @@ + +// tests more complex parses of the index operator + +def Bob::bob3() { return [1,2,3]; } +def Bob::Bob() {} +var b = Bob(); + + +assert_equal(b.bob3()[0], 1); +assert_equal((b.bob3())[1], 2); diff --git a/unittests/3.x/inheritance.chai b/unittests/3.x/inheritance.chai new file mode 100644 index 00000000..1fcd346b --- /dev/null +++ b/unittests/3.x/inheritance.chai @@ -0,0 +1,8 @@ +load_module("test_module") + +var t0 = TestBaseType() +var t = TestDerivedType(); + +assert_equal(t0.func(), 0); +assert_equal(t.func(), 1); + diff --git a/unittests/3.x/instring_eval.chai b/unittests/3.x/instring_eval.chai new file mode 100644 index 00000000..a72b2fc4 --- /dev/null +++ b/unittests/3.x/instring_eval.chai @@ -0,0 +1,3 @@ +var bob = 5.5 +assert_equal("5.5", "${bob}") +assert_equal("val: 8 and 8", "val: ${5.5 + 2.5} and ${bob + 2.5}") diff --git a/unittests/3.x/instring_eval_more.chai b/unittests/3.x/instring_eval_more.chai new file mode 100644 index 00000000..17768f82 --- /dev/null +++ b/unittests/3.x/instring_eval_more.chai @@ -0,0 +1,4 @@ +assert_equal("\$ {4 + 5}", "$ {4 + 5}") +assert_equal("\$9", "$${4+5}") +assert_equal("Value: \${4 + 5}", "Value: \${4 + 5}") +assert_equal("Value: \$9", "Value: \$${4 + 5}") diff --git a/unittests/3.x/invalid_function_assignment.chai b/unittests/3.x/invalid_function_assignment.chai new file mode 100644 index 00000000..99b098db --- /dev/null +++ b/unittests/3.x/invalid_function_assignment.chai @@ -0,0 +1 @@ +assert_throws("Illegal const function assignment", fun() { clone = `-` } ); diff --git a/unittests/3.x/invalid_function_reassignment.chai b/unittests/3.x/invalid_function_reassignment.chai new file mode 100644 index 00000000..cc7cb5af --- /dev/null +++ b/unittests/3.x/invalid_function_reassignment.chai @@ -0,0 +1 @@ +assert_throws("Invalid function reassignment", fun() { var x = 5; x = `-`; } ); diff --git a/unittests/3.x/is_undef.chai b/unittests/3.x/is_undef.chai new file mode 100644 index 00000000..38572f0f --- /dev/null +++ b/unittests/3.x/is_undef.chai @@ -0,0 +1,4 @@ +var i; +assert_equal(true, i.is_var_undef()); +i = 5; +assert_equal(false, i.is_var_undef()); diff --git a/unittests/3.x/join.chai b/unittests/3.x/join.chai new file mode 100644 index 00000000..1891c468 --- /dev/null +++ b/unittests/3.x/join.chai @@ -0,0 +1 @@ +assert_equal("1*2*3", join([1, 2, 3], "*")) diff --git a/unittests/3.x/lambda.chai b/unittests/3.x/lambda.chai new file mode 100644 index 00000000..6b65a1ba --- /dev/null +++ b/unittests/3.x/lambda.chai @@ -0,0 +1,2 @@ +var bob = fun(x) { x + 1 } +assert_equal(4, bob(3)); diff --git a/unittests/3.x/list_push_back.chai b/unittests/3.x/list_push_back.chai new file mode 100644 index 00000000..4d88deb8 --- /dev/null +++ b/unittests/3.x/list_push_back.chai @@ -0,0 +1,8 @@ +load_module("stl_extra") + +var x = List() +x.push_back(3) +x.push_back("A") + +assert_equal(3, x.front()); +assert_equal("A", x.back()); diff --git a/unittests/3.x/list_push_front.chai b/unittests/3.x/list_push_front.chai new file mode 100644 index 00000000..86e28329 --- /dev/null +++ b/unittests/3.x/list_push_front.chai @@ -0,0 +1,8 @@ +load_module("stl_extra") + +var x = List() +x.push_front(3) +x.push_front("A") + +assert_equal("A", x.front()); +assert_equal(3, x.back()); diff --git a/unittests/3.x/load_module.chai b/unittests/3.x/load_module.chai new file mode 100644 index 00000000..a231a200 --- /dev/null +++ b/unittests/3.x/load_module.chai @@ -0,0 +1,2 @@ +load_module("test_module") +assert_equal("Hello World", hello_world()); diff --git a/unittests/3.x/loop_inner_outer.chai b/unittests/3.x/loop_inner_outer.chai new file mode 100644 index 00000000..64a25e6e --- /dev/null +++ b/unittests/3.x/loop_inner_outer.chai @@ -0,0 +1,9 @@ +var total = 0 + +for (var i = 0; i < 10; ++i) { + for (var j = 0; j < 10; ++j) { + total += 1 + } +} + +assert_equal(100, total); diff --git a/unittests/3.x/malformed_inline_map.chai b/unittests/3.x/malformed_inline_map.chai new file mode 100644 index 00000000..d267bcfe --- /dev/null +++ b/unittests/3.x/malformed_inline_map.chai @@ -0,0 +1,2 @@ + +assert_throws("Parse failure", fun() { eval("[\"hello\":5,\"j\",\"k\"]") } ); diff --git a/unittests/3.x/map.chai b/unittests/3.x/map.chai new file mode 100644 index 00000000..a0a31ee1 --- /dev/null +++ b/unittests/3.x/map.chai @@ -0,0 +1 @@ +assert_equal([true, false, true], map([1,2,3], odd)) diff --git a/unittests/3.x/map_access.chai b/unittests/3.x/map_access.chai new file mode 100644 index 00000000..19ebc1ad --- /dev/null +++ b/unittests/3.x/map_access.chai @@ -0,0 +1,2 @@ +var x = ["bob":2, "fred":3] +assert_equal(3, x["fred"]) diff --git a/unittests/3.x/map_inplace_init.chai b/unittests/3.x/map_inplace_init.chai new file mode 100644 index 00000000..b1d8221b --- /dev/null +++ b/unittests/3.x/map_inplace_init.chai @@ -0,0 +1,3 @@ +var x = ["bob":1, "fred":2] + +assert_equal(2, x.size()); diff --git a/unittests/3.x/math_add.chai b/unittests/3.x/math_add.chai new file mode 100644 index 00000000..bcb90369 --- /dev/null +++ b/unittests/3.x/math_add.chai @@ -0,0 +1 @@ +assert_equal(3, (1 + 2)) diff --git a/unittests/3.x/math_add_mixed.chai b/unittests/3.x/math_add_mixed.chai new file mode 100644 index 00000000..b000cafe --- /dev/null +++ b/unittests/3.x/math_add_mixed.chai @@ -0,0 +1 @@ +assert_equal(3.5, 1.5 + 2) diff --git a/unittests/3.x/math_dec.chai b/unittests/3.x/math_dec.chai new file mode 100644 index 00000000..e746f298 --- /dev/null +++ b/unittests/3.x/math_dec.chai @@ -0,0 +1,3 @@ +var i = 3 +assert_equal(2, --i) +assert_equal(2, i) diff --git a/unittests/3.x/math_div.chai b/unittests/3.x/math_div.chai new file mode 100644 index 00000000..971f2170 --- /dev/null +++ b/unittests/3.x/math_div.chai @@ -0,0 +1 @@ +assert_equal(2, 10/5) diff --git a/unittests/3.x/math_inc.chai b/unittests/3.x/math_inc.chai new file mode 100644 index 00000000..ec317c03 --- /dev/null +++ b/unittests/3.x/math_inc.chai @@ -0,0 +1,3 @@ +var i = 3 +assert_equal(4, ++i) +assert_equal(4, i) diff --git a/unittests/3.x/math_mod.chai b/unittests/3.x/math_mod.chai new file mode 100644 index 00000000..326c35a9 --- /dev/null +++ b/unittests/3.x/math_mod.chai @@ -0,0 +1 @@ +assert_equal(2, 11 % 3) diff --git a/unittests/3.x/math_mult.chai b/unittests/3.x/math_mult.chai new file mode 100644 index 00000000..94c355d6 --- /dev/null +++ b/unittests/3.x/math_mult.chai @@ -0,0 +1 @@ +assert_equal(12, 3 * 4) diff --git a/unittests/3.x/math_negate.chai b/unittests/3.x/math_negate.chai new file mode 100644 index 00000000..36bae880 --- /dev/null +++ b/unittests/3.x/math_negate.chai @@ -0,0 +1 @@ +assert_equal(-7, -(3 + 4)) diff --git a/unittests/3.x/math_paren.chai b/unittests/3.x/math_paren.chai new file mode 100644 index 00000000..01b7f205 --- /dev/null +++ b/unittests/3.x/math_paren.chai @@ -0,0 +1 @@ +assert_equal(27, 3*(4+5)) diff --git a/unittests/3.x/math_sub.chai b/unittests/3.x/math_sub.chai new file mode 100644 index 00000000..7e8342c1 --- /dev/null +++ b/unittests/3.x/math_sub.chai @@ -0,0 +1 @@ +assert_equal(2, 5 - 3) diff --git a/unittests/3.x/max.chai b/unittests/3.x/max.chai new file mode 100644 index 00000000..533e7e84 --- /dev/null +++ b/unittests/3.x/max.chai @@ -0,0 +1 @@ +assert_equal(5, max(3, 5)) diff --git a/unittests/3.x/memberscope.chai b/unittests/3.x/memberscope.chai new file mode 100644 index 00000000..fe46810a --- /dev/null +++ b/unittests/3.x/memberscope.chai @@ -0,0 +1,12 @@ +attr Vector3::x +attr Vector3::y +attr Vector3::z + +def Vector3::Vector3(x, y, z) { + this.x = x + this.y = y + this.z = z +} + +var v = Vector3(1,2,3); +assert_equal(1, v.x); diff --git a/unittests/3.x/method_sugar.chai b/unittests/3.x/method_sugar.chai new file mode 100644 index 00000000..521400bc --- /dev/null +++ b/unittests/3.x/method_sugar.chai @@ -0,0 +1 @@ +assert_equal(6, [1, 2, 3].sum()) diff --git a/unittests/3.x/min.chai b/unittests/3.x/min.chai new file mode 100644 index 00000000..0ef1ba79 --- /dev/null +++ b/unittests/3.x/min.chai @@ -0,0 +1 @@ +assert_equal(3, min(3, 5)) diff --git a/unittests/3.x/mmd1.chai b/unittests/3.x/mmd1.chai new file mode 100644 index 00000000..ff38a3c5 --- /dev/null +++ b/unittests/3.x/mmd1.chai @@ -0,0 +1,20 @@ +def bob(x, y, z) { + x + y + z +} + +def bob(x, y) { + x - y +} + +def bob(x) { + -x +} + +def bob() { + 10 +} + +assert_equal(10, bob()) +assert_equal(-5, bob(5)) +assert_equal(-1, bob(5,6)) +assert_equal(18, bob(5,6,7)) diff --git a/unittests/3.x/mmd2.chai b/unittests/3.x/mmd2.chai new file mode 100644 index 00000000..1c5f1771 --- /dev/null +++ b/unittests/3.x/mmd2.chai @@ -0,0 +1,9 @@ +def bob(x, y) : x > 10 { x - y } + +def bob(x, y) : x > 5 { x - y + 10 } + +def bob(x, y) { x + y } + +assert_equal(7, bob(3,4)) +assert_equal(9, bob(6,7)) +assert_equal(-1, bob(11,12)) diff --git a/unittests/3.x/multifile_test_chai.cpp b/unittests/3.x/multifile_test_chai.cpp new file mode 100644 index 00000000..57b89528 --- /dev/null +++ b/unittests/3.x/multifile_test_chai.cpp @@ -0,0 +1,12 @@ +#include "multifile_test_chai.hpp" + +Multi_Test_Chai::Multi_Test_Chai() + : m_chai(new chaiscript::ChaiScript()) +{ +} + + +boost::shared_ptr Multi_Test_Chai::get_chai() +{ + return m_chai; +} diff --git a/unittests/3.x/multifile_test_chai.hpp b/unittests/3.x/multifile_test_chai.hpp new file mode 100644 index 00000000..430b6bc5 --- /dev/null +++ b/unittests/3.x/multifile_test_chai.hpp @@ -0,0 +1,14 @@ +#include + +class Multi_Test_Chai +{ + public: + Multi_Test_Chai(); + + boost::shared_ptr get_chai(); + + private: + boost::shared_ptr m_chai; +}; + + diff --git a/unittests/3.x/multifile_test_main.cpp b/unittests/3.x/multifile_test_main.cpp new file mode 100644 index 00000000..8352ec8b --- /dev/null +++ b/unittests/3.x/multifile_test_main.cpp @@ -0,0 +1,14 @@ +#include "multifile_test_chai.hpp" +#include "multifile_test_module.hpp" + +#include + +int main() +{ + Multi_Test_Chai chaitest; + Multi_Test_Module chaimodule; + + boost::shared_ptr chai = chaitest.get_chai(); + chai->add(chaimodule.get_module()); + return chai->eval("get_module_value()"); +} diff --git a/unittests/3.x/multifile_test_module.cpp b/unittests/3.x/multifile_test_module.cpp new file mode 100644 index 00000000..2457416f --- /dev/null +++ b/unittests/3.x/multifile_test_module.cpp @@ -0,0 +1,21 @@ +#include + +#include "multifile_test_module.hpp" + +Multi_Test_Module::Multi_Test_Module() +{ +} + +int Multi_Test_Module::get_module_value() +{ + return 0; +} + +chaiscript::ModulePtr Multi_Test_Module::get_module() +{ + chaiscript::ModulePtr module(new chaiscript::Module()); + + module->add(chaiscript::fun(&Multi_Test_Module::get_module_value), "get_module_value"); + + return module; +} diff --git a/unittests/3.x/multifile_test_module.hpp b/unittests/3.x/multifile_test_module.hpp new file mode 100644 index 00000000..f01d8f1a --- /dev/null +++ b/unittests/3.x/multifile_test_module.hpp @@ -0,0 +1,11 @@ +#include + +class Multi_Test_Module +{ + public: + static int get_module_value(); + + Multi_Test_Module(); + + chaiscript::ModulePtr get_module(); +}; diff --git a/unittests/3.x/multiline.chai b/unittests/3.x/multiline.chai new file mode 100644 index 00000000..f13be4e6 --- /dev/null +++ b/unittests/3.x/multiline.chai @@ -0,0 +1,9 @@ +var x = [1, 2, + 3, 4] + +assert_equal(1, x[0]) + +var y = map(x, + fun(x) { x + 1 }) + +assert_equal(2, y[0]) diff --git a/unittests/3.x/number_formats.chai b/unittests/3.x/number_formats.chai new file mode 100644 index 00000000..c80ece04 --- /dev/null +++ b/unittests/3.x/number_formats.chai @@ -0,0 +1,3 @@ +assert_equal(10, 012) +assert_equal(31, 0x1f) +assert_equal(3, 0b11) diff --git a/unittests/3.x/object_attr.chai b/unittests/3.x/object_attr.chai new file mode 100644 index 00000000..c2da08ea --- /dev/null +++ b/unittests/3.x/object_attr.chai @@ -0,0 +1,6 @@ +attr bob::z +def bob::bob() { this.z = 10 } +var x = bob() +def bob::fred(x) { this.z - x } + +assert_equal(7, x.fred(3)) diff --git a/unittests/3.x/object_attr_same_name.chai b/unittests/3.x/object_attr_same_name.chai new file mode 100644 index 00000000..fa20bac4 --- /dev/null +++ b/unittests/3.x/object_attr_same_name.chai @@ -0,0 +1,9 @@ +attr bob::z +def bob::bob() { this.z = 10 } + +attr bob2::z +def bob2::bob2() { this.z = 12 } + +var b = bob(); +var b2 = bob2(); + diff --git a/unittests/3.x/object_clone.chai b/unittests/3.x/object_clone.chai new file mode 100644 index 00000000..4659f41a --- /dev/null +++ b/unittests/3.x/object_clone.chai @@ -0,0 +1,11 @@ +attr bob::z +def bob::bob() { } + +var x = bob(); +x.z = 10; + +var y = clone(x); +y.z = 20; + +assert_equal(10, x.z) +assert_equal(20, y.z) diff --git a/unittests/3.x/object_constructor_guards.chai b/unittests/3.x/object_constructor_guards.chai new file mode 100644 index 00000000..f48c00a1 --- /dev/null +++ b/unittests/3.x/object_constructor_guards.chai @@ -0,0 +1,10 @@ +attr bob::val + +def bob::bob(x) : x < 10 { this.val = "Less Than Ten: " + x.to_string(); } +def bob::bob(x) { this.val = "Any Other Value: " + x.to_string(); } + +var b = bob(12) +var c = bob(3) + +assert_equal("Any Other Value: 12", b.val ) +assert_equal("Less Than Ten: 3", c.val ) diff --git a/unittests/3.x/object_lifetime_test.cpp b/unittests/3.x/object_lifetime_test.cpp new file mode 100644 index 00000000..d59957b0 --- /dev/null +++ b/unittests/3.x/object_lifetime_test.cpp @@ -0,0 +1,66 @@ +#include + +class Test +{ + public: + Test() + { + ++count(); + } + + Test(const Test &) + { + ++count(); + } + + ~Test() + { + --count(); + } + + static int& count() + { + static int c = 0; + return c; + } +}; + +int main() +{ + chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module()); + + CHAISCRIPT_CLASS( m, + Test, + (Test ()) + (Test (const Test &)), + ((count)) + ); + + chaiscript::ChaiScript chai; + chai.add(m); + chai.add(chaiscript::fun(&Test::count), "count"); + + int count = chai.eval("count()"); + + int count2 = chai.eval("var i = 0; { var t = Test(); } return i;"); + + int count3 = chai.eval("var i = 0; { var t = Test(); i = count(); } return i;"); + + int count4 = chai.eval("var i = 0; { var t = Test(); { var t2 = Test(); i = count(); } } return i;"); + + int count5 = chai.eval("var i = 0; { var t = Test(); { var t2 = Test(); } i = count(); } return i;"); + + int count6 = chai.eval("var i = 0; { var t = Test(); { var t2 = Test(); } } i = count(); return i;"); + + if (count == 0 + && count2 == 0 + && count3 == 1 + && count4 == 2 + && count5 == 1 + && count6 == 0) + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } +} diff --git a/unittests/3.x/object_method_guards.chai b/unittests/3.x/object_method_guards.chai new file mode 100644 index 00000000..addc8508 --- /dev/null +++ b/unittests/3.x/object_method_guards.chai @@ -0,0 +1,7 @@ +def bob::bob() { } +def bob::fred(e) : e < 10 { assert_equal(true, e<10) } +def bob::fred(e) { assert_equal(true, e >= 10) } + +var b = bob() +b.fred(3) +b.fred(12) diff --git a/unittests/3.x/odd.chai b/unittests/3.x/odd.chai new file mode 100644 index 00000000..dbaf2a01 --- /dev/null +++ b/unittests/3.x/odd.chai @@ -0,0 +1 @@ +assert_equal(false, odd(4)) diff --git a/unittests/3.x/operator_overload.chai b/unittests/3.x/operator_overload.chai new file mode 100644 index 00000000..9bd2eb79 --- /dev/null +++ b/unittests/3.x/operator_overload.chai @@ -0,0 +1,9 @@ +def Bob::`+`(y) { this.x + y.x } +def Bob::Bob() { } +attr Bob::x +var b = Bob() +var c = Bob() +b.x = 4 +c.x = 5 + +assert_equal(9, b+c) diff --git a/unittests/3.x/operator_overload2.chai b/unittests/3.x/operator_overload2.chai new file mode 100644 index 00000000..b4afbe7b --- /dev/null +++ b/unittests/3.x/operator_overload2.chai @@ -0,0 +1,9 @@ +def Bob::Bob() { } +attr Bob::x +def `-`(a, b) : is_type(a, "Bob") && is_type(b, "Bob") { a.x - b.x } +var b = Bob() +var c = Bob() +b.x = 4 +c.x = 5 + +assert_equal(-1, b-c) diff --git a/unittests/3.x/operators_float.chai b/unittests/3.x/operators_float.chai new file mode 100644 index 00000000..931606fb --- /dev/null +++ b/unittests/3.x/operators_float.chai @@ -0,0 +1,16 @@ +var i = 1.0; +var j = 2.0; +var k = 3.0; + +assert_equal(3, i + j) +assert_equal(1.0, +i) +assert_equal(-1, i-j) +assert_equal(-1, -i) +assert_equal(1.5, k/j) +assert_equal(6, j*k) + +assert_equal(0, i -= i) +assert_equal(3, j *= 1.5) +assert_equal(1.5, j /= 2) +assert_equal(2.5, j += 1) +assert_throws("No modulus for float", fun() { k % 2 } ); diff --git a/unittests/3.x/operators_int.chai b/unittests/3.x/operators_int.chai new file mode 100644 index 00000000..4627b552 --- /dev/null +++ b/unittests/3.x/operators_int.chai @@ -0,0 +1,31 @@ +var i = 1; +var j = 2; +var k = 3; + +assert_equal(3, i + j); +assert_equal(1, +i); +assert_equal(-1, i - j); +assert_equal(-1, -i); +assert_equal(2, j & k); +assert_equal(-3, ~j); +assert_equal(1, j ^ k); +assert_equal(3, i | j); +assert_equal(2, j / i); +assert_equal(4, i << j); +assert_equal(6, j * k); +assert_equal(1, k % j); +assert_equal(1, j >> i); + +assert_equal(0, i &= 2); +assert_equal(1, j ^= 3); +assert_equal(3, j |= 2); +assert_equal(-1, i -= 1); +assert_equal(6, j <<= 1); +assert_equal(12, j *= 2); +assert_equal(6, j /= 2); +assert_equal(2, j %= 4); +assert_equal(1, j >>= 1); +assert_equal(2, j += 1); +assert_equal(1, --j); +assert_equal(2, ++j); + diff --git a/unittests/3.x/pair.chai b/unittests/3.x/pair.chai new file mode 100644 index 00000000..9b3c8049 --- /dev/null +++ b/unittests/3.x/pair.chai @@ -0,0 +1,5 @@ +var p = Pair("Hello", "World") + +assert_equal(p.first, "Hello") +assert_equal(p.second, "World") + diff --git a/unittests/3.x/pointer_passed_to_constructor.chai b/unittests/3.x/pointer_passed_to_constructor.chai new file mode 100644 index 00000000..6495ee38 --- /dev/null +++ b/unittests/3.x/pointer_passed_to_constructor.chai @@ -0,0 +1,8 @@ +load_module("test_module") + +var i = 1; +var t0 = TestBaseType(i); + +var t1 = TestBaseType(get_new_int()) + + diff --git a/unittests/3.x/precedence_1.chai b/unittests/3.x/precedence_1.chai new file mode 100644 index 00000000..a5388625 --- /dev/null +++ b/unittests/3.x/precedence_1.chai @@ -0,0 +1 @@ +assert_equal(14, 2 + 3 * 4) diff --git a/unittests/3.x/precedence_2.chai b/unittests/3.x/precedence_2.chai new file mode 100644 index 00000000..27a19d4a --- /dev/null +++ b/unittests/3.x/precedence_2.chai @@ -0,0 +1 @@ +assert_equal(-2, 5 - 4 - 3) diff --git a/unittests/3.x/precedence_3.chai b/unittests/3.x/precedence_3.chai new file mode 100644 index 00000000..6eecbf64 --- /dev/null +++ b/unittests/3.x/precedence_3.chai @@ -0,0 +1 @@ +assert_equal(0, 10 / 5 % 2) diff --git a/unittests/3.x/precedence_eq.chai b/unittests/3.x/precedence_eq.chai new file mode 100644 index 00000000..325d667e --- /dev/null +++ b/unittests/3.x/precedence_eq.chai @@ -0,0 +1,3 @@ +var x = var y = 4 +assert_equal(4, x); +assert_equal(4, y); diff --git a/unittests/3.x/product.chai b/unittests/3.x/product.chai new file mode 100644 index 00000000..03ba3cfa --- /dev/null +++ b/unittests/3.x/product.chai @@ -0,0 +1 @@ +assert_equal(24, product([1, 2, 3, 4])) diff --git a/unittests/3.x/range.chai b/unittests/3.x/range.chai new file mode 100644 index 00000000..ddef4f2a --- /dev/null +++ b/unittests/3.x/range.chai @@ -0,0 +1,4 @@ +var x = [1, 2, 3, 4] +var r = range(x) +r.pop_front() +assert_equal(2, r.front()); diff --git a/unittests/3.x/range_back.chai b/unittests/3.x/range_back.chai new file mode 100644 index 00000000..6bf56721 --- /dev/null +++ b/unittests/3.x/range_back.chai @@ -0,0 +1,4 @@ +var x = [1, 2, 3, 4] +var r = range(x) +r.pop_back() +assert_equal(3, r.back()) diff --git a/unittests/3.x/range_contains.chai b/unittests/3.x/range_contains.chai new file mode 100644 index 00000000..28a99b12 --- /dev/null +++ b/unittests/3.x/range_contains.chai @@ -0,0 +1,5 @@ +var v = [1,2,"hi", "world", 5.5] +assert_equal(true, v.contains(5.5)) +assert_equal(false, v.contains(0)) +assert_equal(false, v.contains(1, lt)) +assert_equal(true, v.contains(2, `==`)) diff --git a/unittests/3.x/range_find.chai b/unittests/3.x/range_find.chai new file mode 100644 index 00000000..08045e5a --- /dev/null +++ b/unittests/3.x/range_find.chai @@ -0,0 +1,6 @@ +var v = [2, 1, "Hi", 5.5] +var r = v.find("Hi"); + +assert_equal("Hi", r.front()) +var r2 = v.find(2, `<`); +assert_equal(1, r2.front()); diff --git a/unittests/3.x/range_inplace.chai b/unittests/3.x/range_inplace.chai new file mode 100644 index 00000000..d661f5de --- /dev/null +++ b/unittests/3.x/range_inplace.chai @@ -0,0 +1 @@ +assert_equal([3,4,5,6], [3..6]) diff --git a/unittests/3.x/reduce.chai b/unittests/3.x/reduce.chai new file mode 100644 index 00000000..3b255b31 --- /dev/null +++ b/unittests/3.x/reduce.chai @@ -0,0 +1 @@ +assert_equal(10, reduce([1, 2, 3, 4], `+`)) diff --git a/unittests/3.x/ref_equal.chai b/unittests/3.x/ref_equal.chai new file mode 100644 index 00000000..1dbb90e1 --- /dev/null +++ b/unittests/3.x/ref_equal.chai @@ -0,0 +1,5 @@ +var i = 3 +var j := i +j = 4 + +assert_equal(4, i) diff --git a/unittests/3.x/reflection_test.chai b/unittests/3.x/reflection_test.chai new file mode 100644 index 00000000..88b39ccc --- /dev/null +++ b/unittests/3.x/reflection_test.chai @@ -0,0 +1,37 @@ +load_module("reflection") +var parser := ChaiScript_Parser() +var parse_success = parser.parse("3 + 4", "INPUT") +var a := parser.ast() + +assert_equal(eval(a), 7) + +var childs := a.children.front().children +var node := childs[0] + +var parser2 := ChaiScript_Parser() +parser2.parse("9", "INPUT") + + +a.children.front().replace_child(childs[0], parser2.ast()) + +assert_equal(eval(a), 13) +assert_equal(node.filename, "INPUT") + + + +def my_fun() +{ + return 1; +} + + +assert_equal(true, my_fun.has_parse_tree()); +assert_equal(false, `+`.has_parse_tree()); + +assert_throws("Function does not have a parse tree", fun() { `+`.get_parse_tree(); } ); + +var parsetree := my_fun.get_parse_tree(); + +assert_equal(1, eval(parsetree)); + +print(parsetree.text()); diff --git a/unittests/3.x/retro.chai b/unittests/3.x/retro.chai new file mode 100644 index 00000000..d7f6818d --- /dev/null +++ b/unittests/3.x/retro.chai @@ -0,0 +1,4 @@ +var x = [1, 2, 3, 4] +var r = retro(range(x)) +r.pop_front() +assert_equal(3, r.front()) diff --git a/unittests/3.x/retroretro.chai b/unittests/3.x/retroretro.chai new file mode 100644 index 00000000..09af3ca7 --- /dev/null +++ b/unittests/3.x/retroretro.chai @@ -0,0 +1,7 @@ +var x = [1, 2, 3, 4] +var r = retro(range(x)) +r.pop_back() +var r2 = retro(r) +r2.pop_front() +assert_equal(2, r.back()) +assert_equal(3, r2.front()) diff --git a/unittests/3.x/return.chai b/unittests/3.x/return.chai new file mode 100644 index 00000000..512f52fc --- /dev/null +++ b/unittests/3.x/return.chai @@ -0,0 +1,5 @@ +def sam() { + return 5 +} + +assert_equal(5, sam()) diff --git a/unittests/3.x/runtime_error.chai b/unittests/3.x/runtime_error.chai new file mode 100644 index 00000000..e1e2fc10 --- /dev/null +++ b/unittests/3.x/runtime_error.chai @@ -0,0 +1,11 @@ +var caught = false + +try { + throw(runtime_error("error")) +} +catch(e) { + caught = true + assert_equal("error", e.what()) +} + +assert_equal(true, caught) diff --git a/unittests/3.x/shift.chai b/unittests/3.x/shift.chai new file mode 100644 index 00000000..03f7ea3a --- /dev/null +++ b/unittests/3.x/shift.chai @@ -0,0 +1 @@ +assert_equal(8, 2 << 2) diff --git a/unittests/3.x/short_comparison_test.cpp b/unittests/3.x/short_comparison_test.cpp new file mode 100644 index 00000000..a57e39c9 --- /dev/null +++ b/unittests/3.x/short_comparison_test.cpp @@ -0,0 +1,29 @@ +#include + +class Test { + public: + Test() : value_(5) {} + + short get_value() { return value_; } + + short value_; +}; + +int main() +{ + + chaiscript::ChaiScript chai; + chai.add(chaiscript::user_type(), "Test"); + chai.add(chaiscript::constructor(), "Test"); + + chai.add(chaiscript::fun(&Test::get_value), "get_value"); + + chai.eval("var t := Test();"); + + if (chai.eval("t.get_value() == 5")) + { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } +} diff --git a/unittests/3.x/string_charptr.chai b/unittests/3.x/string_charptr.chai new file mode 100644 index 00000000..a3065ce4 --- /dev/null +++ b/unittests/3.x/string_charptr.chai @@ -0,0 +1,6 @@ +assert_equal(true, "hello".c_str().is_var_const()) +assert_equal("char", "hello".c_str().type_name()) + +assert_equal(true, "hello".data().is_var_const()) +assert_equal("char", "hello".data().type_name()) + diff --git a/unittests/3.x/string_concat.chai b/unittests/3.x/string_concat.chai new file mode 100644 index 00000000..40bf4aaf --- /dev/null +++ b/unittests/3.x/string_concat.chai @@ -0,0 +1 @@ +assert_equal("hello, there", "hello, " + "there") diff --git a/unittests/3.x/string_find.chai b/unittests/3.x/string_find.chai new file mode 100644 index 00000000..f2cc1f82 --- /dev/null +++ b/unittests/3.x/string_find.chai @@ -0,0 +1 @@ +assert_equal(3, find("123abab", "ab")) diff --git a/unittests/3.x/string_find_first_not_of.chai b/unittests/3.x/string_find_first_not_of.chai new file mode 100644 index 00000000..4d5fd8d4 --- /dev/null +++ b/unittests/3.x/string_find_first_not_of.chai @@ -0,0 +1 @@ +assert_equal(2, find_first_not_of("abcd", "abd")) diff --git a/unittests/3.x/string_find_first_of.chai b/unittests/3.x/string_find_first_of.chai new file mode 100644 index 00000000..0200bb2c --- /dev/null +++ b/unittests/3.x/string_find_first_of.chai @@ -0,0 +1 @@ +assert_equal(1, find_first_of("abab", "bec")) diff --git a/unittests/3.x/string_find_last_not_of.chai b/unittests/3.x/string_find_last_not_of.chai new file mode 100644 index 00000000..0090f9f9 --- /dev/null +++ b/unittests/3.x/string_find_last_not_of.chai @@ -0,0 +1 @@ +assert_equal(3, find_last_not_of("abab", "ac")) diff --git a/unittests/3.x/string_find_last_of.chai b/unittests/3.x/string_find_last_of.chai new file mode 100644 index 00000000..72f0f6a0 --- /dev/null +++ b/unittests/3.x/string_find_last_of.chai @@ -0,0 +1 @@ +assert_equal(3, find_last_of("abab", "bec")) diff --git a/unittests/3.x/string_init.chai b/unittests/3.x/string_init.chai new file mode 100644 index 00000000..a3d11632 --- /dev/null +++ b/unittests/3.x/string_init.chai @@ -0,0 +1 @@ +print("bob") diff --git a/unittests/3.x/string_literal_access.chai b/unittests/3.x/string_literal_access.chai new file mode 100644 index 00000000..e8943a1b --- /dev/null +++ b/unittests/3.x/string_literal_access.chai @@ -0,0 +1 @@ +assert_equal('b', "abc"[1]) diff --git a/unittests/3.x/string_rfind.chai b/unittests/3.x/string_rfind.chai new file mode 100644 index 00000000..01675f34 --- /dev/null +++ b/unittests/3.x/string_rfind.chai @@ -0,0 +1 @@ +assert_equal(5, rfind("123abab", "ab")) diff --git a/unittests/3.x/sum.chai b/unittests/3.x/sum.chai new file mode 100644 index 00000000..7502ae7e --- /dev/null +++ b/unittests/3.x/sum.chai @@ -0,0 +1 @@ +assert_equal(10, sum([1, 2, 3, 4])) diff --git a/unittests/3.x/take.chai b/unittests/3.x/take.chai new file mode 100644 index 00000000..5110392e --- /dev/null +++ b/unittests/3.x/take.chai @@ -0,0 +1 @@ +assert_equal(2, take([1, 2, 3, 4], 2).back()) diff --git a/unittests/3.x/take_while.chai b/unittests/3.x/take_while.chai new file mode 100644 index 00000000..56a4ba22 --- /dev/null +++ b/unittests/3.x/take_while.chai @@ -0,0 +1 @@ +assert_equal([1], take_while([1, 2, 3, 4], odd)) diff --git a/unittests/3.x/type_info.chai b/unittests/3.x/type_info.chai new file mode 100644 index 00000000..fc2dd3e7 --- /dev/null +++ b/unittests/3.x/type_info.chai @@ -0,0 +1,11 @@ +assert_equal("string", string_type.name()); +assert_equal(false, string_type.is_type_const()); +assert_equal(false, string_type.is_type_reference()); +assert_equal(false, string_type.is_type_void()); +assert_equal(false, string_type.is_type_undef()); +assert_equal(false, string_type.is_type_pointer()); +assert_equal("string", "string".get_type_info().name()); +assert_equal(true, string_type.bare_equal("string".get_type_info())); + +assert_equal(true, "bob".is_type(string_type)); + diff --git a/unittests/3.x/type_info_test.cpp b/unittests/3.x/type_info_test.cpp new file mode 100644 index 00000000..361be80f --- /dev/null +++ b/unittests/3.x/type_info_test.cpp @@ -0,0 +1,32 @@ +// Tests to make sure that the order in which function dispatches occur is correct + +#include + +void test_type(const chaiscript::Type_Info &ti, bool t_is_const, bool t_is_pointer, bool t_is_reference, bool t_is_void, + bool t_is_undef) +{ + if (ti.is_const() == t_is_const + && ti.is_pointer() == t_is_pointer + && ti.is_reference() == t_is_reference + && ti.is_void() == t_is_void + && ti.is_undef() == t_is_undef) + { + return; + } else { + exit(EXIT_FAILURE); + } +} + + +int main() +{ + test_type(chaiscript::user_type(), false, false, false, true, false); + test_type(chaiscript::user_type(), true, false, false, false, false); + test_type(chaiscript::user_type(), true, false, true, false, false); + test_type(chaiscript::user_type(), false, false, false, false, false); + test_type(chaiscript::user_type(), false, true, false, false, false); + test_type(chaiscript::user_type(), true, true, false, false, false); + test_type(chaiscript::Type_Info(), false, false, false, false, true); + + return EXIT_SUCCESS; +} diff --git a/unittests/3.x/unit_test.inc b/unittests/3.x/unit_test.inc new file mode 100644 index 00000000..d746e7bf --- /dev/null +++ b/unittests/3.x/unit_test.inc @@ -0,0 +1,53 @@ +def assert_equal(x, y) +{ + if (x == y) + { + // Passes + } else { + // Fails + print("assert_equal failure: got " + to_string(y) + " expected " + to_string(x)); + exit(-1); + } +} + +def assert_false(f) +{ + if (f) + { + print("assert_false failure"); + exit(-1); + } +} + +def assert_true(f) +{ + if (!f) + { + print("assert_false failure"); + exit(-1); + } +} + +def assert_not_equal(x, y) +{ + if (!(x == y)) + { + // Passes + } else { + // Fails + print("assert_not_equal failure: got " + to_string(y) + " which was not expected."); + exit(-1); + } +} + +def assert_throws(desc, x) +{ + if (throws_exception(x)) + { + // Passes + } else { + // Fails + print("assert_throws failure, function did not throw exception: " + to_string(desc)); + exit(-1); + } +} diff --git a/unittests/3.x/use.chai b/unittests/3.x/use.chai new file mode 100644 index 00000000..efd587da --- /dev/null +++ b/unittests/3.x/use.chai @@ -0,0 +1,9 @@ +use("use.inc") + +assert_equal("hello", greet()) + +// Include it a second time and see if there are any errors +use("use.inc") + +assert_equal("hello", greet()) + diff --git a/unittests/3.x/use.inc b/unittests/3.x/use.inc new file mode 100644 index 00000000..204cec40 --- /dev/null +++ b/unittests/3.x/use.inc @@ -0,0 +1,4 @@ +def greet { + return("hello") +} + diff --git a/unittests/3.x/utility_test.cpp b/unittests/3.x/utility_test.cpp new file mode 100644 index 00000000..bcd3240b --- /dev/null +++ b/unittests/3.x/utility_test.cpp @@ -0,0 +1,42 @@ +#include + +class Test +{ + public: + void function() {} + std::string function2() { return "Function2"; } + void function3() {} + std::string functionOverload(double) { return "double"; } + std::string functionOverload(int) { return "int"; } +}; + +int main() +{ + + chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module()); + + CHAISCRIPT_CLASS( m, + Test, + (Test ()) + (Test (const Test &)), + ((function)) + ((function2)) + ((function3)) + ((functionOverload)(std::string (Test::*)(double))) + ((functionOverload)(std::string (Test::*)(int))) + ((operator=)) + ); + + chaiscript::ChaiScript chai; + chai.add(m); + if (chai.eval("var t = Test(); t.function2(); ") == "Function2" + && chai.eval("var t = Test(); t.functionOverload(1); ") == "int" + && chai.eval("var t = Test(); t.functionOverload(1.1); ") == "double") + { + chai.eval("t = Test();"); + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } + +} diff --git a/unittests/3.x/vector_access.chai b/unittests/3.x/vector_access.chai new file mode 100644 index 00000000..34d483cd --- /dev/null +++ b/unittests/3.x/vector_access.chai @@ -0,0 +1,2 @@ +var x = [1, 2, 3] +assert_equal(3, x[2]) diff --git a/unittests/3.x/vector_erase_at.chai b/unittests/3.x/vector_erase_at.chai new file mode 100644 index 00000000..9a96218f --- /dev/null +++ b/unittests/3.x/vector_erase_at.chai @@ -0,0 +1,3 @@ +var x = [1, 2, 3] +x.erase_at(1) +assert_equal([1,3], x); diff --git a/unittests/3.x/vector_inplace_init.chai b/unittests/3.x/vector_inplace_init.chai new file mode 100644 index 00000000..f16c15b3 --- /dev/null +++ b/unittests/3.x/vector_inplace_init.chai @@ -0,0 +1,2 @@ +var x = [1, 2, 3] +assert_equal(3, x.size()) diff --git a/unittests/3.x/vector_insert_at.chai b/unittests/3.x/vector_insert_at.chai new file mode 100644 index 00000000..4f6ec45b --- /dev/null +++ b/unittests/3.x/vector_insert_at.chai @@ -0,0 +1,3 @@ +var x = [1, 2, 3] +x.insert_at(1, 6) +assert_equal([1,6,2,3], x); diff --git a/unittests/3.x/vector_literal_acccess.chai b/unittests/3.x/vector_literal_acccess.chai new file mode 100644 index 00000000..29a7c05f --- /dev/null +++ b/unittests/3.x/vector_literal_acccess.chai @@ -0,0 +1 @@ +assert_equal(1, [1,2,3][0]) diff --git a/unittests/3.x/vector_of_one.chai b/unittests/3.x/vector_of_one.chai new file mode 100644 index 00000000..f4bb01bf --- /dev/null +++ b/unittests/3.x/vector_of_one.chai @@ -0,0 +1,2 @@ +var x = [1] +assert_equal(1, x[0]) diff --git a/unittests/3.x/vector_paren_literal_access.chai b/unittests/3.x/vector_paren_literal_access.chai new file mode 100644 index 00000000..a0c6b966 --- /dev/null +++ b/unittests/3.x/vector_paren_literal_access.chai @@ -0,0 +1 @@ +assert_equal(1, ([1,2,3])[0]) diff --git a/unittests/3.x/vector_push_back.chai b/unittests/3.x/vector_push_back.chai new file mode 100644 index 00000000..715082bd --- /dev/null +++ b/unittests/3.x/vector_push_back.chai @@ -0,0 +1,5 @@ +var x = [1, 2] +x.push_back(3) +assert_equal(3, x.size()) +assert_equal(3, x.back()) +assert_equal(1, x.front()) diff --git a/unittests/3.x/vector_push_empty.chai b/unittests/3.x/vector_push_empty.chai new file mode 100644 index 00000000..29c568d1 --- /dev/null +++ b/unittests/3.x/vector_push_empty.chai @@ -0,0 +1,4 @@ +var bob = [] +bob.push_back(3) +assert_equal(1, bob.size()) +assert_equal(3, bob.front()) diff --git a/unittests/3.x/zip.chai b/unittests/3.x/zip.chai new file mode 100644 index 00000000..d39583f2 --- /dev/null +++ b/unittests/3.x/zip.chai @@ -0,0 +1,5 @@ +var z = zip([1, 2, 3], [4, 5, 6]) + +assert_equal([1,4], z[0]) +assert_equal([2,5], z[1]) +assert_equal([3,6], z[2]) diff --git a/unittests/3.x/zip_with.chai b/unittests/3.x/zip_with.chai new file mode 100644 index 00000000..1fe3dd90 --- /dev/null +++ b/unittests/3.x/zip_with.chai @@ -0,0 +1,3 @@ +var z = zip_with(`+`, [1, 2, 3], [4, 5, 6]) + +assert_equal([5,7,9], z) diff --git a/unittests/assign_const.chai b/unittests/assign_const.chai index 7b2ede58..ff6a8c3d 100644 --- a/unittests/assign_const.chai +++ b/unittests/assign_const.chai @@ -1,2 +1,2 @@ -assert_throws("Mismatched types in equation, lhs is const.", []() { 1 = 2 } ); -assert_throws("Mismatched types in equation, lhs is const.", []() { 1 + 2 = 2 } ); +assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 = 2 } ); +assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 + 2 = 2 } ); diff --git a/unittests/bind.chai b/unittests/bind.chai index d89d66de..a3af3004 100644 --- a/unittests/bind.chai +++ b/unittests/bind.chai @@ -1,2 +1,2 @@ auto prod = bind(foldl, _, `*`, 1.0) -assert_equal(60, prod({3, 4, 5})) +assert_equal(60, prod([3, 4, 5])) diff --git a/unittests/concat.chai b/unittests/concat.chai index 4b897b78..53950a6e 100644 --- a/unittests/concat.chai +++ b/unittests/concat.chai @@ -1,4 +1,4 @@ -auto v = concat({1, 2}, {3, 4}); +auto v = concat([1, 2], [3, 4]); assert_equal(4, v.size()); assert_equal(1, v[0]); diff --git a/unittests/const_range_test.chai b/unittests/const_range_test.chai index d8840f36..044c13d9 100644 --- a/unittests/const_range_test.chai +++ b/unittests/const_range_test.chai @@ -1,4 +1,3 @@ //If the following succeeds, the test passes - -"Hello World".for_each([](x) { print(x) } ) +"Hello World".for_each(fun(x) { print(x) } ) diff --git a/unittests/deep_array_lookup.chai b/unittests/deep_array_lookup.chai index d94cb8f6..8a86eaa3 100644 --- a/unittests/deep_array_lookup.chai +++ b/unittests/deep_array_lookup.chai @@ -1,9 +1,9 @@ -auto a = {1,2,3, {4,5,6} } +auto a = [1,2,3, [4,5,6] ] assert_equal(a[3][0], 4) -def Test::Test() { this.a = {1,2,3}; } +def Test::Test() { this.a = [1,2,3]; } attr Test::a; auto t = Test(); diff --git a/unittests/drop.chai b/unittests/drop.chai index 9758c8fd..c64b431e 100644 --- a/unittests/drop.chai +++ b/unittests/drop.chai @@ -1 +1 @@ -assert_equal({3,4}, drop({1, 2, 3, 4}, 2)) +assert_equal([3,4], drop([1, 2, 3, 4], 2)) diff --git a/unittests/drop_while.chai b/unittests/drop_while.chai index 6912cf27..08e19f2f 100644 --- a/unittests/drop_while.chai +++ b/unittests/drop_while.chai @@ -1 +1 @@ -assert_equal({2, 3}, drop_while({1, 2, 3}, odd)) +assert_equal([2, 3], drop_while([1, 2, 3], odd)) diff --git a/unittests/eval_error.chai b/unittests/eval_error.chai index 54eef2c4..b2737a11 100644 --- a/unittests/eval_error.chai +++ b/unittests/eval_error.chai @@ -34,6 +34,6 @@ def while_doing() } } -auto f = []() { while_doing(); } +auto f = fun() { while_doing(); } assert_equal(get_eval_error(f).call_stack.size(), 16) diff --git a/unittests/exception_guards.chai b/unittests/exception_guards.chai index 2c2ec093..12792985 100644 --- a/unittests/exception_guards.chai +++ b/unittests/exception_guards.chai @@ -1,4 +1,4 @@ -auto results = {}; +auto results = []; for (auto i = 2; i < 6; ++i) { try { @@ -31,4 +31,4 @@ catch { results.push_back("defaultcatch"); } -assert_equal({"c2: 2", "c2: 3", "c3: 4", "c3: 5", "defaultcatch"}, results); +assert_equal(["c2: 2", "c2: 3", "c3: 4", "c3: 5", "defaultcatch"], results); diff --git a/unittests/filter.chai b/unittests/filter.chai index 2b8b43ac..6d805fee 100644 --- a/unittests/filter.chai +++ b/unittests/filter.chai @@ -1 +1 @@ -assert_equal({1,3}, filter({1, 2, 3, 4}, odd)) +assert_equal([1,3], filter([1, 2, 3, 4], odd)) diff --git a/unittests/foldl.chai b/unittests/foldl.chai index 25de4f3d..7e9db51f 100644 --- a/unittests/foldl.chai +++ b/unittests/foldl.chai @@ -1 +1 @@ -assert_equal(10, foldl({1, 2, 3, 4}, `+`, 0)) +assert_equal(10, foldl([1, 2, 3, 4], `+`, 0)) diff --git a/unittests/for.chai b/unittests/for.chai index e4ae118e..c5769992 100644 --- a/unittests/for.chai +++ b/unittests/for.chai @@ -1,7 +1,7 @@ -auto ret = {} +auto ret = [] for (auto i = 0; i < 5; ++i) { ret.push_back(i); } -assert_equal({0,1,2,3,4}, ret); +assert_equal([0,1,2,3,4], ret); diff --git a/unittests/for_each.chai b/unittests/for_each.chai index 0a8d7370..242a1baf 100644 --- a/unittests/for_each.chai +++ b/unittests/for_each.chai @@ -1 +1 @@ -for_each({1, 2, 3}, print) +for_each([1, 2, 3], print) diff --git a/unittests/for_each_range.chai b/unittests/for_each_range.chai index 7af3025d..3a92641d 100644 --- a/unittests/for_each_range.chai +++ b/unittests/for_each_range.chai @@ -1,3 +1,3 @@ -auto v = {1,2,3}; +auto v = [1,2,3]; auto r = range(v); -for_each(r, [](x) { assert_equal(true, x>0); } ) +for_each(r, fun(x) { assert_equal(true, x>0); } ) diff --git a/unittests/for_each_retro.chai b/unittests/for_each_retro.chai index 816d30f4..4cd0ff51 100644 --- a/unittests/for_each_retro.chai +++ b/unittests/for_each_retro.chai @@ -1,4 +1,4 @@ // Don't bother checking the output from this one, just makes sure it executes -auto v = {1,2,3}; +auto v = [1,2,3]; auto r = retro(range(v)); for_each(r, print) diff --git a/unittests/function_introspection.chai b/unittests/function_introspection.chai index e58beb6e..6d808dfe 100644 --- a/unittests/function_introspection.chai +++ b/unittests/function_introspection.chai @@ -18,7 +18,7 @@ assert_equal(test_function, test_function); assert_not_equal(test_function, `+`); -assert_equal(test_function.call({1}), 1); +assert_equal(test_function.call([1]), 1); // dynamic object function tests @@ -67,10 +67,10 @@ auto group = group_guard.get_contained_functions(); assert_equal(true, group[0].has_guard()) assert_equal(false, group[1].has_guard()) -assert_throws("Function does not have a guard", []() { group[0].get_guard(); } ); -assert_throws("Function does not have a guard", []() { without_guard.get_guard(); } ); +assert_throws("Function does not have a guard", fun() { group[0].get_guard(); } ); +assert_throws("Function does not have a guard", fun() { without_guard.get_guard(); } ); auto guard = with_guard.get_guard(); assert_equal(false, guard.has_guard()); -assert_throws("Function does not have a guard", []() { guard.get_guard(); } ); +assert_throws("Function does not have a guard", fun() { guard.get_guard(); } ); diff --git a/unittests/generate_range.chai b/unittests/generate_range.chai index 9f729eda..9e25970a 100644 --- a/unittests/generate_range.chai +++ b/unittests/generate_range.chai @@ -1 +1 @@ -assert_equal({1,2,3,4,5,6,7,8,9,10}, generate_range(1, 10)) +assert_equal([1,2,3,4,5,6,7,8,9,10], generate_range(1, 10)) diff --git a/unittests/index_operator.chai b/unittests/index_operator.chai index 0b7d7706..f8074042 100644 --- a/unittests/index_operator.chai +++ b/unittests/index_operator.chai @@ -1,7 +1,7 @@ // tests more complex parses of the index operator -def Bob::bob3() { return {1,2,3}; } +def Bob::bob3() { return [1,2,3]; } def Bob::Bob() {} auto b = Bob(); diff --git a/unittests/invalid_function_assignment.chai b/unittests/invalid_function_assignment.chai index 69ff5cab..99b098db 100644 --- a/unittests/invalid_function_assignment.chai +++ b/unittests/invalid_function_assignment.chai @@ -1 +1 @@ -assert_throws("Illegal const function assignment", []() { clone = `-` } ); +assert_throws("Illegal const function assignment", fun() { clone = `-` } ); diff --git a/unittests/invalid_function_reassignment.chai b/unittests/invalid_function_reassignment.chai index d688a2a9..784372ac 100644 --- a/unittests/invalid_function_reassignment.chai +++ b/unittests/invalid_function_reassignment.chai @@ -1 +1 @@ -assert_throws("Invalid function reassignment", []() { auto x = 5; x = `-`; } ); +assert_throws("Invalid function reassignment", fun() { auto x = 5; x = `-`; } ); diff --git a/unittests/join.chai b/unittests/join.chai index 4ae6665e..1891c468 100644 --- a/unittests/join.chai +++ b/unittests/join.chai @@ -1 +1 @@ -assert_equal("1*2*3", join({1, 2, 3}, "*")) +assert_equal("1*2*3", join([1, 2, 3], "*")) diff --git a/unittests/lambda.chai b/unittests/lambda.chai index f2bd3db1..9b717ec5 100644 --- a/unittests/lambda.chai +++ b/unittests/lambda.chai @@ -1,2 +1,2 @@ -auto bob = [](x) { x + 1 } +auto bob = fun(x) { x + 1 } assert_equal(4, bob(3)); diff --git a/unittests/malformed_inline_map.chai b/unittests/malformed_inline_map.chai index 1cd8acf5..d267bcfe 100644 --- a/unittests/malformed_inline_map.chai +++ b/unittests/malformed_inline_map.chai @@ -1,2 +1,2 @@ -assert_throws("Parse failure", []() { eval("{\"hello\":5,\"j\",\"k\"}") } ); +assert_throws("Parse failure", fun() { eval("[\"hello\":5,\"j\",\"k\"]") } ); diff --git a/unittests/map.chai b/unittests/map.chai index 7344f809..a0a31ee1 100644 --- a/unittests/map.chai +++ b/unittests/map.chai @@ -1 +1 @@ -assert_equal({true, false, true}, map({1,2,3}, odd)) +assert_equal([true, false, true], map([1,2,3], odd)) diff --git a/unittests/map_access.chai b/unittests/map_access.chai index 1d291237..d544036d 100644 --- a/unittests/map_access.chai +++ b/unittests/map_access.chai @@ -1,2 +1,2 @@ -auto x = {"bob":2, "fred":3} +auto x = ["bob":2, "fred":3] assert_equal(3, x["fred"]) diff --git a/unittests/map_inplace_init.chai b/unittests/map_inplace_init.chai index 5806292b..1d88494f 100644 --- a/unittests/map_inplace_init.chai +++ b/unittests/map_inplace_init.chai @@ -1,3 +1,3 @@ -auto x = {"bob":1, "fred":2} +auto x = ["bob":1, "fred":2] assert_equal(2, x.size()); diff --git a/unittests/method_sugar.chai b/unittests/method_sugar.chai index 97598f90..521400bc 100644 --- a/unittests/method_sugar.chai +++ b/unittests/method_sugar.chai @@ -1 +1 @@ -assert_equal(6, {1, 2, 3}.sum()) +assert_equal(6, [1, 2, 3].sum()) diff --git a/unittests/multiline.chai b/unittests/multiline.chai index 52a29122..dfa213c3 100644 --- a/unittests/multiline.chai +++ b/unittests/multiline.chai @@ -1,9 +1,9 @@ -auto x = {1, 2, - 3, 4} +auto x = [1, 2, + 3, 4] assert_equal(1, x[0]) auto y = map(x, - [](x) { x + 1 }) + fun(x) { x + 1 }) assert_equal(2, y[0]) diff --git a/unittests/operators_float.chai b/unittests/operators_float.chai index 7dcf6293..823d4289 100644 --- a/unittests/operators_float.chai +++ b/unittests/operators_float.chai @@ -13,4 +13,4 @@ assert_equal(0, i -= i) assert_equal(3, j *= 1.5) assert_equal(1.5, j /= 2) assert_equal(2.5, j += 1) -assert_throws("No modulous for float", []() { k % 2 } ); +assert_throws("No modulus for float", fun() { k % 2 } ); diff --git a/unittests/product.chai b/unittests/product.chai index f0b9d0a1..03ba3cfa 100644 --- a/unittests/product.chai +++ b/unittests/product.chai @@ -1 +1 @@ -assert_equal(24, product({1, 2, 3, 4})) +assert_equal(24, product([1, 2, 3, 4])) diff --git a/unittests/range.chai b/unittests/range.chai index cdc5689e..97a430b1 100644 --- a/unittests/range.chai +++ b/unittests/range.chai @@ -1,4 +1,4 @@ -auto x = {1, 2, 3, 4} +auto x = [1, 2, 3, 4] auto r = range(x) r.pop_front() assert_equal(2, r.front()); diff --git a/unittests/range_back.chai b/unittests/range_back.chai index a4936559..b572f944 100644 --- a/unittests/range_back.chai +++ b/unittests/range_back.chai @@ -1,4 +1,4 @@ -auto x = {1, 2, 3, 4} +auto x = [1, 2, 3, 4] auto r = range(x) r.pop_back() assert_equal(3, r.back()) diff --git a/unittests/range_contains.chai b/unittests/range_contains.chai index a5b7705e..e79051e9 100644 --- a/unittests/range_contains.chai +++ b/unittests/range_contains.chai @@ -1,4 +1,4 @@ -auto v = {1,2,"hi", "world", 5.5} +auto v = [1,2,"hi", "world", 5.5] assert_equal(true, v.contains(5.5)) assert_equal(false, v.contains(0)) assert_equal(false, v.contains(1, lt)) diff --git a/unittests/range_find.chai b/unittests/range_find.chai index e51bc719..1bdb1ba9 100644 --- a/unittests/range_find.chai +++ b/unittests/range_find.chai @@ -1,4 +1,4 @@ -auto v = {2, 1, "Hi", 5.5} +auto v = [2, 1, "Hi", 5.5] auto r = v.find("Hi"); assert_equal("Hi", r.front()) diff --git a/unittests/range_inplace.chai b/unittests/range_inplace.chai index ff90a0e3..d661f5de 100644 --- a/unittests/range_inplace.chai +++ b/unittests/range_inplace.chai @@ -1 +1 @@ -assert_equal({3,4,5,6}, {3..6}) +assert_equal([3,4,5,6], [3..6]) diff --git a/unittests/reduce.chai b/unittests/reduce.chai index fb347e80..3b255b31 100644 --- a/unittests/reduce.chai +++ b/unittests/reduce.chai @@ -1 +1 @@ -assert_equal(10, reduce({1, 2, 3, 4}, `+`)) +assert_equal(10, reduce([1, 2, 3, 4], `+`)) diff --git a/unittests/reflection_test.chai b/unittests/reflection_test.chai index 231449e0..42566bc1 100644 --- a/unittests/reflection_test.chai +++ b/unittests/reflection_test.chai @@ -28,7 +28,7 @@ def my_fun() assert_equal(true, my_fun.has_parse_tree()); assert_equal(false, `+`.has_parse_tree()); -assert_throws("Function does not have a parse tree", []() { `+`.get_parse_tree(); } ); +assert_throws("Function does not have a parse tree", fun() { `+`.get_parse_tree(); } ); auto& parsetree = my_fun.get_parse_tree(); diff --git a/unittests/retro.chai b/unittests/retro.chai index 1e8359f2..780a06d9 100644 --- a/unittests/retro.chai +++ b/unittests/retro.chai @@ -1,4 +1,4 @@ -auto x = {1, 2, 3, 4} +auto x = [1, 2, 3, 4] auto r = retro(range(x)) r.pop_front() assert_equal(3, r.front()) diff --git a/unittests/retroretro.chai b/unittests/retroretro.chai index 8e203cb9..36c568c9 100644 --- a/unittests/retroretro.chai +++ b/unittests/retroretro.chai @@ -1,4 +1,4 @@ -auto x = {1, 2, 3, 4} +auto x = [1, 2, 3, 4] auto r = retro(range(x)) r.pop_back() auto r2 = retro(r) diff --git a/unittests/sum.chai b/unittests/sum.chai index 55885931..7502ae7e 100644 --- a/unittests/sum.chai +++ b/unittests/sum.chai @@ -1 +1 @@ -assert_equal(10, sum({1, 2, 3, 4})) +assert_equal(10, sum([1, 2, 3, 4])) diff --git a/unittests/take.chai b/unittests/take.chai index 06df1cb2..5110392e 100644 --- a/unittests/take.chai +++ b/unittests/take.chai @@ -1 +1 @@ -assert_equal(2, take({1, 2, 3, 4}, 2).back()) +assert_equal(2, take([1, 2, 3, 4], 2).back()) diff --git a/unittests/take_while.chai b/unittests/take_while.chai index 3bfc1b0b..56a4ba22 100644 --- a/unittests/take_while.chai +++ b/unittests/take_while.chai @@ -1 +1 @@ -assert_equal({1}, take_while({1, 2, 3, 4}, odd)) +assert_equal([1], take_while([1, 2, 3, 4], odd)) diff --git a/unittests/vector_access.chai b/unittests/vector_access.chai index 7eaa4946..58269a25 100644 --- a/unittests/vector_access.chai +++ b/unittests/vector_access.chai @@ -1,2 +1,2 @@ -auto x = {1, 2, 3} +auto x = [1, 2, 3] assert_equal(3, x[2]) diff --git a/unittests/vector_erase_at.chai b/unittests/vector_erase_at.chai index 3bb77b67..348cd819 100644 --- a/unittests/vector_erase_at.chai +++ b/unittests/vector_erase_at.chai @@ -1,3 +1,3 @@ -auto x = {1, 2, 3} +auto x = [1, 2, 3] x.erase_at(1) -assert_equal({1,3}, x); +assert_equal([1,3], x); diff --git a/unittests/vector_inplace_init.chai b/unittests/vector_inplace_init.chai index 04e0593d..7b01cb9d 100644 --- a/unittests/vector_inplace_init.chai +++ b/unittests/vector_inplace_init.chai @@ -1,2 +1,2 @@ -auto x = {1, 2, 3} +auto x = [1, 2, 3] assert_equal(3, x.size()) diff --git a/unittests/vector_insert_at.chai b/unittests/vector_insert_at.chai index 9a7fd2b4..1b42e1cf 100644 --- a/unittests/vector_insert_at.chai +++ b/unittests/vector_insert_at.chai @@ -1,3 +1,3 @@ -auto x = {1, 2, 3} +auto x = [1, 2, 3] x.insert_at(1, 6) -assert_equal({1,6,2,3}, x); +assert_equal([1,6,2,3], x); diff --git a/unittests/vector_literal_acccess.chai b/unittests/vector_literal_acccess.chai index a33a5525..29a7c05f 100644 --- a/unittests/vector_literal_acccess.chai +++ b/unittests/vector_literal_acccess.chai @@ -1 +1 @@ -assert_equal(1, {1,2,3}[0]) +assert_equal(1, [1,2,3][0]) diff --git a/unittests/vector_of_one.chai b/unittests/vector_of_one.chai index a046e316..2763fc19 100644 --- a/unittests/vector_of_one.chai +++ b/unittests/vector_of_one.chai @@ -1,2 +1,2 @@ -auto x = {1} +auto x = [1] assert_equal(1, x[0]) diff --git a/unittests/vector_paren_literal_access.chai b/unittests/vector_paren_literal_access.chai index f96194e2..a0c6b966 100644 --- a/unittests/vector_paren_literal_access.chai +++ b/unittests/vector_paren_literal_access.chai @@ -1 +1 @@ -assert_equal(1, ({1,2,3})[0]) +assert_equal(1, ([1,2,3])[0]) diff --git a/unittests/vector_push_back.chai b/unittests/vector_push_back.chai index f5d81bf5..82ba4b44 100644 --- a/unittests/vector_push_back.chai +++ b/unittests/vector_push_back.chai @@ -1,4 +1,4 @@ -auto x = {1, 2} +auto x = [1, 2] x.push_back(3) assert_equal(3, x.size()) assert_equal(3, x.back()) diff --git a/unittests/vector_push_empty.chai b/unittests/vector_push_empty.chai index a279eeab..4cb7afea 100644 --- a/unittests/vector_push_empty.chai +++ b/unittests/vector_push_empty.chai @@ -1,4 +1,4 @@ -auto bob = {} +auto bob = [] bob.push_back(3) assert_equal(1, bob.size()) assert_equal(3, bob.front()) diff --git a/unittests/zip.chai b/unittests/zip.chai index a6a83270..6aa5b36c 100644 --- a/unittests/zip.chai +++ b/unittests/zip.chai @@ -1,5 +1,5 @@ -auto z = zip({1, 2, 3}, {4, 5, 6}) +auto z = zip([1, 2, 3], [4, 5, 6]) -assert_equal({1,4}, z[0]) -assert_equal({2,5}, z[1]) -assert_equal({3,6}, z[2]) +assert_equal([1,4], z[0]) +assert_equal([2,5], z[1]) +assert_equal([3,6], z[2]) diff --git a/unittests/zip_with.chai b/unittests/zip_with.chai index 9b232226..ca2665ac 100644 --- a/unittests/zip_with.chai +++ b/unittests/zip_with.chai @@ -1,3 +1,3 @@ -auto z = zip_with(`+`, {1, 2, 3}, {4, 5, 6}) +auto z = zip_with(`+`, [1, 2, 3], [4, 5, 6]) -assert_equal({5,7,9}, z) +assert_equal([5,7,9], z) From cf97a73485e650b5f9d1852ca990742b56c701ca Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 17 May 2012 10:27:26 -0700 Subject: [PATCH 059/108] Syntax updates to a few unit tests. --- unittests/function_redefinition.chai | 2 +- unittests/variable_redefinition.chai | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/unittests/function_redefinition.chai b/unittests/function_redefinition.chai index 69ae19e6..f82a414c 100644 --- a/unittests/function_redefinition.chai +++ b/unittests/function_redefinition.chai @@ -1,2 +1,2 @@ -assert_throws("Function already defined", [](){ def foo(x) { x + 1 }; def foo(x) { x + 1 } } ); +assert_throws("Function already defined", fun(){ def foo(x) { x + 1 }; def foo(x) { x + 1 } } ); diff --git a/unittests/variable_redefinition.chai b/unittests/variable_redefinition.chai index dc670e42..c59107c5 100644 --- a/unittests/variable_redefinition.chai +++ b/unittests/variable_redefinition.chai @@ -1,2 +1,2 @@ -assert_throws("Variable already defined", []() { auto y = 10; auto y = 20; }) +assert_throws("Variable already defined", fun() { auto y = 10; auto y = 20; }) From b82895c489509a319d259318ed6eb6ea91ca0de5 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 17 May 2012 10:31:55 -0700 Subject: [PATCH 060/108] Add the 'auto' keyword. --- contrib/geshi/chaiscript.php | 2 +- contrib/vim/syntax/chaiscript.vim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/geshi/chaiscript.php b/contrib/geshi/chaiscript.php index 99847ec9..d1fd89c3 100644 --- a/contrib/geshi/chaiscript.php +++ b/contrib/geshi/chaiscript.php @@ -51,7 +51,7 @@ $language_data = array ( 'break', 'else', 'else if', 'eval', 'for', 'if', 'return', 'while', 'try', 'catch', 'finally', ), 2 => array( - 'def', 'false', 'fun', 'true', 'var', 'attr', + 'def', 'false', 'fun', 'true', 'var', 'auto', 'attr', ), 3 => array( // built in functions diff --git a/contrib/vim/syntax/chaiscript.vim b/contrib/vim/syntax/chaiscript.vim index 5a64bdb5..dc89d841 100644 --- a/contrib/vim/syntax/chaiscript.vim +++ b/contrib/vim/syntax/chaiscript.vim @@ -49,7 +49,7 @@ syn keyword chaiscriptExceptions try catch throw syn keyword chaiscriptKeyword def true false attr "Built in types -syn keyword chaiscriptType fun var +syn keyword chaiscriptType fun var auto "Built in funcs, keep it simple syn keyword chaiscriptFunc eval throw From cebd2c9763303b4c43c5bf2caf9d2e929d2d01b0 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 17 May 2012 13:56:10 -0700 Subject: [PATCH 061/108] Adding support for switch/case/default to 4.x --- .../chaiscript/language/chaiscript_common.hpp | 4 +- .../chaiscript/language/chaiscript_eval.hpp | 71 ++++++++++++++ .../chaiscript/language/chaiscript_parser.hpp | 94 +++++++++++++++++++ unittests/3.x/switch_break.chai | 22 +++++ unittests/3.x/switch_default.chai | 18 ++++ unittests/3.x/switch_empty.chai | 4 + unittests/3.x/switch_fallthru.chai | 18 ++++ unittests/3.x/switch_fallthru_and_break.chai | 19 ++++ 8 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 unittests/3.x/switch_break.chai create mode 100644 unittests/3.x/switch_default.chai create mode 100644 unittests/3.x/switch_empty.chai create mode 100644 unittests/3.x/switch_fallthru.chai create mode 100644 unittests/3.x/switch_fallthru_and_break.chai diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 7579a61b..02b79cf1 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -23,7 +23,7 @@ namespace chaiscript Comparison, Addition, Subtraction, Multiplication, Division, Modulus, Array_Call, Dot_Access, Quoted_String, Single_Quoted_String, Lambda, Block, Def, While, If, For, Inline_Array, Inline_Map, Return, File, Prefix, Break, Map_Pair, Value_Range, Inline_Range, Annotation, Try, Catch, Finally, Method, Attr_Decl, Shift, Equality, Bitwise_And, Bitwise_Xor, Bitwise_Or, - Logical_And, Logical_Or, Reference + Logical_And, Logical_Or, Reference, Switch, Case, Default }; }; @@ -37,7 +37,7 @@ namespace chaiscript "Comparison", "Addition", "Subtraction", "Multiplication", "Division", "Modulus", "Array_Call", "Dot_Access", "Quoted_String", "Single_Quoted_String", "Lambda", "Block", "Def", "While", "If", "For", "Inline_Array", "Inline_Map", "Return", "File", "Prefix", "Break", "Map_Pair", "Value_Range", "Inline_Range", "Annotation", "Try", "Catch", "Finally", "Method", "Attr_Decl", "Shift", "Equality", "Bitwise_And", "Bitwise_Xor", "Bitwise_Or", - "Logical_And", "Logical_Or", "Reference"}; + "Logical_And", "Logical_Or", "Reference", "Switch", "Case", "Default"}; return ast_node_types[ast_node_type]; } diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index ad8ecd22..7f672577 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -799,6 +799,77 @@ namespace chaiscript }; + struct Switch_AST_Node : public AST_Node { + public: + Switch_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Switch, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } + virtual ~Switch_AST_Node() {} + virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) { + Boxed_Value match_value; + bool breaking = false; + int currentCase = 1; + bool hasMatched = false; + + chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); + + match_value = this->children[0]->eval(t_ss); + + while (!breaking && (currentCase < this->children.size())) { + try { + 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(t_ss.call_function("==", match_value, this->children[currentCase]->children[0]->eval(t_ss)))) { + this->children[currentCase]->eval(t_ss); + hasMatched = true; + } + } + catch (const exception::bad_boxed_cast &) { + throw exception::eval_error("Internal error: case guard evaluation not boolean"); + } + } + else if (this->children[currentCase]->identifier == AST_Node_Type::Default) { + this->children[currentCase]->eval(t_ss); + breaking = true; + } + } + catch (detail::Break_Loop &) { + breaking = true; + } + ++currentCase; + } + return Boxed_Value(); + } + }; + + struct Case_AST_Node : public AST_Node { + public: + Case_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Case, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } + virtual ~Case_AST_Node() {} + virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) { + chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); + + this->children[1]->eval(t_ss); + + return Boxed_Value(); + } + }; + + struct Default_AST_Node : public AST_Node { + public: + Default_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Default, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : + AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col) { } + virtual ~Default_AST_Node() {} + virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &t_ss) { + chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); + + this->children[0]->eval(t_ss); + + return Boxed_Value(); + } + }; + struct Inline_Array_AST_Node : public AST_Node { public: Inline_Array_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Inline_Array, const std::shared_ptr &t_fname=std::shared_ptr(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 6403e664..d1a12b07 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -1416,6 +1416,92 @@ namespace chaiscript return retval; } + /** + * Reads a case block from input + */ + bool Case() { + bool retval = false; + + size_t prev_stack_top = m_match_stack.size(); + + if (Keyword("case")) { + retval = true; + + if (!Char('(')) { + throw exception::eval_error("Incomplete 'case' expression", File_Position(m_line, m_col), *m_filename); + } + + if (!(Operator() && Char(')'))) { + throw exception::eval_error("Incomplete 'case' expression", File_Position(m_line, m_col), *m_filename); + } + + while (Eol()) {} + + if (!Block()) { + throw exception::eval_error("Incomplete 'case' block", File_Position(m_line, m_col), *m_filename); + } + + build_match(AST_NodePtr(new eval::Case_AST_Node()), prev_stack_top); + } + else if (Keyword("default")) { + while (Eol()) {} + + if (!Block()) { + throw exception::eval_error("Incomplete 'default' block", File_Position(m_line, m_col), *m_filename); + } + + build_match(AST_NodePtr(new eval::Default_AST_Node()), prev_stack_top); + } + + return retval; + } + + /** + * Reads a switch statement from input + */ + bool Switch() { + bool retval = false; + + size_t prev_stack_top = m_match_stack.size(); + + if (Keyword("switch")) { + retval = true; + + if (!Char('(')) { + throw exception::eval_error("Incomplete 'switch' expression", File_Position(m_line, m_col), *m_filename); + } + + if (!(Operator() && Char(')'))) { + throw exception::eval_error("Incomplete 'switch' expression", File_Position(m_line, m_col), *m_filename); + } + + while (Eol()) {} + + if (Char('{')) { + retval = true; + + while (Eol()) {} + + while (Case()) { + while (Eol()); + } + + while (Eol()); + + if (!Char('}')) { + throw exception::eval_error("Incomplete block", File_Position(m_line, m_col), *m_filename); + } + } + else { + throw exception::eval_error("Incomplete block", File_Position(m_line, m_col), *m_filename); + } + + build_match(AST_NodePtr(new eval::Switch_AST_Node()), prev_stack_top); + } + + return retval; + } + /** * Reads a curly-brace C-style block from input */ @@ -1957,6 +2043,14 @@ namespace chaiscript retval = true; saw_eol = true; } + else if (Switch()) { + if (!saw_eol) { + throw exception::eval_error("Two function definitions missing line separator", File_Position(prev_line, prev_col), *m_filename); + } + has_more = true; + retval = true; + saw_eol = true; + } else if (Return()) { if (!saw_eol) { throw exception::eval_error("Two expressions missing line separator", File_Position(prev_line, prev_col), *m_filename); diff --git a/unittests/3.x/switch_break.chai b/unittests/3.x/switch_break.chai new file mode 100644 index 00000000..8d362759 --- /dev/null +++ b/unittests/3.x/switch_break.chai @@ -0,0 +1,22 @@ +var total = 0; + +switch(2) { + case (1) { + total += 1; + break; + } + case (2) { + total += 2; + break; + } + case (3) { + total += 4; + break; + } + case (4) { + total += 8; + break; + } +} + +assert_equal(total, 2) diff --git a/unittests/3.x/switch_default.chai b/unittests/3.x/switch_default.chai new file mode 100644 index 00000000..8c48aa50 --- /dev/null +++ b/unittests/3.x/switch_default.chai @@ -0,0 +1,18 @@ +var total = 0; + +switch(2) { + case (1) { + total += 1; + } + case (3) { + total += 4; + } + case (4) { + total += 8; + } + default { + total += 16; + } +} + +assert_equal(total, 16) diff --git a/unittests/3.x/switch_empty.chai b/unittests/3.x/switch_empty.chai new file mode 100644 index 00000000..8d3a1669 --- /dev/null +++ b/unittests/3.x/switch_empty.chai @@ -0,0 +1,4 @@ +switch(true) { } + +// We just have to get here without error for success +assert_equal(true, true); diff --git a/unittests/3.x/switch_fallthru.chai b/unittests/3.x/switch_fallthru.chai new file mode 100644 index 00000000..627b6493 --- /dev/null +++ b/unittests/3.x/switch_fallthru.chai @@ -0,0 +1,18 @@ +var total = 0; + +switch(2) { + case (1) { + total += 1; + } + case (2) { + total += 2; + } + case (3) { + total += 4; + } + case (4) { + total += 8; + } +} + +assert_equal(total, 14); diff --git a/unittests/3.x/switch_fallthru_and_break.chai b/unittests/3.x/switch_fallthru_and_break.chai new file mode 100644 index 00000000..3c93071b --- /dev/null +++ b/unittests/3.x/switch_fallthru_and_break.chai @@ -0,0 +1,19 @@ +var total = 0; + +switch(2) { + case (1) { + total += 1; + } + case (2) { + total += 2; + } + case (3) { + total += 4; + break; + } + case (4) { + total += 8; + } +} + +assert_equal(total, 6) From 7027f6b83483310c4278acc6e26d3be37f9fd895 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 17 May 2012 13:59:43 -0700 Subject: [PATCH 062/108] Add syntax highlighting for switch/case/default --- contrib/geshi/chaiscript.php | 2 +- contrib/vim/syntax/chaiscript.vim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/geshi/chaiscript.php b/contrib/geshi/chaiscript.php index d1fd89c3..1fc6dea7 100644 --- a/contrib/geshi/chaiscript.php +++ b/contrib/geshi/chaiscript.php @@ -48,7 +48,7 @@ $language_data = array ( 'ESCAPE_CHAR' => '\\', 'KEYWORDS' => array( 1 => array( - 'break', 'else', 'else if', 'eval', 'for', 'if', 'return', 'while', 'try', 'catch', 'finally', + 'break', 'else', 'else if', 'eval', 'for', 'if', 'return', 'while', 'try', 'catch', 'finally', 'switch', 'case', 'default', ), 2 => array( 'def', 'false', 'fun', 'true', 'var', 'auto', 'attr', diff --git a/contrib/vim/syntax/chaiscript.vim b/contrib/vim/syntax/chaiscript.vim index dc89d841..e78b4c12 100644 --- a/contrib/vim/syntax/chaiscript.vim +++ b/contrib/vim/syntax/chaiscript.vim @@ -42,7 +42,7 @@ syn match chaiscriptNumber "\<0b[01]\+\>" " Various language features syn keyword chaiscriptCond if else syn keyword chaiscriptRepeat while for do -syn keyword chaiscriptStatement break continue return +syn keyword chaiscriptStatement break continue return switch case default syn keyword chaiscriptExceptions try catch throw "Keyword From 919b6430c493fffc1989a021be350eeb824b2510 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Fri, 18 May 2012 07:36:52 -0700 Subject: [PATCH 063/108] Adding tested compilers to readme. --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index b211c394..741a33fc 100644 --- a/readme.txt +++ b/readme.txt @@ -13,7 +13,7 @@ ChaiScript is one of the only embedded scripting language designed from the grou [Requirements] -ChaiScript requires a C++11 compiler to build with support for variadic templates. +ChaiScript requires a C++11 compiler to build with support for variadic templates. It has been tested with gcc 4.7 and clang 3.1 (with libcxx). [Usage] From b1a27020f794454f92501c1c6a880a9cc7d80fef Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Fri, 1 Jun 2012 14:22:57 -0600 Subject: [PATCH 064/108] Get Cx branch ready for release --- CMakeLists.txt | 2 +- releasenotes.txt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08944f33..b6f765cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/license.txt") set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/readme.txt") set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/description.txt") -set(CPACK_PACKAGE_VERSION_MAJOR 4) +set(CPACK_PACKAGE_VERSION_MAJOR 5) set(CPACK_PACKAGE_VERSION_MINOR 0) set(CPACK_PACKAGE_VERSION_PATCH 0) set(CPACK_PACKAGE_EXECUTABLES "chai;ChaiScript Eval") diff --git a/releasenotes.txt b/releasenotes.txt index 4a523014..e50b6958 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -1,3 +1,7 @@ +Changes since 4.0.0 +* Dropped boost in favor of C++11 +* Separated out stdlib to make more options for compile time improvements + Changes since 3.1.0 * svenstaro: Unused variables and CMake consistency fixes * Added support for returning pointers from functions (#13) From 4ebfe264e98ee393d1a1af50d6c80ee1019434a7 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 3 Jun 2012 08:11:37 -0600 Subject: [PATCH 065/108] Make stdlib * Build the standard library as a module .so * Locate and load lib at runtime as a module if it is not provided to the ChaiScript constructor. Decreases compile time by 1/2 for common use cases where the user can use the dynamic library module. --- CMakeLists.txt | 4 ++ include/chaiscript/chaiscript.hpp | 8 +-- include/chaiscript/chaiscript_defines.hpp | 8 +++ include/chaiscript/chaiscript_stdlib.hpp | 1 + .../chaiscript/language/chaiscript_engine.hpp | 70 ++++++++++++++++++- src/main.cpp | 3 +- 6 files changed, 85 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b6f765cd..1d30e695 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,8 +103,12 @@ if (CMAKE_COMPILER_2005) # ADD_DEFINITIONS(/wd4244) endif() +add_library(chaiscript_stdlib MODULE src/chaiscript_stdlib.cpp) +target_link_libraries(chaiscript_stdlib ${LIBS} ${EXTRA_LINKER_FLAGS}) + add_executable(chai src/main.cpp ${Chai_INCLUDES}) target_link_libraries(chai ${LIBS} ${EXTRA_LINKER_FLAGS}) +add_dependencies(chai chaiscript_stdlib) if (BUILD_SAMPLES) add_executable(example samples/example.cpp) diff --git a/include/chaiscript/chaiscript.hpp b/include/chaiscript/chaiscript.hpp index 11a013a5..380b6eb2 100644 --- a/include/chaiscript/chaiscript.hpp +++ b/include/chaiscript/chaiscript.hpp @@ -752,13 +752,9 @@ #include "dispatchkit/dynamic_object.hpp" #include "dispatchkit/boxed_number.hpp" -#ifdef CHAISCRIPT_HAS_DECLSPEC -#define CHAISCRIPT_MODULE_EXPORT extern "C" __declspec(dllexport) -#else -#define CHAISCRIPT_MODULE_EXPORT extern "C" -#endif - #include "language/chaiscript_eval.hpp" #include "language/chaiscript_engine.hpp" + + #endif /* CHAISCRIPT_HPP_ */ diff --git a/include/chaiscript/chaiscript_defines.hpp b/include/chaiscript/chaiscript_defines.hpp index 162454ce..de6aeb9c 100644 --- a/include/chaiscript/chaiscript_defines.hpp +++ b/include/chaiscript/chaiscript_defines.hpp @@ -16,5 +16,13 @@ #define CHAISCRIPT_WINDOWS #endif + +#ifdef CHAISCRIPT_HAS_DECLSPEC +#define CHAISCRIPT_MODULE_EXPORT extern "C" __declspec(dllexport) +#else +#define CHAISCRIPT_MODULE_EXPORT extern "C" +#endif + + #endif diff --git a/include/chaiscript/chaiscript_stdlib.hpp b/include/chaiscript/chaiscript_stdlib.hpp index 8f4bafa0..0fdad697 100644 --- a/include/chaiscript/chaiscript_stdlib.hpp +++ b/include/chaiscript/chaiscript_stdlib.hpp @@ -7,6 +7,7 @@ #ifndef CHAISCRIPT_STDLIB_HPP_ #define CHAISCRIPT_STDLIB_HPP_ +#include "chaiscript_defines.hpp" #include "dispatchkit/bootstrap.hpp" #include "dispatchkit/bootstrap_stl.hpp" diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index c9dd0bd7..77d5fe0e 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -325,7 +325,10 @@ namespace chaiscript m_engine.add_reserved_word("false"); m_engine.add_reserved_word("_"); - add(t_lib); + if (t_lib) + { + add(t_lib); + } m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::dump_system, std::ref(m_engine)), "dump_system"); m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::dump_object, std::ref(m_engine)), "dump_object"); @@ -399,6 +402,71 @@ namespace chaiscript build_eval_system(t_lib); } + /// \brief Constructor for ChaiScript. + /// + /// This version of the ChaiScript constructor attempts to find the stdlib module to load + /// at runtime generates an error if it cannot be found. + /// + /// \param[in] t_modulepaths Vector of paths to search when attempting to load a binary module + /// \param[in] t_usepaths Vector of paths to search when attempting to "use" an included ChaiScript file + ChaiScript( const std::vector &t_modulepaths = std::vector(), + const std::vector &t_usepaths = std::vector()) + : m_modulepaths(t_modulepaths), m_usepaths(t_usepaths) + { + if (m_modulepaths.empty()) + { + m_modulepaths.push_back(""); + } + + if (m_usepaths.empty()) + { + m_usepaths.push_back(""); + } + + +#ifdef _POSIX_VERSION + // If on Unix, add the path of the current executable to the module search path + // as windows would do + + union cast_union + { + void (ChaiScript::*in_ptr)(const std::string&); + void *out_ptr; + }; + + Dl_info rInfo; + memset( &rInfo, 0, sizeof(rInfo) ); + cast_union u; + u.in_ptr = &ChaiScript::use; + if ( dladdr((void*)(u.out_ptr), &rInfo) && rInfo.dli_fname ) { + std::string dllpath(rInfo.dli_fname); + size_t lastslash = dllpath.rfind('/'); + if (lastslash != std::string::npos) + { + dllpath.erase(lastslash); + } + + // Let's see if this is a link that we should expand + std::vector buf(2048); + size_t pathlen = readlink(dllpath.c_str(), &buf.front(), buf.size()); + if (pathlen > 0 && pathlen < buf.size()) + { + dllpath = std::string(&buf.front(), pathlen); + } + + m_modulepaths.push_back(dllpath+"/"); + } +#endif + + + // attempt to load the stdlib + load_module("chaiscript_stdlib"); + + build_eval_system(ModulePtr()); + } + + + /// \brief Loads and parses a file. If the file is already, it is not reloaded /// The use paths specified at ChaiScript construction time are searched for the /// requested file. diff --git a/src/main.cpp b/src/main.cpp index c990374f..74917a50 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,7 +10,6 @@ #define _CRT_SECURE_NO_WARNINGS #include -#include #ifdef READLINE_AVAILABLE #include @@ -177,7 +176,7 @@ int main(int argc, char *argv[]) modulepaths.push_back(modulepath); } - chaiscript::ChaiScript chai(chaiscript::Std_Lib::library(), modulepaths,usepaths); + chaiscript::ChaiScript chai(modulepaths,usepaths); chai.add(chaiscript::fun(&myexit), "exit"); chai.add(chaiscript::fun(&myexit), "quit"); From 30104cc3ed8bf4dada12c6d69573ee0db2daf6bc Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 3 Jun 2012 18:50:51 -0600 Subject: [PATCH 066/108] Add missing file --- src/chaiscript_stdlib.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/chaiscript_stdlib.cpp diff --git a/src/chaiscript_stdlib.cpp b/src/chaiscript_stdlib.cpp new file mode 100644 index 00000000..cef0473b --- /dev/null +++ b/src/chaiscript_stdlib.cpp @@ -0,0 +1,21 @@ + +#include + + +// MSVC doesn't like that we are using C++ return types from our C declared module +// but this is the best way to do it for cross platform compatibility +#ifdef CHAISCRIPT_MSVC +#pragma warning(push) +#pragma warning(disable : 4190) +#endif + + +CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_chaiscript_stdlib() +{ + return chaiscript::Std_Lib::library(); +} + + +#ifdef CHAISCRIPT_MSVC +#pragma warning(pop) +#endif From b7e1cf41e5b598ec6bdd21446aa833d847a0b772 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 4 Jun 2012 07:31:20 -0600 Subject: [PATCH 067/108] Move to using the new constructor that searched for the stdlib to improve compile time. --- samples/example.cpp | 4 ++-- unittests/cpp_lambda_test.cpp | 3 +-- unittests/dynamic_object_test.cpp | 3 +-- unittests/eval_catch_exception_test.cpp | 11 +++++------ unittests/function_ordering_test.cpp | 3 +-- unittests/functor_cast_test.cpp | 3 +-- unittests/functor_creation_test.cpp | 3 +-- unittests/object_lifetime_test.cpp | 3 +-- unittests/short_comparison_test.cpp | 3 +-- 9 files changed, 14 insertions(+), 22 deletions(-) diff --git a/samples/example.cpp b/samples/example.cpp index e5838b08..e7534515 100644 --- a/samples/example.cpp +++ b/samples/example.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include void log(const std::string &msg) @@ -67,7 +67,7 @@ void take_shared_ptr(const std::shared_ptr &p) int main(int /*argc*/, char * /*argv*/[]) { using namespace chaiscript; - ChaiScript chai(Std_Lib::library()); + ChaiScript chai; //Create a new system object and share it with the chaiscript engine System system; diff --git a/unittests/cpp_lambda_test.cpp b/unittests/cpp_lambda_test.cpp index ec5a0ff0..d38983de 100644 --- a/unittests/cpp_lambda_test.cpp +++ b/unittests/cpp_lambda_test.cpp @@ -1,6 +1,5 @@ #include -#include int main() { @@ -9,7 +8,7 @@ int main() // in an std::function or provide the signature - chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + chaiscript::ChaiScript chai; // provide the signature chai.add(chaiscript::fun([] { return "hello"; } ), "f1"); diff --git a/unittests/dynamic_object_test.cpp b/unittests/dynamic_object_test.cpp index 60c1e5e9..3e09ef64 100644 --- a/unittests/dynamic_object_test.cpp +++ b/unittests/dynamic_object_test.cpp @@ -1,5 +1,4 @@ -#include #include template @@ -16,7 +15,7 @@ void assert_equal(const LHS &lhs, const RHS &rhs) int main() { - chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + chaiscript::ChaiScript chai; chai("attr bob::z; def bob::bob() { this.z = 10 }; auto x = bob()"); diff --git a/unittests/eval_catch_exception_test.cpp b/unittests/eval_catch_exception_test.cpp index 0a7aced1..21510d79 100644 --- a/unittests/eval_catch_exception_test.cpp +++ b/unittests/eval_catch_exception_test.cpp @@ -1,11 +1,10 @@ // Tests to make sure that the order in which function dispatches occur is correct #include -#include int test_generic() { - chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + chaiscript::ChaiScript chai; try { chai.eval("throw(runtime_error(\"error\"));"); @@ -23,7 +22,7 @@ int test_generic() int test_1() { - chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + chaiscript::ChaiScript chai; try { chai.eval("throw(1)", chaiscript::exception_specification()); @@ -40,7 +39,7 @@ int test_1() int test_2() { - chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + chaiscript::ChaiScript chai; try { chai.eval("throw(1.0)", chaiscript::exception_specification()); @@ -57,7 +56,7 @@ int test_2() int test_5() { - chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + chaiscript::ChaiScript chai; try { chai.eval("throw(runtime_error(\"error\"))", chaiscript::exception_specification()); @@ -83,7 +82,7 @@ int test_5() int test_unhandled() { - chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + chaiscript::ChaiScript chai; try { chai.eval("throw(\"error\")", chaiscript::exception_specification()); diff --git a/unittests/function_ordering_test.cpp b/unittests/function_ordering_test.cpp index 125c2a1f..00552207 100644 --- a/unittests/function_ordering_test.cpp +++ b/unittests/function_ordering_test.cpp @@ -1,7 +1,6 @@ // Tests to make sure that the order in which function dispatches occur is correct #include -#include int test_one(const int &) { @@ -15,7 +14,7 @@ int test_two(int &) int main() { - chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + chaiscript::ChaiScript chai; chai.eval("def test_fun(x) { return 3; }"); chai.eval("def test_fun(x) : x == \"hi\" { return 4; }"); // chai.eval("def test_fun(x) { return 5; }"); diff --git a/unittests/functor_cast_test.cpp b/unittests/functor_cast_test.cpp index 33250c90..7c76ca20 100644 --- a/unittests/functor_cast_test.cpp +++ b/unittests/functor_cast_test.cpp @@ -1,5 +1,4 @@ #include -#include double test_call(const std::function &f, int val) { @@ -9,7 +8,7 @@ double test_call(const std::function &f, int val) int main() { - chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + chaiscript::ChaiScript chai; chai.add(chaiscript::fun(&test_call), "test_call"); diff --git a/unittests/functor_creation_test.cpp b/unittests/functor_creation_test.cpp index d5289cbc..bea12447 100644 --- a/unittests/functor_creation_test.cpp +++ b/unittests/functor_creation_test.cpp @@ -1,11 +1,10 @@ #include -#include int main() { - chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + chaiscript::ChaiScript chai; chai.eval("def func() { print(\"Hello World\"); } "); diff --git a/unittests/object_lifetime_test.cpp b/unittests/object_lifetime_test.cpp index 6d24f9c8..ab66ad76 100644 --- a/unittests/object_lifetime_test.cpp +++ b/unittests/object_lifetime_test.cpp @@ -1,5 +1,4 @@ #include -#include class Test { @@ -37,7 +36,7 @@ int main() { {chaiscript::fun(&Test::count), "count"} } ); - chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + chaiscript::ChaiScript chai; chai.add(m); // chai.add(chaiscript::fun(&Test::count), "count"); diff --git a/unittests/short_comparison_test.cpp b/unittests/short_comparison_test.cpp index 8295f326..5aacfdc2 100644 --- a/unittests/short_comparison_test.cpp +++ b/unittests/short_comparison_test.cpp @@ -1,5 +1,4 @@ #include -#include class Test { public: @@ -13,7 +12,7 @@ class Test { int main() { - chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + chaiscript::ChaiScript chai; chai.add(chaiscript::user_type(), "Test"); chai.add(chaiscript::constructor(), "Test"); From a951d2b0af10b33b77f0656d75cc4695254b572c Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 4 Jun 2012 07:32:05 -0600 Subject: [PATCH 068/108] Fix crash discovered by the move to using stdlib for all tests. --- include/chaiscript/dispatchkit/dispatchkit.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index 625b855c..5a764e55 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -154,6 +154,11 @@ namespace chaiscript apply_globals(m_globals.begin(), m_globals.end(), t_engine); } + ~Module() + { + detail::Dynamic_Conversions::get().cleanup(m_conversions.begin(), m_conversions.end()); + } + private: std::vector > m_typeinfos; std::vector > m_funcs; From a67022e31ebb004cff19b59cd4cbd5a1fa9502e1 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 7 Jun 2012 20:04:14 -0600 Subject: [PATCH 069/108] Prep for 5.0.0 release --- unittests/3.x/boxed_cast_test.cpp | 319 -------------------- unittests/3.x/dynamic_object_test.cpp | 44 --- unittests/3.x/eval_catch_exception_test.cpp | 122 -------- unittests/3.x/function_ordering_test.cpp | 38 --- unittests/3.x/functor_cast_test.cpp | 25 -- unittests/3.x/functor_creation_test.cpp | 26 -- unittests/3.x/multifile_test_chai.cpp | 12 - unittests/3.x/multifile_test_chai.hpp | 14 - unittests/3.x/multifile_test_main.cpp | 14 - unittests/3.x/multifile_test_module.cpp | 21 -- unittests/3.x/multifile_test_module.hpp | 11 - unittests/3.x/object_lifetime_test.cpp | 66 ---- unittests/3.x/short_comparison_test.cpp | 29 -- unittests/3.x/type_info_test.cpp | 32 -- unittests/3.x/utility_test.cpp | 42 --- 15 files changed, 815 deletions(-) delete mode 100644 unittests/3.x/boxed_cast_test.cpp delete mode 100644 unittests/3.x/dynamic_object_test.cpp delete mode 100644 unittests/3.x/eval_catch_exception_test.cpp delete mode 100644 unittests/3.x/function_ordering_test.cpp delete mode 100644 unittests/3.x/functor_cast_test.cpp delete mode 100644 unittests/3.x/functor_creation_test.cpp delete mode 100644 unittests/3.x/multifile_test_chai.cpp delete mode 100644 unittests/3.x/multifile_test_chai.hpp delete mode 100644 unittests/3.x/multifile_test_main.cpp delete mode 100644 unittests/3.x/multifile_test_module.cpp delete mode 100644 unittests/3.x/multifile_test_module.hpp delete mode 100644 unittests/3.x/object_lifetime_test.cpp delete mode 100644 unittests/3.x/short_comparison_test.cpp delete mode 100644 unittests/3.x/type_info_test.cpp delete mode 100644 unittests/3.x/utility_test.cpp diff --git a/unittests/3.x/boxed_cast_test.cpp b/unittests/3.x/boxed_cast_test.cpp deleted file mode 100644 index 2e6edd9f..00000000 --- a/unittests/3.x/boxed_cast_test.cpp +++ /dev/null @@ -1,319 +0,0 @@ -#include - - -using namespace chaiscript; - - -template -void use(T){} - -template -bool run_test_type_conversion(const Boxed_Value &bv, bool expectedpass) -{ - try { - To ret = chaiscript::boxed_cast(bv); - use(ret); - } catch (const chaiscript::exception::bad_boxed_cast &/*e*/) { - if (expectedpass) { -// std::cerr << "Failure in run_test_type_conversion: " << e.what() << std::endl; - return false; - } else { - return true; - } - } catch (const std::exception &e) { - std::cerr << "Unexpected standard exception when attempting cast_conversion: " << e.what() << std::endl; - return false; - } catch (...) { - std::cerr << "Unexpected unknown exception when attempting cast_conversion." << std::endl; - return false; - } - - if (expectedpass) - { - return true; - } else { - return false; - } -} - -template -bool test_type_conversion(const Boxed_Value &bv, bool expectedpass) -{ - bool ret = run_test_type_conversion(bv, expectedpass); - - if (!ret) - { - std::cerr << "Error with type conversion test. From: " - << (bv.is_const()?(std::string("const ")):(std::string())) << bv.get_type_info().name() - << " To: " - << (boost::is_const::value?(std::string("const ")):(std::string())) << typeid(To).name() - << " test was expected to " << ((expectedpass)?(std::string("succeed")):(std::string("fail"))) << " but did not" << std::endl; - } - - return ret; -} - -template -bool do_test(const Boxed_Value &bv, bool T, bool ConstT, bool TRef, bool ConstTRef, bool TPtr, bool ConstTPtr, bool TPtrConst, - bool ConstTPtrConst, bool SharedPtrT, bool SharedConstPtrT, - bool ConstSharedPtrT, bool ConstSharedConstPtrT, bool ConstSharedPtrTRef, bool ConstSharedPtrTConstRef, - bool BoostRef, bool BoostConstRef, bool ConstBoostRef, bool ConstBoostConstRef, - bool ConstBoostRefRef, bool ConstBoostConstRefRef, bool Number, - bool ConstNumber, bool ConstNumberRef, bool TPtrConstRef, bool ConstTPtrConstRef) -{ - bool passed = true; - passed &= test_type_conversion(bv, T); - passed &= test_type_conversion(bv, ConstT); - passed &= test_type_conversion(bv, TRef); - passed &= test_type_conversion(bv, ConstTRef); - passed &= test_type_conversion(bv, TPtr); - passed &= test_type_conversion(bv, ConstTPtr); - passed &= test_type_conversion(bv, TPtrConst); - passed &= test_type_conversion(bv, ConstTPtrConst); - passed &= test_type_conversion >(bv, SharedPtrT); - passed &= test_type_conversion >(bv, SharedConstPtrT); - passed &= test_type_conversion &>(bv, false); - passed &= test_type_conversion &>(bv, false); - passed &= test_type_conversion >(bv, ConstSharedPtrT); - passed &= test_type_conversion >(bv, ConstSharedConstPtrT); - passed &= test_type_conversion &>(bv, ConstSharedPtrTRef); - passed &= test_type_conversion &>(bv, ConstSharedPtrTConstRef); - passed &= test_type_conversion >(bv, BoostRef); - passed &= test_type_conversion >(bv, BoostConstRef); - passed &= test_type_conversion &>(bv, false); - passed &= test_type_conversion &>(bv, false); - passed &= test_type_conversion >(bv, ConstBoostRef); - passed &= test_type_conversion >(bv, ConstBoostConstRef); - passed &= test_type_conversion &>(bv, ConstBoostRefRef); - passed &= test_type_conversion &>(bv, ConstBoostConstRefRef); - passed &= test_type_conversion(bv, Number); - passed &= test_type_conversion(bv, ConstNumber); - passed &= test_type_conversion(bv, false); - passed &= test_type_conversion(bv, ConstNumberRef); - passed &= test_type_conversion(bv, false); - passed &= test_type_conversion(bv, false); - passed &= test_type_conversion(bv, false); - passed &= test_type_conversion(bv, false); - passed &= test_type_conversion(bv, false); - passed &= test_type_conversion(bv, false); - passed &= test_type_conversion(bv, TPtrConstRef); - passed &= test_type_conversion(bv, ConstTPtrConstRef); - passed &= test_type_conversion(bv, true); - passed &= test_type_conversion(bv, true); - passed &= test_type_conversion(bv, true); - - return passed; -} - -/** Tests intended for built int types **/ -template -bool built_in_type_test(const T &initial, bool ispod) -{ - bool passed = true; - - /** value tests **/ - T i = T(initial); - passed &= do_test(var(i), true, true, true, true, true, - true, true, true, true, true, - true, true, true, true, true, - true, true, true, true, true, - ispod && true, ispod && true, ispod && true, true, true); - - passed &= do_test(const_var(i), true, true, false, true, false, - true, false, true, false, true, - false, true, false, true, false, - true, false, true, false, true, - ispod && true, ispod && true, ispod && true, false, true); - - passed &= do_test(var(&i), true, true, true, true, true, - true, true, true, false, false, - false, false, false, false, true, - true, true, true, true, true, - ispod && true, ispod && true, ispod && true, true, true); - - passed &= do_test(const_var(&i), true, true, false, true, false, - true, false, true, false, false, - false, false, false, false, false, - true, false, true, false, true, - ispod && true, ispod && true, ispod && true, ispod && false, true); - - passed &= do_test(var(boost::ref(i)), true, true, true, true, true, - true, true, true, false, false, - false, false, false, false, true, - true, true, true, true, true, - ispod && true, ispod && true, ispod && true, true, true); - - passed &= do_test(var(boost::cref(i)), true, true, false, true, false, - true, false, true, false, false, - false, false, false, false, false, - true, false, true, false, true, - ispod && true, ispod && true, ispod && true, false, true); - - /** Const Reference Variable tests */ - - // This reference will be copied on input, which is expected - const T &ir = i; - - passed &= do_test(var(i), true, true, true, true, true, - true, true, true, true, true, - true, true, true, true, true, - true, true, true, true, true, - ispod && true, ispod && true, ispod && true, true, true); - - // But a pointer or reference to it should be necessarily const - passed &= do_test(var(&ir), true, true, false, true, false, - true, false, true, false, false, - false, false, false, false, false, - true, false, true, false, true, - ispod && true, ispod && true, ispod && true, false, true); - - passed &= do_test(var(boost::ref(ir)), true, true, false, true, false, - true, false, true, false, false, - false, false, false, false, false, - true, false, true, false, true, - ispod && true, ispod && true, ispod && true, false, true); - - // Make sure const of const works too - passed &= do_test(const_var(&ir), true, true, false, true, false, - true, false, true, false, false, - false, false, false, false, false, - true, false, true, false, true, - ispod && true, ispod && true, ispod && true, false, true); - - passed &= do_test(const_var(boost::ref(ir)), true, true, false, true, false, - true, false, true, false, false, - false, false, false, false, false, - true, false, true, false, true, - ispod && true, ispod && true, ispod && true, false, true); - - /** Const Reference Variable tests */ - - // This will always be seen as a const - const T*cip = &i; - passed &= do_test(var(cip), true, true, false, true, false, - true, false, true, false, false, - false, false, false, false, false, - true, false, true, false, true, - ispod && true, ispod && true, ispod && true, false, true); - - // make sure const of const works - passed &= do_test(const_var(cip), true, true, false, true, false, - true, false, true, false, false, - false, false, false, false, false, - true, false, true, false, true, - ispod && true, ispod && true, ispod && true, false, true); - - /** shared_ptr tests **/ - - boost::shared_ptr ip(new T(initial)); - - passed &= do_test(var(ip), true, true, true, true, true, - true, true, true, true, true, - true, true, true, true, true, - true, true, true, true, true, - ispod && true, ispod && true, ispod && true, true, true); - - passed &= do_test(const_var(ip), true, true, false, true, false, - true, false, true, false, true, - false, true, false, true, false, - true, false, true, false, true, - ispod && true, ispod && true, ispod && true, false, true); - - /** const shared_ptr tests **/ - boost::shared_ptr ipc(new T(initial)); - - passed &= do_test(var(ipc), true, true, false, true, false, - true, false, true, false, true, - false, true, false, true, false, - true, false, true, false, true, - ispod && true, ispod && true, ispod && true, false, true); - - // const of this should be the same, making sure it compiles - passed &= do_test(const_var(ipc), true, true, false, true, false, - true, false, true, false, true, - false, true, false, true, false, - true, false, true, false, true, - ispod && true, ispod && true, ispod && true, false, true); - - - /** Double ptr tests **/ - - /* - T **doublep; - - passed &= do_test(var(doublep), true, true, false, true, false, - true, false, true, false, true, - false, true, false, true, false, - true, false, true, false, true, - ispod && true, ispod && true, ispod && true, false, true); -*/ - - return passed; -} - - -template -bool pointer_test(const T& default_value, const T& new_value) -{ - T *p = new T(default_value); - - // we store a pointer to a pointer, so we can get a pointer to a pointer - try { - T **result = boxed_cast(var(&p)); - *(*result) = new_value; - - - if (p != (*result) ) { - std::cerr << "Pointer passed in different than one returned" << std::endl; - return false; - } - - if (*p != *(*result) ) { - std::cerr << "Somehow dereferenced pointer values are not the same?" << std::endl; - return false; - } - - return true; - } catch (const exception::bad_boxed_cast &) { - std::cerr << "Bad boxed cast performing ** to ** test" << std::endl; - return false; - } catch (...) { - std::cerr << "Unknown exception performing ** to ** test" << std::endl; - return false; - } - - -} - - -int main() -{ - bool passed = true; - - /* - bool T, bool ConstT, bool TRef, bool ConstTRef, bool TPtr, - bool ConstTPtr, bool TPtrConst, bool ConstTPtrConst, bool SharedPtrT, bool SharedConstPtrT, - bool ConstSharedPtrT, bool ConstSharedConstPtrT, bool ConstSharedPtrTRef, bool ConstSharedPtrTConstRef, bool BoostRef, - bool BoostConstRef, bool ConstBoostRef, bool ConstBoostConstRef, bool ConstBoostRefRef, bool ConstBoostConstRefRef, - bool Number, bool ConstNumber, bool ConstNumberRef - */ - - passed &= built_in_type_test(5, true); - passed &= built_in_type_test(1.1, true); - passed &= built_in_type_test('a', true); - passed &= built_in_type_test('a', true); - passed &= built_in_type_test('a', true); - passed &= built_in_type_test(false, false); - passed &= built_in_type_test("Hello World", false); - - // storing a pointer - passed &= pointer_test(1, 0); - - if (passed) - { - return EXIT_SUCCESS; - } else { - return EXIT_FAILURE; - } - -} diff --git a/unittests/3.x/dynamic_object_test.cpp b/unittests/3.x/dynamic_object_test.cpp deleted file mode 100644 index 8383e039..00000000 --- a/unittests/3.x/dynamic_object_test.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include - -template -void assert_equal(const LHS &lhs, const RHS &rhs) -{ - if (lhs==rhs) - { - return; - } else { - std::cout << "Got: " << lhs << " expected " << rhs << std::endl; - exit(EXIT_FAILURE); - } -} - -int main() -{ - - chaiscript::ChaiScript chai; - - chai("attr bob::z; def bob::bob() { this.z = 10 }; var x = bob()"); - - chaiscript::dispatch::Dynamic_Object &mydo = chai.eval("x"); - - assert_equal(mydo.get_type_name(), "bob"); - - assert_equal(chaiscript::boxed_cast(mydo.get_attr("z")), 10); - - chai("x.z = 15"); - - assert_equal(chaiscript::boxed_cast(mydo.get_attr("z")), 15); - - int &z = chaiscript::boxed_cast(mydo.get_attr("z")); - - assert_equal(z, 15); - - z = 20; - - assert_equal(z, 20); - - assert_equal(chaiscript::boxed_cast(chai("x.z")), 20); - - return EXIT_SUCCESS; - -} diff --git a/unittests/3.x/eval_catch_exception_test.cpp b/unittests/3.x/eval_catch_exception_test.cpp deleted file mode 100644 index c599c091..00000000 --- a/unittests/3.x/eval_catch_exception_test.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// Tests to make sure that the order in which function dispatches occur is correct - -#include - -int test_generic() -{ - chaiscript::ChaiScript chai; - - try { - chai.eval("throw(runtime_error(\"error\"));"); - } catch (const chaiscript::Boxed_Value &bv) { - const std::exception &e = chaiscript::boxed_cast(bv); - if (e.what() == std::string("error")) - { - return EXIT_SUCCESS; - } - } - - std::cout << "test_generic failed" << std::endl; - return EXIT_FAILURE; -} - -int test_1() -{ - chaiscript::ChaiScript chai; - - try { - chai.eval("throw(1)", chaiscript::exception_specification()); - } catch (int e) { - if (e == 1) - { - return EXIT_SUCCESS; - } - } - - std::cout << "test_1 failed" << std::endl; - return EXIT_FAILURE; -} - -int test_2() -{ - chaiscript::ChaiScript chai; - - try { - chai.eval("throw(1.0)", chaiscript::exception_specification()); - } catch (const double e) { - if (e == 1.0) - { - return EXIT_SUCCESS; - } - } - - std::cout << "test_2 failed" << std::endl; - return EXIT_FAILURE; -} - -int test_5() -{ - chaiscript::ChaiScript chai; - - try { - chai.eval("throw(runtime_error(\"error\"))", chaiscript::exception_specification()); - } catch (const double e) { - std::cout << "test_5 failed with double" << std::endl; - return EXIT_FAILURE; - } catch (int) { - std::cout << "test_5 failed with int" << std::endl; - return EXIT_FAILURE; - } catch (float) { - std::cout << "test_5 failed with float" << std::endl; - return EXIT_FAILURE; - } catch (const std::string &) { - std::cout << "test_5 failed with string" << std::endl; - return EXIT_FAILURE; - } catch (const std::exception &e) { - return EXIT_SUCCESS; - } - - std::cout << "test_5 failed" << std::endl; - return EXIT_FAILURE; -} - -int test_unhandled() -{ - chaiscript::ChaiScript chai; - - try { - chai.eval("throw(\"error\")", chaiscript::exception_specification()); - } catch (double) { - std::cout << "test_unhandled failed with double" << std::endl; - return EXIT_FAILURE; - } catch (int) { - std::cout << "test_unhandled failed with int" << std::endl; - return EXIT_FAILURE; - } catch (float) { - std::cout << "test_unhandled failed with float" << std::endl; - return EXIT_FAILURE; - } catch (const std::exception &e) { - std::cout << "test_unhandled failed with std::exception" << std::endl; - return EXIT_FAILURE; - } catch (const chaiscript::Boxed_Value &bv) { - return EXIT_SUCCESS; - } - - std::cout << "test_unhandled failed" << std::endl; - return EXIT_FAILURE; -} - - -int main() -{ - if (test_generic() == EXIT_SUCCESS - && test_1() == EXIT_SUCCESS - && test_2() == EXIT_SUCCESS - && test_5() == EXIT_SUCCESS - && test_unhandled() == EXIT_SUCCESS) - { - return EXIT_SUCCESS; - } else { - return EXIT_FAILURE; - } -} diff --git a/unittests/3.x/function_ordering_test.cpp b/unittests/3.x/function_ordering_test.cpp deleted file mode 100644 index 0a9652c6..00000000 --- a/unittests/3.x/function_ordering_test.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Tests to make sure that the order in which function dispatches occur is correct - -#include - -int test_one(const int &) -{ - return 1; -} - -int test_two(int &) -{ - return 2; -} - -int main() -{ - chaiscript::ChaiScript chai; - chai.eval("def test_fun(x) { return 3; }"); - chai.eval("def test_fun(x) : x == \"hi\" { return 4; }"); - chai.eval("def test_fun(x) { return 5; }"); - chai.add(chaiscript::fun(&test_one), "test_fun"); - chai.add(chaiscript::fun(&test_two), "test_fun"); - - int res1 = chai.eval("test_fun(1)"); - int res2 = chai.eval("var i = 1; test_fun(i)"); - int res3 = chai.eval("test_fun(\"bob\")"); - int res4 = chai.eval("test_fun(\"hi\")"); - - if (res1 == 1 - && res2 == 2 - && res3 == 3 - && res4 == 4 ) - { - return EXIT_SUCCESS; - } else { - return EXIT_FAILURE; - } -} diff --git a/unittests/3.x/functor_cast_test.cpp b/unittests/3.x/functor_cast_test.cpp deleted file mode 100644 index 1f6f7ec1..00000000 --- a/unittests/3.x/functor_cast_test.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include - -double test_call(const boost::function &f, int val) -{ - return f(val); -} - -int main() -{ - - chaiscript::ChaiScript chai; - - chai.add(chaiscript::fun(&test_call), "test_call"); - - chai.eval("def func(i) { return i * 3.5; };"); - double d = chai.eval("test_call(func, 3)"); - - if (d == 3 * 3.5) - { - return EXIT_SUCCESS; - } else { - return EXIT_FAILURE; - } - -} diff --git a/unittests/3.x/functor_creation_test.cpp b/unittests/3.x/functor_creation_test.cpp deleted file mode 100644 index 6578a6d5..00000000 --- a/unittests/3.x/functor_creation_test.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include - -int main() -{ - - chaiscript::ChaiScript chai; - - chai.eval("def func() { print(\"Hello World\"); } "); - - boost::function f = chai.eval >("func"); - f(); - - if (chai.eval >("to_string")(6) != "6") - { - return EXIT_FAILURE; - } - - if (chai.eval >("to_string")(chaiscript::var(6)) == "6") - { - return EXIT_SUCCESS; - } else { - return EXIT_FAILURE; - } - - -} diff --git a/unittests/3.x/multifile_test_chai.cpp b/unittests/3.x/multifile_test_chai.cpp deleted file mode 100644 index 57b89528..00000000 --- a/unittests/3.x/multifile_test_chai.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "multifile_test_chai.hpp" - -Multi_Test_Chai::Multi_Test_Chai() - : m_chai(new chaiscript::ChaiScript()) -{ -} - - -boost::shared_ptr Multi_Test_Chai::get_chai() -{ - return m_chai; -} diff --git a/unittests/3.x/multifile_test_chai.hpp b/unittests/3.x/multifile_test_chai.hpp deleted file mode 100644 index 430b6bc5..00000000 --- a/unittests/3.x/multifile_test_chai.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#include - -class Multi_Test_Chai -{ - public: - Multi_Test_Chai(); - - boost::shared_ptr get_chai(); - - private: - boost::shared_ptr m_chai; -}; - - diff --git a/unittests/3.x/multifile_test_main.cpp b/unittests/3.x/multifile_test_main.cpp deleted file mode 100644 index 8352ec8b..00000000 --- a/unittests/3.x/multifile_test_main.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "multifile_test_chai.hpp" -#include "multifile_test_module.hpp" - -#include - -int main() -{ - Multi_Test_Chai chaitest; - Multi_Test_Module chaimodule; - - boost::shared_ptr chai = chaitest.get_chai(); - chai->add(chaimodule.get_module()); - return chai->eval("get_module_value()"); -} diff --git a/unittests/3.x/multifile_test_module.cpp b/unittests/3.x/multifile_test_module.cpp deleted file mode 100644 index 2457416f..00000000 --- a/unittests/3.x/multifile_test_module.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include - -#include "multifile_test_module.hpp" - -Multi_Test_Module::Multi_Test_Module() -{ -} - -int Multi_Test_Module::get_module_value() -{ - return 0; -} - -chaiscript::ModulePtr Multi_Test_Module::get_module() -{ - chaiscript::ModulePtr module(new chaiscript::Module()); - - module->add(chaiscript::fun(&Multi_Test_Module::get_module_value), "get_module_value"); - - return module; -} diff --git a/unittests/3.x/multifile_test_module.hpp b/unittests/3.x/multifile_test_module.hpp deleted file mode 100644 index f01d8f1a..00000000 --- a/unittests/3.x/multifile_test_module.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#include - -class Multi_Test_Module -{ - public: - static int get_module_value(); - - Multi_Test_Module(); - - chaiscript::ModulePtr get_module(); -}; diff --git a/unittests/3.x/object_lifetime_test.cpp b/unittests/3.x/object_lifetime_test.cpp deleted file mode 100644 index d59957b0..00000000 --- a/unittests/3.x/object_lifetime_test.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include - -class Test -{ - public: - Test() - { - ++count(); - } - - Test(const Test &) - { - ++count(); - } - - ~Test() - { - --count(); - } - - static int& count() - { - static int c = 0; - return c; - } -}; - -int main() -{ - chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module()); - - CHAISCRIPT_CLASS( m, - Test, - (Test ()) - (Test (const Test &)), - ((count)) - ); - - chaiscript::ChaiScript chai; - chai.add(m); - chai.add(chaiscript::fun(&Test::count), "count"); - - int count = chai.eval("count()"); - - int count2 = chai.eval("var i = 0; { var t = Test(); } return i;"); - - int count3 = chai.eval("var i = 0; { var t = Test(); i = count(); } return i;"); - - int count4 = chai.eval("var i = 0; { var t = Test(); { var t2 = Test(); i = count(); } } return i;"); - - int count5 = chai.eval("var i = 0; { var t = Test(); { var t2 = Test(); } i = count(); } return i;"); - - int count6 = chai.eval("var i = 0; { var t = Test(); { var t2 = Test(); } } i = count(); return i;"); - - if (count == 0 - && count2 == 0 - && count3 == 1 - && count4 == 2 - && count5 == 1 - && count6 == 0) - { - return EXIT_SUCCESS; - } else { - return EXIT_FAILURE; - } -} diff --git a/unittests/3.x/short_comparison_test.cpp b/unittests/3.x/short_comparison_test.cpp deleted file mode 100644 index a57e39c9..00000000 --- a/unittests/3.x/short_comparison_test.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include - -class Test { - public: - Test() : value_(5) {} - - short get_value() { return value_; } - - short value_; -}; - -int main() -{ - - chaiscript::ChaiScript chai; - chai.add(chaiscript::user_type(), "Test"); - chai.add(chaiscript::constructor(), "Test"); - - chai.add(chaiscript::fun(&Test::get_value), "get_value"); - - chai.eval("var t := Test();"); - - if (chai.eval("t.get_value() == 5")) - { - return EXIT_SUCCESS; - } else { - return EXIT_FAILURE; - } -} diff --git a/unittests/3.x/type_info_test.cpp b/unittests/3.x/type_info_test.cpp deleted file mode 100644 index 361be80f..00000000 --- a/unittests/3.x/type_info_test.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Tests to make sure that the order in which function dispatches occur is correct - -#include - -void test_type(const chaiscript::Type_Info &ti, bool t_is_const, bool t_is_pointer, bool t_is_reference, bool t_is_void, - bool t_is_undef) -{ - if (ti.is_const() == t_is_const - && ti.is_pointer() == t_is_pointer - && ti.is_reference() == t_is_reference - && ti.is_void() == t_is_void - && ti.is_undef() == t_is_undef) - { - return; - } else { - exit(EXIT_FAILURE); - } -} - - -int main() -{ - test_type(chaiscript::user_type(), false, false, false, true, false); - test_type(chaiscript::user_type(), true, false, false, false, false); - test_type(chaiscript::user_type(), true, false, true, false, false); - test_type(chaiscript::user_type(), false, false, false, false, false); - test_type(chaiscript::user_type(), false, true, false, false, false); - test_type(chaiscript::user_type(), true, true, false, false, false); - test_type(chaiscript::Type_Info(), false, false, false, false, true); - - return EXIT_SUCCESS; -} diff --git a/unittests/3.x/utility_test.cpp b/unittests/3.x/utility_test.cpp deleted file mode 100644 index bcd3240b..00000000 --- a/unittests/3.x/utility_test.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include - -class Test -{ - public: - void function() {} - std::string function2() { return "Function2"; } - void function3() {} - std::string functionOverload(double) { return "double"; } - std::string functionOverload(int) { return "int"; } -}; - -int main() -{ - - chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module()); - - CHAISCRIPT_CLASS( m, - Test, - (Test ()) - (Test (const Test &)), - ((function)) - ((function2)) - ((function3)) - ((functionOverload)(std::string (Test::*)(double))) - ((functionOverload)(std::string (Test::*)(int))) - ((operator=)) - ); - - chaiscript::ChaiScript chai; - chai.add(m); - if (chai.eval("var t = Test(); t.function2(); ") == "Function2" - && chai.eval("var t = Test(); t.functionOverload(1); ") == "int" - && chai.eval("var t = Test(); t.functionOverload(1.1); ") == "double") - { - chai.eval("t = Test();"); - return EXIT_SUCCESS; - } else { - return EXIT_FAILURE; - } - -} From d55439a7acb5da5f70fa924da1880b7da20b9d69 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 19 Jun 2012 09:40:51 -0600 Subject: [PATCH 070/108] Fix multithreaded.cpp to compile / run with C++11 --- src/multithreaded.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/multithreaded.cpp b/src/multithreaded.cpp index 95c827af..2a540b8a 100644 --- a/src/multithreaded.cpp +++ b/src/multithreaded.cpp @@ -11,6 +11,9 @@ #include #include + + + void do_work(chaiscript::ChaiScript &c) { // c("use(\"work.chai\"); do_chai_work(num_iterations);"); @@ -30,7 +33,8 @@ int main(int argc, char *argv[]) { for (int i = 0; i < argc - 1; ++i) { - threads.push_back(std::shared_ptr(new std::thread(std::bind(do_work, std::ref(chai))))); +// std::thread t(&do_work, std::ref(chai)); + threads.push_back(std::shared_ptr(new std::thread(&do_work, std::ref(chai)))); } for (int i = 0; i < argc - 1; ++i) From f6e53dd42d60b9db94c36747d6161c7558160cf4 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Fri, 22 Jun 2012 14:18:44 -0600 Subject: [PATCH 071/108] Correct some threading issues - prototype avoiding a lock with __thread in g++ - pass -pthread and -lpthread when building to get threading actually working --- CMakeLists.txt | 5 +++++ include/chaiscript/chaiscript_threading.hpp | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c5be8a7..b95f0e52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,11 @@ endif() if (CMAKE_HOST_UNIX) list(APPEND LIBS "dl") + + if (MULTITHREAD_SUPPORT_ENABLED) + list(APPEND LIBS "pthread") + add_definitions(-pthread) + endif() endif(CMAKE_HOST_UNIX) list(APPEND LIBS ${READLINE_LIB}) diff --git a/include/chaiscript/chaiscript_threading.hpp b/include/chaiscript/chaiscript_threading.hpp index a955e2bc..2821cfc7 100644 --- a/include/chaiscript/chaiscript_threading.hpp +++ b/include/chaiscript/chaiscript_threading.hpp @@ -7,6 +7,8 @@ #ifndef CHAISCRIPT_THREADING_HPP_ #define CHAISCRIPT_THREADING_HPP_ +#include + #ifndef CHAISCRIPT_NO_THREADS #include #include @@ -86,6 +88,7 @@ namespace chaiscript private: std::shared_ptr get_tls() const { + unique_lock lock(m_mutex); auto itr = m_instances.find(std::this_thread::get_id()); @@ -97,10 +100,20 @@ namespace chaiscript m_instances.insert(std::make_pair(std::this_thread::get_id(), new_instance)); return new_instance; + + + /* + static __thread std::shared_ptr *m_data = 0; + + if (!m_data) { m_data = new std::shared_ptr(new T()); } + + return *m_data; + */ } + mutable mutex m_mutex; - mutable std::map > m_instances; + mutable std::unordered_map > m_instances; }; #else From 949f54b9c48b1a9511788900ddce7a7c38db573a Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Fri, 22 Jun 2012 14:19:52 -0600 Subject: [PATCH 072/108] Use constexpr where possible in user_type() functions - Task #52 - Gives some performance improvement --- include/chaiscript/dispatchkit/type_info.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index 60bd7bb9..296b529a 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -138,7 +138,7 @@ namespace chaiscript { typedef T type; - static Type_Info get() + constexpr static Type_Info get() { return Type_Info(std::is_const::type>::type>::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, @@ -153,7 +153,7 @@ namespace chaiscript { typedef T type; - static Type_Info get() + constexpr static Type_Info get() { return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, @@ -168,7 +168,7 @@ namespace chaiscript { typedef T type; - static Type_Info get() + constexpr static Type_Info get() { return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, @@ -183,7 +183,7 @@ namespace chaiscript { typedef T type; - static Type_Info get() + constexpr static Type_Info get() { return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, @@ -198,7 +198,7 @@ namespace chaiscript { typedef T type; - static Type_Info get() + constexpr static Type_Info get() { return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, @@ -225,7 +225,7 @@ namespace chaiscript /// chaiscript::Type_Info ti = chaiscript::user_type(i); /// \endcode template - Type_Info user_type(const T &/*t*/) + constexpr Type_Info user_type(const T &/*t*/) { return detail::Get_Type_Info::get(); } @@ -240,7 +240,7 @@ namespace chaiscript /// chaiscript::Type_Info ti = chaiscript::user_type(); /// \endcode template - Type_Info user_type() + constexpr Type_Info user_type() { return detail::Get_Type_Info::get(); } From a6924bcc9ef968b6e625cc71c611d2e92cdc269c Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 28 Jun 2012 21:24:51 -0600 Subject: [PATCH 073/108] Use C++11 Raw Strings for chaiscript prelude --- CMakeLists.txt | 2 +- .../chaiscript/language/chaiscript_engine.hpp | 4 +- .../chaiscript/language/chaiscript_parser.hpp | 1 - .../language/chaiscript_prelude.chai | 530 ++++++++++++++++++ .../language/chaiscript_prelude.hpp | 329 ----------- 5 files changed, 533 insertions(+), 333 deletions(-) create mode 100644 include/chaiscript/language/chaiscript_prelude.chai delete mode 100644 include/chaiscript/language/chaiscript_prelude.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0130cfc8..1deb880e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,7 +91,7 @@ endif() include_directories(include) -set (Chai_INCLUDES include/chaiscript/chaiscript.hpp include/chaiscript/chaiscript_threading.hpp include/chaiscript/dispatchkit/bad_boxed_cast.hpp include/chaiscript/dispatchkit/bind_first.hpp include/chaiscript/dispatchkit/bootstrap.hpp include/chaiscript/dispatchkit/bootstrap_stl.hpp include/chaiscript/dispatchkit/boxed_cast.hpp include/chaiscript/dispatchkit/boxed_cast_helper.hpp include/chaiscript/dispatchkit/boxed_number.hpp include/chaiscript/dispatchkit/boxed_value.hpp include/chaiscript/dispatchkit/dispatchkit.hpp include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp include/chaiscript/dispatchkit/dynamic_object.hpp include/chaiscript/dispatchkit/exception_specification.hpp include/chaiscript/dispatchkit/function_call.hpp include/chaiscript/dispatchkit/function_call_detail.hpp include/chaiscript/dispatchkit/handle_return.hpp include/chaiscript/dispatchkit/operators.hpp include/chaiscript/dispatchkit/proxy_constructors.hpp include/chaiscript/dispatchkit/proxy_functions.hpp include/chaiscript/dispatchkit/proxy_functions_detail.hpp include/chaiscript/dispatchkit/register_function.hpp include/chaiscript/dispatchkit/type_info.hpp include/chaiscript/language/chaiscript_algebraic.hpp include/chaiscript/language/chaiscript_common.hpp include/chaiscript/language/chaiscript_engine.hpp include/chaiscript/language/chaiscript_eval.hpp include/chaiscript/language/chaiscript_parser.hpp include/chaiscript/language/chaiscript_prelude.hpp include/chaiscript/language/chaiscript_prelude_docs.hpp include/chaiscript/utility/utility.hpp) +set (Chai_INCLUDES include/chaiscript/chaiscript.hpp include/chaiscript/chaiscript_threading.hpp include/chaiscript/dispatchkit/bad_boxed_cast.hpp include/chaiscript/dispatchkit/bind_first.hpp include/chaiscript/dispatchkit/bootstrap.hpp include/chaiscript/dispatchkit/bootstrap_stl.hpp include/chaiscript/dispatchkit/boxed_cast.hpp include/chaiscript/dispatchkit/boxed_cast_helper.hpp include/chaiscript/dispatchkit/boxed_number.hpp include/chaiscript/dispatchkit/boxed_value.hpp include/chaiscript/dispatchkit/dispatchkit.hpp include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp include/chaiscript/dispatchkit/dynamic_object.hpp include/chaiscript/dispatchkit/exception_specification.hpp include/chaiscript/dispatchkit/function_call.hpp include/chaiscript/dispatchkit/function_call_detail.hpp include/chaiscript/dispatchkit/handle_return.hpp include/chaiscript/dispatchkit/operators.hpp include/chaiscript/dispatchkit/proxy_constructors.hpp include/chaiscript/dispatchkit/proxy_functions.hpp include/chaiscript/dispatchkit/proxy_functions_detail.hpp include/chaiscript/dispatchkit/register_function.hpp include/chaiscript/dispatchkit/type_info.hpp include/chaiscript/language/chaiscript_algebraic.hpp include/chaiscript/language/chaiscript_common.hpp include/chaiscript/language/chaiscript_engine.hpp include/chaiscript/language/chaiscript_eval.hpp include/chaiscript/language/chaiscript_parser.hpp include/chaiscript/language/chaiscript_prelude.chai include/chaiscript/language/chaiscript_prelude_docs.hpp include/chaiscript/utility/utility.hpp) set_source_files_properties(${Chai_INCLUDES} PROPERTIES HEADER_FILE_ONLY TRUE) diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 497aeb30..c3c43e45 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -28,7 +28,7 @@ #endif -#include "chaiscript_prelude.hpp" +#include "chaiscript_prelude.chai" #include "chaiscript_parser.hpp" #include "../dispatchkit/exception_specification.hpp" @@ -351,7 +351,7 @@ namespace chaiscript m_engine.add(fun(&ChaiScript::internal_eval, this), "eval"); m_engine.add(fun(&ChaiScript::internal_eval_ast, this), "eval"); - do_eval(chaiscript_prelude, "standard prelude"); + do_eval(ChaiScript_Prelude::chaiscript_prelude, "standard prelude"); } /** diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index a1138604..31726722 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -12,7 +12,6 @@ #include #include -#include "chaiscript_prelude.hpp" #include "chaiscript_common.hpp" namespace chaiscript diff --git a/include/chaiscript/language/chaiscript_prelude.chai b/include/chaiscript/language/chaiscript_prelude.chai new file mode 100644 index 00000000..29d9b2f7 --- /dev/null +++ b/include/chaiscript/language/chaiscript_prelude.chai @@ -0,0 +1,530 @@ +// This file is distributed under the BSD License. +// See "license.txt" for details. +// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) +// and Jason Turner (jason@emptycrate.com) +// http://www.chaiscript.com + +#ifndef CHAISCRIPT_PRELUDE_HPP_ +#define CHAISCRIPT_PRELUDE_HPP_ + +namespace chaiscript { +struct ChaiScript_Prelude { + constexpr static const char *chaiscript_prelude=R""( + +def lt(l, r) { + if (call_exists(`<`, l, r)) { + l < r + } else { + type_name(l) < type_name(r) + } +} + + +def gt(l, r) { + if (call_exists(`>`, l, r)) { + l > r + } else { + type_name(l) > type_name(r) + } +} + +def eq(l, r) { + if (call_exists(`==`, l, r)) { + l == r + } else { + false + } +} + +def new(x) { + eval(type_name(x))(); +} + +def clone(x) : function_exists(type_name(x)) && call_exists(eval(type_name(x)), x) +{ + eval(type_name(x))(x); +} + + +# to_string for Pair() +def to_string(x) : call_exists(first, x) && call_exists(second, x) { + "<" + x.first.to_string() + ", " + x.second.to_string() + ">"; +} + +# to_string for containers +def to_string(x) : call_exists(range, x) && !x.is_type("string"){ + "[" + x.join(", ") + "]"; +} + +# Basic to_string function +def to_string(x) { + internal_to_string(x); +} + +# Prints to console with no carriage return +def puts(x) { + print_string(x.to_string()); +} + +# Prints to console with carriage return +def print(x) { + println_string(x.to_string()); +} + +# Returns the maximum value of two numbers +def max(a, b) { + if (a>b) { + a + } else { + b + } +} + +# Returns the minimum value of two numbers +def min(a, b) +{ + if (a 0) && (!r.empty())) { + inserter(r.front()); + r.pop_front(); + --i; + } +} + + +# Returns a new container with the given number of elements taken from the container +def take(container, num) { + auto retval = new(container); + take(container, num, back_inserter(retval)); + retval; +} + + +def take_while(container, f, inserter) : call_exists(range, container) { + auto r = range(container); + while ((!r.empty()) && f(r.front())) { + inserter(r.front()); + r.pop_front(); + } +} + + +# Returns a new container with the given elements match the second value function +def take_while(container, f) { + auto retval = new(container); + take_while(container, f, back_inserter(retval)); + retval; +} + + +def drop(container, num, inserter) : call_exists(range, container) { + auto r = range(container); + auto i = num; + while ((i > 0) && (!r.empty())) { + r.pop_front(); + --i; + } + while (!r.empty()) { + inserter(r.front()); + r.pop_front(); + } +} + + +# Returns a new container with the given number of elements dropped from the given container +def drop(container, num) { + auto retval = new(container); + drop(container, num, back_inserter(retval)); + retval; +} + + +def drop_while(container, f, inserter) : call_exists(range, container) { + auto r = range(container); + while ((!r.empty())&& f(r.front())) { + r.pop_front(); + } + while (!r.empty()) { + inserter(r.front()); + r.pop_front(); + } +} + + +# Returns a new container with the given elements dropped that match the second value function +def drop_while(container, f) { + auto retval = new(container); + drop_while(container, f, back_inserter(retval)); + retval; +} + + +# Applies the second value function to the container. Starts with the first two elements. Expects at least 2 elements. +def reduce(container, func) : container.size() >= 2 && call_exists(range, container) { + auto r = range(container); + auto retval = r.front(); + r.pop_front(); + retval = func(retval, r.front()); + r.pop_front(); + while (!r.empty()) { + retval = func(retval, r.front()); + r.pop_front(); + } + retval; +} + + +# Returns a string of the elements in container delimited by the second value string +def join(container, delim) { + auto retval = ""; + auto range = range(container); + if (!range.empty()) { + retval += to_string(range.front()); + range.pop_front(); + while (!range.empty()) { + retval += delim; + retval += to_string(range.front()); + range.pop_front(); + } + } + retval; +} + + +def filter(container, f, inserter) : call_exists(range, container) { + auto r = range(container); + while (!r.empty()) { + if (f(r.front())) { + inserter(r.front()); + } + r.pop_front(); + } +} + + +# Returns a new Vector which match the second value function +def filter(container, f) { + auto retval = new(container); + filter(container, f, back_inserter(retval)); + retval; +} + + +def generate_range(x, y, inserter) { + auto i = x; + while (i <= y) { + inserter(i); + ++i; + } +} + + +# Returns a new Vector which represents the range from the first value to the second value +def generate_range(x, y) { + auto retval = Vector(); + generate_range(x,y,back_inserter(retval)); + retval; +} + + +# Returns a new Vector with the first value to the second value as its elements +def collate(x, y) { + return [x, y]; +} + + +def zip_with(f, x, y, inserter) : call_exists(range, x) && call_exists(range, y) { + auto r_x = range(x); + auto r_y = range(y); + while (!r_x.empty() && !r_y.empty()) { + inserter(f(r_x.front(), r_y.front())); + r_x.pop_front(); + r_y.pop_front(); + } +} + + +# Returns a new Vector which joins matching elements of the second and third value with the first value function +def zip_with(f, x, y) { + auto retval = Vector(); + zip_with(f,x,y,back_inserter(retval)); + retval; +} + + +# Returns a new Vector which joins matching elements of the first and second +def zip(x, y) { + zip_with(collate, x, y); +} + + +# Returns the position of the second value string in the first value string +def string::find(substr) : is_type(substr, "string") { + int(find(this, substr, 0)); +} + + +# Returns the position of last match of the second value string in the first value string +def string::rfind(substr) : is_type(substr, "string") { + int(rfind(this, substr, -1)); +} + + +# Returns the position of the first match of elements in the second value string in the first value string +def string::find_first_of(list) : is_type(list, "string") { + int(find_first_of(this, list, 0)); +} + + +# Returns the position of the last match of elements in the second value string in the first value string +def string::find_last_of(list) : is_type(list, "string") { + int(find_last_of(this, list, -1)); +} + + +# Returns the position of the first non-matching element in the second value string in the first value string +def string::find_first_not_of(list) : is_type(list, "string") { + int(find_first_not_of(this, list, 0)); +} + + +# Returns the position of the last non-matching element in the second value string in the first value string +def string::find_last_not_of(list) : is_type(list, "string") { + int(find_last_not_of(this, list, -1)); +} + + +def string::ltrim() { + drop_while(this, fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'}); +} + + +def string::rtrim() { + reverse(drop_while(reverse(this), fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'})); +} + + +def string::trim() { + ltrim(rtrim(this)); +} + + +def find(container, value, compare_func) : call_exists(range, container) && is_type(compare_func, "Function") { + auto range = range(container); + while (!range.empty()) { + if (compare_func(range.front(), value)) { + return range; + } else { + range.pop_front(); + } + } + return range; +} + + +def find(container, value) { + return find(container, value, eq) +} + + +)""; + +}; +} + +#endif /* CHAISCRIPT_PRELUDE_HPP_ */ diff --git a/include/chaiscript/language/chaiscript_prelude.hpp b/include/chaiscript/language/chaiscript_prelude.hpp deleted file mode 100644 index cee93d0f..00000000 --- a/include/chaiscript/language/chaiscript_prelude.hpp +++ /dev/null @@ -1,329 +0,0 @@ -// This file is distributed under the BSD License. -// See "license.txt" for details. -// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) -// and Jason Turner (jason@emptycrate.com) -// http://www.chaiscript.com - -#ifndef CHAISCRIPT_PRELUDE_HPP_ -#define CHAISCRIPT_PRELUDE_HPP_ - -//Note, the expression "[x,y]" in "collate" is parsed as two separate expressions -//by C++, so CODE_STRING, takes two expressions and adds in the missing comma -#define CODE_STRING(x, y) #x ", " #y - -#define chaiscript_prelude CODE_STRING(\ -def lt(l, r) { if (call_exists(`<`, l, r)) { l < r } else { type_name(l) < type_name(r) } } \n\ -def gt(l, r) { if (call_exists(`>`, l, r)) { l > r } else { type_name(l) > type_name(r) } } \n\ -def eq(l, r) { if (call_exists(`==`, l, r)) { l == r } else { false } } \n\ -def new(x) { eval(type_name(x))(); } \n\ -def clone(x) : function_exists(type_name(x)) && call_exists(eval(type_name(x)), x) { eval(type_name(x))(x); } \n\ -# to_string for Pair()\n\ -def to_string(x) : call_exists(first, x) && call_exists(second, x) { \n\ - "<" + x.first.to_string() + ", " + x.second.to_string() + ">"; \n\ -}\n\ -# to_string for containers\n\ -def to_string(x) : call_exists(range, x) && !x.is_type("string"){ \n\ - "[" + x.join(", ") + "]"; \n\ -}\n\ -# Basic to_string function\n\ -def to_string(x) { \n\ - internal_to_string(x); \n\ -}\n\ -# Prints to console with no carriage return\n\ -def puts(x) { \n\ - print_string(x.to_string()); \n\ -} \n\ -# Prints to console with carriage return\n\ -def print(x) { \n\ - println_string(x.to_string()); \n\ -} \n\ -# Returns the maximum value of two numbers\n\ -def max(a, b) { if (a>b) { a } else { b } } \n\ -# Returns the minimum value of two numbers\n\ -def min(a, b) { if (a 0) && (!r.empty())) { \n\ - inserter(r.front()); \n\ - r.pop_front(); \n\ - --i; \n\ - } \n\ -} \n\ -# Returns a new container with the given number of elements taken from the container\n\ -def take(container, num) {\n\ - auto retval = new(container); \n\ - take(container, num, back_inserter(retval)); \n\ - retval; \n\ -}\n\ -def take_while(container, f, inserter) : call_exists(range, container) { \n\ - auto r = range(container); \n\ - while ((!r.empty()) && f(r.front())) { \n\ - inserter(r.front()); \n\ - r.pop_front(); \n\ - } \n\ -} \n\ -# Returns a new container with the given elements match the second value function\n\ -def take_while(container, f) {\n\ - auto retval = new(container); \n\ - take_while(container, f, back_inserter(retval)); \n\ - retval;\n\ -}\n\ -def drop(container, num, inserter) : call_exists(range, container) { \n\ - auto r = range(container); \n\ - auto i = num; \n\ - while ((i > 0) && (!r.empty())) { \n\ - r.pop_front(); \n\ - --i; \n\ - } \n\ - while (!r.empty()) { \n\ - inserter(r.front()); \n\ - r.pop_front(); \n\ - } \n\ -} \n\ -# Returns a new container with the given number of elements dropped from the given container \n\ -def drop(container, num) {\n\ - auto retval = new(container); \n\ - drop(container, num, back_inserter(retval)); \n\ - retval; \n\ -}\n\ -def drop_while(container, f, inserter) : call_exists(range, container) { \n\ - auto r = range(container); \n\ - while ((!r.empty())&& f(r.front())) { \n\ - r.pop_front(); \n\ - } \n\ - while (!r.empty()) { \n\ - inserter(r.front()); \n\ - r.pop_front(); \n\ - } \n\ -} \n\ -# Returns a new container with the given elements dropped that match the second value function\n\ -def drop_while(container, f) {\n\ - auto retval = new(container); \n\ - drop_while(container, f, back_inserter(retval)); \n\ - retval; \n\ -}\n\ -# Applies the second value function to the container. Starts with the first two elements. Expects at least 2 elements.\n\ -def reduce(container, func) : container.size() >= 2 && call_exists(range, container) { \n\ - auto r = range(container); \n\ - auto retval = r.front(); \n\ - r.pop_front(); \n\ - retval = func(retval, r.front()); \n\ - r.pop_front(); \n\ - while (!r.empty()) { \n\ - retval = func(retval, r.front()); \n\ - r.pop_front(); \n\ - } \n\ - retval; \n\ -} \n\ -# Returns a string of the elements in container delimited by the second value string\n\ -def join(container, delim) { \n\ - auto retval = ""; \n\ - auto range = range(container); \n\ - if (!range.empty()) { \n\ - retval += to_string(range.front()); \n\ - range.pop_front(); \n\ - while (!range.empty()) { \n\ - retval += delim; \n\ - retval += to_string(range.front()); \n\ - range.pop_front(); \n\ - } \n\ - } \n\ - retval; \n\ -} \n\ -def filter(container, f, inserter) : call_exists(range, container) { \n\ - auto r = range(container); \n\ - while (!r.empty()) { \n\ - if (f(r.front())) { \n\ - inserter(r.front()); \n\ - } \n\ - r.pop_front(); \n\ - } \n\ -} \n\ -# Returns a new Vector which match the second value function\n\ -def filter(container, f) { \n\ - auto retval = new(container); \n\ - filter(container, f, back_inserter(retval));\n\ - retval;\n\ -}\n\ -def generate_range(x, y, inserter) { \n\ - auto i = x; \n\ - while (i <= y) { \n\ - inserter(i); \n\ - ++i; \n\ - } \n\ -} \n\ -# Returns a new Vector which represents the range from the first value to the second value\n\ -def generate_range(x, y) { \n\ - auto retval = Vector(); \n\ - generate_range(x,y,back_inserter(retval)); \n\ - retval; \n\ -}\n\ -# Returns a new Vector with the first value to the second value as its elements\n\ -def collate(x, y) { \n\ - return [x, y]; \n\ -} \n\ -def zip_with(f, x, y, inserter) : call_exists(range, x) && call_exists(range, y) { \n\ - auto r_x = range(x); \n\ - auto r_y = range(y); \n\ - while (!r_x.empty() && !r_y.empty()) { \n\ - inserter(f(r_x.front(), r_y.front())); \n\ - r_x.pop_front(); \n\ - r_y.pop_front(); \n\ - } \n\ -} \n\ -# Returns a new Vector which joins matching elements of the second and third value with the first value function\n\ -def zip_with(f, x, y) { \n\ - auto retval = Vector(); \n\ - zip_with(f,x,y,back_inserter(retval)); \n\ - retval;\n\ -}\n\ -# Returns a new Vector which joins matching elements of the first and second\n\ -def zip(x, y) { \n\ - zip_with(collate, x, y); \n\ -}\n\ -# Returns the position of the second value string in the first value string\n\ -def string::find(substr) : is_type(substr, "string") { \n\ - int(find(this, substr, 0)); \n\ -} \n\ -# Returns the position of last match of the second value string in the first value string\n\ -def string::rfind(substr) : is_type(substr, "string") { \n\ - int(rfind(this, substr, -1)); \n\ -} \n\ -# Returns the position of the first match of elements in the second value string in the first value string\n\ -def string::find_first_of(list) : is_type(list, "string") { \n\ - int(find_first_of(this, list, 0)); \n\ -} \n\ -# Returns the position of the last match of elements in the second value string in the first value string\n\ -def string::find_last_of(list) : is_type(list, "string") { \n\ - int(find_last_of(this, list, -1)); \n\ -} \n\ -# Returns the position of the first non-matching element in the second value string in the first value string\n\ -def string::find_first_not_of(list) : is_type(list, "string") { \n\ - int(find_first_not_of(this, list, 0)); \n\ -} \n\ -# Returns the position of the last non-matching element in the second value string in the first value string\n\ -def string::find_last_not_of(list) : is_type(list, "string") { \n\ - int(find_last_not_of(this, list, -1)); \n\ -} \n\ -def string::ltrim() { \n\ - drop_while(this, fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'}); \n\ -} \n\ -def string::rtrim() { \n\ - reverse(drop_while(reverse(this), fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'})); \n\ -} \n\ -def string::trim() { \n\ - ltrim(rtrim(this)); \n\ -} \n\ -def find(container, value, compare_func) : call_exists(range, container) && is_type(compare_func, "Function") { \n\ - auto range = range(container); \n\ - while (!range.empty()) { \n\ - if (compare_func(range.front(), value)) { \n\ - return range; \n\ - } else { \n\ - range.pop_front(); \n\ - } \n\ - } \n\ - return range; \n\ -} \n\ -def find(container, value) { return find(container, value, eq) } \ -) -#endif /* CHAISCRIPT_PRELUDE_HPP_ */ From f27739cf7183a0f9cbdffaa7e29c7b47b25b0508 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 9 Jul 2012 16:20:55 -0600 Subject: [PATCH 074/108] Use unique_ptr instead of shared_ptr in our any implementation, >10% speed improvement --- include/chaiscript/dispatchkit/any.hpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/include/chaiscript/dispatchkit/any.hpp b/include/chaiscript/dispatchkit/any.hpp index e8dcfb8d..22988589 100644 --- a/include/chaiscript/dispatchkit/any.hpp +++ b/include/chaiscript/dispatchkit/any.hpp @@ -44,7 +44,7 @@ namespace chaiscript { { virtual void *data() = 0; virtual const std::type_info &type() const = 0; - virtual std::shared_ptr clone() const = 0; + virtual std::unique_ptr clone() const = 0; }; template @@ -66,16 +66,16 @@ namespace chaiscript { return m_type; } - std::shared_ptr clone() const + std::unique_ptr clone() const { - return std::shared_ptr(new Data_Impl(m_data)); + return std::unique_ptr(new Data_Impl(m_data)); } const std::type_info &m_type; T m_data; }; - std::shared_ptr m_data; + std::unique_ptr m_data; public: // construct/copy/destruct @@ -94,7 +94,7 @@ namespace chaiscript { template Any(const ValueType &t_value) { - m_data = std::shared_ptr(new Data_Impl(t_value)); + m_data = std::unique_ptr(new Data_Impl(t_value)); } Any & operator=(const Any &t_any) @@ -131,9 +131,7 @@ namespace chaiscript { // modifiers Any & swap(Any &t_other) { - std::shared_ptr data = t_other.m_data; - t_other.m_data = m_data; - m_data = data; + std::swap(m_data, t_other.m_data); return *this; } From 7052234650d4a3a7ded99e9cc763f3b990a6c088 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Fri, 13 Jul 2012 13:54:48 -0600 Subject: [PATCH 075/108] Revert "Use unique_ptr instead of shared_ptr in our any implementation, >10% speed improvement" This reverts commit f27739cf7183a0f9cbdffaa7e29c7b47b25b0508. --- include/chaiscript/dispatchkit/any.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/include/chaiscript/dispatchkit/any.hpp b/include/chaiscript/dispatchkit/any.hpp index 22988589..e8dcfb8d 100644 --- a/include/chaiscript/dispatchkit/any.hpp +++ b/include/chaiscript/dispatchkit/any.hpp @@ -44,7 +44,7 @@ namespace chaiscript { { virtual void *data() = 0; virtual const std::type_info &type() const = 0; - virtual std::unique_ptr clone() const = 0; + virtual std::shared_ptr clone() const = 0; }; template @@ -66,16 +66,16 @@ namespace chaiscript { return m_type; } - std::unique_ptr clone() const + std::shared_ptr clone() const { - return std::unique_ptr(new Data_Impl(m_data)); + return std::shared_ptr(new Data_Impl(m_data)); } const std::type_info &m_type; T m_data; }; - std::unique_ptr m_data; + std::shared_ptr m_data; public: // construct/copy/destruct @@ -94,7 +94,7 @@ namespace chaiscript { template Any(const ValueType &t_value) { - m_data = std::unique_ptr(new Data_Impl(t_value)); + m_data = std::shared_ptr(new Data_Impl(t_value)); } Any & operator=(const Any &t_any) @@ -131,7 +131,9 @@ namespace chaiscript { // modifiers Any & swap(Any &t_other) { - std::swap(m_data, t_other.m_data); + std::shared_ptr data = t_other.m_data; + t_other.m_data = m_data; + m_data = data; return *this; } From 84e17b8d06b3e4223a591d15fd0a393d2afab154 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 16 Jul 2012 22:24:25 -0600 Subject: [PATCH 076/108] Port Boxed_Number enhancements from mgee to C++11 branch. #53 --- .../chaiscript/dispatchkit/boxed_number.hpp | 69 ++++++++++--------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index c38f7511..8f7401b5 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -9,6 +9,7 @@ #include "boxed_value.hpp" #include "../language/chaiscript_algebraic.hpp" +#include namespace chaiscript { @@ -354,24 +355,24 @@ namespace chaiscript return get_as_aux(); } else if (inp_ == typeid(unsigned long)) { return get_as_aux(); - } else if (inp_ == typeid(boost::int8_t)) { - return get_as_aux(); - } else if (inp_ == typeid(boost::int16_t)) { - return get_as_aux(); - } else if (inp_ == typeid(boost::int32_t)) { - return get_as_aux(); - } else if (inp_ == typeid(boost::int64_t)) { - return get_as_aux(); - } else if (inp_ == typeid(boost::uint8_t)) { - return get_as_aux(); - } else if (inp_ == typeid(boost::uint16_t)) { - return get_as_aux(); - } else if (inp_ == typeid(boost::uint32_t)) { - return get_as_aux(); - } else if (inp_ == typeid(boost::uint64_t)) { - return get_as_aux(); + } else if (inp_ == typeid(std::int8_t)) { + return get_as_aux(); + } else if (inp_ == typeid(std::int16_t)) { + return get_as_aux(); + } else if (inp_ == typeid(std::int32_t)) { + return get_as_aux(); + } else if (inp_ == typeid(std::int64_t)) { + return get_as_aux(); + } else if (inp_ == typeid(std::uint8_t)) { + return get_as_aux(); + } else if (inp_ == typeid(std::uint16_t)) { + return get_as_aux(); + } else if (inp_ == typeid(std::uint32_t)) { + return get_as_aux(); + } else if (inp_ == typeid(std::uint64_t)) { + return get_as_aux(); } else { - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } } @@ -395,24 +396,24 @@ namespace chaiscript return to_string_aux(bv); } else if (inp_ == typeid(unsigned long)) { return to_string_aux(bv); - } else if (inp_ == typeid(boost::int8_t)) { - return to_string_aux(Boxed_Value(get_as_aux())); - } else if (inp_ == typeid(boost::int16_t)) { - return to_string_aux(bv); - } else if (inp_ == typeid(boost::int32_t)) { - return to_string_aux(bv); - } else if (inp_ == typeid(boost::int64_t)) { - return to_string_aux(bv); - } else if (inp_ == typeid(boost::uint8_t)) { - return to_string_aux(Boxed_Value(get_as_aux())); - } else if (inp_ == typeid(boost::uint16_t)) { - return to_string_aux(bv); - } else if (inp_ == typeid(boost::uint32_t)) { - return to_string_aux(bv); - } else if (inp_ == typeid(boost::uint64_t)) { - return to_string_aux(bv); + } else if (inp_ == typeid(std::int8_t)) { + return to_string_aux(Boxed_Value(get_as_aux())); + } else if (inp_ == typeid(std::int16_t)) { + return to_string_aux(bv); + } else if (inp_ == typeid(std::int32_t)) { + return to_string_aux(bv); + } else if (inp_ == typeid(std::int64_t)) { + return to_string_aux(bv); + } else if (inp_ == typeid(std::uint8_t)) { + return to_string_aux(Boxed_Value(get_as_aux())); + } else if (inp_ == typeid(std::uint16_t)) { + return to_string_aux(bv); + } else if (inp_ == typeid(std::uint32_t)) { + return to_string_aux(bv); + } else if (inp_ == typeid(std::uint64_t)) { + return to_string_aux(bv); } else { - throw boost::bad_any_cast(); + throw chaiscript::detail::exception::bad_any_cast(); } } From 6642e0249698e316c362044d5c6c868015880fdb Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 14 Aug 2012 11:37:58 -0600 Subject: [PATCH 077/108] Update readme for C++11 --- readme.md | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++ readme.txt | 55 --------------------------- 2 files changed, 107 insertions(+), 55 deletions(-) create mode 100644 readme.md delete mode 100644 readme.txt diff --git a/readme.md b/readme.md new file mode 100644 index 00000000..aab6641f --- /dev/null +++ b/readme.md @@ -0,0 +1,107 @@ +ChaiScript +http://www.chaiscript.com +(c) 2009-2012 Jason Turner and Jonathan Turner +Release under the BSD license, see "license.txt" for details. + +Introduction +============ + +ChaiScript is one of the only embedded scripting language designed from the +ground up to directly target C++ and take advantage of modern C++ development +techniques, working with the developer like he expects it to work. Being a +native C++ application, it has some advantages over existing embedded scripting +languages: + +1. It uses a header-only approach, which makes it easy to integrate with + existing projects. +2. It maintains type safety between your C++ application and the user scripts. +3. It supports a variety of C++ techniques including callbacks, overloaded + functions, class methods, and stl containers. + + +Requirements +============ + +ChaiScript requires a C++11 compiler to build with support for variadic +templates. It has been tested with gcc 4.7 and clang 3.1 (with libcxx). MacOS +10.8 (Mountain Lion) is also known to support the C++11 build with Apple's +clang 4.0. + +Usage +===== + +* Add the ChaiScript include directory to your project's header search path +* Add "#include to your source file +* Instantiate the ChaiScript engine in your application. For example, create a + new engine with the name 'chai' like so: "chaiscript::ChaiScript chai" +* The default behavior is to load the ChaiScript standard library from a + loadable module. A second option is to compile the library into your code, + see below for an example. + +Once instantiated, the engine is ready to start running ChaiScript source. You +have two main options for processing ChaiScript source: a line at a time using +"chai.eval(string)" and a file at a time using "chai.eval_file(fname)" + +To make functions in your C++ code visible to scripts, they must be registered +with the scripting engine. To do so, call add: + +chai.add(chaiscript::fun(&my_function), "my_function_name"); + +Once registered the function will be visible to scripts as "my_function_name" + +Examples +======== + +ChaiScript is similar to ECMAScript (aka JavaScript(tm)), but with some +modifications to make it easier to use. For usage examples see the "samples" +directory, and for more in-depth look at the language, the unit tests in the +"unittests" directory cover the most ground. + +For examples of how to register parts of your C++ application, see +"example.cpp" in the "src" directory. Example.cpp is verbose and shows every +possible way of working with the library. For further documentation generate +the doxygen documentation in the build folder or see the website http://www.chaiscript.com. + +The shortest complete example possible follows: + + /// main.cpp + + #include + + double function(int i, double j) + { + return i * j; + } + + int main() + { + chaiscript::ChaiScript chai; + chai.add(chaiscript::fun(&function), "function"); + + double d = chai.eval("function(3, 4.75);"); + } + + + +Or, if you want to compile the std lib into your code, which reduces +runtime requirements. + + /// main.cpp + + #include + #include + + double function(int i, double j) + { + return i * j; + } + + int main() + { + chaiscript::ChaiScript chai(chaiscript::Std_Lib::library()); + chai.add(chaiscript::fun(&function), "function"); + + double d = chai.eval("function(3, 4.75);"); + } + + diff --git a/readme.txt b/readme.txt deleted file mode 100644 index 741a33fc..00000000 --- a/readme.txt +++ /dev/null @@ -1,55 +0,0 @@ -ChaiScript -http://www.chaiscript.com -(c) 2009-2012 Jason Turner and Jonathan Turner -Release under the BSD license, see "license.txt" for details. - -[Introduction] - -ChaiScript is one of the only embedded scripting language designed from the ground up to directly target C++ and take advantage of modern C++ development techniques, working with the developer like he expects it to work. Being a native C++ application, it has some advantages over existing embedded scripting languages: - -1) It uses a header-only approach, which makes it easy to integrate with existing projects. -2) It maintains type safety between your C++ application and the user scripts. -3) It supports a variety of C++ techniques including callbacks, overloaded functions, class methods, and stl containers. - -[Requirements] - -ChaiScript requires a C++11 compiler to build with support for variadic templates. It has been tested with gcc 4.7 and clang 3.1 (with libcxx). - -[Usage] - -* Add the ChaiScript include directory to your project's header search path -* Add "#include to your source file -* Instantiate the ChaiScript engine in your application. For example, create a new engine with the name 'chai' like so: "chaiscript::ChaiScript chai" - -Once instantiated, the engine is ready to start running ChaiScript source. You have two main options for processing ChaiScript source: a line at a time using "chai.evaluate_string(string)" and a file at a time using "chai.evaluate_file(fname)" - -To make functions in your C++ code visible to scripts, they must be registered with the scripting engine. To do so, call add: - -chai.add(chaiscript::fun(&my_function), "my_function_name"); - -Once registered the function will be visible to scripts as "my_function_name" - -[Examples] - -ChaiScript is similar to ECMAScript (aka JavaScript(tm)), but with some modifications to make it easier to use. For usage examples see the "samples" directory, and for more in-depth look at the language, the unit tests in the "unittests" directory cover the most ground. - -For examples of how to register parts of your C++ application, see "example.cpp" in the "src" directory. Example.cpp is verbose and shows every possible way of working with the library. For further documentation generate the doxygen documentation in the build folder or see the website http://www.chaiscript.com. - -The shortest complete example possible follows: - -/// main.cpp - -#include - -double function(int i, double j) -{ - return i * j; -} - -int main() -{ - chaiscript::ChaiScript chai; - chai.add(chaiscript::fun(&function), "function"); - - double d = chai.eval("function(3, 4.75);"); -} From 193151f52edc43ab01baf4f33d179b901b357716 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 14 Aug 2012 11:43:11 -0600 Subject: [PATCH 078/108] Minor syntax updates for C++11 readme.md --- readme.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index aab6641f..87b43128 100644 --- a/readme.md +++ b/readme.md @@ -1,8 +1,12 @@ ChaiScript + http://www.chaiscript.com + (c) 2009-2012 Jason Turner and Jonathan Turner + Release under the BSD license, see "license.txt" for details. + Introduction ============ @@ -40,12 +44,12 @@ Usage Once instantiated, the engine is ready to start running ChaiScript source. You have two main options for processing ChaiScript source: a line at a time using -"chai.eval(string)" and a file at a time using "chai.eval_file(fname)" +`chai.eval(string)` and a file at a time using `chai.eval_file(fname)` To make functions in your C++ code visible to scripts, they must be registered with the scripting engine. To do so, call add: -chai.add(chaiscript::fun(&my_function), "my_function_name"); + chai.add(chaiscript::fun(&my_function), "my_function_name"); Once registered the function will be visible to scripts as "my_function_name" From d47cd63fecd9ec544bb5eef0c7ce38c2eb0cb3b6 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 14 Aug 2012 11:45:00 -0600 Subject: [PATCH 079/108] One more round of updates to readme.md --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 87b43128..a0dc4680 100644 --- a/readme.md +++ b/readme.md @@ -35,9 +35,9 @@ Usage ===== * Add the ChaiScript include directory to your project's header search path -* Add "#include to your source file +* Add `#include ` to your source file * Instantiate the ChaiScript engine in your application. For example, create a - new engine with the name 'chai' like so: "chaiscript::ChaiScript chai" + new engine with the name `chai` like so: `chaiscript::ChaiScript chai` * The default behavior is to load the ChaiScript standard library from a loadable module. A second option is to compile the library into your code, see below for an example. From 691e002f90eae3b87097a253fa083864e8e85c1c Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 28 Nov 2012 16:06:45 -0700 Subject: [PATCH 080/108] Update to support building with MinGW #78 We cannot call MinGW a fully supported platform for C++11 yet: - Concurrency is not yet supported by MinGW, so it is disabled by default - A problem in the memory model / library loader is preventing derived type casts from working. This may be able to be worked around, but has not been yet. --- CMakeLists.txt | 20 +++++++++++++++++--- samples/example.cpp | 1 + src/main.cpp | 14 +++++++++----- unittests/type_info_test.cpp | 1 + 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 51dedff3..71419abf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,13 @@ cmake_minimum_required(VERSION 2.8) project(chaiscript) -option(MULTITHREAD_SUPPORT_ENABLED "Multithreaded Support Enabled" TRUE) +# MINGW does not yet support C++11's concurrency features +if (MINGW) + option(MULTITHREAD_SUPPORT_ENABLED "Multithreaded Support Enabled" FALSE) +else() + option(MULTITHREAD_SUPPORT_ENABLED "Multithreaded Support Enabled" TRUE) +endif() + option(BUILD_MODULES "Build Extra Modules (stl, reflection)" TRUE) option(BUILD_SAMPLES "Build Samples Folder" FALSE) @@ -39,7 +45,9 @@ include(CPack) include(cmake/CheckCXX11Features.cmake) -find_library(READLINE_LIBRARY NAMES readline PATH /usr/lib /usr/local/lib /opt/local/lib) +if(NOT MINGW) + find_library(READLINE_LIBRARY NAMES readline PATH /usr/lib /usr/local/lib /opt/local/lib) +endif() if(HAS_CXX11_VARIADIC_TEMPLATES) message(STATUS "Variadic Template support detected") @@ -68,7 +76,7 @@ if(MSVC) endif() else() add_definitions(-Wall -Wextra -Wshadow -pedantic -std=c++0x) - + if (APPLE) add_definitions(-Wno-sign-compare) endif() @@ -88,6 +96,12 @@ else() set (EXTRA_LINKER_FLAGS ) endif() +# limitations in MinGW require us to make an optimized build +# for the sake of object sizes or something +if (MINGW) + add_definitions(-O3) +endif() + include_directories(include) diff --git a/samples/example.cpp b/samples/example.cpp index e7534515..bc8c9820 100644 --- a/samples/example.cpp +++ b/samples/example.cpp @@ -5,6 +5,7 @@ // http://www.chaiscript.com #include +#include #include #include diff --git a/src/main.cpp b/src/main.cpp index bd80f216..6a8e3a41 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,16 +15,20 @@ #include #include #else + +char *mystrdup (const char *s) { + char *d = static_cast(malloc (strlen (s) + 1)); // Space for length plus nul + if (d == nullptr) return nullptr; // No memory + strcpy (d,s); // Copy the characters + return d; // Return the new string +} + char* readline(const char* p) { std::string retval; std::cout << p ; std::getline(std::cin, retval); -#ifdef CHAISCRIPT_MSVC - return std::cin.eof() ? NULL : _strdup(retval.c_str()); -#else - return std::cin.eof() ? NULL : strdup(retval.c_str()); -#endif + return std::cin.eof() ? NULL : mystrdup(retval.c_str()); } void add_history(const char*){} void using_history(){} diff --git a/unittests/type_info_test.cpp b/unittests/type_info_test.cpp index 361be80f..3dba9071 100644 --- a/unittests/type_info_test.cpp +++ b/unittests/type_info_test.cpp @@ -1,6 +1,7 @@ // Tests to make sure that the order in which function dispatches occur is correct #include +#include void test_type(const chaiscript::Type_Info &ti, bool t_is_const, bool t_is_pointer, bool t_is_reference, bool t_is_void, bool t_is_undef) From 1f1656a6c2bc9b2301617d56e1a27aaad8a397e6 Mon Sep 17 00:00:00 2001 From: Windoze Date: Wed, 27 Feb 2013 13:33:27 +0800 Subject: [PATCH 081/108] C++11 needs constexpr constructor when object used in constexpr expression --- include/chaiscript/dispatchkit/type_info.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index ea4571f3..466f4745 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -28,7 +28,7 @@ namespace chaiscript class Type_Info { public: - Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void, + constexpr Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void, bool t_is_arithmetic, const std::type_info *t_ti, const std::type_info *t_bareti) : m_type_info(t_ti), m_bare_type_info(t_bareti), m_is_const(t_is_const), m_is_reference(t_is_reference), m_is_pointer(t_is_pointer), From 88f7bffc4f3359c4772559c20844b01ab25399c7 Mon Sep 17 00:00:00 2001 From: Windoze Date: Wed, 27 Feb 2013 14:01:09 +0800 Subject: [PATCH 082/108] FreeBSD hasn't libdl, functions included in libc --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bdd53f95..6f3415ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,7 +116,9 @@ else() endif() if (CMAKE_HOST_UNIX) - list(APPEND LIBS "dl") + if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + list(APPEND LIBS "dl") + endif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") if (MULTITHREAD_SUPPORT_ENABLED) list(APPEND LIBS "pthread") From 9ac58a942ed9cbb03e61ddcea789a1f7dd01b19b Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 25 Apr 2013 10:32:40 -0600 Subject: [PATCH 083/108] Fix clang identification --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f3415ba..f2a548bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,7 +83,7 @@ else() endif() endif() -if (CMAKE_CXX_COMPILER MATCHES ".*clang") +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") option(USE_LIBCXX "Use clang's libcxx" TRUE) From 494a67c9a05e2d7329100548354777bc98339afd Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 25 Apr 2013 15:04:44 -0600 Subject: [PATCH 084/108] Fix linking for C++11 builds on macos --- CMakeLists.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2a548bc..78961ae1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,32 +222,32 @@ if(BUILD_TESTING) add_test(NAME cpp_lambda_test COMMAND cpp_lambda_test) add_executable(expected_eval_errors_test unittests/expected_eval_errors_test.cpp) - target_link_libraries(expected_eval_errors_test ${LIBS}) + target_link_libraries(expected_eval_errors_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Expected_Eval_Errors_Test COMMAND expected_eval_errors_test) add_executable(set_state_test unittests/set_state_test.cpp) - target_link_libraries(set_state_test ${LIBS}) + target_link_libraries(set_state_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Set_State_Test COMMAND set_state_test) add_executable(simultaneous_chaiscript_test unittests/simultaneous_chaiscript_test.cpp) - target_link_libraries(simultaneous_chaiscript_test ${LIBS}) + target_link_libraries(simultaneous_chaiscript_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Simultaneous_Chaiscript_Test COMMAND simultaneous_chaiscript_test) add_executable(c_linkage_test unittests/c_linkage_test.cpp) - target_link_libraries(c_linkage_test ${LIBS}) + target_link_libraries(c_linkage_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME C_Linkage_Test COMMAND c_linkage_test) add_executable(integer_literal_test unittests/integer_literal_test.cpp) - target_link_libraries(integer_literal_test ${LIBS}) + target_link_libraries(integer_literal_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Integer_Literal_Test COMMAND integer_literal_test) add_executable(arithmetic_conversions_test unittests/arithmetic_conversions_test.cpp) - target_link_libraries(arithmetic_conversions_test ${LIBS}) + target_link_libraries(arithmetic_conversions_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Arithmetic_Conversions_Test COMMAND arithmetic_conversions_test) if (MULTITHREAD_SUPPORT_ENABLED) add_executable(multithreaded_test unittests/multithreaded_test.cpp) - target_link_libraries(multithreaded_test ${LIBS}) + target_link_libraries(multithreaded_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Multithreaded_Test COMMAND multithreaded_test) set_property(TEST Multithreaded_Test PROPERTY ENVIRONMENT From 21e3d1cc0aadf87b4611f45a2562a5cf5fc4b4c5 Mon Sep 17 00:00:00 2001 From: Mario Bielert Date: Mon, 22 Jul 2013 21:24:16 +0200 Subject: [PATCH 085/108] Fixes build issue for Boxed_Value This ixes the problem, that one has to include chaiscript.hpp to build compilation units, which only use Boxed_Value and boxed_cast. You can now just include boxed_cast.hpp. This decreases build time significant. --- include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp index 38894a0e..97964ca2 100644 --- a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp +++ b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp @@ -7,6 +7,9 @@ #ifndef CHAISCRIPT_DYNAMIC_CAST_CONVERSION_HPP_ #define CHAISCRIPT_DYNAMIC_CAST_CONVERSION_HPP_ +#include +#include + #include "type_info.hpp" #include "boxed_value.hpp" #include "boxed_cast_helper.hpp" From 73b3762f7ad22bdb05a4380147e51120bf45074c Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 2 Nov 2013 07:42:06 -0600 Subject: [PATCH 086/108] Get ChaiScript ported to MSVC 2013. See Notes in code. --- CMakeLists.txt | 11 ++-- include/chaiscript/chaiscript_defines.hpp | 11 +++- include/chaiscript/dispatchkit/any.hpp | 8 ++- .../chaiscript/dispatchkit/bad_boxed_cast.hpp | 10 ++-- .../chaiscript/dispatchkit/bootstrap_stl.hpp | 10 +++- .../chaiscript/dispatchkit/boxed_number.hpp | 6 +- .../chaiscript/dispatchkit/dispatchkit.hpp | 8 +-- .../dispatchkit/dynamic_cast_conversion.hpp | 8 +-- .../dispatchkit/proxy_functions.hpp | 6 +- .../dispatchkit/proxy_functions_detail.hpp | 33 ++++++++++- .../dispatchkit/register_function.hpp | 9 ++- include/chaiscript/dispatchkit/type_info.hpp | 16 ++--- .../chaiscript/language/chaiscript_common.hpp | 14 ++--- .../chaiscript/language/chaiscript_engine.hpp | 6 +- .../language/chaiscript_prelude.chai | 3 +- include/chaiscript/utility/utility.hpp | 3 + src/reflection.cpp | 59 ++++++++++++++----- unittests/multithreaded_test.cpp | 7 ++- unittests/object_lifetime_test.cpp | 7 +++ unittests/type_info_test.cpp | 1 + 20 files changed, 166 insertions(+), 70 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78961ae1..6b9a23a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,9 +72,7 @@ endif(READLINE_LIBRARY) if(MSVC) add_definitions(/W4) - if(CMAKE_CL_64) - add_definitions(/bigobj) - endif() + add_definitions(/bigobj) else() add_definitions(-Wall -Wextra -Wshadow -pedantic -std=c++0x) @@ -177,9 +175,10 @@ if(BUILD_TESTING) ) if (NOT UNIT_TEST_LIGHT) - add_executable(utility_test unittests/utility_test.cpp) - target_link_libraries(utility_test ${LIBS} ${EXTRA_LINKER_FLAGS}) - add_test(NAME Utility_Test COMMAND utility_test) + # commented out because uniform initializer syntax is not working properly in MSVC 2013 + #add_executable(utility_test unittests/utility_test.cpp) + #target_link_libraries(utility_test ${LIBS} ${EXTRA_LINKER_FLAGS}) + #add_test(NAME Utility_Test COMMAND utility_test) add_executable(dynamic_object_test unittests/dynamic_object_test.cpp) target_link_libraries(dynamic_object_test ${LIBS} ${EXTRA_LINKER_FLAGS}) diff --git a/include/chaiscript/chaiscript_defines.hpp b/include/chaiscript/chaiscript_defines.hpp index de6aeb9c..9dd60f99 100644 --- a/include/chaiscript/chaiscript_defines.hpp +++ b/include/chaiscript/chaiscript_defines.hpp @@ -9,7 +9,7 @@ #ifdef _MSC_VER #define CHAISCRIPT_MSVC _MSC_VER -#define CHAISCRIPT_HAS_DECLSPEc +#define CHAISCRIPT_HAS_DECLSPEC #endif #ifdef _WIN32 @@ -23,6 +23,15 @@ #define CHAISCRIPT_MODULE_EXPORT extern "C" #endif +#ifdef CHAISCRIPT_MSVC +#define CHAISCRIPT_NOEXCEPT throw() +#define CHAISCRIPT_CONSTEXPR +#else +#define CHAISCRIPT_NOEXCEPT noexcept +#define CHAISCRIPT_CONSTEXPR constexpr +#endif + + #endif diff --git a/include/chaiscript/dispatchkit/any.hpp b/include/chaiscript/dispatchkit/any.hpp index e8dcfb8d..217ce7fe 100644 --- a/include/chaiscript/dispatchkit/any.hpp +++ b/include/chaiscript/dispatchkit/any.hpp @@ -19,15 +19,15 @@ namespace chaiscript { class bad_any_cast : public std::bad_cast { public: - bad_any_cast() noexcept + bad_any_cast() CHAISCRIPT_NOEXCEPT : m_what("bad any cast") { } - virtual ~bad_any_cast() noexcept {} + virtual ~bad_any_cast() CHAISCRIPT_NOEXCEPT {} /// \brief Description of what error occured - virtual const char * what() const noexcept + virtual const char * what() const CHAISCRIPT_NOEXCEPT { return m_what.c_str(); } @@ -71,6 +71,8 @@ namespace chaiscript { return std::shared_ptr(new Data_Impl(m_data)); } + Data_Impl &operator=(const Data_Impl&) = delete; + const std::type_info &m_type; T m_data; }; diff --git a/include/chaiscript/dispatchkit/bad_boxed_cast.hpp b/include/chaiscript/dispatchkit/bad_boxed_cast.hpp index c4369fa7..0861f2b5 100644 --- a/include/chaiscript/dispatchkit/bad_boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/bad_boxed_cast.hpp @@ -22,25 +22,25 @@ namespace chaiscript { public: bad_boxed_cast(const Type_Info &t_from, const std::type_info &t_to, - const std::string &t_what) noexcept + const std::string &t_what) CHAISCRIPT_NOEXCEPT : from(t_from), to(&t_to), m_what(t_what) { } - bad_boxed_cast(const Type_Info &t_from, const std::type_info &t_to) noexcept + bad_boxed_cast(const Type_Info &t_from, const std::type_info &t_to) CHAISCRIPT_NOEXCEPT : from(t_from), to(&t_to), m_what("Cannot perform boxed_cast") { } - bad_boxed_cast(const std::string &t_what) noexcept + bad_boxed_cast(const std::string &t_what) CHAISCRIPT_NOEXCEPT : to(0), m_what(t_what) { } - virtual ~bad_boxed_cast() noexcept {} + virtual ~bad_boxed_cast() CHAISCRIPT_NOEXCEPT {} /// \brief Description of what error occured - virtual const char * what() const noexcept + virtual const char * what() const CHAISCRIPT_NOEXCEPT { return m_what.c_str(); } diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index ffbf3418..636b1e5c 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -149,6 +149,12 @@ namespace chaiscript namespace detail { + template + size_t count(T &t_target, const typename T::key_type &t_key) + { + return t_target.count(t_key); + } + template void insert(T &t_target, const T &t_other) { @@ -405,11 +411,11 @@ namespace chaiscript template ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&ContainerType::count), "count"); + m->add(fun(detail::count), "count"); typedef size_t (ContainerType::*erase_ptr)(const typename ContainerType::key_type &); - m->add(fun(static_cast(&ContainerType::erase)), "erase"); + m->add(fun(static_cast(&ContainerType::erase)), "erase"); m->add(fun(&detail::insert), "insert"); diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index b2a11d06..194efbd3 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -10,11 +10,13 @@ #include "boxed_value.hpp" #include "../language/chaiscript_algebraic.hpp" #include +#include + namespace chaiscript { -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC #pragma warning(push) #pragma warning(disable : 4244 4018 4389 4146) #endif @@ -846,7 +848,7 @@ namespace chaiscript }; } -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC #pragma warning(pop) #endif diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index b1345fa5..1bc3be59 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -39,12 +39,12 @@ namespace chaiscript class reserved_word_error : public std::runtime_error { public: - reserved_word_error(const std::string &t_word) noexcept + reserved_word_error(const std::string &t_word) CHAISCRIPT_NOEXCEPT : std::runtime_error("Reserved word not allowed in object name: " + t_word), m_word(t_word) { } - virtual ~reserved_word_error() noexcept {} + virtual ~reserved_word_error() CHAISCRIPT_NOEXCEPT {} std::string word() const { @@ -86,12 +86,12 @@ namespace chaiscript class global_non_const : public std::runtime_error { public: - global_non_const() noexcept + global_non_const() CHAISCRIPT_NOEXCEPT : std::runtime_error("a global object must be const") { } - virtual ~global_non_const() noexcept {} + virtual ~global_non_const() CHAISCRIPT_NOEXCEPT {} }; } diff --git a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp index 38894a0e..f2db4eac 100644 --- a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp +++ b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp @@ -20,22 +20,22 @@ namespace chaiscript { public: bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to, - const std::string &t_what) noexcept + const std::string &t_what) CHAISCRIPT_NOEXCEPT : bad_boxed_cast(t_from, t_to, t_what) { } - bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to) noexcept + bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to) CHAISCRIPT_NOEXCEPT : bad_boxed_cast(t_from, t_to) { } - bad_boxed_dynamic_cast(const std::string &w) noexcept + bad_boxed_dynamic_cast(const std::string &w) CHAISCRIPT_NOEXCEPT : bad_boxed_cast(w) { } - virtual ~bad_boxed_dynamic_cast() noexcept {} + virtual ~bad_boxed_dynamic_cast() CHAISCRIPT_NOEXCEPT {} }; } diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 38d20eec..8e5bf7c2 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -176,11 +176,11 @@ namespace chaiscript class guard_error : public std::runtime_error { public: - guard_error() noexcept + guard_error() CHAISCRIPT_NOEXCEPT : std::runtime_error("Guard evaluation failed") { } - virtual ~guard_error() noexcept + virtual ~guard_error() CHAISCRIPT_NOEXCEPT { } }; } @@ -579,7 +579,7 @@ namespace chaiscript { } - virtual ~dispatch_error() noexcept {} + virtual ~dispatch_error() CHAISCRIPT_NOEXCEPT {} std::vector parameters; std::vector functions; diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index 5260ec14..5cfa0c5a 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -32,7 +32,7 @@ namespace chaiscript { } - virtual ~arity_error() noexcept {} + virtual ~arity_error() CHAISCRIPT_NOEXCEPT {} int got; int expected; @@ -43,6 +43,29 @@ namespace chaiscript { namespace detail { + template + struct Build_Param_Type_List; + + template + struct Build_Param_Type_List + { + static void build(std::vector &t_params) + { + t_params.push_back(chaiscript::detail::Get_Type_Info::get()); + Build_Param_Type_List::build(t_params); + } + }; + + // 0th case + template<> + struct Build_Param_Type_List<> + { + static void build(std::vector &) + { + } + }; + + /** * Used by Proxy_Function_Impl to return a list of all param types * it contains. @@ -50,8 +73,12 @@ namespace chaiscript template std::vector build_param_type_list(Ret (*)(Params...)) { - return std::vector { chaiscript::detail::Get_Type_Info::get(), - chaiscript::detail::Get_Type_Info::get()... }; + /// \todo this code was previously using { chaiscript::detail::Get_Type_Info::get()... } + /// but this seems to indicate another bug with MSVC's uniform initializer lists + std::vector params; + params.push_back(chaiscript::detail::Get_Type_Info::get()); + Build_Param_Type_List::build(params); + return params; } diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index 109208cb..50019c03 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -36,13 +36,17 @@ namespace chaiscript template std::function to_function(Ret (Class::*func)(Args...)) { - return std::function(func); + /// \todo this std::mem_fn wrap shouldn't be necessary but type conversions for + /// std::function for member function pointers seems to be broken in MSVC + return std::function(std::mem_fn(func)); } template std::function to_function(Ret (Class::*func)(Args...) const) { - return std::function(func); + /// \todo this std::mem_fn wrap shouldn't be necessary but type conversions for + /// std::function for member function pointers seems to be broken in MSVC + return std::function(std::mem_fn(func)); } template @@ -51,6 +55,7 @@ namespace chaiscript template static Proxy_Function go(T t) { + /// \todo is it possible to reduce the number of templates generated here? return Proxy_Function( new Proxy_Function_Impl::Signature>(to_function(t))); } diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index 466f4745..b634dc69 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -28,7 +28,7 @@ namespace chaiscript class Type_Info { public: - constexpr Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void, + CHAISCRIPT_CONSTEXPR Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void, bool t_is_arithmetic, const std::type_info *t_ti, const std::type_info *t_bareti) : m_type_info(t_ti), m_bare_type_info(t_bareti), m_is_const(t_is_const), m_is_reference(t_is_reference), m_is_pointer(t_is_pointer), @@ -144,7 +144,7 @@ namespace chaiscript { typedef T type; - constexpr static Type_Info get() + CHAISCRIPT_CONSTEXPR static Type_Info get() { return Type_Info(std::is_const::type>::type>::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, @@ -159,7 +159,7 @@ namespace chaiscript { typedef T type; - constexpr static Type_Info get() + CHAISCRIPT_CONSTEXPR static Type_Info get() { return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, @@ -174,7 +174,7 @@ namespace chaiscript { typedef T type; - constexpr static Type_Info get() + CHAISCRIPT_CONSTEXPR static Type_Info get() { return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, @@ -189,7 +189,7 @@ namespace chaiscript { typedef T type; - constexpr static Type_Info get() + CHAISCRIPT_CONSTEXPR static Type_Info get() { return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, @@ -204,7 +204,7 @@ namespace chaiscript { typedef T type; - constexpr static Type_Info get() + CHAISCRIPT_CONSTEXPR static Type_Info get() { return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, @@ -231,7 +231,7 @@ namespace chaiscript /// chaiscript::Type_Info ti = chaiscript::user_type(i); /// \endcode template - constexpr Type_Info user_type(const T &/*t*/) + CHAISCRIPT_CONSTEXPR Type_Info user_type(const T &/*t*/) { return detail::Get_Type_Info::get(); } @@ -246,7 +246,7 @@ namespace chaiscript /// chaiscript::Type_Info ti = chaiscript::user_type(); /// \endcode template - constexpr Type_Info user_type() + CHAISCRIPT_CONSTEXPR Type_Info user_type() { return detail::Get_Type_Info::get(); } diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index e784e871..07969f16 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -75,7 +75,7 @@ namespace chaiscript eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname, const std::vector &t_parameters, const std::vector &t_functions, bool t_dot_notation, - const chaiscript::detail::Dispatch_Engine &t_ss) noexcept : + const chaiscript::detail::Dispatch_Engine &t_ss) CHAISCRIPT_NOEXCEPT : std::runtime_error(format(t_why, t_where, t_fname, t_parameters, t_dot_notation, t_ss)), reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname), detail(format_detail(t_functions, t_dot_notation, t_ss)) {} @@ -83,18 +83,18 @@ namespace chaiscript eval_error(const std::string &t_why, const std::vector &t_parameters, const std::vector &t_functions, bool t_dot_notation, - const chaiscript::detail::Dispatch_Engine &t_ss) noexcept : + const chaiscript::detail::Dispatch_Engine &t_ss) CHAISCRIPT_NOEXCEPT : std::runtime_error(format(t_why, t_parameters, t_dot_notation, t_ss)), reason(t_why), detail(format_detail(t_functions, t_dot_notation, t_ss)) {} - eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) noexcept : + eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) CHAISCRIPT_NOEXCEPT : std::runtime_error(format(t_why, t_where, t_fname)), reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname) {} - eval_error(const std::string &t_why) noexcept + eval_error(const std::string &t_why) CHAISCRIPT_NOEXCEPT : std::runtime_error("Error: \"" + t_why + "\" "), reason(t_why) {} @@ -121,7 +121,7 @@ namespace chaiscript return ss.str(); } - virtual ~eval_error() noexcept {} + virtual ~eval_error() CHAISCRIPT_NOEXCEPT {} private: @@ -381,11 +381,11 @@ namespace chaiscript * Errors generated when loading a file */ struct file_not_found_error : public std::runtime_error { - file_not_found_error(const std::string &t_filename) noexcept + file_not_found_error(const std::string &t_filename) CHAISCRIPT_NOEXCEPT : std::runtime_error("File Not Found: " + t_filename) { } - virtual ~file_not_found_error() noexcept {} + virtual ~file_not_found_error() CHAISCRIPT_NOEXCEPT {} }; } diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index d3fefc6d..5d336d13 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -39,12 +39,12 @@ namespace chaiscript /// \brief Thrown if an error occurs while attempting to load a binary module struct load_module_error : std::runtime_error { - load_module_error(const std::string &t_reason) noexcept + load_module_error(const std::string &t_reason) CHAISCRIPT_NOEXCEPT : std::runtime_error(t_reason) { } - virtual ~load_module_error() noexcept + virtual ~load_module_error() CHAISCRIPT_NOEXCEPT { } }; @@ -355,7 +355,7 @@ namespace chaiscript m_engine.add(fun(&ChaiScript::internal_eval, this), "eval"); m_engine.add(fun(&ChaiScript::internal_eval_ast, this), "eval"); - do_eval(ChaiScript_Prelude::chaiscript_prelude, "standard prelude"); + do_eval(ChaiScript_Prelude::chaiscript_prelude(), "standard prelude"); } /** diff --git a/include/chaiscript/language/chaiscript_prelude.chai b/include/chaiscript/language/chaiscript_prelude.chai index 29d9b2f7..95710ba6 100644 --- a/include/chaiscript/language/chaiscript_prelude.chai +++ b/include/chaiscript/language/chaiscript_prelude.chai @@ -9,7 +9,7 @@ namespace chaiscript { struct ChaiScript_Prelude { - constexpr static const char *chaiscript_prelude=R""( + static std::string chaiscript_prelude() { return R""( def lt(l, r) { if (call_exists(`<`, l, r)) { @@ -523,6 +523,7 @@ def find(container, value) { )""; +} }; } diff --git a/include/chaiscript/utility/utility.hpp b/include/chaiscript/utility/utility.hpp index 63c5a239..1943db7e 100644 --- a/include/chaiscript/utility/utility.hpp +++ b/include/chaiscript/utility/utility.hpp @@ -16,6 +16,8 @@ namespace chaiscript namespace utility { + /// \todo Use of this utility, and uniform initializer lists, is causing memory errors in MSVC + /* template void add_class(ModuleType &t_module, const std::string &t_classname, @@ -35,6 +37,7 @@ namespace chaiscript } } + */ } } diff --git a/src/reflection.cpp b/src/reflection.cpp index b7cb1c58..841e4a21 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -63,13 +63,25 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect using namespace chaiscript; + m->add(chaiscript::user_type(), "eval_error"); + m->add(chaiscript::fun(&chaiscript::exception::eval_error::reason), "reason"); + m->add(chaiscript::fun(&chaiscript::exception::eval_error::call_stack), "call_stack"); + /* chaiscript::utility::add_class(*m, "eval_error", { }, { {fun(&chaiscript::exception::eval_error::reason), "reason"}, {fun(&chaiscript::exception::eval_error::call_stack), "call_stack"} } ); + */ + m->add(chaiscript::user_type(), "File_Position"); + m->add(chaiscript::constructor(), "File_Position"); + m->add(chaiscript::constructor(), "File_Position"); + m->add(chaiscript::fun(&File_Position::line), "line"); + m->add(chaiscript::fun(&File_Position::column), "column"); + + /* chaiscript::utility::add_class(*m, "File_Position", { constructor(), @@ -77,28 +89,47 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect { {fun(&File_Position::line), "line"}, {fun(&File_Position::column), "column"} } ); + */ - chaiscript::utility::add_class(*m, - "AST_Node", - { }, - { {fun(&AST_Node::text), "text"}, - {fun(&AST_Node::identifier), "identifier"}, - {fun(&AST_Node::filename), "filename"}, - {fun(&AST_Node::start), "start"}, - {fun(&AST_Node::end), "end"}, - {fun(&AST_Node::internal_to_string), "internal_to_string"}, - {fun(&AST_Node::children), "children"}, - {fun(&AST_Node::replace_child), "replace_child"} - } - ); + m->add(chaiscript::user_type(), "AST_Node"); + m->add(chaiscript::fun(&AST_Node::text), "text"); + m->add(chaiscript::fun(&AST_Node::identifier), "identifier"); + m->add(chaiscript::fun(&AST_Node::filename), "filename"); + m->add(chaiscript::fun(&AST_Node::start), "start"); + m->add(chaiscript::fun(&AST_Node::end), "end"); + m->add(chaiscript::fun(&AST_Node::internal_to_string), "internal_to_string"); + m->add(chaiscript::fun(&AST_Node::children), "children"); + m->add(chaiscript::fun(&AST_Node::replace_child), "replace_child"); + /* + chaiscript::utility::add_class(*m, + "AST_Node", + { }, + { {fun(&AST_Node::text), "text"}, + {fun(&AST_Node::identifier), "identifier"}, + {fun(&AST_Node::filename), "filename"}, + {fun(&AST_Node::start), "start"}, + {fun(&AST_Node::end), "end"}, + {fun(&AST_Node::internal_to_string), "internal_to_string"}, + {fun(&AST_Node::children), "children"}, + {fun(&AST_Node::replace_child), "replace_child"} + } + ); + */ + + m->add(chaiscript::user_type(), "ChaiScript_Parser"); + m->add(chaiscript::constructor(), "ChaiScript_Parser"); + m->add(chaiscript::fun(&parser::ChaiScript_Parser::parse), "parse"); + m->add(chaiscript::fun(&parser::ChaiScript_Parser::ast), "ast"); + + /* chaiscript::utility::add_class(*m, "ChaiScript_Parser", { constructor() }, { {fun(&parser::ChaiScript_Parser::parse), "parse"}, {fun(&parser::ChaiScript_Parser::ast), "ast"} } ); - + */ return m; diff --git a/unittests/multithreaded_test.cpp b/unittests/multithreaded_test.cpp index 3b8c8620..3386d1d3 100644 --- a/unittests/multithreaded_test.cpp +++ b/unittests/multithreaded_test.cpp @@ -40,7 +40,10 @@ void do_work(chaiscript::ChaiScript &c, int id) int main() { // Disable deprecation warning for getenv call. -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC +#ifdef max // Why microsoft? why? +#undef max +#endif #pragma warning(push) #pragma warning(disable : 4996) #endif @@ -48,7 +51,7 @@ int main() const char *usepath = getenv("CHAI_USE_PATH"); const char *modulepath = getenv("CHAI_MODULE_PATH"); -#ifdef BOOST_MSVC +#ifdef CHAISCRIPT_MSVC #pragma warning(pop) #endif diff --git a/unittests/object_lifetime_test.cpp b/unittests/object_lifetime_test.cpp index ab66ad76..3b7ed2fe 100644 --- a/unittests/object_lifetime_test.cpp +++ b/unittests/object_lifetime_test.cpp @@ -29,12 +29,19 @@ int main() { chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module()); + /* chaiscript::utility::add_class(*m, "Test", { chaiscript::constructor(), chaiscript::constructor() }, { {chaiscript::fun(&Test::count), "count"} } ); + */ + + m->add(chaiscript::user_type(), "Test"); + m->add(chaiscript::constructor(), "Test"); + m->add(chaiscript::constructor(), "Test"); + m->add(chaiscript::fun(&Test::count), "count"); chaiscript::ChaiScript chai; chai.add(m); diff --git a/unittests/type_info_test.cpp b/unittests/type_info_test.cpp index 3dba9071..56f2681c 100644 --- a/unittests/type_info_test.cpp +++ b/unittests/type_info_test.cpp @@ -1,5 +1,6 @@ // Tests to make sure that the order in which function dispatches occur is correct +#include #include #include From 510d550d64d27cc24678442784a5c775a7945963 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 2 Nov 2013 08:18:09 -0600 Subject: [PATCH 087/108] Fix static analysis issue --- include/chaiscript/language/chaiscript_engine.hpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 5d336d13..26c1404f 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -157,9 +157,9 @@ namespace chaiscript typedef LPSTR StringType; std::string retval = "Unknown Error"; #endif - StringType lpMsgBuf = 0; + StringType lpMsgBuf = nullptr; - FormatMessage( + if (FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, @@ -167,14 +167,12 @@ namespace chaiscript t_err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (StringType)&lpMsgBuf, - 0, NULL ); - - if (lpMsgBuf) + 0, NULL ) != 0 && lpMsgBuf) { retval = lpMsgBuf; + LocalFree(lpMsgBuf); } - LocalFree(lpMsgBuf); return tostring(retval); } From 95e3093df364b5384e049214776954b44395e990 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 2 Nov 2013 10:55:36 -0600 Subject: [PATCH 088/108] Update -std=c++0x to -std=c++11 --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b9a23a3..129e4252 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,7 @@ if(MSVC) add_definitions(/W4) add_definitions(/bigobj) else() - add_definitions(-Wall -Wextra -Wshadow -pedantic -std=c++0x) + add_definitions(-Wall -Wextra -Wshadow -pedantic -std=c++11) if (APPLE) add_definitions(-Wno-sign-compare) @@ -87,9 +87,9 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if (USE_LIBCXX) add_definitions(-stdlib=libc++) - set (EXTRA_LINKER_FLAGS -std=c++0x -stdlib=libc++) + set (EXTRA_LINKER_FLAGS -std=c++11 -stdlib=libc++) else () - set (EXTRA_LINKER_FLAGS -std=c++0x ) + set (EXTRA_LINKER_FLAGS -std=c++11 ) endif() else() set (EXTRA_LINKER_FLAGS ) From 7cebc8d748444691e429828c42f02f6b1f727adb Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 27 Nov 2013 09:36:50 -0700 Subject: [PATCH 089/108] Make map::count() properly const. #90 --- include/chaiscript/dispatchkit/bootstrap_stl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 0c090cf1..42c0ef0c 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -150,7 +150,7 @@ namespace chaiscript namespace detail { template - size_t count(T &t_target, const typename T::key_type &t_key) + size_t count(const T &t_target, const typename T::key_type &t_key) { return t_target.count(t_key); } From e667b4df5fe9f0ca4d207df7d859ec67c5e09d56 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 5 Jan 2014 11:52:59 -0700 Subject: [PATCH 090/108] Fix missing empty, clear and size methods for strings Fixes bugs #95 and #93 --- .../chaiscript/dispatchkit/bootstrap_stl.hpp | 29 +++---------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 42c0ef0c..975c90f1 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -519,31 +519,6 @@ namespace chaiscript return m; } - namespace detail { - template - struct apple_string_workarounds - { - /// The latest version of MacOS has a broken std::string implementation which will not allow - /// us to take pointers to the members. Code compiles, but does not link - /// \todo re-evaluate at some point - - static size_t find(const String *s, const String &w, int pos) { return s->find(w, pos); } - static size_t rfind(const String *s, const String &w, size_t pos) { return s->rfind(w, pos); } - static size_t find_first_of(const String *s, const String &w, size_t pos) { return s->find_first_of(w, pos); } - static size_t find_last_of(const String *s, const String &w, size_t pos) { return s->find_last_of(w, pos); } - static size_t find_first_not_of(const String *s, const String &w, size_t pos) { return s->find_first_not_of(w, pos); } - static size_t find_last_not_of(const String *s, const String &w, size_t pos) { return s->find_last_not_of(w, pos); } - - static void clear(String *s) { s->clear(); } - static bool empty(const String *s) { return s->empty(); } - static size_t size(const String *s) { return s->size(); } - - static std::string substr(const String *s, size_t pos, size_t len) { return s->substr(pos,len); } - static const char *c_str(const String *s) { return s->c_str(); } - static const char *data(const String *s) { return s->data(); } - }; - } - /** * Add a String container * http://www.sgi.com/tech/stl/basic_string.html @@ -582,6 +557,10 @@ namespace chaiscript m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_last_not_of(f, pos); } ) ), "find_last_not_of"); m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_first_not_of(f, pos); } ) ), "find_first_not_of"); + m->add(fun( std::function( [](String *s) { return s->clear(); } ) ), "clear"); + m->add(fun( std::function( [](const String *s) { return s->empty(); } ) ), "empty"); + m->add(fun( std::function( [](const String *s) { return s->size(); } ) ), "size"); + m->add(fun( std::function( [](const String *s) { return s->c_str(); } ) ), "c_str"); m->add(fun( std::function( [](const String *s) { return s->data(); } ) ), "data"); m->add(fun( std::function( [](const String *s, int pos, int len) { return s->substr(pos, len); } ) ), "substr"); From 5272a64be9b832a19aa2371668ab51f69a3b3e4f Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 5 Jan 2014 16:27:32 -0700 Subject: [PATCH 091/108] Fix (legit) warning in VisualStudio --- include/chaiscript/dispatchkit/boxed_number.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index ce93228f..543f267f 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -50,7 +50,6 @@ namespace chaiscript default: throw chaiscript::detail::exception::bad_any_cast(); } - throw chaiscript::detail::exception::bad_any_cast(); } }; @@ -146,7 +145,6 @@ namespace chaiscript default: throw chaiscript::detail::exception::bad_any_cast(); } - throw chaiscript::detail::exception::bad_any_cast(); } }; @@ -172,7 +170,6 @@ namespace chaiscript default: throw chaiscript::detail::exception::bad_any_cast(); } - throw chaiscript::detail::exception::bad_any_cast(); } }; From ac21c8b0631e807bd4f301d37a1b443a0692ee72 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 7 Jan 2014 17:35:58 -0600 Subject: [PATCH 092/108] fix building main.cpp when readline is available This changes around the pragma conditionals to make sure that certain symbols (such as "default_search_path") are defined even if the system has readline available during builds. --- src/main.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0a84cd09..edb19a6d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,6 +23,18 @@ char *mystrdup (const char *s) { return d; // Return the new string } +char* readline(const char* p) +{ + std::string retval; + std::cout << p ; + std::getline(std::cin, retval); + return std::cin.eof() ? NULL : mystrdup(retval.c_str()); +} + +void add_history(const char*){} +void using_history(){} +#endif + void *cast_module_symbol(std::string (*t_path)()) { union cast_union @@ -101,19 +113,6 @@ std::string default_search_path() #endif } - -char* readline(const char* p) -{ - std::string retval; - std::cout << p ; - std::getline(std::cin, retval); - return std::cin.eof() ? NULL : mystrdup(retval.c_str()); -} - -void add_history(const char*){} -void using_history(){} -#endif - void help(int n) { if ( n >= 0 ) { std::cout << "ChaiScript evaluator. To evaluate an expression, type it and press ." << std::endl; From a195fac4ca2ff3af009b8bb944b44982a02877f3 Mon Sep 17 00:00:00 2001 From: Cameron Garnham Date: Fri, 17 Jan 2014 14:36:36 -0800 Subject: [PATCH 093/108] force no unicode in search parth windows --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index edb19a6d..edc77fac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,9 +50,9 @@ void *cast_module_symbol(std::string (*t_path)()) std::string default_search_path() { -#ifdef CHAISCRIPT_WINDOWS - TCHAR path[2048]; - int size = GetModuleFileName(0, path, sizeof(path)-1); +#ifdef CHAISCRIPT_WINDOWS // force no unicode + CHAR path[4096]; + int size = GetModuleFileNameA(0, path, sizeof(path)-1); std::string exepath(path, size); From 3a6caeb1c5d3d87bf2bdc7d8626f7950340cd03d Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 23 Jan 2014 13:08:08 -0700 Subject: [PATCH 094/108] Fix #98 for unavoidable C style returns in modules --- src/chaiscript_stdlib.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/chaiscript_stdlib.cpp b/src/chaiscript_stdlib.cpp index cef0473b..d4ea13e8 100644 --- a/src/chaiscript_stdlib.cpp +++ b/src/chaiscript_stdlib.cpp @@ -9,6 +9,11 @@ #pragma warning(disable : 4190) #endif +#ifdef __llvm__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wreturn-type-c-linkage" +#endif + CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_chaiscript_stdlib() { @@ -16,6 +21,10 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_chaiscr } +#ifdef __llvm__ +#pragma clang diagnostic pop +#endif + #ifdef CHAISCRIPT_MSVC #pragma warning(pop) #endif From b2b9efebe364af725eb444eb57673d233723a089 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 26 Feb 2014 10:50:33 -0700 Subject: [PATCH 095/108] Add unit test to make sure heap allocation of chai works --- CMakeLists.txt | 4 ++++ unittests/heap_allocated_chaiscript_test.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+) create mode 100644 unittests/heap_allocated_chaiscript_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 77f672d9..76ed062d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -232,6 +232,10 @@ if(BUILD_TESTING) target_link_libraries(simultaneous_chaiscript_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME Simultaneous_Chaiscript_Test COMMAND simultaneous_chaiscript_test) + add_executable(heap_allocated_chaiscript_test unittests/heap_allocated_chaiscript_test.cpp) + target_link_libraries(heap_allocated_chaiscript_test ${LIBS} ${EXTRA_LINKER_FLAGS}) + add_test(NAME Heap_Allocated_Chaiscript_Test COMMAND heap_allocated_chaiscript_test) + add_executable(c_linkage_test unittests/c_linkage_test.cpp) target_link_libraries(c_linkage_test ${LIBS} ${EXTRA_LINKER_FLAGS}) add_test(NAME C_Linkage_Test COMMAND c_linkage_test) diff --git a/unittests/heap_allocated_chaiscript_test.cpp b/unittests/heap_allocated_chaiscript_test.cpp new file mode 100644 index 00000000..ce37cbac --- /dev/null +++ b/unittests/heap_allocated_chaiscript_test.cpp @@ -0,0 +1,10 @@ +#include + + +int main() +{ + chaiscript::ChaiScript *chai = new chaiscript::ChaiScript(); + delete chai; + + return EXIT_SUCCESS; +} From 3d76e980cc81e3c371b6ce4e5d06e079369491cb Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 1 Mar 2014 07:42:32 -0700 Subject: [PATCH 096/108] Attempt to detect if g++ is old and we should use --c++0x --- CMakeLists.txt | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04be8b7c..acf6de8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,11 +70,25 @@ else(READLINE_LIBRARY) set (READLINE_FLAG ) endif(READLINE_LIBRARY) + +if (CMAKE_COMPILER_IS_GNUCC) + execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion + OUTPUT_VARIABLE GCC_VERSION) + + if (GCC_VERSION VERSION_LESS 4.8) + SET(CPP11_FLAG "-std=c++0x") + else() + SET(CPP11_FLAG "-std=c++11") + endif() +else() + SET(CPP11_FLAG "-std=c++11") +endif() + if(MSVC) add_definitions(/W4) add_definitions(/bigobj) else() - add_definitions(-Wall -Wextra -Wshadow -pedantic -std=c++11) + add_definitions(-Wall -Wextra -Wshadow -pedantic ${CPP11_FLAG}) if (APPLE) add_definitions(-Wno-sign-compare) @@ -87,9 +101,9 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if (USE_LIBCXX) add_definitions(-stdlib=libc++) - set (EXTRA_LINKER_FLAGS -std=c++11 -stdlib=libc++) + set (EXTRA_LINKER_FLAGS ${CPP11_FLAG}-stdlib=libc++) else () - set (EXTRA_LINKER_FLAGS -std=c++11 ) + set (EXTRA_LINKER_FLAGS ${CPP11_FLAG} ) endif() else() set (EXTRA_LINKER_FLAGS ) From a38d89cb412edc582d2ca784d6941da4f656cd6c Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 1 Mar 2014 13:49:03 -0700 Subject: [PATCH 097/108] Add fixes for parsing of inplace vectors with newlines from jespada --- .../chaiscript/language/chaiscript_parser.hpp | 23 ++++++++++++++++--- releasenotes.txt | 1 + unittests/vector_inplace_init.chai | 7 ++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 3580c9f1..0b30cc41 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -317,13 +317,21 @@ namespace chaiscript /** * Skips ChaiScript whitespace, which means space and tab, but not cr/lf + * jespada: Modified SkipWS to skip optionally CR ('\n') */ - bool SkipWS() { + bool SkipWS(bool skip_cr=false) { bool retval = false; while (has_more_input()) { - if ( char_in_alphabet(*m_input_pos,detail::white_alphabet) ) { + if ( char_in_alphabet(*m_input_pos,detail::white_alphabet) || (skip_cr && (*m_input_pos == '\n'))) { + if(*m_input_pos == '\n') { + m_col = 1; + ++m_line; + } + else { + ++m_col; + } ++m_input_pos; - ++m_col; + retval = true; } else if (SkipComment()) { @@ -1241,6 +1249,8 @@ namespace chaiscript * Reads a comma-separated list of values from input */ bool Arg_List() { + + SkipWS(true); bool retval = false; size_t prev_stack_top = m_match_stack.size(); @@ -1259,6 +1269,8 @@ namespace chaiscript build_match(AST_NodePtr(new eval::Arg_List_AST_Node()), prev_stack_top); } + SkipWS(true); + return retval; } @@ -1267,6 +1279,7 @@ namespace chaiscript */ bool Container_Arg_List() { bool retval = false; + SkipWS(true); size_t prev_stack_top = m_match_stack.size(); @@ -1301,6 +1314,8 @@ namespace chaiscript build_match(AST_NodePtr(new eval::Arg_List_AST_Node()), prev_stack_top); } + SkipWS(true); + return retval; } @@ -1917,6 +1932,7 @@ namespace chaiscript if (Char('[')) { retval = true; Container_Arg_List(); + if (!Char(']')) { throw exception::eval_error("Missing closing square bracket ']' in container initializer", File_Position(m_line, m_col), *m_filename); } @@ -2228,6 +2244,7 @@ namespace chaiscript Symbol("-=", true, true) || Symbol("*=", true, true) || Symbol("/=", true, true) || Symbol("%=", true, true) || Symbol("<<=", true, true) || Symbol(">>=", true, true) || Symbol("&=", true, true) || Symbol("^=", true, true) || Symbol("|=", true, true)) { + SkipWS(true); if (!Equation()) { throw exception::eval_error("Incomplete equation", File_Position(m_line, m_col), *m_filename); } diff --git a/releasenotes.txt b/releasenotes.txt index 9e3d8e24..c25d0dd3 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -21,6 +21,7 @@ Notes: * Fix various string / map / vector `size` and `count` calls for compilers which have weird overloads for them. #90 #93 #95 * Make module search path relative to the currently running executable * Build and work with wstring windows builds +* fix for some new line cases in the middle of a vector initialization from jespada ### Changes since 5.1.0 * Add support for automatic conversion of arithmetic types when possible diff --git a/unittests/vector_inplace_init.chai b/unittests/vector_inplace_init.chai index e3bf6a37..56e06906 100644 --- a/unittests/vector_inplace_init.chai +++ b/unittests/vector_inplace_init.chai @@ -3,6 +3,7 @@ assert_equal(3, x.size()) + // Make sure vector elements are copied into place for consistency with // map inplace construction var i = 1; @@ -12,3 +13,9 @@ assert_equal(1, y[0]); i = 3; assert_equal(3, i); assert_equal(1, y[0]); + + +// make sure initialization with a break in the middle works as expected +var a = [0.0,0.0, + 1.0,1.0] + From daf5480c483ae5a9c6153e1e38748c166d3eeb4f Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 1 Mar 2014 16:03:01 -0700 Subject: [PATCH 098/108] Fix up the pthread usage on broken ubuntu gcc4.8.1 For more information: http://stackoverflow.com/questions/19463602/compiling-multithread-code-with-g --- CMakeLists.txt | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index acf6de8f..c122aac4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,6 +75,7 @@ if (CMAKE_COMPILER_IS_GNUCC) execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) + if (GCC_VERSION VERSION_LESS 4.8) SET(CPP11_FLAG "-std=c++0x") else() @@ -101,12 +102,12 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if (USE_LIBCXX) add_definitions(-stdlib=libc++) - set (EXTRA_LINKER_FLAGS ${CPP11_FLAG}-stdlib=libc++) + set (EXTRA_LINKER_FLAGS ${CPP11_FLAG} -stdlib=libc++) else () - set (EXTRA_LINKER_FLAGS ${CPP11_FLAG} ) + set (EXTRA_LINKER_FLAGS ${CPP11_FLAG}) endif() else() - set (EXTRA_LINKER_FLAGS ) + set (EXTRA_LINKER_FLAGS ${CPP11_FLAG}) endif() # limitations in MinGW require us to make an optimized build @@ -133,9 +134,20 @@ if (CMAKE_HOST_UNIX) endif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") if (MULTITHREAD_SUPPORT_ENABLED) - list(APPEND LIBS "pthread") + if (CMAKE_COMPILER_IS_GNUCC) + execute_process(COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_VARIABLE GCC_FULL_VERSION) + if (GCC_FULL_VERSION MATCHES "4.8.1.*ubuntu") + set (EXTRA_LINKER_FLAGS ${EXTRA_LINKER_FLAGS} -Wl,--no-as-needed -pthread ) + else() + set (EXTRA_LINKER_FLAGS ${EXTRA_LINKER_FLAGS} -pthread ) + endif() + else() + set (EXTRA_LINKER_FLAGS ${EXTRA_LINKER_FLAGS} -pthread ) + endif() + add_definitions(-pthread) endif() + endif(CMAKE_HOST_UNIX) list(APPEND LIBS ${READLINE_LIB}) @@ -147,7 +159,7 @@ if (CMAKE_COMPILER_2005) endif() add_library(chaiscript_stdlib MODULE src/chaiscript_stdlib.cpp) -target_link_libraries(chaiscript_stdlib ${LIBS} ${EXTRA_LINKER_FLAGS}) +target_link_libraries(chaiscript_stdlib ${LIBS} ${EXTRA_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT}) add_executable(chai src/main.cpp ${Chai_INCLUDES}) target_link_libraries(chai ${LIBS} ${EXTRA_LINKER_FLAGS}) From dbd9534bd924654ee9e983e69188c4925b3d897e Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 2 Mar 2014 08:18:36 -0700 Subject: [PATCH 099/108] Eliminate warnings on MSVC 2013 Note that this required ignoring a few warnings with pragmas, changing the parameter type and return types of std::string::find functions to size_t from int and a new global warning disable on MSVC. I've managed to avoid global warning disables up to this point in the code, but I don't see a way around the "decorated name too long (C4503)" warning. Closes #100 --- CMakeLists.txt | 14 +++++++---- include/chaiscript/chaiscript_stdlib.hpp | 2 -- .../chaiscript/dispatchkit/bootstrap_stl.hpp | 24 ++++++++++--------- .../dispatchkit/proxy_functions_detail.hpp | 12 ++++++---- .../language/chaiscript_prelude.chai | 12 +++++----- src/main.cpp | 13 ++++++---- 6 files changed, 44 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c122aac4..96f4d512 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,14 @@ endif() if(MSVC) add_definitions(/W4) add_definitions(/bigobj) + # Note on MSVC compiler flags. + # The code base selective disables warnings as necessary when the compiler is complaining too much + # about something that is perfectly valid, or there is simply no technical way around it + # This particular warning, C4503 is in regards to the decorated names that MSVC generates internally. + # The error did not come up until the move to C++11, but the compiler doesn't give enough information + # to determine where the error is coming from, and the internet provides no real information for + # how to workaround or fix the error. So I'm disabling it globally. + ADD_DEFINITIONS(/wd4503) else() add_definitions(-Wall -Wextra -Wshadow -pedantic ${CPP11_FLAG}) @@ -106,7 +114,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") else () set (EXTRA_LINKER_FLAGS ${CPP11_FLAG}) endif() -else() +elseif(CMAKE_COMPILER_IS_GNUCC) set (EXTRA_LINKER_FLAGS ${CPP11_FLAG}) endif() @@ -153,10 +161,6 @@ endif(CMAKE_HOST_UNIX) list(APPEND LIBS ${READLINE_LIB}) -if (CMAKE_COMPILER_2005) - # vs2005 is a bit too loud about possible loss of data warnings -# ADD_DEFINITIONS(/wd4244) -endif() add_library(chaiscript_stdlib MODULE src/chaiscript_stdlib.cpp) target_link_libraries(chaiscript_stdlib ${LIBS} ${EXTRA_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT}) diff --git a/include/chaiscript/chaiscript_stdlib.hpp b/include/chaiscript/chaiscript_stdlib.hpp index 0fdad697..57f312f0 100644 --- a/include/chaiscript/chaiscript_stdlib.hpp +++ b/include/chaiscript/chaiscript_stdlib.hpp @@ -38,7 +38,5 @@ namespace chaiscript }; } - - #endif diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 034bc83a..13b778a9 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -266,7 +266,7 @@ namespace chaiscript template ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { - m->add(fun( std::function( [](const ContainerType *a) { return a->size(); } ) ), "size"); + m->add(fun( std::function( [](const ContainerType *a) { return a->size(); } ) ), "size"); m->add(fun( std::function( [](const ContainerType *a) { return a->empty(); } ) ), "empty"); m->add(fun( std::function( [](ContainerType *a) { a->clear(); } ) ), "clear"); return m; @@ -525,19 +525,19 @@ namespace chaiscript } m->add(fun(&String::push_back), push_back_name); - typedef std::function find_func; + typedef std::function find_func; - m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find(f, pos); } )), "find"); - m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->rfind(f, pos); } ) ), "rfind"); - m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_first_of(f, pos); } ) ), "find_first_of"); - m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_last_of(f, pos); } ) ), "find_last_of"); - m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_last_not_of(f, pos); } ) ), "find_last_not_of"); - m->add(fun(find_func( [](const String *s, const String &f, int pos) { return s->find_first_not_of(f, pos); } ) ), "find_first_not_of"); + m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->find(f, pos); } )), "find"); + m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->rfind(f, pos); } ) ), "rfind"); + m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->find_first_of(f, pos); } ) ), "find_first_of"); + m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->find_last_of(f, pos); } ) ), "find_last_of"); + m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->find_last_not_of(f, pos); } ) ), "find_last_not_of"); + m->add(fun(find_func( [](const String *s, const String &f, size_t pos) { return s->find_first_not_of(f, pos); } ) ), "find_first_not_of"); - m->add(fun( std::function( [](String *s) { return s->clear(); } ) ), "clear"); - m->add(fun( std::function( [](const String *s) { return s->empty(); } ) ), "empty"); - m->add(fun( std::function( [](const String *s) { return s->size(); } ) ), "size"); + m->add(fun( std::function( [](String *s) { return s->clear(); } ) ), "clear"); + m->add(fun( std::function( [](const String *s) { return s->empty(); } ) ), "empty"); + m->add(fun( std::function( [](const String *s) { return s->size(); } ) ), "size"); m->add(fun( std::function( [](const String *s) { return s->c_str(); } ) ), "c_str"); m->add(fun( std::function( [](const String *s) { return s->data(); } ) ), "data"); @@ -551,3 +551,5 @@ namespace chaiscript #endif + + diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index 11cda9ec..8f1901c6 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -106,11 +106,6 @@ namespace chaiscript }; - -#ifdef BOOST_MSVC -#pragma warning(pop) -#endif - /** * Used by Proxy_Function_Impl to determine if it is equivalent to another * Proxy_Function_Impl object. This function is primarly used to prevent @@ -144,12 +139,19 @@ namespace chaiscript template struct Call_Func { +#ifdef CHAISCRIPT_MSVC +#pragma warning(push) +#pragma warning(disable : 4100) /// Disable unreferenced formal parameter warning, which only shows up in MSVC I don't think there's any way around it \todo evaluate this +#endif template static Ret do_call(const std::function &f, const std::vector &, const Dynamic_Cast_Conversions &t_conversions, InnerParams &&... innerparams) { return f(boxed_cast(std::forward(innerparams), &t_conversions)...); } +#ifdef CHAISCRIPT_MSVC +#pragma warning(pop) +#endif }; /** diff --git a/include/chaiscript/language/chaiscript_prelude.chai b/include/chaiscript/language/chaiscript_prelude.chai index 95710ba6..7af9a619 100644 --- a/include/chaiscript/language/chaiscript_prelude.chai +++ b/include/chaiscript/language/chaiscript_prelude.chai @@ -455,37 +455,37 @@ def zip(x, y) { # Returns the position of the second value string in the first value string def string::find(substr) : is_type(substr, "string") { - int(find(this, substr, 0)); + find(this, substr, size_t(0)); } # Returns the position of last match of the second value string in the first value string def string::rfind(substr) : is_type(substr, "string") { - int(rfind(this, substr, -1)); + rfind(this, substr, size_t(-1)); } # Returns the position of the first match of elements in the second value string in the first value string def string::find_first_of(list) : is_type(list, "string") { - int(find_first_of(this, list, 0)); + find_first_of(this, list, size_t(0)); } # Returns the position of the last match of elements in the second value string in the first value string def string::find_last_of(list) : is_type(list, "string") { - int(find_last_of(this, list, -1)); + find_last_of(this, list, size_t(-1)); } # Returns the position of the first non-matching element in the second value string in the first value string def string::find_first_not_of(list) : is_type(list, "string") { - int(find_first_not_of(this, list, 0)); + find_first_not_of(this, list, size_t(0)); } # Returns the position of the last non-matching element in the second value string in the first value string def string::find_last_not_of(list) : is_type(list, "string") { - int(find_last_not_of(this, list, -1)); + find_last_not_of(this, list, size_t(-1)); } diff --git a/src/main.cpp b/src/main.cpp index a4738941..d633c76f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,10 +17,15 @@ #else char *mystrdup (const char *s) { - char *d = static_cast(malloc (strlen (s) + 1)); // Space for length plus nul - if (d == nullptr) return nullptr; // No memory - strcpy (d,s); // Copy the characters - return d; // Return the new string + size_t len = strlen(s) + 1; // Space for length plus nul + char *d = static_cast(malloc (len)); + if (d == nullptr) return nullptr; // No memory +#ifdef CHAISCRIPT_MSVC + strcpy_s(d, len, s); // Copy the characters +#else + strcpy(d,s); // Copy the characters +#endif + return d; // Return the new string } char* readline(const char* p) From ebbcc5cbdbb1283c78a36f5b1021171b752e5cbe Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 4 Mar 2014 11:20:45 -0700 Subject: [PATCH 100/108] Catch missing virtual destructors, enable g++ warnings --- CMakeLists.txt | 2 +- include/chaiscript/dispatchkit/any.hpp | 7 +++++-- include/chaiscript/dispatchkit/proxy_functions.hpp | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c122aac4..2875f31b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,7 +89,7 @@ if(MSVC) add_definitions(/W4) add_definitions(/bigobj) else() - add_definitions(-Wall -Wextra -Wshadow -pedantic ${CPP11_FLAG}) + add_definitions(-Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic ${CPP11_FLAG}) if (APPLE) add_definitions(-Wno-sign-compare) diff --git a/include/chaiscript/dispatchkit/any.hpp b/include/chaiscript/dispatchkit/any.hpp index 217ce7fe..75a01c0f 100644 --- a/include/chaiscript/dispatchkit/any.hpp +++ b/include/chaiscript/dispatchkit/any.hpp @@ -42,6 +42,7 @@ namespace chaiscript { private: struct Data { + virtual ~Data() {} virtual void *data() = 0; virtual const std::type_info &type() const = 0; virtual std::shared_ptr clone() const = 0; @@ -56,6 +57,8 @@ namespace chaiscript { { } + virtual ~Data_Impl() {} + virtual void *data() { return &m_data; @@ -94,9 +97,9 @@ namespace chaiscript { } template - Any(const ValueType &t_value) + Any(const ValueType &t_value) + : m_data(std::shared_ptr(new Data_Impl(t_value))) { - m_data = std::shared_ptr(new Data_Impl(t_value)); } Any & operator=(const Any &t_any) diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 6abc3aaa..d5de8556 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -39,6 +39,7 @@ namespace chaiscript { public: virtual ~Proxy_Function_Base() {} + Boxed_Value operator()(const std::vector ¶ms, const chaiscript::Dynamic_Cast_Conversions &t_conversions) const { Boxed_Value bv = do_call(params, t_conversions); @@ -205,6 +206,8 @@ namespace chaiscript { } + virtual ~Dynamic_Proxy_Function() {} + virtual bool operator==(const Proxy_Function_Base &rhs) const { const Dynamic_Proxy_Function *prhs = dynamic_cast(&rhs); @@ -221,9 +224,6 @@ namespace chaiscript && test_guard(vals, t_conversions); } - virtual ~Dynamic_Proxy_Function() {} - - virtual int get_arity() const { return m_arity; From 8b134c65d1d280e42a28f1059c3e7b11f192ac84 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 10 Mar 2014 14:16:56 -0600 Subject: [PATCH 101/108] Add travis script for automated testing --- .travis.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..35235e12 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: cpp +compiler: + - gcc + - clang +script: + - mkdir build + - cd build + - cmake ../build + - make test +notifications: + recipients: + - jason@emptycrate.com + email: + on_success: always + on_failure: always + From 385465cf3f606cfd0e6d213845f4883deb285f96 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 10 Mar 2014 15:05:54 -0600 Subject: [PATCH 102/108] Update readme.md --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index a82f9162..2bd07cea 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/ChaiScript/ChaiScript.png?branch=ChaiScript_5_0_CPP_11)](https://travis-ci.org/ChaiScript/ChaiScript) + ChaiScript http://www.chaiscript.com From 593ce462f7f329dafe7e09c905fa28a3deb3fcc8 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 22 Mar 2014 16:24:16 -0600 Subject: [PATCH 103/108] Re-enable C++11 registration utility The latest VisualStudio 2013 CTP2 sworks with this now. Be sure to install it to build chaiscript --- include/chaiscript/utility/utility.hpp | 4 +-- src/reflection.cpp | 44 +++++--------------------- 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/include/chaiscript/utility/utility.hpp b/include/chaiscript/utility/utility.hpp index 7f5b6c01..262ae1ab 100644 --- a/include/chaiscript/utility/utility.hpp +++ b/include/chaiscript/utility/utility.hpp @@ -17,7 +17,7 @@ namespace chaiscript { /// \todo Use of this utility, and uniform initializer lists, is causing memory errors in MSVC - /* + template void add_class(ModuleType &t_module, const std::string &t_classname, @@ -37,7 +37,7 @@ namespace chaiscript } } - */ + } } diff --git a/src/reflection.cpp b/src/reflection.cpp index 7f9f31f0..cb369f25 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -73,26 +73,15 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect chaiscript::bootstrap::standard_library::vector_type > >("AST_NodeVector", m); using namespace chaiscript; - - m->add(chaiscript::user_type(), "eval_error"); - m->add(chaiscript::fun(&chaiscript::exception::eval_error::reason), "reason"); - m->add(chaiscript::fun(&chaiscript::exception::eval_error::call_stack), "call_stack"); - /* + chaiscript::utility::add_class(*m, "eval_error", { }, { {fun(&chaiscript::exception::eval_error::reason), "reason"}, {fun(&chaiscript::exception::eval_error::call_stack), "call_stack"} } ); - */ - - m->add(chaiscript::user_type(), "File_Position"); - m->add(chaiscript::constructor(), "File_Position"); - m->add(chaiscript::constructor(), "File_Position"); - m->add(chaiscript::fun(&File_Position::line), "line"); - m->add(chaiscript::fun(&File_Position::column), "column"); - - /* + + chaiscript::utility::add_class(*m, "File_Position", { constructor(), @@ -100,19 +89,8 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect { {fun(&File_Position::line), "line"}, {fun(&File_Position::column), "column"} } ); - */ - - m->add(chaiscript::user_type(), "AST_Node"); - m->add(chaiscript::fun(&AST_Node::text), "text"); - m->add(chaiscript::fun(&AST_Node::identifier), "identifier"); - m->add(chaiscript::fun(&AST_Node::filename), "filename"); - m->add(chaiscript::fun(&AST_Node::start), "start"); - m->add(chaiscript::fun(&AST_Node::end), "end"); - m->add(chaiscript::fun(&AST_Node::internal_to_string), "internal_to_string"); - m->add(chaiscript::fun(&AST_Node::children), "children"); - m->add(chaiscript::fun(&AST_Node::replace_child), "replace_child"); - - /* + + chaiscript::utility::add_class(*m, "AST_Node", { }, @@ -126,21 +104,15 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect {fun(&AST_Node::replace_child), "replace_child"} } ); - */ - - m->add(chaiscript::user_type(), "ChaiScript_Parser"); - m->add(chaiscript::constructor(), "ChaiScript_Parser"); - m->add(chaiscript::fun(&parser::ChaiScript_Parser::parse), "parse"); - m->add(chaiscript::fun(&parser::ChaiScript_Parser::ast), "ast"); - - /* + + chaiscript::utility::add_class(*m, "ChaiScript_Parser", { constructor() }, { {fun(&parser::ChaiScript_Parser::parse), "parse"}, {fun(&parser::ChaiScript_Parser::ast), "ast"} } ); - */ + return m; From bf0737a35cb6140ca3d667fc6ed72f15eee15a97 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 23 Mar 2014 16:42:04 -0600 Subject: [PATCH 104/108] Cleanup search for chaiscript_stdlib and fix some bugs --- CMakeLists.txt | 26 +++++++--- .../chaiscript/language/chaiscript_engine.hpp | 36 ++++++------- src/main.cpp | 50 ++++++++++++------- 3 files changed, 69 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88574666..7c5ea5c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,12 @@ else() option(MULTITHREAD_SUPPORT_ENABLED "Multithreaded Support Enabled" TRUE) endif() +if (CMAKE_COMPILER_IS_GNUCC) + option(ENABLE_COVERAGE "Enable Coverage Reporting in GCC" FALSE) +endif() + + + option(BUILD_MODULES "Build Extra Modules (stl, reflection)" TRUE) option(BUILD_SAMPLES "Build Samples Folder" FALSE) @@ -70,17 +76,24 @@ else(READLINE_LIBRARY) set (READLINE_FLAG ) endif(READLINE_LIBRARY) +SET(EXTRA_LINKER_FLAGS "") if (CMAKE_COMPILER_IS_GNUCC) - execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion - OUTPUT_VARIABLE GCC_VERSION) - + execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) if (GCC_VERSION VERSION_LESS 4.8) SET(CPP11_FLAG "-std=c++0x") else() SET(CPP11_FLAG "-std=c++11") endif() + + if (ENABLE_COVERAGE) + add_definitions(-fprofile-arcs -ftest-coverage) + SET(EXTRA_LINKER_FLAGS ${EXTRA_LINKER_FLAGS} "-fprofile-arcs -ftest-coverage") + # SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "-fprofile-arcs -ftest-coverage") + endif() + + else() SET(CPP11_FLAG "-std=c++11") endif() @@ -105,17 +118,16 @@ else() endif() if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - option(USE_LIBCXX "Use clang's libcxx" TRUE) if (USE_LIBCXX) add_definitions(-stdlib=libc++) - set (EXTRA_LINKER_FLAGS ${CPP11_FLAG} -stdlib=libc++) + set (EXTRA_LINKER_FLAGS ${EXTRA_LINKER_FLAGS} ${CPP11_FLAG} -stdlib=libc++) else () - set (EXTRA_LINKER_FLAGS ${CPP11_FLAG}) + set (EXTRA_LINKER_FLAGS ${EXTRA_LINKER_FLAGS} ${CPP11_FLAG}) endif() elseif(CMAKE_COMPILER_IS_GNUCC) - set (EXTRA_LINKER_FLAGS ${CPP11_FLAG}) + set (EXTRA_LINKER_FLAGS ${EXTRA_LINKER_FLAGS} ${CPP11_FLAG}) endif() # limitations in MinGW require us to make an optimized build diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index ff37d566..58d48f0a 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -337,7 +337,7 @@ namespace chaiscript m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_type_name, std::ref(m_engine)), "name"); - typedef void (ChaiScript::*load_mod_1)(const std::string&); + typedef std::string (ChaiScript::*load_mod_1)(const std::string&); typedef void (ChaiScript::*load_mod_2)(const std::string&, const std::string&); m_engine.add(fun(static_cast(&ChaiScript::load_module), this), "load_module"); @@ -449,7 +449,7 @@ namespace chaiscript dllpath = std::string(&buf.front(), pathlen); } - m_modulepaths.push_back(dllpath+"/"); + m_modulepaths.insert(m_modulepaths.begin(), dllpath+"/"); } #endif @@ -652,7 +652,7 @@ namespace chaiscript /// (the symbol mentioned above), an exception is thrown. /// /// \throw chaiscript::exception::load_module_error In the event that no matching module can be found. - void load_module(const std::string &t_module_name) + std::string load_module(const std::string &t_module_name) { std::vector errors; @@ -665,23 +665,25 @@ namespace chaiscript postfixes.push_back(".so"); postfixes.push_back(""); - for (size_t i = 0; i < m_modulepaths.size(); ++i) + for (size_t i = 0; i < m_modulepaths.size(); ++i) + { + for (size_t j = 0; j < prefixes.size(); ++j) { - for (size_t j = 0; j < prefixes.size(); ++j) - { - for (size_t k = 0; k < postfixes.size(); ++k) - { - try { - std::string name = m_modulepaths[i] + prefixes[j] + t_module_name + postfixes[k]; - load_module(t_module_name, name); - return; - } catch (const chaiscript::exception::load_module_error &e) { - errors.push_back(e); - // Try next set - } - } + for (size_t k = 0; k < postfixes.size(); ++k) + { + try { + std::string name = m_modulepaths[i] + prefixes[j] + t_module_name + postfixes[k]; + // std::cerr << "trying location: " << name << std::endl; + load_module(t_module_name, name); + return name; + } catch (const chaiscript::exception::load_module_error &e) { + // std::cerr << "error: " << e.what() << std::endl; + errors.push_back(e); + // Try next set } + } } + } std::string errstring; diff --git a/src/main.cpp b/src/main.cpp index d633c76f..c8d98e71 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,11 +43,11 @@ void using_history(){} -void *cast_module_symbol(std::string (*t_path)()) +void *cast_module_symbol(std::vector (*t_path)()) { union cast_union { - std::string (*in_ptr)(); + std::vector (*in_ptr)(); void *out_ptr; }; @@ -56,22 +56,27 @@ void *cast_module_symbol(std::string (*t_path)()) return c.out_ptr; } -std::string default_search_path() +std::vector default_search_paths() { + std::vector paths; + #ifdef CHAISCRIPT_WINDOWS // force no unicode CHAR path[4096]; int size = GetModuleFileNameA(0, path, sizeof(path)-1); std::string exepath(path, size); - size_t secondtolastslash = exepath.rfind('\\', exepath.rfind('\\') - 1); - if (secondtolastslash != std::string::npos) + size_t lastslash = exepath.rfind('\\'); + size_t secondtolastslash = exepath.rfind('\\', lastslash - 1); + if (lastslash != std::string::npos) { - return exepath.substr(0, secondtolastslash) + "\\lib\\chaiscript\\"; - } else { - return ""; + paths.push_back(exepath.substr(0, lastslash)); } + if (secondtolastslash != std::string::npos) + { + return {exepath.substr(0, secondtolastslash) + "\\lib\\chaiscript\\"}; + } #else std::string exepath; @@ -102,23 +107,30 @@ std::string default_search_path() if (exepath.empty()) { - Dl_info rInfo; + Dl_info rInfo; memset( &rInfo, 0, sizeof(rInfo) ); - if ( !dladdr(cast_module_symbol(&default_search_path), &rInfo) || !rInfo.dli_fname ) { - return ""; + if ( !dladdr(cast_module_symbol(&default_search_paths), &rInfo) || !rInfo.dli_fname ) { + return paths; } exepath = std::string(rInfo.dli_fname); } - size_t secondtolastslash = exepath.rfind('/', exepath.rfind('/') - 1); + size_t lastslash = exepath.rfind('/'); + + size_t secondtolastslash = exepath.rfind('/', lastslash - 1); + if (lastslash != std::string::npos) + { + paths.push_back(exepath.substr(0, lastslash)); + } + if (secondtolastslash != std::string::npos) { - return exepath.substr(0, secondtolastslash) + "/lib/chaiscript/"; - } else { - return ""; + paths.push_back(exepath.substr(0, secondtolastslash) + "/lib/chaiscript/"); } #endif + + return paths; } void help(int n) { @@ -239,8 +251,6 @@ void interactive(chaiscript::ChaiScript& chai) int main(int argc, char *argv[]) { - std::vector usepaths; - std::vector modulepaths; // Disable deprecation warning for getenv call. #ifdef CHAISCRIPT_MSVC @@ -255,14 +265,16 @@ int main(int argc, char *argv[]) #pragma warning(pop) #endif + std::vector usepaths; usepaths.push_back(""); if (usepath) { usepaths.push_back(usepath); } - std::string searchpath = default_search_path(); - modulepaths.push_back(searchpath); + std::vector modulepaths; + std::vector searchpaths = default_search_paths(); + modulepaths.insert(modulepaths.end(), searchpaths.begin(), searchpaths.end()); modulepaths.push_back(""); if (modulepath) { From a1fc7416e143ae95fa5c7d36f62b1e07cff061d6 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 23 Mar 2014 16:51:32 -0600 Subject: [PATCH 105/108] Update travis to also push coverage results --- .travis.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 78fa6bd2..b79aeaba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,13 @@ -language: cpp +language: cpp clang compiler: - gcc +before_install: + - sudo pip install cpp-coveralls --use-mirrors script: - - mkdir build - - cd build - - cmake ../ + - cmake -D ENABLE_COVERAGE:BOOL=TRUE -D CMAKE_BUILD_TYPE:STRING=Debug -D UNIT_TEST_LIGHT:BOOL=TRUE -D USE_LIBCXX:BOOL=FALSE . - make - make test + - coverall -x hpp notifications: recipients: - jason@emptycrate.com From 782c3040cc17aeb04ca257ffcc6133cefd4ee26a Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 23 Mar 2014 18:42:17 -0600 Subject: [PATCH 106/108] Add badge display for coveralls status, update travis --- .travis.yml | 7 ++++--- CMakeLists.txt | 6 +++--- readme.md | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index b79aeaba..511be7ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,14 @@ -language: cpp clang +language: cpp compiler: - gcc + - clang before_install: - sudo pip install cpp-coveralls --use-mirrors script: - - cmake -D ENABLE_COVERAGE:BOOL=TRUE -D CMAKE_BUILD_TYPE:STRING=Debug -D UNIT_TEST_LIGHT:BOOL=TRUE -D USE_LIBCXX:BOOL=FALSE . + - cmake -D ENABLE_COVERAGE:BOOL=TRUE -D CMAKE_BUILD_TYPE:STRING=Debug -D USE_LIBCXX:BOOL=FALSE . - make - make test - - coverall -x hpp + - coveralls -x hpp notifications: recipients: - jason@emptycrate.com diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c5ea5c7..6626fc0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,9 +218,9 @@ if(BUILD_TESTING) if (NOT UNIT_TEST_LIGHT) # commented out because uniform initializer syntax is not working properly in MSVC 2013 - #add_executable(utility_test unittests/utility_test.cpp) - #target_link_libraries(utility_test ${LIBS} ${EXTRA_LINKER_FLAGS}) - #add_test(NAME Utility_Test COMMAND utility_test) + add_executable(utility_test unittests/utility_test.cpp) + target_link_libraries(utility_test ${LIBS} ${EXTRA_LINKER_FLAGS}) + add_test(NAME Utility_Test COMMAND utility_test) add_executable(dynamic_object_test unittests/dynamic_object_test.cpp) target_link_libraries(dynamic_object_test ${LIBS} ${EXTRA_LINKER_FLAGS}) diff --git a/readme.md b/readme.md index 2bd07cea..a8919e4f 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,5 @@ [![Build Status](https://travis-ci.org/ChaiScript/ChaiScript.png?branch=ChaiScript_5_0_CPP_11)](https://travis-ci.org/ChaiScript/ChaiScript) +[![Coverage Status](https://coveralls.io/repos/ChaiScript/ChaiScript/badge.png?branch=ChaiScript_5_0_CPP_11)](https://coveralls.io/r/ChaiScript/ChaiScript?branch=ChaiScript_5_0_CPP_11) ChaiScript From c021cc931ca6f699b945bcba5574050f4885a8a8 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 23 Mar 2014 18:55:57 -0600 Subject: [PATCH 107/108] Disable travis clang again, it seems to not be up to it --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 511be7ce..dacb8f18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: cpp compiler: - gcc - - clang before_install: - sudo pip install cpp-coveralls --use-mirrors script: From 8d96abe73091c2eb6d5c53a2d94fb5884bbcb5fa Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 24 Mar 2014 14:09:20 -0600 Subject: [PATCH 108/108] Fix test for overload registration with add_class utility --- .../dispatchkit/register_function.hpp | 36 ++++++++++--------- unittests/utility_test.cpp | 9 +++-- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index 5dfdeed2..c1993b39 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -73,23 +73,6 @@ namespace chaiscript } } - /// \brief Creates a new Proxy_Function object from a std::function object - /// \param[in] f std::function to expose to ChaiScript - /// - /// \b Example: - /// \code - /// std::function f = get_some_function(); - /// chaiscript::ChaiScript chai; - /// chai.add(fun(f), "some_function"); - /// \endcode - /// - /// \sa \ref addingfunctions - template - Proxy_Function fun(const std::function &f) - { - return Proxy_Function(new dispatch::Proxy_Function_Impl(f)); - } - /// \brief Creates a new Proxy_Function object from a free function, member function or data member /// \param[in] t Function / member to expose /// @@ -116,6 +99,25 @@ namespace chaiscript return dispatch::detail::Fun_Helper::value>::go(t); } + + /// \brief Creates a new Proxy_Function object from a std::function object + /// \param[in] f std::function to expose to ChaiScript + /// + /// \b Example: + /// \code + /// std::function f = get_some_function(); + /// chaiscript::ChaiScript chai; + /// chai.add(fun(f), "some_function"); + /// \endcode + /// + /// \sa \ref addingfunctions + template + Proxy_Function fun(const std::function &f) + { + return Proxy_Function(new dispatch::Proxy_Function_Impl(f)); + } + + /// \brief Creates a new Proxy_Function object from a free function, member function or data member and binds the first parameter of it /// \param[in] t Function / member to expose /// \param[in] q Value to bind to first parameter diff --git a/unittests/utility_test.cpp b/unittests/utility_test.cpp index b611fd63..12796588 100644 --- a/unittests/utility_test.cpp +++ b/unittests/utility_test.cpp @@ -1,5 +1,7 @@ +#include #include #include +#include class Test { @@ -18,6 +20,7 @@ int main() using namespace chaiscript; + /// \todo fix overload resolution for fun<> chaiscript::utility::add_class(*m, "Test", { constructor(), @@ -25,9 +28,9 @@ int main() { {fun(&Test::function), "function"}, {fun(&Test::function2), "function2"}, {fun(&Test::function3), "function3"}, - {fun(&Test::functionOverload), "functionOverload"}, - {fun(&Test::functionOverload), "functionOverload"}, - {fun(&Test::operator=), "="} + {fun(static_cast(&Test::functionOverload)), "functionOverload" }, + {fun(static_cast(&Test::functionOverload)), "functionOverload" }, + {fun(static_cast(&Test::operator=)), "=" } } );