From 6a8cb704d9c2543cb30df2e26b992c17e3bc488d Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 11 Dec 2011 20:42:37 -0800 Subject: get basic code generation working, clone type descs for lambda[send] --- src/rt/rust_internal.h | 2 ++ src/rt/rust_upcall.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'src/rt') diff --git a/src/rt/rust_internal.h b/src/rt/rust_internal.h index 1e65d701e8f..889b5f62018 100644 --- a/src/rt/rust_internal.h +++ b/src/rt/rust_internal.h @@ -279,6 +279,8 @@ struct type_desc { const type_desc *descs[]; }; +extern "C" type_desc *rust_clone_type_desc(type_desc*); + #include "circular_buffer.h" #include "rust_task.h" #include "rust_port.h" 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; -- cgit 1.4.1-3-g733a5