Skip to content

Commit aa2ab26

Browse files
committed
Add core::reflect, start migrating core::repr to use it. Tidy up various Repr types.
1 parent 1c5db46 commit aa2ab26

File tree

9 files changed

+925
-48
lines changed

9 files changed

+925
-48
lines changed

src/libcore/at_vec.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pure fn capacity<T>(&&v: @[const T]) -> uint {
3030
unsafe {
3131
let repr: **unsafe::VecRepr =
3232
::unsafe::reinterpret_cast(&addr_of(v));
33-
(**repr).alloc / sys::size_of::<T>()
33+
(**repr).unboxed.alloc / sys::size_of::<T>()
3434
}
3535
}
3636

@@ -155,14 +155,14 @@ mod unsafe {
155155
#[inline(always)]
156156
unsafe fn set_len<T>(&&v: @[const T], new_len: uint) {
157157
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
158-
(**repr).fill = new_len * sys::size_of::<T>();
158+
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
159159
}
160160

161161
#[inline(always)]
162162
unsafe fn push<T>(&v: @[const T], +initval: T) {
163163
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
164-
let fill = (**repr).fill;
165-
if (**repr).alloc > fill {
164+
let fill = (**repr).unboxed.fill;
165+
if (**repr).unboxed.alloc > fill {
166166
push_fast(v, move initval);
167167
}
168168
else {
@@ -173,9 +173,9 @@ mod unsafe {
173173
#[inline(always)] // really pretty please
174174
unsafe fn push_fast<T>(&v: @[const T], +initval: T) {
175175
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
176-
let fill = (**repr).fill;
177-
(**repr).fill += sys::size_of::<T>();
178-
let p = ptr::addr_of((**repr).data);
176+
let fill = (**repr).unboxed.fill;
177+
(**repr).unboxed.fill += sys::size_of::<T>();
178+
let p = ptr::addr_of((**repr).unboxed.data);
179179
let p = ptr::offset(p, fill) as *mut T;
180180
rusti::move_val_init(*p, move initval);
181181
}

src/libcore/box.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,25 @@
55
#[forbid(deprecated_pattern)];
66

77
use cmp::{Eq, Ord};
8+
use intrinsic::TyDesc;
89

9-
export ptr_eq;
10+
export ptr_eq, raw;
11+
12+
mod raw {
13+
14+
struct BoxHeaderRepr {
15+
ref_count: uint,
16+
type_desc: *TyDesc,
17+
prev: *BoxRepr,
18+
next: *BoxRepr,
19+
}
20+
21+
struct BoxRepr {
22+
header: BoxHeaderRepr,
23+
data: u8
24+
}
25+
26+
}
1027

1128
pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
1229
//! Determine if two shared boxes point to the same object

src/libcore/cleanup.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,28 @@ pub unsafe fn annihilate() {
8080
let mut box: *mut BoxRepr = transmute(copy box);
8181
while box != mut_null() {
8282
debug!("making box immortal: %x", box as uint);
83-
(*box).ref_count = 0x77777777;
84-
box = transmute(copy (*box).next);
83+
(*box).header.ref_count = 0x77777777;
84+
box = transmute(copy (*box).header.next);
8585
}
8686

8787
// Pass 2: Drop all boxes.
8888
let box = (*task).boxed_region.live_allocs;
8989
let mut box: *mut BoxRepr = transmute(copy box);
9090
while box != mut_null() {
9191
debug!("calling drop glue for box: %x", box as uint);
92-
let tydesc: *TypeDesc = transmute(copy (*box).type_desc);
92+
let tydesc: *TypeDesc = transmute(copy (*box).header.type_desc);
9393
let drop_glue: DropGlue = transmute(((*tydesc).drop_glue, 0));
9494
drop_glue(to_unsafe_ptr(&tydesc), transmute(&(*box).data));
9595

96-
box = transmute(copy (*box).next);
96+
box = transmute(copy (*box).header.next);
9797
}
9898

9999
// Pass 3: Free all boxes.
100100
loop {
101101
let box = (*task).boxed_region.live_allocs;
102102
if box == null() { break; }
103103
let mut box: *mut BoxRepr = transmute(copy box);
104-
assert (*box).prev == null();
104+
assert (*box).header.prev == null();
105105

106106
debug!("freeing box: %x", box as uint);
107107
rt_free(transmute(box));

src/libcore/core.rc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export unit;
6363
export uniq;
6464
export repr;
6565
export cleanup;
66+
export reflect;
6667

6768
// NDM seems to be necessary for resolve to work
6869
export option_iter;
@@ -230,6 +231,7 @@ mod mutable;
230231
mod flate;
231232
mod repr;
232233
mod cleanup;
234+
mod reflect;
233235

234236
// Modules supporting compiler-generated code
235237
// Exported but not part of the public interface

0 commit comments

Comments
 (0)