Skip to content

Commit 3261693

Browse files
bogglebrson
authored andcommitted
---
yaml --- r: 6280 b: refs/heads/master c: d335d1a h: refs/heads/master v: v3
1 parent 47120f7 commit 3261693

File tree

17 files changed

+123
-142
lines changed

17 files changed

+123
-142
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: a7188a6577518475cbeafffb5551b2835f2ec91d
2+
refs/heads/master: d335d1a1699ed66d44d3efa03a46762c0473f316

trunk/src/lib/bitv.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ The bitvector type.
3636
type t = @{storage: [mutable uint], nbits: uint};
3737

3838

39-
// FIXME: this should be a constant once they work
40-
fn uint_bits() -> uint { ret 32u + (1u << 32u >> 27u); }
39+
const uint_bits: uint = 32u + (1u << 32u >> 27u);
4140

4241
/*
4342
Function: create
@@ -50,7 +49,7 @@ init - If true then the bits are initialized to 1, otherwise 0
5049
*/
5150
fn create(nbits: uint, init: bool) -> t {
5251
let elt = if init { !0u } else { 0u };
53-
let storage = vec::init_elt_mut::<uint>(elt, nbits / uint_bits() + 1u);
52+
let storage = vec::init_elt_mut::<uint>(elt, nbits / uint_bits + 1u);
5453
ret @{storage: storage, nbits: nbits};
5554
}
5655

@@ -118,7 +117,7 @@ Function: clone
118117
Makes a copy of a bitvector
119118
*/
120119
fn clone(v: t) -> t {
121-
let storage = vec::init_elt_mut::<uint>(0u, v.nbits / uint_bits() + 1u);
120+
let storage = vec::init_elt_mut::<uint>(0u, v.nbits / uint_bits + 1u);
122121
let len = vec::len(v.storage);
123122
uint::range(0u, len) {|i| storage[i] = v.storage[i]; };
124123
ret @{storage: storage, nbits: v.nbits};
@@ -131,7 +130,7 @@ Retreive the value at index `i`
131130
*/
132131
fn get(v: t, i: uint) -> bool {
133132
assert (i < v.nbits);
134-
let bits = uint_bits();
133+
let bits = uint_bits;
135134
let w = i / bits;
136135
let b = i % bits;
137136
let x = 1u & v.storage[w] >> b;
@@ -229,7 +228,7 @@ Preconditions:
229228
*/
230229
fn set(v: t, i: uint, x: bool) {
231230
assert (i < v.nbits);
232-
let bits = uint_bits();
231+
let bits = uint_bits;
233232
let w = i / bits;
234233
let b = i % bits;
235234
let flag = 1u << b;

trunk/src/lib/float.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn from_str(num: str) -> float {
107107
//The string must start with one of the following characters.
108108
alt str::char_at(num, 0u) {
109109
'-' | '+' | '0' to '9' | '.' {}
110-
_ { ret NaN(); }
110+
_ { ret NaN; }
111111
}
112112

113113
//Determine if first char is '-'/'+'. Set [pos] and [neg] accordingly.
@@ -137,7 +137,7 @@ fn from_str(num: str) -> float {
137137
break;
138138
}
139139
_ {
140-
ret NaN();
140+
ret NaN;
141141
}
142142
}
143143
}
@@ -157,7 +157,7 @@ fn from_str(num: str) -> float {
157157
break;
158158
}
159159
_ {
160-
ret NaN();
160+
ret NaN;
161161
}
162162
}
163163
}
@@ -202,12 +202,12 @@ fn from_str(num: str) -> float {
202202
total = total * multiplier;
203203
}
204204
} else {
205-
ret NaN();
205+
ret NaN;
206206
}
207207
}
208208

