PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/IronPython_Main/Runtime/Microsoft.Dynamic/Interpreter/Instructions/DynamicSplatInstruction.cs

#
C# | 55 lines | 29 code | 9 blank | 17 comment | 0 complexity | 748ef2f2f2350598ebd4fe359a833c12 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
  6. * copy of the license can be found in the License.html file at the root of this distribution. If
  7. * you cannot locate the Apache License, Version 2.0, please send an email to
  8. * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. * by the terms of the Apache License, Version 2.0.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Runtime.CompilerServices;
  18. using System.Reflection;
  19. using Microsoft.Scripting.Utils;
  20. using Microsoft.Scripting.Ast;
  21. using Microsoft.Scripting.Runtime;
  22. namespace Microsoft.Scripting.Interpreter {
  23. /// <summary>
  24. /// Implements dynamic call site with many arguments. Wraps the arguments into <see cref="ArgumentArray"/>.
  25. /// </summary>
  26. internal sealed partial class DynamicSplatInstruction : Instruction {
  27. private readonly CallSite<Func<CallSite, ArgumentArray, object>> _site;
  28. private readonly int _argumentCount;
  29. internal DynamicSplatInstruction(int argumentCount, CallSite<Func<CallSite, ArgumentArray, object>> site) {
  30. _site = site;
  31. _argumentCount = argumentCount;
  32. }
  33. public override int ProducedStack { get { return 1; } }
  34. public override int ConsumedStack { get { return _argumentCount; } }
  35. public override int Run(InterpretedFrame frame) {
  36. int first = frame.StackIndex - _argumentCount;
  37. object ret = _site.Target(_site, new ArgumentArray(frame.Data, first, _argumentCount));
  38. frame.Data[first] = ret;
  39. frame.StackIndex = first + 1;
  40. return 1;
  41. }
  42. public override string ToString() {
  43. return "DynamicSplatInstruction(" + _site + ")";
  44. }
  45. }
  46. }