diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-03-24 11:38:36 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-03-24 11:38:36 -0700 |
commit | 3589c440a872f6e622d9fe62af83b4fe69114add (patch) | |
tree | d58be59995e27bf24147a7cf7dcc21abbc476302 | |
parent | 6bed086e87f6bc5d90699e8ddad97eb8bf05371a (diff) | |
download | mu-3589c440a872f6e622d9fe62af83b4fe69114add.tar.gz |
2810 - undo 2767, reclaiming local allocations
I realize that there's still a serious problem with refcounts. Everything's fine as long as I copy those shared addresses manually elsewhere, but there's a couple of places where I just do a memcopy right now without any extra smarts: in 'copy' and 'merge' instructions. I need to replace support for arbitrary types in these instructions, and replace it with transforms to generate the right code. Mu basically needs copy constructors and destructors, so that containers can decrement the refcounts of any elements (or elements of elements, or elements of elements of elements..) that are shared addresses. But my confidence in this whole approach is shaken. Maybe I should stop this project. It's turning into a language+OS design project where I was hoping that being a toy would shelter me from these concerns. I just want to explore turning manual tests into reproducible automatic ones. Maybe I should just build libraries for each interface to hardware (network, disk, screen, keyboard, ...) in C++11 or something. Use no high-level libraries for sockets, files, etc. Instead rely on just the kernel syscalls, memory allocator, RAII, STL. Build things from scratch atop those building blocks.
-rw-r--r-- | 043space.cc | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/043space.cc b/043space.cc index 06cd09b1..51c84af6 100644 --- a/043space.cc +++ b/043space.cc @@ -211,12 +211,13 @@ def foo [ # both calls to foo should have received the same default-space +mem: storing 1 in location 3 -:(scenario local_scope_frees_up_allocations) -def main [ - local-scope - x:address:shared:array:character <- new [abc] -] -+mem: clearing x:address:shared:array:character +:(code) // pending test +//? :(scenario local_scope_frees_up_allocations) +//? def main [ +//? local-scope +//? x:address:shared:array:character <- new [abc] +//? ] +//? +mem: clearing x:address:shared:array:character //: todo: do this in a transform, rather than magically in the reply instruction :(after "Falling Through End Of Recipe") @@ -240,20 +241,24 @@ void try_reclaim_locals() { const instruction& inst = exiting_recipe.steps.at(0); if (inst.old_name != "local-scope") return; // reclaim any local variables unless they're being returned - vector<double> zero; - zero.push_back(0); - for (int i = /*leave default space for last*/1; i < SIZE(exiting_recipe.steps); ++i) { - const instruction& inst = exiting_recipe.steps.at(i); - for (int i = 0; i < SIZE(inst.products); ++i) { - if (!is_mu_address(inst.products.at(i))) continue; - // local variables only - if (has_property(inst.products.at(i), "space")) continue; - if (has_property(inst.products.at(i), "lookup")) continue; - if (escaping(inst.products.at(i))) continue; - trace(9999, "mem") << "clearing " << inst.products.at(i).original_string << end(); - write_memory(inst.products.at(i), zero); - } - } + // TODO: this isn't working yet. Doesn't handle address:shared stored in + // containers created by 'copy' or 'merge'. We'd end up deleting the address + // even if some container containing it was returned. + // This might doom our whole refcounting-based approach :/ +//? vector<double> zero; +//? zero.push_back(0); +//? for (int i = /*leave default space for last*/1; i < SIZE(exiting_recipe.steps); ++i) { +//? const instruction& inst = exiting_recipe.steps.at(i); +//? for (int i = 0; i < SIZE(inst.products); ++i) { +//? if (!is_mu_address(inst.products.at(i))) continue; +//? // local variables only +//? if (has_property(inst.products.at(i), "space")) continue; +//? if (has_property(inst.products.at(i), "lookup")) continue; +//? if (escaping(inst.products.at(i))) continue; +//? trace(9999, "mem") << "clearing " << inst.products.at(i).original_string << end(); +//? write_memory(inst.products.at(i), zero); +//? } +//? } abandon(current_call().default_space, /*refcount*/1 + /*array length*/1 + /*number-of-locals*/Name[r][""]); } |