Skip to content

Commit 25b8b35

Browse files
committed
Finish compare glue for classes
This tests == and !=. I don't know what <, >, etc. should do. Closes #2601
1 parent 95feaee commit 25b8b35

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

src/rt/rust_shape.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ cmp::walk_struct2(const uint8_t *end_sp) {
356356

357357
void
358358
cmp::walk_res2(const rust_fn *dtor, const uint8_t *end_sp) {
359-
abort(); // TODO
359+
return cmp_two_pointers();
360360
}
361361

362362
void

src/rustc/middle/trans/shape.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> [u8] {
334334
let mut s = if option::is_some(m_dtor_did) {
335335
[shape_res]
336336
}
337-
else { [shape_struct] };
337+
else { [shape_struct] }, sub = [];
338338
option::iter(m_dtor_did) {|dtor_did|
339339
let ri = @{did: dtor_did, parent_id: some(did), tps: tps};
340340
let id = interner::intern(ccx.shape_cx.resources, ri);
@@ -345,8 +345,9 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> [u8] {
345345
add_u16(s, 0_u16);
346346
};
347347
for ty::class_items_as_mutable_fields(ccx.tcx, did, substs).each {|f|
348-
add_substr(s, shape_of(ccx, f.mt.ty));
348+
sub += shape_of(ccx, f.mt.ty);
349349
}
350+
add_substr(s, sub);
350351
s
351352
}
352353
ty::ty_rptr(_, mt) {

src/test/run-pass/binops.rs

+24-4
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,11 @@ fn test_box() {
6060
}
6161

6262
fn test_port() {
63-
// FIXME: Re-enable this once we can compare resources. (#2601)
64-
/*
6563
let p1 = comm::port::<int>();
6664
let p2 = comm::port::<int>();
6765

6866
assert (p1 == p1);
6967
assert (p1 != p2);
70-
*/
7168
}
7269

7370
fn test_chan() {
@@ -98,7 +95,7 @@ fn test_ptr() unsafe {
9895
fn test_fn() {
9996
fn f() { }
10097
fn g() { }
101-
fn h(i: int) { }
98+
fn h(_i: int) { }
10299
let f1 = f;
103100
let f2 = f;
104101
let g1 = g;
@@ -128,6 +125,28 @@ fn test_native_fn() {
128125
assert test::unsupervise == test::unsupervise;
129126
}
130127

128+
class p {
129+
let mut x: int;
130+
let mut y: int;
131+
new(x: int, y: int) { self.x = x; self.y = y; }
132+
}
133+
134+
fn test_class() {
135+
let q = p(1, 2);
136+
let r = p(1, 2);
137+
138+
unsafe {
139+
#error("q = %x, r = %x",
140+
(unsafe::reinterpret_cast::<*p, uint>(ptr::addr_of(q))),
141+
(unsafe::reinterpret_cast::<*p, uint>(ptr::addr_of(r))));
142+
}
143+
assert(q == r);
144+
r.y = 17;
145+
assert(r.y != q.y);
146+
assert(r.y == 17);
147+
assert(q != r);
148+
}
149+
131150
fn main() {
132151
test_nil();
133152
test_bool();
@@ -138,4 +157,5 @@ fn main() {
138157
test_ptr();
139158
test_fn();
140159
test_native_fn();
160+
test_class();
141161
}

0 commit comments

Comments
 (0)