Skip to content

Commit a0cc07d

Browse files
committed
---
yaml --- r: 5983 b: refs/heads/master c: e071538 h: refs/heads/master i: 5981: 00b93f8 5979: feb92a8 5975: 10afe13 5967: 30e730a 5951: 3e75698 v: v3
1 parent 7f27b63 commit a0cc07d

File tree

8 files changed

+146
-28
lines changed

8 files changed

+146
-28
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: 8222fa4e278cc15f5bf1044c6b1960a4291dce31
2+
refs/heads/master: e0715380dc27c06c168696a89dd2596debfa1919

trunk/src/lib/term.rs

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,65 @@
1+
/*
2+
Module: term
13
4+
Simple ANSI color library
5+
*/
26

3-
4-
// Simple ANSI color library.
5-
//
67
// TODO: Windows support.
7-
const color_black: u8 = 0u8;
88

9+
/* Const: color_black */
10+
const color_black: u8 = 0u8;
11+
/* Const: color_red */
912
const color_red: u8 = 1u8;
10-
13+
/* Const: color_green */
1114
const color_green: u8 = 2u8;
12-
15+
/* Const: color_yellow */
1316
const color_yellow: u8 = 3u8;
14-
17+
/* Const: color_blue */
1518
const color_blue: u8 = 4u8;
16-
19+
/* Const: color_magenta */
1720
const color_magenta: u8 = 5u8;
18-
21+
/* Const: color_cyan */
1922
const color_cyan: u8 = 6u8;
20-
23+
/* Const: color_light_gray */
2124
const color_light_gray: u8 = 7u8;
22-
25+
/* Const: color_light_grey */
2326
const color_light_grey: u8 = 7u8;
24-
27+
/* Const: color_dark_gray */
2528
const color_dark_gray: u8 = 8u8;
26-
29+
/* Const: color_dark_grey */
2730
const color_dark_grey: u8 = 8u8;
28-
31+
/* Const: color_bright_red */
2932
const color_bright_red: u8 = 9u8;
30-
33+
/* Const: color_bright_green */
3134
const color_bright_green: u8 = 10u8;
32-
35+
/* Const: color_bright_yellow */
3336
const color_bright_yellow: u8 = 11u8;
34-
37+
/* Const: color_bright_blue */
3538
const color_bright_blue: u8 = 12u8;
36-
39+
/* Const: color_bright_magenta */
3740
const color_bright_magenta: u8 = 13u8;
38-
41+
/* Const: color_bright_cyan */
3942
const color_bright_cyan: u8 = 14u8;
40-
43+
/* Const: color_bright_white */
4144
const color_bright_white: u8 = 15u8;
4245

4346
fn esc(writer: io::buf_writer) { writer.write([0x1bu8, '[' as u8]); }
4447

48+
/*
49+
Function: reset
50+
51+
Reset the foreground and background colors to default
52+
*/
4553
fn reset(writer: io::buf_writer) {
4654
esc(writer);
4755
writer.write(['0' as u8, 'm' as u8]);
4856
}
4957

