about summary refs log tree commit diff
path: root/src/rt/rust_crate_cache.cpp
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-01-06 17:29:06 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2012-01-06 17:40:05 +0100
commit822acdd1703af1714cb084a76c10937713339f6d (patch)
treeba886f43420a5b2d0905887c89794a5116220e0e /src/rt/rust_crate_cache.cpp
parentd23e2052e0187e57b2fe626e5354a77ced29d0cf (diff)
downloadrust-822acdd1703af1714cb084a76c10937713339f6d.tar.gz
rust-822acdd1703af1714cb084a76c10937713339f6d.zip
Make binding of fns with bounded type parameters work
Interns non-static dicts to heap-allocated equivalents so that they no
longer have stack scope.

Closes #1436
Diffstat (limited to 'src/rt/rust_crate_cache.cpp')
-rw-r--r--src/rt/rust_crate_cache.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/rt/rust_crate_cache.cpp b/src/rt/rust_crate_cache.cpp
index 47b402102f3..6fcb0fc699e 100644
--- a/src/rt/rust_crate_cache.cpp
+++ b/src/rt/rust_crate_cache.cpp
@@ -45,8 +45,30 @@ rust_crate_cache::get_type_desc(size_t size,
     return td;
 }
 
+void**
+rust_crate_cache::get_dict(size_t n_fields, void** dict) {
+    rust_hashable_dict *found = NULL;
+    uintptr_t key = 0;
+    for (size_t i = 0; i < n_fields; ++i) key ^= (uintptr_t)dict[i];
+    size_t keysz = sizeof(uintptr_t);
+    HASH_FIND(hh, this->dicts, &key, keysz, found);
+    if (found) { printf("found!\n"); return &(found->fields[0]); }
+    printf("not found\n");
+    size_t dictsz = n_fields * sizeof(void*);
+    found = (rust_hashable_dict*)
+        sched->kernel->malloc(keysz + sizeof(UT_hash_handle) + dictsz,
+                              "crate cache dict");
+    if (!found) return NULL;
+    found->key = key;
+    void** retptr = &(found->fields[0]);
+    memcpy(retptr, dict, dictsz);
+    HASH_ADD(hh, this->dicts, key, keysz, found);
+    return retptr;
+}
+
 rust_crate_cache::rust_crate_cache(rust_scheduler *sched)
     : type_descs(NULL),
+      dicts(NULL),
       sched(sched),
       idx(0)
 {
@@ -62,6 +84,11 @@ rust_crate_cache::flush() {
         DLOG(sched, mem, "rust_crate_cache::flush() tydesc %" PRIxPTR, d);
         sched->kernel->free(d);
     }
+    while (dicts) {
+        rust_hashable_dict *d = dicts;
+        HASH_DEL(dicts, d);
+        sched->kernel->free(d);
+    }
 }
 
 rust_crate_cache::~rust_crate_cache()