Skip to content

Commit 61019e0

Browse files
committed
---
yaml --- r: 7864 b: refs/heads/snap-stage3 c: ca0aefa h: refs/heads/master v: v3
1 parent ce10fa8 commit 61019e0

File tree

15 files changed

+720
-168
lines changed

15 files changed

+720
-168
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 4e1bf8d69238bc0ca801f100a88399475da49066
4+
refs/heads/snap-stage3: ca0aefa8bfbd1f1906f6aa7bba430c1765d2345f
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/comp/syntax/print/pprust.rs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,34 @@ fn test_fun_to_str() {
117117
assert fun_to_str(decl, "a", []) == "fn a()";
118118
}
119119

120+
fn res_to_str(decl: ast::fn_decl, name: ast::ident,
121+
params: [ast::ty_param]) -> str {
122+
let buffer = io::mk_mem_buffer();
123+
let s = rust_printer(io::mem_buffer_writer(buffer));
124+
print_res(s, decl, name, params);
125+
end(s); // Close the head box
126+
end(s); // Close the outer box
127+
eof(s.s);
128+
io::mem_buffer_str(buffer)
129+
}
130+
131+
#[test]
132+
fn test_res_to_str() {
133+
let decl: ast::fn_decl = {
134+
inputs: [{
135+
mode: ast::by_val,
136+
ty: @ast_util::respan(ast_util::dummy_sp(), ast::ty_bool),
137+
ident: "b",
138+
id: 0
139+
}],
140+
output: @ast_util::respan(ast_util::dummy_sp(), ast::ty_nil),
141+
purity: ast::impure_fn,
142+
cf: ast::return_val,
143+
constraints: []
144+
};
145+
assert res_to_str(decl, "a", []) == "resource a(b: bool)";
146+
}
147+
120148
fn block_to_str(blk: ast::blk) -> str {
121149
let buffer = io::mk_mem_buffer();
122150
let s = rust_printer(io::mem_buffer_writer(buffer));
@@ -498,20 +526,25 @@ fn print_item(s: ps, &&item: @ast::item) {
498526
bclose(s, item.span);
499527
}
500528
ast::item_res(decl, tps, body, dt_id, ct_id) {
501-
head(s, "resource");
502-
word(s.s, item.ident);
503-
print_type_params(s, tps);
504-
popen(s);
505-
word_space(s, decl.inputs[0].ident + ":");
506-
print_type(s, decl.inputs[0].ty);
507-
pclose(s);
508-
space(s.s);
529+
print_res(s, decl, item.ident, tps);
509530
print_block(s, body);
510531
}
511532
}
512533
s.ann.post(ann_node);
513534
}
514535

