Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e5fdd7b6
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,发现更多精彩内容 >>
提交
e5fdd7b6
编写于
11月 03, 2010
作者:
G
Graydon Hoare
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support while and do-while loops in rustc.
上级
dc299c9a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
116 addition
and
0 deletion
+116
-0
src/comp/front/ast.rs
src/comp/front/ast.rs
+2
-0
src/comp/front/parser.rs
src/comp/front/parser.rs
+43
-0
src/comp/middle/fold.rs
src/comp/middle/fold.rs
+35
-0
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+36
-0
未找到文件。
src/comp/front/ast.rs
浏览文件 @
e5fdd7b6
...
...
@@ -94,6 +94,8 @@
expr_lit
(
@
lit
,
option
[
@
ty
]);
expr_cast
(
@
expr
,
@
ty
);
expr_if
(
@
expr
,
block
,
option
[
block
],
option
[
@
ty
]);
expr_while
(
@
expr
,
block
,
option
[
@
ty
]);
expr_do_while
(
block
,
@
expr
,
option
[
@
ty
]);
expr_block
(
block
,
option
[
@
ty
]);
expr_assign
(
@
expr
/* TODO: @expr|is_lval */
,
@
expr
,
option
[
@
ty
]);
expr_field
(
@
expr
,
ident
,
option
[
@
ty
]);
...
...
src/comp/front/parser.rs
浏览文件 @
e5fdd7b6
...
...
@@ -613,6 +613,33 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
ret
@
spanned
(
lo
,
hi
,
ast
.expr_if
(
cond
,
thn
,
els
,
none
[
@
ast
.ty
]));
}
impure
fn
parse_while_expr
(
parser
p
)
->
@
ast
.expr
{
auto
lo
=
p
.get_span
();
auto
hi
=
lo
;
expect
(
p
,
token
.WHILE
);
expect
(
p
,
token
.LPAREN
);
auto
cond
=
parse_expr
(
p
);
expect
(
p
,
token
.RPAREN
);
auto
body
=
parse_block
(
p
);
hi
=
body
.span
;
ret
@
spanned
(
lo
,
hi
,
ast
.expr_while
(
cond
,
body
,
none
[
@
ast
.ty
]));
}
impure
fn
parse_do_while_expr
(
parser
p
)
->
@
ast
.expr
{
auto
lo
=
p
.get_span
();
auto
hi
=
lo
;
expect
(
p
,
token
.DO
);
auto
body
=
parse_block
(
p
);
expect
(
p
,
token
.WHILE
);
expect
(
p
,
token
.LPAREN
);
auto
cond
=
parse_expr
(
p
);
expect
(
p
,
token
.RPAREN
);
hi
=
cond
.span
;
ret
@
spanned
(
lo
,
hi
,
ast
.expr_do_while
(
body
,
cond
,
none
[
@
ast
.ty
]));
}
impure
fn
parse_expr
(
parser
p
)
->
@
ast
.expr
{
alt
(
p
.peek
())
{
case
(
token
.LBRACE
)
{
...
...
@@ -623,6 +650,12 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
case
(
token
.IF
)
{
ret
parse_if_expr
(
p
);
}
case
(
token
.WHILE
)
{
ret
parse_while_expr
(
p
);
}
case
(
token
.DO
)
{
ret
parse_do_while_expr
(
p
);
}
case
(
_
)
{
ret
parse_assign_expr
(
p
);
}
...
...
@@ -741,6 +774,16 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
ret
@
spanned
(
lo
,
e
.span
,
ast
.stmt_expr
(
e
));
}
case
(
token
.WHILE
)
{
auto
e
=
parse_expr
(
p
);
ret
@
spanned
(
lo
,
e
.span
,
ast
.stmt_expr
(
e
));
}
case
(
token
.DO
)
{
auto
e
=
parse_expr
(
p
);
ret
@
spanned
(
lo
,
e
.span
,
ast
.stmt_expr
(
e
));
}
case
(
token
.LBRACE
)
{
auto
e
=
parse_expr
(
p
);
ret
@
spanned
(
lo
,
e
.span
,
ast
.stmt_expr
(
e
));
...
...
src/comp/middle/fold.rs
浏览文件 @
e5fdd7b6
...
...
@@ -81,6 +81,14 @@
&
option
[
block
]
els
,
option
[
@
ty
]
ty
)
->
@
expr
)
fold_expr_if
,
(
fn
(
&
ENV
e
,
&
span
sp
,
@
expr
cond
,
&
block
body
,
option
[
@
ty
]
ty
)
->
@
expr
)
fold_expr_while
,
(
fn
(
&
ENV
e
,
&
span
sp
,
&
block
body
,
@
expr
cond
,
option
[
@
ty
]
ty
)
->
@
expr
)
fold_expr_do_while
,
(
fn
(
&
ENV
e
,
&
span
sp
,
&
block
blk
,
option
[
@
ty
]
ty
)
->
@
expr
)
fold_expr_block
,
...
...
@@ -335,6 +343,18 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr {
ret
fld
.fold_expr_if
(
env_
,
e
.span
,
ccnd
,
tthn
,
eels
,
t
);
}
case
(
ast
.expr_while
(
?
cnd
,
?
body
,
?
t
))
{
auto
ccnd
=
fold_expr
(
env_
,
fld
,
cnd
);
auto
bbody
=
fold_block
(
env_
,
fld
,
body
);
ret
fld
.fold_expr_while
(
env_
,
e
.span
,
ccnd
,
bbody
,
t
);
}
case
(
ast
.expr_do_while
(
?
body
,
?
cnd
,
?
t
))
{
auto
bbody
=
fold_block
(
env_
,
fld
,
body
);
auto
ccnd
=
fold_expr
(
env_
,
fld
,
cnd
);
ret
fld
.fold_expr_do_while
(
env_
,
e
.span
,
bbody
,
ccnd
,
t
);
}
case
(
ast
.expr_block
(
?
b
,
?
t
))
{
auto
bb
=
fold_block
(
env_
,
fld
,
b
);
ret
fld
.fold_expr_block
(
env_
,
e
.span
,
bb
,
t
);
...
...
@@ -598,6 +618,18 @@ fn identity_fold_expr_if[ENV](&ENV env, &span sp,
ret
@
respan
(
sp
,
ast
.expr_if
(
cond
,
thn
,
els
,
t
));
}
fn
identity_fold_expr_while
[
ENV
](
&
ENV
env
,
&
span
sp
,
@
expr
cond
,
&
block
body
,
option
[
@
ty
]
t
)
->
@
expr
{
ret
@
respan
(
sp
,
ast
.expr_while
(
cond
,
body
,
t
));
}
fn
identity_fold_expr_do_while
[
ENV
](
&
ENV
env
,
&
span
sp
,
&
block
body
,
@
expr
cond
,
option
[
@
ty
]
t
)
->
@
expr
{
ret
@
respan
(
sp
,
ast
.expr_do_while
(
body
,
cond
,
t
));
}
fn
identity_fold_expr_block
[
ENV
](
&
ENV
env
,
&
span
sp
,
&
block
blk
,
option
[
@
ty
]
t
)
->
@
expr
{
ret
@
respan
(
sp
,
ast
.expr_block
(
blk
,
t
));
...
...
@@ -765,6 +797,9 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
fold_expr_unary
=
bind
identity_fold_expr_unary
[
ENV
](
_
,
_
,
_
,
_
,
_
),
fold_expr_lit
=
bind
identity_fold_expr_lit
[
ENV
](
_
,
_
,
_
,
_
),
fold_expr_if
=
bind
identity_fold_expr_if
[
ENV
](
_
,
_
,
_
,
_
,
_
,
_
),
fold_expr_while
=
bind
identity_fold_expr_while
[
ENV
](
_
,
_
,
_
,
_
,
_
),
fold_expr_do_while
=
bind
identity_fold_expr_do_while
[
ENV
](
_
,
_
,
_
,
_
,
_
),
fold_expr_block
=
bind
identity_fold_expr_block
[
ENV
](
_
,
_
,
_
,
_
),
fold_expr_assign
=
bind
identity_fold_expr_assign
[
ENV
](
_
,
_
,
_
,
_
,
_
),
fold_expr_field
=
bind
identity_fold_expr_field
[
ENV
](
_
,
_
,
_
,
_
,
_
),
...
...
src/comp/middle/trans.rs
浏览文件 @
e5fdd7b6
...
...
@@ -653,6 +653,38 @@ fn trans_drop_str(@block_ctxt cx, ValueRef v) -> result {
ret
res
(
next_cx
,
phi
);
}
impure
fn
trans_while
(
@
block_ctxt
cx
,
&
ast
.expr
cond
,
&
ast
.block
body
)
->
result
{
auto
cond_cx
=
new_empty_block_ctxt
(
cx
.fcx
);
auto
body_cx
=
new_empty_block_ctxt
(
cx
.fcx
);
auto
next_cx
=
new_extension_block_ctxt
(
cx
);
cx
.build
.Br
(
cond_cx
.llbb
);
auto
cond_res
=
trans_expr
(
cond_cx
,
cond
);
cond_cx
.build
.CondBr
(
cond_res
.val
,
body_cx
.llbb
,
next_cx
.llbb
);
auto
body_res
=
trans_block
(
body_cx
,
body
);
body_cx
.build
.Br
(
cond_cx
.llbb
);
ret
res
(
next_cx
,
C_nil
());
}
impure
fn
trans_do_while
(
@
block_ctxt
cx
,
&
ast
.block
body
,
&
ast
.expr
cond
)
->
result
{
auto
body_cx
=
new_empty_block_ctxt
(
cx
.fcx
);
auto
next_cx
=
new_extension_block_ctxt
(
cx
);
cx
.build
.Br
(
body_cx
.llbb
);
auto
body_res
=
trans_block
(
body_cx
,
body
);
auto
cond_res
=
trans_expr
(
body_cx
,
cond
);
body_cx
.build
.CondBr
(
cond_res
.val
,
body_cx
.llbb
,
next_cx
.llbb
);
ret
res
(
next_cx
,
body_res
.val
);
}
// The additional bool returned indicates whether it's a local
// (that is represented as an alloca, hence needs a 'load' to be
// used as an rval).
...
...
@@ -723,6 +755,10 @@ fn trans_lval(@block_ctxt cx, &ast.expr e)
ret
trans_if
(
cx
,
*
cond
,
thn
,
els
);
}
case
(
ast
.expr_while
(
?
cond
,
?
body
,
_
))
{
ret
trans_while
(
cx
,
*
cond
,
body
);
}
case
(
ast
.expr_block
(
?
blk
,
_
))
{
auto
sub_cx
=
new_empty_block_ctxt
(
cx
.fcx
);
auto
next_cx
=
new_extension_block_ctxt
(
cx
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录