PageRenderTime 64ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 0ms

/DICK.B1/IronPython/Compiler/CompilationMode.cs

https://bitbucket.org/williamybs/uidipythontool
C# | 120 lines | 65 code | 22 blank | 33 comment | 2 complexity | f5b3d455096cfa2ee3b7d043ffd3edb4 MD5 | raw file
  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * This source code is subject to terms and conditions of the Microsoft Public License. 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 Microsoft Public License, 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 Microsoft Public License.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. #if !CLR2
  16. using MSAst = System.Linq.Expressions;
  17. #else
  18. using MSAst = Microsoft.Scripting.Ast;
  19. #endif
  20. using System;
  21. using System.Collections.Generic;
  22. using System.Dynamic;
  23. using System.Runtime.CompilerServices;
  24. using Microsoft.Scripting;
  25. using Microsoft.Scripting.Utils;
  26. using IronPython.Compiler.Ast;
  27. using IronPython.Runtime;
  28. namespace IronPython.Compiler {
  29. /// <summary>
  30. /// Specifies the compilation mode which will be used during the AST transformation
  31. /// </summary>
  32. [Serializable]
  33. internal abstract class CompilationMode {
  34. /// <summary>
  35. /// Compilation will proceed in a manner in which the resulting AST can be serialized to disk.
  36. /// </summary>
  37. public static readonly CompilationMode ToDisk = new ToDiskCompilationMode();
  38. /// <summary>
  39. /// Compilation will use a type and declare static fields for globals. The resulting type
  40. /// is uncollectible and therefore extended use of this will cause memory leaks.
  41. /// </summary>
  42. public static readonly CompilationMode Uncollectable = new UncollectableCompilationMode();
  43. /// <summary>
  44. /// Compilation will use an array for globals. The resulting code will be fully collectible
  45. /// and once all references are released will be collected.
  46. /// </summary>
  47. public static readonly CompilationMode Collectable = new CollectableCompilationMode();
  48. /// <summary>
  49. /// Compilation will force all global accesses to do a full lookup. This will also happen for
  50. /// any unbound local references. This is the slowest form of code generation and is only
  51. /// used for exec/eval code where we can run against an arbitrary dictionary.
  52. /// </summary>
  53. public static readonly CompilationMode Lookup = new LookupCompilationMode();
  54. public virtual ScriptCode MakeScriptCode(PythonAst ast) {
  55. return new RuntimeScriptCode(ast, ast.ModuleContext.GlobalContext);
  56. }
  57. public virtual MSAst.Expression GetConstant(object value) {
  58. return MSAst.Expression.Constant(value);
  59. }
  60. public virtual Type GetConstantType(object value) {
  61. if (value == null) {
  62. return typeof(object);
  63. }
  64. return value.GetType();
  65. }
  66. public virtual void PrepareScope(PythonAst ast, ReadOnlyCollectionBuilder<MSAst.ParameterExpression> locals, List<MSAst.Expression> init) {
  67. }
  68. public virtual Type DelegateType {
  69. get {
  70. return typeof(MSAst.Expression<Func<CodeContext, FunctionCode, object>>);
  71. }
  72. }
  73. public virtual UncollectableCompilationMode.ConstantInfo GetContext() {
  74. return null;
  75. }
  76. public virtual void PublishContext(CodeContext codeContext, UncollectableCompilationMode.ConstantInfo _contextInfo) {
  77. }
  78. public virtual MSAst.Expression/*!*/ Dynamic(DynamicMetaObjectBinder/*!*/ binder, Type/*!*/ retType, MSAst.Expression/*!*/ arg0) {
  79. return MSAst.Expression.Dynamic(binder, retType, arg0);
  80. }
  81. public virtual MSAst.Expression/*!*/ Dynamic(DynamicMetaObjectBinder/*!*/ binder, Type/*!*/ retType, MSAst.Expression/*!*/ arg0, MSAst.Expression/*!*/ arg1) {
  82. return MSAst.Expression.Dynamic(binder, retType, arg0, arg1);
  83. }
  84. public virtual MSAst.Expression/*!*/ Dynamic(DynamicMetaObjectBinder/*!*/ binder, Type/*!*/ retType, MSAst.Expression/*!*/ arg0, MSAst.Expression/*!*/ arg1, MSAst.Expression/*!*/ arg2) {
  85. return MSAst.Expression.Dynamic(binder, retType, arg0, arg1, arg2);
  86. }
  87. public virtual MSAst.Expression/*!*/ Dynamic(DynamicMetaObjectBinder/*!*/ binder, Type/*!*/ retType, MSAst.Expression/*!*/ arg0, MSAst.Expression/*!*/ arg1, MSAst.Expression/*!*/ arg2, MSAst.Expression/*!*/ arg3) {
  88. return MSAst.Expression.Dynamic(binder, retType, arg0, arg1, arg2, arg3);
  89. }
  90. public virtual MSAst.Expression/*!*/ Dynamic(DynamicMetaObjectBinder/*!*/ binder, Type/*!*/ retType, IList<MSAst.Expression/*!*/>/*!*/ args) {
  91. Assert.NotNull(binder, retType, args);
  92. Assert.NotNullItems(args);
  93. return MSAst.Expression.Dynamic(binder, retType, args);
  94. }
  95. public abstract MSAst.Expression GetGlobal(MSAst.Expression globalContext, int arrayIndex, PythonVariable variable, PythonGlobal global);
  96. public abstract MSAst.LambdaExpression ReduceAst(PythonAst instance, string name);
  97. }
  98. }