about summary refs log tree commit diff
path: root/src/rt/rust_upcall.cpp
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2011-12-11 20:42:37 -0800
committerNiko Matsakis <niko@alum.mit.edu>2011-12-14 14:32:20 -0800
commit6a8cb704d9c2543cb30df2e26b992c17e3bc488d (patch)
tree6ba04893e5cf0f91ecf9c19dc15b783184dc0093 /src/rt/rust_upcall.cpp
parent36177dd3e986199f4f6cb669423ca9cf78ff8d74 (diff)
downloadrust-6a8cb704d9c2543cb30df2e26b992c17e3bc488d.tar.gz
rust-6a8cb704d9c2543cb30df2e26b992c17e3bc488d.zip
get basic code generation working, clone type descs for lambda[send]
Diffstat (limited to 'src/rt/rust_upcall.cpp')
-rw-r--r--src/rt/rust_upcall.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp
index 811a6b36df0..d91e282d2e2 100644
--- a/src/rt/rust_upcall.cpp
+++ b/src/rt/rust_upcall.cpp
@@ -195,6 +195,39 @@ upcall_shared_free(void* ptr) {
     SWITCH_STACK(&args, upcall_s_shared_free);
 }
 
+struct s_clone_type_desc_args {
+    const type_desc *td;
+    type_desc *res;
+};
+
+void upcall_s_clone_type_desc(s_clone_type_desc_args *args)
+{
+    // Copy the main part of the type descriptor:
+    const type_desc *td = args->td;
+    int n_descs = td->n_descs;
+    size_t sz = sizeof(type_desc) + sizeof(type_desc*) * n_descs;
+    args->res = (type_desc*) malloc(sz);
+    memcpy(args->res, td, sizeof(type_desc));
+
+    // Recursively copy any referenced descriptors:
+    for (int i = 0; i < n_descs; i++) {
+        s_clone_type_desc_args rec_args = { td->descs[i], 0 };
+        upcall_s_clone_type_desc(&rec_args);
+        args->res->descs[i] = rec_args.res;
+    }
+}
+
+/**
+ * Called to deep-clone type descriptors so they can be attached to a sendable
+ * function.  Eventually this should perhaps move to a centralized hashtable.
+ */
+type_desc *
+upcall_clone_type_desc(type_desc *td) {
+    s_clone_type_desc_args args = { td, 0 };
+    SWITCH_STACK(&args, upcall_s_clone_type_desc);
+    return args.res;
+}
+
 struct s_get_type_desc_args {
     type_desc *retval;
     size_t size;