git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: make thunks function pointers instead of std::function
commitc9cce9b5fe9e156df694643e5a52a160db07bc88 authorAndy Arvanitis <andyarvanitis@gmail.com> dateThu 14 Jan 2016, 20:27 (11 years ago) parent0ce22bc
2 files changed+7−7
pcc/include/purescript.cc+3−3 pcc/include/purescript.hh+4−4
pcc/include/purescript.cc+3−3
@@ -28,7 +28,7 @@ namespace PureScript {
2828 case Type::Vector: new (&v) shared<vector> (src.v); break; \
2929 case Type::Function: new (&f) shared<fn> (src.f); break; \
3030 case Type::EffFunction: new (&e) shared<eff_fn> (src.e); break; \
31− case Type::Thunk: new (&t) shared<thunk> (src.t); break; \
31+ case Type::Thunk: t = src.t; break; \
3232 case Type::Pointer: new (&p) shared<void> (src.p); break; \
3333 \
3434 default: assert(false && "Unsupported type in copy"); \
@@ -46,7 +46,7 @@ namespace PureScript {
4646 case Type::Vector: new (&v) shared<vector> (std::move(src.v)); break; \
4747 case Type::Function: new (&f) shared<fn> (std::move(src.f)); break; \
4848 case Type::EffFunction: new (&e) shared<eff_fn> (std::move(src.e)); break; \
49− case Type::Thunk: new (&t) shared<thunk> (std::move(src.t)); break; \
49+ case Type::Thunk: t = src.t; break; \
5050 case Type::Pointer: new (&p) shared<void> (std::move(src.p)); break; \
5151 \
5252 default: assert(false && "Unsupported type in move"); \
@@ -88,7 +88,7 @@ any::~any() {
8888 case Type::Vector: v.~shared<vector>(); break;
8989 case Type::Function: f.~shared<fn>(); break;
9090 case Type::EffFunction: e.~shared<eff_fn>(); break;
91− case Type::Thunk: t.~shared<thunk>(); break;
91+ case Type::Thunk: ; break;
9292 case Type::Pointer: p.~shared<void>(); break;
9393
9494 default: assert(false && "Unsupported type in destructor");
pcc/include/purescript.hh+4−4
@@ -71,7 +71,7 @@ class any {
7171 using vector = std::vector<any>;
7272 using fn = std::function<any(const any&)>;
7373 using eff_fn = std::function<any()>;
74− using thunk = std::function<const any& (const as_thunk)>;
74+ using thunk = auto (*)(const as_thunk) -> const any&;
7575
7676 template <typename T>
7777 using shared = std::shared_ptr<T>;
@@ -92,7 +92,7 @@ class any {
9292 mutable shared<vector> v;
9393 mutable shared<fn> f;
9494 mutable shared<eff_fn> e;
95− mutable shared<thunk> t;
95+ mutable thunk t;
9696 mutable shared<void> p;
9797 };
9898
@@ -126,8 +126,8 @@ class any {
126126 : type(Type::EffFunction), e(make_shared<eff_fn>(val)) {}
127127
128128 template <typename T>
129− any(const T& val, typename std::enable_if<std::is_assignable<thunk,T>::value>::type* = 0)
130− : type(Type::Thunk), t(make_shared<thunk>(val)) {}
129+ any(const T& val, typename std::enable_if<std::is_convertible<T,thunk>::value>::type* = 0)
130+ : type(Type::Thunk), t(val) {}
131131
132132 template <typename T>
133133 any(const T& val, typename std::enable_if<std::is_assignable<shared<void>,T>::value>::type* = 0)