Skip to content

Commit 3054090

Browse files
committed
---
yaml --- r: 13695 b: refs/heads/master c: f1acc69 h: refs/heads/master i: 13693: 99d7116 13691: 924014d 13687: 32a1156 13679: 347d1ec 13663: ccd8425 13631: 4849b1e 13567: aad563c v: v3
1 parent fe694f5 commit 3054090

File tree

120 files changed

+1279
-1782
lines changed

Some content is hidden

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

120 files changed

+1279
-1782
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: 6322eda35ca0e5d05247eccfa820f0aa730591ce
2+
refs/heads/master: f1acc69a2a81c9f82b78c4d9773202f39e8ada5c
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/RELEASES.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Version 0.3 (June 2012) - not yet!
77
* Integer-literal suffix inference
88
* Per-module control over warnings, errors
99
* #[cfg(windows)] and #[cfg(unix)] attributes
10+
* *-patterns (wildcard extended to all constructor fields)
1011

1112
* Semantic cleanup
1213
* Resolve pass and exhaustiveness checker rewritten
@@ -17,12 +18,13 @@ Version 0.3 (June 2012) - not yet!
1718
* Experimental new language features
1819
* Slices and fixed-size, interior-allocated vectors
1920
* #!-comments for lang versioning, shell execution
20-
* More work on classes
21+
* Destructors and iface implementation for classes;
22+
type-parameterized classes and class methods
2123
* Type reflection
2224

2325
* Removal of various obsolete features
2426
* Keywords: be, prove, syntax, note, mutable, do, bind
25-
* Constructs: do-while loops, fn binding,
27+
* Constructs: do-while loops, fn binding, resources
2628

2729
* Compiler reorganization
2830
* Syntax-layer of compiler split into separate crate
@@ -39,6 +41,9 @@ Version 0.3 (June 2012) - not yet!
3941
* Syntax extensions: #line, #col, #file, #mod,
4042
#stringify, #include, #include_str, #include_bin.
4143

44+
* Tool improvements
45+
* Cargo automatically resolves dependencies
46+
4247
Version 0.2 (March 2012)
4348
-------------------------
4449

trunk/configure

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,8 @@ fi
311311
step_msg "looking for build programs"
312312

313313
probe_need CFG_PERL perl
314+
probe_need CFG_PYTHON python python2.6 python2 python3
314315
probe_need CFG_CURL curl
315-
probe_need CFG_PYTHON python2.7 python2.6 python2 python
316-
317-
python_version=$($CFG_PYTHON -V 2>&1)
318-
if [ $(echo $python_version | grep -c '^Python 2\.[4567]') -ne 1 ]; then
319-
err "Found $python_version, but LLVM requires Python 2.4-2.7"
320-
fi
321316

322317
# If we have no git directory then we are probably a tarball distribution
323318
# and shouldn't attempt to load submodules

