Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adds Windows 8 RC reference assemblies, implements delegate creator v…

…ia Expression Trees for Win8
  • Loading branch information...
commit 19afcac2d1a98c986c4845dd0dcffc6c4b9eea24 1 parent 8582506
@tmat tmat authored
Showing with 41,015 additions and 324 deletions.
  1. +36 −2 .gitignore
  2. +1 −1  Languages/IronPython/IronPython/Compiler/Ast/AstMethods.cs
  3. +1 −1  Languages/IronPython/IronPython/Runtime/FunctionCode.cs
  4. +2 −2 Languages/IronPython/IronPython/Runtime/PythonDynamicStackFrame.cs
  5. +44 −44 Languages/IronPython/IronPython/Runtime/Types/NewTypeMaker.cs
  6. +1 −1  Languages/IronPython/IronPython/Runtime/Types/PythonType.cs
  7. +38 −0 Languages/Ruby/IronRuby.Tests/DLR/ReflectionUtilsTests.cs
  8. +2 −0  Languages/Ruby/IronRuby.Tests/RubyTests.cs
  9. +2 −1  Languages/Ruby/IronRuby.Tests/Runtime/ClrTests.cs
  10. +2 −2 Languages/Ruby/Libraries/Builtins/ExceptionOps.cs
  11. +1 −1  Languages/Ruby/Libraries/Builtins/IoOps.cs
  12. +1 −1  Languages/Ruby/Ruby/Builtins/RubyClass.cs
  13. +2 −2 Languages/Ruby/Ruby/Compiler/Ast/AstFactory.cs
  14. +6 −6 Languages/Ruby/Ruby/Runtime/Calls/LibraryOverloadInfo.cs
  15. +1 −1  Languages/Ruby/Ruby/Runtime/Calls/RubyCustomMethodInfo.cs
  16. +1 −1  Languages/Ruby/Ruby/Runtime/Calls/RubyLambdaMethodInfo.cs
  17. +1 −1  Languages/Ruby/Ruby/Runtime/Calls/RubyMethodInfo.cs
  18. +2 −2 Languages/Ruby/Ruby/Runtime/RubyContext.cs
  19. +3 −3 Msi/{ → Ruby}/Installer.proj
  20. +1 −1  Runtime/Microsoft.Dynamic/Actions/ActionBinder.cs
  21. +1 −1  Runtime/Microsoft.Dynamic/Actions/Calls/ParamsDictArgBuilder.cs
  22. +1 −1  Runtime/Microsoft.Dynamic/Actions/Calls/ReferenceArgBuilder.cs
  23. +4 −4 Runtime/Microsoft.Dynamic/Actions/NamespaceTracker.cs
  24. +1 −1  Runtime/Microsoft.Dynamic/Actions/TypeGroup.cs
  25. +14 −0 Runtime/Microsoft.Dynamic/Actions/TypeTracker.cs
  26. +12 −12 Runtime/Microsoft.Dynamic/Ast/ConstantExpression.cs
  27. +2 −2 Runtime/Microsoft.Dynamic/Ast/LightExceptionRewriter.cs
  28. +1 −1  Runtime/Microsoft.Dynamic/Ast/LightThrowExpression.cs
  29. +2 −0  Runtime/Microsoft.Dynamic/Generation/CompilerHelpers.cs
  30. +2 −0  Runtime/Microsoft.Dynamic/Generation/DynamicILGen.cs
  31. +3 −0  Runtime/Microsoft.Dynamic/Generation/ILGen.cs
  32. +5 −0 Runtime/Microsoft.Dynamic/Generation/Snippets.cs
  33. +40 −40 Runtime/Microsoft.Dynamic/Interpreter/Instructions/CallInstruction.Generated.cs
  34. +3 −3 Runtime/Microsoft.Dynamic/Interpreter/Instructions/CallInstruction.cs
  35. +5 −1 Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs
  36. +1 −1  Runtime/Microsoft.Dynamic/Interpreter/LightLambda.cs
  37. +1 −1  Runtime/Microsoft.Dynamic/Runtime/ArgumentArray.cs
  38. +230 −71 Runtime/Microsoft.Dynamic/Runtime/DelegateInfo.cs
  39. +23 −20 Runtime/Microsoft.Dynamic/Runtime/DelegateSignatureInfo.cs
  40. +45 −20 Runtime/Microsoft.Dynamic/Runtime/DynamicDelegateCreator.cs
  41. +1 −1  Runtime/Microsoft.Dynamic/Runtime/LightExceptions.cs
  42. +29 −21 Runtime/Microsoft.Dynamic/Runtime/ReflectionCache.cs
  43. +3 −1 Runtime/Microsoft.Dynamic/Runtime/ReturnFixer.cs
  44. +57 −27 Runtime/Microsoft.Dynamic/Utils/ReflectionUtils.cs
  45. +1 −1  Runtime/Microsoft.Scripting/Runtime/DynamicOperations.Generated.cs
  46. +1 −9 Runtime/Microsoft.Scripting/Utils/ReflectionUtils.cs
  47. +1 −5 Solutions/Build.IronRuby.proj
  48. +7 −7 Solutions/Common.proj
  49. BIN  Util/References/Win8/Microsoft.CSharp.dll
  50. +192 −0 Util/References/Win8/Microsoft.CSharp.xml
  51. BIN  Util/References/Win8/Microsoft.VisualBasic.dll
  52. +969 −0 Util/References/Win8/Microsoft.VisualBasic.xml
  53. BIN  Util/References/Win8/System.Collections.Concurrent.dll
  54. +1,126 −0 Util/References/Win8/System.Collections.Concurrent.xml
  55. BIN  Util/References/Win8/System.Collections.dll
  56. +2,517 −0 Util/References/Win8/System.Collections.xml
  57. BIN  Util/References/Win8/System.ComponentModel.Annotations.dll
  58. +739 −0 Util/References/Win8/System.ComponentModel.Annotations.xml
  59. BIN  Util/References/Win8/System.ComponentModel.DataAnnotations.dll
  60. BIN  Util/References/Win8/System.ComponentModel.EventBasedAsync.dll
  61. +64 −0 Util/References/Win8/System.ComponentModel.EventBasedAsync.xml
  62. BIN  Util/References/Win8/System.ComponentModel.dll
  63. +50 −0 Util/References/Win8/System.ComponentModel.xml
  64. BIN  Util/References/Win8/System.Core.dll
  65. BIN  Util/References/Win8/System.Diagnostics.Contracts.dll
  66. +335 −0 Util/References/Win8/System.Diagnostics.Contracts.xml
  67. BIN  Util/References/Win8/System.Diagnostics.Debug.dll
  68. +211 −0 Util/References/Win8/System.Diagnostics.Debug.xml
  69. BIN  Util/References/Win8/System.Diagnostics.Tools.dll
  70. +56 −0 Util/References/Win8/System.Diagnostics.Tools.xml
  71. BIN  Util/References/Win8/System.Diagnostics.Tracing.dll
  72. +467 −0 Util/References/Win8/System.Diagnostics.Tracing.xml
  73. BIN  Util/References/Win8/System.Dynamic.Runtime.dll
  74. +1,142 −0 Util/References/Win8/System.Dynamic.Runtime.xml
  75. BIN  Util/References/Win8/System.Globalization.dll
  76. +1,650 −0 Util/References/Win8/System.Globalization.xml
  77. BIN  Util/References/Win8/System.IO.Compression.dll
  78. +433 −0 Util/References/Win8/System.IO.Compression.xml
  79. BIN  Util/References/Win8/System.IO.dll
  80. +2,105 −0 Util/References/Win8/System.IO.xml
  81. BIN  Util/References/Win8/System.Linq.Expressions.dll
  82. +3,928 −0 Util/References/Win8/System.Linq.Expressions.xml
  83. BIN  Util/References/Win8/System.Linq.Parallel.dll
  84. +2,457 −0 Util/References/Win8/System.Linq.Parallel.xml
  85. BIN  Util/References/Win8/System.Linq.Queryable.dll
  86. +1,282 −0 Util/References/Win8/System.Linq.Queryable.xml
  87. BIN  Util/References/Win8/System.Linq.dll
  88. +1,763 −0 Util/References/Win8/System.Linq.xml
  89. BIN  Util/References/Win8/System.Net.Http.Rtc.dll
  90. +17 −0 Util/References/Win8/System.Net.Http.Rtc.xml
  91. BIN  Util/References/Win8/System.Net.Http.dll
  92. +1,853 −0 Util/References/Win8/System.Net.Http.xml
  93. BIN  Util/References/Win8/System.Net.NetworkInformation.dll
  94. +28 −0 Util/References/Win8/System.Net.NetworkInformation.xml
  95. BIN  Util/References/Win8/System.Net.Primitives.dll
  96. +589 −0 Util/References/Win8/System.Net.Primitives.xml
  97. BIN  Util/References/Win8/System.Net.Requests.dll
  98. +648 −0 Util/References/Win8/System.Net.Requests.xml
  99. BIN  Util/References/Win8/System.Net.dll
  100. BIN  Util/References/Win8/System.Numerics.dll
  101. BIN  Util/References/Win8/System.ObjectModel.dll
  102. +713 −0 Util/References/Win8/System.ObjectModel.xml
  103. BIN  Util/References/Win8/System.Reflection.Context.dll
  104. +56 −0 Util/References/Win8/System.Reflection.Context.xml
  105. BIN  Util/References/Win8/System.Reflection.Extensions.dll
  106. +260 −0 Util/References/Win8/System.Reflection.Extensions.xml
  107. BIN  Util/References/Win8/System.Reflection.Primitives.dll
  108. +1,380 −0 Util/References/Win8/System.Reflection.Primitives.xml
  109. BIN  Util/References/Win8/System.Reflection.dll
  110. +1,093 −0 Util/References/Win8/System.Reflection.xml
  111. BIN  Util/References/Win8/System.Resources.ResourceManager.dll
  112. +78 −0 Util/References/Win8/System.Resources.ResourceManager.xml
  113. BIN  Util/References/Win8/System.Runtime.Extensions.dll
  114. +3,396 −0 Util/References/Win8/System.Runtime.Extensions.xml
  115. BIN  Util/References/Win8/System.Runtime.InteropServices.WindowsRuntime.dll
  116. +167 −0 Util/References/Win8/System.Runtime.InteropServices.WindowsRuntime.xml
  117. BIN  Util/References/Win8/System.Runtime.InteropServices.dll
  118. +4,405 −0 Util/References/Win8/System.Runtime.InteropServices.xml
  119. BIN  Util/References/Win8/System.Runtime.Numerics.dll
  120. +1,029 −0 Util/References/Win8/System.Runtime.Numerics.xml
  121. BIN  Util/References/Win8/System.Runtime.Serialization.Json.dll
  122. +128 −0 Util/References/Win8/System.Runtime.Serialization.Json.xml
  123. BIN  Util/References/Win8/System.Runtime.Serialization.Primitives.dll
  124. +180 −0 Util/References/Win8/System.Runtime.Serialization.Primitives.xml
  125. BIN  Util/References/Win8/System.Runtime.Serialization.Xml.dll
  126. +2,021 −0 Util/References/Win8/System.Runtime.Serialization.Xml.xml
  127. BIN  Util/References/Win8/System.Runtime.Serialization.dll
  128. BIN  Util/References/Win8/System.Runtime.WindowsRuntime.UI.Xaml.dll
  129. +844 −0 Util/References/Win8/System.Runtime.WindowsRuntime.UI.Xaml.xml
  130. BIN  Util/References/Win8/System.Runtime.WindowsRuntime.dll
