Skip to content

Commit

Permalink
Finish compare glue for classes
Browse files Browse the repository at this point in the history
This tests == and !=. I don't know what <, >, etc. should do.
Closes #2601
  • Loading branch information
catamorphism committed Jun 25, 2012
1 parent 95feaee commit 25b8b35
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/rt/rust_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ cmp::walk_struct2(const uint8_t *end_sp) {

void
cmp::walk_res2(const rust_fn *dtor, const uint8_t *end_sp) {
abort(); // TODO
return cmp_two_pointers();
}

void
Expand Down
5 changes: 3 additions & 2 deletions src/rustc/middle/trans/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> [u8] {
let mut s = if option::is_some(m_dtor_did) {
[shape_res]
}
else { [shape_struct] };
else { [shape_struct] }, sub = [];
option::iter(m_dtor_did) {|dtor_did|
let ri = @{did: dtor_did, parent_id: some(did), tps: tps};
let id = interner::intern(ccx.shape_cx.resources, ri);
Expand All @@ -345,8 +345,9 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> [u8] {
add_u16(s, 0_u16);
};
for ty::class_items_as_mutable_fields(ccx.tcx, did, substs).each {|f|
add_substr(s, shape_of(ccx, f.mt.ty));
sub += shape_of(ccx, f.mt.ty);
}
add_substr(s, sub);
s
}
ty::ty_rptr(_, mt) {
Expand Down
28 changes: 24 additions & 4 deletions src/test/run-pass/binops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,11 @@ fn test_box() {
}

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

assert (p1 == p1);
assert (p1 != p2);
*/
}

fn test_chan() {
Expand Down Expand Up @@ -98,7 +95,7 @@ fn test_ptr() unsafe {
fn test_fn() {
fn f() { }
fn g() { }
fn h(i: int) { }
fn h(_i: int) { }
let f1 = f;
let f2 = f;
let g1 = g;
Expand Down Expand Up @@ -128,6 +125,28 @@ fn test_native_fn() {
assert test::unsupervise == test::unsupervise;
}

class p {
let mut x: int;
let mut y: int;
new(x: int, y: int) { self.x = x; self.y = y; }
}

fn test_class() {
let q = p(1, 2);
let r = p(1, 2);

unsafe {
#error("q = %x, r = %x",
(unsafe::reinterpret_cast::<*p, uint>(ptr::addr_of(q))),
(unsafe::reinterpret_cast::<*p, uint>(ptr::addr_of(r))));
}
assert(q == r);
r.y = 17;
assert(r.y != q.y);
assert(r.y == 17);
assert(q != r);
}

fn main() {
test_nil();
test_bool();
Expand All @@ -138,4 +157,5 @@ fn main() {
test_ptr();
test_fn();
test_native_fn();
test_class();
}

0 comments on commit 25b8b35

Please sign in to comment.