@@ -22,32 +22,32 @@ any::any(const any& val) : type(val.type) {
22 case Type::Double: d = val.d; break;
22 case Type::Double: d = val.d; break;
23 case Type::Character: c = val.c; break;
23 case Type::Character: c = val.c; break;
24 case Type::Boolean: b = val.b; break;
24 case Type::Boolean: b = val.b; break;
25− case Type::String: new (&s) shared_string (val.s); break;
25+ case Type::String: new (&s) shared<string> (val.s); break;
26− case Type::Map: new (&m) shared_map (val.m); break;
26+ case Type::Map: new (&m) shared<map> (val.m); break;
27− case Type::Vector: new (&v) shared_vector (val.v); break;
27+ case Type::Vector: new (&v) shared<vector> (val.v); break;
28− case Type::Function: new (&f) shared_fn (val.f); break;
28+ case Type::Function: new (&f) shared<fn> (val.f); break;
29− case Type::EffFunction: new (&e) shared_eff_fn (val.e); break;
29+ case Type::EffFunction: new (&e) shared<eff_fn> (val.e); break;
30− case Type::Thunk: new (&t) shared_thunk (val.t); break;
30+ case Type::Thunk: new (&t) shared<thunk> (val.t); break;
31− case Type::Pointer: new (&p) shared_void_ptr (val.p); break;
31+ case Type::Pointer: new (&p) shared<void> (val.p); break;
33 default: assert(false && "Unsupported type in copy ctor");
33 default: assert(false && "Unsupported type in copy ctor");
37−void any::swap(any&& val) {
37+void any::swap(any&& val) const {
38 type = val.type;
38 type = val.type;
39 switch (type) {
39 switch (type) {
40 case Type::Integer: i = val.i; break;
40 case Type::Integer: i = val.i; break;
41 case Type::Double: d = val.d; break;
41 case Type::Double: d = val.d; break;
42 case Type::Character: c = val.c; break;
42 case Type::Character: c = val.c; break;
43 case Type::Boolean: b = val.b; break;
43 case Type::Boolean: b = val.b; break;
44− case Type::String: new (&s) shared_string (std::move(val.s)); break;
44+ case Type::String: new (&s) shared<string> (std::move(val.s)); break;
45− case Type::Map: new (&m) shared_map (std::move(val.m)); break;
45+ case Type::Map: new (&m) shared<map> (std::move(val.m)); break;
46− case Type::Vector: new (&v) shared_vector (std::move(val.v)); break;
46+ case Type::Vector: new (&v) shared<vector> (std::move(val.v)); break;
47− case Type::Function: new (&f) shared_fn (std::move(val.f)); break;
47+ case Type::Function: new (&f) shared<fn> (std::move(val.f)); break;
48− case Type::EffFunction: new (&e) shared_eff_fn (std::move(val.e)); break;
48+ case Type::EffFunction: new (&e) shared<eff_fn> (std::move(val.e)); break;
49− case Type::Thunk: new (&t) shared_thunk (std::move(val.t)); break;
49+ case Type::Thunk: new (&t) shared<thunk> (std::move(val.t)); break;
50− case Type::Pointer: new (&p) shared_void_ptr (std::move(val.p)); break;
50+ case Type::Pointer: new (&p) shared<void> (std::move(val.p)); break;
52 default: assert(false && "Unsupported type in move ctor");
52 default: assert(false && "Unsupported type in move ctor");
@@ -60,13 +60,13 @@ any::~any() {
60 case Type::Double: ; break;
60 case Type::Double: ; break;
61 case Type::Character: ; break;
61 case Type::Character: ; break;
62 case Type::Boolean: ; break;
62 case Type::Boolean: ; break;
63− case Type::String: s.~shared_string(); break;
63+ case Type::String: s.~shared<string>(); break;
64− case Type::Map: m.~shared_map(); break;
64+ case Type::Map: m.~shared<map>(); break;
65− case Type::Vector: v.~shared_vector(); break;
65+ case Type::Vector: v.~shared<vector>(); break;
66− case Type::Function: f.~shared_fn(); break;
66+ case Type::Function: f.~shared<fn>(); break;
67− case Type::EffFunction: e.~shared_eff_fn(); break;
67+ case Type::EffFunction: e.~shared<eff_fn>(); break;
68− case Type::Thunk: t.~shared_thunk(); break;
68+ case Type::Thunk: t.~shared<thunk>(); break;
69− case Type::Pointer: p.~shared_void_ptr(); break;
69+ case Type::Pointer: p.~shared<void>(); break;
71 default: assert(false && "Unsupported type in destructor");
71 default: assert(false && "Unsupported type in destructor");
@@ -229,21 +229,21 @@ any::~any() {
230#define DEFINE_OPERATOR_LHS(K, T, OP, V, R, P) \
230#define DEFINE_OPERATOR_LHS(K, T, OP, V, R, P) \
231auto operator OP(const T lhs, const any& rhs_) -> R { \
231auto operator OP(const T lhs, const any& rhs_) -> R { \
232− auto& rhs = any::extract_value(rhs_); \
232+ const any& rhs = any::extract_value(rhs_); \
233 assert(rhs.type == any::Type::K); \
233 assert(rhs.type == any::Type::K); \
234 return lhs OP P(rhs.V); \
234 return lhs OP P(rhs.V); \
237#define DEFINE_OPERATOR_RHS(K, T, OP, V, R, P) \
237#define DEFINE_OPERATOR_RHS(K, T, OP, V, R, P) \
238auto any::operator OP(const T rhs) const -> R { \
238auto any::operator OP(const T rhs) const -> R { \
239− auto& lhs = any::extract_value(*this); \
239+ const any& lhs = any::extract_value(*this); \
240 assert(lhs.type == Type::K); \
240 assert(lhs.type == Type::K); \
241 return P(lhs.V) OP rhs; \
241 return P(lhs.V) OP rhs; \
244auto any::operator==(const any& rhs_) const -> bool {
244auto any::operator==(const any& rhs_) const -> bool {
245− auto& lhs = extract_value(*this);
245+ const any& lhs = extract_value(*this);
246− auto& rhs = extract_value(rhs_);
246+ const any& rhs = extract_value(rhs_);
247 assert(lhs.type == rhs.type);
247 assert(lhs.type == rhs.type);
248 switch (lhs.type) {
248 switch (lhs.type) {
249 case Type::Integer: return lhs.i == rhs.i;
249 case Type::Integer: return lhs.i == rhs.i;
@@ -265,8 +265,8 @@ DEFINE_OPERATOR_RHS(String, string&, ==, s, bool, *)
265DEFINE_OPERATOR_RHS(String, char* const, ==, s, bool, *)
265DEFINE_OPERATOR_RHS(String, char* const, ==, s, bool, *)
267auto any::operator!=(const any& rhs_) const -> bool {
267auto any::operator!=(const any& rhs_) const -> bool {
268− auto& lhs = extract_value(*this);
268+ const any& lhs = extract_value(*this);
269− auto& rhs = extract_value(rhs_);
269+ const any& rhs = extract_value(rhs_);
270 assert(lhs.type == rhs.type);
270 assert(lhs.type == rhs.type);
271 switch (lhs.type) {
271 switch (lhs.type) {
272 case Type::Integer: return lhs.i != rhs.i;
272 case Type::Integer: return lhs.i != rhs.i;
@@ -288,8 +288,8 @@ DEFINE_OPERATOR_RHS(String, string&, !=, s, bool, *)
288DEFINE_OPERATOR_RHS(String, char* const, !=, s, bool, *)
288DEFINE_OPERATOR_RHS(String, char* const, !=, s, bool, *)
290auto any::operator<(const any& rhs_) const -> bool {
290auto any::operator<(const any& rhs_) const -> bool {
291− auto& lhs = extract_value(*this);
291+ const any& lhs = extract_value(*this);
292− auto& rhs = extract_value(rhs_);
292+ const any& rhs = extract_value(rhs_);
293 assert(lhs.type == rhs.type);
293 assert(lhs.type == rhs.type);
294 switch (lhs.type) {
294 switch (lhs.type) {
295 case Type::Integer: return lhs.i < rhs.i;
295 case Type::Integer: return lhs.i < rhs.i;
@@ -310,8 +310,8 @@ DEFINE_OPERATOR_RHS(String, string&, <, s, bool, *)
310DEFINE_OPERATOR_RHS(String, char* const, <, s, bool, *)
310DEFINE_OPERATOR_RHS(String, char* const, <, s, bool, *)
312auto any::operator<=(const any& rhs_) const -> bool {
312auto any::operator<=(const any& rhs_) const -> bool {
313− auto& lhs = extract_value(*this);
313+ const any& lhs = extract_value(*this);
314− auto& rhs = extract_value(rhs_);
314+ const any& rhs = extract_value(rhs_);
315 assert(lhs.type == rhs.type);
315 assert(lhs.type == rhs.type);
316 switch (lhs.type) {
316 switch (lhs.type) {
317 case Type::Integer: return lhs.i <= rhs.i;
317 case Type::Integer: return lhs.i <= rhs.i;
@@ -332,8 +332,8 @@ DEFINE_OPERATOR_RHS(String, string&, <=, s, bool, *)
332DEFINE_OPERATOR_RHS(String, char* const, <=, s, bool, *)
332DEFINE_OPERATOR_RHS(String, char* const, <=, s, bool, *)
334auto any::operator>(const any& rhs_) const -> bool {
334auto any::operator>(const any& rhs_) const -> bool {
335− auto& lhs = extract_value(*this);
335+ const any& lhs = extract_value(*this);
336− auto& rhs = extract_value(rhs_);
336+ const any& rhs = extract_value(rhs_);
337 assert(lhs.type == rhs.type);
337 assert(lhs.type == rhs.type);
338 switch (lhs.type) {
338 switch (lhs.type) {
339 case Type::Integer: return lhs.i > rhs.i;
339 case Type::Integer: return lhs.i > rhs.i;
@@ -354,8 +354,8 @@ DEFINE_OPERATOR_RHS(String, string&, >, s, bool, *)
354DEFINE_OPERATOR_RHS(String, char* const, >, s, bool, *)
354DEFINE_OPERATOR_RHS(String, char* const, >, s, bool, *)
356auto any::operator>=(const any& rhs_) const -> bool {
356auto any::operator>=(const any& rhs_) const -> bool {
357− auto& lhs = extract_value(*this);
357+ const any& lhs = extract_value(*this);
358− auto& rhs = extract_value(rhs_);
358+ const any& rhs = extract_value(rhs_);
359 assert(lhs.type == rhs.type);
359 assert(lhs.type == rhs.type);
360 switch (lhs.type) {
360 switch (lhs.type) {
361 case Type::Integer: return lhs.i >= rhs.i;
361 case Type::Integer: return lhs.i >= rhs.i;
@@ -376,8 +376,8 @@ DEFINE_OPERATOR_RHS(String, string&, >=, s, bool, *)
376DEFINE_OPERATOR_RHS(String, char* const, >=, s, bool, *)
376DEFINE_OPERATOR_RHS(String, char* const, >=, s, bool, *)
378auto any::operator+(const any& rhs_) const -> any {
378auto any::operator+(const any& rhs_) const -> any {
379− auto& lhs = extract_value(*this);
379+ const any& lhs = extract_value(*this);
380− auto& rhs = extract_value(rhs_);
380+ const any& rhs = extract_value(rhs_);
381 assert(lhs.type == rhs.type);
381 assert(lhs.type == rhs.type);
382 switch (lhs.type) {
382 switch (lhs.type) {
383 case Type::Integer: return lhs.i + rhs.i;
383 case Type::Integer: return lhs.i + rhs.i;
@@ -396,8 +396,8 @@ DEFINE_OPERATOR_RHS(String, string&, +, s, string, *)
396DEFINE_OPERATOR_RHS(String, char* const, +, s, string, *)
396DEFINE_OPERATOR_RHS(String, char* const, +, s, string, *)
398auto any::operator-(const any& rhs_) const -> any {
398auto any::operator-(const any& rhs_) const -> any {
399− auto& lhs = extract_value(*this);
399+ const any& lhs = extract_value(*this);
400− auto& rhs = extract_value(rhs_);
400+ const any& rhs = extract_value(rhs_);
401 assert(lhs.type == rhs.type);
401 assert(lhs.type == rhs.type);
402 switch (lhs.type) {
402 switch (lhs.type) {
403 case Type::Integer: return lhs.i - rhs.i;
403 case Type::Integer: return lhs.i - rhs.i;
@@ -413,8 +413,8 @@ DEFINE_OPERATOR_RHS(Double, double, -, d, double,)
413DEFINE_OPERATOR_RHS(Character, char, -, c, char,)
413DEFINE_OPERATOR_RHS(Character, char, -, c, char,)
415auto any::operator*(const any& rhs_) const -> any {
415auto any::operator*(const any& rhs_) const -> any {
416− auto& lhs = extract_value(*this);
416+ const any& lhs = extract_value(*this);
417− auto& rhs = extract_value(rhs_);
417+ const any& rhs = extract_value(rhs_);
418 assert(lhs.type == rhs.type);
418 assert(lhs.type == rhs.type);
419 switch (lhs.type) {
419 switch (lhs.type) {
420 case Type::Integer: return lhs.i * rhs.i;
420 case Type::Integer: return lhs.i * rhs.i;
@@ -428,8 +428,8 @@ DEFINE_OPERATOR_RHS(Integer, long, *, i, long,)
428DEFINE_OPERATOR_RHS(Double, double, *, d, double,)
428DEFINE_OPERATOR_RHS(Double, double, *, d, double,)
430auto any::operator/(const any& rhs_) const -> any {
430auto any::operator/(const any& rhs_) const -> any {
431− auto& lhs = extract_value(*this);
431+ const any& lhs = extract_value(*this);
432− auto& rhs = extract_value(rhs_);
432+ const any& rhs = extract_value(rhs_);
433 assert(lhs.type == rhs.type);
433 assert(lhs.type == rhs.type);
434 switch (lhs.type) {
434 switch (lhs.type) {
435 case Type::Integer: return lhs.i / rhs.i;
435 case Type::Integer: return lhs.i / rhs.i;
@@ -443,8 +443,8 @@ DEFINE_OPERATOR_RHS(Integer, long, /, i, long,)
443DEFINE_OPERATOR_RHS(Double, double, /, d, double,)
443DEFINE_OPERATOR_RHS(Double, double, /, d, double,)
445auto any::operator%(const any& rhs_) const -> any {
445auto any::operator%(const any& rhs_) const -> any {
446− auto& lhs = extract_value(*this);
446+ const any& lhs = extract_value(*this);
447− auto& rhs = extract_value(rhs_);
447+ const any& rhs = extract_value(rhs_);
448 assert(lhs.type == rhs.type);
448 assert(lhs.type == rhs.type);
449 switch (lhs.type) {
449 switch (lhs.type) {
450 case Type::Integer: return lhs.i % rhs.i;
450 case Type::Integer: return lhs.i % rhs.i;
@@ -456,7 +456,7 @@ auto any::operator%(const any& rhs_) const -> any {
456DEFINE_OPERATOR_RHS(Integer, long, %, i, long,)
456DEFINE_OPERATOR_RHS(Integer, long, %, i, long,)
458auto any::operator-() const -> any {
458auto any::operator-() const -> any {
459− auto& lhs = any::extract_value(*this);
459+ const any& lhs = any::extract_value(*this);
460 switch (lhs.type) {
460 switch (lhs.type) {
461 case Type::Integer: return (- lhs.i);
461 case Type::Integer: return (- lhs.i);
462 case Type::Double: return (- lhs.d);
462 case Type::Double: return (- lhs.d);