Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
941101a9
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,发现更多精彩内容 >>
提交
941101a9
编写于
12月 08, 2011
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
define ty and update parser for sendable lambdas
上级
327ec89f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
97 addition
and
7 deletion
+97
-7
src/comp/middle/ty.rs
src/comp/middle/ty.rs
+1
-0
src/comp/syntax/ast.rs
src/comp/syntax/ast.rs
+11
-1
src/comp/syntax/parse/parser.rs
src/comp/syntax/parse/parser.rs
+85
-6
未找到文件。
src/comp/middle/ty.rs
浏览文件 @
941101a9
...
...
@@ -980,6 +980,7 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
alt
proto
{
ast
::
proto_block
.
{
ast
::
kind_noncopyable
}
ast
::
proto_shared
(
_
)
{
ast
::
kind_copyable
}
ast
::
proto_send
.
{
ast
::
kind_sendable
}
ast
::
proto_bare
.
{
ast
::
kind_sendable
}
}
}
...
...
src/comp/syntax/ast.rs
浏览文件 @
941101a9
...
...
@@ -113,6 +113,7 @@
tag
proto
{
proto_bare
;
proto_send
;
proto_shared
(
proto_sugar
);
proto_block
;
}
...
...
@@ -198,7 +199,7 @@
expr_for
(
@
local
,
@
expr
,
blk
);
expr_do_while
(
blk
,
@
expr
);
expr_alt
(
@
expr
,
[
arm
]);
expr_fn
(
_
fn
);
expr_fn
(
_
fn
,
@
capture
);
expr_block
(
blk
);
/*
...
...
@@ -233,6 +234,15 @@
expr_mac
(
mac
);
}
// At the moment, one can only capture local variables.
type
capture_
=
{
is_send
:
bool
,
copies
:
[
ident
],
moves
:
[
ident
]
};
type
capture
=
spanned
<
capture_
>
;
/*
// Says whether this is a block the user marked as
// "unchecked"
...
...
src/comp/syntax/parse/parser.rs
浏览文件 @
941101a9
...
...
@@ -14,6 +14,12 @@
tag
file_type
{
CRATE_FILE
;
SOURCE_FILE
;
}
tag
fn_kw
{
fn_kw_fn
;
fn_kw_lambda
;
fn_kw_block
;
};
type
parse_sess
=
@
{
cm
:
codemap
::
codemap
,
mutable
next_id
:
node_id
};
fn
next_node_id
(
sess
:
parse_sess
)
->
node_id
{
...
...
@@ -536,7 +542,14 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
}
else
if
eat_word
(
p
,
"block"
)
{
t
=
parse_ty_fn
(
ast
::
proto_block
,
p
);
}
else
if
eat_word
(
p
,
"lambda"
)
{
t
=
parse_ty_fn
(
ast
::
proto_shared
(
ast
::
sugar_sexy
),
p
);
if
p
.peek
()
==
token
::
LBRACE
{
// lambda[send](...)
expect
(
p
,
token
::
LBRACE
);
expect_word
(
p
,
"send"
);
expect
(
p
,
token
::
RBRACE
);
t
=
parse_ty_fn
(
ast
::
proto_send
,
p
);
}
else
{
// lambda(...)
t
=
parse_ty_fn
(
ast
::
proto_shared
(
ast
::
sugar_sexy
),
p
);
}
}
else
if
eat_word
(
p
,
"obj"
)
{
t
=
parse_ty_obj
(
p
);
}
else
if
p
.peek
()
==
token
::
MOD_SEP
||
is_ident
(
p
.peek
())
{
...
...
@@ -831,11 +844,11 @@ fn parse_bottom_expr(p: parser) -> @ast::expr {
*/
}
else
if
eat_word
(
p
,
"fn"
)
{
let
proto
=
parse_fn_anon_proto
(
p
);
ret
parse_fn_expr
(
p
,
proto
);
ret
parse_fn_expr
(
p
,
fn_kw_fn
);
}
else
if
eat_word
(
p
,
"block"
)
{
ret
parse_fn_expr
(
p
,
ast
::
proto
_block
);
ret
parse_fn_expr
(
p
,
fn_kw
_block
);
}
else
if
eat_word
(
p
,
"lambda"
)
{
ret
parse_fn_expr
(
p
,
ast
::
proto_shared
(
ast
::
sugar_sexy
)
);
ret
parse_fn_expr
(
p
,
fn_kw_lambda
);
}
else
if
eat_word
(
p
,
"unchecked"
)
{
ret
parse_block_expr
(
p
,
lo
,
ast
::
unchecked_blk
);
}
else
if
eat_word
(
p
,
"unsafe"
)
{
...
...
@@ -1274,12 +1287,78 @@ fn parse_if_expr(p: parser) -> @ast::expr {
}
}
fn
parse_fn_expr
(
p
:
parser
,
proto
:
ast
::
proto
)
->
@
ast
::
expr
{
// Parses:
//
// CC := [send; copy ID*; move ID*]
//
// where any part is optional and trailing ; is permitted.
fn
parse_capture_clause
(
p
:
parser
)
->
(
bool
,
@
ast
::
capture
)
{
fn
expect_opt_trailing_semi
(
p
:
parser
)
{
if
!
eat
(
p
,
token
::
SEMI
)
{
if
p
.peek
()
!=
token
::
RBRACE
{
p
.fatal
(
"expecting ; or ]"
);
}
}
}
fn
eat_ident_list
(
p
:
parser
)
->
[
ast
::
ident
]
{
let
res
=
[];
while
true
{
alt
p
.peek
()
{
token
::
IDENT
(
_
,
_
)
{
res
+=
parse_ident
(
p
);
if
!
eat
(
p
,
token
::
COMMA
)
{
ret
res
;
}
}
_
{
ret
res
;
}
}
}
}
let
is_send
=
false
;
let
copies
=
[];
let
moves
=
[];
if
p
.peek
()
!=
token
::
LBRACE
{
ret
(
is_send
,
captures
);
}
expect
(
p
,
token
::
LBRACE
);
while
p
.peek
()
!=
token
::
RBRACE
{
if
eat_word
(
p
,
"send"
)
{
is_send
=
true
;
expect_opt_trailing_semi
(
p
);
}
else
if
eat_word
(
p
,
"copy"
)
{
copies
+=
eat_ident_list
();
expect_opt_trailing_semi
(
p
);
}
else
if
eat_word
(
p
,
"move"
)
{
moves
+=
eat_ident_list
();
expect_opt_trailing_semi
(
p
);
}
else
{
let
s
:
str
=
"expecting send, copy, or move clause"
;
p
.fatal
(
s
);
}
}
ret
@
{
is_send
:
is_send
,
copies
:
copies
,
moves
:
moves
};
}
fn
parse_fn_expr
(
p
:
parser
,
kw
:
fn_kw
)
->
@
ast
::
expr
{
let
lo
=
p
.get_last_lo_pos
();
let
cap
=
parse_capture_clause
(
p
);
let
decl
=
parse_fn_decl
(
p
,
ast
::
impure_fn
,
ast
::
il_normal
);
let
body
=
parse_block
(
p
);
let
proto
=
alt
(
kw
,
cap
.is_send
)
{
(
fn_kw_fn
.
,
true
)
{
ast
::
proto_bare
}
(
fn_kw_lambda
.
,
true
)
{
ast
::
proto_send
}
(
fn_kw_lambda
.
,
false
)
{
ast
::
proto_shared
(
ast
::
sugar_sexy
)
}
(
fn_kw_block
.
,
false
)
{
ast
::
proto_block
}
(
_
,
true
)
{
p
.fatal
(
"only lambda can be declared sendable"
);
}
}
let
_
fn
=
{
decl
:
decl
,
proto
:
proto
,
body
:
body
};
ret
mk_expr
(
p
,
lo
,
body
.span.hi
,
ast
::
expr_fn
(
_
fn
));
ret
mk_expr
(
p
,
lo
,
body
.span.hi
,
ast
::
expr_fn
(
_
fn
,
cap
));
}
fn
parse_fn_block_expr
(
p
:
parser
)
->
@
ast
::
expr
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录