Merge branch 'smaller_make_shared' into develop

This commit is contained in:
Jason Turner 2015-04-29 16:58:34 -06:00
commit 3e5034ecf8
25 changed files with 198 additions and 220 deletions

View File

@ -23,7 +23,13 @@ endif()
option(BUILD_MODULES "Build Extra Modules (stl)" TRUE) option(BUILD_MODULES "Build Extra Modules (stl)" TRUE)
option(BUILD_SAMPLES "Build Samples Folder" FALSE) option(BUILD_SAMPLES "Build Samples Folder" FALSE)
option(USE_STD_MAKE_SHARED "Use std::make_shared instead of chaiscript::make_shared" FALSE)
mark_as_advanced(USE_STD_MAKE_SHARED)
if(USE_STD_MAKE_SHARED)
add_definitions(-DCHAISCRIPT_USE_STD_MAKE_SHARED)
endif()
if(CMAKE_COMPILER_IS_GNUCC) if(CMAKE_COMPILER_IS_GNUCC)
option(ENABLE_COVERAGE "Enable Coverage Reporting in GCC" FALSE) option(ENABLE_COVERAGE "Enable Coverage Reporting in GCC" FALSE)
@ -278,8 +284,6 @@ if(BUILD_TESTING)
get_target_property(target_files ${executable} SOURCES) get_target_property(target_files ${executable} SOURCES)
message("Files: ${target_files}")
foreach(source ${target_files}) foreach(source ${target_files})
if(NOT "${source}" MATCHES "/moc_.*cxx") if(NOT "${source}" MATCHES "/moc_.*cxx")
string(REGEX MATCH .*cpp source "${source}") string(REGEX MATCH .*cpp source "${source}")
@ -287,7 +291,6 @@ if(BUILD_TESTING)
file(READ "${source}" contents) file(READ "${source}" contents)
string(REGEX MATCHALL "TEST_CASE\\([ ]*\"[^\"]+\"" found_tests ${contents}) string(REGEX MATCHALL "TEST_CASE\\([ ]*\"[^\"]+\"" found_tests ${contents})
foreach(hit ${found_tests}) foreach(hit ${found_tests})
message("Found Test: ${hit}")
string(REGEX REPLACE "TEST_CASE\\([ ]*(\"[^\"]+\").*" "\\1" test_name ${hit}) string(REGEX REPLACE "TEST_CASE\\([ ]*(\"[^\"]+\").*" "\\1" test_name ${hit})
add_test(${test_name} "${executable}" ${test_name}) add_test(${test_name} "${executable}" ${test_name})
set_tests_properties(${test_name} PROPERTIES TIMEOUT 660 ENVIRONMENT "PATH=${NEWPATH}") set_tests_properties(${test_name} PROPERTIES TIMEOUT 660 ENVIRONMENT "PATH=${NEWPATH}")

View File

@ -52,11 +52,23 @@
#define CHAISCRIPT_CONSTEXPR constexpr #define CHAISCRIPT_CONSTEXPR constexpr
#endif #endif
#include <memory>
namespace chaiscript { namespace chaiscript {
static const int version_major = 5; static const int version_major = 5;
static const int version_minor = 7; static const int version_minor = 7;
static const int version_patch = 0; static const int version_patch = 0;
}
template<typename B, typename D, typename ...Arg>
inline std::shared_ptr<B> make_shared(Arg && ... arg)
{
#ifdef CHAISCRIPT_USE_STD_MAKE_SHARED
return std::make_shared<D>(std::forward<Arg>(arg)...);
#else
return std::shared_ptr<B>(static_cast<B*>(new D(std::forward<Arg>(arg)...)));
#endif
}
}
#endif #endif

View File

