Skip to content

Commit 4b745a4

Browse files
committed
---
yaml --- r: 24455 b: refs/heads/master c: d8287f0 h: refs/heads/master i: 24453: 495b8d6 24451: d9287ef 24447: 83f7273 v: v3
1 parent 476725b commit 4b745a4

Some content is hidden

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

41 files changed

+501
-392
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 84bc74e54a2d46f87c4205b99e78c2ce3ef9c881
2+
refs/heads/master: d8287f0e41be93fa0c902cac71637cbcb1632a50
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/doc/rust.md

Lines changed: 130 additions & 141 deletions
Large diffs are not rendered by default.

trunk/doc/tutorial.md

Lines changed: 10 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,12 @@ and functions defined in it. If it has a `main` function, it can be
162162
compiled to an executable. Rust does not allow code that's not a
163163
declaration to appear at the top level of the file—all statements must
164164
live inside a function. Rust programs can also be compiled as
165-
libraries, and included in other programs.
165+
libraries, and included in other programs. The `extern mod std`
166+
directive that appears at the top of many examples imports the
167+
[standard library][std], described in more detail [later
168+
on](#modules-and-crates).
169+
170+
[std]: http://doc.rust-lang.org/doc/std
166171

167172
## Editing Rust code
168173

@@ -1279,73 +1284,6 @@ For a more in-depth explanation of borrowed pointers, read the
12791284
12801285
[borrowtut]: tutorial-borrowed-ptr.html
12811286
1282-
## Dereferencing pointers
1283-
1284-
Rust uses the unary star operator (`*`) to access the contents of a
1285-
box or pointer, similarly to C.
1286-
1287-
~~~
1288-
let managed = @10;
1289-
let owned = ~20;
1290-
let borrowed = &30;
1291-
1292-
let sum = *managed + *owned + *borrowed;
1293-
~~~
1294-
1295-
Dereferenced mutable pointers may appear on the left hand side of
1296-
assignments, in which case the value they point to is modified.
1297-
1298-
~~~
1299-
let managed = @mut 10;
1300-
let owned = ~mut 20;
1301-
1302-
let mut value = 30;
1303-
let borrowed = &mut value;
1304-
1305-
*managed = *owned + 10;
1306-
*owned = *borrowed + 100;
1307-
*borrowed = *managed + 1000;
1308-
~~~
1309-
1310-
Pointers have high operator precedence, but lower precedence than the
1311-
dot operator used for field and method access. This can lead to some
1312-
awkward code filled with parenthesis.
1313-
1314-
~~~
1315-
# struct Point { x: float, y: float }
1316-
# enum Shape { Rectangle(Point, Point) }
1317-
# impl Shape { fn area() -> int { 0 } }
1318-
let start = @Point { x: 10f, y: 20f };
1319-
let end = ~Point { x: (*start).x + 100f, y: (*start).y + 100f };
1320-
let rect = &Rectangle(*start, *end);
1321-
let area = (*rect).area();
1322-
~~~
1323-
1324-
To combat this ugliness the dot operator performs _automatic pointer
1325-
dereferencing_ on the receiver (the value on the left hand side of the
1326-
dot), so in most cases dereferencing the receiver is not necessary.
1327-
1328-
~~~
1329-
# struct Point { x: float, y: float }
1330-
# enum Shape { Rectangle(Point, Point) }
1331-
# impl Shape { fn area() -> int { 0 } }
1332-
let start = @Point { x: 10f, y: 20f };
1333-
let end = ~Point { x: start.x + 100f, y: start.y + 100f };
1334-
let rect = &Rectangle(*start, *end);
1335-
let area = rect.area();
1336-
~~~
1337-
1338-
Auto-dereferencing is performed through any number of pointers. If you
1339-
felt inclined you could write something silly like
1340-
1341-
~~~
1342-
# struct Point { x: float, y: float }
1343-
let point = &@~Point { x: 10f, y: 20f };
1344-
io::println(fmt!("%f", point.x));
1345-
~~~
1346-
1347-
The indexing operator (`[]`) is also auto-dereferencing.
1348-
13491287
# Vectors and strings
13501288
13511289
Vectors are a contiguous section of memory containing zero or more
@@ -1443,7 +1381,7 @@ mutable_crayons[0] = Apricot;
14431381
This is a simple example of Rust's _dual-mode data structures_, also
14441382
referred to as _freezing and thawing_.
14451383

1446-
Strings are implemented with vectors of `u8`, though they have a distinct
1384+
Strings are implemented with vectors of `[u8]`, though they have a distinct
14471385
type. They support most of the same allocation options as
14481386
vectors, though the string literal without a storage sigil, e.g.
14491387
`"foo"` is treated differently than a comparable vector (`[foo]`).
@@ -1553,7 +1491,7 @@ access local variables in the enclosing scope.
15531491

15541492
~~~~
15551493
let mut max = 0;
1556-
[1, 2, 3].map(|x| if *x > max { max = *x });
1494+
(~[1, 2, 3]).map(|x| if *x > max { max = *x });
15571495
~~~~
15581496

15591497
Stack closures are very efficient because their environment is
@@ -1581,7 +1519,8 @@ This code creates a closure that adds a given string to its argument,
15811519
returns it from a function, and then calls it:
15821520

15831521
~~~~
1584-
# extern mod std;
1522+
extern mod std;
1523+
15851524
fn mk_appender(suffix: ~str) -> fn@(~str) -> ~str {
15861525
return fn@(s: ~str) -> ~str { s + suffix };
15871526
}

trunk/src/etc/kate/rust.xml

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE language SYSTEM "language.dtd">
3-
<language name="Rust" version="0.4.0" kateversion="2.4" section="Sources" extensions="*.rs;*.rc" mimetype="text/x-rust" priority="15">
3+
<language name="Rust" version="0.3.1" kateversion="2.4" section="Sources" extensions="*.rs;*.rc" mimetype="text/x-rust" priority="15">
44
<highlighting>
55
<list name="fn">
66
<item> fn </item>
@@ -9,39 +9,59 @@
99
<item> type </item>
1010
</list>
1111
<list name="keywords">
12+
<item> alt </item>
13+
<item> again </item>
1214
<item> as </item>
1315
<item> assert </item>
1416
<item> break </item>
17+
<item> check </item>
18+
<item> claim </item>
1519
<item> const </item>
1620
<item> copy </item>
1721
<item> do </item>
1822
<item> drop </item>
1923
<item> else </item>
20-
<item> enum </item>
2124
<item> export </item>
2225
<item> extern </item>
26+
<item> f16 </item>
27+
<item> f80 </item>
28+
<item> f128 </item>
2329
<item> fail </item>
2430
<item> for </item>
2531
<item> if </item>
2632
<item> impl </item>
33+
<item> import </item>
34+
<item> in </item>
2735
<item> let </item>
2836
<item> log </item>
2937
<item> loop </item>
38+
<item> m32 </item>
39+
<item> m64 </item>
40+
<item> m128 </item>
3041
<item> match </item>
3142
<item> mod </item>
43+
<item> module </item>
3244
<item> move </item>
3345
<item> mut </item>
46+
<item> new </item>
47+
<item> of </item>
48+
<item> owned </item>
3449
<item> priv </item>
3550
<item> pub </item>
3651
<item> pure </item>
37-
<item> ref </item>
52+
<item> ret </item>
3853
<item> return </item>
39-
<item> static </item>
40-
<item> struct </item>
41-
<item> trait </item>
54+
<item> to </item>
55+
<item> unchecked </item>
4256
<item> unsafe </item>
4357
<item> use </item>
4458
<item> while </item>
59+
<item> with </item>
60+
<item> mod </item>
61+
<item> trait </item>
62+
<item> class </item>
63+
<item> struct </item>
64+
<item> enum </item>
4565
</list>
4666
<list name="types">
4767
<item> bool </item>
@@ -60,9 +80,8 @@
6080
<item> float </item>
6181
<item> char </item>
6282
<item> str </item>
63-
<item> Either </item>
64-
<item> Option </item>
65-
<item> Result </item>
83+
<item> option </item>
84+
<item> either </item>
6685
</list>
6786
<list name="ctypes">
6887
<item> c_float </item>
@@ -102,16 +121,16 @@
102121
<list name="constants">
103122
<item> true </item>
104123
<item> false </item>
105-
<item> Some </item>
106-
<item> None </item>
107-
<item> Left </item>
108-
<item> Right </item>
109-
<item> Ok </item>
110-
<item> Err </item>
111-
<item> Success </item>
112-
<item> Failure </item>
113-
<item> Cons </item>
114-
<item> Nil </item>
124+
<item> some </item>
125+
<item> none </item>
126+
<item> left </item>
127+
<item> right </item>
128+
<item> ok </item>
129+
<item> err </item>
130+
<item> success </item>
131+
<item> failure </item>
132+
<item> cons </item>
133+
<item> nil </item>
115134
</list>
116135
<list name="cconstants">
117136
<item> EXIT_FAILURE </item>

trunk/src/libcore/at_vec.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ extern mod rustrt {
2121
#[abi = "rust-intrinsic"]
2222
extern mod rusti {
2323
#[legacy_exports];
24+
#[cfg(stage0)]
25+
fn move_val_init<T>(&dst: T, -src: T);
26+
#[cfg(stage1)]
27+
#[cfg(stage2)]
2428
fn move_val_init<T>(dst: &mut T, -src: T);
2529
}
2630

@@ -177,6 +181,20 @@ pub mod raw {
177181
}
178182
}
179183

184+
// This doesn't bother to make sure we have space.
185+
#[cfg(stage0)]
186+
#[inline(always)] // really pretty please
187+
pub unsafe fn push_fast<T>(v: &mut @[const T], initval: T) {
188+
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
189+
let fill = (**repr).unboxed.fill;
190+
(**repr).unboxed.fill += sys::size_of::<T>();
191+
let p = addr_of(&((**repr).unboxed.data));
192+
let p = ptr::offset(p, fill) as *mut T;
193+
rusti::move_val_init(*p, move initval);
194+
}
195+
// This doesn't bother to make sure we have space.
196+
#[cfg(stage1)]
197+
#[cfg(stage2)]
180198
#[inline(always)] // really pretty please
181199
pub unsafe fn push_fast<T>(v: &mut @[const T], initval: T) {
182200
let repr: **VecRepr = ::cast::reinterpret_cast(&v);

trunk/src/libcore/vec.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ extern mod rustrt {
1818

1919
#[abi = "rust-intrinsic"]
2020
extern mod rusti {
21+
#[cfg(stage0)]
22+
fn move_val_init<T>(&dst: T, -src: T);
23+
#[cfg(stage1)]
24+
#[cfg(stage2)]
2125
fn move_val_init<T>(dst: &mut T, -src: T);
2226
}
2327

@@ -99,6 +103,23 @@ pub pure fn len<T>(v: &[const T]) -> uint {
99103
* Creates an immutable vector of size `n_elts` and initializes the elements
100104
* to the value returned by the function `op`.
101105
*/
106+
#[cfg(stage0)]
107+
pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
108+
unsafe {
109+
let mut v = with_capacity(n_elts);
110+
do as_mut_buf(v) |p, _len| {
111+
let mut i: uint = 0u;
112+
while i < n_elts {
113+
rusti::move_val_init(*ptr::mut_offset(p, i), op(i));
114+
i += 1u;
115+
}
116+
}
117+
raw::set_len(&mut v, n_elts);
118+
return move v;
119+
}
120+
}
121+
#[cfg(stage1)]
122+
#[cfg(stage2)]
102123
pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
103124
unsafe {
104125
let mut v = with_capacity(n_elts);
@@ -482,6 +503,19 @@ pub fn push<T>(v: &mut ~[T], initval: T) {
482503
}
483504
}
484505

506+
#[cfg(stage0)]
507+
// This doesn't bother to make sure we have space.
508+
#[inline(always)] // really pretty please
509+
unsafe fn push_fast<T>(v: &mut ~[T], initval: T) {
510+
let repr: **raw::VecRepr = ::cast::transmute(v);
511+
let fill = (**repr).unboxed.fill;
512+
(**repr).unboxed.fill += sys::size_of::<T>();
513+
let p = addr_of(&((**repr).unboxed.data));
514+
let p = ptr::offset(p, fill) as *mut T;
515+
rusti::move_val_init(*p, move initval);
516+
}
517+
#[cfg(stage1)]
518+
#[cfg(stage2)]
485519
// This doesn't bother to make sure we have space.
486520
#[inline(always)] // really pretty please
487521
unsafe fn push_fast<T>(v: &mut ~[T], initval: T) {
@@ -1759,6 +1793,18 @@ pub mod raw {
17591793
as_const_buf(v, |p, _len| *ptr::const_offset(p, i))
17601794
}
17611795

1796+
#[cfg(stage0)]
1797+
#[inline(always)]
1798+
pub unsafe fn init_elem<T>(v: &[mut T], i: uint, val: T) {
1799+
let mut box = Some(move val);
1800+
do as_mut_buf(v) |p, _len| {
1801+
let mut box2 = None;
1802+
box2 <-> box;
1803+
rusti::move_val_init(*ptr::mut_offset(p, i),
1804+
option::unwrap(move box2));
1805+
}
1806+
}
1807+
#[cfg(stage1)]
17621808
/**
17631809
* Unchecked vector index assignment. Does not drop the
17641810
* old value and hence is only suitable when the vector

0 commit comments

Comments
 (0)