1
Fork 0

Remove uses of tuples from the test suite

This commit is contained in:
Marijn Haverbeke 2011-07-26 14:49:40 +02:00
parent aea537779e
commit f8968d1e71
51 changed files with 191 additions and 264 deletions

View file

@ -21,24 +21,24 @@ obj myrandom(mutable u32 last) {
} }
} }
type aminoacids = tup(char, u32); type aminoacids = rec(char ch, u32 prob);
fn make_cumulative(vec[aminoacids] aa) -> vec[aminoacids] { fn make_cumulative(vec[aminoacids] aa) -> vec[aminoacids] {
let u32 cp = 0u32; let u32 cp = 0u32;
let vec[aminoacids] ans = []; let vec[aminoacids] ans = [];
for (aminoacids a in aa) { cp += a._1; ans += [tup(a._0, cp)]; } for (aminoacids a in aa) { cp += a.prob; ans += [rec(ch=a.ch, prob=cp)]; }
ret ans; ret ans;
} }
fn select_random(u32 r, vec[aminoacids] genelist) -> char { fn select_random(u32 r, vec[aminoacids] genelist) -> char {
if (r < genelist.(0)._1) { ret genelist.(0)._0; } if (r < genelist.(0).prob) { ret genelist.(0).ch; }
fn bisect(vec[aminoacids] v, uint lo, uint hi, u32 target) -> char { fn bisect(vec[aminoacids] v, uint lo, uint hi, u32 target) -> char {
if (hi > lo + 1u) { if (hi > lo + 1u) {
let uint mid = lo + (hi - lo) / 2u; let uint mid = lo + (hi - lo) / 2u;
if (target < v.(mid)._1) { if (target < v.(mid).prob) {
be bisect(v, lo, mid, target); be bisect(v, lo, mid, target);
} else { be bisect(v, mid, hi, target); } } else { be bisect(v, mid, hi, target); }
} else { ret v.(hi)._0; } } else { ret v.(hi).ch; }
} }
ret bisect(genelist, 0u, vec::len[aminoacids](genelist) - 1u, r); ret bisect(genelist, 0u, vec::len[aminoacids](genelist) - 1u, r);
} }
@ -65,16 +65,18 @@ fn make_repeat_fasta(str id, str desc, str s, int n) {
if (str::byte_len(op) > 0u) { log op; } if (str::byte_len(op) > 0u) { log op; }
} }
fn acid(char ch, u32 prob) { ret rec(ch=ch, prob=prob); }
fn main(vec[str] args) { fn main(vec[str] args) {
let vec[aminoacids] iub = let vec[aminoacids] iub =
make_cumulative([tup('a', 27u32), tup('c', 12u32), tup('g', 12u32), make_cumulative([acid('a', 27u32), acid('c', 12u32), acid('g', 12u32),
tup('t', 27u32), tup('B', 2u32), tup('D', 2u32), acid('t', 27u32), acid('B', 2u32), acid('D', 2u32),
tup('H', 2u32), tup('K', 2u32), tup('M', 2u32), acid('H', 2u32), acid('K', 2u32), acid('M', 2u32),
tup('N', 2u32), tup('R', 2u32), tup('S', 2u32), acid('N', 2u32), acid('R', 2u32), acid('S', 2u32),
tup('V', 2u32), tup('W', 2u32), tup('Y', 2u32)]); acid('V', 2u32), acid('W', 2u32), acid('Y', 2u32)]);
let vec[aminoacids] homosapiens = let vec[aminoacids] homosapiens =
make_cumulative([tup('a', 30u32), tup('c', 20u32), tup('g', 20u32), make_cumulative([acid('a', 30u32), acid('c', 20u32), acid('g', 20u32),
tup('t', 30u32)]); acid('t', 30u32)]);
let str alu = let str alu =
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" + "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" + "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +

View file

@ -134,9 +134,10 @@ mod map_reduce {
map(input, bind emit(intermediates, ctrl, _, _)); map(input, bind emit(intermediates, ctrl, _, _));
for each(@tup(str, chan[reduce_proto]) kv in intermediates.items()) { for each(@rec(str key, chan[reduce_proto] val) kv
in intermediates.items()) {
// log_err "sending done to reducer for " + kv._0; // log_err "sending done to reducer for " + kv._0;
kv._1 <| release; kv.val <| release;
} }
ctrl <| mapper_done; ctrl <| mapper_done;
@ -228,9 +229,10 @@ mod map_reduce {
} }
} }
for each(@tup(str, chan[reduce_proto]) kv in reducers.items()) { for each(@rec(str key, chan[reduce_proto] val) kv
in reducers.items()) {
// log_err "sending done to reducer for " + kv._0; // log_err "sending done to reducer for " + kv._0;
kv._1 <| done; kv.val <| done;
} }
// log_err #fmt("joining %u tasks", ivec::len(tasks)); // log_err #fmt("joining %u tasks", ivec::len(tasks));

