Skip to content

Commit

Permalink
Cleanup: PR preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
xFrednet committed Nov 7, 2024
1 parent 84557bf commit 54aadbb
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
24 changes: 23 additions & 1 deletion docs/builtin.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
Expand All @@ -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.

Expand All @@ -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, ..)`
Expand Down
1 change: 1 addition & 0 deletions src/lang/interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/rt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace rt::core

FrameObject() : objects::DynObject(framePrototypeObject()) {}

std::string& stack_name(int idx)
std::string& stack_name(size_t idx)
{
if (idx == stack_keys.size())
{
Expand Down
1 change: 0 additions & 1 deletion src/rt/core/builtin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/rt/objects/region.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "dyn_object.h"
#include "region_object.h"

#include <algorithm>

namespace rt::objects
{
Region* get_region(DynObject* obj)
Expand Down Expand Up @@ -284,7 +286,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)
{
Expand Down Expand Up @@ -334,13 +336,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();
}
Expand Down
14 changes: 8 additions & 6 deletions src/rt/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ namespace rt::ui
public:
virtual void output(std::vector<objects::DynObject*>&, std::string) {}

virtual void highlight(std::string, std::vector<objects::DynObject*>&) {};
virtual void highlight(std::string, std::vector<objects::DynObject*>&) {}

virtual void error(std::string){};
virtual void error(std::string, std::vector<objects::DynObject*>&) {};
virtual void error(std::string, std::vector<objects::Edge>&) {};
virtual void error(std::string) {}

virtual void error(std::string, std::vector<objects::DynObject*>&) {}

virtual void error(std::string, std::vector<objects::Edge>&) {}

virtual bool is_mermaid() = 0;
};
Expand Down Expand Up @@ -159,8 +161,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<objects::DynObject*> local_root_objects();
};

Expand Down

0 comments on commit 54aadbb

Please sign in to comment.