Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
081c3aa7
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,发现更多精彩内容 >>
提交
081c3aa7
编写于
2月 25, 2011
作者:
R
Rafael Ávila de Espíndola
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass the abi of native functions all the way to codegen.
上级
f8f6f078
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
32 deletion
+51
-32
src/comp/front/parser.rs
src/comp/front/parser.rs
+2
-2
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+4
-3
src/comp/middle/ty.rs
src/comp/middle/ty.rs
+20
-11
src/comp/middle/typeck.rs
src/comp/middle/typeck.rs
+25
-16
未找到文件。
src/comp/front/parser.rs
浏览文件 @
081c3aa7
...
...
@@ -1818,8 +1818,8 @@ fn default_native_name(session.session sess, str id) -> str {
auto
abi
=
ast
.native_abi_cdecl
;
if
(
p
.peek
()
!=
token
.MOD
)
{
auto
t
=
parse_str_lit
(
p
);
if
(
t
==
"cdecl"
)
{
}
else
if
(
t
==
"rust"
)
{
if
(
_
str
.eq
(
t
,
"cdecl"
)
)
{
}
else
if
(
_
str
.eq
(
t
,
"rust"
)
)
{
abi
=
ast
.native_abi_rust
;
}
else
{
p
.err
(
"unsupported abi: "
+
t
);
...
...
src/comp/middle/trans.rs
浏览文件 @
081c3aa7
...
...
@@ -516,7 +516,8 @@ fn type_of_fn(@crate_ctxt cx,
ret
type_of_fn_full
(
cx
,
proto
,
none
[
TypeRef
],
inputs
,
output
);
}
fn
type_of_native_fn
(
@
crate_ctxt
cx
,
vec
[
ty
.arg
]
inputs
,
fn
type_of_native_fn
(
@
crate_ctxt
cx
,
ast
.native_abi
abi
,
vec
[
ty
.arg
]
inputs
,
@
ty
.t
output
)
->
TypeRef
{
let
vec
[
TypeRef
]
atys
=
type_of_explicit_args
(
cx
,
inputs
);
ret
T_fn
(
atys
,
type_of
(
cx
,
output
));
...
...
@@ -571,8 +572,8 @@ fn type_of_inner(@crate_ctxt cx, @ty.t t) -> TypeRef {
case
(
ty
.ty_fn
(
?
proto
,
?
args
,
?
out
))
{
ret
T_fn_pair
(
cx
.tn
,
type_of_fn
(
cx
,
proto
,
args
,
out
));
}
case
(
ty
.ty_native_fn
(
?
args
,
?
out
))
{
ret
T_fn_pair
(
cx
.tn
,
type_of_native_fn
(
cx
,
args
,
out
));
case
(
ty
.ty_native_fn
(
?
a
bi
,
?
a
rgs
,
?
out
))
{
ret
T_fn_pair
(
cx
.tn
,
type_of_native_fn
(
cx
,
a
bi
,
a
rgs
,
out
));
}
case
(
ty
.ty_obj
(
?
meths
))
{
auto
th
=
mk_type_handle
();
...
...
src/comp/middle/ty.rs
浏览文件 @
081c3aa7
...
...
@@ -41,7 +41,7 @@
ty_tup
(
vec
[
@
t
]);
ty_rec
(
vec
[
field
]);
ty_fn
(
ast
.proto
,
vec
[
arg
],
@
t
);
// TODO: effect
ty_native_fn
(
vec
[
arg
],
@
t
);
// TODO: effect
ty_native_fn
(
ast
.native_abi
,
vec
[
arg
],
@
t
);
// TODO: effect
ty_obj
(
vec
[
method
]);
ty_var
(
int
);
// ephemeral type var
ty_local
(
ast
.def_id
);
// type of a local var
...
...
@@ -261,7 +261,7 @@ fn field_to_str(&field f) -> str {
s
=
fn_to_str
(
proto
,
none
[
ast
.ident
],
inputs
,
output
);
}
case
(
ty_native_fn
(
?
inputs
,
?
output
))
{
case
(
ty_native_fn
(
_
,
?
inputs
,
?
output
))
{
s
=
fn_to_str
(
ast
.proto_fn
,
none
[
ast
.ident
],
inputs
,
output
);
}
...
...
@@ -346,13 +346,13 @@ fn rewrap(@t orig, &sty new) -> @t {
}
ret
rewrap
(
ty
,
ty_fn
(
proto
,
new_args
,
fold_ty
(
fld
,
ret_ty
)));
}
case
(
ty_native_fn
(
?
args
,
?
ret_ty
))
{
case
(
ty_native_fn
(
?
a
bi
,
?
a
rgs
,
?
ret_ty
))
{
let
vec
[
arg
]
new_args
=
vec
();
for
(
arg
a
in
args
)
{
auto
new_ty
=
fold_ty
(
fld
,
a
.ty
);
new_args
+=
vec
(
rec
(
mode
=
a
.mode
,
ty
=
new_ty
));
}
ret
rewrap
(
ty
,
ty_native_fn
(
new_args
,
fold_ty
(
fld
,
ret_ty
)));
ret
rewrap
(
ty
,
ty_native_fn
(
abi
,
new_args
,
fold_ty
(
fld
,
ret_ty
)));
}
case
(
ty_obj
(
?
methods
))
{
let
vec
[
method
]
new_methods
=
vec
();
...
...
@@ -596,7 +596,7 @@ fn fold_simple_ty(@t ty) -> @t {
fn
ty_fn_args
(
@
t
fty
)
->
vec
[
arg
]
{
alt
(
fty
.struct
)
{
case
(
ty
.ty_fn
(
_
,
?
a
,
_
))
{
ret
a
;
}
case
(
ty
.ty_native_fn
(
?
a
,
_
))
{
ret
a
;
}
case
(
ty
.ty_native_fn
(
_
,
?
a
,
_
))
{
ret
a
;
}
}
fail
;
}
...
...
@@ -611,7 +611,7 @@ fn ty_fn_proto(@t fty) -> ast.proto {
fn
ty_fn_ret
(
@
t
fty
)
->
@
t
{
alt
(
fty
.struct
)
{
case
(
ty
.ty_fn
(
_
,
_
,
?
r
))
{
ret
r
;
}
case
(
ty
.ty_native_fn
(
_
,
?
r
))
{
ret
r
;
}
case
(
ty
.ty_native_fn
(
_
,
_
,
?
r
))
{
ret
r
;
}
}
fail
;
}
...
...
@@ -619,7 +619,7 @@ fn ty_fn_ret(@t fty) -> @t {
fn
is_fn_ty
(
@
t
fty
)
->
bool
{
alt
(
fty
.struct
)
{
case
(
ty
.ty_fn
(
_
,
_
,
_
))
{
ret
true
;
}
case
(
ty
.ty_native_fn
(
_
,
_
))
{
ret
true
;
}
case
(
ty
.ty_native_fn
(
_
,
_
,
_
))
{
ret
true
;
}
case
(
_
)
{
ret
false
;
}
}
ret
false
;
...
...
@@ -938,12 +938,18 @@ fn unify_fn(@hashmap[int,@ty.t] bindings,
}
fn
unify_native_fn
(
@
hashmap
[
int
,
@
ty
.t
]
bindings
,
ast
.native_abi
e_abi
,
ast
.native_abi
a_abi
,
@
ty
.t
expected
,
@
ty
.t
actual
,
&
unify_handler
handler
,
vec
[
arg
]
expected_inputs
,
@
t
expected_output
,
vec
[
arg
]
actual_inputs
,
@
t
actual_output
)
->
unify_result
{
if
(
e_abi
!=
a_abi
)
{
ret
ures_err
(
terr_mismatch
,
expected
,
actual
);
}
auto
t
=
unify_fn_common
(
bindings
,
expected
,
actual
,
handler
,
expected_inputs
,
expected_output
,
actual_inputs
,
actual_output
);
...
...
@@ -952,7 +958,8 @@ fn unify_native_fn(@hashmap[int,@ty.t] bindings,
ret
r
;
}
case
(
fn_common_res_ok
(
?
result_ins
,
?
result_out
))
{
auto
t2
=
plain_ty
(
ty
.ty_native_fn
(
result_ins
,
result_out
));
auto
t2
=
plain_ty
(
ty
.ty_native_fn
(
e_abi
,
result_ins
,
result_out
));
ret
ures_ok
(
t2
);
}
}
...
...
@@ -1314,10 +1321,12 @@ fn unify_step(@hashmap[int,@ty.t] bindings, @ty.t in_expected,
}
}
case
(
ty
.ty_native_fn
(
?
expected_inputs
,
?
expected_output
))
{
case
(
ty
.ty_native_fn
(
?
e_abi
,
?
expected_inputs
,
?
expected_output
))
{
alt
(
actual
.struct
)
{
case
(
ty
.ty_native_fn
(
?
actual_inputs
,
?
actual_output
))
{
ret
unify_native_fn
(
bindings
,
case
(
ty
.ty_native_fn
(
?
a_abi
,
?
actual_inputs
,
?
actual_output
))
{
ret
unify_native_fn
(
bindings
,
e_abi
,
a_abi
,
expected
,
actual
,
handler
,
expected_inputs
,
expected_output
,
actual_inputs
,
actual_output
);
...
...
src/comp/middle/typeck.rs
浏览文件 @
081c3aa7
...
...
@@ -35,7 +35,7 @@
tag
any_item
{
any_item_rust
(
@
ast
.item
);
any_item_native
(
@
ast
.native_item
);
any_item_native
(
@
ast
.native_item
,
ast
.native_abi
);
}
type
ty_item_table
=
hashmap
[
ast
.def_id
,
any_item
];
...
...
@@ -272,7 +272,7 @@ fn getter(@crate_ctxt ccx, ast.def_id id) -> ty_and_params {
ty
=
actual_type
(
ty
,
item
);
params
=
ty_params_of_item
(
item
);
}
case
(
any_item_native
(
?
native_item
))
{
case
(
any_item_native
(
?
native_item
,
_
))
{
params
=
ty_params_of_native_item
(
native_item
);
}
}
...
...
@@ -346,10 +346,11 @@ fn ty_of_native_fn_decl(@ty_item_table id_to_ty_item,
fn
(
&@
ast
.ty
ast_ty
)
->
@
ty
.t
convert
,
fn
(
&
ast
.arg
a
)
->
arg
ty_of_arg
,
&
ast
.fn_decl
decl
,
ast
.native_abi
abi
,
ast
.def_id
def_id
)
->
@
ty
.t
{
auto
input_tys
=
_
vec
.map
[
ast
.arg
,
arg
](
ty_of_arg
,
decl
.inputs
);
auto
output_ty
=
convert
(
decl
.output
);
auto
t_fn
=
plain_ty
(
ty
.ty_native_fn
(
input_tys
,
output_ty
));
auto
t_fn
=
plain_ty
(
ty
.ty_native_fn
(
abi
,
input_tys
,
output_ty
));
item_to_ty
.insert
(
def_id
,
t_fn
);
ret
t_fn
;
}
...
...
@@ -370,9 +371,9 @@ fn getter(@ty_item_table id_to_ty_item,
ty
=
actual_type
(
ty
,
item
);
params
=
ty_params_of_item
(
item
);
}
case
(
any_item_native
(
?
native_item
))
{
case
(
any_item_native
(
?
native_item
,
?
abi
))
{
ty
=
ty_of_native_item
(
id_to_ty_item
,
item_to_ty
,
native_item
);
native_item
,
abi
);
params
=
ty_params_of_native_item
(
native_item
);
}
}
...
...
@@ -490,14 +491,15 @@ fn ty_of_item(@ty_item_table id_to_ty_item,
fn
ty_of_native_item
(
@
ty_item_table
id_to_ty_item
,
@
ty_table
item_to_ty
,
@
ast
.native_item
it
)
->
@
ty
.t
{
@
ast
.native_item
it
,
ast
.native_abi
abi
)
->
@
ty
.t
{
alt
(
it
.node
)
{
case
(
ast
.native_item_fn
(
?
ident
,
?
fn_decl
,
?
params
,
?
def_id
,
_
))
{
auto
get
=
bind
getter
(
id_to_ty_item
,
item_to_ty
,
_
);
auto
convert
=
bind
ast_ty_to_ty
(
get
,
_
);
auto
f
=
bind
ty_of_arg
(
id_to_ty_item
,
item_to_ty
,
_
);
ret
ty_of_native_fn_decl
(
id_to_ty_item
,
item_to_ty
,
convert
,
f
,
fn_decl
,
def_id
);
f
,
fn_decl
,
abi
,
def_id
);
}
case
(
ast
.native_item_ty
(
_
,
?
def_id
))
{
if
(
item_to_ty
.contains_key
(
def_id
))
{
...
...
@@ -578,7 +580,10 @@ fn collect_native(&@ty_item_table id_to_ty_item, @ast.native_item i)
->
@
ty_item_table
{
alt
(
i
.node
)
{
case
(
ast
.native_item_ty
(
_
,
?
def_id
))
{
id_to_ty_item
.insert
(
def_id
,
any_item_native
(
i
));
// The abi of types is not used.
id_to_ty_item
.insert
(
def_id
,
any_item_native
(
i
,
ast
.native_abi_cdecl
));
}
case
(
_
)
{
}
...
...
@@ -598,18 +603,22 @@ fn collect_native(&@ty_item_table id_to_ty_item, @ast.native_item i)
type
env
=
rec
(
session
.session
sess
,
@
ty_item_table
id_to_ty_item
,
@
ty_table
item_to_ty
);
@
ty_table
item_to_ty
,
ast
.native_abi
abi
);
let
@
env
e
=
@
rec
(
sess
=
sess
,
id_to_ty_item
=
id_to_ty_item
,
item_to_ty
=
item_to_ty
);
item_to_ty
=
item_to_ty
,
abi
=
ast
.native_abi_cdecl
);
fn
convert
(
&@
env
e
,
@
ast
.item
i
)
->
@
env
{
auto
abi
=
e
.abi
;
alt
(
i
.node
)
{
case
(
ast
.item_mod
(
_
,
_
,
_
))
{
// ignore item_mod, it has no type.
}
case
(
ast
.item_native_mod
(
_
,
_
,
_
))
{
case
(
ast
.item_native_mod
(
_
,
?
native_mod
,
_
))
{
// ignore item_native_mod, it has no type.
abi
=
native_mod
.abi
;
}
case
(
_
)
{
// This call populates the ty_table with the converted type of
...
...
@@ -617,11 +626,11 @@ fn convert(&@env e, @ast.item i) -> @env {
ty_of_item
(
e
.id_to_ty_item
,
e
.item_to_ty
,
i
);
}
}
ret
e
;
ret
@
rec
(
abi
=
abi
with
*
e
)
;
}
fn
convert_native
(
&@
env
e
,
@
ast
.native_item
i
)
->
@
env
{
ty_of_native_item
(
e
.id_to_ty_item
,
e
.item_to_ty
,
i
);
ty_of_native_item
(
e
.id_to_ty_item
,
e
.item_to_ty
,
i
,
e
.abi
);
ret
e
;
}
...
...
@@ -1322,8 +1331,8 @@ fn check_call_or_bind(&@fn_ctxt fcx, &@ast.expr f,
case
(
ty
.ty_fn
(
?
proto
,
_
,
_
))
{
t_0
=
plain_ty
(
ty
.ty_fn
(
proto
,
arg_tys_0
,
rt_0
));
}
case
(
ty
.ty_native_fn
(
_
,
_
))
{
t_0
=
plain_ty
(
ty
.ty_native_fn
(
arg_tys_0
,
rt_0
));
case
(
ty
.ty_native_fn
(
?
abi
,
_
,
_
))
{
t_0
=
plain_ty
(
ty
.ty_native_fn
(
a
bi
,
a
rg_tys_0
,
rt_0
));
}
case
(
_
)
{
log
"check_call_or_bind(): fn expr doesn't have fn type"
;
...
...
@@ -1807,7 +1816,7 @@ fn check_call_or_bind(&@fn_ctxt fcx, &@ast.expr f,
auto
rt_1
=
plain_ty
(
ty
.ty_nil
);
// FIXME: typestate botch
alt
(
expr_ty
(
result
._0
)
.struct
)
{
case
(
ty
.ty_fn
(
_
,
_
,
?
rt
))
{
rt_1
=
rt
;
}
case
(
ty
.ty_native_fn
(
_
,
?
rt
))
{
rt_1
=
rt
;
}
case
(
ty
.ty_native_fn
(
_
,
_
,
?
rt
))
{
rt_1
=
rt
;
}
case
(
_
)
{
log
"LHS of call expr didn't have a function type?!"
;
fail
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录