Skip to content

Commit 5299eb0

Browse files
committed
---
yaml --- r: 4926 b: refs/heads/master c: b371891 h: refs/heads/master v: v3
1 parent c856e26 commit 5299eb0

File tree

3 files changed

+42
-28
lines changed

3 files changed

+42
-28
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 72d78e6a93829703f64bd59f502410bebe64ae91
2+
refs/heads/master: b371891c7c35f5d561a4847515e41014c652fa26

trunk/src/rt/rust_shape.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,21 @@ type_param::make(const type_desc **tydescs, unsigned n_tydescs,
4242
return ptrs;
4343
}
4444

45+
// Constructs type parameters from an object shape. This is a bit messy,
46+
// because it requires that the object shape have a specific format.
4547
type_param *
46-
type_param::from_obj_shape(const uint8_t *sp, arena &arena) {
47-
// TODO
48-
abort();
48+
type_param::from_obj_shape(const uint8_t *sp, ptr dp, arena &arena) {
49+
uint8_t shape = *sp++; assert(shape == SHAPE_STRUCT);
50+
get_u16_bump(sp); // Skip over the size.
51+
shape = *sp++; assert(shape == SHAPE_PTR);
52+
shape = *sp++; assert(shape == SHAPE_STRUCT);
53+
54+
unsigned n_tydescs = get_u16_bump(sp);
55+
56+
// Type descriptors start right after the reference count.
57+
const type_desc **descs = (const type_desc **)(dp + sizeof(uintptr_t));
58+
59+
return make(descs, n_tydescs, arena);
4960
}
5061

5162

trunk/src/rt/rust_shape.h

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,18 @@ const uint8_t SHAPE_OBJ = 19u;
4646
const uint8_t SHAPE_RES = 20u;
4747
const uint8_t SHAPE_VAR = 21u;
4848

49+
#ifdef _LP64
50+
const uint8_t SHAPE_PTR = SHAPE_U64;
51+
#else
52+
const uint8_t SHAPE_PTR = SHAPE_U32;
53+
#endif
54+
4955

5056
// Forward declarations
5157

5258
struct rust_obj;
5359
struct size_align;
60+
class ptr;
5461
class type_param;
5562

5663

@@ -129,6 +136,21 @@ struct tag_info {
129136
};
130137

131138

139+
// Utility functions
140+
141+
inline uint16_t
142+
get_u16(const uint8_t *addr) {
143+
return *reinterpret_cast<const uint16_t *>(addr);
144+
}
145+
146+
inline uint16_t
147+
get_u16_bump(const uint8_t *&addr) {
148+
uint16_t result = get_u16(addr);
149+
addr += sizeof(uint16_t);
150+
return result;
151+
}
152+
153+
132154
// Contexts
133155

134156
// The base context, an abstract class. We use the curiously recurring
@@ -166,8 +188,6 @@ class ctxt {
166188
protected:
167189
inline uint8_t peek() { return *sp; }
168190

169-
static inline uint16_t get_u16(const uint8_t *addr);
170-
static inline uint16_t get_u16_bump(const uint8_t *&addr);
171191
inline size_align get_size_align(const uint8_t *&addr);
172192

173193
private:
@@ -226,7 +246,8 @@ class type_param {
226246
const type_param *params; // subparameters
227247

228248
// Creates type parameters from an object shape description.
229-
static type_param *from_obj_shape(const uint8_t *sp, arena &arena);
249+
static type_param *from_obj_shape(const uint8_t *sp, ptr dp,
250+
arena &arena);
230251

231252
template<typename T>
232253
inline void set(ctxt<T> *cx) {
@@ -284,20 +305,6 @@ ctxt<T>::walk_reset(bool align) {
284305
sp = old_sp;
285306
}
286307

287-
template<typename T>
288-
uint16_t
289-
ctxt<T>::get_u16(const uint8_t *addr) {
290-
return *reinterpret_cast<const uint16_t *>(addr);
291-
}
292-
293-
template<typename T>
294-
uint16_t
295-
ctxt<T>::get_u16_bump(const uint8_t *&addr) {
296-
uint16_t result = get_u16(addr);
297-
addr += sizeof(uint16_t);
298-
return result;
299-
}
300-
301308
template<typename T>
302309
size_align
303310
ctxt<T>::get_size_align(const uint8_t *&addr) {
@@ -892,17 +899,13 @@ data<T,U>::walk_obj_contents(bool align, ptr &dp) {
892899
uint8_t *box_ptr = bump_dp<uint8_t *>(dp);
893900
type_desc *subtydesc =
894901
*reinterpret_cast<type_desc **>(box_ptr + sizeof(void *));
895-
ptr obj_closure_dp(*box_ptr + sizeof(void *));
902+
ptr obj_closure_dp(box_ptr + sizeof(void *));
896903

897-
// FIXME: Should be type_param::from_obj_shape() below.
898904
arena arena;
899-
type_param *params = type_param::from_tydesc(subtydesc, arena);
905+
type_param *params = type_param::from_obj_shape(subtydesc->shape,
906+
obj_closure_dp, arena);
900907
T sub(*static_cast<T *>(this), subtydesc->shape, params,
901908
subtydesc->shape_tables, obj_closure_dp);
902-
903-
print print(sub);
904-
print.walk(false);
905-
906909
sub.walk(true);
907910
}
908911

0 commit comments

Comments
 (0)