Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
adb1754e
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
adb1754e
编写于
11月 03, 2010
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move the option type to its own module
上级
e3999267
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
115 addition
and
93 deletion
+115
-93
src/comp/driver/rustc.rs
src/comp/driver/rustc.rs
+5
-5
src/comp/front/ast.rs
src/comp/front/ast.rs
+7
-8
src/comp/front/parser.rs
src/comp/front/parser.rs
+7
-7
src/comp/middle/fold.rs
src/comp/middle/fold.rs
+11
-11
src/comp/middle/resolve.rs
src/comp/middle/resolve.rs
+9
-9
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+5
-5
src/lib/_vec.rs
src/lib/_vec.rs
+2
-2
src/lib/deque.rs
src/lib/deque.rs
+9
-9
src/lib/list.rs
src/lib/list.rs
+4
-4
src/lib/map.rs
src/lib/map.rs
+14
-14
src/lib/option.rs
src/lib/option.rs
+40
-0
src/lib/std.rc
src/lib/std.rc
+1
-0
src/lib/util.rs
src/lib/util.rs
+0
-18
src/test/run-pass/lib-vec.rs
src/test/run-pass/lib-vec.rs
+1
-1
未找到文件。
src/comp/driver/rustc.rs
浏览文件 @
adb1754e
...
@@ -5,9 +5,9 @@
...
@@ -5,9 +5,9 @@
import
middle
.trans
;
import
middle
.trans
;
import
middle
.resolve
;
import
middle
.resolve
;
import
std
.
util.
option
;
import
std
.option
;
import
std
.
util
.some
;
import
std
.
option
.some
;
import
std
.
util
.none
;
import
std
.
option
.none
;
import
std
._str
;
import
std
._str
;
import
std
._vec
;
import
std
._vec
;
...
@@ -39,8 +39,8 @@ fn usage(session.session sess, str argv0) {
...
@@ -39,8 +39,8 @@ fn usage(session.session sess, str argv0) {
impure
fn
main
(
vec
[
str
]
args
)
{
impure
fn
main
(
vec
[
str
]
args
)
{
auto
sess
=
session
.session
();
auto
sess
=
session
.session
();
let
option
[
str
]
input_file
=
none
[
str
];
let
option
.t
[
str
]
input_file
=
none
[
str
];
let
option
[
str
]
output_file
=
none
[
str
];
let
option
.t
[
str
]
output_file
=
none
[
str
];
let
bool
do_warn
=
true
;
let
bool
do_warn
=
true
;
auto
i
=
1u
;
auto
i
=
1u
;
...
...
src/comp/front/ast.rs
浏览文件 @
adb1754e
import
util
.common.option
;
import
std
.map.hashmap
;
import
std
.map.hashmap
;
import
std
.
util.
option
;
import
std
.option
;
import
util
.common.span
;
import
util
.common.span
;
import
util
.common.spanned
;
import
util
.common.spanned
;
...
@@ -71,16 +70,16 @@
...
@@ -71,16 +70,16 @@
type
stmt
=
spanned
[
stmt_
];
type
stmt
=
spanned
[
stmt_
];
tag
stmt_
{
tag
stmt_
{
stmt_decl
(
@
decl
);
stmt_decl
(
@
decl
);
stmt_ret
(
option
[
@
expr
]);
stmt_ret
(
option
.t
[
@
expr
]);
stmt_log
(
@
expr
);
stmt_log
(
@
expr
);
stmt_check_expr
(
@
expr
);
stmt_check_expr
(
@
expr
);
stmt_expr
(
@
expr
);
stmt_expr
(
@
expr
);
}
}
type
local
=
rec
(
option
[
@
ty
]
ty
,
type
local
=
rec
(
option
.t
[
@
ty
]
ty
,
bool
infer
,
bool
infer
,
ident
ident
,
ident
ident
,
option
[
@
expr
]
init
,
option
.t
[
@
expr
]
init
,
def_id
id
);
def_id
id
);
type
decl
=
spanned
[
decl_
];
type
decl
=
spanned
[
decl_
];
...
@@ -99,14 +98,14 @@
...
@@ -99,14 +98,14 @@
expr_unary
(
unop
,
@
expr
,
ann
);
expr_unary
(
unop
,
@
expr
,
ann
);
expr_lit
(
@
lit
,
ann
);
expr_lit
(
@
lit
,
ann
);
expr_cast
(
@
expr
,
@
ty
,
ann
);
expr_cast
(
@
expr
,
@
ty
,
ann
);
expr_if
(
@
expr
,
block
,
option
[
block
],
ann
);
expr_if
(
@
expr
,
block
,
option
.t
[
block
],
ann
);
expr_while
(
@
expr
,
block
,
ann
);
expr_while
(
@
expr
,
block
,
ann
);
expr_do_while
(
block
,
@
expr
,
ann
);
expr_do_while
(
block
,
@
expr
,
ann
);
expr_block
(
block
,
ann
);
expr_block
(
block
,
ann
);
expr_assign
(
@
expr
/* TODO: @expr|is_lval */
,
@
expr
,
ann
);
expr_assign
(
@
expr
/* TODO: @expr|is_lval */
,
@
expr
,
ann
);
expr_field
(
@
expr
,
ident
,
ann
);
expr_field
(
@
expr
,
ident
,
ann
);
expr_index
(
@
expr
,
@
expr
,
ann
);
expr_index
(
@
expr
,
@
expr
,
ann
);
expr_name
(
name
,
option
[
def
],
ann
);
expr_name
(
name
,
option
.t
[
def
],
ann
);
}
}
type
lit
=
spanned
[
lit_
];
type
lit
=
spanned
[
lit_
];
...
@@ -131,7 +130,7 @@
...
@@ -131,7 +130,7 @@
ty_box
(
@
ty
);
ty_box
(
@
ty
);
ty_vec
(
@
ty
);
ty_vec
(
@
ty
);
ty_tup
(
vec
[
tup
(
bool
/* mutability */
,
@
ty
)]);
ty_tup
(
vec
[
tup
(
bool
/* mutability */
,
@
ty
)]);
ty_path
(
path
,
option
[
def
]);
ty_path
(
path
,
option
.t
[
def
]);
}
}
tag
mode
{
tag
mode
{
...
...
src/comp/front/parser.rs
浏览文件 @
adb1754e
import
std
._io
;
import
std
._io
;
import
std
.
util.
option
;
import
std
.option
;
import
std
.
util
.some
;
import
std
.
option
.some
;
import
std
.
util
.none
;
import
std
.
option
.none
;
import
std
.map.hashmap
;
import
std
.map.hashmap
;
import
driver
.session
;
import
driver
.session
;
...
@@ -157,7 +157,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
...
@@ -157,7 +157,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
impure
fn
parse_seq
[
T
](
token
.token
bra
,
impure
fn
parse_seq
[
T
](
token
.token
bra
,
token
.token
ket
,
token
.token
ket
,
option
[
token
.token
]
sep
,
option
.t
[
token
.token
]
sep
,
(
impure
fn
(
parser
)
->
T
)
f
,
(
impure
fn
(
parser
)
->
T
)
f
,
parser
p
)
->
util
.common.spanned
[
vec
[
T
]]
{
parser
p
)
->
util
.common.spanned
[
vec
[
T
]]
{
let
bool
first
=
true
;
let
bool
first
=
true
;
...
@@ -185,7 +185,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
...
@@ -185,7 +185,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
ret
spanned
(
lo
,
hi
,
v
);
ret
spanned
(
lo
,
hi
,
v
);
}
}
impure
fn
parse_lit
(
parser
p
)
->
option
[
ast
.lit
]
{
impure
fn
parse_lit
(
parser
p
)
->
option
.t
[
ast
.lit
]
{
auto
lo
=
p
.get_span
();
auto
lo
=
p
.get_span
();
let
ast
.lit_
lit
;
let
ast
.lit_
lit
;
alt
(
p
.peek
())
{
alt
(
p
.peek
())
{
...
@@ -600,7 +600,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
...
@@ -600,7 +600,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
auto
cond
=
parse_expr
(
p
);
auto
cond
=
parse_expr
(
p
);
expect
(
p
,
token
.RPAREN
);
expect
(
p
,
token
.RPAREN
);
auto
thn
=
parse_block
(
p
);
auto
thn
=
parse_block
(
p
);
let
option
[
ast
.block
]
els
=
none
[
ast
.block
];
let
option
.t
[
ast
.block
]
els
=
none
[
ast
.block
];
hi
=
thn
.span
;
hi
=
thn
.span
;
alt
(
p
.peek
())
{
alt
(
p
.peek
())
{
case
(
token
.ELSE
)
{
case
(
token
.ELSE
)
{
...
@@ -664,7 +664,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
...
@@ -664,7 +664,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
}
}
}
}
impure
fn
parse_initializer
(
parser
p
)
->
option
[
@
ast
.expr
]
{
impure
fn
parse_initializer
(
parser
p
)
->
option
.t
[
@
ast
.expr
]
{
if
(
p
.peek
()
==
token
.EQ
)
{
if
(
p
.peek
()
==
token
.EQ
)
{
p
.bump
();
p
.bump
();
ret
some
(
parse_expr
(
p
));
ret
some
(
parse_expr
(
p
));
...
...
src/comp/middle/fold.rs
浏览文件 @
adb1754e
import
std
.map.hashmap
;
import
std
.map.hashmap
;
import
std
.
util.
option
;
import
std
.option
;
import
std
.
util
.some
;
import
std
.
option
.some
;
import
std
.
util
.none
;
import
std
.
option
.none
;
import
util
.common.new_str_hash
;
import
util
.common.new_str_hash
;
import
util
.common.spanned
;
import
util
.common.spanned
;
...
@@ -47,7 +47,7 @@
...
@@ -47,7 +47,7 @@
vec
[
tup
(
bool
,
@
ty
)]
elts
)
->
@
ty
)
fold_ty_tup
,
vec
[
tup
(
bool
,
@
ty
)]
elts
)
->
@
ty
)
fold_ty_tup
,
(
fn
(
&
ENV
e
,
&
span
sp
,
ast
.path
p
,
(
fn
(
&
ENV
e
,
&
span
sp
,
ast
.path
p
,
&
option
[
def
]
d
)
->
@
ty
)
fold_ty_path
,
&
option
.t
[
def
]
d
)
->
@
ty
)
fold_ty_path
,
// Expr folds.
// Expr folds.
(
fn
(
&
ENV
e
,
&
span
sp
,
(
fn
(
&
ENV
e
,
&
span
sp
,
...
@@ -79,7 +79,7 @@
...
@@ -79,7 +79,7 @@
(
fn
(
&
ENV
e
,
&
span
sp
,
(
fn
(
&
ENV
e
,
&
span
sp
,
@
expr
cond
,
&
block
thn
,
@
expr
cond
,
&
block
thn
,
&
option
[
block
]
els
,
&
option
.t
[
block
]
els
,
ann
a
)
->
@
expr
)
fold_expr_if
,
ann
a
)
->
@
expr
)
fold_expr_if
,
(
fn
(
&
ENV
e
,
&
span
sp
,
(
fn
(
&
ENV
e
,
&
span
sp
,
...
@@ -107,7 +107,7 @@
...
@@ -107,7 +107,7 @@
(
fn
(
&
ENV
e
,
&
span
sp
,
(
fn
(
&
ENV
e
,
&
span
sp
,
&
name
n
,
&
name
n
,
&
option
[
def
]
d
,
&
option
.t
[
def
]
d
,
ann
a
)
->
@
expr
)
fold_expr_name
,
ann
a
)
->
@
expr
)
fold_expr_name
,
// Decl folds.
// Decl folds.
...
@@ -123,7 +123,7 @@
...
@@ -123,7 +123,7 @@
@
decl
decl
)
->
@
stmt
)
fold_stmt_decl
,
@
decl
decl
)
->
@
stmt
)
fold_stmt_decl
,
(
fn
(
&
ENV
e
,
&
span
sp
,
(
fn
(
&
ENV
e
,
&
span
sp
,
&
option
[
@
expr
]
rv
)
->
@
stmt
)
fold_stmt_ret
,
&
option
.t
[
@
expr
]
rv
)
->
@
stmt
)
fold_stmt_ret
,
(
fn
(
&
ENV
e
,
&
span
sp
,
(
fn
(
&
ENV
e
,
&
span
sp
,
@
expr
e
)
->
@
stmt
)
fold_stmt_log
,
@
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)
...
@@ -568,7 +568,7 @@ fn identity_fold_ty_tup[ENV](&ENV env, &span sp, vec[tup(bool,@ty)] elts)
}
}
fn
identity_fold_ty_path
[
ENV
](
&
ENV
env
,
&
span
sp
,
ast
.path
p
,
fn
identity_fold_ty_path
[
ENV
](
&
ENV
env
,
&
span
sp
,
ast
.path
p
,
&
option
[
def
]
d
)
->
@
ty
{
&
option
.t
[
def
]
d
)
->
@
ty
{
ret
@
respan
(
sp
,
ast
.ty_path
(
p
,
d
));
ret
@
respan
(
sp
,
ast
.ty_path
(
p
,
d
));
}
}
...
@@ -614,7 +614,7 @@ fn identity_fold_expr_lit[ENV](&ENV env, &span sp, @ast.lit lit,
...
@@ -614,7 +614,7 @@ fn identity_fold_expr_lit[ENV](&ENV env, &span sp, @ast.lit lit,
fn
identity_fold_expr_if
[
ENV
](
&
ENV
env
,
&
span
sp
,
fn
identity_fold_expr_if
[
ENV
](
&
ENV
env
,
&
span
sp
,
@
expr
cond
,
&
block
thn
,
@
expr
cond
,
&
block
thn
,
&
option
[
block
]
els
,
ann
a
)
->
@
expr
{
&
option
.t
[
block
]
els
,
ann
a
)
->
@
expr
{
ret
@
respan
(
sp
,
ast
.expr_if
(
cond
,
thn
,
els
,
a
));
ret
@
respan
(
sp
,
ast
.expr_if
(
cond
,
thn
,
els
,
a
));
}
}
...
@@ -650,7 +650,7 @@ fn identity_fold_expr_index[ENV](&ENV env, &span sp,
...
@@ -650,7 +650,7 @@ fn identity_fold_expr_index[ENV](&ENV env, &span sp,
}
}
fn
identity_fold_expr_name
[
ENV
](
&
ENV
env
,
&
span
sp
,
fn
identity_fold_expr_name
[
ENV
](
&
ENV
env
,
&
span
sp
,
&
name
n
,
&
option
[
def
]
d
,
&
name
n
,
&
option
.t
[
def
]
d
,
ann
a
)
->
@
expr
{
ann
a
)
->
@
expr
{
ret
@
respan
(
sp
,
ast
.expr_name
(
n
,
d
,
a
));
ret
@
respan
(
sp
,
ast
.expr_name
(
n
,
d
,
a
));
}
}
...
@@ -675,7 +675,7 @@ fn identity_fold_stmt_decl[ENV](&ENV env, &span sp, @decl d) -> @stmt {
...
@@ -675,7 +675,7 @@ fn identity_fold_stmt_decl[ENV](&ENV env, &span sp, @decl d) -> @stmt {
}
}
fn
identity_fold_stmt_ret
[
ENV
](
&
ENV
env
,
&
span
sp
,
fn
identity_fold_stmt_ret
[
ENV
](
&
ENV
env
,
&
span
sp
,
&
option
[
@
expr
]
rv
)
->
@
stmt
{
&
option
.t
[
@
expr
]
rv
)
->
@
stmt
{
ret
@
respan
(
sp
,
ast
.stmt_ret
(
rv
));
ret
@
respan
(
sp
,
ast
.stmt_ret
(
rv
));
}
}
...
...
src/comp/middle/resolve.rs
浏览文件 @
adb1754e
...
@@ -8,9 +8,9 @@
...
@@ -8,9 +8,9 @@
import
std
.list.list
;
import
std
.list.list
;
import
std
.list.nil
;
import
std
.list.nil
;
import
std
.list.cons
;
import
std
.list.cons
;
import
std
.
util.
option
;
import
std
.option
;
import
std
.
util
.some
;
import
std
.
option
.some
;
import
std
.
util
.none
;
import
std
.
option
.none
;
import
std
._str
;
import
std
._str
;
tag
scope
{
tag
scope
{
...
@@ -22,11 +22,11 @@
...
@@ -22,11 +22,11 @@
type
env
=
rec
(
list
[
scope
]
scopes
,
type
env
=
rec
(
list
[
scope
]
scopes
,
session
.session
sess
);
session
.session
sess
);
fn
lookup_name
(
&
env
e
,
ast
.ident
i
)
->
option
[
def
]
{
fn
lookup_name
(
&
env
e
,
ast
.ident
i
)
->
option
.t
[
def
]
{
// log "resolving name " + i;
// log "resolving name " + i;
fn
found_def_item
(
@
ast
.item
i
)
->
option
[
def
]
{
fn
found_def_item
(
@
ast
.item
i
)
->
option
.t
[
def
]
{
alt
(
i
.node
)
{
alt
(
i
.node
)
{
case
(
ast
.item_fn
(
_
,
_
,
?
id
))
{
case
(
ast
.item_fn
(
_
,
_
,
?
id
))
{
ret
some
[
def
](
ast
.def_fn
(
id
));
ret
some
[
def
](
ast
.def_fn
(
id
));
...
@@ -40,7 +40,7 @@ fn found_def_item(@ast.item i) -> option[def] {
...
@@ -40,7 +40,7 @@ fn found_def_item(@ast.item i) -> option[def] {
}
}
}
}
fn
found_decl_stmt
(
@
ast
.stmt
s
)
->
option
[
def
]
{
fn
found_decl_stmt
(
@
ast
.stmt
s
)
->
option
.t
[
def
]
{
alt
(
s
.node
)
{
alt
(
s
.node
)
{
case
(
ast
.stmt_decl
(
?
d
))
{
case
(
ast
.stmt_decl
(
?
d
))
{
alt
(
d
.node
)
{
alt
(
d
.node
)
{
...
@@ -56,7 +56,7 @@ fn found_decl_stmt(@ast.stmt s) -> option[def] {
...
@@ -56,7 +56,7 @@ fn found_decl_stmt(@ast.stmt s) -> option[def] {
ret
none
[
def
];
ret
none
[
def
];
}
}
fn
check_mod
(
ast
.ident
i
,
ast
._mod
m
)
->
option
[
def
]
{
fn
check_mod
(
ast
.ident
i
,
ast
._mod
m
)
->
option
.t
[
def
]
{
alt
(
m
.index
.find
(
i
))
{
alt
(
m
.index
.find
(
i
))
{
case
(
some
[
uint
](
?
ix
))
{
case
(
some
[
uint
](
?
ix
))
{
ret
found_def_item
(
m
.items
.
(
ix
));
ret
found_def_item
(
m
.items
.
(
ix
));
...
@@ -66,7 +66,7 @@ fn check_mod(ast.ident i, ast._mod m) -> option[def] {
...
@@ -66,7 +66,7 @@ fn check_mod(ast.ident i, ast._mod m) -> option[def] {
}
}
fn
in_scope
(
ast
.ident
i
,
&
scope
s
)
->
option
[
def
]
{
fn
in_scope
(
ast
.ident
i
,
&
scope
s
)
->
option
.t
[
def
]
{
alt
(
s
)
{
alt
(
s
)
{
case
(
scope_crate
(
?
c
))
{
case
(
scope_crate
(
?
c
))
{
...
@@ -103,7 +103,7 @@ fn in_scope(ast.ident i, &scope s) -> option[def] {
...
@@ -103,7 +103,7 @@ fn in_scope(ast.ident i, &scope s) -> option[def] {
}
}
fn
fold_expr_name
(
&
env
e
,
&
span
sp
,
&
ast
.name
n
,
fn
fold_expr_name
(
&
env
e
,
&
span
sp
,
&
ast
.name
n
,
&
option
[
def
]
d
,
ann
a
)
->
@
ast
.expr
{
&
option
.t
[
def
]
d
,
ann
a
)
->
@
ast
.expr
{
auto
d_
=
lookup_name
(
e
,
n
.node.ident
);
auto
d_
=
lookup_name
(
e
,
n
.node.ident
);
...
...
src/comp/middle/trans.rs
浏览文件 @
adb1754e
...
@@ -3,9 +3,9 @@
...
@@ -3,9 +3,9 @@
import
std
._str.rustrt.sbuf
;
import
std
._str.rustrt.sbuf
;
import
std
._vec.rustrt.vbuf
;
import
std
._vec.rustrt.vbuf
;
import
std
.map.hashmap
;
import
std
.map.hashmap
;
import
std
.
util.
option
;
import
std
.option
;
import
std
.
util
.some
;
import
std
.
option
.some
;
import
std
.
util
.none
;
import
std
.
option
.none
;
import
front
.ast
;
import
front
.ast
;
import
driver
.session
;
import
driver
.session
;
...
@@ -613,7 +613,7 @@ fn trans_drop_str(@block_ctxt cx, ValueRef v) -> result {
...
@@ -613,7 +613,7 @@ fn trans_drop_str(@block_ctxt cx, ValueRef v) -> result {
}
}
impure
fn
trans_if
(
@
block_ctxt
cx
,
&
ast
.expr
cond
,
impure
fn
trans_if
(
@
block_ctxt
cx
,
&
ast
.expr
cond
,
&
ast
.block
thn
,
&
option
[
ast
.block
]
els
)
->
result
{
&
ast
.block
thn
,
&
option
.t
[
ast
.block
]
els
)
->
result
{
auto
cond_res
=
trans_expr
(
cx
,
cond
);
auto
cond_res
=
trans_expr
(
cx
,
cond
);
...
@@ -868,7 +868,7 @@ fn trans_lval(@block_ctxt cx, &ast.expr e)
...
@@ -868,7 +868,7 @@ fn trans_lval(@block_ctxt cx, &ast.expr e)
ret
res
(
next_cx
,
C_nil
());
ret
res
(
next_cx
,
C_nil
());
}
}
impure
fn
trans_ret
(
@
block_ctxt
cx
,
&
option
[
@
ast
.expr
]
e
)
->
result
{
impure
fn
trans_ret
(
@
block_ctxt
cx
,
&
option
.t
[
@
ast
.expr
]
e
)
->
result
{
auto
r
=
res
(
cx
,
C_nil
());
auto
r
=
res
(
cx
,
C_nil
());
alt
(
e
)
{
alt
(
e
)
{
case
(
some
[
@
ast
.expr
](
?
x
))
{
case
(
some
[
@
ast
.expr
](
?
x
))
{
...
...
src/lib/_vec.rs
浏览文件 @
adb1754e
import
vbuf
=
rustrt
.vbuf
;
import
vbuf
=
rustrt
.vbuf
;
import
op
=
util
.operator
;
import
std
.option
;
native
"rust"
mod
rustrt
{
native
"rust"
mod
rustrt
{
type
vbuf
;
type
vbuf
;
...
@@ -129,7 +129,7 @@ fn grow[T](&mutable vec[T] v, int n, &T initval) {
...
@@ -129,7 +129,7 @@ fn grow[T](&mutable vec[T] v, int n, &T initval) {
}
}
}
}
fn
map
[
T
,
U
](
&
op
[
T
,
U
]
f
,
&
vec
[
T
]
v
)
->
vec
[
U
]
{
fn
map
[
T
,
U
](
&
op
tion
.operator
[
T
,
U
]
f
,
&
vec
[
T
]
v
)
->
vec
[
U
]
{
let
vec
[
U
]
u
=
alloc
[
U
](
len
[
T
](
v
));
let
vec
[
U
]
u
=
alloc
[
U
](
len
[
T
](
v
));
for
(
T
ve
in
v
)
{
for
(
T
ve
in
v
)
{
u
+=
vec
(
f
(
ve
));
u
+=
vec
(
f
(
ve
));
...
...
src/lib/deque.rs
浏览文件 @
adb1754e
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* A deque, for fun. Untested as of yet. Likely buggy.
* A deque, for fun. Untested as of yet. Likely buggy.
*/
*/
import
std
.
util
;
import
std
.
option
;
import
std
._vec
;
import
std
._vec
;
import
std
._int
;
import
std
._int
;
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
fn
create
[
T
]()
->
t
[
T
]
{
fn
create
[
T
]()
->
t
[
T
]
{
type
cell
[
T
]
=
mutable
util
.option
[
T
];
type
cell
[
T
]
=
mutable
option
.t
[
T
];
let
uint
initial_capacity
=
32u
;
// 2^5
let
uint
initial_capacity
=
32u
;
// 2^5
...
@@ -39,7 +39,7 @@ fn fill[T](uint i, uint nelts, uint lo,
...
@@ -39,7 +39,7 @@ fn fill[T](uint i, uint nelts, uint lo,
if
(
i
<
nelts
)
{
if
(
i
<
nelts
)
{
ret
old
.
((
lo
+
i
)
%
nelts
);
ret
old
.
((
lo
+
i
)
%
nelts
);
}
else
{
}
else
{
ret
util
.none
[
T
];
ret
option
.none
[
T
];
}
}
}
}
...
@@ -50,7 +50,7 @@ fn fill[T](uint i, uint nelts, uint lo,
...
@@ -50,7 +50,7 @@ fn fill[T](uint i, uint nelts, uint lo,
fn
get
[
T
](
vec
[
cell
[
T
]]
elts
,
uint
i
)
->
T
{
fn
get
[
T
](
vec
[
cell
[
T
]]
elts
,
uint
i
)
->
T
{
alt
(
elts
.
(
i
))
{
alt
(
elts
.
(
i
))
{
case
(
util
.some
[
T
](
?
t
))
{
ret
t
;
}
case
(
option
.some
[
T
](
?
t
))
{
ret
t
;
}
case
(
_
)
{
fail
;
}
case
(
_
)
{
fail
;
}
}
}
}
}
...
@@ -77,7 +77,7 @@ fn add_front(&T t) {
...
@@ -77,7 +77,7 @@ fn add_front(&T t) {
hi
=
nelts
;
hi
=
nelts
;
}
}
elts
.
(
lo
)
=
util
.some
[
T
](
t
);
elts
.
(
lo
)
=
option
.some
[
T
](
t
);
nelts
+=
1u
;
nelts
+=
1u
;
}
}
...
@@ -88,7 +88,7 @@ fn add_back(&T t) {
...
@@ -88,7 +88,7 @@ fn add_back(&T t) {
hi
=
nelts
;
hi
=
nelts
;
}
}
elts
.
(
hi
)
=
util
.some
[
T
](
t
);
elts
.
(
hi
)
=
option
.some
[
T
](
t
);
hi
=
(
hi
+
1u
)
%
_
vec
.len
[
cell
[
T
]](
elts
);
hi
=
(
hi
+
1u
)
%
_
vec
.len
[
cell
[
T
]](
elts
);
nelts
+=
1u
;
nelts
+=
1u
;
}
}
...
@@ -99,7 +99,7 @@ fn add_back(&T t) {
...
@@ -99,7 +99,7 @@ fn add_back(&T t) {
*/
*/
fn
pop_front
()
->
T
{
fn
pop_front
()
->
T
{
let
T
t
=
get
[
T
](
elts
,
lo
);
let
T
t
=
get
[
T
](
elts
,
lo
);
elts
.
(
lo
)
=
util
.none
[
T
];
elts
.
(
lo
)
=
option
.none
[
T
];
lo
=
(
lo
+
1u
)
%
_
vec
.len
[
cell
[
T
]](
elts
);
lo
=
(
lo
+
1u
)
%
_
vec
.len
[
cell
[
T
]](
elts
);
nelts
-=
1u
;
nelts
-=
1u
;
ret
t
;
ret
t
;
...
@@ -113,7 +113,7 @@ fn pop_back() -> T {
...
@@ -113,7 +113,7 @@ fn pop_back() -> T {
}
}
let
T
t
=
get
[
T
](
elts
,
hi
);
let
T
t
=
get
[
T
](
elts
,
hi
);
elts
.
(
hi
)
=
util
.none
[
T
];
elts
.
(
hi
)
=
option
.none
[
T
];
nelts
-=
1u
;
nelts
-=
1u
;
ret
t
;
ret
t
;
}
}
...
@@ -132,7 +132,7 @@ fn get(int i) -> T {
...
@@ -132,7 +132,7 @@ fn get(int i) -> T {
}
}
}
}
let
vec
[
cell
[
T
]]
v
=
_
vec
.init_elt
[
cell
[
T
]](
util
.none
[
T
],
let
vec
[
cell
[
T
]]
v
=
_
vec
.init_elt
[
cell
[
T
]](
option
.none
[
T
],
initial_capacity
);
initial_capacity
);
ret
deque
[
T
](
0u
,
0u
,
0u
,
v
);
ret
deque
[
T
](
0u
,
0u
,
0u
,
v
);
...
...
src/lib/list.rs
浏览文件 @
adb1754e
import
util
.option
;
import
std
.option
;
import
util
.some
;
import
option
.some
;
import
util
.none
;
import
option
.none
;
// FIXME: It would probably be more appealing to define this as
// FIXME: It would probably be more appealing to define this as
// type list[T] = rec(T hd, option[@list[T]] tl), but at the moment
// type list[T] = rec(T hd, option[@list[T]] tl), but at the moment
...
@@ -27,7 +27,7 @@ fn foldl[T,U](&list[T] ls, &U u, fn(&T t, U u) -> U f) -> U {
...
@@ -27,7 +27,7 @@ fn foldl[T,U](&list[T] ls, &U u, fn(&T t, U u) -> U f) -> U {
}
}
fn
find
[
T
,
U
](
&
list
[
T
]
ls
,
fn
find
[
T
,
U
](
&
list
[
T
]
ls
,
(
fn
(
&
T
)
->
option
[
U
])
f
)
->
option
[
U
]
{
(
fn
(
&
T
)
->
option
.t
[
U
])
f
)
->
option
.t
[
U
]
{
alt
(
ls
)
{
alt
(
ls
)
{
case
(
cons
[
T
](
?
hd
,
?
tl
))
{
case
(
cons
[
T
](
?
hd
,
?
tl
))
{
alt
(
f
(
hd
))
{
alt
(
f
(
hd
))
{
...
...
src/lib/map.rs
浏览文件 @
adb1754e
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
import
std
._int
;
import
std
._int
;
import
std
.sys
;
import
std
.sys
;
import
std
.
util
;
import
std
.
option
;
import
std
._vec
;
import
std
._vec
;
...
@@ -17,8 +17,8 @@
...
@@ -17,8 +17,8 @@
fn
insert
(
&
K
key
,
&
V
val
)
->
bool
;
fn
insert
(
&
K
key
,
&
V
val
)
->
bool
;
fn
contains_key
(
&
K
key
)
->
bool
;
fn
contains_key
(
&
K
key
)
->
bool
;
fn
get
(
&
K
key
)
->
V
;
fn
get
(
&
K
key
)
->
V
;
fn
find
(
&
K
key
)
->
util
.option
[
V
];
fn
find
(
&
K
key
)
->
option
.t
[
V
];
fn
remove
(
&
K
key
)
->
util
.option
[
V
];
fn
remove
(
&
K
key
)
->
option
.t
[
V
];
fn
rehash
();
fn
rehash
();
iter
items
()
->
tup
(
K
,
V
);
iter
items
()
->
tup
(
K
,
V
);
};
};
...
@@ -103,7 +103,7 @@ fn find_common[K, V](&hashfn[K] hasher,
...
@@ -103,7 +103,7 @@ fn find_common[K, V](&hashfn[K] hasher,
vec
[
mutable
bucket
[
K
,
V
]]
bkts
,
vec
[
mutable
bucket
[
K
,
V
]]
bkts
,
uint
nbkts
,
uint
nbkts
,
&
K
key
)
&
K
key
)
->
util
.option
[
V
]
->
option
.t
[
V
]
{
{
let
uint
i
=
0u
;
let
uint
i
=
0u
;
while
(
i
<
nbkts
)
{
while
(
i
<
nbkts
)
{
...
@@ -111,17 +111,17 @@ fn find_common[K, V](&hashfn[K] hasher,
...
@@ -111,17 +111,17 @@ fn find_common[K, V](&hashfn[K] hasher,
alt
(
bkts
.
(
j
))
{
alt
(
bkts
.
(
j
))
{
case
(
some
[
K
,
V
](
?
k
,
?
v
))
{
case
(
some
[
K
,
V
](
?
k
,
?
v
))
{
if
(
eqer
(
key
,
k
))
{
if
(
eqer
(
key
,
k
))
{
ret
util
.some
[
V
](
v
);
ret
option
.some
[
V
](
v
);
}
}
}
}
case
(
nil
[
K
,
V
])
{
case
(
nil
[
K
,
V
])
{
ret
util
.none
[
V
];
ret
option
.none
[
V
];
}
}
case
(
deleted
[
K
,
V
])
{
}
case
(
deleted
[
K
,
V
])
{
}
}
}
i
+=
1u
;
i
+=
1u
;
}
}
ret
util
.none
[
V
];
ret
option
.none
[
V
];
}
}
...
@@ -173,25 +173,25 @@ fn insert(&K key, &V val) -> bool {
...
@@ -173,25 +173,25 @@ fn insert(&K key, &V val) -> bool {
fn
contains_key
(
&
K
key
)
->
bool
{
fn
contains_key
(
&
K
key
)
->
bool
{
alt
(
find_common
[
K
,
V
](
hasher
,
eqer
,
bkts
,
nbkts
,
key
))
{
alt
(
find_common
[
K
,
V
](
hasher
,
eqer
,
bkts
,
nbkts
,
key
))
{
case
(
util
.some
[
V
](
_
))
{
ret
true
;
}
case
(
option
.some
[
V
](
_
))
{
ret
true
;
}
case
(
_
)
{
ret
false
;
}
case
(
_
)
{
ret
false
;
}
}
}
}
}
fn
get
(
&
K
key
)
->
V
{
fn
get
(
&
K
key
)
->
V
{
alt
(
find_common
[
K
,
V
](
hasher
,
eqer
,
bkts
,
nbkts
,
key
))
{
alt
(
find_common
[
K
,
V
](
hasher
,
eqer
,
bkts
,
nbkts
,
key
))
{
case
(
util
.some
[
V
](
?
val
))
{
ret
val
;
}
case
(
option
.some
[
V
](
?
val
))
{
ret
val
;
}
case
(
_
)
{
fail
;
}
case
(
_
)
{
fail
;
}
}
}
}
}
fn
find
(
&
K
key
)
->
util
.option
[
V
]
{
fn
find
(
&
K
key
)
->
option
.t
[
V
]
{
// FIXME: should be 'be' but parametric tail-calls don't
// FIXME: should be 'be' but parametric tail-calls don't
// work at the moment.
// work at the moment.
ret
find_common
[
K
,
V
](
hasher
,
eqer
,
bkts
,
nbkts
,
key
);
ret
find_common
[
K
,
V
](
hasher
,
eqer
,
bkts
,
nbkts
,
key
);
}
}
fn
remove
(
&
K
key
)
->
util
.option
[
V
]
{
fn
remove
(
&
K
key
)
->
option
.t
[
V
]
{
let
uint
i
=
0u
;
let
uint
i
=
0u
;
while
(
i
<
nbkts
)
{
while
(
i
<
nbkts
)
{
let
uint
j
=
(
hash
[
K
](
hasher
,
nbkts
,
key
,
i
));
let
uint
j
=
(
hash
[
K
](
hasher
,
nbkts
,
key
,
i
));
...
@@ -200,17 +200,17 @@ fn remove(&K key) -> util.option[V] {
...
@@ -200,17 +200,17 @@ fn remove(&K key) -> util.option[V] {
if
(
eqer
(
key
,
k
))
{
if
(
eqer
(
key
,
k
))
{
bkts
.
(
j
)
=
deleted
[
K
,
V
];
bkts
.
(
j
)
=
deleted
[
K
,
V
];
nelts
-=
1u
;
nelts
-=
1u
;
ret
util
.some
[
V
](
v
);
ret
option
.some
[
V
](
v
);
}
}
}
}
case
(
deleted
[
K
,
V
])
{
}
case
(
deleted
[
K
,
V
])
{
}
case
(
nil
[
K
,
V
])
{
case
(
nil
[
K
,
V
])
{
ret
util
.none
[
V
];
ret
option
.none
[
V
];
}
}
}
}
i
+=
1u
;
i
+=
1u
;
}
}
ret
util
.none
[
V
];
ret
option
.none
[
V
];
}
}
fn
rehash
()
{
fn
rehash
()
{
...
...
src/lib/option.rs
0 → 100644
浏览文件 @
adb1754e
// lib/option.rs
tag
t
[
T
]
{
none
;
some
(
T
);
}
type
operator
[
T
,
U
]
=
fn
(
&
T
)
->
U
;
fn
get
[
T
](
&
t
[
T
]
opt
)
->
T
{
alt
(
opt
)
{
case
(
some
[
T
](
?
x
))
{
ret
x
;
}
case
(
none
[
T
])
{
fail
;
}
}
}
fn
map
[
T
,
U
](
&
operator
[
T
,
U
]
f
,
&
t
[
T
]
opt
)
->
t
[
U
]
{
alt
(
opt
)
{
case
(
some
[
T
](
?
x
))
{
ret
some
[
U
](
f
(
x
));
}
case
(
none
[
T
])
{
ret
none
[
U
];
}
}
}
// Local Variables:
// mode: rust;
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:
src/lib/std.rc
浏览文件 @
adb1754e
...
@@ -20,6 +20,7 @@ mod _task;
...
@@ -20,6 +20,7 @@ mod _task;
// Utility modules.
// Utility modules.
mod option;
mod util;
mod util;
// Authorize various rule-bendings.
// Authorize various rule-bendings.
...
...
src/lib/util.rs
浏览文件 @
adb1754e
tag
option
[
T
]
{
none
;
some
(
T
);
}
type
operator
[
T
,
U
]
=
fn
(
&
T
)
->
U
;
fn
option_map
[
T
,
U
](
&
operator
[
T
,
U
]
f
,
&
option
[
T
]
opt
)
->
option
[
U
]
{
alt
(
opt
)
{
case
(
some
[
T
](
?
x
))
{
ret
some
[
U
](
f
(
x
));
}
case
(
none
[
T
])
{
ret
none
[
U
];
}
}
}
fn
id
[
T
](
&
T
x
)
->
T
{
fn
id
[
T
](
&
T
x
)
->
T
{
ret
x
;
ret
x
;
}
}
...
...
src/test/run-pass/lib-vec.rs
浏览文件 @
adb1754e
...
@@ -32,7 +32,7 @@ fn test_slice() {
...
@@ -32,7 +32,7 @@ fn test_slice() {
fn
test_map
()
{
fn
test_map
()
{
fn
square
(
&
int
x
)
->
int
{
ret
x
*
x
;
}
fn
square
(
&
int
x
)
->
int
{
ret
x
*
x
;
}
let
std
.
util
.operator
[
int
,
int
]
op
=
square
;
let
std
.
option
.operator
[
int
,
int
]
op
=
square
;
let
vec
[
int
]
v
=
vec
(
1
,
2
,
3
,
4
,
5
);
let
vec
[
int
]
v
=
vec
(
1
,
2
,
3
,
4
,
5
);
let
vec
[
int
]
s
=
std
._vec.map
[
int
,
int
](
op
,
v
);
let
vec
[
int
]
s
=
std
._vec.map
[
int
,
int
](
op
,
v
);
let
int
i
=
0
;
let
int
i
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录