trunk/doc/rust.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,30 +1127,40 @@ enum list<T> {
11271127
let a: list<int> = cons(7, @cons(13, @nil));
11281128
~~~~
11291129

1130-
### Resources
1130+
### Classes
11311131

1132-
_Resources_ are values that have a destructor associated with them. A
1133-
_resource item_ is used to declare resource type and constructor.
1132+
TODO: more about classes
1133+
1134+
_Classes_ are named record types that may have a destructor associated
1135+
with them, as well as fields and methods. For historical reasons, we
1136+
may call a class with a destructor and a single field a "resource".
1137+
1138+
A _class item_ declares a class type:
11341139

11351140
~~~~
1136-
resource file_descriptor(fd: libc::c_int) {
1137-
libc::close(fd);
1141+
class file_descriptor {
1142+
let fd: libc::c_int;
1143+
new(fd: libc::c_int) { self.fd = fd; }
1144+
drop { libc::close(self.fd); }
11381145
}
11391146
~~~~
11401147

11411148
Calling the `file_descriptor` constructor function on an integer will
11421149
produce a value with the `file_descriptor` type. Resource types have a
1143-
noncopyable [type kind](#type-kinds), and thus may not be copied. The
1144-
semantics guarantee that for each constructed resources value, the
1145-
destructor will run once: when the value is disposed of (barring
1146-
drastic program termination that somehow prevents unwinding from taking
1147-
place). For stack-allocated values, disposal happens when the value
1148-
goes out of scope. For values in shared boxes, it happens when the
1149-
reference count of the box reaches zero.
1150-
1151-
The argument to the resource constructor is stored in the resulting
1152-
value, and can be accessed using the dereference (`*`) [unary
1153-
operator](#unary-operator-expressions).
1150+
noncopyable [type kind](#type-kinds), and thus may not be
1151+
copied. Class types that don't have destructors may be copied if all
1152+
their fields are copyable. The semantics guarantee that for each
1153+
constructed resource value, the destructor will run once: when the
1154+
value is disposed of (barring drastic program termination that somehow
1155+
prevents unwinding from taking place). For stack-allocated values,
1156+
disposal happens when the value goes out of scope. For values in
1157+
shared boxes, it happens when the reference count of the box reaches
1158+
zero.
1159+
1160+
The argument or arguments to the class constructor may be stored in
1161+
the class's named fields, and can be accessed by a field reference. In
1162+
this case, the `file_descriptor`'s data field would be accessed like
1163+
`f.fd`, if `f` is a value of type `file_descriptor`.
11541164

11551165
### Interfaces
11561166

trunk/doc/tutorial.md

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,26 +1377,7 @@ Like vectors, strings are always unique. You can wrap them in a shared
13771377
box to share them. Unlike vectors, there is no mutable variant of
13781378
strings. They are always immutable.
13791379
1380-
## Resources
1381-
1382-
Resources are data types that have a destructor associated with them.
1383-
1384-
~~~~
1385-
# fn close_file_desc(x: int) {}
1386-
resource file_desc(fd: int) {
1387-
close_file_desc(fd);
1388-
}
1389-
~~~~
1390-
1391-
This defines a type `file_desc` and a constructor of the same name,
1392-
which takes an integer. The type has an associated destructor procedure,
1393-
whose contents are specified by the block. Values of such a type can not
1394-
be copied, and when they are destroyed (by going out of scope, or, when
1395-
boxed, when their box is cleaned up), their body runs. In the example
1396-
above, this would cause the given file descriptor to be closed.
1397-
1398-
NOTE: We're considering alternative approaches for data types with
1399-
destructors. Resources might go away in the future.
1380+
NOTE: Section on resources removed. ToDo: document classes and destructors
14001381
14011382
# Argument passing
14021383
@@ -1581,7 +1562,7 @@ without any sophistication).
15811562
## Kinds
15821563
15831564
Perhaps surprisingly, the 'copy' (duplicate) operation is not defined
1584-
for all Rust types. Resource types (types with destructors) can not be
1565+
for all Rust types. Resource types (classes with destructors) cannot be
15851566
copied, and neither can any type whose copying would require copying a
15861567
resource (such as records or unique boxes containing a resource).
15871568

trunk/mk/platform.mk

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ endef
99
$(foreach t,$(CFG_TARGET_TRIPLES),$(eval $(call DEF_HOST_VAR,$(t))))
1010
$(foreach t,$(CFG_TARGET_TRIPLES),$(info cfg: host for $(t) is $(HOST_$(t))))
1111

12-
# FIXME: This appears to do nothing
13-
CFG_GCCISH_FLAGS += -fno-strict-aliasing
14-
1512
# FIXME: no-omit-frame-pointer is just so that task_start_wrapper
1613
# has a frame pointer and the stack walker can understand it. Turning off
1714
# frame pointers everywhere is overkill
@@ -146,7 +143,7 @@ ifdef CFG_UNIXY
146143
CFG_VALGRIND += wine
147144
endif
148145

149-
CFG_GCCISH_CFLAGS := -fno-strict-aliasing -march=i586
146+
CFG_GCCISH_CFLAGS := -march=i586
150147
CFG_GCCISH_PRE_LIB_FLAGS :=
151148
CFG_GCCISH_POST_LIB_FLAGS :=
152149
CFG_GCCISH_DEF_FLAG :=

trunk/src/libcore/arc.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ type arc_data<T> = {
2424
data: T
2525
};
2626

27-
resource arc_destruct<T>(data: *libc::c_void) {
28-
unsafe {
29-
let data: ~arc_data<T> = unsafe::reinterpret_cast(data);
30-
let new_count = rustrt::rust_atomic_decrement(&mut data.count);
31-
assert new_count >= 0;
32-
if new_count == 0 {
33-
// drop glue takes over.
34-
} else {
35-
unsafe::forget(data);
36-
}
37-
}
27+
class arc_destruct<T> {
28+
let data: *libc::c_void;
29+
new(data: *libc::c_void) { self.data = data; }
30+
drop unsafe {
31+
let data: ~arc_data<T> = unsafe::reinterpret_cast(self.data);
32+
let new_count = rustrt::rust_atomic_decrement(&mut data.count);
33+
assert new_count >= 0;
34+
if new_count == 0 {
35+
// drop glue takes over.
36+
} else {
37+
unsafe::forget(data);
38+
}
39+
}
3840
}
3941

4042
type arc<T: const> = arc_destruct<T>;
@@ -52,7 +54,7 @@ fn arc<T: const>(-data: T) -> arc<T> {
5254
wrapper."]
5355
fn get<T: const>(rc: &a.arc<T>) -> &a.T {
5456
unsafe {
55-
let ptr: ~arc_data<T> = unsafe::reinterpret_cast(**rc);
57+
let ptr: ~arc_data<T> = unsafe::reinterpret_cast((*rc).data);
5658
// Cast us back into the correct region
5759
let r = unsafe::reinterpret_cast(&ptr.data);
5860
unsafe::forget(ptr);
@@ -67,12 +69,12 @@ object. However, one of the `arc` objects can be sent to another task,
6769
allowing them to share the underlying data."]
6870
fn clone<T: const>(rc: &arc<T>) -> arc<T> {
6971
unsafe {
70-
let ptr: ~arc_data<T> = unsafe::reinterpret_cast(**rc);
72+
let ptr: ~arc_data<T> = unsafe::reinterpret_cast((*rc).data);
7173
let new_count = rustrt::rust_atomic_increment(&mut ptr.count);
7274
assert new_count >= 2;
7375
unsafe::forget(ptr);
7476
}
75-
arc_destruct(**rc)
77+
arc_destruct((*rc).data)
7678
}
7779

7880
// An arc over mutable data that is protected by a lock.
@@ -93,17 +95,19 @@ impl methods<T: send> for exclusive<T> {
9395
fn clone() -> exclusive<T> {
9496
unsafe {
9597
// this makes me nervous...
96-
let ptr: ~arc_data<ex_data<T>> = unsafe::reinterpret_cast(*self);
98+
let ptr: ~arc_data<ex_data<T>> =
99+
unsafe::reinterpret_cast(self.data);
97100
let new_count = rustrt::rust_atomic_increment(&mut ptr.count);
98101
assert new_count > 1;
99102
unsafe::forget(ptr);
100103
}
101-
arc_destruct(*self)
104+
arc_destruct(self.data)
102105
}
103106

104107
fn with<U>(f: fn(sys::condition, x: &T) -> U) -> U {
105108
unsafe {
106-
let ptr: ~arc_data<ex_data<T>> = unsafe::reinterpret_cast(*self);
109+
let ptr: ~arc_data<ex_data<T>> =
110+
unsafe::reinterpret_cast(self.data);
107111
let r = {
108112
let rec: &ex_data<T> = &(*ptr).data;
109113
rec.lock.lock_cond() {|c|
@@ -123,8 +127,10 @@ type get_chan<T: const send> = chan<chan<arc<T>>>;
123127
// (terminate, get)
124128
type shared_arc<T: const send> = (shared_arc_res, get_chan<T>);
125129

126-
resource shared_arc_res(c: comm::chan<()>) {
127-
c.send(());
130+
class shared_arc_res {
131+
let c: comm::chan<()>;
132+
new(c: comm::chan<()>) { self.c = c; }
133+
drop { self.c.send(()); }
128134
}
129135

130136
fn shared_arc<T: send const>(-data: T) -> shared_arc<T> {

trunk/src/libcore/box.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
export ptr_eq;
44

5-
pure fn ptr_eq<T>(a: @T, b: @T) -> bool unchecked {
5+
pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
66
#[doc = "Determine if two shared boxes point to the same object"];
7-
ptr::addr_of(*a) == ptr::addr_of(*b)
7+
unsafe { ptr::addr_of(*a) == ptr::addr_of(*b) }
88
}
99

1010
#[test]

trunk/src/libcore/char.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ fn test_to_digit() {
231231
}
232232

233233
#[test]
234-
fn test_is_ascii() unsafe {
234+
fn test_is_ascii() {
235235
assert str::all("banana", char::is_ascii);
236236
assert ! str::all("ประเทศไทย中华Việt Nam", char::is_ascii);
237237
}

trunk/src/libcore/comm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ fn recv_<T: send>(p: *rust_port) -> T {
210210
ret res;
211211
}
212212

213-
fn peek_(p: *rust_port) -> bool unsafe {
213+
fn peek_(p: *rust_port) -> bool {
214214
rustrt::rust_port_size(p) != 0u as libc::size_t
215215
}
216216

217217
#[doc = "Receive on one of two ports"]
218218
fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>)
219-
-> either<A, B> unsafe {
219+
-> either<A, B> {
220220
let ports = [(**p_a).po, (**p_b).po];
221221
let n_ports = 2 as libc::size_t;
222222
let yield = 0u, yieldp = ptr::addr_of(yield);

trunk/src/libcore/core.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,24 @@ import option_iter::extensions;
1212
import ptr::extensions;
1313
import rand::extensions;
1414
import result::extensions;
15+
import int::num;
16+
import i8::num;
17+
import i16::num;
18+
import i32::num;
19+
import i64::num;
20+
import uint::num;
21+
import u8::num;
22+
import u16::num;
23+
import u32::num;
24+
import u64::num;
25+
import float::num;
26+
import f32::num;
27+
import f64::num;
1528

1629
export path, option, some, none, unreachable;
1730
export extensions;
31+
// The following exports are the extension impls for numeric types
32+
export num;
1833

1934
// Export the log levels as global constants. Higher levels mean
2035
// more-verbosity. Error is the bottom level, default logging level is

trunk/src/libcore/extfmt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ mod ct {
8181
enum piece { piece_string(str), piece_conv(conv), }
8282
type error_fn = fn@(str) -> ! ;
8383

84-
fn parse_fmt_string(s: str, error: error_fn) -> [piece] unsafe {
84+
fn parse_fmt_string(s: str, error: error_fn) -> [piece] {
8585
let mut pieces: [piece] = [];
8686
let lim = str::len(s);
8787
let mut buf = "";
@@ -225,7 +225,7 @@ mod ct {
225225
} else { {count: count_implied, next: i} };
226226
}
227227
fn parse_type(s: str, i: uint, lim: uint, error: error_fn) ->
228-
{ty: ty, next: uint} unsafe {
228+
{ty: ty, next: uint} {
229229
if i >= lim { error("missing type in conversion"); }
230230
let tstr = str::slice(s, i, i+1u);
231231
// TODO: Do we really want two signed types here?
@@ -314,7 +314,7 @@ mod rt {
314314
let mut s = str::from_char(c);
315315
ret pad(cv, s, pad_nozero);
316316
}
317-
fn conv_str(cv: conv, s: str) -> str unsafe {
317+
fn conv_str(cv: conv, s: str) -> str {
318318
// For strings, precision is the maximum characters
319319
// displayed
320320
let mut unpadded = alt cv.precision {
@@ -378,7 +378,7 @@ mod rt {
378378
};
379379
}
380380
enum pad_mode { pad_signed, pad_unsigned, pad_nozero, pad_float }
381-
fn pad(cv: conv, &s: str, mode: pad_mode) -> str unsafe {
381+
fn pad(cv: conv, &s: str, mode: pad_mode) -> str {
382382
let uwidth : uint = alt cv.width {
383383
count_implied { ret s; }
384384
count_is(width) {

trunk/src/libcore/f32.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
import cmath::c_float::*;
66
import cmath::c_float_targ_consts::*;
7-
import num::num;
87

9-
export add, sub, mul, div, rem, lt, le, gt, eq, eq, ne;
8+
export add, sub, mul, div, rem, lt, le, gt, eq, ne;
109
export is_positive, is_negative, is_nonpositive, is_nonnegative;
1110
export is_zero, is_infinite, is_finite;
1211
export NaN, is_NaN, infinity, neg_infinity;
@@ -18,6 +17,7 @@ export mul_add, fmax, fmin, nextafter, frexp, hypot, ldexp;
1817
export lgamma, ln, log_radix, ln1p, log10, log2, ilog_radix;
1918
export modf, pow, round, sin, sinh, sqrt, tan, tanh, tgamma, trunc;
2019
export signbit;
20+
2121
export num;
2222

2323
// These are not defined inside consts:: for consistency with
@@ -173,7 +173,7 @@ pure fn log2(n: f32) -> f32 {
173173
ret ln(n) / consts::ln_2;
174174
}
175175

176-
impl num of num for f32 {
176+
impl num of num::num for f32 {
177177
fn add(&&other: f32) -> f32 { ret self + other; }
178178
fn sub(&&other: f32) -> f32 { ret self - other; }
179179
fn mul(&&other: f32) -> f32 { ret self * other; }

0 commit comments

Comments
 (0)