View file

@ -1,7 +1,7 @@
// xfail-stage0 // xfail-stage0
// error-pattern:+ cannot be applied to type `tup(bool)` // error-pattern:+ cannot be applied to type `rec(bool x)`
fn main() { fn main() {
auto x = tup(true); auto x = rec(x=true);
x += tup(false); x += rec(x=false);
} }

View file

@ -1,6 +1,6 @@
// xfail-stage0 // xfail-stage0
// error-pattern:+ cannot be applied to type `tup(bool)` // error-pattern:+ cannot be applied to type `rec(bool x)`
fn main() { fn main() {
auto x = tup(true) + tup(false); auto x = rec(x=true) + rec(x=false);
} }

View file

@ -9,9 +9,10 @@ type var_info = rec(uint a, uint b);
fn bitv_to_str(fn_info enclosing, bitv::t v) -> str { fn bitv_to_str(fn_info enclosing, bitv::t v) -> str {
auto s = ""; auto s = "";
// error is that the value type in the hash map is var_info, not a tuple // error is that the value type in the hash map is var_info, not a box
for each (@tup(uint, tup(uint, uint)) p in enclosing.vars.items()) { for each (@rec(uint key, @uint val) p
if (bitv::get(v, p._1._0)) { in enclosing.vars.items()) {
if (bitv::get(v, *p.val)) {
s += "foo"; s += "foo";
} }
} }

View file

@ -4,7 +4,7 @@
mod foo { mod foo {
fn bar[T](T f) -> int { ret 17; } fn bar[T](T f) -> int { ret 17; }
type bar[U, T] = tup(int, U, T); type bar[U, T] = rec(int a, U b, T c);
} }
fn main() {} fn main() {}

View file

@ -1,5 +0,0 @@
// error-pattern: assignment to immutable field
fn main() {
let tup(int) t = tup(1);
t._0 = 5;
}

View file

@ -4,12 +4,11 @@
// xfail-stage3 // xfail-stage3
// -*- rust -*- // -*- rust -*-
fn f(chan[int] c) fn f(chan[int] c) {
{ type t = rec(int _0, int _1, int _2);
type t = tup(int,int,int);
// Allocate a box. // Allocate a box.
let @t x = @tup(1,2,3); let @t x = @rec(_0=1, _1=2, _2=3);
// Signal parent that we've allocated a box. // Signal parent that we've allocated a box.
c <| 1; c <| 1;

View file

@ -2,6 +2,6 @@
// -*- rust -*- // -*- rust -*-
fn f[T, U](&T x, &U y) -> tup(T, U) { ret tup(x, y); } fn f[T, U](&T x, &U y) -> rec(T a, U b) { ret rec(a=x, b=y); }
fn main() { log f(tup(3, 4, 5), 4)._0._0; log f(5, 6)._0; } fn main() { log f(rec(x=3, y=4, z=5), 4).a.x; log f(5, 6).a; }

View file

@ -4,7 +4,7 @@
// -*- rust -*- // -*- rust -*-
type clam = rec(@int x, @int y); type clam = rec(@int x, @int y);
type fish = tup(@int); type fish = rec(@int a);
fn main() { fn main() {
let clam a = rec(x=@1, y=@2); let clam a = rec(x=@1, y=@2);
@ -12,9 +12,9 @@ fn main() {
let int z = a.x + b.y; let int z = a.x + b.y;
log z; log z;
assert (z == 21); assert (z == 21);
let fish forty = tup(@40); let fish forty = rec(a=@40);
let fish two = tup(@2); let fish two = rec(a=@2);
let int answer = forty._0 + two._0; let int answer = forty.a + two.a;
log answer; log answer;
assert (answer == 42); assert (answer == 42);
} }

View file

@ -54,7 +54,7 @@ fn test_char() {
fn test_box() { fn test_box() {
assert @10 == 10; assert @10 == 10;
assert 0xFF & @0xF0 == 0xF0; assert 0xFF & @0xF0 == 0xF0;
assert tup(1, 3) < @tup(1, 4); assert rec(a=1, b=3) < @rec(a=1, b=4);
assert @rec(a = 'x') != @rec(a = 'y'); assert @rec(a = 'x') != @rec(a = 'y');
} }

View file

@ -1,3 +0,0 @@
fn main() { let tup(mutable @int) i = tup(mutable @10); i._0 = @11; }

View file

@ -1,12 +1,12 @@
type box[T] = tup(@T); type box[T] = rec(@T c);
fn unbox[T](&box[T] b) -> T { ret *b._0; } fn unbox[T](&box[T] b) -> T { ret *b.c; }
fn main() { fn main() {
let int foo = 17; let int foo = 17;
let box[int] bfoo = tup(@foo); let box[int] bfoo = rec(c=@foo);
log "see what's in our box"; log "see what's in our box";
assert (unbox[int](bfoo) == foo); assert (unbox[int](bfoo) == foo);
} }

View file

@ -15,12 +15,12 @@ fn test_bool() {
test_generic[bool](true, eq); test_generic[bool](true, eq);
} }
fn test_tup() { fn test_rec() {
type t = tup(int, int); type t = rec(int a, int b);
fn compare_tup(&t t1, &t t2) -> bool { ret t1 == t2; } fn compare_rec(&t t1, &t t2) -> bool { ret t1 == t2; }
auto eq = bind compare_tup(_, _); auto eq = bind compare_rec(_, _);
test_generic[t](tup(1, 2), eq); test_generic[t](rec(a=1, b=2), eq);
} }
fn main() { test_bool(); test_tup(); } fn main() { test_bool(); test_rec(); }

View file

@ -17,12 +17,12 @@ fn test_bool() {
test_generic[bool](true, eq); test_generic[bool](true, eq);
} }
fn test_tup() { fn test_rec() {
type t = tup(int, int); type t = rec(int a, int b);
fn compare_tup(&t t1, &t t2) -> bool { ret t1 == t2; } fn compare_rec(&t t1, &t t2) -> bool { ret t1 == t2; }
auto eq = bind compare_tup(_, _); auto eq = bind compare_rec(_, _);
test_generic[t](tup(1, 2), eq); test_generic[t](rec(a=1, b=2), eq);
} }
fn main() { test_bool(); test_tup(); } fn main() { test_bool(); test_rec(); }

View file

@ -5,8 +5,8 @@
// Regression test for issue #377 // Regression test for issue #377
fn main() { fn main() {
auto a = { auto b = tup(3); b }; auto a = { auto b = rec(a=3); b };
assert (a._0 == 3); assert (a.a == 3);
auto c = { auto d = rec(v=3); d }; auto c = { auto d = rec(v=3); d };
assert (c.v == 3); assert (c.v == 3);
} }

View file

@ -17,12 +17,12 @@ fn test_bool() {
test_generic[bool](true, false, eq); test_generic[bool](true, false, eq);
} }
fn test_tup() { fn test_rec() {
type t = tup(int, int); type t = rec(int a, int b);
fn compare_tup(&t t1, &t t2) -> bool { ret t1 == t2; } fn compare_rec(&t t1, &t t2) -> bool { ret t1 == t2; }
auto eq = bind compare_tup(_, _); auto eq = bind compare_rec(_, _);
test_generic[t](tup(1, 2), tup(2, 3), eq); test_generic[t](rec(a=1, b=2), rec(a=2, b=3), eq);
} }
fn main() { test_bool(); test_tup(); } fn main() { test_bool(); test_rec(); }

View file

@ -1,9 +1,9 @@
obj ob[K](K k) { obj ob[K](K k) {
iter foo() -> @tup(K) { put @tup(k); } iter foo() -> @rec(K a) { put @rec(a=k); }
} }
fn x(&ob[str] o) { for each (@tup(str) i in o.foo()) { } } fn x(&ob[str] o) { for each (@rec(str a) i in o.foo()) { } }
fn main() { auto o = ob[str]("hi" + "there"); x(o); } fn main() { auto o = ob[str]("hi" + "there"); x(o); }

View file

@ -1,15 +1,15 @@
iter pairs() -> tup(int, int) { iter pairs() -> rec(int _0, int _1) {
let int i = 0; let int i = 0;
let int j = 0; let int j = 0;
while (i < 10) { put tup(i, j); i += 1; j += i; } while (i < 10) { put rec(_0=i, _1=j); i += 1; j += i; }
} }
fn main() { fn main() {
let int i = 10; let int i = 10;
let int j = 0; let int j = 0;
for each (tup(int, int) p in pairs()) { for each (rec(int _0, int _1) p in pairs()) {
log p._0; log p._0;
log p._1; log p._1;
assert (p._0 + 10 == i); assert (p._0 + 10 == i);

View file

@ -3,8 +3,8 @@
fn id[T](&T t) -> T { ret t; } fn id[T](&T t) -> T { ret t; }
fn main() { fn main() {
auto t = tup(1, 2, 3, 4, 5, 6, 7); auto t = rec(a=1, b=2, c=3, d=4, e=5, f=6, g=7);
assert (t._5 == 6); assert (t.f == 6);
auto f0 = bind id[tup(int, int, int, int, int, int, int)](t); auto f0 = bind id(t);
assert (f0()._5 == 6); assert (f0().f == 6);
} }

View file

@ -3,8 +3,9 @@
fn id[T](&T t) -> T { ret t; } fn id[T](&T t) -> T { ret t; }
fn main() { fn main() {
auto t = tup(1, 2, 3, 4, 5, 6, 7); auto t = rec(_0=1, _1=2, _2=3, _3=4, _4=5, _5=6, _6=7);
assert (t._5 == 6); assert (t._5 == 6);
auto f1 = bind id[tup(int, int, int, int, int, int, int)](_); auto f1 = bind id[rec(int _0, int _1, int _2, int _3, int _4,
int _5, int _6)](_);
assert (f1(t)._5 == 6); assert (f1(t)._5 == 6);
} }

View file

@ -1,8 +1,8 @@
fn box[T](&tup(T, T, T) x) -> @tup(T, T, T) { ret @x; } fn box[T](&rec(T x, T y, T z) x) -> @rec(T x, T y, T z) { ret @x; }
fn main() { fn main() {
let @tup(int, int, int) x = box[int](tup(1, 2, 3)); let @rec(int x, int y, int z) x = box[int](rec(x=1, y=2, z=3));
assert (x._1 == 2); assert (x.y == 2);
} }

View file

@ -2,17 +2,17 @@
fn g[X](&X x) -> X { ret x; } fn g[X](&X x) -> X { ret x; }
fn f[T](&T t) -> tup(T, T) { fn f[T](&T t) -> rec(T a, T b) {
type pair = tup(T, T); type pair = rec(T a, T b);
let pair x = tup(t, t); let pair x = rec(a=t, b=t);
ret g[pair](x); ret g[pair](x);
} }
fn main() { fn main() {
auto b = f[int](10); auto b = f[int](10);
log b._0; log b.a;
log b._1; log b.b;
assert (b._0 == 10); assert (b.a == 10);
assert (b._1 == 10); assert (b.b == 10);
} }

View file

@ -1,17 +1,11 @@
type tupbox[T] = tup(@T);
type recbox[T] = rec(@T x); type recbox[T] = rec(@T x);
fn tuplift[T](&T t) -> tupbox[T] { ret tup(@t); }
fn reclift[T](&T t) -> recbox[T] { ret rec(x=@t); } fn reclift[T](&T t) -> recbox[T] { ret rec(x=@t); }
fn main() { fn main() {
let int foo = 17; let int foo = 17;
let tupbox[int] tbfoo = tuplift[int](foo);
let recbox[int] rbfoo = reclift[int](foo); let recbox[int] rbfoo = reclift[int](foo);
assert (tbfoo._0 == foo);
assert (rbfoo.x == foo); assert (rbfoo.x == foo);
} }

View file

@ -4,15 +4,15 @@
// -*- rust -*- // -*- rust -*-
fn id[T](&T x) -> T { ret x; } fn id[T](&T x) -> T { ret x; }
type triple = tup(int, int, int); type triple = rec(int x, int y, int z);
fn main() { fn main() {
auto x = 62; auto x = 62;
auto y = 63; auto y = 63;
auto a = 'a'; auto a = 'a';
auto b = 'b'; auto b = 'b';
let triple p = tup(65, 66, 67); let triple p = rec(x=65, y=66, z=67);
let triple q = tup(68, 69, 70); let triple q = rec(x=68, y=69, z=70);
y = id[int](x); y = id[int](x);
log y; log y;
assert (x == y); assert (x == y);
@ -20,8 +20,8 @@ fn main() {
log b; log b;
assert (a == b); assert (a == b);
q = id[triple](p); q = id[triple](p);
x = p._2; x = p.z;
y = q._2; y = q.z;
log y; log y;
assert (x == y); assert (x == y);
} }

View file

@ -5,14 +5,16 @@ obj handle[T](T data) {
} }
fn main() { fn main() {
type rgb = tup(u8, u8, u8); type rgb = rec(u8 x, u8 y, u8 z);
let handle[rgb] h = handle[rgb](tup(1 as u8, 2 as u8, 3 as u8)); let handle[rgb] h = handle[rgb](rec(x=1 as u8,
y=2 as u8,
z=3 as u8));
log "constructed object"; log "constructed object";
log h.get()._0; log h.get().x;
log h.get()._1; log h.get().y;
log h.get()._2; log h.get().z;
assert (h.get()._0 == 1 as u8); assert (h.get().x == 1 as u8);
assert (h.get()._1 == 2 as u8); assert (h.get().y == 2 as u8);
assert (h.get()._2 == 3 as u8); assert (h.get().z == 3 as u8);
} }

View file

@ -1,6 +1,6 @@
obj buf[T](tup(T, T, T) data) { obj buf[T](rec(T _0, T _1, T _2) data) {
fn get(int i) -> T { fn get(int i) -> T {
if (i == 0) { if (i == 0) {
ret data._0; ret data._0;
@ -11,7 +11,7 @@ obj buf[T](tup(T, T, T) data) {
} }
fn main() { fn main() {
let buf[int] b = buf[int](tup(1, 2, 3)); let buf[int] b = buf[int](rec(_0=1, _1=2, _2=3));
log "constructed object"; log "constructed object";
log b.get(0); log b.get(0);
log b.get(1); log b.get(1);

View file

@ -7,13 +7,13 @@ tag noption[T] { some(T); }
fn main() { fn main() {
let noption[int] nop = some[int](5); let noption[int] nop = some[int](5);
alt (nop) { case (some[int](?n)) { log n; assert (n == 5); } } alt (nop) { case (some[int](?n)) { log n; assert (n == 5); } }
let noption[tup(int, int)] nop2 = some[tup(int, int)](tup(17, 42)); let noption[rec(int x, int y)] nop2 = some(rec(x=17, y=42));
alt (nop2) { alt (nop2) {
case (some[tup(int, int)](?t)) { case (some(?t)) {
log t._0; log t.x;
log t._1; log t.y;
assert (t._0 == 17); assert (t.x == 17);
assert (t._1 == 42); assert (t.y == 42);
} }
} }
} }

View file

@ -1,9 +0,0 @@
fn get_third[T](&tup(T, T, T) t) -> T { ret t._2; }
fn main() {
log get_third(tup(1, 2, 3));
assert (get_third(tup(1, 2, 3)) == 3);
assert (get_third(tup(5u8, 6u8, 7u8)) == 7u8);
}

View file

@ -1,6 +1,6 @@
type foo[T] = tup(T); type foo[T] = rec(T a);
type bar[T] = foo[T]; type bar[T] = foo[T];

View file

@ -1,9 +1,9 @@
type pair[T] = tup(T, T); type pair[T] = rec(T x, T y);
fn main() { fn main() {
let pair[int] x = tup(10, 12); let pair[int] x = rec(x=10, y=12);
assert (x._0 == 10); assert (x.x == 10);
assert (x._1 == 12); assert (x.y == 12);
} }

View file

@ -7,14 +7,14 @@
// -*- rust -*- // -*- rust -*-
use std; use std;
type cell = tup(mutable @list); type cell = rec(mutable @list c);
tag list { link(@cell); nil; } tag list { link(@cell); nil; }
fn main() { fn main() {
let @cell first = @tup(mutable @nil()); let @cell first = @rec(mutable c=@nil());
let @cell second = @tup(mutable @link(first)); let @cell second = @rec(mutable c=@link(first));
first._0 = @link(second); first._0 = @link(second);
std::sys.rustrt.gc(); std::sys.rustrt.gc();
let @cell third = @tup(mutable @nil()); let @cell third = @rec(mutable c=@nil());
} }

View file

@ -1,16 +1,16 @@
fn test(bool x, @tup(int, int, int) foo) -> int { fn test(bool x, @rec(int x, int y, int z) foo) -> int {
auto bar = foo; auto bar = foo;
let @tup(int,int,int) y; let @rec(int x,int y, int z) y;
if (x) { if (x) {
y <- bar; y <- bar;
} else { } else {
y = @tup(4,5,6); y = @rec(x=4, y=5, z=6);
} }
ret y._1; ret y.y;
} }
fn main() { fn main() {
auto x = @tup(1,2,3); auto x = @rec(x=1, y=2, z=3);
assert (test(true, x) == 2); assert (test(true, x) == 2);
assert (test(true, x) == 2); assert (test(true, x) == 2);
assert (test(true, x) == 2); assert (test(true, x) == 2);

View file

@ -1,3 +1,7 @@
fn main() { auto x = @tup(1, 2, 3); auto y <- x; assert (y._1 == 2); } fn main() {
auto x = @rec(x=1, y=2, z=3);
auto y <- x;
assert (y.y == 2);
}

View file

@ -1,19 +1,19 @@
use std; use std;
import std::uint; import std::uint;
fn test(bool x, @tup(int, int, int) foo) -> int { fn test(bool x, @rec(int x, int y, int z) foo) -> int {
auto bar = foo; auto bar = foo;
let @tup(int,int,int) y; let @rec(int x, int y, int z) y;
if (x) { if (x) {
y <- bar; y <- bar;
} else { } else {
y = @tup(4,5,6); y = @rec(x=4, y=5, z=6);
} }
ret y._1; ret y.y;
} }
fn main() { fn main() {
auto x = @tup(1,2,3); auto x = @rec(x=1, y=2, z=3);
for each (uint i in uint::range(0u, 10000u)) { for each (uint i in uint::range(0u, 10000u)) {
assert (test(true, x) == 2); assert (test(true, x) == 2);
} }

View file

@ -2,11 +2,15 @@
use std; use std;
import std::uint; import std::uint;
fn test(@tup(int, int, int) foo) -> @tup(int, int, int) { fn test(@rec(int a, int b, int c) foo) -> @rec(int a, int b, int c) {
auto bar <- foo; auto bar <- foo;
auto baz <- bar; auto baz <- bar;
auto quux <- baz; auto quux <- baz;
ret quux; ret quux;
} }
fn main() { auto x = @tup(1, 2, 3); auto y = test(x); assert (y._2 == 3); } fn main() {
auto x = @rec(a=1, b=2, c=3);
auto y = test(x);
assert (y.c == 3);
}

View file

@ -1,8 +1,6 @@
fn main() { fn main() {
// This just tests whether the vec leaks its members. // This just tests whether the vec leaks its members.
let vec[mutable @rec(int a, int b)] pvec =
let vec[mutable @tup(int, int)] pvec = [mutable @rec(a=1, b=2), @rec(a=3, b=4), @rec(a=5, b=6)];
[mutable @tup(1, 2), @tup(3, 4), @tup(5, 6)];
} }

View file

@ -4,21 +4,21 @@ fn ret_int_i() -> int { ret 10; }
fn ret_ext_i() -> @int { ret @10; } fn ret_ext_i() -> @int { ret @10; }
fn ret_int_tup() -> tup(int, int) { ret tup(10, 10); } fn ret_int_rec() -> rec(int a, int b) { ret rec(a=10, b=10); }
fn ret_ext_tup() -> @tup(int, int) { ret @tup(10, 10); } fn ret_ext_rec() -> @rec(int a, int b) { ret @rec(a=10, b=10); }
fn ret_ext_mem() -> tup(@int, @int) { ret tup(@10, @10); } fn ret_ext_mem() -> rec(@int a, @int b) { ret rec(a=@10, b=@10); }
fn ret_ext_ext_mem() -> @tup(@int, @int) { ret @tup(@10, @10); } fn ret_ext_ext_mem() -> @rec(@int a, @int b) { ret @rec(a=@10, b=@10); }
fn main() { fn main() {
let int int_i; let int int_i;
let @int ext_i; let @int ext_i;
let tup(int, int) int_tup; let rec(int a, int b) int_rec;
let @tup(int, int) ext_tup; let @rec(int a, int b) ext_rec;
let tup(@int, @int) ext_mem; let rec(@int a, @int b) ext_mem;
let @tup(@int, @int) ext_ext_mem; let @rec(@int a, @int b) ext_ext_mem;
int_i = ret_int_i(); // initializing int_i = ret_int_i(); // initializing
int_i = ret_int_i(); // non-initializing int_i = ret_int_i(); // non-initializing
@ -31,17 +31,17 @@ fn main() {
ext_i = ret_ext_i(); // non-initializing ext_i = ret_ext_i(); // non-initializing
int_tup = ret_int_tup(); // initializing int_rec = ret_int_rec(); // initializing
int_tup = ret_int_tup(); // non-initializing int_rec = ret_int_rec(); // non-initializing
int_tup = ret_int_tup(); // non-initializing int_rec = ret_int_rec(); // non-initializing
ext_tup = ret_ext_tup(); // initializing ext_rec = ret_ext_rec(); // initializing
ext_tup = ret_ext_tup(); // non-initializing ext_rec = ret_ext_rec(); // non-initializing
ext_tup = ret_ext_tup(); // non-initializing ext_rec = ret_ext_rec(); // non-initializing
ext_mem = ret_ext_mem(); // initializing ext_mem = ret_ext_mem(); // initializing

View file

@ -1,27 +0,0 @@
// -*- rust -*-
type point = rec(int x, int y);
type rect = tup(point, point);
fn f(rect r, int x1, int y1, int x2, int y2) {
assert (r._0.x == x1);
assert (r._0.y == y1);
assert (r._1.x == x2);
assert (r._1.y == y2);
}
fn main() {
let rect r = tup(rec(x=10, y=20), rec(x=11, y=22));
assert (r._0.x == 10);
assert (r._0.y == 20);
assert (r._1.x == 11);
assert (r._1.y == 22);
let rect r2 = r;
let int x = r2._0.x;
assert (x == 10);
f(r, 10, 20, 11, 22);
f(r2, 10, 20, 11, 22);
}

View file

@ -14,7 +14,7 @@ fn test_qsort() {
sort::ivector::quick_sort(lteq, names); sort::ivector::quick_sort(lteq, names);
auto pairs = ivec::zip(expected, ivec::from_mut(names)); auto pairs = ivec::zip(expected, ivec::from_mut(names));
for (tup(int, int) p in pairs) { for (rec(int _0, int _1) p in pairs) {
log_err #fmt("%d %d", p._0, p._1); log_err #fmt("%d %d", p._0, p._1);
assert p._0 == p._1; assert p._0 == p._1;
} }

View file

@ -3,14 +3,14 @@
tag foo { large; small; } tag foo { large; small; }
fn main() { fn main() {
auto a = tup(1, 2, 3); auto a = rec(x=1, y=2, z=3);
auto b = tup(1, 2, 3); auto b = rec(x=1, y=2, z=3);
assert (a == b); assert (a == b);
assert (a != tup(1, 2, 4)); assert (a != rec(x=1, y=2, z=4));
assert (a < tup(1, 2, 4)); assert (a < rec(x=1, y=2, z=4));
assert (a <= tup(1, 2, 4)); assert (a <= rec(x=1, y=2, z=4));
assert (tup(1, 2, 4) > a); assert (rec(x=1, y=2, z=4) > a);
assert (tup(1, 2, 4) >= a); assert (rec(x=1, y=2, z=4) >= a);
auto x = large; auto x = large;
auto y = small; auto y = small;
assert (x != y); assert (x != y);

View file

@ -40,20 +40,6 @@ fn test_str() {
assert (s1.(3) as u8 == 't' as u8); assert (s1.(3) as u8 == 't' as u8);
} }
fn test_tup() {
type t = tup(int, u8, char);
let port[t] po = port();
let chan[t] ch = chan(po);
let t t0 = tup(0, 1u8, '2');
ch <| t0;
let t t1;
po |> t1;
assert (t0._0 == 0);
assert (t0._1 == 1u8);
assert (t0._2 == '2');
}
fn test_tag() { fn test_tag() {
tag t { tag1; tag2(int); tag3(int, u8, char); } tag t { tag1; tag2(int); tag3(int, u8, char); }
let port[t] po = port(); let port[t] po = port();
@ -90,7 +76,6 @@ fn main() {
test_rec(); test_rec();
test_vec(); test_vec();
test_str(); test_str();
test_tup();
test_tag(); test_tag();
test_chan(); test_chan();
} }

View file

@ -1,18 +0,0 @@
// -*- rust -*-
type point = tup(int, int);
fn f(point p, int x, int y) { assert (p._0 == x); assert (p._1 == y); }
fn main() {
let point p = tup(10, 20);
assert (p._0 == 10);
assert (p._1 == 20);
let point p2 = p;
let int x = p2._0;
assert (x == 10);
f(p, 10, 20);
f(p2, 10, 20);
}

View file

@ -5,7 +5,7 @@ iter range(uint lo, uint hi) -> uint {
while (lo_ < hi) { put lo_; lo_ += 1u; } while (lo_ < hi) { put lo_; lo_ += 1u; }
} }
fn create_index[T](vec[tup(T, uint)] index, fn(&T) -> uint hash_fn) { fn create_index[T](vec[rec(T a, uint b)] index, fn(&T) -> uint hash_fn) {
for each (uint i in range(0u, 256u)) { let vec[T] bucket = []; } for each (uint i in range(0u, 256u)) { let vec[T] bucket = []; }
} }

View file

@ -13,13 +13,14 @@ fn main() {
assert (size_of[char]() == 4 as uint); assert (size_of[char]() == 4 as uint);
assert (size_of[i8]() == 1 as uint); assert (size_of[i8]() == 1 as uint);
assert (size_of[i32]() == 4 as uint); assert (size_of[i32]() == 4 as uint);
assert (size_of[tup(u8, i8)]() == 2 as uint); assert (size_of[rec(u8 a, i8 b)]() == 2 as uint);
assert (size_of[tup(u8, i8, u8)]() == 3 as uint); assert (size_of[rec(u8 a, i8 b, u8 c)]() == 3 as uint);
// Alignment causes padding before the char and the u32. // Alignment causes padding before the char and the u32.
assert (size_of[tup(u8, i8, tup(char, u8), u32)]() == 16 as uint); assert (size_of[rec(u8 a, i8 b, rec(char u, u8 v) c, u32 d)]()
== 16 as uint);
assert (size_of[int]() == size_of[uint]()); assert (size_of[int]() == size_of[uint]());
assert (size_of[tup(int, ())]() == size_of[int]()); assert (size_of[rec(int a, () b)]() == size_of[int]());
assert (size_of[tup(int, (), ())]() == size_of[int]()); assert (size_of[rec(int a, () b, () c)]() == size_of[int]());
assert (size_of[int]() == size_of[rec(int x)]()); assert (size_of[int]() == size_of[rec(int x)]());
} }

View file

@ -3,5 +3,7 @@
fn main() { fn main() {
// This just tests whether the vec leaks its members. // This just tests whether the vec leaks its members.
let vec[@tup(int, int)] pvec = [@tup(1, 2), @tup(3, 4), @tup(5, 6)]; let vec[@rec(int x, int y)] pvec = [@rec(x=1, y=2),
@rec(x=3, y=4),
@rec(x=5, y=6)];
} }

View file

@ -1,6 +0,0 @@
fn main() {
let tup(mutable vec[int]) i = tup(mutable [1, 2, 3]);
i._0 = [4, 5, 6];
}

View file

@ -78,11 +78,11 @@ fn test_partition() {
right(13), right(13),
left(14)]; left(14)];
auto result = partition(input); auto result = partition(input);
assert (result._0.(0) == 10); assert (result.lefts.(0) == 10);
assert (result._0.(1) == 12); assert (result.lefts.(1) == 12);
assert (result._0.(2) == 14); assert (result.lefts.(2) == 14);
assert (result._1.(0) == 11); assert (result.rights.(0) == 11);
assert (result._1.(1) == 13); assert (result.rights.(1) == 13);
} }
#[test] #[test]
@ -90,8 +90,8 @@ fn test_partition_no_lefts() {
let (t[int, int])[] input = ~[right(10), let (t[int, int])[] input = ~[right(10),
right(11)]; right(11)];
auto result = partition(input); auto result = partition(input);
assert (len(result._0) == 0u); assert (len(result.lefts) == 0u);
assert (len(result._1) == 2u); assert (len(result.rights) == 2u);
} }
#[test] #[test]
@ -99,14 +99,14 @@ fn test_partition_no_rights() {
let (t[int, int])[] input = ~[left(10), let (t[int, int])[] input = ~[left(10),
left(11)]; left(11)];
auto result = partition(input); auto result = partition(input);
assert (len(result._0) == 2u); assert (len(result.lefts) == 2u);
assert (len(result._1) == 0u); assert (len(result.rights) == 0u);
} }
#[test] #[test]
fn test_partition_empty() { fn test_partition_empty() {
let (t[int, int])[] input = ~[]; let (t[int, int])[] input = ~[];
auto result = partition(input); auto result = partition(input);
assert (len(result._0) == 0u); assert (len(result.lefts) == 0u);
assert (len(result._1) == 0u); assert (len(result.rights) == 0u);
} }

View file

@ -285,15 +285,15 @@ fn test_zip_unzip() {
auto v2 = ~[4, 5, 6]; auto v2 = ~[4, 5, 6];
auto z1 = ivec::zip(v1, v2); auto z1 = ivec::zip(v1, v2);
assert tup(1, 4) == z1.(0); assert rec(_0=1, _1=4) == z1.(0);
assert tup(2, 5) == z1.(1); assert rec(_0=2, _1=5) == z1.(1);
assert tup(3, 6) == z1.(2); assert rec(_0=3, _1=6) == z1.(2);
auto u1 = ivec::unzip(z1); auto u1 = ivec::unzip(z1);
assert tup(1, 4) == tup(u1._0.(0), u1._1.(0)); assert rec(_0=1, _1=4) == rec(_0=u1._0.(0), _1=u1._1.(0));
assert tup(2, 5) == tup(u1._0.(1), u1._1.(1)); assert rec(_0=2, _1=5) == rec(_0=u1._0.(1), _1=u1._1.(1));
assert tup(3, 6) == tup(u1._0.(2), u1._1.(2)); assert rec(_0=3, _1=6) == rec(_0=u1._0.(2), _1=u1._1.(2));
} }
// Local Variables: // Local Variables:

View file

@ -50,7 +50,7 @@ fn test_simple() {
sort::ivector::quick_sort(lteq, names); sort::ivector::quick_sort(lteq, names);
auto pairs = ivec::zip(expected, ivec::from_mut(names)); auto pairs = ivec::zip(expected, ivec::from_mut(names));
for (tup(int, int) p in pairs) { for (rec(int _0, int _1) p in pairs) {
log #fmt("%d %d", p._0, p._1); log #fmt("%d %d", p._0, p._1);
assert p._0 == p._1; assert p._0 == p._1;
} }

View file

@ -105,7 +105,7 @@ fn sort_tests() {
auto pairs = ivec::zip(expected, filtered); auto pairs = ivec::zip(expected, filtered);
for (tup(str, test::test_desc) p in pairs) { for (rec(str _0, test::test_desc _1) p in pairs) {
assert p._0 == p._1.name; assert p._0 == p._1.name;
} }
} }