rustc: Translate parametric function signatures into task + type parameters + formal arguments
This commit is contained in:
parent
31f0642da3
commit
bfdba2dbcc
@ -214,6 +214,21 @@ fn T_task() -> TypeRef {
|
||||
));
|
||||
}
|
||||
|
||||
fn T_tydesc() -> TypeRef {
|
||||
auto pvoid = T_ptr(T_i8());
|
||||
auto glue_fn_ty = T_ptr(T_fn(vec(T_taskptr(), pvoid), T_void()));
|
||||
ret T_struct(vec(pvoid, // first_param
|
||||
T_int(), // size
|
||||
T_int(), // align
|
||||
glue_fn_ty, // copy_glue_off
|
||||
glue_fn_ty, // drop_glue_off
|
||||
glue_fn_ty, // free_glue_off
|
||||
glue_fn_ty, // sever_glue_off
|
||||
glue_fn_ty, // mark_glue_off
|
||||
glue_fn_ty, // obj_drop_glue_off
|
||||
glue_fn_ty)); // is_stateful
|
||||
}
|
||||
|
||||
fn T_array(TypeRef t, uint n) -> TypeRef {
|
||||
ret llvm.LLVMArrayType(t, n);
|
||||
}
|
||||
@ -271,6 +286,15 @@ fn type_of_fn(@crate_ctxt cx,
|
||||
vec[typeck.arg] inputs,
|
||||
@typeck.ty output) -> TypeRef {
|
||||
let vec[TypeRef] atys = vec(T_taskptr());
|
||||
|
||||
auto fn_ty = typeck.plain_ty(typeck.ty_fn(inputs, output));
|
||||
auto ty_param_count = typeck.count_ty_params(fn_ty);
|
||||
auto i = 0u;
|
||||
while (i < ty_param_count) {
|
||||
atys += T_tydesc();
|
||||
i += 1u;
|
||||
}
|
||||
|
||||
for (typeck.arg arg in inputs) {
|
||||
let TypeRef t = type_of(cx, arg.ty);
|
||||
alt (arg.mode) {
|
||||
@ -2614,6 +2638,7 @@ fn trans_exit_task_glue(@crate_ctxt cx) {
|
||||
fn create_typedefs(@crate_ctxt cx) {
|
||||
llvm.LLVMAddTypeName(cx.llmod, _str.buf("rust_crate"), T_crate());
|
||||
llvm.LLVMAddTypeName(cx.llmod, _str.buf("rust_task"), T_task());
|
||||
llvm.LLVMAddTypeName(cx.llmod, _str.buf("rust_tydesc"), T_tydesc());
|
||||
}
|
||||
|
||||
fn crate_constant(@crate_ctxt cx) -> ValueRef {
|
||||
|
@ -942,6 +942,33 @@ fn ann_to_type(&ast.ann ann) -> @ty {
|
||||
}
|
||||
}
|
||||
|
||||
fn count_ty_params(@ty t) -> uint {
|
||||
state obj ty_param_counter(@mutable vec[ast.def_id] param_ids) {
|
||||
fn fold_simple_ty(@ty t) -> @ty {
|
||||
alt (t.struct) {
|
||||
case (ty_param(?param_id)) {
|
||||
for (ast.def_id other_param_id in *param_ids) {
|
||||
if (param_id._0 == other_param_id._0 &&
|
||||
param_id._1 == other_param_id._1) {
|
||||
ret t;
|
||||
}
|
||||
}
|
||||
*param_ids += vec(param_id);
|
||||
}
|
||||
case (_) { /* fall through */ }
|
||||
}
|
||||
ret t;
|
||||
}
|
||||
}
|
||||
|
||||
let vec[ast.def_id] param_ids_inner = vec();
|
||||
let @mutable vec[ast.def_id] param_ids = @mutable param_ids_inner;
|
||||
fold_ty(ty_param_counter(param_ids), t);
|
||||
ret _vec.len[ast.def_id](*param_ids);
|
||||
}
|
||||
|
||||
// Type accessors for AST nodes
|
||||
|
||||
fn stmt_ty(@ast.stmt s) -> @ty {
|
||||
alt (s.node) {
|
||||
case (ast.stmt_expr(?e)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user