Sorry, we could not display the entire diff because it was too big.
View
38 .gitignore
@@ -21,5 +21,39 @@ TestResult.xml
Solutions/TestResults/
Runtime/Samples/Hosting/Scenarios/bin/
-# TODO - testing scripts should not created this file here
-debug.log
+# TODO - testing scripts should not create these files
+debug.log
+External.LCA_RESTRICTED/Languages/IronPython/27/Lib/@test_2000_tmp1
+External.LCA_RESTRICTED/Languages/IronPython/27/Lib/@test_2000_tmp2
+External.LCA_RESTRICTED/Languages/IronPython/27/Lib/@test_2928_tmp/
+External.LCA_RESTRICTED/Languages/IronPython/27/Lib/@test_4044_tmp
+External.LCA_RESTRICTED/Languages/IronPython/27/Lib/@test_4500_tmp
+External.LCA_RESTRICTED/Languages/IronPython/27/Lib/@test_4500_tmp.1341096880.IOCASTE.4500
+External.LCA_RESTRICTED/Languages/IronPython/27/Lib/@test_4500_tmp.lock
+External.LCA_RESTRICTED/Languages/IronPython/27/Lib/@test_5992_tmp
+External.LCA_RESTRICTED/Languages/IronPython/27/Lib/@test_7680_tmp.dir
+External.LCA_RESTRICTED/Languages/IronPython/27/Lib/lib2to3/Grammar2.9.9.alpha.0.pickle
+External.LCA_RESTRICTED/Languages/IronPython/27/Lib/lib2to3/PatternGrammar2.9.9.alpha.0.pickle
+Languages/IronPython/Tests/ImportTestDir/
+Languages/IronPython/Tests/InheritanceTypes.dll
+Languages/IronPython/Tests/OutterDir/
+Languages/IronPython/Tests/another.py
+Languages/IronPython/Tests/cached_type_dll.dll
+Languages/IronPython/Tests/cp7007/
+Languages/IronPython/Tests/finaltest.dll
+Languages/IronPython/Tests/foo
+Languages/IronPython/Tests/imfpstart.tpy
+Languages/IronPython/Tests/impcp13736.py
+Languages/IronPython/Tests/impmodfrmpkg/
+Languages/IronPython/Tests/onlyread.tmp
+Languages/IronPython/Tests/onlywrite.tmp
+Languages/IronPython/Tests/tempFile1.tpy
+Languages/IronPython/Tests/temp_syspath_none.py
+Languages/IronPython/Tests/test.dll
+Languages/IronPython/Tests/test.pyil
+Languages/IronPython/Tests/test.xaml
+Languages/IronPython/Tests/testfile.tmp
+Languages/IronPython/Tests/testilcode.dll
+Languages/IronPython/Tests/the_dir/
+Languages/IronPython/Tests/vbproptest0.159422.dll
+Languages/IronPython/Tests/vbproptest0.999147.dll
View
2  Languages/IronPython/IronPython/Compiler/Ast/AstMethods.cs
@@ -103,7 +103,7 @@ static class AstMethods {
public static readonly MethodInfo GeneratorCheckThrowableAndReturnSendValue = GetMethod((Func<object, object>)PythonOps.GeneratorCheckThrowableAndReturnSendValue);
private static MethodInfo GetMethod(Delegate x) {
- return x.GetMethod();
+ return x.GetMethodInfo();
}
}
}
View
2  Languages/IronPython/IronPython/Runtime/FunctionCode.cs
@@ -579,7 +579,7 @@ public class FunctionCode : IExpressionSerializable {
throw PythonOps.TypeError("cannot exec code object that contains free variables: {0}", co_freevars.__repr__(context));
}
- if (Target == null || (Target.GetMethod() != null && Target.GetMethod().DeclaringType == typeof(PythonCallTargets))) {
+ if (Target == null || (Target.GetMethodInfo() != null && Target.GetMethodInfo().DeclaringType == typeof(PythonCallTargets))) {
UpdateDelegate(context.LanguageContext, true);
}
View
4 Languages/IronPython/IronPython/Runtime/PythonDynamicStackFrame.cs
@@ -45,9 +45,9 @@ public PythonDynamicStackFrame(CodeContext/*!*/ context, FunctionCode/*!*/ funcC
MethodBase method;
Debug.Assert(funcCode._normalDelegate != null || funcCode._tracingDelegate != null);
if (!context.LanguageContext.EnableTracing || funcCode._tracingDelegate == null) {
- method = funcCode._normalDelegate.GetMethod();
+ method = funcCode._normalDelegate.GetMethodInfo();
} else {
- method = funcCode._tracingDelegate.GetMethod();
+ method = funcCode._tracingDelegate.GetMethodInfo();
}
return method;
}
View
88 Languages/IronPython/IronPython/Runtime/Types/NewTypeMaker.cs
@@ -1546,6 +1546,50 @@ sealed class NewTypeMaker {
}
return sig;
}
+
+ /// <summary>
+ /// Same as the DLR ReturnFixer, but accepts lower level constructs,
+ /// such as LocalBuilder, ParameterInfos and ILGen.
+ /// </summary>
+ private sealed class ReturnFixer {
+ private readonly ParameterInfo _parameter;
+ private readonly LocalBuilder _reference;
+ private readonly int _index;
+
+ private ReturnFixer(LocalBuilder reference, ParameterInfo parameter, int index) {
+ Debug.Assert(reference.LocalType.IsGenericType() && reference.LocalType.GetGenericTypeDefinition() == typeof(StrongBox<>));
+ Debug.Assert(parameter.ParameterType.IsByRef);
+
+ _parameter = parameter;
+ _reference = reference;
+ _index = index;
+ }
+
+ public void FixReturn(ILGen il) {
+ il.EmitLoadArg(_index);
+ il.Emit(OpCodes.Ldloc, _reference);
+ il.EmitFieldGet(_reference.LocalType.GetDeclaredField("Value"));
+ il.EmitStoreValueIndirect(_parameter.ParameterType.GetElementType());
+ }
+
+ public static ReturnFixer EmitArgument(ILGen il, ParameterInfo parameter, int index) {
+ il.EmitLoadArg(index);
+ if (parameter.ParameterType.IsByRef) {
+ Type elementType = parameter.ParameterType.GetElementType();
+ Type concreteType = typeof(StrongBox<>).MakeGenericType(elementType);
+ LocalBuilder refSlot = il.DeclareLocal(concreteType);
+ il.EmitLoadValueIndirect(elementType);
+ ConstructorInfo ci = concreteType.GetConstructor(new Type[] { elementType });
+ il.Emit(OpCodes.Newobj, ci);
+ il.Emit(OpCodes.Stloc, refSlot);
+ il.Emit(OpCodes.Ldloc, refSlot);
+ return new ReturnFixer(refSlot, parameter, index);
+ } else {
+ il.EmitBoxing(parameter.ParameterType);
+ return null;
+ }
+ }
+ }
#endif
#endregion
@@ -1789,48 +1833,4 @@ sealed class NewTypeMaker {
#endregion
}
-
- /// <summary>
- /// Same as the DLR ReturnFixer, but accepts lower level constructs,
- /// such as LocalBuilder, ParameterInfos and ILGen.
- /// </summary>
- sealed class ReturnFixer {
- private readonly ParameterInfo _parameter;
- private readonly LocalBuilder _reference;
- private readonly int _index;
-
- private ReturnFixer(LocalBuilder reference, ParameterInfo parameter, int index) {
- Debug.Assert(reference.LocalType.IsGenericType() && reference.LocalType.GetGenericTypeDefinition() == typeof(StrongBox<>));
- Debug.Assert(parameter.ParameterType.IsByRef);
-
- _parameter = parameter;
- _reference = reference;
- _index = index;
- }
-
- public void FixReturn(ILGen il) {
- il.EmitLoadArg(_index);
- il.Emit(OpCodes.Ldloc, _reference);
- il.EmitFieldGet(_reference.LocalType.GetDeclaredField("Value"));
- il.EmitStoreValueIndirect(_parameter.ParameterType.GetElementType());
- }
-
- public static ReturnFixer EmitArgument(ILGen il, ParameterInfo parameter, int index) {
- il.EmitLoadArg(index);
- if (parameter.ParameterType.IsByRef) {
- Type elementType = parameter.ParameterType.GetElementType();
- Type concreteType = typeof(StrongBox<>).MakeGenericType(elementType);
- LocalBuilder refSlot = il.DeclareLocal(concreteType);
- il.EmitLoadValueIndirect(elementType);
- ConstructorInfo ci = concreteType.GetConstructor(new Type[] { elementType });
- il.Emit(OpCodes.Newobj, ci);
- il.Emit(OpCodes.Stloc, refSlot);
- il.Emit(OpCodes.Ldloc, refSlot);
- return new ReturnFixer(refSlot, parameter, index);
- } else {
- il.EmitBoxing(parameter.ParameterType);
- return null;
- }
- }
- }
}
View
2  Languages/IronPython/IronPython/Runtime/Types/PythonType.cs
@@ -784,7 +784,7 @@ internal PythonType(PythonContext context, PythonType[] baseTypes, Type underlyi
}
public static implicit operator TypeTracker(PythonType self) {
- return ReflectionCache.GetTypeTracker(self.UnderlyingSystemType);
+ return TypeTracker.GetTypeTracker(self.UnderlyingSystemType);
}
#endregion
View
38 Languages/Ruby/IronRuby.Tests/DLR/ReflectionUtilsTests.cs
@@ -17,6 +17,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
+using Microsoft.Scripting.Runtime;
using Microsoft.Scripting.Utils;
namespace IronRuby.Tests {
@@ -302,5 +303,42 @@ public abstract class GetMembers<T> where T : GetMembers_A {
var gp_actual = gp.GetInheritedMembers();
AreSetsEqual(gp_actual.Select(m => m.ToString()), gp_expected.Select(m => m.ToString()));
}
+
+ public delegate int FRefIntIntOutInt(ref int a, int b, out int c);
+
+ public delegate int FIntIntInt(int a, int b);
+
+ public void DelegateInfo1() {
+ object lambda = Engine.Execute("lambda { |a,b| a + b }");
+
+ var creator = new DynamicDelegateCreator(Context);
+ var d1a = (Func<int, int, int>)creator.GetDelegate(lambda, typeof(Func<int, int, int>));
+ var d1b = (Func<int, int, int>)creator.GetDelegate(lambda, typeof(Func<int, int, int>));
+ var d2 = (FIntIntInt)creator.GetDelegate(lambda, typeof(FIntIntInt));
+ Assert(d1a == d1b);
+
+ int r1 = d1a(1, 2);
+ int r2 = d2(10, 20);
+
+ Assert(r1 == 3);
+ Assert(r2 == 30);
+ }
+
+ public void DelegateInfo2() {
+ object lambda = Engine.Execute("lambda { |a,b,c| r = a.value + b; a.value = 1; c.value = 10; r }");
+
+ var creator = new DynamicDelegateCreator(Context);
+ var da = (FRefIntIntOutInt)creator.GetDelegate(lambda, typeof(FRefIntIntOutInt));
+ var db = (FRefIntIntOutInt)creator.GetDelegate(lambda, typeof(FRefIntIntOutInt));
+ Assert(da == db);
+
+ int a = 2;
+ int c = 3;
+ int r = da(ref a, 3, out c);
+
+ Assert(r == 5);
+ Assert(a == 1);
+ Assert(c == 10);
+ }
}
}
View
2  Languages/Ruby/IronRuby.Tests/RubyTests.cs
@@ -62,6 +62,8 @@ public partial class Tests {
TypeMemberCache,
ReflectionUtils_GetMembers,
+ DelegateInfo1,
+ DelegateInfo2,
Scenario_ParserLogging,
Parser1,
View
3  Languages/Ruby/IronRuby.Tests/Runtime/ClrTests.cs
@@ -28,6 +28,7 @@
using Microsoft.Scripting.Math;
using Microsoft.Scripting.Runtime;
using Microsoft.Scripting.Utils;
+using Microsoft.Scripting.Actions;
#if !CLR2
using BigInt = System.Numerics.BigInteger;
@@ -1780,7 +1781,7 @@ p Inst.clr_member(InterfaceFoo2, :[]).call(1)
/// </summary>
public void ClrTypes1() {
TestTypeAndTracker(typeof(ClassWithMethods1));
- TestTypeAndTracker(ReflectionCache.GetTypeTracker(typeof(ClassWithMethods1)));
+ TestTypeAndTracker(TypeTracker.GetTypeTracker(typeof(ClassWithMethods1)));
}
public void TestTypeAndTracker(object type) {
View
4 Languages/Ruby/Libraries/Builtins/ExceptionOps.cs
@@ -140,13 +140,13 @@ public static class ExceptionOps {
// RubyOps.MarkException(new <exception-type>(GetClrMessage(<class>, #message = <message>)))
if (cls.BuildAllocatorCall(metaBuilder, args, () =>
- Ast.Call(null, new Func<RubyClass, object, string>(GetClrMessage).GetMethod(),
+ Ast.Call(null, new Func<RubyClass, object, string>(GetClrMessage).GetMethodInfo(),
classExpression,
Ast.Assign(messageVariable = metaBuilder.GetTemporary(typeof(object), "#message"), AstUtils.Box(argsBuilder[0]))
)
)) {
// ReinitializeException(<result>, #message)
- metaBuilder.Result = Ast.Call(null, new Func<RubyContext, Exception, object, Exception>(ReinitializeException).GetMethod(),
+ metaBuilder.Result = Ast.Call(null, new Func<RubyContext, Exception, object, Exception>(ReinitializeException).GetMethodInfo(),
AstUtils.Convert(args.MetaContext.Expression, typeof(RubyContext)),
metaBuilder.Result,
messageVariable ?? AstUtils.Box(argsBuilder[0])
View
2  Languages/Ruby/Libraries/Builtins/IoOps.cs
@@ -250,7 +250,7 @@ public static class WaitWritable {
metaBuilder.BfcVariable = metaBuilder.GetTemporary(typeof(BlockParam), "#bfc");
}
- metaBuilder.Result = Ast.Call(new Func<UnaryOpStorage, BlockParam, object, object>(InvokeOpenBlock).GetMethod(),
+ metaBuilder.Result = Ast.Call(new Func<UnaryOpStorage, BlockParam, object, object>(InvokeOpenBlock).GetMethodInfo(),
Ast.Constant(new UnaryOpStorage(args.RubyContext)),
metaBuilder.BfcVariable,
metaBuilder.Result
View
2  Languages/Ruby/Ruby/Builtins/RubyClass.cs
@@ -1401,7 +1401,7 @@ private sealed class ClrOverloadInfo {
} else if (_structInfo != null) {
constructionOverloads = new OverloadInfo[] { new ReflectionOverloadInfo(Methods.CreateStructInstance) };
} else if (_factories.Length != 0) {
- constructionOverloads = ArrayUtils.ConvertAll(_factories, (d) => new ReflectionOverloadInfo(d.GetMethod()));
+ constructionOverloads = ArrayUtils.ConvertAll(_factories, (d) => new ReflectionOverloadInfo(d.GetMethodInfo()));
} else {
// TODO: handle protected constructors
constructionOverloads = GetConstructors(type == typeof(object) ? typeof(RubyObject) : type).ToArray();
View
4 Languages/Ruby/Ruby/Compiler/Ast/AstFactory.cs
@@ -105,7 +105,7 @@ public static class AstFactory {
}
internal static MSA.Expression/*!*/ CallDelegate(Delegate/*!*/ method, MSA.Expression[]/*!*/ arguments) {
- MethodInfo methodInfo = method.GetMethod();
+ MethodInfo methodInfo = method.GetMethodInfo();
// We prefer to peek inside the delegate and call the target method directly. However, we need to
// exclude DynamicMethods since Delegate.Method returns a dummy MethodInfo, and we cannot emit a call to it.
@@ -117,7 +117,7 @@ public static class AstFactory {
if (method.Target != null) {
// inline a closed static delegate:
if (methodInfo.IsStatic) {
- return Ast.Call(null, method.GetMethod(), ArrayUtils.Insert(AstUtils.Constant(method.Target), arguments));
+ return Ast.Call(null, method.GetMethodInfo(), ArrayUtils.Insert(AstUtils.Constant(method.Target), arguments));
}
// inline a closed instance delegate:
View
12 Languages/Ruby/Ruby/Runtime/Calls/LibraryOverloadInfo.cs
@@ -99,23 +99,23 @@ public abstract class LibraryOverload : OverloadInfo {
}
internal static LibraryOverload/*!*/ Reflect(Delegate/*!*/ overloadDelegate) {
- return Create(overloadDelegate, EncodeCustomAttributes(overloadDelegate.GetMethod()));
+ return Create(overloadDelegate, EncodeCustomAttributes(overloadDelegate.GetMethodInfo()));
}
public override MethodBase ReflectionInfo {
- get { return _delegate.GetMethod(); }
+ get { return _delegate.GetMethodInfo(); }
}
public override Type ReturnType {
- get { return _delegate.GetMethod().ReturnType; }
+ get { return _delegate.GetMethodInfo().ReturnType; }
}
public override ParameterInfo/*!*/ ReturnParameter {
- get { return _delegate.GetMethod().ReturnParameter; }
+ get { return _delegate.GetMethodInfo().ReturnParameter; }
}
public override Type/*!*/ DeclaringType {
- get { return _delegate.GetMethod().DeclaringType; }
+ get { return _delegate.GetMethodInfo().DeclaringType; }
}
// name is irrelevant for library methods
@@ -124,7 +124,7 @@ public abstract class LibraryOverload : OverloadInfo {
}
public override IList<ParameterInfo>/*!*/ Parameters {
- get { return _parameters ?? (_parameters = new ReadOnlyCollection<ParameterInfo>(_delegate.GetMethod().GetParameters())); }
+ get { return _parameters ?? (_parameters = new ReadOnlyCollection<ParameterInfo>(_delegate.GetMethodInfo().GetParameters())); }
}
public override bool IsParamArray(int parameterIndex) {
View
2  Languages/Ruby/Ruby/Runtime/Calls/RubyCustomMethodInfo.cs
@@ -40,7 +40,7 @@ public RubyCustomMethodInfo(RuleGenerator/*!*/ ruleGenerator, RubyMemberFlags fl
}
public override MemberInfo/*!*/[]/*!*/ GetMembers() {
- return new MemberInfo[] { _ruleGenerator.GetMethod() };
+ return new MemberInfo[] { _ruleGenerator.GetMethodInfo() };
}
public override RubyMemberInfo TrySelectOverload(Type/*!*/[]/*!*/ parameterTypes) {
View
2  Languages/Ruby/Ruby/Runtime/Calls/RubyLambdaMethodInfo.cs
@@ -65,7 +65,7 @@ internal RubyLambdaMethodInfo(Proc/*!*/ block, string/*!*/ definitionName, RubyM
}
public override MemberInfo/*!*/[]/*!*/ GetMembers() {
- return new MemberInfo[] { _lambda.Dispatcher.Method.GetMethod() };
+ return new MemberInfo[] { _lambda.Dispatcher.Method.GetMethodInfo() };
}
protected internal override RubyMemberInfo/*!*/ Copy(RubyMemberFlags flags, RubyModule/*!*/ module) {
View
2  Languages/Ruby/Ruby/Runtime/Calls/RubyMethodInfo.cs
@@ -67,7 +67,7 @@ internal RubyMethodInfo(RubyMethodBody/*!*/ body, RubyScope/*!*/ declaringScope,
}
public override MemberInfo/*!*/[]/*!*/ GetMembers() {
- return new MemberInfo[] { GetDelegate().GetMethod() };
+ return new MemberInfo[] { GetDelegate().GetMethodInfo() };
}
public override int GetArity() {
View
4 Languages/Ruby/Ruby/Runtime/RubyContext.cs
@@ -716,7 +716,7 @@ public RubyContext(ScriptDomainManager/*!*/ manager, IDictionary<string, object>
//
// only Object should expose CLR methods:
- TypeTracker objectTracker = ReflectionCache.GetTypeTracker(typeof(object));
+ TypeTracker objectTracker = TypeTracker.GetTypeTracker(typeof(object));
var moduleFactories = new Delegate[] {
new Func<RubyScope, BlockParam, RubyClass, object>(RubyModule.CreateAnonymousModule),
@@ -1366,7 +1366,7 @@ public RubyContext(ScriptDomainManager/*!*/ manager, IDictionary<string, object>
}
private static TypeTracker GetLibraryModuleTypeTracker(Type/*!*/ type, ModuleRestrictions restrictions) {
- return (restrictions & ModuleRestrictions.NoUnderlyingType) != 0 ? null : ReflectionCache.GetTypeTracker(type);
+ return (restrictions & ModuleRestrictions.NoUnderlyingType) != 0 ? null : TypeTracker.GetTypeTracker(type);
}
#endregion
View
6 Msi/Installer.proj → Msi/Ruby/Installer.proj
@@ -6,11 +6,11 @@
</PropertyGroup>
<ItemGroup>
<!-- Needed to be built ahead of time for the MSIs to include the Silverlight binaries -->
- <ProjectToBuild Include="..\Solutions\Dlr.sln">
+ <ProjectToBuild Include="..\..\Solutions\Dlr.sln">
<Properties>Configuration=Silverlight4$(Configuration)</Properties>
</ProjectToBuild>
<!-- It looks like the IronPython installer has been rewritten as a seperate wixproj... -->
- <ProjectToBuild Include="Ruby\Msi\IronRuby.Msi.wproj">
+ <ProjectToBuild Include="Msi\IronRuby.Msi.wproj">
<Properties>Configuration=$(Configuration);TreatWarningsAsErrors=false</Properties>
</ProjectToBuild>
</ItemGroup>
@@ -19,7 +19,7 @@
<MSBuild Projects="@(ProjectToBuild)"/>
</Target>
<Target Name="Rebuild">
- <!-- WiX deosn't clean up properly -->
+ <!-- WiX doesn't clean up properly -->
<RemoveDir Directories="
IronStudio\obj;
Python\Msi\obj;
View
2  Runtime/Microsoft.Dynamic/Actions/ActionBinder.cs
@@ -293,7 +293,7 @@ public abstract class ActionBinder {
public virtual ErrorInfo MakeConversionError(Type toType, Expression value) {
return ErrorInfo.FromException(
Expression.Call(
- new Func<Type, object, Exception>(ScriptingRuntimeHelpers.CannotConvertError).GetMethod(),
+ new Func<Type, object, Exception>(ScriptingRuntimeHelpers.CannotConvertError).GetMethodInfo(),
AstUtils.Constant(toType),
AstUtils.Convert(value, typeof(object))
)
View
2  Runtime/Microsoft.Dynamic/Actions/Calls/ParamsDictArgBuilder.cs
@@ -61,7 +61,7 @@ public ParamsDictArgBuilder(ParameterInfo info, int argIndex, string[] names, in
Type dictType = ParameterInfo.ParameterType;
return Ast.Call(
- GetCreationDelegate(dictType).GetMethod(),
+ GetCreationDelegate(dictType).GetMethodInfo(),
Ast.NewArrayInit(typeof(string), ConstantNames()),
AstUtils.NewArrayHelper(typeof(object), GetParameters(args, hasBeenUsed))
);
View
2  Runtime/Microsoft.Dynamic/Actions/Calls/ReferenceArgBuilder.cs
@@ -75,7 +75,7 @@ public ReferenceArgBuilder(ParameterInfo info, Type elementType, Type strongBox,
),
Expression.Throw(
Expression.Call(
- new Func<Type, object, Exception>(RuntimeHelpers.MakeIncorrectBoxTypeError).GetMethod(),
+ new Func<Type, object, Exception>(RuntimeHelpers.MakeIncorrectBoxTypeError).GetMethodInfo(),
AstUtils.Constant(_elementType),
AstUtils.Convert(arg, typeof(object))
),
View
8 Runtime/Microsoft.Dynamic/Actions/NamespaceTracker.cs
@@ -140,7 +140,7 @@ public class NamespaceTracker : MemberTracker, IMembersList, IEnumerable<KeyValu
_dict[normalizedTypeName] = MemberTracker.FromMemberInfo(newType.GetTypeInfo());
} else {
// Unify the new type with the existing type
- _dict[normalizedTypeName] = TypeGroup.UpdateTypeEntity(existingTypeEntity, ReflectionCache.GetTypeTracker(newType));
+ _dict[normalizedTypeName] = TypeGroup.UpdateTypeEntity(existingTypeEntity, TypeTracker.GetTypeTracker(newType));
}
}
}
@@ -240,7 +240,7 @@ public class NamespaceTracker : MemberTracker, IMembersList, IEnumerable<KeyValu
}
// We dont use TypeCollision.UpdateTypeEntity here because we do not handle generic type names
- return ReflectionCache.GetTypeTracker(type);
+ return TypeTracker.GetTypeTracker(type);
}
return null;
@@ -411,7 +411,7 @@ internal class TypeNames {
if (_simpleTypeNames.Contains(normalizedTypeName)) {
Type newType = LoadType(_assembly, GetFullChildName(normalizedTypeName));
if (newType != null) {
- existingTypeEntity = TypeGroup.UpdateTypeEntity(existingTypeEntity, ReflectionCache.GetTypeTracker(newType));
+ existingTypeEntity = TypeGroup.UpdateTypeEntity(existingTypeEntity, TypeTracker.GetTypeTracker(newType));
}
}
@@ -421,7 +421,7 @@ internal class TypeNames {
foreach (string actualName in actualNames) {
Type newType = LoadType(_assembly, GetFullChildName(actualName));
if (newType != null) {
- existingTypeEntity = TypeGroup.UpdateTypeEntity(existingTypeEntity, ReflectionCache.GetTypeTracker(newType));
+ existingTypeEntity = TypeGroup.UpdateTypeEntity(existingTypeEntity, TypeTracker.GetTypeTracker(newType));
}
}
}
View
2  Runtime/Microsoft.Dynamic/Actions/TypeGroup.cs
@@ -101,7 +101,7 @@ public sealed class TypeGroup : TypeTracker {
if (!_typesByArity.TryGetValue(arity, out typeWithMatchingArity)) {
return null;
}
- return ReflectionCache.GetTypeTracker(typeWithMatchingArity);
+ return TypeTracker.GetTypeTracker(typeWithMatchingArity);
}
/// <param name="existingTypeEntity">The merged list so far. Could be null</param>
View
14 Runtime/Microsoft.Dynamic/Actions/TypeTracker.cs
@@ -73,5 +73,19 @@ public abstract class TypeTracker : MemberTracker, IMembersList {
}
return tracker.Type;
}
+
+ private static readonly Dictionary<Type, TypeTracker> _typeCache = new Dictionary<Type, TypeTracker>();
+
+ public static TypeTracker GetTypeTracker(Type type) {
+ TypeTracker res;
+
+ lock (_typeCache) {
+ if (!_typeCache.TryGetValue(type, out res)) {
+ _typeCache[type] = res = new NestedTypeTracker(type);
+ }
+ }
+
+ return res;
+ }
}
}
View
24 Runtime/Microsoft.Dynamic/Ast/ConstantExpression.cs
@@ -116,7 +116,7 @@ public static partial class Utils {
int ival;
if (value.AsInt32(out ival)) {
return Expression.Call(
- new Func<int, BigInteger>(BigInteger.Create).GetMethod(),
+ new Func<int, BigInteger>(BigInteger.Create).GetMethodInfo(),
Constant(ival)
);
}
@@ -124,7 +124,7 @@ public static partial class Utils {
long lval;
if (value.AsInt64(out lval)) {
return Expression.Call(
- new Func<long, BigInteger>(BigInteger.Create).GetMethod(),
+ new Func<long, BigInteger>(BigInteger.Create).GetMethodInfo(),
Constant(lval)
);
}
@@ -137,7 +137,7 @@ public static partial class Utils {
);
#else
return Expression.Call(
- new Func<bool, byte[], BigInteger>(CompilerHelpers.CreateBigInteger).GetMethod(),
+ new Func<bool, byte[], BigInteger>(CompilerHelpers.CreateBigInteger).GetMethodInfo(),
Constant(value.Sign < 0),
CreateArray<byte>(value.Abs().ToByteArray())
);
@@ -147,7 +147,7 @@ public static partial class Utils {
int ival;
if (value.AsInt32(out ival)) {
return Expression.Call(
- new Func<int, BigInt>(CompilerHelpers.CreateBigInt).GetMethod(),
+ new Func<int, BigInt>(CompilerHelpers.CreateBigInt).GetMethodInfo(),
Constant(ival)
);
}
@@ -155,13 +155,13 @@ public static partial class Utils {
long lval;
if (value.AsInt64(out lval)) {
return Expression.Call(
- new Func<long, BigInt>(CompilerHelpers.CreateBigInt).GetMethod(),
+ new Func<long, BigInt>(CompilerHelpers.CreateBigInt).GetMethodInfo(),
Constant(lval)
);
}
return Expression.Call(
- new Func<bool, byte[], BigInt>(CompilerHelpers.CreateBigInt).GetMethod(),
+ new Func<bool, byte[], BigInt>(CompilerHelpers.CreateBigInt).GetMethodInfo(),
Constant(value.Sign < 0),
CreateArray<byte>(value.Abs().ToByteArray())
);
@@ -182,19 +182,19 @@ public static partial class Utils {
if (value.Real != 0.0) {
if (value.Imaginary() != 0.0) {
return Expression.Call(
- new Func<double, double, Complex>(MathUtils.MakeComplex).GetMethod(),
+ new Func<double, double, Complex>(MathUtils.MakeComplex).GetMethodInfo(),
Constant(value.Real),
Constant(value.Imaginary())
);
} else {
return Expression.Call(
- new Func<double, Complex>(MathUtils.MakeReal).GetMethod(),
+ new Func<double, Complex>(MathUtils.MakeReal).GetMethodInfo(),
Constant(value.Real)
);
}
} else {
return Expression.Call(
- new Func<double, Complex>(MathUtils.MakeImaginary).GetMethod(),
+ new Func<double, Complex>(MathUtils.MakeImaginary).GetMethodInfo(),
Constant(value.Imaginary())
);
}
@@ -205,19 +205,19 @@ public static partial class Utils {
if (value.Real != 0.0) {
if (value.Imag != 0.0) {
return Expression.Call(
- new Func<double, double, Complex64>(Complex64.Make).GetMethod(),
+ new Func<double, double, Complex64>(Complex64.Make).GetMethodInfo(),
Constant(value.Real),
Constant(value.Imag)
);
} else {
return Expression.Call(
- new Func<double, Complex64>(Complex64.MakeReal).GetMethod(),
+ new Func<double, Complex64>(Complex64.MakeReal).GetMethodInfo(),
Constant(value.Real)
);
}
} else {
return Expression.Call(
- new Func<double, Complex64>(Complex64.MakeImaginary).GetMethod(),
+ new Func<double, Complex64>(Complex64.MakeImaginary).GetMethodInfo(),
Constant(value.Imag)
);
}
View
4 Runtime/Microsoft.Dynamic/Ast/LightExceptionRewriter.cs
@@ -42,8 +42,8 @@ class LightExceptionRewriter : DynamicExpressionVisitor {
private static readonly ParameterExpression _lastValue = Expression.Parameter(typeof(object), "$lastValue");
private static readonly ReadOnlyCollection<ParameterExpression> _lastValueParamArray = new ReadOnlyCollectionBuilder<ParameterExpression>(1) { _lastValue }.ToReadOnlyCollection();
- private static readonly Expression _isLightExExpr = Expression.Call(new Func<Exception, bool>(LightExceptions.IsLightException).GetMethod(), _lastValue);
- private static readonly Expression _lastException = Expression.Call(new Func<object, Exception>(LightExceptions.GetLightException).GetMethod(), _lastValue);
+ private static readonly Expression _isLightExExpr = Expression.Call(new Func<Exception, bool>(LightExceptions.IsLightException).GetMethodInfo(), _lastValue);
+ private static readonly Expression _lastException = Expression.Call(new Func<object, Exception>(LightExceptions.GetLightException).GetMethodInfo(), _lastValue);
private readonly LabelTarget _returnLabel = Expression.Label(typeof(object), GetEhLabelName("ehUnwind"));
#if DEBUG
private static int _curLabel;
View
2  Runtime/Microsoft.Dynamic/Ast/LightThrowExpression.cs
@@ -36,7 +36,7 @@ namespace Microsoft.Scripting.Ast {
/// </summary>
class LightThrowExpression : Expression {
private readonly Expression _exception;
- private static MethodInfo _throw = new Func<Exception, object>(LightExceptions.Throw).GetMethod();
+ private static MethodInfo _throw = new Func<Exception, object>(LightExceptions.Throw).GetMethodInfo();
public LightThrowExpression(Expression exception) {
_exception = exception;
View
2  Runtime/Microsoft.Dynamic/Generation/CompilerHelpers.cs
@@ -807,6 +807,7 @@ private sealed class DebuggableCodeRewriter : DynamicExpressionVisitor {
return "lambda_method" + "$" + System.Threading.Interlocked.Increment(ref _Counter);
}
+#if FEATURE_LCG
// Matches ILGen.TryEmitConstant
public static bool CanEmitConstant(object value, Type type) {
if (value == null || CanEmitILConstant(type)) {
@@ -847,6 +848,7 @@ private sealed class DebuggableCodeRewriter : DynamicExpressionVisitor {
}
return false;
}
+#endif
/// <summary>
/// Reduces the provided DynamicExpression into site.Target(site, *args).
View
2  Runtime/Microsoft.Dynamic/Generation/DynamicILGen.cs
@@ -12,6 +12,7 @@
*
*
* ***************************************************************************/
+#if FEATURE_LCG
using System;
using System.Reflection;
@@ -81,3 +82,4 @@ internal DynamicILGenType(TypeBuilder tb, MethodBuilder mb, ILGenerator il)
}
#endif
}
+#endif
View
3  Runtime/Microsoft.Dynamic/Generation/ILGen.cs
@@ -12,6 +12,8 @@
*
*
* ***************************************************************************/
+#if FEATURE_LCG
+
#if FEATURE_PDBEMIT
using System.Diagnostics.SymbolStore;
#endif
@@ -1667,3 +1669,4 @@ public static partial class GeneratorOps {
}
}
}
+#endif
View
5 Runtime/Microsoft.Dynamic/Generation/Snippets.cs
@@ -34,7 +34,10 @@ public sealed class Snippets {
public static readonly Snippets Shared = new Snippets();
private Snippets() { }
+
+#if FEATURE_LCG
private int _methodNameIndex;
+#endif
#if FEATURE_REFEMIT
@@ -219,6 +222,7 @@ public sealed class Snippets {
#endif
+#if FEATURE_LCG
public DynamicILGen CreateDynamicMethod(string methodName, Type returnType, Type[] parameterTypes, bool isDebuggable) {
ContractUtils.RequiresNotEmpty(methodName, "methodName");
ContractUtils.RequiresNotNull(returnType, "returnType");
@@ -240,5 +244,6 @@ public sealed class Snippets {
string uniqueName = name + "##" + Interlocked.Increment(ref _methodNameIndex);
return ReflectionUtils.RawCreateDynamicMethod(uniqueName, returnType, parameterTypes);
}
+#endif
}
}
View
80 Runtime/Microsoft.Dynamic/Interpreter/Instructions/CallInstruction.Generated.cs
@@ -236,7 +236,7 @@ public partial class CallInstruction {
return t;
}
public static MethodInfo CacheFunc<TRet>(Func<TRet> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new FuncCallInstruction<TRet>(method);
}
@@ -244,7 +244,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheFunc<T0, TRet>(Func<T0, TRet> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new FuncCallInstruction<T0, TRet>(method);
}
@@ -252,7 +252,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheFunc<T0, T1, TRet>(Func<T0, T1, TRet> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new FuncCallInstruction<T0, T1, TRet>(method);
}
@@ -260,7 +260,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheFunc<T0, T1, T2, TRet>(Func<T0, T1, T2, TRet> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new FuncCallInstruction<T0, T1, T2, TRet>(method);
}
@@ -268,7 +268,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheFunc<T0, T1, T2, T3, TRet>(Func<T0, T1, T2, T3, TRet> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new FuncCallInstruction<T0, T1, T2, T3, TRet>(method);
}
@@ -276,7 +276,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheFunc<T0, T1, T2, T3, T4, TRet>(Func<T0, T1, T2, T3, T4, TRet> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new FuncCallInstruction<T0, T1, T2, T3, T4, TRet>(method);
}
@@ -284,7 +284,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheFunc<T0, T1, T2, T3, T4, T5, TRet>(Func<T0, T1, T2, T3, T4, T5, TRet> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new FuncCallInstruction<T0, T1, T2, T3, T4, T5, TRet>(method);
}
@@ -292,7 +292,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheFunc<T0, T1, T2, T3, T4, T5, T6, TRet>(Func<T0, T1, T2, T3, T4, T5, T6, TRet> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new FuncCallInstruction<T0, T1, T2, T3, T4, T5, T6, TRet>(method);
}
@@ -300,7 +300,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheFunc<T0, T1, T2, T3, T4, T5, T6, T7, TRet>(Func<T0, T1, T2, T3, T4, T5, T6, T7, TRet> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new FuncCallInstruction<T0, T1, T2, T3, T4, T5, T6, T7, TRet>(method);
}
@@ -308,7 +308,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheFunc<T0, T1, T2, T3, T4, T5, T6, T7, T8, TRet>(Func<T0, T1, T2, T3, T4, T5, T6, T7, T8, TRet> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new FuncCallInstruction<T0, T1, T2, T3, T4, T5, T6, T7, T8, TRet>(method);
}
@@ -316,7 +316,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheAction(Action method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new ActionCallInstruction(method);
}
@@ -324,7 +324,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheAction<T0>(Action<T0> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new ActionCallInstruction<T0>(method);
}
@@ -332,7 +332,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheAction<T0, T1>(Action<T0, T1> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new ActionCallInstruction<T0, T1>(method);
}
@@ -340,7 +340,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheAction<T0, T1, T2>(Action<T0, T1, T2> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new ActionCallInstruction<T0, T1, T2>(method);
}
@@ -348,7 +348,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheAction<T0, T1, T2, T3>(Action<T0, T1, T2, T3> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new ActionCallInstruction<T0, T1, T2, T3>(method);
}
@@ -356,7 +356,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheAction<T0, T1, T2, T3, T4>(Action<T0, T1, T2, T3, T4> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new ActionCallInstruction<T0, T1, T2, T3, T4>(method);
}
@@ -364,7 +364,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheAction<T0, T1, T2, T3, T4, T5>(Action<T0, T1, T2, T3, T4, T5> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new ActionCallInstruction<T0, T1, T2, T3, T4, T5>(method);
}
@@ -372,7 +372,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheAction<T0, T1, T2, T3, T4, T5, T6>(Action<T0, T1, T2, T3, T4, T5, T6> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new ActionCallInstruction<T0, T1, T2, T3, T4, T5, T6>(method);
}
@@ -380,7 +380,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheAction<T0, T1, T2, T3, T4, T5, T6, T7>(Action<T0, T1, T2, T3, T4, T5, T6, T7> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new ActionCallInstruction<T0, T1, T2, T3, T4, T5, T6, T7>(method);
}
@@ -388,7 +388,7 @@ public partial class CallInstruction {
}
public static MethodInfo CacheAction<T0, T1, T2, T3, T4, T5, T6, T7, T8>(Action<T0, T1, T2, T3, T4, T5, T6, T7, T8> method) {
- var info = method.GetMethod();
+ var info = method.GetMethodInfo();
lock (_cache) {
_cache[info] = new ActionCallInstruction<T0, T1, T2, T3, T4, T5, T6, T7, T8>(method);
}
@@ -399,7 +399,7 @@ public partial class CallInstruction {
internal sealed class ActionCallInstruction : CallInstruction {
private readonly Action _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 0; } }
public ActionCallInstruction(Action target) {
@@ -424,7 +424,7 @@ internal sealed class ActionCallInstruction : CallInstruction {
internal sealed class ActionCallInstruction<T0> : CallInstruction {
private readonly Action<T0> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 1; } }
public ActionCallInstruction(Action<T0> target) {
@@ -449,7 +449,7 @@ internal sealed class ActionCallInstruction<T0> : CallInstruction {
internal sealed class ActionCallInstruction<T0, T1> : CallInstruction {
private readonly Action<T0, T1> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 2; } }
public ActionCallInstruction(Action<T0, T1> target) {
@@ -474,7 +474,7 @@ internal sealed class ActionCallInstruction<T0, T1> : CallInstruction {
internal sealed class ActionCallInstruction<T0, T1, T2> : CallInstruction {
private readonly Action<T0, T1, T2> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 3; } }
public ActionCallInstruction(Action<T0, T1, T2> target) {
@@ -499,7 +499,7 @@ internal sealed class ActionCallInstruction<T0, T1, T2> : CallInstruction {
internal sealed class ActionCallInstruction<T0, T1, T2, T3> : CallInstruction {
private readonly Action<T0, T1, T2, T3> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 4; } }
public ActionCallInstruction(Action<T0, T1, T2, T3> target) {
@@ -524,7 +524,7 @@ internal sealed class ActionCallInstruction<T0, T1, T2, T3> : CallInstruction {
internal sealed class ActionCallInstruction<T0, T1, T2, T3, T4> : CallInstruction {
private readonly Action<T0, T1, T2, T3, T4> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 5; } }
public ActionCallInstruction(Action<T0, T1, T2, T3, T4> target) {
@@ -549,7 +549,7 @@ internal sealed class ActionCallInstruction<T0, T1, T2, T3, T4> : CallInstructio
internal sealed class ActionCallInstruction<T0, T1, T2, T3, T4, T5> : CallInstruction {
private readonly Action<T0, T1, T2, T3, T4, T5> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 6; } }
public ActionCallInstruction(Action<T0, T1, T2, T3, T4, T5> target) {
@@ -574,7 +574,7 @@ internal sealed class ActionCallInstruction<T0, T1, T2, T3, T4, T5> : CallInstru
internal sealed class ActionCallInstruction<T0, T1, T2, T3, T4, T5, T6> : CallInstruction {
private readonly Action<T0, T1, T2, T3, T4, T5, T6> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 7; } }
public ActionCallInstruction(Action<T0, T1, T2, T3, T4, T5, T6> target) {
@@ -599,7 +599,7 @@ internal sealed class ActionCallInstruction<T0, T1, T2, T3, T4, T5, T6> : CallIn
internal sealed class ActionCallInstruction<T0, T1, T2, T3, T4, T5, T6, T7> : CallInstruction {
private readonly Action<T0, T1, T2, T3, T4, T5, T6, T7> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 8; } }
public ActionCallInstruction(Action<T0, T1, T2, T3, T4, T5, T6, T7> target) {
@@ -624,7 +624,7 @@ internal sealed class ActionCallInstruction<T0, T1, T2, T3, T4, T5, T6, T7> : Ca
internal sealed class ActionCallInstruction<T0, T1, T2, T3, T4, T5, T6, T7, T8> : CallInstruction {
private readonly Action<T0, T1, T2, T3, T4, T5, T6, T7, T8> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 9; } }
public ActionCallInstruction(Action<T0, T1, T2, T3, T4, T5, T6, T7, T8> target) {
@@ -649,7 +649,7 @@ internal sealed class ActionCallInstruction<T0, T1, T2, T3, T4, T5, T6, T7, T8>
internal sealed class FuncCallInstruction<TRet> : CallInstruction {
private readonly Func<TRet> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 0; } }
public FuncCallInstruction(Func<TRet> target) {
@@ -673,7 +673,7 @@ internal sealed class FuncCallInstruction<TRet> : CallInstruction {
internal sealed class FuncCallInstruction<T0, TRet> : CallInstruction {
private readonly Func<T0, TRet> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 1; } }
public FuncCallInstruction(Func<T0, TRet> target) {
@@ -697,7 +697,7 @@ internal sealed class FuncCallInstruction<T0, TRet> : CallInstruction {
internal sealed class FuncCallInstruction<T0, T1, TRet> : CallInstruction {
private readonly Func<T0, T1, TRet> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 2; } }
public FuncCallInstruction(Func<T0, T1, TRet> target) {
@@ -721,7 +721,7 @@ internal sealed class FuncCallInstruction<T0, T1, TRet> : CallInstruction {
internal sealed class FuncCallInstruction<T0, T1, T2, TRet> : CallInstruction {
private readonly Func<T0, T1, T2, TRet> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 3; } }
public FuncCallInstruction(Func<T0, T1, T2, TRet> target) {
@@ -745,7 +745,7 @@ internal sealed class FuncCallInstruction<T0, T1, T2, TRet> : CallInstruction {
internal sealed class FuncCallInstruction<T0, T1, T2, T3, TRet> : CallInstruction {
private readonly Func<T0, T1, T2, T3, TRet> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 4; } }
public FuncCallInstruction(Func<T0, T1, T2, T3, TRet> target) {
@@ -769,7 +769,7 @@ internal sealed class FuncCallInstruction<T0, T1, T2, T3, TRet> : CallInstructio
internal sealed class FuncCallInstruction<T0, T1, T2, T3, T4, TRet> : CallInstruction {
private readonly Func<T0, T1, T2, T3, T4, TRet> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 5; } }
public FuncCallInstruction(Func<T0, T1, T2, T3, T4, TRet> target) {
@@ -793,7 +793,7 @@ internal sealed class FuncCallInstruction<T0, T1, T2, T3, T4, TRet> : CallInstru
internal sealed class FuncCallInstruction<T0, T1, T2, T3, T4, T5, TRet> : CallInstruction {
private readonly Func<T0, T1, T2, T3, T4, T5, TRet> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 6; } }
public FuncCallInstruction(Func<T0, T1, T2, T3, T4, T5, TRet> target) {
@@ -817,7 +817,7 @@ internal sealed class FuncCallInstruction<T0, T1, T2, T3, T4, T5, TRet> : CallIn
internal sealed class FuncCallInstruction<T0, T1, T2, T3, T4, T5, T6, TRet> : CallInstruction {
private readonly Func<T0, T1, T2, T3, T4, T5, T6, TRet> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 7; } }
public FuncCallInstruction(Func<T0, T1, T2, T3, T4, T5, T6, TRet> target) {
@@ -841,7 +841,7 @@ internal sealed class FuncCallInstruction<T0, T1, T2, T3, T4, T5, T6, TRet> : Ca
internal sealed class FuncCallInstruction<T0, T1, T2, T3, T4, T5, T6, T7, TRet> : CallInstruction {
private readonly Func<T0, T1, T2, T3, T4, T5, T6, T7, TRet> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 8; } }
public FuncCallInstruction(Func<T0, T1, T2, T3, T4, T5, T6, T7, TRet> target) {
@@ -865,7 +865,7 @@ internal sealed class FuncCallInstruction<T0, T1, T2, T3, T4, T5, T6, T7, TRet>
internal sealed class FuncCallInstruction<T0, T1, T2, T3, T4, T5, T6, T7, T8, TRet> : CallInstruction {
private readonly Func<T0, T1, T2, T3, T4, T5, T6, T7, T8, TRet> _target;
- public override MethodInfo Info { get { return _target.GetMethod(); } }
+ public override MethodInfo Info { get { return _target.GetMethodInfo(); } }
public override int ArgumentCount { get { return 9; } }
public FuncCallInstruction(Func<T0, T1, T2, T3, T4, T5, T6, T7, T8, TRet> target) {
View
6 Runtime/Microsoft.Dynamic/Interpreter/Instructions/CallInstruction.cs
@@ -117,19 +117,19 @@ public abstract partial class CallInstruction : Instruction {
case 1:
return Create(isGetter ?
arrayType.GetMethod("GetValue", new[] { typeof(int)}) :
- new Action<Array, int, object>(ArrayItemSetter1).GetMethod()
+ new Action<Array, int, object>(ArrayItemSetter1).GetMethodInfo()
);
case 2:
return Create(isGetter ?
arrayType.GetMethod("GetValue", new[] { typeof(int), typeof(int) }) :
- new Action<Array, int, int, object>(ArrayItemSetter2).GetMethod()
+ new Action<Array, int, int, object>(ArrayItemSetter2).GetMethodInfo()
);
case 3:
return Create(isGetter ?
arrayType.GetMethod("GetValue", new[] { typeof(int), typeof(int), typeof(int) }) :
- new Action<Array, int, int, int, object>(ArrayItemSetter3).GetMethod()
+ new Action<Array, int, int, int, object>(ArrayItemSetter3).GetMethodInfo()
);
default:
View
6 Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs
@@ -1263,7 +1263,11 @@ private LightCompiler(LightCompiler parent)
if (node.Constructor != null) {
var parameters = node.Constructor.GetParameters();
- if (!CollectionUtils.TrueForAll(parameters, (p) => !p.ParameterType.IsByRef) || node.Constructor.DeclaringType == typeof(DynamicMethod)) {
+ if (!CollectionUtils.TrueForAll(parameters, (p) => !p.ParameterType.IsByRef)
+#if FEATURE_LCG
+ || node.Constructor.DeclaringType == typeof(DynamicMethod)
+#endif
+ ) {
_forceCompile = true;
}
}
View
2  Runtime/Microsoft.Dynamic/Interpreter/LightLambda.cs
@@ -123,7 +123,7 @@ public partial class LightLambda {
runMethod = typeof(LightLambda).GetMethod(name + paramInfos.Length, BindingFlags.NonPublic | BindingFlags.Instance);
}
-#if !SILVERLIGHT && !WP75
+#if FEATURE_LCG && !SILVERLIGHT && !WP75
try {
DynamicMethod dm = new DynamicMethod("FastCtor", typeof(Delegate), new[] { typeof(LightLambda) }, typeof(LightLambda), true);
var ilgen = dm.GetILGenerator();
View
2  Runtime/Microsoft.Dynamic/Runtime/ArgumentArray.cs
@@ -71,6 +71,6 @@ public sealed class ArgumentArray {
return array._arguments[array._first + index];
}
- private static readonly MethodInfo _GetArgMethod = new Func<ArgumentArray, int, object>(GetArg).GetMethod();
+ private static readonly MethodInfo _GetArgMethod = new Func<ArgumentArray, int, object>(GetArg).GetMethodInfo();
}
}
View
301 Runtime/Microsoft.Dynamic/Runtime/DelegateInfo.cs
@@ -12,11 +12,11 @@
*
*
* ***************************************************************************/
-
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Dynamic;
+using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
@@ -28,25 +28,45 @@ namespace Microsoft.Scripting.Runtime {
/// <summary>
/// Used as the value for the ScriptingRuntimeHelpers.GetDelegate method caching system
/// </summary>
- internal sealed class DelegateInfo {
+ public sealed class DelegateInfo {
+#if FEATURE_LCG
+ private const int TargetIndex = 0;
+ private const int CallSiteIndex = 1;
+ private const int ConvertSiteIndex = 2;
+ private static readonly object TargetPlaceHolder = new object();
+ private static readonly object CallSitePlaceHolder = new object();
+ private static readonly object ConvertSitePlaceHolder = new object();
+
+ // to enable:
+ // function x() { }
+ // someClass.someEvent += delegateType(x)
+ // someClass.someEvent -= delegateType(x)
+ //
+ // We need to avoid re-creating the closure because the delegates won't
+ // compare equal when removing the delegate if they have different closure
+ // instances. Therefore we use a weak hashtable to get back the
+ // original closure. The closures also need to be held via a weak refererence to avoid
+ // creating a circular reference from the constants target back to the
+ // target. This is fine because as long as the delegate is referenced
+ // the object array will stay alive. Once the delegate is gone it's not
+ // wired up anywhere and -= will never be used again.
+ //
+ // Note that the closure content depends on the signature of the delegate. So a single dynamic object
+ // might need multiple closures if it is converted to delegates of different signatures.
+ private WeakDictionary<object, WeakReference> _closureMap = new WeakDictionary<object, WeakReference>();
+
private readonly Type _returnType;
- private readonly ParameterInfo[] _parameters;
+ private readonly Type[] _parameterTypes;
private readonly MethodInfo _method;
- private readonly object[] _constants;
- private WeakDictionary<object, WeakReference> _constantMap = new WeakDictionary<object, WeakReference>();
private readonly InvokeBinder _invokeBinder;
private readonly ConvertBinder _convertBinder;
- private static readonly object TargetPlaceHolder = new object();
- private static readonly object CallSitePlaceHolder = new object();
- private static readonly object ConvertSitePlaceHolder = new object();
-
- internal DelegateInfo(LanguageContext context, Type returnType, ParameterInfo[] parameters) {
+ public DelegateInfo(LanguageContext context, Type returnType, Type[] parameters) {
Assert.NotNull(returnType);
Assert.NotNullItems(parameters);
_returnType = returnType;
- _parameters = parameters;
+ _parameterTypes = parameters;
PerfTrack.NoteEvent(PerfTrack.Categories.DelegateCreate, ToString());
@@ -54,47 +74,30 @@ internal sealed class DelegateInfo {
_convertBinder = context.CreateConvertBinder(_returnType, true);
}
- _invokeBinder = context.CreateInvokeBinder(new CallInfo(_parameters.Length));
+ _invokeBinder = context.CreateInvokeBinder(new CallInfo(_parameterTypes.Length));
- Type[] delegateParams = new Type[_parameters.Length];
- for (int i = 0; i < _parameters.Length; i++) {
- delegateParams[i] = _parameters[i].ParameterType;
+ Type[] delegateParams = new Type[1 + _parameterTypes.Length];
+ delegateParams[0] = typeof(object[]);
+ for (int i = 0; i < _parameterTypes.Length; i++) {
+ delegateParams[1 + i] = _parameterTypes[i];
}
- // Create the method with a special name so the langauge compiler knows that method's stack frame is not visible
- DynamicILGen cg = Snippets.Shared.CreateDynamicMethod("_Scripting_", _returnType, ArrayUtils.Insert(typeof(object[]), delegateParams), false);
-
- // Emit the stub
- _constants = EmitClrCallStub(cg);
- _method = cg.Finish();
+ EmitClrCallStub(returnType, delegateParams, out _method);
}
- internal Delegate CreateDelegate(Type delegateType, object target) {
- Assert.NotNull(delegateType, target);
-
- // to enable:
- // function x() { }
- // someClass.someEvent += delegateType(x)
- // someClass.someEvent -= delegateType(x)
- //
- // we need to avoid re-creating the object array because they won't
- // be compare equal when removing the delegate if they're difference
- // instances. Therefore we use a weak hashtable to get back the
- // original object array. The values also need to be weak to avoid
- // creating a circular reference from the constants target back to the
- // target. This is fine because as long as the delegate is referenced
- // the object array will stay alive. Once the delegate is gone it's not
- // wired up anywhere and -= will never be used again.
-
- object[] clone;
- lock (_constantMap) {
- WeakReference cloneRef;
-
- if (!_constantMap.TryGetValue(target, out cloneRef) ||
- (clone = (object[])cloneRef.Target) == null) {
- _constantMap[target] = new WeakReference(clone = (object[])_constants.Clone());
-
- Type[] siteTypes = MakeSiteSignature();
+ public Delegate CreateDelegate(Type delegateType, object dynamicObject) {
+ Assert.NotNull(delegateType, dynamicObject);
+
+ object[] closure;
+ lock (_closureMap) {
+ WeakReference weakClosure;
+
+ if (!_closureMap.TryGetValue(dynamicObject, out weakClosure) || (closure = (object[])weakClosure.Target) == null) {
+
+ closure = new[] { TargetPlaceHolder, CallSitePlaceHolder, ConvertSitePlaceHolder };
+ _closureMap[dynamicObject] = new WeakReference(closure);
+
+ Type[] siteTypes = MakeSiteSignature(_parameterTypes);
CallSite callSite = CallSite.Create(DynamicSiteHelpers.MakeCallSiteDelegate(siteTypes), _invokeBinder);
@@ -103,28 +106,31 @@ internal sealed class DelegateInfo {
convertSite = CallSite.Create(DynamicSiteHelpers.MakeCallSiteDelegate(typeof(object), _returnType), _convertBinder);
}
- Debug.Assert(clone[0] == TargetPlaceHolder);
- Debug.Assert(clone[1] == CallSitePlaceHolder);
- Debug.Assert(clone[2] == ConvertSitePlaceHolder);
-
- clone[0] = target;
- clone[1] = callSite;
- clone[2] = convertSite;
+ closure[TargetIndex] = dynamicObject;
+ closure[CallSiteIndex] = callSite;
+ closure[ConvertSiteIndex] = convertSite;
}
}
- return _method.CreateDelegate(delegateType, clone);
+ return _method.CreateDelegate(delegateType, closure);
+ }
+
+ private void EmitClrCallStub(Type returnType, Type[] parameterTypes, out MethodInfo method) {
+ // Create the method with a special name so the langauge compiler knows that method's stack frame is not visible
+ DynamicILGen cg = Snippets.Shared.CreateDynamicMethod("_Scripting_", returnType, parameterTypes, false);
+ EmitClrCallStub(cg);
+ method = cg.Finish();
}
/// <summary>
/// Generates stub to receive the CLR call and then call the dynamic language code.
/// </summary>
- private object[] EmitClrCallStub(ILGen cg) {
+ private void EmitClrCallStub(ILGen cg) {
List<ReturnFixer> fixers = new List<ReturnFixer>(0);
// Create strongly typed return type from the site.
// This will, among other things, generate tighter code.
- Type[] siteTypes = MakeSiteSignature();
+ Type[] siteTypes = MakeSiteSignature(_parameterTypes);
CallSite callSite = CallSite.Create(DynamicSiteHelpers.MakeCallSiteDelegate(siteTypes), _invokeBinder);
Type siteType = callSite.GetType();
@@ -137,14 +143,10 @@ internal sealed class DelegateInfo {
convertSiteType = convertSite.GetType();
}
- // build up constants array
- object[] constants = new object[] { TargetPlaceHolder, CallSitePlaceHolder, ConvertSitePlaceHolder };
- const int TargetIndex = 0, CallSiteIndex = 1, ConvertSiteIndex = 2;
-
LocalBuilder convertSiteLocal = null;
FieldInfo convertTarget = null;
if (_returnType != typeof(void)) {
- // load up the conversesion logic on the stack
+ // load up the conversion logic on the stack
convertSiteLocal = cg.DeclareLocal(convertSiteType);
EmitConstantGet(cg, ConvertSiteIndex, convertSiteType);
@@ -168,9 +170,9 @@ internal sealed class DelegateInfo {
EmitConstantGet(cg, TargetIndex, typeof(object));
- for (int i = 0; i < _parameters.Length; i++) {
- if (_parameters[i].ParameterType.IsByRef) {
- ReturnFixer rf = ReturnFixer.EmitArgument(cg, i + 1, _parameters[i].ParameterType);
+ for (int i = 0; i < _parameterTypes.Length; i++) {
+ if (_parameterTypes[i].IsByRef) {
+ ReturnFixer rf = ReturnFixer.EmitArgument(cg, i + 1, _parameterTypes[i]);
if (rf != null) fixers.Add(rf);
} else {
cg.EmitLoadArg(i + 1);
@@ -193,7 +195,6 @@ internal sealed class DelegateInfo {
}
cg.Emit(OpCodes.Ret);
- return constants;
}
private static void EmitConstantGet(ILGen il, int index, Type type) {
@@ -205,18 +206,18 @@ internal sealed class DelegateInfo {
}
}
- internal Type[] MakeSiteSignature() {
- Type[] sig = new Type[_parameters.Length + 2];
+ private static Type[] MakeSiteSignature(Type[] parameterTypes) {
+ Type[] sig = new Type[parameterTypes.Length + 2];
// target object
sig[0] = typeof(object);
// arguments
- for (int i = 0; i < _parameters.Length; i++) {
- if (_parameters[i].ParameterType.IsByRef) {
+ for (int i = 0; i < parameterTypes.Length; i++) {
+ if (parameterTypes[i].IsByRef) {
sig[i + 1] = typeof(object);
} else {
- sig[i + 1] = _parameters[i].ParameterType;
+ sig[i + 1] = parameterTypes[i];
}
}
@@ -225,5 +226,163 @@ internal sealed class DelegateInfo {
return sig;
}
+#else
+ private static Type[] MakeSiteSignature(ParameterInfo[] parameterInfos) {
+ Type[] sig = new Type[parameterInfos.Length + 2];
+
+ // target object
+ sig[0] = typeof(object);
+
+ // arguments
+ for (int i = 0; i < parameterInfos.Length; i++) {
+ if (parameterInfos[i].ParameterType.IsByRef) {
+ sig[i + 1] = typeof(object);
+ } else {
+ sig[i + 1] = parameterInfos[i].ParameterType;
+ }
+ }
+
+ // return type
+ sig[sig.Length - 1] = typeof(object);
+
+ return sig;
+ }
+
+ internal static Delegate CreateDelegateForDynamicObject(LanguageContext context, object dynamicObject, Type delegateType, MethodInfo invoke) {
+ PerfTrack.NoteEvent(PerfTrack.Categories.DelegateCreate, delegateType.ToString());
+
+ Type returnType = invoke.ReturnType;
+ ParameterInfo[] parameterInfos = invoke.GetParameters();
+
+ var parameters = new List<ParameterExpression>();
+ for (int i = 0; i < parameterInfos.Length; i++) {
+ parameters.Add(Expression.Parameter(parameterInfos[i].ParameterType, "p" + i));
+ }
+
+ InvokeBinder invokeBinder = context.CreateInvokeBinder(new CallInfo(parameterInfos.Length));
+ ConvertBinder convertBinder = (returnType != typeof(void)) ? context.CreateConvertBinder(returnType, explicitCast: true) : null;
+
+ CallSite invokeSite = CallSite.Create(DynamicSiteHelpers.MakeCallSiteDelegate(MakeSiteSignature(parameterInfos)), invokeBinder);
+ Type invokeSiteType = invokeSite.GetType();
+
+ Type convertSiteType;
+ CallSite convertSite;
+ if (convertBinder != null) {
+ convertSite = CallSite.Create(DynamicSiteHelpers.MakeCallSiteDelegate(typeof(object), returnType), convertBinder);
+ convertSiteType = convertSite.GetType();
+ } else {
+ convertSiteType = null;
+ convertSite = null;
+ }
+
+ var locals = new List<ParameterExpression>();
+
+ ParameterExpression invokeSiteVar = Expression.Parameter(invokeSiteType, "site");
+ ParameterExpression convertSiteVar = null;
+
+ var args = new List<Expression>();
+ args.Add(invokeSiteVar);
+ args.Add(Expression.Constant(dynamicObject));
+
+ int strongBoxVarsStart = locals.Count;
+
+ for (int i = 0; i < parameterInfos.Length; i++) {
+ if (parameterInfos[i].ParameterType.IsByRef) {
+ var argType = parameterInfos[i].ParameterType;
+
+ Type elementType = argType.GetElementType();
+ Type concreteType = typeof(StrongBox<>).MakeGenericType(elementType);
+
+ var strongBox = Expression.Parameter(concreteType, "box" + i);
+ locals.Add(strongBox);
+
+ args.Add(
+ Expression.Assign(
+ strongBox,
+ Expression.New(
+ concreteType.GetConstructor(new Type[] { elementType }),
+ parameters[i]
+ )
+ )
+ );
+
+ } else {
+ args.Add(parameters[i]);
+ }
+ }
+
+ int strongBoxVarsEnd = locals.Count;
+
+ Expression invocation = Expression.Invoke(
+ Expression.Field(
+ Expression.Assign(
+ invokeSiteVar,
+ Expression.Convert(Expression.Constant(invokeSite), invokeSiteType)
+ ),
+ invokeSiteType.GetDeclaredField("Target")
+ ),
+ args
+ );
+
+ if (convertBinder != null) {
+ convertSiteVar = Expression.Parameter(convertSiteType, "convertSite");
+
+ invocation = Expression.Invoke(
+ Expression.Field(
+ Expression.Assign(
+ convertSiteVar,
+ Expression.Convert(Expression.Constant(convertSite), convertSiteType)
+ ),
+ convertSiteType.GetDeclaredField("Target")
+ ),
+ convertSiteVar,
+ invocation
+ );
+ }
+
+ locals.Add(invokeSiteVar);
+ if (convertSiteVar != null) {
+ locals.Add(convertSiteVar);
+ }
+
+ Expression body;
+
+ // copy back from StrongBox.Value
+ if (strongBoxVarsEnd > strongBoxVarsStart) {
+ var block = new Expression[1 + strongBoxVarsEnd - strongBoxVarsStart + 1];
+
+ var resultVar = Expression.Parameter(invocation.Type, "result");
+ locals.Add(resultVar);
+
+ int b = 0;
+ int l = strongBoxVarsStart;
+
+ // values of strong boxes are initialized in invocation expression:
+ block[b++] = Expression.Assign(resultVar, invocation);
+
+ for (int i = 0; i < parameterInfos.Length; i++) {
+ if (parameterInfos[i].ParameterType.IsByRef) {
+ var local = locals[l++];
+ block[b++] = Expression.Assign(
+ parameters[i],
+ Expression.Field(local, local.Type.GetDeclaredField("Value"))
+ );
+ }
+ }
+
+ block[b++] = resultVar;
+
+ Debug.Assert(l == strongBoxVarsEnd);
+ Debug.Assert(b == block.Length);
+
+ body = Expression.Block(locals, block);
+ } else {
+ body = Expression.Block(locals, invocation);
+ }
+
+ var lambda = Expression.Lambda(delegateType, body, "_Scripting_", parameters);
+ return lambda.Compile();
+ }
+#endif
}
}
View
43 Runtime/Microsoft.Dynamic/Runtime/DelegateSignatureInfo.cs
@@ -12,7 +12,6 @@
*
*
* ***************************************************************************/
-
using System;
using System.Reflection;
using System.Text;
@@ -24,27 +23,35 @@ namespace Microsoft.Scripting.Runtime {
/// </summary>
internal sealed class DelegateSignatureInfo {
private readonly Type _returnType;
- private readonly ParameterInfo[] _parameters;
+ private readonly Type[] _parameterTypes;
+
+ internal DelegateSignatureInfo(MethodInfo invoke) {
+ Assert.NotNull(invoke);
- internal DelegateSignatureInfo(Type returnType, ParameterInfo[] parameters) {
- Assert.NotNull(returnType);
- Assert.NotNullItems(parameters);
+ ParameterInfo[] parameters = invoke.GetParameters();
+ Type[] parameterTypes = new Type[parameters.Length];
+ for (int i = 0; i < parameters.Length; i++) {
+ parameterTypes[i] = parameters[i].ParameterType;
+ }
- _parameters = parameters;
- _returnType = returnType;
+ _parameterTypes = parameterTypes;
+ _returnType = invoke.ReturnType;
}
+ internal Type ReturnType { get { return _returnType; } }
+ internal Type[] ParameterTypes { get { return _parameterTypes; } }
+
public override bool Equals(object obj) {
DelegateSignatureInfo dsi = obj as DelegateSignatureInfo;
- if (dsi == null ||
- dsi._parameters.Length != _parameters.Length ||
+ if (dsi == null ||
+ dsi._parameterTypes.Length != _parameterTypes.Length ||
dsi._returnType != _returnType) {
return false;
}
- for (int i = 0; i < _parameters.Length; i++) {
- if (dsi._parameters[i] != _parameters[i]) {
+ for (int i = 0; i < _parameterTypes.Length; i++) {
+ if (dsi._parameterTypes[i] != _parameterTypes[i]) {
return false;
}
}
@@ -55,8 +62,8 @@ internal sealed class DelegateSignatureInfo {
public override int GetHashCode() {
int hashCode = 5331;
- for (int i = 0; i < _parameters.Length; i++) {
- hashCode ^= _parameters[i].GetHashCode();
+ for (int i = 0; i < _parameterTypes.Length; i++) {
+ hashCode ^= _parameterTypes[i].GetHashCode();
}
hashCode ^= _returnType.GetHashCode();
return hashCode;
@@ -66,16 +73,12 @@ internal sealed class DelegateSignatureInfo {
StringBuilder text = new StringBuilder();
text.Append(_returnType.ToString());
text.Append("(");
- for (int i = 0; i < _parameters.Length; i++) {
+ for (int i = 0; i < _parameterTypes.Length; i++) {
if (i != 0) text.Append(", ");
- text.Append(_parameters[i].ParameterType.Name);
+ text.Append(_parameterTypes[i].Name);
}
text.Append(")");
return text.ToString();
}
-
- internal DelegateInfo GenerateDelegateStub(LanguageContext context) {
- return new DelegateInfo(context, _returnType, _parameters);
- }
}
-}
+}
View
65 Runtime/Microsoft.Dynamic/Runtime/DynamicDelegateCreator.cs
@@ -12,11 +12,13 @@
*
*
* ***************************************************************************/
-
using System;
+using System.Collections.Generic;
using System.Dynamic;
+using System.Linq.Expressions;
using System.Reflection;
-
+using System.Runtime.CompilerServices;
+using Microsoft.Scripting.Actions;
using Microsoft.Scripting.Utils;
namespace Microsoft.Scripting.Runtime {
@@ -39,9 +41,6 @@ public class DynamicDelegateCreator {
_languageContext = languageContext;
}
- /// <summary> Table of dynamically generated delegates which are shared based upon method signature. </summary>
- private Publisher<DelegateSignatureInfo, DelegateInfo> _dynamicDelegateCache = new Publisher<DelegateSignatureInfo, DelegateInfo>();
-
/// <summary>
/// Creates a delegate with a given signature that could be used to invoke this object from non-dynamic code (w/o code context).
/// A stub is created that makes appropriate conversions/boxing and calls the object.
@@ -70,20 +69,7 @@ public class DynamicDelegateCreator {
throw ScriptingRuntimeHelpers.SimpleTypeError("A specific delegate type is required.");
}
- ParameterInfo[] parameters = invoke.GetParameters();
- DelegateSignatureInfo signatureInfo = new DelegateSignatureInfo(
- invoke.ReturnType,
- parameters
- );
-
- DelegateInfo delegateInfo = _dynamicDelegateCache.GetOrCreateValue(signatureInfo,
- delegate() {
- // creation code
- return signatureInfo.GenerateDelegateStub(_languageContext);
- });
-
-
- result = delegateInfo.CreateDelegate(delegateType, dynamicObject);
+ result = GetOrCreateDelegateForDynamicObject(callableObject, delegateType, invoke);
if (result != null) {
return result;
}
@@ -92,5 +78,44 @@ public class DynamicDelegateCreator {
throw ScriptingRuntimeHelpers.SimpleTypeError("Object is not callable.");
}
+#if FEATURE_LCG
+ // Table of dynamically generated delegates which are shared based upon method signature.
+ //
+ // We generate a dynamic method stub and object[] closure template for each signature.
+ // The stub does only depend on the signature, it doesn't depend on the dynamic object.
+ // So we can reuse these stubs among multiple dynamic object for which a delegate was created with the same signature.
+ //
+ private Publisher<DelegateSignatureInfo, DelegateInfo> _dynamicDelegateCache = new Publisher<DelegateSignatureInfo, DelegateInfo>();
+
+ public Delegate GetOrCreateDelegateForDynamicObject(object dynamicObject, Type delegateType, MethodInfo invoke) {
+ var signatureInfo = new DelegateSignatureInfo(invoke);
+ DelegateInfo delegateInfo = _dynamicDelegateCache.GetOrCreateValue(
+ signatureInfo,
+ () => new DelegateInfo(_languageContext, signatureInfo.ReturnType, signatureInfo.ParameterTypes)
+ );
+
+ return delegateInfo.CreateDelegate(delegateType, dynamicObject);
+ }
+#else
+ //
+ // Using Expression Trees we create a new stub for every dynamic object and every delegate type.
+ // This is less efficient than with LCG since we can't reuse generated code for multiple dynamic objects and signatures.
+ //
+ private static ConditionalWeakTable<object, Dictionary<Type, Delegate>> _dynamicDelegateCache =
+ new ConditionalWeakTable<object, Dictionary<Type, Delegate>>();
+
+ private Delegate GetOrCreateDelegateForDynamicObject(object dynamicObject, Type delegateType, MethodInfo invoke) {
+ var signatures = _dynamicDelegateCache.GetOrCreateValue(dynamicObject);
+ lock (signatures) {
+ Delegate result;
+ if (!signatures.TryGetValue(delegateType, out result)) {
+ result = DelegateInfo.CreateDelegateForDynamicObject(_languageContext, dynamicObject, delegateType, invoke);
+ signatures.Add(delegateType, result);
+ }
+
+ return result;
+ }
+ }
+#endif
}
-}
+}
View
2  Runtime/Microsoft.Dynamic/Runtime/LightExceptions.cs
@@ -51,7 +51,7 @@ namespace Microsoft.Scripting.Runtime {
/// via 2-pass exception handling.
/// </summary>
public static class LightExceptions {
- internal static MethodInfo _checkAndThrow = new Func<object, object>(LightExceptions.CheckAndThrow).GetMethod();
+ internal static MethodInfo _checkAndThrow = new Func<object, object>(LightExceptions.CheckAndThrow).GetMethodInfo();
/// <summary>
/// Rewrites the provided expression to support light exceptions.
View
50 Runtime/Microsoft.Dynamic/Runtime/ReflectionCache.cs
@@ -12,7 +12,6 @@
*
*
* ***************************************************************************/
-
using System;
using System.Collections.Generic;
using System.Reflection;
@@ -25,9 +24,29 @@ namespace Microsoft.Scripting.Runtime {
/// specific request.
/// </summary>
public static class ReflectionCache {
- private static readonly Dictionary<MethodBaseCache, MethodGroup> _functions = new Dictionary<MethodBaseCache, MethodGroup>();
- private static readonly Dictionary<Type, TypeTracker> _typeCache = new Dictionary<Type, TypeTracker>();
+#if WIN8 // tokens are not exposed, we need to implement method comparison that doesn't use them, for now just always return a new method group
+ public static MethodGroup GetMethodGroup(string name, MethodBase[] methods) {
+ return new MethodGroup(
+ ArrayUtils.ConvertAll<MethodBase, MethodTracker>(
+ methods,
+ delegate(MethodBase x) {
+ return (MethodTracker)MemberTracker.FromMemberInfo(x);
+ }
+ )
+ );
+ }
+ public static MethodGroup GetMethodGroup(string name, MemberGroup mems) {
+ MethodTracker[] trackers = new MethodTracker[mems.Count];
+ for (int i = 0; i < trackers.Length; i++) {
+ trackers[i] = (MethodTracker)mems[i];
+ }
+
+ return new MethodGroup(trackers);
+ }
+#else
+ private static readonly Dictionary<MethodBaseCache, MethodGroup> _functions = new Dictionary<MethodBaseCache, MethodGroup>();
+
public static MethodGroup GetMethodGroup(string name, MethodBase[] methods) {
MethodGroup res = null;
MethodBaseCache cache = new MethodBaseCache(name, methods);
@@ -68,18 +87,6 @@ public static class ReflectionCache {
return res;
}
- public static TypeTracker GetTypeTracker(Type type) {
- TypeTracker res;
-
- lock (_typeCache) {
- if (!_typeCache.TryGetValue(type, out res)) {
- _typeCache[type] = res = new NestedTypeTracker(type);
- }
- }
-
- return res;
- }
-
/// <summary>
/// TODO: Make me private again
/// </summary>
@@ -97,11 +104,11 @@ public class MethodBaseCache {
}
private static int CompareMethods(MethodBase x, MethodBase y) {
- Module xModule = x.GetModule();
- Module yModule = y.GetModule();
+ Module xModule = x.Module;
+ Module yModule = y.Module;
if (xModule == yModule) {
- return x.GetMetadataToken() - y.GetMetadataToken();
+ return x.MetadataToken - y.MetadataToken;
}
#if SILVERLIGHT || WIN8 || WP75
@@ -132,7 +139,7 @@ public class MethodBaseCache {
for (int i = 0; i < _members.Length; i++) {
if (_members[i].DeclaringType != other._members[i].DeclaringType ||
- _members[i].GetMetadataToken() != other._members[i].GetMetadataToken() ||
+ _members[i].MetadataToken != other._members[i].MetadataToken ||
_members[i].IsGenericMethod != other._members[i].IsGenericMethod) {
return false;
}
@@ -159,12 +166,13 @@ public class MethodBaseCache {
public override int GetHashCode() {
int res = 6551;
foreach (MemberInfo mi in _members) {
- res ^= res << 5 ^ mi.DeclaringType.GetHashCode() ^ mi.GetMetadataToken();
+ res ^= res << 5 ^ mi.DeclaringType.GetHashCode() ^ mi.MetadataToken;
}
res ^= _name.GetHashCode();
return res;
}
}
+#endif
}
-}
+}
View
4 Runtime/Microsoft.Dynamic/Runtime/ReturnFixer.cs
@@ -12,6 +12,7 @@
*
*
* ***************************************************************************/
+#if FEATURE_LCG
using System;
using System.Diagnostics;
@@ -20,7 +21,7 @@
using Microsoft.Scripting.Utils;
namespace Microsoft.Scripting.Generation {
- sealed class ReturnFixer {
+ internal sealed class ReturnFixer {
private readonly LocalBuilder _refSlot;
private readonly int _argIndex;
private readonly Type _argType;
@@ -59,3 +60,4 @@ sealed class ReturnFixer {
}
}
}
+#endif
View
84 Runtime/Microsoft.Dynamic/Utils/ReflectionUtils.cs
@@ -807,25 +807,8 @@ private static IEnumerable<T> WithBindingFlags<T>(this IEnumerable<T> members, F
return type.GetTypeInfo().GetDeclaredMethods(name).WithBindingFlags(bindingFlags);
}
-
- public static Type CreateType(this TypeBuilder builder) {
- return builder.CreateTypeInfo().AsType();
- }
-
public static MethodInfo GetMethod(this Delegate d) {
- return ((dynamic)d).Method;
- }
-
- public static object GetRawConstantValue(this FieldInfo field) {
- return ((dynamic)field).GetRawConstantValue();
- }
-
- public static int GetMetadataToken(this MemberInfo member) {
- return ((dynamic)member).MetadataToken;
- }
-
- public static Module GetModule(this MemberInfo member) {
- return ((dynamic)member).Module;
+ return d.GetMethodInfo();
}
public static Type[] GetGenericArguments(this Type type) {