git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: make thunks function pointers instead of std::function
c9cce9bAndy Arvanitis
pcc/include/purescript.cc+3−3
@@ -28,7 +28,7 @@ namespace PureScript {
28 case Type::Vector: new (&v) shared<vector> (src.v); break; \
28 case Type::Vector: new (&v) shared<vector> (src.v); break; \
29 case Type::Function: new (&f) shared<fn> (src.f); break; \
29 case Type::Function: new (&f) shared<fn> (src.f); break; \
30 case Type::EffFunction: new (&e) shared<eff_fn> (src.e); break; \
30 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; \
32 case Type::Pointer: new (&p) shared<void> (src.p); break; \
32 case Type::Pointer: new (&p) shared<void> (src.p); break; \
33 \
33 \
34 default: assert(false && "Unsupported type in copy"); \
34 default: assert(false && "Unsupported type in copy"); \
@@ -46,7 +46,7 @@ namespace PureScript {
46 case Type::Vector: new (&v) shared<vector> (std::move(src.v)); break; \
46 case Type::Vector: new (&v) shared<vector> (std::move(src.v)); break; \
47 case Type::Function: new (&f) shared<fn> (std::move(src.f)); break; \
47 case Type::Function: new (&f) shared<fn> (std::move(src.f)); break; \
48 case Type::EffFunction: new (&e) shared<eff_fn> (std::move(src.e)); break; \
48 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; \
50 case Type::Pointer: new (&p) shared<void> (std::move(src.p)); break; \
50 case Type::Pointer: new (&p) shared<void> (std::move(src.p)); break; \
51 \
51 \
52 default: assert(false && "Unsupported type in move"); \
52 default: assert(false && "Unsupported type in move"); \
@@ -88,7 +88,7 @@ any::~any() {
88 case Type::Vector: v.~shared<vector>(); break;
88 case Type::Vector: v.~shared<vector>(); break;
89 case Type::Function: f.~shared<fn>(); break;
89 case Type::Function: f.~shared<fn>(); break;
90 case Type::EffFunction: e.~shared<eff_fn>(); break;
90 case Type::EffFunction: e.~shared<eff_fn>(); break;
91− case Type::Thunk: t.~shared<thunk>(); break;
91+ case Type::Thunk: ; break;
92 case Type::Pointer: p.~shared<void>(); break;
92 case Type::Pointer: p.~shared<void>(); break;
93
93
94 default: assert(false && "Unsupported type in destructor");
94 default: assert(false && "Unsupported type in destructor");
pcc/include/purescript.hh+4−4
@@ -71,7 +71,7 @@ class any {
71 using vector = std::vector<any>;
71 using vector = std::vector<any>;
72 using fn = std::function<any(const any&)>;
72 using fn = std::function<any(const any&)>;
73 using eff_fn = std::function<any()>;
73 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&;
75
75
76 template <typename T>
76 template <typename T>
77 using shared = std::shared_ptr<T>;
77 using shared = std::shared_ptr<T>;
@@ -92,7 +92,7 @@ class any {
92 mutable shared<vector> v;
92 mutable shared<vector> v;
93 mutable shared<fn> f;
93 mutable shared<fn> f;
94 mutable shared<eff_fn> e;
94 mutable shared<eff_fn> e;
95− mutable shared<thunk> t;
95+ mutable thunk t;
96 mutable shared<void> p;
96 mutable shared<void> p;
97 };
97 };
98
98
@@ -126,8 +126,8 @@ class any {
126 : type(Type::EffFunction), e(make_shared<eff_fn>(val)) {}
126 : type(Type::EffFunction), e(make_shared<eff_fn>(val)) {}
127
127
128 template <typename T>
128 template <typename T>
129− any(const T& val, typename std::enable_if<std::is_assignable<thunk,T>::value>::type* = 0)
129+ any(const T& val, typename std::enable_if<std::is_convertible<T,thunk>::value>::type* = 0)
130− : type(Type::Thunk), t(make_shared<thunk>(val)) {}
130+ : type(Type::Thunk), t(val) {}
131
131
132 template <typename T>
132 template <typename T>
133 any(const T& val, typename std::enable_if<std::is_assignable<shared<void>,T>::value>::type* = 0)
133 any(const T& val, typename std::enable_if<std::is_assignable<shared<void>,T>::value>::type* = 0)