Skip to content

Commit aa50930

Browse files
committed
---
yaml --- r: 106398 b: refs/heads/auto c: 9ed33c0 h: refs/heads/master v: v3
1 parent 1c53704 commit aa50930

File tree

14 files changed

+302
-43
lines changed

14 files changed

+302
-43
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: a7085940499748558f4236368a145b03f521843b
16+
refs/heads/auto: 9ed33c00ead8ad048488476310da434c461f4a4e
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/configure

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,6 @@ case $CFG_OSTYPE in
274274
MINGW32*)
275275
CFG_OSTYPE=pc-mingw32
276276
;;
277-
278-
MINGW64*)
279-
# msys2, MSYSTEM=MINGW64
280-
CFG_OSTYPE=w64-mingw32
281-
;;
282-
283277
# Thad's Cygwin identifers below
284278

285279
# Vista 32 bit
@@ -413,7 +407,7 @@ valopt mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
413407
# --libdir is used to configure the installation directory.
414408
# FIXME: Thise needs to parameterized over target triples. Do it in platform.mk
415409
CFG_LIBDIR_RELATIVE=lib
416-
if [ "$CFG_OSTYPE" = "pc-mingw32" ] || [ "$CFG_OSTYPE" = "w64-mingw32" ]
410+
if [ "$CFG_OSTYPE" = "pc-mingw32" ]
417411
then
418412
CFG_LIBDIR_RELATIVE=bin
419413
fi
@@ -539,7 +533,7 @@ then
539533
fi
540534

541535
BIN_SUF=
542-
if [ "$CFG_OSTYPE" = "pc-mingw32" ] || [ "$CFG_OSTYPE" = "w64-mingw32" ]
536+
if [ $CFG_OSTYPE = "pc-mingw32" ]
543537
then
544538
BIN_SUF=.exe
545539
fi

branches/auto/src/libarena/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
extern crate collections;
2929

30+
use collections::list::{List, Cons, Nil};
31+
3032
use std::cast::{transmute, transmute_mut, transmute_mut_region};
3133
use std::cast;
3234
use std::cell::{Cell, RefCell};
@@ -85,7 +87,7 @@ pub struct Arena {
8587
// access the head.
8688
priv head: Chunk,
8789
priv copy_head: Chunk,
88-
priv chunks: RefCell<Vec<Chunk>>,
90+
priv chunks: RefCell<@List<Chunk>>,
8991
}
9092

