Skip to content

Commit

Permalink
Interpreter: Improve reference counting
Browse files Browse the repository at this point in the history
  • Loading branch information
xFrednet committed Oct 22, 2024
1 parent c256cc8 commit 6339dc5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/lang/interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ namespace verona::interpreter
{
std::string field{node->location().view()};
auto v = rt::get(frame(), field);
if (!v)
{
if (field == "True")
{
v = rt::get_true();
}
else if (field == "False")
{
rt::get_false();
}
}

rt::add_reference(frame(), v);
stack().push_back(v);
std::cout << "push " << v << std::endl;
Expand Down Expand Up @@ -308,6 +320,7 @@ namespace verona::interpreter
result = rt::get_false();
result_str = "false";
}
rt::add_reference(frame(), result);
stack().push_back(result);
std::cout << "push " << result << " (" << result_str << ")"
<< std::endl;
Expand All @@ -326,6 +339,7 @@ namespace verona::interpreter
{
auto v = pop("jump condition");
auto jump = (v == rt::get_false());
rt::remove_reference(frame(), v);
if (jump)
{
return ExecJump{node->location()};
Expand Down Expand Up @@ -442,7 +456,9 @@ namespace verona::interpreter
// Setup the new frame
for (size_t i = 0; i < func.arg_ctn; i++)
{
frame->stack.push_back(parent_frame->stack.back());
auto value = parent_frame->stack.back();
frame->stack.push_back(value);
rt::move_reference(parent_frame->frame, frame->frame, value);
parent_frame->stack.pop_back();
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/recursive_list.vpy
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ list = new_list()
region list

value = "x"

# Dyrona doesn't freeze shared objects automatically (yet)
# There is currently a bug, where the LRC gets incorrect, if "[String]" isn't frozen
proto = value["__proto__"]
freeze proto
drop proto

insert(list.head, {})
insert(list.head, {})
insert(list.head, value)
insert(list.head, {})
remove(list.head, value)

drop value
drop list

0 comments on commit 6339dc5

Please sign in to comment.