From 49ef5306a9c7b7f9c7c5dde37c2f52b9be85366d Mon Sep 17 00:00:00 2001 From: ELynx Date: Fri, 15 Apr 2016 13:15:30 +0300 Subject: [PATCH 1/7] Add resize to stl list and vector; add reserve to stl vector --- .../chaiscript/dispatchkit/bootstrap_stl.hpp | 24 +++++++++++++++++++ unittests/list_resize.chai | 13 ++++++++++ unittests/vector_reserve.chai | 7 ++++++ unittests/vector_resize.chai | 13 ++++++++++ 4 files changed, 57 insertions(+) create mode 100644 unittests/list_resize.chai create mode 100644 unittests/vector_reserve.chai create mode 100644 unittests/vector_resize.chai diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 7ba588b7..3c93c919 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -292,6 +292,27 @@ namespace chaiscript } + /// Add container resize concept to the given ContainerType + /// http://www.cplusplus.com/reference/stl/ + template + ModulePtr resizable_type(const std::string &/*type*/, ModulePtr m = std::make_shared()) + { + m->add(fun([](ContainerType *a, ContainerType::size_type n, ContainerType::value_type val) { return a->resize(n, val); } ), "resize"); + m->add(fun([](ContainerType *a, ContainerType::size_type n) { return a->resize(n, ContainerType::value_type()); } ), "resize"); + return m; + } + + + /// Add container reserve concept to the given ContainerType + /// http://www.cplusplus.com/reference/stl/ + template + ModulePtr reservable_type(const std::string &/*type*/, ModulePtr m = std::make_shared()) + { + m->add(fun([](ContainerType *a, ContainerType::size_type n) { return a->reserve(n); } ), "reserve"); + return m; + } + + /// Add container concept to the given ContainerType /// http://www.sgi.com/tech/stl/Container.html template @@ -581,6 +602,7 @@ namespace chaiscript front_insertion_sequence_type(type, m); back_insertion_sequence_type(type, m); sequence_type(type, m); + resizable_type(type, m); container_type(type, m); default_constructible_type(type, m); assignable_type(type, m); @@ -612,6 +634,8 @@ namespace chaiscript back_insertion_sequence_type(type, m); sequence_type(type, m); random_access_container_type(type, m); + resizable_type(type, m); + reservable_type(type, m); container_type(type, m); default_constructible_type(type, m); assignable_type(type, m); diff --git a/unittests/list_resize.chai b/unittests/list_resize.chai new file mode 100644 index 00000000..f34e77aa --- /dev/null +++ b/unittests/list_resize.chai @@ -0,0 +1,13 @@ +load_module("stl_extra"); + +auto list = List(); + +list.resize(2); +assert_equal(list.size(), 2); + +list.resize(6, "AAA"); +assert_equal(list[5], "AAA"); + +list.resize(0); +assert_equal(list.size(), 0); + diff --git a/unittests/vector_reserve.chai b/unittests/vector_reserve.chai new file mode 100644 index 00000000..764002af --- /dev/null +++ b/unittests/vector_reserve.chai @@ -0,0 +1,7 @@ +load_module("stl_extra"); + +auto uint16v = u16vector(); + +uint16v.reserve(5); +assert_true(uint16v.size() >= 5); + diff --git a/unittests/vector_resize.chai b/unittests/vector_resize.chai new file mode 100644 index 00000000..577ae6df --- /dev/null +++ b/unittests/vector_resize.chai @@ -0,0 +1,13 @@ +load_module("stl_extra"); + +auto uint16v = u16vector(); + +uint16v.resize(2); +assert_equal(uint16v.size(), 2); + +uint16v.resize(6, 3); +assert_equal(uint16v[5], 3); + +uint16v.resize(0); +assert_equal(uint16v.size(), 0); + From e8ff1f9d7e4849781300efe1b12dcb67dc5717a0 Mon Sep 17 00:00:00 2001 From: ELynx Date: Fri, 15 Apr 2016 13:39:51 +0300 Subject: [PATCH 2/7] Proper template types for resizable_type and reservable_type --- .../chaiscript/dispatchkit/bootstrap_stl.hpp | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 3c93c919..f9a209bf 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -295,22 +295,34 @@ namespace chaiscript /// Add container resize concept to the given ContainerType /// http://www.cplusplus.com/reference/stl/ template - ModulePtr resizable_type(const std::string &/*type*/, ModulePtr m = std::make_shared()) - { - m->add(fun([](ContainerType *a, ContainerType::size_type n, ContainerType::value_type val) { return a->resize(n, val); } ), "resize"); - m->add(fun([](ContainerType *a, ContainerType::size_type n) { return a->resize(n, ContainerType::value_type()); } ), "resize"); + void resizable_type(const std::string &/*type*/, Module& m) + { + m.add(fun([](ContainerType *a, ContainerType::size_type n, ContainerType::value_type val) { return a->resize(n, val); } ), "resize"); + m.add(fun([](ContainerType *a, ContainerType::size_type n) { return a->resize(n, ContainerType::value_type()); } ), "resize"); + } + template + ModulePtr resizable_type(const std::string &type) + { + auto m = std::make_shared(); + resizable_type(type, *m); return m; - } + } /// Add container reserve concept to the given ContainerType /// http://www.cplusplus.com/reference/stl/ template - ModulePtr reservable_type(const std::string &/*type*/, ModulePtr m = std::make_shared()) - { - m->add(fun([](ContainerType *a, ContainerType::size_type n) { return a->reserve(n); } ), "reserve"); + void reservable_type(const std::string &/*type*/, Module& m) + { + m.add(fun([](ContainerType *a, ContainerType::size_type n) { return a->reserve(n); } ), "reserve"); + } + template + ModulePtr reservable_type(const std::string &type) + { + auto m = std::make_shared(); + reservable_type(type, *m); return m; - } + } /// Add container concept to the given ContainerType From 14d429853bc5d2399b23a187c6215511bb52ad01 Mon Sep 17 00:00:00 2001 From: ELynx Date: Fri, 15 Apr 2016 14:00:01 +0300 Subject: [PATCH 3/7] Add typename; pass value to resize by const referene --- include/chaiscript/dispatchkit/bootstrap_stl.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index f9a209bf..b86b1e44 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -297,8 +297,8 @@ namespace chaiscript template void resizable_type(const std::string &/*type*/, Module& m) { - m.add(fun([](ContainerType *a, ContainerType::size_type n, ContainerType::value_type val) { return a->resize(n, val); } ), "resize"); - m.add(fun([](ContainerType *a, ContainerType::size_type n) { return a->resize(n, ContainerType::value_type()); } ), "resize"); + m.add(fun([](ContainerType *a, typename ContainerType::size_type n, const typename ContainerType::value_type& val) { return a->resize(n, val); } ), "resize"); + m.add(fun([](ContainerType *a, typename ContainerType::size_type n) { return a->resize(n); } ), "resize"); } template ModulePtr resizable_type(const std::string &type) @@ -314,7 +314,7 @@ namespace chaiscript template void reservable_type(const std::string &/*type*/, Module& m) { - m.add(fun([](ContainerType *a, ContainerType::size_type n) { return a->reserve(n); } ), "reserve"); + m.add(fun([](ContainerType *a, typename ContainerType::size_type n) { return a->reserve(n); } ), "reserve"); } template ModulePtr reservable_type(const std::string &type) From cdb9dcc15443d927e892e65ade6b1b8e421bb6aa Mon Sep 17 00:00:00 2001 From: ELynx Date: Fri, 15 Apr 2016 14:08:03 +0300 Subject: [PATCH 4/7] Fix list unittest --- unittests/list_resize.chai | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/list_resize.chai b/unittests/list_resize.chai index f34e77aa..0d6f05cf 100644 --- a/unittests/list_resize.chai +++ b/unittests/list_resize.chai @@ -6,7 +6,7 @@ list.resize(2); assert_equal(list.size(), 2); list.resize(6, "AAA"); -assert_equal(list[5], "AAA"); +assert_equal(list.back(), "AAA"); list.resize(0); assert_equal(list.size(), 0); From 62e34c097cb2fdd9c26776024589d4fdd9574b7c Mon Sep 17 00:00:00 2001 From: ELynx Date: Fri, 15 Apr 2016 14:12:07 +0300 Subject: [PATCH 5/7] Add capacity check; fix vector_reserve unittest --- include/chaiscript/dispatchkit/bootstrap_stl.hpp | 1 + unittests/vector_reserve.chai | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index b86b1e44..b9e0a9f5 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -315,6 +315,7 @@ namespace chaiscript void reservable_type(const std::string &/*type*/, Module& m) { m.add(fun([](ContainerType *a, typename ContainerType::size_type n) { return a->reserve(n); } ), "reserve"); + m.add(fun([](const ContainerType *a) { return a->capacity(); } ), "capacity"); } template ModulePtr reservable_type(const std::string &type) diff --git a/unittests/vector_reserve.chai b/unittests/vector_reserve.chai index 764002af..68c8dbdb 100644 --- a/unittests/vector_reserve.chai +++ b/unittests/vector_reserve.chai @@ -3,5 +3,5 @@ load_module("stl_extra"); auto uint16v = u16vector(); uint16v.reserve(5); -assert_true(uint16v.size() >= 5); +assert_true(uint16v.capacity() >= 5); From 6d6f79b1a45348a8b3d4120a9241a2ab9113e4ac Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 18 Apr 2016 14:38:25 -0600 Subject: [PATCH 6/7] Only pop min/max if they were defined previously --- include/chaiscript/language/chaiscript_parser.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 715d90cf..1ea73716 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -23,6 +23,7 @@ #if defined(CHAISCRIPT_MSVC) && defined(max) && defined(min) +#define CHAISCRIPT_PUSHED_MIN_MAX #pragma push_macro("max") // Why Microsoft? why? This is worse than bad #undef max #pragma push_macro("min") @@ -2454,7 +2455,8 @@ namespace chaiscript } -#ifdef CHAISCRIPT_MSVC +#if defined(CHAISCRIPT_MSVC) && defined(CHAISCRIPT_PUSHED_MIN_MAX) +#undef CHAISCRIPT_PUSHED_MIN_MAX #pragma pop_macro("min") #pragma pop_macro("max") #endif From 41c1c490c8af4eabdf50b5078853d9ea5cb308bc Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Fri, 29 Apr 2016 08:31:59 -0600 Subject: [PATCH 7/7] Add support for *& return types --- .../chaiscript/dispatchkit/handle_return.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/chaiscript/dispatchkit/handle_return.hpp b/include/chaiscript/dispatchkit/handle_return.hpp index 2650e3b7..58bfafb7 100644 --- a/include/chaiscript/dispatchkit/handle_return.hpp +++ b/include/chaiscript/dispatchkit/handle_return.hpp @@ -115,6 +115,24 @@ namespace chaiscript } }; + template + struct Handle_Return + { + static Boxed_Value handle(Ret *p) + { + return Boxed_Value(p, true); + } + }; + + template + struct Handle_Return + { + static Boxed_Value handle(const Ret *p) + { + return Boxed_Value(p, true); + } + }; + template struct Handle_Return {