Skip to content

Commit b2e2390

Browse files
committed
---
yaml --- r: 56070 b: refs/heads/auto c: 61b2999 h: refs/heads/master v: v3
1 parent 79278f1 commit b2e2390

File tree

21 files changed

+249
-1778
lines changed

21 files changed

+249
-1778
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: bfeb6d124dc924e52a218387a388caf87964162f
17+
refs/heads/auto: 61b29993ddd531c6f53f7d21ddf28d26d4d63a21
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ do
859859
LDFLAGS=$LLVM_LDFLAGS
860860

861861
LLVM_FLAGS="$LLVM_TARGETS $LLVM_OPTS $LLVM_BUILD \
862-
$LLVM_HOST $LLVM_TARGET --with-python=$CFG_PYTHON"
862+
$LLVM_HOST $LLVM_TARGET"
863863

864864
msg "configuring LLVM with:"
865865
msg "$LLVM_FLAGS"

branches/auto/src/libcore/bool.rs

Lines changed: 72 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
1211
//! Boolean logic
1312
13+
#[cfg(notest)]
14+
use cmp::{Eq, Ord, TotalOrd, Ordering};
1415
use option::{None, Option, Some};
1516
use from_str::FromStr;
1617

17-
#[cfg(notest)] use cmp;
18-
1918
/// Negation / inverse
2019
pub fn not(v: bool) -> bool { !v }
2120

@@ -73,40 +72,86 @@ pub fn all_values(blk: &fn(v: bool)) {
7372
}
7473

7574
/// converts truth value to an 8 bit byte
75+
#[inline(always)]
7676
pub fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }
7777

