Skip to content

Commit

Permalink
Stop treating the stack as a contiguous array.
Browse files Browse the repository at this point in the history
With the switch to a deque, the stack is not a contiguous array
anymore. Avoid direct indexing and pointer arithmetic and instead use
the existing accessor functions.
  • Loading branch information
plietar committed Oct 13, 2020
1 parent 2767ece commit 7f16395
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/interpreter/vm.cc
Expand Up @@ -516,8 +516,9 @@ namespace verona::interpreter
header.argc);
}

size_t top = frame().base + frame().locals;
Value* values = &stack_[top - callspace + 1];
// Compute the base of the new "frame", relative to the current frame.
// We use this to copy these values into the message
size_t base = frame().locals - callspace;

// Prepare the cowns and the arguments for the method invocation.
std::vector<Value> args;
Expand All @@ -531,7 +532,7 @@ namespace verona::interpreter
// The rest are the cowns
for (size_t i = 0; i < cown_count; i++)
{
Value& v = values[i];
Value& v = read(Register(truncate<uint8_t>(base + 1 + i)));
trace("Capturing cown {:d}: {}", i, v);
check_type(v, Value::COWN);

Expand All @@ -547,7 +548,7 @@ namespace verona::interpreter
// The rest are the captured values
for (size_t i = 0; i < capture_count; i++)
{
Value& v = values[i + cown_count];
Value& v = read(Register(truncate<uint8_t>(base + 1 + cown_count + i)));
trace("Capturing variable {:d}: {}", i + cown_count, v);
args.push_back(std::move(v));
}
Expand Down

0 comments on commit 7f16395

Please sign in to comment.