@@ -25,7 +25,6 @@
25 #define assert(x)
25 #define assert(x)
29#include <functional>
28#include <functional>
30#include <string>
29#include <string>
31#include <vector>
30#include <vector>
@@ -33,6 +32,7 @@
33#include <utility>
32#include <utility>
34#include <stdexcept>
33#include <stdexcept>
35#include <iso646.h> // mostly for MS Visual Studio compiler
34#include <iso646.h> // mostly for MS Visual Studio compiler
35+#include "PureScript_GC.hh"
37namespace PureScript {
37namespace PureScript {
@@ -80,12 +80,13 @@ class any {
81 static constexpr as_thunk unthunk = as_thunk{};
81 static constexpr as_thunk unthunk = as_thunk{};
83− using map = std::vector<std::pair<const char * const, const any>>;
83+ using map_pair = std::pair<const char * const, const any>;
84+ using map = std::vector<map_pair WITH_ALLOCATOR(map_pair)>;
84− using data = std::vector<any>;
85+ using data = std::vector<any WITH_ALLOCATOR(any)>;
85− using array = std::deque<any>;
86+ using array = std::deque<any WITH_ALLOCATOR(any)>;
86− using fn = auto (*)(const any&) -> any;
87+ using fn = auto (*)(const any&) -> any;
87− using eff_fn = auto (*)() -> any;
88+ using eff_fn = auto (*)() -> any;
88− using thunk = auto (*)(const as_thunk) -> const any&;
89+ using thunk = auto (*)(const as_thunk) -> const any&;
91 class closure {
92 class closure {
@@ -122,11 +123,11 @@ class any {
124 template <typename T>
125 template <typename T>
125− using shared = std::shared_ptr<T>;
126+ using shared = SHARED_TYPE(T);
127 template <typename T, typename... Args>
128 template <typename T, typename... Args>
128− inline static auto make_shared(Args&&... args) -> decltype(std::make_shared<T>(std::forward<Args>(args)...)) {
129+ inline static auto make_shared(Args&&... args) -> SHARED_TYPE(T) {
129− return std::make_shared<T>(std::forward<Args>(args)...);
130+ return MAKE_SHARED(T)(std::forward<Args>(args)...);
@@ -201,8 +202,9 @@ class any {
201 any(const T& val, typename std::enable_if<std::is_convertible<T,thunk>::value>::type* = 0) noexcept
202 any(const T& val, typename std::enable_if<std::is_convertible<T,thunk>::value>::type* = 0) noexcept
202 : type(Type::Thunk), t(val) {}
203 : type(Type::Thunk), t(val) {}
204− template <typename T>
205+ template <typename T,
206+ typename = typename std::enable_if<std::is_class<typename std::remove_pointer<T>::type>::value>::type>
205− any(const T& val, typename std::enable_if<std::is_assignable<shared<void>,T>::value>::type* = 0) noexcept
207+ any(const T& val, typename std::enable_if<IS_POINTER_TYPE(T)::value>::type* = 0) noexcept
206 : type(Type::Pointer), p(val) {}
208 : type(Type::Pointer), p(val) {}
208 template <typename T>
210 template <typename T>
@@ -211,8 +213,9 @@ class any {
212 any(std::nullptr_t) noexcept : type(Type::Pointer), p(nullptr) {}
214 any(std::nullptr_t) noexcept : type(Type::Pointer), p(nullptr) {}
216 auto copy(const any& other) const noexcept -> void {
219 auto copy(const any& other) const noexcept -> void {
217 if (type & Type::Shared) {
220 if (type & Type::Shared) {
218 new (&p) shared<void>(other.p);
221 new (&p) shared<void>(other.p);
@@ -236,7 +239,6 @@ class any {
240 any(const any& other) noexcept : type(other.type) {
242 any(const any& other) noexcept : type(other.type) {
241 copy(other);
243 copy(other);
@@ -259,11 +261,13 @@ class any {
259 return *this;
261 return *this;
265 destruct();
265 destruct();
267+#endif // !defined(USE_GC)
268 auto operator()(const any&) const -> any;
272 auto operator()(const any&) const -> any;
269 auto operator()(const as_thunk) const -> const any&;
273 auto operator()(const as_thunk) const -> const any&;
@@ -384,6 +388,10 @@ inline auto cast(const any& a) ->
385} // namespace PureScript
389} // namespace PureScript
391+#undef WITH_ALLOCATOR
394+#undef IS_POINTER_TYPE
387#undef DEFINE_OPERATOR
395#undef DEFINE_OPERATOR
388#undef DEFINE_INT_OPERATOR
396#undef DEFINE_INT_OPERATOR
389#undef DECLARE_COMPARISON_OPERATOR
397#undef DECLARE_COMPARISON_OPERATOR