209209
if(pos < len) {
210-
ret NaN();
210+
ret NaN;
211211
} else {
212212
if(neg) {
213213
total *= -1f;
@@ -235,7 +235,7 @@ Returns:
235235
fn pow_uint_to_uint_as_float(x: uint, pow: uint) -> float {
236236
if x == 0u {
237237
if pow == 0u {
238-
ret NaN();
238+
ret NaN;
239239
}
240240
ret 0.;
241241
}
@@ -260,23 +260,17 @@ fn pow_uint_to_uint_as_float(x: uint, pow: uint) -> float {
260260
//TODO: Once this is possible, replace the body of these functions
261261
//by an actual constant.
262262

263-
/* Function: NaN */
264-
fn NaN() -> float {
265-
ret 0./0.;
266-
}
263+
/* Const: NaN */
264+
const NaN: float = 0./0.;
267265

268266
/* Predicate: isNaN */
269267
pure fn isNaN(f: float) -> bool { f != f }
270268

271-
/* Function: infinity */
272-
pure fn infinity() -> float {
273-
ret 1./0.;
274-
}
269+
/* Const: infinity */
270+
const infinity: float = 1./0.;
275271

276-
/* Function: neg_infinity */
277-
pure fn neg_infinity() -> float {
278-
ret -1./0.;
279-
}
272+
/* Const: neg_infinity */
273+
const neg_infinity: float = -1./0.;
280274

281275
/* Function: add */
282276
pure fn add(x: float, y: float) -> float { ret x + y; }
@@ -316,14 +310,14 @@ Predicate: positive
316310
317311
Returns true if `x` is a positive number, including +0.0 and +Infinity.
318312
*/
319-
pure fn positive(x: float) -> bool { ret x > 0. || (1./x) == infinity(); }
313+
pure fn positive(x: float) -> bool { ret x > 0. || (1./x) == infinity; }
320314

321315
/*
322316
Predicate: negative
323317
324318
Returns true if `x` is a negative number, including -0.0 and -Infinity.
325319
*/
326-
pure fn negative(x: float) -> bool { ret x < 0. || (1./x) == neg_infinity(); }
320+
pure fn negative(x: float) -> bool { ret x < 0. || (1./x) == neg_infinity; }
327321

328322
/*
329323
Predicate: nonpositive
@@ -332,7 +326,7 @@ Returns true if `x` is a negative number, including -0.0 and -Infinity.
332326
(This is the same as `float::negative`.)
333327
*/
334328
pure fn nonpositive(x: float) -> bool {
335-
ret x < 0. || (1./x) == neg_infinity();
329+
ret x < 0. || (1./x) == neg_infinity;
336330
}
337331

338332
/*
@@ -342,7 +336,7 @@ Returns true if `x` is a positive number, including +0.0 and +Infinity.
342336
(This is the same as `float::positive`.)
343337
*/
344338
pure fn nonnegative(x: float) -> bool {
345-
ret x > 0. || (1./x) == infinity();
339+
ret x > 0. || (1./x) == infinity;
346340
}
347341

348342
//

trunk/src/lib/int.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@ Module: int
33
*/
44

55
/*
6-
Function: max_value
6+
Const: max_value
77
88
The maximum value of an integer
99
*/
10-
fn max_value() -> int {
11-
ret min_value() - 1;
12-
}
10+
// FIXME: Find another way to access the machine word size in a const expr
11+
#[cfg(target_arch="x86")]
12+
const max_value: int = (-1 << 31)-1;
13+
14+
#[cfg(target_arch="x86_64")]
15+
const max_value: int = (-1 << 63)-1;
1316

1417
/*
15-
Function: min_value
18+
Const: min_value
1619
1720
The minumum value of an integer
1821
*/
19-
fn min_value() -> int {
20-
ret (-1 << (sys::size_of::<int>() * 8u as int - 1)) as int;
21-
}
22+
#[cfg(target_arch="x86")]
23+
const min_value: int = -1 << 31;
24+
25+
#[cfg(target_arch="x86_64")]
26+
const min_value: int = -1 << 63;
2227

2328
/* Function: add */
2429
pure fn add(x: int, y: int) -> int { ret x + y; }

trunk/src/lib/io.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,21 +282,21 @@ obj fd_buf_writer(fd: int, res: option::t<@fd_res>) {
282282
fn file_buf_writer(path: str,
283283
flags: [fileflag]) -> result::t<buf_writer, str> {
284284
let fflags: int =
285-
os::libc_constants::O_WRONLY() | os::libc_constants::O_BINARY();
285+
os::libc_constants::O_WRONLY | os::libc_constants::O_BINARY;
286286
for f: fileflag in flags {
287287
alt f {
288-
append. { fflags |= os::libc_constants::O_APPEND(); }
289-
create. { fflags |= os::libc_constants::O_CREAT(); }
290-
truncate. { fflags |= os::libc_constants::O_TRUNC(); }
288+
append. { fflags |= os::libc_constants::O_APPEND; }
289+
create. { fflags |= os::libc_constants::O_CREAT; }
290+
truncate. { fflags |= os::libc_constants::O_TRUNC; }
291291
none. { }
292292
}
293293
}
294294
let fd =
295295
str::as_buf(path,
296296
{|pathbuf|
297297
os::libc::open(pathbuf, fflags,
298-
os::libc_constants::S_IRUSR() |
299-
os::libc_constants::S_IWUSR())
298+
os::libc_constants::S_IRUSR |
299+
os::libc_constants::S_IWUSR)
300300
});
301301
ret if fd < 0 {
302302
log_err sys::last_os_error();
@@ -384,6 +384,7 @@ fn buffered_file_buf_writer(path: str) -> result::t<buf_writer, str> {
384384

385385

386386
// FIXME it would be great if this could be a const
387+
// Problem seems to be that new_writer is not pure
387388
fn stdout() -> writer { ret new_writer(fd_buf_writer(1, option::none)); }
388389
fn stderr() -> writer { ret new_writer(fd_buf_writer(2, option::none)); }
389390

trunk/src/lib/linux_os.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,22 @@ native "cdecl" mod libc = "" {
3737
}
3838

3939
mod libc_constants {
40-
fn O_RDONLY() -> int { ret 0; }
41-
fn O_WRONLY() -> int { ret 1; }
42-
fn O_RDWR() -> int { ret 2; }
43-
fn O_APPEND() -> int { ret 1024; }
44-
fn O_CREAT() -> int { ret 64; }
45-
fn O_EXCL() -> int { ret 128; }
46-
fn O_TRUNC() -> int { ret 512; }
47-
fn O_TEXT() -> int {
48-
ret 0; // nonexistent in linux libc
49-
50-
}
51-
fn O_BINARY() -> int {
52-
ret 0; // nonexistent in linux libc
53-
54-
}
55-
fn S_IRUSR() -> uint { ret 256u; }
56-
fn S_IWUSR() -> uint { ret 128u; }
40+
const O_RDONLY: int = 0;
41+
const O_WRONLY: int = 1;
42+
const O_RDWR: int = 2;
43+
const O_APPEND: int = 1024;
44+
const O_CREAT: int = 64;
45+
const O_EXCL: int = 128;
46+
const O_TRUNC: int = 512;
47+
const O_TEXT: int = 0; // nonexistent in linux libc
48+
const O_BINARY: int = 0; // nonexistent in linux libc
49+
50+
const S_IRUSR: uint = 256u;
51+
const S_IWUSR: uint = 128u;
5752
}
5853

54+
// FIXME turn into constants
5955
fn exec_suffix() -> str { ret ""; }
60-
6156
fn target_os() -> str { ret "linux"; }
6257

6358
fn dylib_filename(base: str) -> str { ret "lib" + base + ".so"; }

trunk/src/lib/macos_os.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,22 @@ native "cdecl" mod libc = "" {
3030
}
3131

3232
mod libc_constants {
33-
fn O_RDONLY() -> int { ret 0; }
34-
fn O_WRONLY() -> int { ret 1; }
35-
fn O_RDWR() -> int { ret 2; }
36-
fn O_APPEND() -> int { ret 8; }
37-
fn O_CREAT() -> int { ret 512; }
38-
fn O_EXCL() -> int { ret 2048; }
39-
fn O_TRUNC() -> int { ret 1024; }
40-
fn O_TEXT() -> int {
41-
ret 0; // nonexistent in darwin libc
42-
43-
}
44-
fn O_BINARY() -> int {
45-
ret 0; // nonexistent in darwin libc
46-
47-
}
48-
fn S_IRUSR() -> uint { ret 1024u; }
49-
fn S_IWUSR() -> uint { ret 512u; }
33+
const O_RDONLY: int = 0;
34+
const O_WRONLY: int = 1;
35+
const O_RDWR: int = 2;
36+
const O_APPEND: int = 8;
37+
const O_CREAT: int = 512;
38+
const O_EXCL: int = 248;
39+
const O_TRUNC: int = 1024;
40+
const O_TEXT: int = 0; // nonexistent in darwin libc
41+
const O_BINARY: int = 0; // nonexistent in darwin libc
42+
43+
const S_IRUSR: uint = 1024u;
44+
const S_IWUSR: uint = 512u;
5045
}
5146

47+
// FIXME turn into constants
5248
fn exec_suffix() -> str { ret ""; }
53-
5449
fn target_os() -> str { ret "macos"; }
5550

5651
fn dylib_filename(base: str) -> str { ret "lib" + base + ".dylib"; }

trunk/src/lib/rand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn mk_rng() -> rng {
4949
let u1 = rustrt::rand_next(**c) as float;
5050
let u2 = rustrt::rand_next(**c) as float;
5151
let u3 = rustrt::rand_next(**c) as float;
52-
let scale = u32::max_value() as float;
52+
let scale = u32::max_value as float;
5353
ret ((u1 / scale + u2) / scale + u3) / scale;
5454
}
5555
}

trunk/src/lib/u32.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ Module: u32
33
*/
44

55
/*
6-
Function: min_value
6+
Const: min_value
77

88
Return the minimal value for a u32
99
*/
10-
pure fn min_value() -> u32 { ret 0u32; }
10+
const min_value: u32 = 0u32;
1111

1212
/*
13-
Function: max_value
13+
Const: max_value
1414

1515
Return the maximal value for a u32
1616
*/
17-
pure fn max_value() -> u32 { ret 4294967296u32; }
17+
const max_value: u32 = 4294967296u32;
1818

1919
//
2020
// Local Variables:

trunk/src/lib/u64.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ Module: u64
33
*/
44

55
/*
6-
Function: min_value
6+
Const: min_value
77
88
Return the minimal value for a u64
99
*/
10-
pure fn min_value() -> u64 { ret 0u64; }
10+
const min_value: u64 = 0u64;
1111

1212
/*
13-
Function: max_value
13+
Const: max_value
1414
1515
Return the maximal value for a u64
1616
*/
17-
pure fn max_value() -> u64 { ret 18446744073709551615u64; }
17+
const max_value: u64 = 18446744073709551615u64;
1818

1919
/*
2020
Function: to_str

trunk/src/lib/u8.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ Module: u8
33
*/
44

55
/*
6-
Function: max_value
6+
Const: max_value
77
88
The maximum value of a u8.
99
*/
10-
pure fn max_value() -> u8 { ret 255u8; }
10+
const max_value: u8 = 255u8;
1111

1212
/*
13-
Function: min_value
13+
Const: min_value
1414
1515
The minumum value of a u8.
1616
*/
17-
pure fn min_value() -> u8 { ret 0u8; }
17+
const min_value: u8 = 0u8;
1818

1919
/* Function: add */
2020
pure fn add(x: u8, y: u8) -> u8 { ret x + y; }

0 commit comments

Comments
 (0)