536+
fn print_res(s: ps, decl: ast::fn_decl, name: ast::ident,
537+
typarams: [ast::ty_param]) {
538+
head(s, "resource");
539+
word(s.s, name);
540+
print_type_params(s, typarams);
541+
popen(s);
542+
word_space(s, decl.inputs[0].ident + ":");
543+
print_type(s, decl.inputs[0].ty);
544+
pclose(s);
545+
space(s.s);
546+
}
547+
515548
fn print_variant(s: ps, v: ast::variant) {
516549
word(s.s, v.node.name);
517550
if vec::len(v.node.args) > 0u {

branches/snap-stage3/src/libcore/f32.rs

Lines changed: 123 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
#[doc = "Floating point operations and constants for `f32`"];
1+
/*
2+
Module: f32
3+
4+
Floating point operations and constants for `f32`
5+
*/
26

37
// PORT
48

@@ -25,87 +29,113 @@ type t = f32;
2529
// These are not defined inside consts:: for consistency with
2630
// the integer types
2731

32+
/* Const: NaN */
2833
const NaN: f32 = 0.0_f32/0.0_f32;
2934

35+
/* Const: infinity */
3036
const infinity: f32 = 1.0_f32/0.0_f32;
3137

38+
/* Const: neg_infinity */
3239
const neg_infinity: f32 = -1.0_f32/0.0_f32;
3340

41+
/* Predicate: isNaN */
3442
pure fn is_NaN(f: f32) -> bool { f != f }
3543

44+
/* Function: add */
3645
pure fn add(x: f32, y: f32) -> f32 { ret x + y; }
3746

47+
/* Function: sub */
3848
pure fn sub(x: f32, y: f32) -> f32 { ret x - y; }
3949

50+
/* Function: mul */
4051
pure fn mul(x: f32, y: f32) -> f32 { ret x * y; }
4152

53+
/* Function: div */
4254
pure fn div(x: f32, y: f32) -> f32 { ret x / y; }
4355

56+
/* Function: rem */
4457
pure fn rem(x: f32, y: f32) -> f32 { ret x % y; }
4558

59+
/* Predicate: lt */
4660
pure fn lt(x: f32, y: f32) -> bool { ret x < y; }
4761

62+
/* Predicate: le */
4863
pure fn le(x: f32, y: f32) -> bool { ret x <= y; }
4964

65+
/* Predicate: eq */
5066
pure fn eq(x: f32, y: f32) -> bool { ret x == y; }
5167

68+
/* Predicate: ne */
5269
pure fn ne(x: f32, y: f32) -> bool { ret x != y; }
5370

71+
/* Predicate: ge */
5472
pure fn ge(x: f32, y: f32) -> bool { ret x >= y; }
5573

74+
/* Predicate: gt */
5675
pure fn gt(x: f32, y: f32) -> bool { ret x > y; }
5776

5877
// FIXME replace the predicates below with llvm intrinsics or calls
5978
// to the libmath macros in the rust runtime for performance
6079

61-
#[doc(
62-
brief = "Returns true if `x` is a positive number, including +0.0f320 and +Infinity."
63-
)]
80+
/*
81+
Predicate: is_positive
82+
83+
Returns true if `x` is a positive number, including +0.0f320 and +Infinity.
84+
*/
6485
pure fn is_positive(x: f32) -> bool
6586
{ ret x > 0.0f32 || (1.0f32/x) == infinity; }
6687

67-
#[doc(
68-
brief = "Returns true if `x` is a negative number, including -0.0f320 and -Infinity."
69-
)]
88+
/*
89+
Predicate: is_negative
90+
91+
Returns true if `x` is a negative number, including -0.0f320 and -Infinity.
92+
*/
7093
pure fn is_negative(x: f32) -> bool
7194
{ ret x < 0.0f32 || (1.0f32/x) == neg_infinity; }
7295

73-
#[doc(
74-
brief = "Returns true if `x` is a negative number, including \
75-
-0.0f320 and -Infinity. (This is the same as \
76-
`f32::negative`.)"
77-
)]
96+
/*
97+
Predicate: is_nonpositive
98+
99+
Returns true if `x` is a negative number, including -0.0f320 and -Infinity.
100+
(This is the same as `f32::negative`.)
101+
*/
78102
pure fn is_nonpositive(x: f32) -> bool {
79103
ret x < 0.0f32 || (1.0f32/x) == neg_infinity;
80104
}
81105

82-
#[doc(
83-
brief = "Returns true if `x` is a positive number, \
84-
including +0.0f320 and +Infinity. (This is \
85-
the same as `f32::positive`.)"
86-
)]
106+
/*
107+
Predicate: nonnegative
108+
109+
Returns true if `x` is a positive number, including +0.0f320 and +Infinity.
110+
(This is the same as `f32::positive`.)
111+
*/
87112
pure fn is_nonnegative(x: f32) -> bool {
88113
ret x > 0.0f32 || (1.0f32/x) == infinity;
89114
}
90115

91-
#[doc(
92-
brief = "Returns true if `x` is a zero number \
93-
(positive or negative zero)"
94-
)]
116+
/*
117+
Predicate: is_zero
118+
119+
Returns true if `x` is a zero number (positive or negative zero)
120+
*/
95121
pure fn is_zero(x: f32) -> bool {
96122
ret x == 0.0f32 || x == -0.0f32;
97123
}
98124

99-
#[doc(
100-
brief = "Returns true if `x`is an infinite number"
101-
)]
125+
/*
126+
Predicate: is_infinite
127+
128+
Returns true if `x`is an infinite numer
129+
*/
102130
pure fn is_infinite(x: f32) -> bool {
103131
ret x == infinity || x == neg_infinity;
104132
}
105133

