From 0aeddb3673459969fdbb32018f9c59f603607cf5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 5 Aug 2011 18:47:12 -0700 Subject: [PATCH] rt: Stub compare glue --- src/rt/rust_shape.cpp | 82 +++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 22 deletions(-) diff --git a/src/rt/rust_shape.cpp b/src/rt/rust_shape.cpp index e33d70913f2..594c3138331 100644 --- a/src/rt/rust_shape.cpp +++ b/src/rt/rust_shape.cpp @@ -75,6 +75,14 @@ round_up(T size, size_t alignment) { return x; } +template +static inline T +bump_dp(uint8_t *dp) { + T x = *((T *)dp); + dp += sizeof(T); + return x; +} + // Utility classes @@ -125,6 +133,34 @@ struct tag_info { const type_param *params; // Array of type parameters. }; +template +class data_pair { +public: + T fst, snd; + inline void operator=(const T rhs) { fst = snd = rhs; } +}; + +class ptr_pair { +public: + uint8_t *fst, *snd; + + template + class data { typedef data_pair t; }; + + ptr_pair(uint8_t *in_fst, uint8_t *in_snd) : fst(in_fst), snd(in_snd) {} + + inline void operator=(uint8_t *rhs) { fst = snd = rhs; } + + inline ptr_pair operator+(size_t n) const { + return make(fst + n, snd + n); + } + + static inline ptr_pair make(uint8_t *fst, uint8_t *snd) { + ptr_pair self(fst, snd); + return self; + } +}; + // Contexts @@ -719,16 +755,15 @@ size_of::walk_ivec(bool align, bool is_pod, size_align &elem_sa) { // for methods that actually manipulate the data involved. #define DATA_SIMPLE(ty, call) \ - if (align) dp.align_to(sizeof(ty)); \ + if (align) dp = align_to(dp, sizeof(ty)); \ static_cast(this)->call; \ dp += sizeof(ty); -template -class data : public ctxt< data > { -private: - typename T::data_ptr dp; - +template +class data : public ctxt< data > { public: + U dp; + void walk_tag(bool align, tag_info &tinfo); void walk_ivec(bool align, bool is_pod, size_align &elem_sa); @@ -750,13 +785,13 @@ public: void walk_task(bool align) { DATA_SIMPLE(void *, walk_task(align)); } void walk_fn(bool align) { - if (align) dp.align_to(sizeof(void *)); + if (align) dp = align_to(dp, sizeof(void *)); static_cast(this)->walk_fn(align); dp += sizeof(void *) * 2; } void walk_obj(bool align) { - if (align) dp.align_to(sizeof(void *)); + if (align) dp = align_to(dp, sizeof(void *)); static_cast(this)->walk_obj(align); dp += sizeof(void *) * 2; } @@ -766,23 +801,20 @@ public: } template - void walk_number(bool align) { - DATA_SIMPLE(W, walk_number(align)); - } + void walk_number(bool align) { DATA_SIMPLE(W, walk_number(align)); } }; -template +template void -data::walk_ivec(bool align, bool is_pod, size_align &elem_sa) { +data::walk_ivec(bool align, bool is_pod, size_align &elem_sa) { if (!elem_sa.is_set()) elem_sa = size_of::get(*this); else if (elem_sa.alignment == 8) elem_sa.alignment = 4; // FIXME: This is an awful hack. // Get a pointer to the interior vector, and skip over it. - if (align) dp.align_to(ALIGNOF(rust_ivec *)); - typename T::data_ptr end_dp = dp + sizeof(rust_ivec) - sizeof(uintptr_t) + - elem_sa.size * 4; + if (align) dp = align_to(dp, ALIGNOF(rust_ivec *)); + U end_dp = dp + sizeof(rust_ivec) - sizeof(uintptr_t) + elem_sa.size * 4; // Call to the implementation. static_cast(this)->walk_ivec(align, is_pod, elem_sa); @@ -790,19 +822,19 @@ data::walk_ivec(bool align, bool is_pod, size_align &elem_sa) { dp = end_dp; } -template +template void -data::walk_tag(bool align, tag_info &tinfo) { +data::walk_tag(bool align, tag_info &tinfo) { size_of::compute_tag_size(tinfo); if (tinfo.variant_count > 1 && align) - dp.align_to(ALIGNOF(uint32_t)); + dp = align_to(dp, ALIGNOF(uint32_t)); - typename T::data_ptr end_dp = tinfo.tag_sa.size; + U end_dp = tinfo.tag_sa.size; - typename T::template data tag_variant; + typename U::template data::t tag_variant; if (tinfo.variant_count > 1) - tag_variant = dp.template get_bump(); + tag_variant = bump_dp(dp); else tag_variant = 0; @@ -820,5 +852,11 @@ class copy : public data { #endif + +// Structural comparison glue. + +class cmp : public data { +}; + } // end namespace shape