@ -10,14 +10,13 @@
#include <cstdint> #include <cstdint>
#include <exception> #include <exception>
#include <functional> #include <functional>
#include <iostream>
#include <map>
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <vector> #include <vector>
#include <iterator>
#include "bad_boxed_cast.hpp" #include "bad_boxed_cast.hpp"
#include "boxed_cast.hpp" #include "boxed_cast.hpp"
@ -53,7 +52,7 @@ namespace chaiscript
} }
template<typename T, typename = typename std::enable_if<std::is_array<T>::value>::type > template<typename T, typename = typename std::enable_if<std::is_array<T>::value>::type >
ModulePtr array(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr array(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
typedef typename std::remove_extent<T>::type ReturnType; typedef typename std::remove_extent<T>::type ReturnType;
const auto extent = std::extent<T>::value; const auto extent = std::extent<T>::value;
@ -95,7 +94,7 @@ namespace chaiscript
/// \tparam T The type to add a copy constructor for /// \tparam T The type to add a copy constructor for
/// \returns The passed in ModulePtr, or the newly constructed one if the default param is used /// \returns The passed in ModulePtr, or the newly constructed one if the default param is used
template<typename T> template<typename T>
ModulePtr copy_constructor(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr copy_constructor(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
m->add(constructor<T (const T &)>(), type); m->add(constructor<T (const T &)>(), type);
return m; return m;
@ -106,7 +105,7 @@ namespace chaiscript
/// \param[in,out] m module to add comparison operators to /// \param[in,out] m module to add comparison operators to
/// \returns the passed in ModulePtr or the newly constructed one if the default params are used. /// \returns the passed in ModulePtr or the newly constructed one if the default params are used.
template<typename T> template<typename T>
ModulePtr opers_comparison(ModulePtr m = ModulePtr(new Module())) ModulePtr opers_comparison(ModulePtr m = std::make_shared<Module>())
{ {
operators::equal<T>(m); operators::equal<T>(m);
operators::greater_than<T>(m); operators::greater_than<T>(m);
@ -127,7 +126,7 @@ namespace chaiscript
/// \sa copy_constructor /// \sa copy_constructor
/// \sa constructor /// \sa constructor
template<typename T> template<typename T>
ModulePtr basic_constructors(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr basic_constructors(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
m->add(constructor<T ()>(), type); m->add(constructor<T ()>(), type);
copy_constructor<T>(type, m); copy_constructor<T>(type, m);
@ -139,7 +138,7 @@ namespace chaiscript
/// \param[in] type The name of the type /// \param[in] type The name of the type
/// \param[in,out] m The Module to add the constructor to /// \param[in,out] m The Module to add the constructor to
template<typename T> template<typename T>
ModulePtr construct_pod(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr construct_pod(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
m->add(fun(&detail::construct_pod<T>), type); m->add(fun(&detail::construct_pod<T>), type);
return m; return m;
@ -170,7 +169,7 @@ namespace chaiscript
/// Add all common functions for a POD type. All operators, and /// Add all common functions for a POD type. All operators, and
/// common conversions /// common conversions
template<typename T> template<typename T>
ModulePtr bootstrap_pod_type(const std::string &name, ModulePtr m = ModulePtr(new Module())) ModulePtr bootstrap_pod_type(const std::string &name, ModulePtr m = std::make_shared<Module>())
{ {
m->add(user_type<T>(), name); m->add(user_type<T>(), name);
m->add(constructor<T()>(), name); m->add(constructor<T()>(), name);
@ -251,7 +250,7 @@ namespace chaiscript
/// Add all arithmetic operators for PODs /// Add all arithmetic operators for PODs
static void opers_arithmetic_pod(ModulePtr m = ModulePtr(new Module())) static void opers_arithmetic_pod(ModulePtr m = std::make_shared<Module>())
{ {
m->add(fun(&Boxed_Number::equals), "=="); m->add(fun(&Boxed_Number::equals), "==");
m->add(fun(&Boxed_Number::less_than), "<"); m->add(fun(&Boxed_Number::less_than), "<");
@ -390,7 +389,7 @@ namespace chaiscript
/// \brief perform all common bootstrap functions for std::string, void and POD types /// \brief perform all common bootstrap functions for std::string, void and POD types
/// \param[in,out] m Module to add bootstrapped functions to /// \param[in,out] m Module to add bootstrapped functions to
/// \returns passed in ModulePtr, or newly created one if default argument is used /// \returns passed in ModulePtr, or newly created one if default argument is used
static ModulePtr bootstrap(ModulePtr m = ModulePtr(new Module())) static ModulePtr bootstrap(ModulePtr m = std::make_shared<Module>())
{ {
m->add(user_type<void>(), "void"); m->add(user_type<void>(), "void");
m->add(user_type<bool>(), "bool"); m->add(user_type<bool>(), "bool");
@ -498,7 +497,7 @@ namespace chaiscript
m->add(fun(&print), "print_string"); m->add(fun(&print), "print_string");
m->add(fun(&println), "println_string"); m->add(fun(&println), "println_string");
m->add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(&bind_function)), "bind"); m->add(chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Dynamic_Proxy_Function>(&bind_function), "bind");
m->add(fun(&shared_ptr_unconst_clone<dispatch::Proxy_Function_Base>), "clone"); m->add(fun(&shared_ptr_unconst_clone<dispatch::Proxy_Function_Base>), "clone");
m->add(fun(&ptr_assign<std::remove_const<dispatch::Proxy_Function_Base>::type>), "="); m->add(fun(&ptr_assign<std::remove_const<dispatch::Proxy_Function_Base>::type>), "=");

View File

@ -14,10 +14,8 @@
#define CHAISCRIPT_BOOTSTRAP_STL_HPP_ #define CHAISCRIPT_BOOTSTRAP_STL_HPP_
#include <functional> #include <functional>
#include <iterator>
#include <memory> #include <memory>
#include <stdexcept> #include <stdexcept>
#include <string>
#include <typeinfo> #include <typeinfo>
#include <vector> #include <vector>
@ -179,7 +177,7 @@ namespace chaiscript
/// Add Bidir_Range support for the given ContainerType /// Add Bidir_Range support for the given ContainerType
template<typename Bidir_Type> template<typename Bidir_Type>
ModulePtr input_range_type_impl(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr input_range_type_impl(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
m->add(user_type<Bidir_Type>(), type + "_Range"); m->add(user_type<Bidir_Type>(), type + "_Range");
@ -232,7 +230,7 @@ namespace chaiscript
} }
template<typename ContainerType> template<typename ContainerType>
ModulePtr input_range_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr input_range_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
detail::input_range_type_impl<Bidir_Range<ContainerType> >(type,m); detail::input_range_type_impl<Bidir_Range<ContainerType> >(type,m);
detail::input_range_type_impl<Const_Bidir_Range<ContainerType> >("Const_" + type, m); detail::input_range_type_impl<Const_Bidir_Range<ContainerType> >("Const_" + type, m);
@ -243,7 +241,7 @@ namespace chaiscript
/// Add random_access_container concept to the given ContainerType /// Add random_access_container concept to the given ContainerType
/// http://www.sgi.com/tech/stl/RandomAccessContainer.html /// http://www.sgi.com/tech/stl/RandomAccessContainer.html
template<typename ContainerType> template<typename ContainerType>
ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
{ {
// cppcheck-suppress syntaxError // cppcheck-suppress syntaxError
typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t); typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t);
@ -266,7 +264,7 @@ namespace chaiscript
/// Add assignable concept to the given ContainerType /// Add assignable concept to the given ContainerType
/// http://www.sgi.com/tech/stl/Assignable.html /// http://www.sgi.com/tech/stl/Assignable.html
template<typename ContainerType> template<typename ContainerType>
ModulePtr assignable_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr assignable_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
copy_constructor<ContainerType>(type, m); copy_constructor<ContainerType>(type, m);
operators::assign<ContainerType>(m); operators::assign<ContainerType>(m);
@ -277,7 +275,7 @@ namespace chaiscript
/// Add container concept to the given ContainerType /// Add container concept to the given ContainerType
/// http://www.sgi.com/tech/stl/Container.html /// http://www.sgi.com/tech/stl/Container.html
template<typename ContainerType> template<typename ContainerType>
ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) ModulePtr container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
{ {
m->add(fun<size_t (const ContainerType *)>([](const ContainerType *a) { return a->size(); } ), "size"); m->add(fun<size_t (const ContainerType *)>([](const ContainerType *a) { return a->size(); } ), "size");
m->add(fun<bool (const ContainerType *)>([](const ContainerType *a) { return a->empty(); } ), "empty"); m->add(fun<bool (const ContainerType *)>([](const ContainerType *a) { return a->empty(); } ), "empty");
@ -289,7 +287,7 @@ namespace chaiscript
/// Add default constructable concept to the given Type /// Add default constructable concept to the given Type
/// http://www.sgi.com/tech/stl/DefaultConstructible.html /// http://www.sgi.com/tech/stl/DefaultConstructible.html
template<typename Type> template<typename Type>
ModulePtr default_constructible_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr default_constructible_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
m->add(constructor<Type ()>(), type); m->add(constructor<Type ()>(), type);
return m; return m;
@ -301,7 +299,7 @@ namespace chaiscript
/// Add sequence concept to the given ContainerType /// Add sequence concept to the given ContainerType
/// http://www.sgi.com/tech/stl/Sequence.html /// http://www.sgi.com/tech/stl/Sequence.html
template<typename ContainerType> template<typename ContainerType>
ModulePtr sequence_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) ModulePtr sequence_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
{ {
m->add(fun(&detail::insert_at<ContainerType>), m->add(fun(&detail::insert_at<ContainerType>),
[]()->std::string{ []()->std::string{
@ -321,7 +319,7 @@ namespace chaiscript
/// Add back insertion sequence concept to the given ContainerType /// Add back insertion sequence concept to the given ContainerType
/// http://www.sgi.com/tech/stl/BackInsertionSequence.html /// http://www.sgi.com/tech/stl/BackInsertionSequence.html
template<typename ContainerType> template<typename ContainerType>
ModulePtr back_insertion_sequence_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) ModulePtr back_insertion_sequence_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
{ {
typedef typename ContainerType::reference (ContainerType::*backptr)(); typedef typename ContainerType::reference (ContainerType::*backptr)();
@ -347,7 +345,7 @@ namespace chaiscript
/// Front insertion sequence /// Front insertion sequence
/// http://www.sgi.com/tech/stl/FrontInsertionSequence.html /// http://www.sgi.com/tech/stl/FrontInsertionSequence.html
template<typename ContainerType> template<typename ContainerType>
ModulePtr front_insertion_sequence_type(const std::string &, ModulePtr m = ModulePtr(new Module())) ModulePtr front_insertion_sequence_type(const std::string &, ModulePtr m = std::make_shared<Module>())
{ {
typedef typename ContainerType::reference (ContainerType::*front_ptr)(); typedef typename ContainerType::reference (ContainerType::*front_ptr)();
typedef typename ContainerType::const_reference (ContainerType::*const_front_ptr)() const; typedef typename ContainerType::const_reference (ContainerType::*const_front_ptr)() const;
@ -374,7 +372,7 @@ namespace chaiscript
/// bootstrap a given PairType /// bootstrap a given PairType
/// http://www.sgi.com/tech/stl/pair.html /// http://www.sgi.com/tech/stl/pair.html
template<typename PairType> template<typename PairType>
ModulePtr pair_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr pair_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
m->add(user_type<PairType>(), type); m->add(user_type<PairType>(), type);
@ -397,7 +395,7 @@ namespace chaiscript
/// http://www.sgi.com/tech/stl/PairAssociativeContainer.html /// http://www.sgi.com/tech/stl/PairAssociativeContainer.html
template<typename ContainerType> template<typename ContainerType>
ModulePtr pair_associative_container_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr pair_associative_container_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
pair_type<typename ContainerType::value_type>(type + "_Pair", m); pair_type<typename ContainerType::value_type>(type + "_Pair", m);
@ -408,7 +406,7 @@ namespace chaiscript
/// Add unique associative container concept to the given ContainerType /// Add unique associative container concept to the given ContainerType
/// http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html /// http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html
template<typename ContainerType> template<typename ContainerType>
ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
{ {
m->add(fun(detail::count<ContainerType>), "count"); m->add(fun(detail::count<ContainerType>), "count");
@ -435,7 +433,7 @@ namespace chaiscript
/// Add a MapType container /// Add a MapType container
/// http://www.sgi.com/tech/stl/Map.html /// http://www.sgi.com/tech/stl/Map.html
template<typename MapType> template<typename MapType>
ModulePtr map_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr map_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
m->add(user_type<MapType>(), type); m->add(user_type<MapType>(), type);
@ -457,7 +455,7 @@ namespace chaiscript
/// hopefully working List type /// hopefully working List type
/// http://www.sgi.com/tech/stl/List.html /// http://www.sgi.com/tech/stl/List.html
template<typename ListType> template<typename ListType>
ModulePtr list_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr list_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
m->add(user_type<ListType>(), type); m->add(user_type<ListType>(), type);
@ -476,7 +474,7 @@ namespace chaiscript
/// Create a vector type with associated concepts /// Create a vector type with associated concepts
/// http://www.sgi.com/tech/stl/Vector.html /// http://www.sgi.com/tech/stl/Vector.html
template<typename VectorType> template<typename VectorType>
ModulePtr vector_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr vector_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
m->add(user_type<VectorType>(), type); m->add(user_type<VectorType>(), type);
@ -525,7 +523,7 @@ namespace chaiscript
/// Add a String container /// Add a String container
/// http://www.sgi.com/tech/stl/basic_string.html /// http://www.sgi.com/tech/stl/basic_string.html
template<typename String> template<typename String>
ModulePtr string_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr string_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
m->add(user_type<String>(), type); m->add(user_type<String>(), type);
operators::addition<String>(m); operators::addition<String>(m);
@ -575,7 +573,7 @@ namespace chaiscript
/// Add a MapType container /// Add a MapType container
/// http://www.sgi.com/tech/stl/Map.html /// http://www.sgi.com/tech/stl/Map.html
template<typename FutureType> template<typename FutureType>
ModulePtr future_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) ModulePtr future_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
{ {
m->add(user_type<FutureType>(), type); m->add(user_type<FutureType>(), type);

View File

@ -7,10 +7,7 @@
#ifndef CHAISCRIPT_BOXED_CAST_HPP_ #ifndef CHAISCRIPT_BOXED_CAST_HPP_
#define CHAISCRIPT_BOXED_CAST_HPP_ #define CHAISCRIPT_BOXED_CAST_HPP_
#include <type_traits>
#include "../chaiscript_defines.hpp" #include "../chaiscript_defines.hpp"
#include "../chaiscript_threading.hpp"
#include "bad_boxed_cast.hpp" #include "bad_boxed_cast.hpp"
#include "boxed_cast_helper.hpp" #include "boxed_cast_helper.hpp"
#include "boxed_value.hpp" #include "boxed_value.hpp"

View File

@ -7,7 +7,6 @@
#ifndef CHAISCRIPT_BOXED_CAST_HELPER_HPP_ #ifndef CHAISCRIPT_BOXED_CAST_HELPER_HPP_
#define CHAISCRIPT_BOXED_CAST_HELPER_HPP_ #define CHAISCRIPT_BOXED_CAST_HELPER_HPP_
#include <functional>
#include <memory> #include <memory>
#include <type_traits> #include <type_traits>
@ -34,7 +33,7 @@ namespace chaiscript
template<typename Result> template<typename Result>
struct Cast_Helper_Inner struct Cast_Helper_Inner
{ {
typedef typename std::reference_wrapper<typename std::add_const<Result>::type > Result_Type; typedef std::reference_wrapper<typename std::add_const<Result>::type > Result_Type;
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *)
{ {
@ -112,9 +111,9 @@ namespace chaiscript
/// Cast_Helper_Inner for casting to a std::shared_ptr<> type /// Cast_Helper_Inner for casting to a std::shared_ptr<> type
template<typename Result> template<typename Result>
struct Cast_Helper_Inner<typename std::shared_ptr<Result> > struct Cast_Helper_Inner<std::shared_ptr<Result> >
{ {
typedef typename std::shared_ptr<Result> Result_Type; typedef std::shared_ptr<Result> Result_Type;
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *)
{ {
@ -124,9 +123,9 @@ namespace chaiscript
/// Cast_Helper_Inner for casting to a std::shared_ptr<const> type /// Cast_Helper_Inner for casting to a std::shared_ptr<const> type
template<typename Result> template<typename Result>
struct Cast_Helper_Inner<typename std::shared_ptr<const Result> > struct Cast_Helper_Inner<std::shared_ptr<const Result> >
{ {
typedef typename std::shared_ptr<const Result> Result_Type; typedef std::shared_ptr<const Result> Result_Type;
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *)
{ {

View File

@ -26,7 +26,7 @@ namespace chaiscript
{ {
namespace exception namespace exception
{ {
struct arithmetic_error : public std::runtime_error struct arithmetic_error : std::runtime_error
{ {
arithmetic_error(const std::string& reason) : std::runtime_error("Arithmetic error: " + reason) {} arithmetic_error(const std::string& reason) : std::runtime_error("Arithmetic error: " + reason) {}
arithmetic_error(const arithmetic_error &) = default; arithmetic_error(const arithmetic_error &) = default;
@ -60,7 +60,7 @@ namespace chaiscript
{ {
private: private:
template<typename T> template<typename T>
static void check_divide_by_zero(T t, typename std::enable_if<std::is_integral<T>::value>::type* = 0) static void check_divide_by_zero(T t, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr)
{ {
#ifndef CHAISCRIPT_NO_PROTECT_DIVIDEBYZERO #ifndef CHAISCRIPT_NO_PROTECT_DIVIDEBYZERO
if (t == 0) { if (t == 0) {
@ -70,7 +70,7 @@ namespace chaiscript
} }
template<typename T> template<typename T>
static void check_divide_by_zero(T, typename std::enable_if<std::is_floating_point<T>::value>::type* = 0) static void check_divide_by_zero(T, typename std::enable_if<std::is_floating_point<T>::value>::type* = nullptr)
{ {
} }

View File

@ -7,12 +7,10 @@
#ifndef CHAISCRIPT_BOXED_VALUE_HPP_ #ifndef CHAISCRIPT_BOXED_VALUE_HPP_
#define CHAISCRIPT_BOXED_VALUE_HPP_ #define CHAISCRIPT_BOXED_VALUE_HPP_
#include <functional>
#include <map> #include <map>
#include <memory> #include <memory>
#include <type_traits> #include <type_traits>
#include "../chaiscript_threading.hpp"
#include "../chaiscript_defines.hpp" #include "../chaiscript_defines.hpp"
#include "any.hpp" #include "any.hpp"
#include "type_info.hpp" #include "type_info.hpp"

View File

@ -8,10 +8,8 @@
#define CHAISCRIPT_DISPATCHKIT_HPP_ #define CHAISCRIPT_DISPATCHKIT_HPP_
#include <algorithm> #include <algorithm>
#include <cassert>
#include <deque> #include <deque>
#include <iostream> #include <iostream>
#include <iterator>
#include <list> #include <list>
#include <map> #include <map>
#include <memory> #include <memory>

View File

@ -7,19 +7,11 @@
#ifndef CHAISCRIPT_DYNAMIC_OBJECT_HPP_ #ifndef CHAISCRIPT_DYNAMIC_OBJECT_HPP_
#define CHAISCRIPT_DYNAMIC_OBJECT_HPP_ #define CHAISCRIPT_DYNAMIC_OBJECT_HPP_
#include <cassert>
#include <map> #include <map>
#include <memory>
#include <string> #include <string>
#include <typeinfo>
#include <utility> #include <utility>
#include <vector>
#include "../chaiscript_defines.hpp"
#include "boxed_cast.hpp"
#include "boxed_cast_helper.hpp"
#include "boxed_value.hpp" #include "boxed_value.hpp"
#include "type_info.hpp"
namespace chaiscript { namespace chaiscript {
class Type_Conversions; class Type_Conversions;

View File

@ -8,7 +8,6 @@
#define CHAISCRIPT_FUNCTION_CALL_HPP_ #define CHAISCRIPT_FUNCTION_CALL_HPP_
#include <functional> #include <functional>
#include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>

View File

@ -7,7 +7,6 @@
#ifndef CHAISCRIPT_FUNCTION_CALL_DETAIL_HPP_ #ifndef CHAISCRIPT_FUNCTION_CALL_DETAIL_HPP_
#define CHAISCRIPT_FUNCTION_CALL_DETAIL_HPP_ #define CHAISCRIPT_FUNCTION_CALL_DETAIL_HPP_
#include <algorithm>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <string> #include <string>

View File

@ -9,14 +9,11 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <stdexcept>
#include <string> #include <string>
#include <vector>
#include <type_traits> #include <type_traits>
#include "boxed_number.hpp" #include "boxed_number.hpp"
#include "boxed_value.hpp" #include "boxed_value.hpp"
#include "type_info.hpp"
namespace chaiscript { namespace chaiscript {
class Boxed_Number; class Boxed_Number;

View File

@ -229,231 +229,231 @@ namespace chaiscript
template<typename T> template<typename T>
ModulePtr assign(ModulePtr m = ModulePtr(new Module())) ModulePtr assign(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::assign<T &, const T&>), "="); m->add(chaiscript::fun(&detail::assign<T &, const T&>), "=");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr assign_bitwise_and(ModulePtr m = ModulePtr(new Module())) ModulePtr assign_bitwise_and(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::assign_bitwise_and<T &, const T&>), "&="); m->add(chaiscript::fun(&detail::assign_bitwise_and<T &, const T&>), "&=");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr assign_xor(ModulePtr m = ModulePtr(new Module())) ModulePtr assign_xor(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::assign_xor<T &, const T&>), "^="); m->add(chaiscript::fun(&detail::assign_xor<T &, const T&>), "^=");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr assign_bitwise_or(ModulePtr m = ModulePtr(new Module())) ModulePtr assign_bitwise_or(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::assign_bitwise_or<T &, const T&>), "|="); m->add(chaiscript::fun(&detail::assign_bitwise_or<T &, const T&>), "|=");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr assign_difference(ModulePtr m = ModulePtr(new Module())) ModulePtr assign_difference(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::assign_difference<T &, const T&>), "-="); m->add(chaiscript::fun(&detail::assign_difference<T &, const T&>), "-=");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr assign_left_shift(ModulePtr m = ModulePtr(new Module())) ModulePtr assign_left_shift(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::assign_left_shift<T &, const T&>), "<<="); m->add(chaiscript::fun(&detail::assign_left_shift<T &, const T&>), "<<=");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr assign_product(ModulePtr m = ModulePtr(new Module())) ModulePtr assign_product(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::assign_product<T &, const T&>), "*="); m->add(chaiscript::fun(&detail::assign_product<T &, const T&>), "*=");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr assign_quotient(ModulePtr m = ModulePtr(new Module())) ModulePtr assign_quotient(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::assign_quotient<T &, const T&>), "/="); m->add(chaiscript::fun(&detail::assign_quotient<T &, const T&>), "/=");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr assign_remainder(ModulePtr m = ModulePtr(new Module())) ModulePtr assign_remainder(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::assign_remainder<T &, const T&>), "%="); m->add(chaiscript::fun(&detail::assign_remainder<T &, const T&>), "%=");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr assign_right_shift(ModulePtr m = ModulePtr(new Module())) ModulePtr assign_right_shift(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::assign_right_shift<T &, const T&>), ">>="); m->add(chaiscript::fun(&detail::assign_right_shift<T &, const T&>), ">>=");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr assign_sum(ModulePtr m = ModulePtr(new Module())) ModulePtr assign_sum(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::assign_sum<T &, const T&>), "+="); m->add(chaiscript::fun(&detail::assign_sum<T &, const T&>), "+=");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr prefix_decrement(ModulePtr m = ModulePtr(new Module())) ModulePtr prefix_decrement(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::prefix_decrement<T &>), "--"); m->add(chaiscript::fun(&detail::prefix_decrement<T &>), "--");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr prefix_increment(ModulePtr m = ModulePtr(new Module())) ModulePtr prefix_increment(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::prefix_increment<T &>), "++"); m->add(chaiscript::fun(&detail::prefix_increment<T &>), "++");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr equal(ModulePtr m = ModulePtr(new Module())) ModulePtr equal(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::equal<const T&, const T&>), "=="); m->add(chaiscript::fun(&detail::equal<const T&, const T&>), "==");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr greater_than(ModulePtr m = ModulePtr(new Module())) ModulePtr greater_than(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::greater_than<const T&, const T&>), ">"); m->add(chaiscript::fun(&detail::greater_than<const T&, const T&>), ">");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr greater_than_equal(ModulePtr m = ModulePtr(new Module())) ModulePtr greater_than_equal(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::greater_than_equal<const T&, const T&>), ">="); m->add(chaiscript::fun(&detail::greater_than_equal<const T&, const T&>), ">=");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr less_than(ModulePtr m = ModulePtr(new Module())) ModulePtr less_than(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::less_than<const T&, const T&>), "<"); m->add(chaiscript::fun(&detail::less_than<const T&, const T&>), "<");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr less_than_equal(ModulePtr m = ModulePtr(new Module())) ModulePtr less_than_equal(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::less_than_equal<const T&, const T&>), "<="); m->add(chaiscript::fun(&detail::less_than_equal<const T&, const T&>), "<=");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr logical_compliment(ModulePtr m = ModulePtr(new Module())) ModulePtr logical_compliment(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::logical_compliment<const T &>), "!"); m->add(chaiscript::fun(&detail::logical_compliment<const T &>), "!");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr not_equal(ModulePtr m = ModulePtr(new Module())) ModulePtr not_equal(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::not_equal<const T &, const T &>), "!="); m->add(chaiscript::fun(&detail::not_equal<const T &, const T &>), "!=");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr addition(ModulePtr m = ModulePtr(new Module())) ModulePtr addition(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::addition<const T &, const T &>), "+"); m->add(chaiscript::fun(&detail::addition<const T &, const T &>), "+");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr unary_plus(ModulePtr m = ModulePtr(new Module())) ModulePtr unary_plus(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::unary_plus<const T &>), "+"); m->add(chaiscript::fun(&detail::unary_plus<const T &>), "+");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr subtraction(ModulePtr m = ModulePtr(new Module())) ModulePtr subtraction(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::subtraction<const T &, const T &>), "-"); m->add(chaiscript::fun(&detail::subtraction<const T &, const T &>), "-");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr unary_minus(ModulePtr m = ModulePtr(new Module())) ModulePtr unary_minus(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::unary_minus<const T &>), "-"); m->add(chaiscript::fun(&detail::unary_minus<const T &>), "-");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr bitwise_and(ModulePtr m = ModulePtr(new Module())) ModulePtr bitwise_and(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::bitwise_and<const T &, const T &>), "&"); m->add(chaiscript::fun(&detail::bitwise_and<const T &, const T &>), "&");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr bitwise_compliment(ModulePtr m = ModulePtr(new Module())) ModulePtr bitwise_compliment(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::bitwise_compliment<const T &>), "~"); m->add(chaiscript::fun(&detail::bitwise_compliment<const T &>), "~");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr bitwise_xor(ModulePtr m = ModulePtr(new Module())) ModulePtr bitwise_xor(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::bitwise_xor<const T &, const T &>), "^"); m->add(chaiscript::fun(&detail::bitwise_xor<const T &, const T &>), "^");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr bitwise_or(ModulePtr m = ModulePtr(new Module())) ModulePtr bitwise_or(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::bitwise_or<const T &, const T &>), "|"); m->add(chaiscript::fun(&detail::bitwise_or<const T &, const T &>), "|");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr division(ModulePtr m = ModulePtr(new Module())) ModulePtr division(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::division<const T &, const T &>), "/"); m->add(chaiscript::fun(&detail::division<const T &, const T &>), "/");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr left_shift(ModulePtr m = ModulePtr(new Module())) ModulePtr left_shift(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::left_shift<const T &, const T &>), "<<"); m->add(chaiscript::fun(&detail::left_shift<const T &, const T &>), "<<");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr multiplication(ModulePtr m = ModulePtr(new Module())) ModulePtr multiplication(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::multiplication<const T &, const T &>), "*"); m->add(chaiscript::fun(&detail::multiplication<const T &, const T &>), "*");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr remainder(ModulePtr m = ModulePtr(new Module())) ModulePtr remainder(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::remainder<const T &, const T &>), "%"); m->add(chaiscript::fun(&detail::remainder<const T &, const T &>), "%");
return m; return m;
} }
template<typename T> template<typename T>
ModulePtr right_shift(ModulePtr m = ModulePtr(new Module())) ModulePtr right_shift(ModulePtr m = std::make_shared<Module>())
{ {
m->add(chaiscript::fun(&detail::right_shift<const T &, const T &>), ">>"); m->add(chaiscript::fun(&detail::right_shift<const T &, const T &>), ">>");
return m; return m;

View File

@ -9,7 +9,6 @@
#define CHAISCRIPT_PROXY_FUNCTIONS_HPP_ #define CHAISCRIPT_PROXY_FUNCTIONS_HPP_
#include <algorithm>
#include <cassert> #include <cassert>
#include <functional> #include <functional>
#include <memory> #include <memory>
@ -20,7 +19,6 @@
#include "../chaiscript_defines.hpp" #include "../chaiscript_defines.hpp"
#include "boxed_cast.hpp" #include "boxed_cast.hpp"
#include "boxed_cast_helper.hpp"
#include "boxed_value.hpp" #include "boxed_value.hpp"
#include "proxy_functions_detail.hpp" #include "proxy_functions_detail.hpp"
#include "type_info.hpp" #include "type_info.hpp"
@ -582,7 +580,7 @@ namespace chaiscript
} }
protected: protected:
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions &t_conversions) const virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE
{ {
return detail::Do_Call<typename std::function<Func>::result_type>::go(m_f, params, t_conversions); return detail::Do_Call<typename std::function<Func>::result_type>::go(m_f, params, t_conversions);
} }
@ -638,12 +636,12 @@ namespace chaiscript
return m_f.get(); return m_f.get();
} }
virtual void assign(const std::shared_ptr<const Proxy_Function_Base> &t_rhs) { virtual void assign(const std::shared_ptr<const Proxy_Function_Base> &t_rhs) CHAISCRIPT_OVERRIDE {
m_f.get() = dispatch::functor<Func>(t_rhs, nullptr); m_f.get() = dispatch::functor<Func>(t_rhs, nullptr);
} }
protected: protected:
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions &t_conversions) const virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE
{ {
return detail::Do_Call<typename std::function<Func>::result_type>::go(m_f.get(), params, t_conversions); return detail::Do_Call<typename std::function<Func>::result_type>::go(m_f.get(), params, t_conversions);
} }

View File

@ -7,10 +7,8 @@
#ifndef CHAISCRIPT_PROXY_FUNCTIONS_DETAIL_HPP_ #ifndef CHAISCRIPT_PROXY_FUNCTIONS_DETAIL_HPP_
#define CHAISCRIPT_PROXY_FUNCTIONS_DETAIL_HPP_ #define CHAISCRIPT_PROXY_FUNCTIONS_DETAIL_HPP_
#include <algorithm>
#include <functional> #include <functional>
#include <stdexcept> #include <stdexcept>
#include <string>
#include <vector> #include <vector>
#include "../chaiscript_defines.hpp" #include "../chaiscript_defines.hpp"

View File

@ -11,7 +11,6 @@
#include <type_traits> #include <type_traits>
#include "bind_first.hpp" #include "bind_first.hpp"
#include "dispatchkit.hpp"
#include "proxy_functions.hpp" #include "proxy_functions.hpp"
namespace chaiscript namespace chaiscript
@ -90,28 +89,28 @@ namespace chaiscript
Proxy_Function fun(const T &t) Proxy_Function fun(const T &t)
{ {
return Proxy_Function( return Proxy_Function(
static_cast<dispatch::Proxy_Function_Impl_Base *>(new dispatch::Proxy_Function_Impl<typename dispatch::detail::FunctionSignature<decltype(dispatch::detail::to_function(t)) >::Signature>(dispatch::detail::to_function(t)))); chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Proxy_Function_Impl<typename dispatch::detail::FunctionSignature<decltype(dispatch::detail::to_function(t)) >::Signature>>(dispatch::detail::to_function(t)));
} }
template<typename Ret, typename Class, typename ... Param> template<typename Ret, typename Class, typename ... Param>
Proxy_Function fun(Ret (Class::*func)(Param...) const) Proxy_Function fun(Ret (Class::*func)(Param...) const)
{ {
return Proxy_Function( return Proxy_Function(
static_cast<dispatch::Proxy_Function_Impl_Base *>(new dispatch::Proxy_Function_Impl<typename dispatch::detail::FunctionSignature<decltype(dispatch::detail::to_function(func)) >::Signature>(dispatch::detail::to_function(func)))); chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Proxy_Function_Impl<typename dispatch::detail::FunctionSignature<decltype(dispatch::detail::to_function(func)) >::Signature>>(dispatch::detail::to_function(func)));
} }
template<typename Ret, typename Class, typename ... Param> template<typename Ret, typename Class, typename ... Param>
Proxy_Function fun(Ret (Class::*func)(Param...)) Proxy_Function fun(Ret (Class::*func)(Param...))
{ {
return Proxy_Function( return Proxy_Function(
static_cast<dispatch::Proxy_Function_Impl_Base *>(new dispatch::Proxy_Function_Impl<typename dispatch::detail::FunctionSignature<decltype(dispatch::detail::to_function(func)) >::Signature>(dispatch::detail::to_function(func)))); chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Proxy_Function_Impl<typename dispatch::detail::FunctionSignature<decltype(dispatch::detail::to_function(func)) >::Signature>>(dispatch::detail::to_function(func)));
} }
template<typename T, typename Class /*, typename = typename std::enable_if<std::is_member_object_pointer<T>::value>::type*/> template<typename T, typename Class /*, typename = typename std::enable_if<std::is_member_object_pointer<T>::value>::type*/>
Proxy_Function fun(T Class::* m /*, typename std::enable_if<std::is_member_object_pointer<T>::value>::type* = 0*/ ) Proxy_Function fun(T Class::* m /*, typename std::enable_if<std::is_member_object_pointer<T>::value>::type* = 0*/ )
{ {
return Proxy_Function(new dispatch::Attribute_Access<T, Class>(m)); return Proxy_Function(chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Attribute_Access<T, Class>>(m));
} }
@ -129,7 +128,7 @@ namespace chaiscript
template<typename T> template<typename T>
Proxy_Function fun(const std::function<T> &f) Proxy_Function fun(const std::function<T> &f)
{ {
return Proxy_Function(static_cast<dispatch::Proxy_Function_Impl_Base *>(new dispatch::Proxy_Function_Impl<T>(f))); return Proxy_Function(chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Proxy_Function_Impl<T>>(f));
} }

View File

@ -92,13 +92,14 @@ namespace chaiscript
return m_from; return m_from;
} }
virtual ~Type_Conversion_Base() {}
protected: protected:
Type_Conversion_Base(const Type_Info &t_to, const Type_Info &t_from) Type_Conversion_Base(const Type_Info &t_to, const Type_Info &t_from)
: m_to(t_to), m_from(t_from) : m_to(t_to), m_from(t_from)
{ {
} }
virtual ~Type_Conversion_Base() {}
private: private:
Type_Info m_to; Type_Info m_to;
@ -424,14 +425,14 @@ namespace chaiscript
static_assert(std::is_polymorphic<Base>::value, "Base class must be polymorphic"); static_assert(std::is_polymorphic<Base>::value, "Base class must be polymorphic");
static_assert(std::is_polymorphic<Derived>::value, "Derived class must be polymorphic"); static_assert(std::is_polymorphic<Derived>::value, "Derived class must be polymorphic");
return std::make_shared<detail::Dynamic_Conversion_Impl<Base, Derived>>(); return chaiscript::make_shared<detail::Type_Conversion_Base, detail::Dynamic_Conversion_Impl<Base, Derived>>();
} }
template<typename Callable> template<typename Callable>
Type_Conversion type_conversion(const Type_Info &t_from, const Type_Info &t_to, Type_Conversion type_conversion(const Type_Info &t_from, const Type_Info &t_to,
const Callable &t_func) const Callable &t_func)
{ {
return std::make_shared<detail::Type_Conversion_Impl<Callable>>(t_from, t_to, t_func); return chaiscript::make_shared<detail::Type_Conversion_Base, detail::Type_Conversion_Impl<Callable>>(t_from, t_to, t_func);
} }
template<typename From, typename To, typename Callable> template<typename From, typename To, typename Callable>
@ -442,7 +443,7 @@ namespace chaiscript
return chaiscript::Boxed_Value(t_function(detail::Cast_Helper<const From &>::cast(t_bv, nullptr))); return chaiscript::Boxed_Value(t_function(detail::Cast_Helper<const From &>::cast(t_bv, nullptr)));
}; };
return std::make_shared<detail::Type_Conversion_Impl<decltype(func)>>(user_type<From>(), user_type<To>(), func); return chaiscript::make_shared<detail::Type_Conversion_Base, detail::Type_Conversion_Impl<decltype(func)>>(user_type<From>(), user_type<To>(), func);
} }
template<typename From, typename To> template<typename From, typename To>
@ -454,7 +455,7 @@ namespace chaiscript
return chaiscript::Boxed_Value(To(detail::Cast_Helper<From>::cast(t_bv, nullptr))); return chaiscript::Boxed_Value(To(detail::Cast_Helper<From>::cast(t_bv, nullptr)));
}; };
return std::make_shared<detail::Type_Conversion_Impl<decltype(func)>>(user_type<From>(), user_type<To>(), func); return chaiscript::make_shared<detail::Type_Conversion_Base, detail::Type_Conversion_Impl<decltype(func)>>(user_type<From>(), user_type<To>(), func);
} }
} }

