aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2010-12-16 16:34:20 -0800
committerPatrick Walton <[email protected]>2010-12-16 16:35:19 -0800
commitbfdba2dbcceb33e0738949e9f4d6635f689baf1b (patch)
tree636784b5a2386843c51df82988d5041438d8b6dc /src
parentStub out translation of obj ctors (no vtbl or body built). (diff)
downloadrust-bfdba2dbcceb33e0738949e9f4d6635f689baf1b.tar.xz
rust-bfdba2dbcceb33e0738949e9f4d6635f689baf1b.zip
rustc: Translate parametric function signatures into task + type parameters + formal arguments
Diffstat (limited to 'src')
-rw-r--r--src/comp/middle/trans.rs25
-rw-r--r--src/comp/middle/typeck.rs27
2 files changed, 52 insertions, 0 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index b074e6d6..8b094ffc 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -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 {
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index 26bb8871..b318ce33 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -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)) {