@@ -17,7 +17,6 @@
17namespace PureScript {
17namespace PureScript {
19#define COPY_DATA(src) \
19#define COPY_DATA(src) \
21 switch (type) { \
20 switch (type) { \
22 case Type::Integer: i = src.i; break; \
21 case Type::Integer: i = src.i; break; \
23 case Type::Double: d = src.d; break; \
22 case Type::Double: d = src.d; break; \
@@ -37,7 +36,6 @@ namespace PureScript {
39#define MOVE_DATA(src) \
38#define MOVE_DATA(src) \
41 switch (type) { \
39 switch (type) { \
42 case Type::Integer: i = src.i; break; \
40 case Type::Integer: i = src.i; break; \
43 case Type::Double: d = src.d; break; \
41 case Type::Double: d = src.d; break; \
@@ -56,32 +54,34 @@ namespace PureScript {
56 default: assert(false && "Unsupported type in move"); \
54 default: assert(false && "Unsupported type in move"); \
59−any::any(const any& other) {
57+any::any(const any& other) : type(other.type) {
60 COPY_DATA(other);
58 COPY_DATA(other);
63−any::any(any&& other) noexcept {
61+any::any(any&& other) noexcept : type(other.type) {
64 MOVE_DATA(other);
62 MOVE_DATA(other);
67auto any::operator=(const any& rhs) -> any& {
65auto any::operator=(const any& rhs) -> any& {
68 COPY_DATA(rhs);
67 COPY_DATA(rhs);
69 return *this;
68 return *this;
72// Takes ownership -- might need to reconsider this
71// Takes ownership -- might need to reconsider this
73auto any::operator=(any& rhs) noexcept -> any& {
72auto any::operator=(any& rhs) noexcept -> any& {
74 MOVE_DATA(rhs);
74 MOVE_DATA(rhs);
75 return *this;
75 return *this;
78auto any::operator=(any&& rhs) noexcept -> any& {
78auto any::operator=(any&& rhs) noexcept -> any& {
79 MOVE_DATA(rhs);
80 MOVE_DATA(rhs);
80 return *this;
81 return *this;
83any::~any() {
84any::~any() {
84− // std::cout << "destroy" << std::endl;
85 switch (type) {
85 switch (type) {
86 case Type::Integer: ; break;
86 case Type::Integer: ; break;
87 case Type::Double: ; break;
87 case Type::Double: ; break;
@@ -225,10 +225,6 @@ any::operator string() const {
225 return cast<string>();
225 return cast<string>();
228−any::operator std::string() const {
229− return cast<string>();
232any::operator const map&() const {
228any::operator const map&() const {
233 RETURN_VALUE(Type::Map, m, *)
229 RETURN_VALUE(Type::Map, m, *)
@@ -257,16 +253,38 @@ auto any::extractValue(const any& a) -> const any& {
257 return a;
253 return a;
260−auto any::operator[](const map_key_t& rhs) const -> const any& {
256+auto any::operator[](const char rhs[]) const -> const any& {
261− RETURN_VALUE(Type::Map, m->at(rhs),)
257+ const any& val = extractValue(*this);
258+ assert(val.type == Type::Map);
259+ for (any::map::const_iterator it = val.m->begin(), end = val.m->end(); it != end; ++it) {
260+ if (it->first == rhs || strcmp(it->first, rhs) == 0) {
264+ throw runtime_error("map key not found");
264auto any::operator[](const vector::size_type rhs) const -> const any& {
267auto any::operator[](const vector::size_type rhs) const -> const any& {
265− RETURN_VALUE(Type::Vector, v->at(rhs),)
268+ const any& val = extractValue(*this);
269+ assert(val.type == Type::Vector);
270+ return (*val.v)[rhs];
268auto any::operator[](const any& rhs) const -> const any& {
273auto any::operator[](const any& rhs) const -> const any& {
274+ const any& val = extractValue(*this);
275+ assert(val.type == Type::Vector);
269− RETURN_VALUE(Type::Vector, v->at(rhs.cast<long>()),)
276+ return (*val.v)[rhs.cast<long>()];
279+auto any::contains(const char key[]) const -> bool {
280+ const any& val = extractValue(*this);
281+ assert(val.type == Type::Map);
282+ for (any::map::const_iterator it = val.m->begin(), end = val.m->end(); it != end; ++it) {
283+ if (it->first == key || strcmp(it->first, key) == 0) {
272//-----------------------------------------------------------------------------
290//-----------------------------------------------------------------------------