View File

@ -7,11 +7,10 @@
#ifndef CHAISCRIPT_TYPE_INFO_HPP_ #ifndef CHAISCRIPT_TYPE_INFO_HPP_
#define CHAISCRIPT_TYPE_INFO_HPP_ #define CHAISCRIPT_TYPE_INFO_HPP_
#include <functional>
#include <memory> #include <memory>
#include <string>
#include <type_traits> #include <type_traits>
#include <typeinfo> #include <typeinfo>
#include <string>
namespace chaiscript namespace chaiscript
{ {

View File

@ -9,8 +9,6 @@
#include <string> #include <string>
#include "../dispatchkit/dispatchkit.hpp"
namespace chaiscript namespace chaiscript
{ {

View File

@ -26,6 +26,7 @@ struct AST_Node;
namespace chaiscript namespace chaiscript
{ {
/// Signature of module entry point that all binary loadable modules must implement. /// Signature of module entry point that all binary loadable modules must implement.
typedef ModulePtr (*Create_Module_Func)(); typedef ModulePtr (*Create_Module_Func)();
@ -77,7 +78,7 @@ namespace chaiscript
{ {
/// Errors generated during parsing or evaluation /// Errors generated during parsing or evaluation
struct eval_error : public std::runtime_error { struct eval_error : std::runtime_error {
std::string reason; std::string reason;
File_Position start_position; File_Position start_position;
File_Position end_position; File_Position end_position;
@ -391,7 +392,7 @@ namespace chaiscript
/// Errors generated when loading a file /// Errors generated when loading a file
struct file_not_found_error : public std::runtime_error { struct file_not_found_error : std::runtime_error {
file_not_found_error(const std::string &t_filename) CHAISCRIPT_NOEXCEPT file_not_found_error(const std::string &t_filename) CHAISCRIPT_NOEXCEPT
: std::runtime_error("File Not Found: " + t_filename) : std::runtime_error("File Not Found: " + t_filename)
{ } { }
@ -465,6 +466,8 @@ namespace chaiscript
std::replace(children.begin(), children.end(), t_child, t_new_child); std::replace(children.begin(), children.end(), t_child, t_new_child);
} }
virtual ~AST_Node() {}
protected: protected:
AST_Node(std::string t_ast_node_text, int t_id, const std::shared_ptr<const std::string> &t_fname, AST_Node(std::string t_ast_node_text, int t_id, const std::shared_ptr<const std::string> &t_fname,
int t_start_line, int t_start_col, int t_end_line, int t_end_col) : int t_start_line, int t_start_col, int t_end_line, int t_end_col) :
@ -476,7 +479,6 @@ namespace chaiscript
AST_Node(std::string t_ast_node_text, int t_id, const std::shared_ptr<const std::string> &t_fname) : AST_Node(std::string t_ast_node_text, int t_id, const std::shared_ptr<const std::string> &t_fname) :
identifier(t_id), text(std::move(t_ast_node_text)), filename(t_fname) {} identifier(t_id), text(std::move(t_ast_node_text)), filename(t_fname) {}
virtual ~AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &) const virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &) const
{ {

View File

@ -8,8 +8,6 @@
#define CHAISCRIPT_ENGINE_HPP_ #define CHAISCRIPT_ENGINE_HPP_
#include <cassert> #include <cassert>
#include <cstring>
#include <algorithm>
#include <exception> #include <exception>
#include <fstream> #include <fstream>
#include <functional> #include <functional>
@ -18,7 +16,6 @@
#include <mutex> #include <mutex>
#include <set> #include <set>
#include <stdexcept> #include <stdexcept>
#include <string>
#include <vector> #include <vector>
#include "../chaiscript_defines.hpp" #include "../chaiscript_defines.hpp"
@ -363,10 +360,10 @@ namespace chaiscript
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::function_exists, std::ref(m_engine)), "function_exists"); 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_function_objects, std::ref(m_engine)), "get_functions"); m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_function_objects, std::ref(m_engine)), "get_functions");
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_scripting_objects, std::ref(m_engine)), "get_objects"); m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_scripting_objects, std::ref(m_engine)), "get_objects");
m_engine.add(Proxy_Function(new dispatch::Dynamic_Proxy_Function( m_engine.add(chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Dynamic_Proxy_Function>(
[this](const std::vector<Boxed_Value> &t_params) { [this](const std::vector<Boxed_Value> &t_params) {
return m_engine.call_exists(t_params); return m_engine.call_exists(t_params);
})), "call_exists"); }), "call_exists");
// m_engine.add(fun<Boxed_Value (const dispatch::Proxy_Function_Base *, const std::vector<Boxed_Value> &)>(std::bind(&chaiscript::dispatch::Proxy_Function_Base::operator(), std::placeholders::_1, std::placeholders::_2, std::ref(m_engine.conversions()))), "call"); // m_engine.add(fun<Boxed_Value (const dispatch::Proxy_Function_Base *, const std::vector<Boxed_Value> &)>(std::bind(&chaiscript::dispatch::Proxy_Function_Base::operator(), std::placeholders::_1, std::placeholders::_2, std::ref(m_engine.conversions()))), "call");
// //

