static void HandleBlockReturn(Vm vm) { var returnValue = vm.stack.PopTop (); var name = vm.stack.PopTop (); if (name.Kind != Value.Kinds.String) { vm.RaiseShovelError ("The name of a block must be a string."); } var namedBlockIndex = vm.FindNamedBlock (name.stringValue); if (vm.stack.Count > namedBlockIndex + 1) { vm.stack.RemoveRange (namedBlockIndex + 1, vm.stack.Count - namedBlockIndex - 1); } var namedBlock = vm.stack.Top ().NamedBlockValue; vm.stack.Push (returnValue); vm.programCounter = namedBlock.BlockEnd; vm.currentEnvironment = namedBlock.Environment; }
static void HandleBlockReturn(Vm vm) { var returnValue = vm.stack.PopTop (); var name = vm.stack.PopTop (); if (name.Kind != Value.Kinds.String) { vm.RaiseShovelError ("The name of a block must be a string."); } var namedBlockIndex = vm.FindNamedBlock (name.StringValue); if (vm.stack.Count > namedBlockIndex + 1) { for (var i = namedBlockIndex + 1; i < vm.stack.Count; i++) { if (vm.stack.Storage [i].Kind == Value.Kinds.ReturnAddress) { vm.stack.Storage [i].ReturnAddressValue.Environment.DecreaseUsesLocally (); } } vm.stack.RemoveRange (namedBlockIndex + 1, vm.stack.Count - namedBlockIndex - 1); } var namedBlock = vm.stack.Top ().NamedBlockValue; vm.stack.Push (returnValue); vm.programCounter = namedBlock.BlockEnd; vm.currentEnvironment = namedBlock.Environment; }