106-
#[doc(
107-
brief = "Returns true if `x`is a finite number"
108-
)]
134+
/*
135+
Predicate: is_finite
136+
137+
Returns true if `x`is a finite numer
138+
*/
109139
pure fn is_finite(x: f32) -> bool {
110140
ret !(is_NaN(x) || is_infinite(x));
111141
}
@@ -116,69 +146,96 @@ pure fn is_finite(x: f32) -> bool {
116146
mod consts {
117147

118148
// FIXME replace with mathematical constants from cmath
119-
#[doc(
120-
brief = "Archimedes' constant"
121-
)]
149+
150+
/*
151+
Const: pi
152+
153+
Archimedes' constant
154+
*/
122155
const pi: f32 = 3.14159265358979323846264338327950288_f32;
123156

124-
#[doc(
125-
brief = "pi/2.0"
126-
)]
157+
/*
158+
Const: frac_pi_2
159+
160+
pi/2.0
161+
*/
127162
const frac_pi_2: f32 = 1.57079632679489661923132169163975144_f32;
128163

129-
#[doc(
130-
brief = "pi/4.0"
131-
)]
164+
/*
165+
Const: frac_pi_4
166+
167+
pi/4.0
168+
*/
132169
const frac_pi_4: f32 = 0.785398163397448309615660845819875721_f32;
133170

134-
#[doc(
135-
brief = "1.0/pi"
136-
)]
171+
/*
172+
Const: frac_1_pi
173+
174+
1.0/pi
175+
*/
137176
const frac_1_pi: f32 = 0.318309886183790671537767526745028724_f32;
138177

139-
#[doc(
140-
brief = "2.0/pi"
141-
)]
178+
/*
179+
Const: frac_2_pi
180+
181+
2.0/pi
182+
*/
142183
const frac_2_pi: f32 = 0.636619772367581343075535053490057448_f32;
143184

144-
#[doc(
145-
brief = "2.0/sqrt(pi)"
146-
)]
185+
/*
186+
Const: frac_2_sqrtpi
187+
188+
2.0/sqrt(pi)
189+
*/
147190
const frac_2_sqrtpi: f32 = 1.12837916709551257389615890312154517_f32;
148191

149-
#[doc(
150-
brief = "sqrt(2.0)"
151-
)]
192+
/*
193+
Const: sqrt2
194+
195+
sqrt(2.0)
196+
*/
152197
const sqrt2: f32 = 1.41421356237309504880168872420969808_f32;
153198

154-
#[doc(
155-
brief = "1.0/sqrt(2.0)"
156-
)]
199+
/*
200+
Const: frac_1_sqrt2
201+
202+
1.0/sqrt(2.0)
203+
*/
157204
const frac_1_sqrt2: f32 = 0.707106781186547524400844362104849039_f32;
158205

159-
#[doc(
160-
brief = "Euler's number"
161-
)]
206+
/*
207+
Const: e
208+
209+
Euler's number
210+
*/
162211
const e: f32 = 2.71828182845904523536028747135266250_f32;
163212

164-
#[doc(
165-
brief = "log2(e)"
166-
)]
213+
/*
214+
Const: log2_e
215+
216+
log2(e)
217+
*/
167218
const log2_e: f32 = 1.44269504088896340735992468100189214_f32;
168219

169-
#[doc(
170-
brief = "log10(e)"
171-
)]
220+
/*
221+
Const: log10_e
222+
223+
log10(e)
224+
*/
172225
const log10_e: f32 = 0.434294481903251827651128918916605082_f32;
173226

174-
#[doc(
175-
brief = "ln(2.0)"
176-
)]
227+
/*
228+
Const: ln_2
229+
230+
ln(2.0)
231+
*/
177232
const ln_2: f32 = 0.693147180559945309417232121458176568_f32;
178233

179-
#[doc(
180-
brief = "ln(10.0)"
181-
)]
234+
/*
235+
Const: ln_10
236+
237+
ln(10.0)
238+
*/
182239
const ln_10: f32 = 2.30258509299404568401799145468436421_f32;
183240
}
184241

0 commit comments

Comments
 (0)