View File

@ -7,8 +7,6 @@
#ifndef CHAISCRIPT_EVAL_HPP_ #ifndef CHAISCRIPT_EVAL_HPP_
#define CHAISCRIPT_EVAL_HPP_ #define CHAISCRIPT_EVAL_HPP_
#include <assert.h>
#include <cstdlib>
#include <exception> #include <exception>
#include <functional> #include <functional>
#include <limits> #include <limits>
@ -21,7 +19,6 @@
#include "../chaiscript_defines.hpp" #include "../chaiscript_defines.hpp"
#include "../dispatchkit/boxed_cast.hpp" #include "../dispatchkit/boxed_cast.hpp"
#include "../dispatchkit/boxed_cast_helper.hpp"
#include "../dispatchkit/boxed_number.hpp" #include "../dispatchkit/boxed_number.hpp"
#include "../dispatchkit/boxed_value.hpp" #include "../dispatchkit/boxed_value.hpp"
#include "../dispatchkit/dispatchkit.hpp" #include "../dispatchkit/dispatchkit.hpp"
@ -803,12 +800,12 @@ namespace chaiscript
const auto &lambda_node = this->children.back(); const auto &lambda_node = this->children.back();
return Boxed_Value(Proxy_Function(new dispatch::Dynamic_Proxy_Function( return Boxed_Value(chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Dynamic_Proxy_Function>(
[&t_ss, lambda_node, param_names, captures](const std::vector<Boxed_Value> &t_params) [&t_ss, lambda_node, param_names, captures](const std::vector<Boxed_Value> &t_params)
{ {
return detail::eval_function(t_ss, lambda_node, param_names, t_params, captures); return detail::eval_function(t_ss, lambda_node, param_names, t_params, captures);
}, },
static_cast<int>(numparams), lambda_node, param_types))); static_cast<int>(numparams), lambda_node, param_types));
} }
@ -864,23 +861,23 @@ namespace chaiscript
std::shared_ptr<dispatch::Dynamic_Proxy_Function> guard; std::shared_ptr<dispatch::Dynamic_Proxy_Function> guard;
if (guardnode) { if (guardnode) {
guard = std::shared_ptr<dispatch::Dynamic_Proxy_Function> guard = std::make_shared<dispatch::Dynamic_Proxy_Function>
(new dispatch::Dynamic_Proxy_Function([&t_ss, guardnode, t_param_names](const std::vector<Boxed_Value> &t_params) ([&t_ss, guardnode, t_param_names](const std::vector<Boxed_Value> &t_params)
{ {
return detail::eval_function(t_ss, guardnode, t_param_names, t_params); return detail::eval_function(t_ss, guardnode, t_param_names, t_params);
}, static_cast<int>(numparams), guardnode)); }, static_cast<int>(numparams), guardnode);
} }
try { try {
const std::string & l_function_name = this->children[0]->text; const std::string & l_function_name = this->children[0]->text;
const std::string & l_annotation = this->annotation?this->annotation->text:""; const std::string & l_annotation = this->annotation?this->annotation->text:"";
const auto & func_node = this->children.back(); const auto & func_node = this->children.back();
t_ss.add(Proxy_Function t_ss.add(chaiscript::make_shared<dispatch::Proxy_Function_Base, dispatch::Dynamic_Proxy_Function>
(new dispatch::Dynamic_Proxy_Function([&t_ss, guardnode, func_node, t_param_names](const std::vector<Boxed_Value> &t_params) ([&t_ss, guardnode, func_node, t_param_names](const std::vector<Boxed_Value> &t_params)
{ {
return detail::eval_function(t_ss, func_node, t_param_names, t_params); return detail::eval_function(t_ss, func_node, t_param_names, t_params);
}, static_cast<int>(numparams), this->children.back(), }, static_cast<int>(numparams), this->children.back(),
param_types, l_annotation, guard)), l_function_name); param_types, l_annotation, guard), l_function_name);
} }
catch (const exception::reserved_word_error &e) { catch (const exception::reserved_word_error &e) {
throw exception::eval_error("Reserved word used as function name '" + e.word() + "'"); throw exception::eval_error("Reserved word used as function name '" + e.word() + "'");

View File

@ -10,7 +10,6 @@
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <exception> #include <exception>
#include <fstream>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <sstream> #include <sstream>
@ -229,7 +228,7 @@ namespace chaiscript
for (const auto &count : counts) { for (const auto &count : counts) {
// std::cout << " Fun Call Count: " << count.first << " " << count.second << '\n'; // std::cout << " Fun Call Count: " << count.first << " " << count.second << '\n';
if (count.second > 1) { if (count.second > 1) {
children_to_add.push_back(std::make_shared<eval::Fun_Lookup_AST_Node>(count.first)); children_to_add.push_back(chaiscript::make_shared<AST_Node, eval::Fun_Lookup_AST_Node>(count.first));
} }
} }
c->children.back()->children.insert(c->children.back()->children.begin(), children_to_add.begin(), children_to_add.end()); c->children.back()->children.insert(c->children.back()->children.begin(), children_to_add.begin(), children_to_add.end());
@ -277,7 +276,7 @@ namespace chaiscript
for (auto &c : p->children) for (auto &c : p->children)
{ {
if (c->identifier == AST_Node_Type::Fun_Call && c->children.size() == 2 && c->children[1]->children.size() == 1) { if (c->identifier == AST_Node_Type::Fun_Call && c->children.size() == 2 && c->children[1]->children.size() == 1) {
c = std::make_shared<eval::Unary_Fun_Call_AST_Node>(dynamic_cast<eval::Fun_Call_AST_Node &>(*c)); c = chaiscript::make_shared<AST_Node, eval::Unary_Fun_Call_AST_Node>(dynamic_cast<eval::Fun_Call_AST_Node &>(*c));
// std::cout << "optimized unary fun call\n"; // std::cout << "optimized unary fun call\n";
} }
optimize_fun_calls(c); optimize_fun_calls(c);
@ -728,7 +727,7 @@ namespace chaiscript
if (has_more_input() && char_in_alphabet(*m_input_pos, detail::float_alphabet) ) { if (has_more_input() && char_in_alphabet(*m_input_pos, detail::float_alphabet) ) {
if (Hex_()) { if (Hex_()) {
std::string match(start, m_input_pos); std::string match(start, m_input_pos);
m_match_stack.emplace_back(std::make_shared<eval::Int_AST_Node>(std::move(match), buildInt(std::hex, match), m_filename, prev_line, prev_col, m_line, m_col)); m_match_stack.emplace_back(chaiscript::make_shared<AST_Node, eval::Int_AST_Node>(std::move(match), buildInt(std::hex, match), m_filename, prev_line, prev_col, m_line, m_col));
return true; return true;
} }
@ -754,22 +753,22 @@ namespace chaiscript
i = const_var(temp_int); i = const_var(temp_int);
} }
m_match_stack.push_back(std::make_shared<eval::Int_AST_Node>(std::move(match), std::move(i), m_filename, prev_line, prev_col, m_line, m_col)); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Int_AST_Node>(std::move(match), std::move(i), m_filename, prev_line, prev_col, m_line, m_col));
return true; return true;
} }
if (Float_()) { if (Float_()) {
std::string match(start, m_input_pos); std::string match(start, m_input_pos);
m_match_stack.push_back(std::make_shared<eval::Float_AST_Node>(std::move(match), buildFloat(match), m_filename, prev_line, prev_col, m_line, m_col)); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Float_AST_Node>(std::move(match), buildFloat(match), m_filename, prev_line, prev_col, m_line, m_col));
return true; return true;
} }
else { else {
IntSuffix_(); IntSuffix_();
std::string match(start, m_input_pos); std::string match(start, m_input_pos);
if (!match.empty() && (match[0] == '0')) { if (!match.empty() && (match[0] == '0')) {
m_match_stack.push_back(std::make_shared<eval::Int_AST_Node>(std::move(match), buildInt(std::oct, match), m_filename, prev_line, prev_col, m_line, m_col)); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Int_AST_Node>(std::move(match), buildInt(std::oct, match), m_filename, prev_line, prev_col, m_line, m_col));
} }
else { else {
m_match_stack.push_back(std::make_shared<eval::Int_AST_Node>(std::move(match), buildInt(std::dec, match), m_filename, prev_line, prev_col, m_line, m_col)); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Int_AST_Node>(std::move(match), buildInt(std::dec, match), m_filename, prev_line, prev_col, m_line, m_col));
} }
return true; return true;
} }
@ -827,7 +826,7 @@ namespace chaiscript
const auto prev_col = m_col; const auto prev_col = m_col;
const auto prev_line = m_line; const auto prev_line = m_line;
if (Id_()) { if (Id_()) {
m_match_stack.push_back(std::make_shared<eval::Id_AST_Node>( m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Id_AST_Node>(
[&]()->std::string{ [&]()->std::string{
if (*start == '`') { if (*start == '`') {
//Id Literal //Id Literal
@ -858,7 +857,7 @@ namespace chaiscript
Id(); Id();
} }
build_match(std::make_shared<eval::Arg_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Arg_AST_Node>(), prev_stack_top);
return true; return true;
} }
@ -885,7 +884,7 @@ namespace chaiscript
} while (Symbol("#")); } while (Symbol("#"));
std::string match(start, m_input_pos); std::string match(start, m_input_pos);
m_match_stack.push_back(std::make_shared<eval::Annotation_AST_Node>(std::move(match), m_filename, prev_line, prev_col, m_line, m_col)); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Annotation_AST_Node>(std::move(match), m_filename, prev_line, prev_col, m_line, m_col));
return true; return true;
} }
else { else {
@ -951,11 +950,11 @@ namespace chaiscript
if (is_interpolated) { if (is_interpolated) {
//If we've seen previous interpolation, add on instead of making a new one //If we've seen previous interpolation, add on instead of making a new one
m_match_stack.push_back(std::make_shared<eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col)); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
build_match(std::make_shared<eval::Binary_Operator_AST_Node>("+"), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Binary_Operator_AST_Node>("+"), prev_stack_top);
} else { } else {
m_match_stack.push_back(std::make_shared<eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col)); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
} }
//We've finished with the part of the string up to this point, so clear it //We've finished with the part of the string up to this point, so clear it
@ -975,22 +974,22 @@ namespace chaiscript
const auto tostr_stack_top = m_match_stack.size(); const auto tostr_stack_top = m_match_stack.size();
m_match_stack.push_back(std::make_shared<eval::Id_AST_Node>("to_string", m_filename, prev_line, prev_col, m_line, m_col)); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Id_AST_Node>("to_string", m_filename, prev_line, prev_col, m_line, m_col));
const auto ev_stack_top = m_match_stack.size(); const auto ev_stack_top = m_match_stack.size();
/// \todo can we evaluate this in place and save the runtime cost of evaluating with each execution of the node? /// \todo can we evaluate this in place and save the runtime cost of evaluating with each execution of the node?
m_match_stack.push_back(std::make_shared<eval::Id_AST_Node>("eval", m_filename, prev_line, prev_col, m_line, m_col)); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Id_AST_Node>("eval", m_filename, prev_line, prev_col, m_line, m_col));
const auto arg_stack_top = m_match_stack.size(); const auto arg_stack_top = m_match_stack.size();
m_match_stack.push_back(std::make_shared<eval::Quoted_String_AST_Node>(eval_match, m_filename, prev_line, prev_col, m_line, m_col)); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Quoted_String_AST_Node>(eval_match, m_filename, prev_line, prev_col, m_line, m_col));
build_match(std::make_shared<eval::Arg_List_AST_Node>(), arg_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), arg_stack_top);
build_match(std::make_shared<eval::Inplace_Fun_Call_AST_Node>(), ev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Inplace_Fun_Call_AST_Node>(), ev_stack_top);
build_match(std::make_shared<eval::Arg_List_AST_Node>(), ev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), ev_stack_top);
build_match(std::make_shared<eval::Fun_Call_AST_Node>(), tostr_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Fun_Call_AST_Node>(), tostr_stack_top);
build_match(std::make_shared<eval::Binary_Operator_AST_Node>("+"), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Binary_Operator_AST_Node>("+"), prev_stack_top);
} else { } else {
throw exception::eval_error("Unclosed in-string eval", File_Position(prev_line, prev_col), *m_filename); throw exception::eval_error("Unclosed in-string eval", File_Position(prev_line, prev_col), *m_filename);
} }
@ -1031,11 +1030,11 @@ namespace chaiscript
} }
if (is_interpolated) { if (is_interpolated) {
m_match_stack.push_back(std::make_shared<eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col)); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
build_match(std::make_shared<eval::Binary_Operator_AST_Node>("+"), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Binary_Operator_AST_Node>("+"), prev_stack_top);
} else { } else {
m_match_stack.push_back(std::make_shared<eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col)); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
} }
return true; return true;
} else { } else {
@ -1114,7 +1113,7 @@ namespace chaiscript
is_escaped = false; is_escaped = false;
} }
} }
m_match_stack.push_back(std::make_shared<eval::Single_Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col)); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Single_Quoted_String_AST_Node>(match, m_filename, prev_line, prev_col, m_line, m_col));
return true; return true;
} }
else { else {
@ -1146,7 +1145,7 @@ namespace chaiscript
const auto prev_line = m_line; const auto prev_line = m_line;
if (Char_(t_c)) { if (Char_(t_c)) {
m_match_stack.push_back( m_match_stack.push_back(
std::make_shared<eval::Char_AST_Node>(std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col)); chaiscript::make_shared<AST_Node, eval::Char_AST_Node>(std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col));
return true; return true;
} else { } else {
return false; return false;
@ -1190,7 +1189,7 @@ namespace chaiscript
} }
if ( t_capture && retval ) { if ( t_capture && retval ) {
m_match_stack.push_back(std::make_shared<eval::Str_AST_Node>( m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Str_AST_Node>(
std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col)); std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col));
} }
return retval; return retval;
@ -1233,7 +1232,7 @@ namespace chaiscript
} }
if ( t_capture && retval ) { if ( t_capture && retval ) {
m_match_stack.push_back(std::make_shared<eval::Str_AST_Node>( m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Str_AST_Node>(
std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col)); std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col));
} }
@ -1266,7 +1265,7 @@ namespace chaiscript
const auto prev_col = m_col; const auto prev_col = m_col;
const auto prev_line = m_line; const auto prev_line = m_line;
if (Eol_()) { if (Eol_()) {
m_match_stack.push_back(std::make_shared<eval::Eol_AST_Node>( m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Eol_AST_Node>(
std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col)); std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col));
return true; return true;
} else { } else {
@ -1294,7 +1293,7 @@ namespace chaiscript
} while (Char(',')); } while (Char(','));
} }
} }
build_match(std::make_shared<eval::Arg_List_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), prev_stack_top);
SkipWS(true); SkipWS(true);
@ -1320,7 +1319,7 @@ namespace chaiscript
} while (Char(',')); } while (Char(','));
} }
} }
build_match(std::make_shared<eval::Arg_List_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), prev_stack_top);
SkipWS(true); SkipWS(true);
@ -1348,7 +1347,7 @@ namespace chaiscript
} }
} }
build_match(std::make_shared<eval::Arg_List_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), prev_stack_top);
SkipWS(true); SkipWS(true);
@ -1364,7 +1363,7 @@ namespace chaiscript
if (Value_Range()) { if (Value_Range()) {
retval = true; retval = true;
build_match(std::make_shared<eval::Arg_List_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), prev_stack_top);
} else if (Map_Pair()) { } else if (Map_Pair()) {
retval = true; retval = true;
while (Eol()) {} while (Eol()) {}
@ -1376,7 +1375,7 @@ namespace chaiscript
} }
} while (Char(',')); } while (Char(','));
} }
build_match(std::make_shared<eval::Arg_List_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), prev_stack_top);
} else if (Operator()) { } else if (Operator()) {
retval = true; retval = true;
while (Eol()) {} while (Eol()) {}
@ -1388,7 +1387,7 @@ namespace chaiscript
} }
} while (Char(',')); } while (Char(','));
} }
build_match(std::make_shared<eval::Arg_List_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), prev_stack_top);
} }
SkipWS(true); SkipWS(true);
@ -1412,7 +1411,7 @@ namespace chaiscript
} }
} else { } else {
// make sure we always have the same number of nodes // make sure we always have the same number of nodes
build_match(std::make_shared<eval::Arg_List_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Arg_List_AST_Node>(), prev_stack_top);
} }
if (Char('(')) { if (Char('(')) {
@ -1431,7 +1430,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete anonymous function", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete anonymous function", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Lambda_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Lambda_AST_Node>(), prev_stack_top);
} }
return retval; return retval;
@ -1489,9 +1488,9 @@ namespace chaiscript
} }
if (is_method || t_class_context) { if (is_method || t_class_context) {
build_match(std::make_shared<eval::Method_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Method_AST_Node>(), prev_stack_top);
} else { } else {
build_match(std::make_shared<eval::Def_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Def_AST_Node>(), prev_stack_top);
} }
if (annotation) { if (annotation) {
@ -1539,7 +1538,7 @@ namespace chaiscript
if (!Block()) { if (!Block()) {
throw exception::eval_error("Incomplete 'catch' block", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete 'catch' block", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Catch_AST_Node>(), catch_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Catch_AST_Node>(), catch_stack_top);
has_matches = true; has_matches = true;
} }
} }
@ -1552,10 +1551,10 @@ namespace chaiscript
if (!Block()) { if (!Block()) {
throw exception::eval_error("Incomplete 'finally' block", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete 'finally' block", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Finally_AST_Node>(), finally_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Finally_AST_Node>(), finally_stack_top);
} }
build_match(std::make_shared<eval::Try_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Try_AST_Node>(), prev_stack_top);
} }
return retval; return retval;
@ -1591,7 +1590,7 @@ namespace chaiscript
if (Keyword("else", true)) { if (Keyword("else", true)) {
if (Keyword("if")) { if (Keyword("if")) {
const AST_NodePtr back(m_match_stack.back()); const AST_NodePtr back(m_match_stack.back());
m_match_stack.back() = std::make_shared<eval::If_AST_Node>("else if"); m_match_stack.back() = chaiscript::make_shared<AST_Node, eval::If_AST_Node>("else if");
m_match_stack.back()->start = back->start; m_match_stack.back()->start = back->start;
m_match_stack.back()->end = back->end; m_match_stack.back()->end = back->end;
m_match_stack.back()->children = back->children; m_match_stack.back()->children = back->children;
@ -1621,7 +1620,7 @@ namespace chaiscript
} }
} }
build_match(std::make_shared<eval::If_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::If_AST_Node>(), prev_stack_top);
} }
return retval; return retval;
@ -1647,7 +1646,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete 'class' block", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete 'class' block", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Class_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Class_AST_Node>(), prev_stack_top);
} }
return retval; return retval;
@ -1677,7 +1676,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete 'while' block", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete 'while' block", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::While_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::While_AST_Node>(), prev_stack_top);
} }
return retval; return retval;
@ -1692,7 +1691,7 @@ namespace chaiscript
{ {
throw exception::eval_error("'for' loop initial statment missing", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("'for' loop initial statment missing", File_Position(m_line, m_col), *m_filename);
} else { } else {
m_match_stack.push_back(std::make_shared<eval::Noop_AST_Node>()); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Noop_AST_Node>());
} }
} }
@ -1702,13 +1701,13 @@ namespace chaiscript
{ {
throw exception::eval_error("'for' loop condition missing", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("'for' loop condition missing", File_Position(m_line, m_col), *m_filename);
} else { } else {
m_match_stack.push_back(std::make_shared<eval::Noop_AST_Node>()); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Noop_AST_Node>());
} }
} }
if (!Equation()) if (!Equation())
{ {
m_match_stack.push_back(std::make_shared<eval::Noop_AST_Node>()); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Noop_AST_Node>());
} }
return true; return true;
@ -1739,7 +1738,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete 'for' block", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete 'for' block", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::For_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::For_AST_Node>(), prev_stack_top);
} }
return retval; return retval;
@ -1768,7 +1767,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete 'case' block", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete 'case' block", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Case_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Case_AST_Node>(), prev_stack_top);
} else if (Keyword("default")) { } else if (Keyword("default")) {
while (Eol()) {} while (Eol()) {}
@ -1776,7 +1775,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete 'default' block", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete 'default' block", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Default_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Default_AST_Node>(), prev_stack_top);
} }
return retval; return retval;
@ -1816,7 +1815,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete block", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete block", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Switch_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Switch_AST_Node>(), prev_stack_top);
return true; return true;
} else { } else {
@ -1841,10 +1840,10 @@ namespace chaiscript
} }
if (m_match_stack.size() == prev_stack_top) { if (m_match_stack.size() == prev_stack_top) {
m_match_stack.push_back(std::make_shared<eval::Noop_AST_Node>()); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Noop_AST_Node>());
} }
build_match(std::make_shared<eval::Block_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Block_AST_Node>(), prev_stack_top);
} }
return retval; return retval;
@ -1865,10 +1864,10 @@ namespace chaiscript
} }
if (m_match_stack.size() == prev_stack_top) { if (m_match_stack.size() == prev_stack_top) {
m_match_stack.push_back(std::make_shared<eval::Noop_AST_Node>()); m_match_stack.push_back(chaiscript::make_shared<AST_Node, eval::Noop_AST_Node>());
} }
build_match(std::make_shared<eval::Block_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Block_AST_Node>(), prev_stack_top);
} }
return retval; return retval;
@ -1880,7 +1879,7 @@ namespace chaiscript
if (Keyword("return")) { if (Keyword("return")) {
Operator(); Operator();
build_match(std::make_shared<eval::Return_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Return_AST_Node>(), prev_stack_top);
return true; return true;
} else { } else {
return false; return false;
@ -1892,7 +1891,7 @@ namespace chaiscript
const auto prev_stack_top = m_match_stack.size(); const auto prev_stack_top = m_match_stack.size();
if (Keyword("break")) { if (Keyword("break")) {
build_match(std::make_shared<eval::Break_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Break_AST_Node>(), prev_stack_top);
return true; return true;
} else { } else {
return false; return false;
@ -1904,7 +1903,7 @@ namespace chaiscript
const auto prev_stack_top = m_match_stack.size(); const auto prev_stack_top = m_match_stack.size();
if (Keyword("continue")) { if (Keyword("continue")) {
build_match(std::make_shared<eval::Continue_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Continue_AST_Node>(), prev_stack_top);
return true; return true;
} else { } else {
return false; return false;
@ -1933,7 +1932,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete function call", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete function call", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Fun_Call_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Fun_Call_AST_Node>(), prev_stack_top);
/// \todo Work around for method calls until we have a better solution /// \todo Work around for method calls until we have a better solution
if (!m_match_stack.back()->children.empty()) { if (!m_match_stack.back()->children.empty()) {
if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Dot_Access) { if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Dot_Access) {
@ -1954,7 +1953,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete array access", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete array access", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Array_Call_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Array_Call_AST_Node>(), prev_stack_top);
} }
else if (Symbol(".", true)) { else if (Symbol(".", true)) {
has_more = true; has_more = true;
@ -1962,7 +1961,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete array access", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete array access", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Dot_Access_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Dot_Access_AST_Node>(), prev_stack_top);
} }
} }
} }
@ -1983,7 +1982,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Attr_Decl_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Attr_Decl_AST_Node>(), prev_stack_top);
} else if (Keyword("auto") || Keyword("var")) { } else if (Keyword("auto") || Keyword("var")) {
retval = true; retval = true;
@ -1991,7 +1990,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete variable declaration", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete variable declaration", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Var_Decl_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Var_Decl_AST_Node>(), prev_stack_top);
} else if (Keyword("attr")) { } else if (Keyword("attr")) {
retval = true; retval = true;
@ -2006,7 +2005,7 @@ namespace chaiscript
} }
build_match(std::make_shared<eval::Attr_Decl_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Attr_Decl_AST_Node>(), prev_stack_top);
} }
return retval; return retval;
@ -2039,17 +2038,17 @@ namespace chaiscript
} }
if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) { 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) { if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Value_Range) {
build_match(std::make_shared<eval::Inline_Range_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Inline_Range_AST_Node>(), prev_stack_top);
} }
else if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Map_Pair) { else if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Map_Pair) {
build_match(std::make_shared<eval::Inline_Map_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Inline_Map_AST_Node>(), prev_stack_top);
} }
else { else {
build_match(std::make_shared<eval::Inline_Array_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Inline_Array_AST_Node>(), prev_stack_top);
} }
} }
else { else {
build_match(std::make_shared<eval::Inline_Array_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Inline_Array_AST_Node>(), prev_stack_top);
} }
return true; return true;
@ -2067,7 +2066,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete '&' expression", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete '&' expression", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Reference_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Reference_AST_Node>(), prev_stack_top);
return true; return true;
} else { } else {
return false; return false;
@ -2088,7 +2087,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete prefix '" + oper + "' expression", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete prefix '" + oper + "' expression", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Prefix_AST_Node>(Operators::to_operator(oper, true)), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Prefix_AST_Node>(Operators::to_operator(oper, true)), prev_stack_top);
return true; return true;
} }
} }
@ -2138,7 +2137,7 @@ namespace chaiscript
+ std::string(ast_node_type_to_string(m_operators[t_precedence])) + " expression", + std::string(ast_node_type_to_string(m_operators[t_precedence])) + " expression",
File_Position(m_line, m_col), *m_filename); File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Ternary_Cond_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Ternary_Cond_AST_Node>(), prev_stack_top);
} }
else { else {
throw exception::eval_error("Incomplete " throw exception::eval_error("Incomplete "
@ -2157,14 +2156,14 @@ namespace chaiscript
case(AST_Node_Type::Comparison) : case(AST_Node_Type::Comparison) :
assert(m_match_stack.size() > 1); assert(m_match_stack.size() > 1);
m_match_stack.erase(m_match_stack.begin() + m_match_stack.size() - 2, m_match_stack.begin() + m_match_stack.size() - 1); m_match_stack.erase(m_match_stack.begin() + m_match_stack.size() - 2, m_match_stack.begin() + m_match_stack.size() - 1);
build_match(std::make_shared<eval::Binary_Operator_AST_Node>(oper->text), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Binary_Operator_AST_Node>(oper->text), prev_stack_top);
break; break;
case(AST_Node_Type::Logical_And) : case(AST_Node_Type::Logical_And) :
build_match(std::make_shared<eval::Logical_And_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Logical_And_AST_Node>(), prev_stack_top);
break; break;
case(AST_Node_Type::Logical_Or) : case(AST_Node_Type::Logical_Or) :
build_match(std::make_shared<eval::Logical_Or_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Logical_Or_AST_Node>(), prev_stack_top);
break; break;
default: default:
@ -2196,7 +2195,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete map pair", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete map pair", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Map_Pair_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Map_Pair_AST_Node>(), prev_stack_top);
} }
else { else {
m_input_pos = prev_pos; m_input_pos = prev_pos;
@ -2225,7 +2224,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete value range", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete value range", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Value_Range_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Value_Range_AST_Node>(), prev_stack_top);
} }
else { else {
m_input_pos = prev_pos; m_input_pos = prev_pos;
@ -2256,7 +2255,7 @@ namespace chaiscript
throw exception::eval_error("Incomplete equation", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete equation", File_Position(m_line, m_col), *m_filename);
} }
build_match(std::make_shared<eval::Equation_AST_Node>(), prev_stack_top); build_match(chaiscript::make_shared<AST_Node, eval::Equation_AST_Node>(), prev_stack_top);
} }
} }
@ -2350,7 +2349,7 @@ namespace chaiscript
if (m_input_pos != m_input_end) { if (m_input_pos != m_input_end) {
throw exception::eval_error("Unparsed input", File_Position(m_line, m_col), t_fname); throw exception::eval_error("Unparsed input", File_Position(m_line, m_col), t_fname);
} else { } else {
build_match(std::make_shared<eval::File_AST_Node>(), 0); build_match(chaiscript::make_shared<AST_Node, eval::File_AST_Node>(), 0);
return true; return true;
} }
} else { } else {

View File

@ -1,6 +1,5 @@
#include <iostream> #include <iostream>
#include <list>
#include <algorithm> #include <algorithm>
#include <chaiscript/chaiscript.hpp> #include <chaiscript/chaiscript.hpp>
@ -74,7 +73,7 @@ int main()
for (int i = 0; i < num_threads; ++i) for (int i = 0; i < num_threads; ++i)
{ {
threads.push_back(std::shared_ptr<std::thread>(new std::thread(do_work, std::ref(chai), i))); threads.push_back(std::make_shared<std::thread>(do_work, std::ref(chai), i));
} }
for (int i = 0; i < num_threads; ++i) for (int i = 0; i < num_threads; ++i)