Skip to content

Commit adb1754

Browse files
committed
Move the option type to its own module
1 parent e399926 commit adb1754

File tree

14 files changed

+115
-93
lines changed

14 files changed

+115
-93
lines changed

src/comp/driver/rustc.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import front.token;
55
import middle.trans;
66
import middle.resolve;
77

8-
import std.util.option;
9-
import std.util.some;
10-
import std.util.none;
8+
import std.option;
9+
import std.option.some;
10+
import std.option.none;
1111
import std._str;
1212
import std._vec;
1313

@@ -39,8 +39,8 @@ fn usage(session.session sess, str argv0) {
3939
impure fn main(vec[str] args) {
4040

4141
auto sess = session.session();
42-
let option[str] input_file = none[str];
43-
let option[str] output_file = none[str];
42+
let option.t[str] input_file = none[str];
43+
let option.t[str] output_file = none[str];
4444
let bool do_warn = true;
4545

4646
auto i = 1u;

src/comp/front/ast.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

2-
import util.common.option;
32
import std.map.hashmap;
4-
import std.util.option;
3+
import std.option;
54
import util.common.span;
65
import util.common.spanned;
76

@@ -71,16 +70,16 @@ tag unop {
7170
type stmt = spanned[stmt_];
7271
tag stmt_ {
7372
stmt_decl(@decl);
74-
stmt_ret(option[@expr]);
73+
stmt_ret(option.t[@expr]);
7574
stmt_log(@expr);
7675
stmt_check_expr(@expr);
7776
stmt_expr(@expr);
7877
}
7978

80-
type local = rec(option[@ty] ty,
79+
type local = rec(option.t[@ty] ty,
8180
bool infer,
8281
ident ident,
83-
option[@expr] init,
82+
option.t[@expr] init,
8483
def_id id);
8584

8685
type decl = spanned[decl_];
@@ -99,14 +98,14 @@ tag expr_ {
9998
expr_unary(unop, @expr, ann);
10099
expr_lit(@lit, ann);
101100
expr_cast(@expr, @ty, ann);
102-
expr_if(@expr, block, option[block], ann);
101+
expr_if(@expr, block, option.t[block], ann);
103102
expr_while(@expr, block, ann);
104103
expr_do_while(block, @expr, ann);
105104
expr_block(block, ann);
106105
expr_assign(@expr /* TODO: @expr|is_lval */, @expr, ann);
107106
expr_field(@expr, ident, ann);
108107
expr_index(@expr, @expr, ann);
109-
expr_name(name, option[def], ann);
108+
expr_name(name, option.t[def], ann);
110109
}
111110

112111
type lit = spanned[lit_];
@@ -131,7 +130,7 @@ tag ty_ {
131130
ty_box(@ty);
132131
ty_vec(@ty);
133132
ty_tup(vec[tup(bool /* mutability */, @ty)]);
134-
ty_path(path, option[def]);
133+
ty_path(path, option.t[def]);
135134
}
136135

137136
tag mode {

src/comp/front/parser.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import std._io;
2-
import std.util.option;
3-
import std.util.some;
4-
import std.util.none;
2+
import std.option;
3+
import std.option.some;
4+
import std.option.none;
55
import std.map.hashmap;
66

77
import driver.session;
@@ -157,7 +157,7 @@ impure fn parse_arg(parser p) -> ast.arg {
157157

158158
impure fn parse_seq[T](token.token bra,
159159
token.token ket,
160-
option[token.token] sep,
160+
option.t[token.token] sep,
161161
(impure fn(parser) -> T) f,
162162
parser p) -> util.common.spanned[vec[T]] {
163163
let bool first = true;
@@ -185,7 +185,7 @@ impure fn parse_seq[T](token.token bra,
185185
ret spanned(lo, hi, v);
186186
}
187187

188-
impure fn parse_lit(parser p) -> option[ast.lit] {
188+
impure fn parse_lit(parser p) -> option.t[ast.lit] {
189189
auto lo = p.get_span();
190190
let ast.lit_ lit;
191191
alt (p.peek()) {
@@ -600,7 +600,7 @@ impure fn parse_if_expr(parser p) -> @ast.expr {
600600
auto cond = parse_expr(p);
601601
expect(p, token.RPAREN);
602602
auto thn = parse_block(p);
603-
let option[ast.block] els = none[ast.block];
603+
let option.t[ast.block] els = none[ast.block];
604604
hi = thn.span;
605605
alt (p.peek()) {
606606
case (token.ELSE) {
@@ -664,7 +664,7 @@ impure fn parse_expr(parser p) -> @ast.expr {
664664
}
665665
}
666666

667-
impure fn parse_initializer(parser p) -> option[@ast.expr] {
667+
impure fn parse_initializer(parser p) -> option.t[@ast.expr] {
668668
if (p.peek() == token.EQ) {
669669
p.bump();
670670
ret some(parse_expr(p));

src/comp/middle/fold.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import std.map.hashmap;
2-
import std.util.option;
3-
import std.util.some;
4-
import std.util.none;
2+
import std.option;
3+
import std.option.some;
4+
import std.option.none;
55

66
import util.common.new_str_hash;
77
import util.common.spanned;
@@ -47,7 +47,7 @@ type ast_fold[ENV] =
4747
vec[tup(bool, @ty)] elts) -> @ty) fold_ty_tup,
4848

4949
(fn(&ENV e, &span sp, ast.path p,
50-
&option[def] d) -> @ty) fold_ty_path,
50+
&option.t[def] d) -> @ty) fold_ty_path,
5151

5252
// Expr folds.
5353
(fn(&ENV e, &span sp,
@@ -79,7 +79,7 @@ type ast_fold[ENV] =
7979

8080
(fn(&ENV e, &span sp,
8181
@expr cond, &block thn,
82-
&option[block] els,
82+
&option.t[block] els,
8383
ann a) -> @expr) fold_expr_if,
8484

8585
(fn(&ENV e, &span sp,
@@ -107,7 +107,7 @@ type ast_fold[ENV] =
107107

108108
(fn(&ENV e, &span sp,
109109
&name n,
110-
&option[def] d,
110+
&option.t[def] d,
111111
ann a) -> @expr) fold_expr_name,
112112

113113
// Decl folds.
@@ -123,7 +123,7 @@ type ast_fold[ENV] =
123123
@decl decl) -> @stmt) fold_stmt_decl,
124124

125125
(fn(&ENV e, &span sp,
126-
&option[@expr] rv) -> @stmt) fold_stmt_ret,
126+
&option.t[@expr] rv) -> @stmt) fold_stmt_ret,
127127

128128
(fn(&ENV e, &span sp,
129129
@expr e) -> @stmt) fold_stmt_log,
@@ -568,7 +568,7 @@ fn identity_fold_ty_tup[ENV](&ENV env, &span sp, vec[tup(bool,@ty)] elts)
568568
}
569569

570570
fn identity_fold_ty_path[ENV](&ENV env, &span sp, ast.path p,
571-
&option[def] d) -> @ty {
571+
&option.t[def] d) -> @ty {
572572
ret @respan(sp, ast.ty_path(p, d));
573573
}
574574

@@ -614,7 +614,7 @@ fn identity_fold_expr_lit[ENV](&ENV env, &span sp, @ast.lit lit,
614614

615615
fn identity_fold_expr_if[ENV](&ENV env, &span sp,
616616
@expr cond, &block thn,
617-
&option[block] els, ann a) -> @expr {
617+
&option.t[block] els, ann a) -> @expr {
618618
ret @respan(sp, ast.expr_if(cond, thn, els, a));
619619
}
620620

@@ -650,7 +650,7 @@ fn identity_fold_expr_index[ENV](&ENV env, &span sp,
650650
}
651651

652652
fn identity_fold_expr_name[ENV](&ENV env, &span sp,
653-
&name n, &option[def] d,
653+
&name n, &option.t[def] d,
654654
ann a) -> @expr {
655655
ret @respan(sp, ast.expr_name(n, d, a));
656656
}
@@ -675,7 +675,7 @@ fn identity_fold_stmt_decl[ENV](&ENV env, &span sp, @decl d) -> @stmt {
675675
}
676676

677677
fn identity_fold_stmt_ret[ENV](&ENV env, &span sp,
678-
&option[@expr] rv) -> @stmt {
678+
&option.t[@expr] rv) -> @stmt {
679679
ret @respan(sp, ast.stmt_ret(rv));
680680
}
681681

src/comp/middle/resolve.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import std.map.hashmap;
88
import std.list.list;
99
import std.list.nil;
1010
import std.list.cons;
11-
import std.util.option;
12-
import std.util.some;
13-
import std.util.none;
11+
import std.option;
12+
import std.option.some;
13+
import std.option.none;
1414
import std._str;
1515

1616
tag scope {
@@ -22,11 +22,11 @@ tag scope {
2222
type env = rec(list[scope] scopes,
2323
session.session sess);
2424

25-
fn lookup_name(&env e, ast.ident i) -> option[def] {
25+
fn lookup_name(&env e, ast.ident i) -> option.t[def] {
2626

2727
// log "resolving name " + i;
2828

29-
fn found_def_item(@ast.item i) -> option[def] {
29+
fn found_def_item(@ast.item i) -> option.t[def] {
3030
alt (i.node) {
3131
case (ast.item_fn(_, _, ?id)) {
3232
ret some[def](ast.def_fn(id));
@@ -40,7 +40,7 @@ fn lookup_name(&env e, ast.ident i) -> option[def] {
4040
}
4141
}
4242

43-
fn found_decl_stmt(@ast.stmt s) -> option[def] {
43+
fn found_decl_stmt(@ast.stmt s) -> option.t[def] {
4444
alt (s.node) {
4545
case (ast.stmt_decl(?d)) {
4646
alt (d.node) {
@@ -56,7 +56,7 @@ fn lookup_name(&env e, ast.ident i) -> option[def] {
5656
ret none[def];
5757
}
5858

59-
fn check_mod(ast.ident i, ast._mod m) -> option[def] {
59+
fn check_mod(ast.ident i, ast._mod m) -> option.t[def] {
6060
alt (m.index.find(i)) {
6161
case (some[uint](?ix)) {
6262
ret found_def_item(m.items.(ix));
@@ -66,7 +66,7 @@ fn lookup_name(&env e, ast.ident i) -> option[def] {
6666
}
6767

6868

69-
fn in_scope(ast.ident i, &scope s) -> option[def] {
69+
fn in_scope(ast.ident i, &scope s) -> option.t[def] {
7070
alt (s) {
7171

7272
case (scope_crate(?c)) {
@@ -103,7 +103,7 @@ fn lookup_name(&env e, ast.ident i) -> option[def] {
103103
}
104104

105105
fn fold_expr_name(&env e, &span sp, &ast.name n,
106-
&option[def] d, ann a) -> @ast.expr {
106+
&option.t[def] d, ann a) -> @ast.expr {
107107

108108
auto d_ = lookup_name(e, n.node.ident);
109109

src/comp/middle/trans.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import std._vec;
33
import std._str.rustrt.sbuf;
44
import std._vec.rustrt.vbuf;
55
import std.map.hashmap;
6-
import std.util.option;
7-
import std.util.some;
8-
import std.util.none;
6+
import std.option;
7+
import std.option.some;
8+
import std.option.none;
99

1010
import front.ast;
1111
import driver.session;
@@ -613,7 +613,7 @@ impure fn trans_binary(@block_ctxt cx, ast.binop op,
613613
}
614614

615615
impure fn trans_if(@block_ctxt cx, &ast.expr cond,
616-
&ast.block thn, &option[ast.block] els) -> result {
616+
&ast.block thn, &option.t[ast.block] els) -> result {
617617

618618
auto cond_res = trans_expr(cx, cond);
619619

@@ -868,7 +868,7 @@ impure fn trans_check_expr(@block_ctxt cx, &ast.expr e) -> result {
868868
ret res(next_cx, C_nil());
869869
}
870870

871-
impure fn trans_ret(@block_ctxt cx, &option[@ast.expr] e) -> result {
871+
impure fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
872872
auto r = res(cx, C_nil());
873873
alt (e) {
874874
case (some[@ast.expr](?x)) {

src/lib/_vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import vbuf = rustrt.vbuf;
2-
import op = util.operator;
2+
import std.option;
33

44
native "rust" mod rustrt {
55
type vbuf;
@@ -129,7 +129,7 @@ fn grow[T](&mutable vec[T] v, int n, &T initval) {
129129
}
130130
}
131131

132-
fn map[T, U](&op[T,U] f, &vec[T] v) -> vec[U] {
132+
fn map[T, U](&option.operator[T,U] f, &vec[T] v) -> vec[U] {
133133
let vec[U] u = alloc[U](len[T](v));
134134
for (T ve in v) {
135135
u += vec(f(ve));

src/lib/deque.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* A deque, for fun. Untested as of yet. Likely buggy.
33
*/
44

5-
import std.util;
5+
import std.option;
66
import std._vec;
77
import std._int;
88

@@ -23,7 +23,7 @@ type t[T] = obj {
2323

2424
fn create[T]() -> t[T] {
2525

26-
type cell[T] = mutable util.option[T];
26+
type cell[T] = mutable option.t[T];
2727

2828
let uint initial_capacity = 32u; // 2^5
2929

@@ -39,7 +39,7 @@ fn create[T]() -> t[T] {
3939
if (i < nelts) {
4040
ret old.((lo + i) % nelts);
4141
} else {
42-
ret util.none[T];
42+
ret option.none[T];
4343
}
4444
}
4545

@@ -50,7 +50,7 @@ fn create[T]() -> t[T] {
5050

5151
fn get[T](vec[cell[T]] elts, uint i) -> T {
5252
alt (elts.(i)) {
53-
case (util.some[T](?t)) { ret t; }
53+
case (option.some[T](?t)) { ret t; }
5454
case (_) { fail; }
5555
}
5656
}
@@ -77,7 +77,7 @@ fn create[T]() -> t[T] {
7777
hi = nelts;
7878
}
7979

80-
elts.(lo) = util.some[T](t);
80+
elts.(lo) = option.some[T](t);
8181
nelts += 1u;
8282
}
8383

@@ -88,7 +88,7 @@ fn create[T]() -> t[T] {
8888
hi = nelts;
8989
}
9090

91-
elts.(hi) = util.some[T](t);
91+
elts.(hi) = option.some[T](t);
9292
hi = (hi + 1u) % _vec.len[cell[T]](elts);
9393
nelts += 1u;
9494
}
@@ -99,7 +99,7 @@ fn create[T]() -> t[T] {
9999
*/
100100
fn pop_front() -> T {
101101
let T t = get[T](elts, lo);
102-
elts.(lo) = util.none[T];
102+
elts.(lo) = option.none[T];
103103
lo = (lo + 1u) % _vec.len[cell[T]](elts);
104104
nelts -= 1u;
105105
ret t;
@@ -113,7 +113,7 @@ fn create[T]() -> t[T] {
113113
}
114114

115115
let T t = get[T](elts, hi);
116-
elts.(hi) = util.none[T];
116+
elts.(hi) = option.none[T];
117117
nelts -= 1u;
118118
ret t;
119119
}
@@ -132,7 +132,7 @@ fn create[T]() -> t[T] {
132132
}
133133

134134
}
135-
let vec[cell[T]] v = _vec.init_elt[cell[T]](util.none[T],
135+
let vec[cell[T]] v = _vec.init_elt[cell[T]](option.none[T],
136136
initial_capacity);
137137

138138
ret deque[T](0u, 0u, 0u, v);

0 commit comments

Comments
 (0)