Skip to content

Commit c6ca8ba

Browse files
committed
---
yaml --- r: 140766 b: refs/heads/try2 c: 4f44624 h: refs/heads/master v: v3
1 parent 8edf1f0 commit c6ca8ba

Some content is hidden

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

69 files changed

+826
-945
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: 3abc5b3ffb87b51931594f9ce953af648aad342e
8+
refs/heads/try2: 4f446244155984a6674f69ab6e9d49704ab0c20d
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: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ each of which may have some number of [attributes](#attributes) attached to it.
618618

619619
~~~~~~~~ {.ebnf .gram}
620620
item : mod_item | fn_item | type_item | struct_item | enum_item
621-
| static_item | trait_item | impl_item | extern_block ;
621+
| static_item | trait_item | impl_item | foreign_mod_item ;
622622
~~~~~~~~
623623

624624
An _item_ is a component of a crate; some module items can be defined in crate
@@ -752,11 +752,10 @@ link_attr : ident '=' literal ;
752752
~~~~~~~~
753753

754754
An _`extern mod` declaration_ specifies a dependency on an external crate.
755-
The external crate is then bound into the declaring scope
756-
as the `ident` provided in the `extern_mod_decl`.
755+
The external crate is then bound into the declaring scope as the `ident` provided in the `extern_mod_decl`.
757756

758-
The external crate is resolved to a specific `soname` at compile time,
759-
and a runtime linkage requirement to that `soname` is passed to the linker for
757+
The external crate is resolved to a specific `soname` at compile time, and a
758+
runtime linkage requirement to that `soname` is passed to the linker for
760759
loading at runtime. The `soname` is resolved at compile time by scanning the
761760
compiler's library path and matching the `link_attrs` provided in the
762761
`use_decl` against any `#link` attributes that were declared on the external
@@ -993,10 +992,10 @@ Thus the return type on `f` only needs to reflect the `if` branch of the conditi
993992
#### Extern functions
994993

995994
Extern functions are part of Rust's foreign function interface,
996-
providing the opposite functionality to [external blocks](#external-blocks).
997-
Whereas external blocks allow Rust code to call foreign code,
998-
extern functions with bodies defined in Rust code _can be called by foreign
999-
code_. They are defined in the same way as any other Rust function,
995+
providing the opposite functionality to [foreign modules](#foreign-modules).
996+
Whereas foreign modules allow Rust code to call foreign code,
997+
extern functions with bodies defined in Rust code _can be called by foreign code_.
998+
They are defined in the same way as any other Rust function,
1000999
except that they have the `extern` modifier.
10011000

10021001
~~~
@@ -1012,8 +1011,7 @@ let fptr: *u8 = new_vec;
10121011
~~~
10131012

10141013
The primary motivation for extern functions is
1015-
to create callbacks for foreign functions that expect to receive function
1016-
pointers.
1014+
to create callbacks for foreign functions that expect to receive function pointers.
10171015

10181016
### Type definitions
10191017

@@ -1310,61 +1308,64 @@ impl Seq<bool> for u32 {
13101308
}
13111309
~~~~
13121310

1313-
### External blocks
1311+
### Foreign modules
13141312

13151313
~~~ {.ebnf .gram}
1316-
extern_block_item : "extern" '{' extern_block '} ;
1317-
extern_block : [ foreign_fn ] * ;
1314+
foreign_mod_item : "extern mod" ident '{' foreign_mod '} ;
1315+
foreign_mod : [ foreign_fn ] * ;
13181316
~~~
13191317

1320-
External blocks form the basis for Rust's foreign function interface.
1321-
Declarations in an external block describe symbols
1322-
in external, non-Rust libraries.
1323-
1324-
Functions within external blocks
1325-
are declared in the same way as other Rust functions,
1326-
with the exception that they may not have a body
1327-
and are instead terminated by a semicolon.
1318+
Foreign modules form the basis for Rust's foreign function interface. A
1319+
foreign module describes functions in external, non-Rust
1320+
libraries.
1321+
Functions within foreign modules are declared in the same way as other Rust functions,
1322+
with the exception that they may not have a body and are instead terminated by a semicolon.
13281323

13291324
~~~
13301325
# use core::libc::{c_char, FILE};
13311326
# #[nolink]
13321327
1333-
extern {
1328+
extern mod c {
13341329
fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
13351330
}
13361331
~~~
13371332

1338-
Functions within external blocks may be called by Rust code,
1339-
just like functions defined in Rust.
1340-
The Rust compiler automatically translates
1341-
between the Rust ABI and the foreign ABI.
1333+
Functions within foreign modules may be called by Rust code, just like functions defined in Rust.
1334+
The Rust compiler automatically translates between the Rust ABI and the foreign ABI.
1335+
1336+
The name of the foreign module has special meaning to the Rust compiler in
1337+
that it will treat the module name as the name of a library to link to,
1338+
performing the linking as appropriate for the target platform. The name
1339+
given for the foreign module will be transformed in a platform-specific way
1340+
to determine the name of the library. For example, on Linux the name of the
1341+
foreign module is prefixed with 'lib' and suffixed with '.so', so the
1342+
foreign mod 'rustrt' would be linked to a library named 'librustrt.so'.
13421343

1343-
A number of [attributes](#attributes) control the behavior of external
1344-
blocks.
1344+
A number of [attributes](#attributes) control the behavior of foreign
1345+
modules.
13451346

1346-
By default external blocks assume
1347-
that the library they are calling uses the standard C "cdecl" ABI.
1348-
Other ABIs may be specified using the `abi` attribute as in
1347+
By default foreign modules assume that the library they are calling use the
1348+
standard C "cdecl" ABI. Other ABIs may be specified using the `abi`
1349+
attribute as in
13491350

13501351
~~~{.xfail-test}
13511352
// Interface to the Windows API
13521353
#[abi = "stdcall"]
1353-
extern { }
1354+
extern mod kernel32 { }
13541355
~~~
13551356

1356-
The `link_name` attribute allows the name of the library to be specified.
1357+
The `link_name` attribute allows the default library naming behavior to
1358+
be overridden by explicitly specifying the name of the library.
13571359

13581360
~~~{.xfail-test}
13591361
#[link_name = "crypto"]
1360-
extern { }
1362+
extern mod mycrypto { }
13611363
~~~
13621364

1363-
The `nolink` attribute tells the Rust compiler
1364-
not to do any linking for the external block.
1365-
This is particularly useful for creating external blocks for libc,
1366-
which tends to not follow standard library naming conventions
1367-
and is linked to all Rust programs anyway.
1365+
The `nolink` attribute tells the Rust compiler not to do any linking for the foreign module.
1366+
This is particularly useful for creating foreign
1367+
modules for libc, which tends to not follow standard library naming
1368+
conventions and is linked to all Rust programs anyway.
13681369

13691370
## Attributes
13701371

branches/try2/doc/tutorial-ffi.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ convention to use:
237237
~~~~
238238
#[cfg(target_os = "win32")]
239239
#[abi = "stdcall"]
240-
#[link_name = "kernel32"]
241-
extern {
240+
extern mod kernel32 {
242241
fn SetEnvironmentVariableA(n: *u8, v: *u8) -> int;
243242
}
244243
~~~~

branches/try2/src/libcore/cell.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@ pub fn empty_cell<T>() -> Cell<T> {
4444
pub impl<T> Cell<T> {
4545
/// Yields the value, failing if the cell is empty.
4646
fn take(&self) -> T {
47-
let this = unsafe { transmute_mut(self) };
48-
if this.is_empty() {
47+
let self = unsafe { transmute_mut(self) };
48+
if self.is_empty() {
4949
fail!(~"attempt to take an empty cell");
5050
}
5151
52-
replace(&mut this.value, None).unwrap()
52+
replace(&mut self.value, None).unwrap()
5353
}
5454
5555
/// Returns the value, failing if the cell is full.
5656
fn put_back(&self, value: T) {
57-
let this = unsafe { transmute_mut(self) };
58-
if !this.is_empty() {
57+
let self = unsafe { transmute_mut(self) };
58+
if !self.is_empty() {
5959
fail!(~"attempt to put a value back into a full cell");
6060
}
61-
this.value = Some(value);
61+
self.value = Some(value);
6262
}
6363

6464
/// Returns true if the cell is empty and false if the cell is full.

branches/try2/src/libcore/core.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ pub mod util;
238238
/* Unsupported interfaces */
239239

240240
// Private APIs
241+
#[path = "unstable/mod.rs"]
241242
pub mod unstable;
242243

243244
/* For internal use, not exported */

branches/try2/src/libcore/num/strconv.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,11 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
486486
}
487487
}
488488

489-
let (start, accum_positive) = match buf[0] as char {
490-
'-' if !negative => return None,
491-
'-' => (1u, false),
492-
'+' => (1u, true),
493-
_ => (0u, true)
489+
let (start, accum_positive) = match buf[0] {
490+
'-' as u8 if !negative => return None,
491+
'-' as u8 => (1u, false),
492+
'+' as u8 => (1u, true),
493+
_ => (0u, true)
494494
};
495495

496496
// Initialize accumulator with signed zero for floating point parsing to

branches/try2/src/libcore/old_iter.rs

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -116,72 +116,66 @@ pub trait Buildable<A> {
116116
}
117117

118118
#[inline(always)]
119-
pub fn _eachi<A,IA:BaseIter<A>>(this: &IA, blk: &fn(uint, &A) -> bool) -> bool {
119+
pub fn _eachi<A,IA:BaseIter<A>>(self: &IA, blk: &fn(uint, &A) -> bool) -> bool {
120120
let mut i = 0;
121-
for this.each |a| {
122-
if !blk(i, a) {
123-
return false;
124-
}
121+
for self.each |a| {
122+
if !blk(i, a) { return false; }
125123
i += 1;
126124
}
127125
return true;
128126
}
129127

130128
#[cfg(stage0)]
131-
pub fn eachi<A,IA:BaseIter<A>>(this: &IA, blk: &fn(uint, &A) -> bool) {
132-
_eachi(this, blk);
129+
pub fn eachi<A,IA:BaseIter<A>>(self: &IA, blk: &fn(uint, &A) -> bool) {
130+
_eachi(self, blk);
133131
}
134132
#[cfg(not(stage0))]
135-
pub fn eachi<A,IA:BaseIter<A>>(this: &IA, blk: &fn(uint, &A) -> bool) -> bool {
136-
_eachi(this, blk)
133+
pub fn eachi<A,IA:BaseIter<A>>(self: &IA, blk: &fn(uint, &A) -> bool) -> bool {
134+
_eachi(self, blk)
137135
}
138136

139137
#[inline(always)]
140-
pub fn all<A,IA:BaseIter<A>>(this: &IA, blk: &fn(&A) -> bool) -> bool {
141-
for this.each |a| {
142-
if !blk(a) {
143-
return false;
144-
}
138+
pub fn all<A,IA:BaseIter<A>>(self: &IA, blk: &fn(&A) -> bool) -> bool {
139+
for self.each |a| {
140+
if !blk(a) { return false; }
145141
}
146142
return true;
147143
}
148144

149145
#[inline(always)]
150-
pub fn any<A,IA:BaseIter<A>>(this: &IA, blk: &fn(&A) -> bool) -> bool {
151-
for this.each |a| {
152-
if blk(a) {
153-
return true;
154-
}
146+
pub fn any<A,IA:BaseIter<A>>(self: &IA, blk: &fn(&A) -> bool) -> bool {
147+
for self.each |a| {
148+
if blk(a) { return true; }
155149
}
156150
return false;
157151
}
158152

159153
#[inline(always)]
160-
pub fn filter_to_vec<A:Copy,IA:BaseIter<A>>(this: &IA,
154+
pub fn filter_to_vec<A:Copy,IA:BaseIter<A>>(self: &IA,
161155
prd: &fn(&A) -> bool)
162156
-> ~[A] {
163-
do vec::build_sized_opt(this.size_hint()) |push| {
164-
for this.each |a| {
157+
do vec::build_sized_opt(self.size_hint()) |push| {
158+
for self.each |a| {
165159
if prd(a) { push(*a); }
166160
}
167161
}
168162
}
169163

170164
#[inline(always)]
171-
pub fn map_to_vec<A,B,IA:BaseIter<A>>(this: &IA, op: &fn(&A) -> B) -> ~[B] {
172-
do vec::build_sized_opt(this.size_hint()) |push| {
173-
for this.each |a| {
165+
pub fn map_to_vec<A,B,IA:BaseIter<A>>(self: &IA, op: &fn(&A) -> B) -> ~[B] {
166+
do vec::build_sized_opt(self.size_hint()) |push| {
167+
for self.each |a| {
174168
push(op(a));
175169
}
176170
}
177171
}
178172

179173
#[inline(always)]
180-
pub fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(this: &IA,
174+
pub fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(self: &IA,
181175
op: &fn(&A) -> IB)
182176
-> ~[B] {
183177
do vec::build |push| {
184-
for this.each |a| {
178+
for self.each |a| {
185179
for op(a).each |&b| {
186180
push(b);
187181
}
@@ -190,31 +184,31 @@ pub fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(this: &IA,
190184
}
191185

192186
#[inline(always)]
193-
pub fn foldl<A,B,IA:BaseIter<A>>(this: &IA, b0: B, blk: &fn(&B, &A) -> B)
187+
pub fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B, blk: &fn(&B, &A) -> B)
194188
-> B {
195189
let mut b = b0;
196-
for this.each |a| {
190+
for self.each |a| {
197191
b = blk(&b, a);
198192
}
199193
b
200194
}
201195

202196
#[inline(always)]
203-
pub fn to_vec<A:Copy,IA:BaseIter<A>>(this: &IA) -> ~[A] {
204-
map_to_vec(this, |&x| x)
197+
pub fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
198+
map_to_vec(self, |&x| x)
205199
}
206200

207201
#[inline(always)]
208-
pub fn contains<A:Eq,IA:BaseIter<A>>(this: &IA, x: &A) -> bool {
209-
for this.each |a| {
202+
pub fn contains<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> bool {
203+
for self.each |a| {
210204
if *a == *x { return true; }
211205
}
212206
return false;
213207
}
214208

215209
#[inline(always)]
216-
pub fn count<A:Eq,IA:BaseIter<A>>(this: &IA, x: &A) -> uint {
217-
do foldl(this, 0) |count, value| {
210+
pub fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
211+
do foldl(self, 0) |count, value| {
218212
if *value == *x {
219213
*count + 1
220214
} else {
@@ -224,10 +218,10 @@ pub fn count<A:Eq,IA:BaseIter<A>>(this: &IA, x: &A) -> uint {
224218
}
225219

226220
#[inline(always)]
227-
pub fn position<A,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool)
221+
pub fn position<A,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
228222
-> Option<uint> {
229223
let mut i = 0;
230-
for this.each |a| {
224+
for self.each |a| {
231225
if f(a) { return Some(i); }
232226
i += 1;
233227
}
@@ -259,8 +253,8 @@ pub fn repeat(times: uint, blk: &fn() -> bool) -> bool {
259253
}
260254

261255
#[inline(always)]
262-
pub fn min<A:Copy + Ord,IA:BaseIter<A>>(this: &IA) -> A {
263-
match do foldl::<A,Option<A>,IA>(this, None) |a, b| {
256+
pub fn min<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
257+
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
264258
match a {
265259
&Some(ref a_) if *a_ < *b => {
266260
*(a)
@@ -274,8 +268,8 @@ pub fn min<A:Copy + Ord,IA:BaseIter<A>>(this: &IA) -> A {
274268
}
275269
276270
#[inline(always)]
277-
pub fn max<A:Copy + Ord,IA:BaseIter<A>>(this: &IA) -> A {
278-
match do foldl::<A,Option<A>,IA>(this, None) |a, b| {
271+
pub fn max<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
272+
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
279273
match a {
280274
&Some(ref a_) if *a_ > *b => {
281275
*(a)
@@ -289,9 +283,9 @@ pub fn max<A:Copy + Ord,IA:BaseIter<A>>(this: &IA) -> A {
289283
}
290284

291285
#[inline(always)]
292-
pub fn find<A:Copy,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool)
286+
pub fn find<A:Copy,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
293287
-> Option<A> {
294-
for this.each |i| {
288+
for self.each |i| {
295289
if f(i) { return Some(*i) }
296290
}
297291
return None;

0 commit comments

Comments
 (0)