7878
#[cfg(notest)]
79-
impl cmp::Eq for bool {
79+
impl Ord for bool {
80+
#[inline(always)]
81+
fn lt(&self, other: &bool) -> bool { to_bit(*self) < to_bit(*other) }
82+
#[inline(always)]
83+
fn le(&self, other: &bool) -> bool { to_bit(*self) <= to_bit(*other) }
84+
#[inline(always)]
85+
fn gt(&self, other: &bool) -> bool { to_bit(*self) > to_bit(*other) }
86+
#[inline(always)]
87+
fn ge(&self, other: &bool) -> bool { to_bit(*self) >= to_bit(*other) }
88+
}
89+
90+
#[cfg(notest)]
91+
impl TotalOrd for bool {
92+
#[inline(always)]
93+
fn cmp(&self, other: &bool) -> Ordering { to_bit(*self).cmp(&to_bit(*other)) }
94+
}
95+
96+
#[cfg(notest)]
97+
impl Eq for bool {
98+
#[inline(always)]
8099
fn eq(&self, other: &bool) -> bool { (*self) == (*other) }
100+
#[inline(always)]
81101
fn ne(&self, other: &bool) -> bool { (*self) != (*other) }
82102
}
83103

84-
#[test]
85-
pub fn test_bool_from_str() {
86-
use from_str::FromStr;
104+
#[cfg(test)]
105+
mod tests {
106+
use super::*;
107+
use prelude::*;
87108

88-
do all_values |v| {
89-
assert!(Some(v) == FromStr::from_str(to_str(v)))
109+
#[test]
110+
fn test_bool_from_str() {
111+
use from_str::FromStr;
112+
113+
do all_values |v| {
114+
assert!(Some(v) == FromStr::from_str(to_str(v)))
115+
}
90116
}
91-
}
92117

93-
#[test]
94-
pub fn test_bool_to_str() {
95-
assert!(to_str(false) == ~"false");
96-
assert!(to_str(true) == ~"true");
97-
}
118+
#[test]
119+
fn test_bool_to_str() {
120+
assert!(to_str(false) == ~"false");
121+
assert!(to_str(true) == ~"true");
122+
}
98123

99-
#[test]
100-
pub fn test_bool_to_bit() {
101-
do all_values |v| {
102-
assert!(to_bit(v) == if is_true(v) { 1u8 } else { 0u8 });
124+
#[test]
125+
fn test_bool_to_bit() {
126+
do all_values |v| {
127+
assert!(to_bit(v) == if is_true(v) { 1u8 } else { 0u8 });
128+
}
103129
}
104-
}
105130

106-
// Local Variables:
107-
// mode: rust;
108-
// fill-column: 78;
109-
// indent-tabs-mode: nil
110-
// c-basic-offset: 4
111-
// buffer-file-coding-system: utf-8-unix
112-
// End:
131+
#[test]
132+
fn test_bool_ord() {
133+
assert!(true > false);
134+
assert!(!(false > true));
135+
136+
assert!(false < true);
137+
assert!(!(true < false));
138+
139+
assert!(false <= false);
140+
assert!(false >= false);
141+
assert!(true <= true);
142+
assert!(true >= true);
143+
144+
assert!(false <= true);
145+
assert!(!(false >= true));
146+
assert!(true >= false);
147+
assert!(!(true <= false));
148+
}
149+
150+
#[test]
151+
fn test_bool_totalord() {
152+
assert_eq!(true.cmp(&true), Equal);
153+
assert_eq!(false.cmp(&false), Equal);
154+
assert_eq!(true.cmp(&false), Greater);
155+
assert_eq!(false.cmp(&true), Less);
156+
}
157+
}

branches/auto/src/libcore/rand.rs

Lines changed: 9 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,7 @@ pub struct Weighted<T> {
150150

151151
pub trait RngUtil {
152152
fn gen<T:Rand>(&self) -> T;
153-
/**
154-
* Return a random int
155-
*
156-
* *Example*
157-
*
158-
* ~~~
159-
*
160-
* use core::rand::RngUtil;
161-
*
162-
* fn main() {
163-
* rng = rand::Rng();
164-
* println(fmt!("%d",rng.gen_int()));
165-
* }
166-
* ~~~
167-
*/
153+
/// Return a random int
168154
fn gen_int(&self) -> int;
169155
fn gen_int_range(&self, start: int, end: int) -> int;
170156
/// Return a random i8
@@ -190,21 +176,7 @@ pub trait RngUtil {
190176
fn gen_u32(&self) -> u32;
191177
/// Return a random u64
192178
fn gen_u64(&self) -> u64;
193-
/**
194-
* Return random float in the interval [0,1]
195-
*
196-
* *Example*
197-
*
198-
* ~~~
199-
*
200-
* use core::rand::RngUtil;
201-
*
202-
* fn main() {
203-
* rng = rand::Rng();
204-
* println(fmt!("%f",rng.gen_float()));
205-
* }
206-
* ~~~
207-
*/
179+
/// Return a random float in the interval [0,1]
208180
fn gen_float(&self) -> float;
209181
/// Return a random f32 in the interval [0,1]
210182
fn gen_f32(&self) -> f32;
@@ -216,184 +188,38 @@ pub trait RngUtil {
216188
* Return a char randomly chosen from chars, failing if chars is empty
217189
*/
218190
fn gen_char_from(&self, chars: &str) -> char;
219-
/**
220-
* Return a random bool
221-
*
222-
* *Example*
223-
*
224-
* ~~~
225-
*
226-
* use core::rand::RngUtil;
227-
*
228-
* fn main() {
229-
* rng = rand::Rng();
230-
* println(fmt!("%b",rng.gen_bool()));
231-
* }
232-
* ~~~
233-
*/
191+
/// Return a random bool
234192
fn gen_bool(&self) -> bool;
235-
/**
236-
* Return a bool with a 1 in n chance of true
237-
*
238-
* *Example*
239-
*
240-
* ~~~
241-
*
242-
* use core::rand::RngUtil;
243-
*
244-
* fn main() {
245-
* rng = rand::Rng();
246-
* println(fmt!("%b",rng.gen_weighted_bool(3)));
247-
* }
248-
* ~~~
249-
*/
193+
/// Return a bool with a 1 in n chance of true
250194
fn gen_weighted_bool(&self, n: uint) -> bool;
251195
/**
252196
* Return a random string of the specified length composed of A-Z,a-z,0-9
253-
*
254-
* *Example*
255-
*
256-
* ~~~
257-
*
258-
* use core::rand::RngUtil;
259-
*
260-
* fn main() {
261-
* rng = rand::Rng();
262-
* println(rng.gen_str(8));
263-
* }
264-
* ~~~
265197
*/
266198
fn gen_str(&self, len: uint) -> ~str;
267-
/**
268-
* Return a random byte string of the specified length
269-
*
270-
* *Example*
271-
*
272-
* ~~~
273-
*
274-
* use core::rand::RngUtil;
275-
*
276-
* fn main() {
277-
* rng = rand::Rng();
278-
* println(fmt!("%?",rng.gen_bytes(8)));
279-
* }
280-
* ~~~
281-
*/
199+
/// Return a random byte string of the specified length
282200
fn gen_bytes(&self, len: uint) -> ~[u8];
283-
///
284-
/**
285-
* Choose an item randomly, failing if values is empty
286-
*
287-
* *Example*
288-
*
289-
* ~~~
290-
*
291-
* use core::rand::RngUtil;
292-
*
293-
* fn main() {
294-
* rng = rand::Rng();
295-
* println(fmt!("%d",rng.choose([1,2,4,8,16,32])));
296-
* }
297-
* ~~~
298-
*/
201+
/// Choose an item randomly, failing if values is empty
299202
fn choose<T:Copy>(&self, values: &[T]) -> T;
300203
/// Choose Some(item) randomly, returning None if values is empty
301204
fn choose_option<T:Copy>(&self, values: &[T]) -> Option<T>;
302205
/**
303206
* Choose an item respecting the relative weights, failing if the sum of
304207
* the weights is 0
305-
*
306-
* *Example*
307-
*
308-
* ~~~
309-
*
310-
* use core::rand::RngUtil;
311-
*
312-
* fn main() {
313-
* rng = rand::Rng();
314-
* let x = [rand::Weighted {weight: 4, item: 'a'},
315-
* rand::Weighted {weight: 2, item: 'b'},
316-
* rand::Weighted {weight: 2, item: 'c'}];
317-
* println(fmt!("%c",rng.choose_weighted(x)));
318-
* }
319-
* ~~~
320208
*/
321209
fn choose_weighted<T:Copy>(&self, v : &[Weighted<T>]) -> T;
322210
/**
323211
* Choose Some(item) respecting the relative weights, returning none if
324212
* the sum of the weights is 0
325-
*
326-
* *Example*
327-
*
328-
* ~~~
329-
*
330-
* use core::rand::RngUtil;
331-
*
332-
* fn main() {
333-
* rng = rand::Rng();
334-
* let x = [rand::Weighted {weight: 4, item: 'a'},
335-
* rand::Weighted {weight: 2, item: 'b'},
336-
* rand::Weighted {weight: 2, item: 'c'}];
337-
* println(fmt!("%?",rng.choose_weighted_option(x)));
338-
* }
339-
* ~~~
340213
*/
341214
fn choose_weighted_option<T:Copy>(&self, v: &[Weighted<T>]) -> Option<T>;
342215
/**
343216
* Return a vec containing copies of the items, in order, where
344217
* the weight of the item determines how many copies there are
345-
*
346-
* *Example*
347-
*
348-
* ~~~
349-
*
350-
* use core::rand::RngUtil;
351-
*
352-
* fn main() {
353-
* rng = rand::Rng();
354-
* let x = [rand::Weighted {weight: 4, item: 'a'},
355-
* rand::Weighted {weight: 2, item: 'b'},
356-
* rand::Weighted {weight: 2, item: 'c'}];
357-
* println(fmt!("%?",rng.weighted_vec(x)));
358-
* }
359-
* ~~~
360218
*/
361219
fn weighted_vec<T:Copy>(&self, v: &[Weighted<T>]) -> ~[T];
362-
/**
363-
* Shuffle a vec
364-
*
365-
* *Example*
366-
*
367-
* ~~~
368-
*
369-
* use core::rand::RngUtil;
370-
*
371-
* fn main() {
372-
* rng = rand::Rng();
373-
* println(fmt!("%?",rng.shuffle([1,2,3])));
374-
* }
375-
* ~~~
376-
*/
220+
/// Shuffle a vec
377221
fn shuffle<T:Copy>(&self, values: &[T]) -> ~[T];
378-
/**
379-
* Shuffle a mutable vec in place
380-
*
381-
* *Example*
382-
*
383-
* ~~~
384-
*
385-
* use core::rand::RngUtil;
386-
*
387-
* fn main() {
388-
* rng = rand::Rng();
389-
* let mut y = [1,2,3];
390-
* rng.shuffle_mut(y);
391-
* println(fmt!("%?",y));
392-
* rng.shuffle_mut(y);
393-
* println(fmt!("%?",y));
394-
* }
395-
* ~~~
396-
*/
222+
/// Shuffle a mutable vec in place
397223
fn shuffle_mut<T>(&self, values: &mut [T]);
398224
}
399225

@@ -511,7 +337,7 @@ impl RngUtil for @Rng {
511337
self.next() & 1u32 == 1u32
512338
}
513339

514-
/// Return a bool with a 1-in-n chance of true
340+
/// Return a bool with a 1 in n chance of true
515341
fn gen_weighted_bool(&self, n: uint) -> bool {
516342
if n == 0u {
517343
true

0 commit comments

Comments
 (0)