Skip to content

Commit 561a6e0

Browse files
committed
---
yaml --- r: 144987 b: refs/heads/try2 c: 0a2d3c5 h: refs/heads/master i: 144985: 556a79c 144983: 65ba2d1 v: v3
1 parent 19dd3b2 commit 561a6e0

File tree

129 files changed

+2092
-553
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+2092
-553
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a9184975da62769dfccbca73fb9bd554298a4d36
8+
refs/heads/try2: 0a2d3c5a6f3bbd5f8cd8e3361995d5fa6c4d1e73
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/rust.md

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,25 +2459,12 @@ do k(3) |j| {
24592459
### For expressions
24602460

24612461
~~~~~~~~{.ebnf .gram}
2462-
for_expr : "for" expr [ '|' ident_list '|' ] ? '{' block '}' ;
2462+
for_expr : "for" pat "in" expr '{' block '}' ;
24632463
~~~~~~~~
24642464

2465-
A _for expression_ is similar to a [`do` expression](#do-expressions),
2466-
in that it provides a special block-form of lambda expression,
2467-
suited to passing the `block` function to a higher-order function implementing a loop.
2468-
2469-
In contrast to a `do` expression, a `for` expression is designed to work
2470-
with methods such as `each` and `times`, that require the body block to
2471-
return a boolean. The `for` expression accommodates this by implicitly
2472-
returning `true` at the end of each block, unless a `break` expression
2473-
is evaluated.
2474-
2475-
In addition, [`break`](#break-expressions) and [`loop`](#loop-expressions) expressions
2476-
are rewritten inside `for` expressions in the same way that `return` expressions are,
2477-
with a combination of local flag variables,
2478-
and early boolean-valued returns from the `block` function,
2479-
such that the meaning of `break` and `loop` is preserved in a primitive loop
2480-
when rewritten as a `for` loop controlled by a higher order function.
2465+
A `for` expression is a syntactic construct for looping
2466+
over elements provided by an implementation of
2467+
`std::iterator::Iterator`.
24812468

24822469
An example of a for loop over the contents of a vector:
24832470

branches/try2/src/libextra/num/bigint.rs

Lines changed: 130 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl Integer for BigUint {
503503
impl IntConvertible for BigUint {
504504
#[inline]
505505
fn to_int(&self) -> int {
506-
num::min(self.to_uint(), int::max_value as uint) as int
506+
self.to_int_opt().expect("BigUint conversion would overflow int")
507507
}
508508

509509
#[inline]
@@ -615,18 +615,43 @@ impl BigUint {
615615
}
616616

617617

618-
/// Converts this big integer into a uint, returning the uint::max_value if
619-
/// it's too large to fit in a uint.
618+
/// Converts this BigUint into a uint, failing if the conversion
619+
/// would overflow.
620620
#[inline]
621621
pub fn to_uint(&self) -> uint {
622+
self.to_uint_opt().expect("BigUint conversion would overflow uint")
623+
}
624+
625+
/// Converts this BigUint into a uint, unless it would overflow.
626+
#[inline]
627+
pub fn to_uint_opt(&self) -> Option<uint> {
622628
match self.data.len() {
623-
0 => 0,
624-
1 => self.data[0] as uint,
625-
2 => BigDigit::to_uint(self.data[1], self.data[0]),
626-
_ => uint::max_value
629+
0 => Some(0),
630+
1 => Some(self.data[0] as uint),
631+
2 => Some(BigDigit::to_uint(self.data[1], self.data[0])),
632+
_ => None
627633
}
628634
}
629635

636+
// Converts this BigUint into an int, unless it would overflow.
637+
pub fn to_int_opt(&self) -> Option<int> {
638+
self.to_uint_opt().chain(|n| {
639+
// If top bit of uint is set, it's too large to convert to
640+
// int.
641+
if (n >> (2*BigDigit::bits - 1) != 0) {
642+
None
643+
} else {
644+
Some(n as int)
645+
}
646+
})
647+
}
648+
649+
/// Converts this BigUint into a BigInt.
650+
#[inline]
651+
pub fn to_bigint(&self) -> BigInt {
652+
BigInt::from_biguint(Plus, self.clone())
653+
}
654+
630655
#[inline]
631656
fn shl_unit(&self, n_unit: uint) -> BigUint {
632657
if n_unit == 0 || self.is_zero() { return (*self).clone(); }
@@ -1048,12 +1073,7 @@ impl Integer for BigInt {
10481073
impl IntConvertible for BigInt {
10491074
#[inline]
10501075
fn to_int(&self) -> int {
1051-
match self.sign {
1052-
Plus => num::min(self.to_uint(), int::max_value as uint) as int,
1053-
Zero => 0,
1054-
Minus => num::min((-self).to_uint(),
1055-
(int::max_value as uint) + 1) as int
1056-
}
1076+
self.to_int_opt().expect("BigInt conversion would overflow int")
10571077
}
10581078

10591079
#[inline]
@@ -1179,12 +1199,55 @@ impl BigInt {
11791199
.map_move(|bu| BigInt::from_biguint(sign, bu));
11801200
}
11811201
1202+
/// Converts this BigInt into a uint, failing if the conversion
1203+
/// would overflow.
11821204
#[inline]
11831205
pub fn to_uint(&self) -> uint {
1206+
self.to_uint_opt().expect("BigInt conversion would overflow uint")
1207+
}
1208+
1209+
/// Converts this BigInt into a uint, unless it would overflow.
1210+
#[inline]
1211+
pub fn to_uint_opt(&self) -> Option<uint> {
1212+
match self.sign {
1213+
Plus => self.data.to_uint_opt(),
1214+
Zero => Some(0),
1215+
Minus => None
1216+
}
1217+
}
1218+
1219+
/// Converts this BigInt into an int, unless it would overflow.
1220+
pub fn to_int_opt(&self) -> Option<int> {
1221+
match self.sign {
1222+
Plus => self.data.to_int_opt(),
1223+
Zero => Some(0),
1224+
Minus => self.data.to_uint_opt().chain(|n| {
1225+
let m: uint = 1 << (2*BigDigit::bits-1);
1226+
if (n > m) {
1227+
None
1228+
} else if (n == m) {
1229+
Some(int::min_value)
1230+
} else {
1231+
Some(-(n as int))
1232+
}
1233+
})
1234+
}
1235+
}
1236+
1237+
/// Converts this BigInt into a BigUint, failing if BigInt is
1238+
/// negative.
1239+
#[inline]
1240+
pub fn to_biguint(&self) -> BigUint {
1241+
self.to_biguint_opt().expect("negative BigInt cannot convert to BigUint")
1242+
}
1243+
1244+
/// Converts this BigInt into a BigUint, if it's not negative.
1245+
#[inline]
1246+
pub fn to_biguint_opt(&self) -> Option<BigUint> {
11841247
match self.sign {
1185-
Plus => self.data.to_uint(),
1186-
Zero => 0,
1187-
Minus => 0
1248+
Plus => Some(self.data.clone()),
1249+
Zero => Some(Zero::zero()),
1250+
Minus => None
11881251
}
11891252
}
11901253
}
@@ -1385,9 +1448,9 @@ mod biguint_tests {
13851448
check(~[ 0, 1], ((uint::max_value >> BigDigit::bits) + 1) as int);
13861449
check(~[-1, -1 >> 1], int::max_value);
13871450

1388-
assert_eq!(BigUint::new(~[0, -1]).to_int(), int::max_value);
1389-
assert_eq!(BigUint::new(~[0, 0, 1]).to_int(), int::max_value);
1390-
assert_eq!(BigUint::new(~[0, 0, -1]).to_int(), int::max_value);
1451+
assert_eq!(BigUint::new(~[0, -1]).to_int_opt(), None);
1452+
assert_eq!(BigUint::new(~[0, 0, 1]).to_int_opt(), None);
1453+
assert_eq!(BigUint::new(~[0, 0, -1]).to_int_opt(), None);
13911454
}
13921455

13931456
#[test]
@@ -1405,8 +1468,19 @@ mod biguint_tests {
14051468
check(~[ 0, -1], uint::max_value << BigDigit::bits);
14061469
check(~[-1, -1], uint::max_value);
14071470

1408-
assert_eq!(BigUint::new(~[0, 0, 1]).to_uint(), uint::max_value);
1409-
assert_eq!(BigUint::new(~[0, 0, -1]).to_uint(), uint::max_value);
1471+
assert_eq!(BigUint::new(~[0, 0, 1]).to_uint_opt(), None);
1472+
assert_eq!(BigUint::new(~[0, 0, -1]).to_uint_opt(), None);
1473+
}
1474+
1475+
#[test]
1476+
fn test_convert_to_bigint() {
1477+
fn check(n: BigUint, ans: BigInt) {
1478+
assert_eq!(n.to_bigint(), ans);
1479+
assert_eq!(n.to_bigint().to_biguint(), n);
1480+
}
1481+
check(Zero::zero(), Zero::zero());
1482+
check(BigUint::new(~[1,2,3]),
1483+
BigInt::from_biguint(Plus, BigUint::new(~[1,2,3])));
14101484
}
14111485

14121486
static sum_triples: &'static [(&'static [BigDigit],
@@ -1793,22 +1867,21 @@ mod bigint_tests {
17931867
Plus, BigUint::from_uint(int::max_value as uint)
17941868
), int::max_value);
17951869

1796-
assert!(BigInt::from_biguint(
1870+
assert_eq!(BigInt::from_biguint(
17971871
Plus, BigUint::from_uint(int::max_value as uint + 1)
1798-
).to_int() == int::max_value);
1799-
assert!(BigInt::from_biguint(
1872+
).to_int_opt(), None);
1873+
assert_eq!(BigInt::from_biguint(
18001874
Plus, BigUint::new(~[1, 2, 3])
1801-
).to_int() == int::max_value);
1875+
).to_int_opt(), None);
18021876

18031877
check(BigInt::from_biguint(
1804-
Minus, BigUint::from_uint(-int::min_value as uint)
1878+
Minus, BigUint::new(~[0, 1<<(BigDigit::bits-1)])
18051879
), int::min_value);
1806-
assert!(BigInt::from_biguint(
1807-
Minus, BigUint::from_uint(-int::min_value as uint + 1)
1808-
).to_int() == int::min_value);
1809-
assert!(BigInt::from_biguint(
1810-
Minus, BigUint::new(~[1, 2, 3])
1811-
).to_int() == int::min_value);
1880+
assert_eq!(BigInt::from_biguint(
1881+
Minus, BigUint::new(~[1, 1<<(BigDigit::bits-1)])
1882+
).to_int_opt(), None);
1883+
assert_eq!(BigInt::from_biguint(
1884+
Minus, BigUint::new(~[1, 2, 3])).to_int_opt(), None);
18121885
}
18131886

18141887
#[test]
@@ -1824,16 +1897,31 @@ mod bigint_tests {
18241897
check(
18251898
BigInt::from_biguint(Plus, BigUint::from_uint(uint::max_value)),
18261899
uint::max_value);
1827-
assert!(BigInt::from_biguint(
1828-
Plus, BigUint::new(~[1, 2, 3])
1829-
).to_uint() == uint::max_value);
1830-
1831-
assert!(BigInt::from_biguint(
1832-
Minus, BigUint::from_uint(uint::max_value)
1833-
).to_uint() == 0);
1834-
assert!(BigInt::from_biguint(
1835-
Minus, BigUint::new(~[1, 2, 3])
1836-
).to_uint() == 0);
1900+
assert_eq!(BigInt::from_biguint(
1901+
Plus, BigUint::new(~[1, 2, 3])).to_uint_opt(), None);
1902+
1903+
assert_eq!(BigInt::from_biguint(
1904+
Minus, BigUint::from_uint(uint::max_value)).to_uint_opt(), None);
1905+
assert_eq!(BigInt::from_biguint(
1906+
Minus, BigUint::new(~[1, 2, 3])).to_uint_opt(), None);
1907+
}
1908+
1909+
#[test]
1910+
fn test_convert_to_biguint() {
1911+
fn check(n: BigInt, ans_1: BigUint) {
1912+
assert_eq!(n.to_biguint(), ans_1);
1913+
assert_eq!(n.to_biguint().to_bigint(), n);
1914+
}
1915+
let zero: BigInt = Zero::zero();
1916+
let unsigned_zero: BigUint = Zero::zero();
1917+
let positive = BigInt::from_biguint(
1918+
Plus, BigUint::new(~[1,2,3]));
1919+
let negative = -positive;
1920+
1921+
check(zero, unsigned_zero);
1922+
check(positive, BigUint::new(~[1,2,3]));
1923+
1924+
assert_eq!(negative.to_biguint_opt(), None);
18371925
}
18381926

18391927
static sum_triples: &'static [(&'static [BigDigit],

branches/try2/src/librustc/lib/llvm.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,14 @@ pub mod llvm {
21092109
ArgNo: c_uint)
21102110
-> ValueRef;
21112111

2112+
#[fast_ffi]
2113+
pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
2114+
Scope: ValueRef,
2115+
Name: *c_char,
2116+
File: ValueRef,
2117+
LineNo: c_uint)
2118+
-> ValueRef;
2119+
21122120
#[fast_ffi]
21132121
pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
21142122

branches/try2/src/librustc/metadata/decoder.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ enum Family {
115115
Mod, // m
116116
ForeignMod, // n
117117
Enum, // t
118-
Variant, // v
118+
TupleVariant, // v
119+
StructVariant, // V
119120
Impl, // i
120121
Trait, // I
121122
Struct, // S
@@ -139,7 +140,8 @@ fn item_family(item: ebml::Doc) -> Family {
139140
'm' => Mod,
140141
'n' => ForeignMod,
141142
't' => Enum,
142-
'v' => Variant,
143+
'v' => TupleVariant,
144+
'V' => StructVariant,
143145
'i' => Impl,
144146
'I' => Trait,
145147
'S' => Struct,
@@ -361,9 +363,13 @@ fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
361363
Type | ForeignType => DlDef(ast::DefTy(did)),
362364
Mod => DlDef(ast::DefMod(did)),
363365
ForeignMod => DlDef(ast::DefForeignMod(did)),
364-
Variant => {
366+
StructVariant => {
365367
let enum_did = item_reqd_and_translated_parent_item(cnum, item);
366-
DlDef(ast::DefVariant(enum_did, did))
368+
DlDef(ast::DefVariant(enum_did, did, true))
369+
}
370+
TupleVariant => {
371+
let enum_did = item_reqd_and_translated_parent_item(cnum, item);
372+
DlDef(ast::DefVariant(enum_did, did, false))
367373
}
368374
Trait => DlDef(ast::DefTrait(did)),
369375
Enum => DlDef(ast::DefTy(did)),
@@ -575,8 +581,8 @@ impl<'self> EachItemContext<'self> {
575581
}
576582
ImmStatic | MutStatic | Struct | UnsafeFn | Fn | ForeignFn |
577583
UnsafeStaticMethod | StaticMethod | Type | ForeignType |
578-
Variant | Enum | PublicField | PrivateField |
579-
InheritedField => {}
584+
TupleVariant | StructVariant | Enum | PublicField |
585+
PrivateField | InheritedField => {}
580586
}
581587
}
582588

@@ -1268,7 +1274,8 @@ fn item_family_to_str(fam: Family) -> ~str {
12681274
Mod => ~"mod",
12691275
ForeignMod => ~"foreign mod",
12701276
Enum => ~"enum",
1271-
Variant => ~"variant",
1277+
StructVariant => ~"struct variant",
1278+
TupleVariant => ~"tuple variant",
12721279
Impl => ~"impl",
12731280
Trait => ~"trait",
12741281
Struct => ~"struct",

0 commit comments

Comments
 (0)