Skip to content

Commit

Permalink
vm: If popCount == _stack.Count in ExitBlock, just clear the stack an…
Browse files Browse the repository at this point in the history
…d return
  • Loading branch information
PaddiM8 committed Dec 9, 2024
1 parent 154228a commit 53daa1c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/Std/Iteration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,12 @@ public static RuntimeGenerator Repeat(RuntimeObject item, RuntimeInteger? n = nu
public static RuntimeGenerator Reverse(IEnumerable<RuntimeObject> items)
=> new(items.Reverse());

[ElkFunction("reverseMut")]
public static void Reverse(RuntimeList items)
{
items.Values.Reverse();
}

/// <param name="items">All items</param>
/// <param name="count">The amount of items to skip from the left</param>
/// <returns>A generator for the first n items.</returns>
Expand Down
11 changes: 8 additions & 3 deletions src/Vm/InstructionExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,14 +655,19 @@ private void UnpackUpper(byte count)

private void ExitBlock(byte popCount)
{
if (_stack.Count == 1)
if (_stack.Count == popCount)
{
while (_stack.Any())
Pop();

return;
}

var returnValue = _stack.Pop();
var returnValue = _stack.PopObject() as RuntimeObject;
for (byte i = 0; i < popCount; i++)
Pop();

_stack.Push(returnValue);
_stack.Push(returnValue ?? RuntimeNil.Value);
}

private void Ret()
Expand Down

0 comments on commit 53daa1c

Please sign in to comment.