@@ -25,7 +25,6 @@
2525 #define assert(x)
2626#endif
2727
28−#include <memory>
2928#include <functional>
3029#include <string>
3130#include <vector>
@@ -33,6 +32,7 @@
3332#include <utility>
3433#include <stdexcept>
3534#include <iso646.h> // mostly for MS Visual Studio compiler
35+#include "PureScript_GC.hh"
3636
3737namespace PureScript {
3838
@@ -80,12 +80,13 @@ class any {
8080 };
8181 static constexpr as_thunk unthunk = as_thunk{};
8282
83− using map = std::vector<std::pair<const char * const, const any>>;
84− using data = std::vector<any>;
85− using array = std::deque<any>;
86− using fn = auto (*)(const any&) -> any;
87− using eff_fn = auto (*)() -> any;
88− using thunk = auto (*)(const as_thunk) -> const any&;
83+ using map_pair = std::pair<const char * const, const any>;
84+ using map = std::vector<map_pair WITH_ALLOCATOR(map_pair)>;
85+ using data = std::vector<any WITH_ALLOCATOR(any)>;
86+ using array = std::deque<any WITH_ALLOCATOR(any)>;
87+ using fn = auto (*)(const any&) -> any;
88+ using eff_fn = auto (*)() -> any;
89+ using thunk = auto (*)(const as_thunk) -> const any&;
8990
9091 private:
9192 class closure {
@@ -122,11 +123,11 @@ class any {
122123
123124 public:
124125 template <typename T>
125− using shared = std::shared_ptr<T>;
126+ using shared = SHARED_TYPE(T);
126127
127128 template <typename T, typename... Args>
128− inline static auto make_shared(Args&&... args) -> decltype(std::make_shared<T>(std::forward<Args>(args)...)) {
129− return std::make_shared<T>(std::forward<Args>(args)...);
129+ inline static auto make_shared(Args&&... args) -> SHARED_TYPE(T) {
130+ return MAKE_SHARED(T)(std::forward<Args>(args)...);
130131 }
131132
132133 private:
@@ -201,8 +202,9 @@ class any {
201202 any(const T& val, typename std::enable_if<std::is_convertible<T,thunk>::value>::type* = 0) noexcept
202203 : type(Type::Thunk), t(val) {}
203204
204− template <typename T>
205− any(const T& val, typename std::enable_if<std::is_assignable<shared<void>,T>::value>::type* = 0) noexcept
205+ template <typename T,
206+ typename = typename std::enable_if<std::is_class<typename std::remove_pointer<T>::type>::value>::type>
207+ any(const T& val, typename std::enable_if<IS_POINTER_TYPE(T)::value>::type* = 0) noexcept
206208 : type(Type::Pointer), p(val) {}
207209
208210 template <typename T>
@@ -211,8 +213,9 @@ class any {
211213
212214 any(std::nullptr_t) noexcept : type(Type::Pointer), p(nullptr) {}
213215
214− private:
215216
217+#if !defined(USE_GC)
218+ private:
216219 auto copy(const any& other) const noexcept -> void {
217220 if (type & Type::Shared) {
218221 new (&p) shared<void>(other.p);
@@ -236,7 +239,6 @@ class any {
236239 }
237240
238241 public:
239−
240242 any(const any& other) noexcept : type(other.type) {
241243 copy(other);
242244 }
@@ -259,11 +261,13 @@ class any {
259261 return *this;
260262 }
261263
262− any() = delete;
263−
264264 ~any() {
265265 destruct();
266266 }
267+#endif // !defined(USE_GC)
268+
269+ public:
270+ any() = delete;
267271
268272 auto operator()(const any&) const -> any;
269273 auto operator()(const as_thunk) const -> const any&;
@@ -384,6 +388,10 @@ inline auto cast(const any& a) ->
384388
385389} // namespace PureScript
386390
391+#undef WITH_ALLOCATOR
392+#undef SHARED_TYPE
393+#undef MAKE_SHARED
394+#undef IS_POINTER_TYPE
387395#undef DEFINE_OPERATOR
388396#undef DEFINE_INT_OPERATOR
389397#undef DECLARE_COMPARISON_OPERATOR