9193
impl Arena {
@@ -97,7 +99,7 @@ impl Arena {
9799
Arena {
98100
head: chunk(initial_size, false),
99101
copy_head: chunk(initial_size, true),
100-
chunks: RefCell::new(Vec::new()),
102+
chunks: RefCell::new(@Nil),
101103
}
102104
}
103105
}
@@ -115,7 +117,7 @@ impl Drop for Arena {
115117
fn drop(&mut self) {
116118
unsafe {
117119
destroy_chunk(&self.head);
118-
for chunk in self.chunks.borrow().iter() {
120+
for chunk in self.chunks.get().iter() {
119121
if !chunk.is_copy.get() {
120122
destroy_chunk(chunk);
121123
}
@@ -177,7 +179,7 @@ impl Arena {
177179
fn alloc_copy_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
178180
// Allocate a new chunk.
179181
let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size());
180-
self.chunks.borrow_mut().push(self.copy_head.clone());
182+
self.chunks.set(@Cons(self.copy_head.clone(), self.chunks.get()));
181183
self.copy_head =
182184
chunk(num::next_power_of_two(new_min_chunk_size + 1u), true);
183185

@@ -217,7 +219,7 @@ impl Arena {
217219
-> (*u8, *u8) {
218220
// Allocate a new chunk.
219221
let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size());
220-
self.chunks.borrow_mut().push(self.head.clone());
222+
self.chunks.set(@Cons(self.head.clone(), self.chunks.get()));
221223
self.head =
222224
chunk(num::next_power_of_two(new_min_chunk_size + 1u), false);
223225

branches/auto/src/libcollections/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub use deque::Deque;
3333
pub use dlist::DList;
3434
pub use enum_set::EnumSet;
3535
pub use hashmap::{HashMap, HashSet};
36+
pub use list::List;
3637
pub use lru_cache::LruCache;
3738
pub use priority_queue::PriorityQueue;
3839
pub use ringbuf::RingBuf;
@@ -46,6 +47,7 @@ pub mod deque;
4647
pub mod dlist;
4748
pub mod enum_set;
4849
pub mod hashmap;
50+
pub mod list;
4951
pub mod lru_cache;
5052
pub mod priority_queue;
5153
pub mod ringbuf;
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! A standard, garbage-collected linked list.
12+
13+
use std::container::Container;
14+
15+
#[deriving(Clone, Eq)]
16+
#[allow(missing_doc)]
17+
pub enum List<T> {
18+
Cons(T, @List<T>),
19+
Nil,
20+
}
21+
22+
pub struct Items<'a, T> {
23+
priv head: &'a List<T>,
24+
priv next: Option<&'a @List<T>>
25+
}
26+
27+
impl<'a, T> Iterator<&'a T> for Items<'a, T> {
28+
fn next(&mut self) -> Option<&'a T> {
29+
match self.next {
30+
None => match *self.head {
31+
Nil => None,
32+
Cons(ref value, ref tail) => {
33+
self.next = Some(tail);
34+
Some(value)
35+
}
36+
},
37+
Some(next) => match **next {
38+
Nil => None,
39+
Cons(ref value, ref tail) => {
40+
self.next = Some(tail);
41+
Some(value)
42+
}
43+
}
44+
}
45+
}
46+
}
47+
48+
impl<T> List<T> {
49+
/// Returns a forward iterator
50+
pub fn iter<'a>(&'a self) -> Items<'a, T> {
51+
Items {
52+
head: self,
53+
next: None
54+
}
55+
}
56+
57+
/// Returns the first element of a list
58+
pub fn head<'a>(&'a self) -> Option<&'a T> {
59+
match *self {
60+
Nil => None,
61+
Cons(ref head, _) => Some(head)
62+
}
63+
}
64+
65+
/// Returns all but the first element of a list
66+
pub fn tail(&self) -> Option<@List<T>> {
67+
match *self {
68+
Nil => None,
69+
Cons(_, tail) => Some(tail)
70+
}
71+
}
72+
}
73+
74+
impl<T> Container for List<T> {
75+
/// Returns the length of a list
76+
fn len(&self) -> uint { self.iter().len() }
77+
78+
/// Returns true if the list is empty
79+
fn is_empty(&self) -> bool { match *self { Nil => true, _ => false } }
80+
}
81+
82+
impl<T:Eq> List<T> {
83+
/// Returns true if a list contains an element with the given value
84+
pub fn contains(&self, element: T) -> bool {
85+
self.iter().any(|list_element| *list_element == element)
86+
}
87+
}
88+
89+
impl<T:'static + Clone> List<T> {
90+
/// Create a list from a vector
91+
pub fn from_vec(v: &[T]) -> List<T> {
92+
match v.len() {
93+
0 => Nil,
94+
_ => v.rev_iter().fold(Nil, |tail, value: &T| Cons(value.clone(), @tail))
95+
}
96+
}
97+
98+
/// Appends one list to another, returning a new list
99+
pub fn append(&self, other: List<T>) -> List<T> {
100+
match other {
101+
Nil => return self.clone(),
102+
_ => match *self {
103+
Nil => return other,
104+
Cons(ref value, tail) => Cons(value.clone(), @tail.append(other))
105+
}
106+
}
107+
}
108+
109+
/// Push one element into the front of a list, returning a new list
110+
pub fn unshift(&self, element: T) -> List<T> {
111+
Cons(element, @(self.clone()))
112+
}
113+
}
114+
115+
#[cfg(test)]
116+
mod tests {
117+
use list::{List, Nil};
118+
use list;
119+
120+
#[test]
121+
fn test_iter() {
122+
let list = List::from_vec([0, 1, 2]);
123+
let mut iter = list.iter();
124+
assert_eq!(&0, iter.next().unwrap());
125+
assert_eq!(&1, iter.next().unwrap());
126+
assert_eq!(&2, iter.next().unwrap());
127+
assert_eq!(None, iter.next());
128+
}
129+
130+
#[test]
131+
fn test_is_empty() {
132+
let empty : list::List<int> = List::from_vec([]);
133+
let full1 = List::from_vec([1]);
134+
let full2 = List::from_vec(['r', 'u']);
135+
136+
assert!(empty.is_empty());
137+
assert!(!full1.is_empty());
138+
assert!(!full2.is_empty());
139+
}
140+
141+
#[test]
142+
fn test_from_vec() {
143+
let list = List::from_vec([0, 1, 2]);
144+
assert_eq!(list.head().unwrap(), &0);
145+
146+
let mut tail = list.tail().unwrap();
147+
assert_eq!(tail.head().unwrap(), &1);
148+
149+
tail = tail.tail().unwrap();
150+
assert_eq!(tail.head().unwrap(), &2);
151+
}
152+
153+
#[test]
154+
fn test_from_vec_empty() {
155+
let empty : list::List<int> = List::from_vec([]);
156+
assert!(empty == Nil::<int>);
157+
}
158+
159+
#[test]
160+
fn test_fold() {
161+
fn add_(a: uint, b: &uint) -> uint { a + *b }
162+
fn subtract_(a: uint, b: &uint) -> uint { a - *b }
163+
164+
let empty = Nil::<uint>;
165+
assert_eq!(empty.iter().fold(0u, add_), 0u);
166+
assert_eq!(empty.iter().fold(10u, subtract_), 10u);
167+
168+
let list = List::from_vec([0u, 1u, 2u, 3u, 4u]);
169+
assert_eq!(list.iter().fold(0u, add_), 10u);
170+
assert_eq!(list.iter().fold(10u, subtract_), 0u);
171+
}
172+
173+
#[test]
174+
fn test_find_success() {
175+
fn match_(i: & &int) -> bool { **i == 2 }
176+
177+
let list = List::from_vec([0, 1, 2]);
178+
assert_eq!(list.iter().find(match_).unwrap(), &2);
179+
}
180+
181+
#[test]
182+
fn test_find_fail() {
183+
fn match_(_i: & &int) -> bool { false }
184+
185+
let empty = Nil::<int>;
186+
assert_eq!(empty.iter().find(match_), None);
187+
188+
let list = List::from_vec([0, 1, 2]);
189+
assert_eq!(list.iter().find(match_), None);
190+
}
191+
192+
#[test]
193+
fn test_any() {
194+
fn match_(i: &int) -> bool { *i == 2 }
195+
196+
let empty = Nil::<int>;
197+
assert_eq!(empty.iter().any(match_), false);
198+
199+
let list = List::from_vec([0, 1, 2]);
200+
assert_eq!(list.iter().any(match_), true);
201+
}
202+
203+
#[test]
204+
fn test_contains() {
205+
let empty = Nil::<int>;
206+
assert!((!empty.contains(5)));
207+
208+
let list = List::from_vec([5, 8, 6]);
209+
assert!((list.contains(5)));
210+
assert!((!list.contains(7)));
211+
assert!((list.contains(8)));
212+
}
213+
214+
#[test]
215+
fn test_len() {
216+
let empty = Nil::<int>;
217+
assert_eq!(empty.len(), 0u);
218+
219+
let list = List::from_vec([0, 1, 2]);
220+
assert_eq!(list.len(), 3u);
221+
}
222+
223+
#[test]
224+
fn test_append() {
225+
assert!(List::from_vec([1, 2, 3, 4]) ==
226+
List::from_vec([1, 2]).append(List::from_vec([3, 4])));
227+
}
228+
229+
#[test]
230+
fn test_unshift() {
231+
let list = List::from_vec([1]);
232+
let new_list = list.unshift(0);
233+
assert_eq!(list.len(), 1u);
234+
assert_eq!(new_list.len(), 2u);
235+
assert!(new_list == List::from_vec([0, 1]));
236+
}
237+
}

