diff --git a/docs/builtin.md b/docs/builtin.md index efdeea4..eabaf6d 100644 --- a/docs/builtin.md +++ b/docs/builtin.md @@ -10,6 +10,10 @@ Causes the interpreter to enter *interactive mode*. Aborts the interpreter process. It's intended to indicate that an execution branch is not reachable. +#### `pass()` + +Does nothing it can be used to fill empty blocks + ## Constructors #### `Region()` @@ -22,7 +26,7 @@ Creates a new `cown` object. The region must have a local reference count of one. The `move` keyword is used to replace the local value with `None`. -### `create(proto)` +#### `create(proto)` Creates a new object from the given prototype. @@ -34,6 +38,24 @@ Performs a deep freeze of the object and all referenced objects. This will move the objects out of their current region into the immutable region. Cowns will stop the freeze propagation, as they can be safely shared across threads and behaviors. +#### `close(reg)` + +Forces the given region to close by invalidating all local references into to region and its subregions. + +This function will also correct all dirty LRCs. + +#### `try_close(reg)` + +Checks if the given region can be closed. If the LRC is dirty or subreagions are open, it will correct all dirty LRCs. + +Returns `True`, if the region is closed in the end, `False` otherwise. + +## Pragmas + +#### `pragma_disable_implicit_freezing()` + +Disables implicit freezing for the rest of the program. + ## Mermaid #### `mermaid_hide(obj, ..)` diff --git a/src/lang/interpreter.cc b/src/lang/interpreter.cc index 1e6f90c..f017053 100644 --- a/src/lang/interpreter.cc +++ b/src/lang/interpreter.cc @@ -287,6 +287,7 @@ namespace verona::interpreter // RC stays the same frame()->stack_push(old_var, "swapped value", false); + rt::move_reference(obj, frame()->object(), old_var); rt::move_reference(frame()->object(), obj, new_var); rt::remove_reference(frame()->object(), obj); rt::remove_reference(frame()->object(), key); diff --git a/src/rt/core/builtin.cc b/src/rt/core/builtin.cc index a99b969..59d6cce 100644 --- a/src/rt/core/builtin.cc +++ b/src/rt/core/builtin.cc @@ -239,7 +239,6 @@ namespace rt::core return std::nullopt; }); - // TODO: Document add_builtin("close", [](auto frame, auto args) { close_function_impl(frame, args, true); return std::nullopt; diff --git a/src/rt/objects/region.cc b/src/rt/objects/region.cc index ab4a9ae..e34a1ff 100644 --- a/src/rt/objects/region.cc +++ b/src/rt/objects/region.cc @@ -284,7 +284,7 @@ namespace rt::objects auto invalidate = dst_reg == to_close_reg; invalidate |= - (to_close_reg->sub_region_reference_count != 0 && + (to_close_reg && to_close_reg->sub_region_reference_count != 0 && Region::is_ancestor(dst_reg, to_close_reg)); if (invalidate) { @@ -334,13 +334,12 @@ namespace rt::objects bool Region::try_close() { - // TODO: Is this correct, or should it be the combined LRC? if (is_closed()) { return true; } - if (this->is_lrc_dirty) + if (this->is_lrc_dirty || this->sub_region_reference_count != 0) { clean_lrcs(); } diff --git a/src/rt/ui.h b/src/rt/ui.h index 5b55350..1d9e7c6 100644 --- a/src/rt/ui.h +++ b/src/rt/ui.h @@ -159,8 +159,8 @@ namespace rt::ui }; private: - /// Uses the local set to construct a reasonable set of roots, used for UI - /// methods that don't start from the local frame. + /// Uses the local region to construct a reasonable set of roots, used for + /// UI methods that don't start from the local frame. std::vector local_root_objects(); };