diff --git a/src/Std/Iteration.cs b/src/Std/Iteration.cs index 7aa1680..f00499c 100644 --- a/src/Std/Iteration.cs +++ b/src/Std/Iteration.cs @@ -601,6 +601,12 @@ public static RuntimeGenerator Repeat(RuntimeObject item, RuntimeInteger? n = nu public static RuntimeGenerator Reverse(IEnumerable items) => new(items.Reverse()); + [ElkFunction("reverseMut")] + public static void Reverse(RuntimeList items) + { + items.Values.Reverse(); + } + /// All items /// The amount of items to skip from the left /// A generator for the first n items. diff --git a/src/Vm/InstructionExecutor.cs b/src/Vm/InstructionExecutor.cs index 5dbc923..3b35757 100644 --- a/src/Vm/InstructionExecutor.cs +++ b/src/Vm/InstructionExecutor.cs @@ -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()