branches/auto/src/libgreen/sched.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ mod test {
14731473
let mut handle = pool.spawn_sched();
14741474
handle.send(PinnedTask(pool.task(TaskOpts::new(), proc() {
14751475
unsafe {
1476-
let guard = LOCK.lock();
1476+
let mut guard = LOCK.lock();
14771477

14781478
start_tx.send(());
14791479
guard.wait(); // block the scheduler thread
@@ -1509,7 +1509,7 @@ mod test {
15091509
child_tx.send(20);
15101510
pingpong(&parent_rx, &child_tx);
15111511
unsafe {
1512-
let guard = LOCK.lock();
1512+
let mut guard = LOCK.lock();
15131513
guard.signal(); // wakeup waiting scheduler
15141514
guard.wait(); // wait for them to grab the lock
15151515
}

branches/auto/src/librustc/front/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ fn add_test_module(cx: &TestCtxt, m: &ast::Mod) -> ast::Mod {
282282
We're going to be building a module that looks more or less like:
283283
284284
mod __test {
285-
#[!resolve_unexported]
285+
#![!resolve_unexported]
286286
extern crate test (name = "test", vers = "...");
287287
fn main() {
288288
test::test_main_static(::os::args(), tests)
@@ -326,8 +326,8 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::Item {
326326
// with our list of tests
327327
let mainfn = (quote_item!(&cx.ext_cx,
328328
pub fn main() {
329-
#[allow(deprecated_owned_vector)];
330-
#[main];
329+
#![main]
330+
#![allow(deprecated_owned_vector)]
331331
test::test_main_static(::std::os::args(), TESTS);
332332
}
333333
)).unwrap();

0 commit comments

Comments
 (0)