58+
/*
59+
Function: color_supported
60+
61+
Returns true if the terminal supports color
62+
*/
5063
fn color_supported() -> bool {
5164
let supported_terms = ["xterm-color", "xterm", "screen-bce"];
5265
ret alt generic_os::getenv("TERM") {
@@ -67,15 +80,23 @@ fn set_color(writer: io::buf_writer, first_char: u8, color: u8) {
6780
writer.write([first_char, ('0' as u8) + color, 'm' as u8]);
6881
}
6982

83+
/*
84+
Function: fg
85+
86+
Set the foreground color
87+
*/
7088
fn fg(writer: io::buf_writer, color: u8) {
7189
ret set_color(writer, '3' as u8, color);
7290
}
7391

92+
/*
93+
Function: fg
94+
95+
Set the background color
96+
*/
7497
fn bg(writer: io::buf_writer, color: u8) {
7598
ret set_color(writer, '4' as u8, color);
7699
}
77-
// export fg;
78-
// export bg;
79100

80101
// Local Variables:
81102
// fill-column: 78;

trunk/src/lib/time.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1+
/*
2+
Module: time
3+
*/
14

5+
// FIXME: Document what these functions do
26

37
native "c-stack-cdecl" mod rustrt {
48
fn get_time(&sec: u32, &usec: u32);
59
fn nano_time(&ns: u64);
610
}
711

12+
/* Type: timeval */
813
type timeval = {sec: u32, usec: u32};
914

15+
/* Function: get_time */
1016
fn get_time() -> timeval {
1117
let sec = 0u32;
1218
let usec = 0u32;
1319
rustrt::get_time(sec, usec);
1420
ret {sec: sec, usec: usec};
1521
}
1622

23+
/* Function: precise_time_ns */
1724
fn precise_time_ns() -> u64 { let ns = 0u64; rustrt::nano_time(ns); ret ns; }
1825

26+
/* Function: precise_time_s */
1927
fn precise_time_s() -> float {
2028
ret (precise_time_ns() as float) / 1000000000.;
2129
}

trunk/src/lib/u32.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1-
pure fn max_value() -> u32 { ret 4294967296u32; }
1+
/*
2+
Module: u32
3+
*/
4+
5+
/*
6+
Function: min_value
7+
8+
Return the minimal value for a u32
9+
*/
210
pure fn min_value() -> u32 { ret 0u32; }
311

12+
/*
13+
Function: max_value
14+
15+
Return the maximal value for a u32
16+
*/
17+
pure fn max_value() -> u32 { ret 4294967296u32; }
18+
419
//
520
// Local Variables:
621
// mode: rust

trunk/src/lib/u64.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1-
pure fn max_value() -> u64 { ret 18446744073709551615u64; }
1+
/*
2+
Module: u64
3+
*/
4+
5+
/*
6+
Function: min_value
7+
8+
Return the minimal value for a u64
9+
*/
210
pure fn min_value() -> u64 { ret 0u64; }
311

12+
/*
13+
Function: max_value
14+
15+
Return the maximal value for a u64
16+
*/
17+
pure fn max_value() -> u64 { ret 18446744073709551615u64; }
18+
19+
/*
20+
Function: to_str
21+
22+
Convert to a string in a given base
23+
*/
424
fn to_str(n: u64, radix: uint) -> str {
525
assert (0u < radix && radix <= 16u);
626

@@ -36,4 +56,9 @@ fn to_str(n: u64, radix: uint) -> str {
3656
ret s;
3757
}
3858

59+
/*
60+
Function: str
61+
62+
Convert to a string
63+
*/
3964
fn str(n: u64) -> str { ret to_str(n, 10u); }

trunk/src/lib/u8.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ pure fn ge(x: u8, y: u8) -> bool { ret x >= y; }
4949
/* Predicate: gt */
5050
pure fn gt(x: u8, y: u8) -> bool { ret x > y; }
5151

52+
/*
53+
Function: range
54+
55+
Iterate over the range [`lo`..`hi`)
56+
*/
5257
fn range(lo: u8, hi: u8, it: block(u8)) {
5358
while lo < hi { it(lo); lo += 1u8; }
5459
}

trunk/src/lib/unsafe.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
// Unsafe operations.
1+
/*
2+
Module: unsafe
3+
4+
Unsafe operations
5+
*/
26

37
native "rust-intrinsic" mod rusti {
48
fn cast<T, U>(src: T) -> U;
@@ -8,7 +12,21 @@ native "c-stack-cdecl" mod rustrt {
812
fn leak<T>(-thing: T);
913
}
1014

11-
// Casts the value at `src` to U. The two types must have the same length.
15+
/*
16+
Function: reinterpret_cast
17+
18+
Casts the value at `src` to U. The two types must have the same length.
19+
*/
1220
fn reinterpret_cast<T, U>(src: T) -> U { ret rusti::cast(src); }
1321

22+
/*
23+
Function: leak
24+
25+
Move `thing` into the void.
26+
27+
The leak function will take ownership of the provided value but neglect
28+
to run any required cleanup or memory-management operations on it. This
29+
can be used for various acts of magick, particularly when using
30+
reinterpret_cast on managed pointer types.
31+
*/
1432
fn leak<T>(-thing: T) { rustrt::leak(thing); }

trunk/src/lib/util.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,49 @@
1+
/*
2+
Module: util
3+
*/
14

5+
/*
6+
Function: id
7+
8+
The identity function
9+
*/
210
pure fn id<T>(x: T) -> T { x }
311

12+
/*
13+
Function: unreachable
14+
15+
A standard function to use to indicate unreachable code. Because the
16+
function is guaranteed to fail typestate will correctly identify
17+
any code paths following the appearance of this function as unreachable.
18+
*/
419
fn unreachable() -> ! {
520
fail "Internal error: entered unreachable code";
621
}
722

823
/* FIXME (issue #141): See test/run-pass/constrained-type.rs. Uncomment
924
* the constraint once fixed. */
25+
/*
26+
Function: rational
27+
28+
A rational number
29+
*/
1030
type rational = {num: int, den: int}; // : int::positive(*.den);
1131

12-
// : int::positive(*.den);
32+
/*
33+
Function: rational_leq
34+
*/
1335
pure fn rational_leq(x: rational, y: rational) -> bool {
1436
// NB: Uses the fact that rationals have positive denominators WLOG:
1537

1638
x.num * y.den <= y.num * x.den
1739
}
1840

41+
/*
42+
Function: orb
43+
*/
1944
pure fn orb(a: bool, b: bool) -> bool { a || b }
2045

46+
// FIXME: Document what this is for or delete it
2147
tag void {
2248
void(@void);
2349
}

0 commit comments

Comments
 (0)