| CODENOTIFIER | HelpYou are not signed inSign in |
Project: IronRuby
Revision: 132
Author: jlam
Date: 15 Aug 2008 14:36:06
Changes:Syncing to head of TFS
Files:| ... | ...@@ -725,7 +725,7 @@ | |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | // more than one method found, no clear best method, report an ambigious match |
| 728 | return MakeAmbigiousBindingTarget(callType, types, result); | |
| 728 | return MakeAmbiguousBindingTarget(callType, types, result); | |
| 729 | 729 | } |
| 730 | 730 | } |
| 731 | 731 | |
| ... | ...@@ -778,7 +778,7 @@ | |
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | // more than one method found, no clear best method, report an ambigious match |
| 781 | return MakeAmbigiousBindingTarget(callType, metaObjects, result); | |
| 781 | return MakeAmbiguousBindingTarget(callType, metaObjects, result); | |
| 782 | 782 | } |
| 783 | 783 | } |
| 784 | 784 | |
| ... | ...@@ -956,7 +956,7 @@ | |
| 956 | 956 | return new BindingTarget(_binder.Name, callType == CallTypes.None ? objects.Length : objects.Length - 1, resTarget.Target, resTarget.NarrowingLevel, GetRestrictedMetaObjects(resTarget, objects, _targets)); |
| 957 | 957 | } |
| 958 | 958 | |
| 959 | private BindingTarget MakeAmbigiousBindingTarget<T>(CallTypes callType, T[] types, List<MethodCandidate> result) { | |
| 959 | private BindingTarget MakeAmbiguousBindingTarget<T>(CallTypes callType, T[] types, List<MethodCandidate> result) { | |
| 960 | 960 | MethodTarget[] methods = new MethodTarget[result.Count]; |
| 961 | 961 | for (int i = 0; i < result.Count; i++) { |
| 962 | 962 | methods[i] = result[i].Target; |
| ... | ...@@ -31,9 +31,9 @@ | |
| 31 | 31 | return EmptyReadOnlyCollection<T>.Instance; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | var roc = enumerable as ReadOnlyCollection<T>; | |
| 35 | if (roc != null) { | |
| 36 | return roc; | |
| 34 | var roCollection = enumerable as ReadOnlyCollection<T>; | |
| 35 | if (roCollection != null) { | |
| 36 | return roCollection; | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | var collection = enumerable as ICollection<T>; |
| ... | ...@@ -48,7 +48,7 @@ | |
| 48 | 48 | private readonly object _singletonClassOf; |
| 49 | 49 | |
| 50 | 50 | // null for singletons: |
| 51 | private readonly Type _underlyingSystemType; | |
| 51 | private Type _underlyingSystemType; | |
| 52 | 52 | private readonly bool _isRubyClass; |
| 53 | 53 | private GlobalScopeExtension _globalScope; |
| 54 | 54 | |
| ... | ...@@ -83,6 +83,10 @@ | |
| 83 | 83 | _globalScope = value; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | protected override bool CanIncludeClrInterface { | |
| 87 | get { return !IsSingletonClass && (_underlyingSystemType == null); } | |
| 88 | } | |
| 89 | ||
| 86 | 90 | #if FALSE |
| 87 | 91 | private Type _extensionType; |
| 88 | 92 | |
| ... | ...@@ -102,6 +106,10 @@ | |
| 102 | 106 | throw new InvalidOperationException("Singleton class doesn't have underlying system type."); |
| 103 | 107 | } |
| 104 | 108 | |
| 109 | if (_underlyingSystemType == null) { | |
| 110 | Interlocked.Exchange(ref _underlyingSystemType, RubyTypeBuilder.GetOrCreateType(_superClass.GetUnderlyingSystemType(), GetClrInterfaces())); | |
| 111 | } | |
| 112 | ||
| 105 | 113 | Debug.Assert(_underlyingSystemType != null); |
| 106 | 114 | return _underlyingSystemType; |
| 107 | 115 | } |
| ... | ...@@ -118,16 +126,16 @@ | |
| 118 | 126 | // friend: RubyExecutionContext |
| 119 | 127 | // tracker: non-null => show members declared on the tracker |
| 120 | 128 | internal RubyClass(RubyExecutionContext/*!*/ context, SymbolId name, Type type, object singletonClassOf, Action<RubyModule> initializer, |
| 121 | RubyClass superClass, TypeTracker tracker, bool isRubyClass) | |
| 129 | RubyClass superClass, TypeTracker tracker, bool isRubyClass, bool isSingletonClass) | |
| 122 | 130 | : base(context, name, initializer, null, tracker) { |
| 123 | ||
| 131 | ||
| 124 | 132 | Debug.Assert((superClass == null) == (type == typeof(object)), "All classes have a superclass, except for Object"); |
| 125 | 133 | Debug.Assert(!isRubyClass || tracker == null, "Ruby class cannot have a tracker"); |
| 126 | Debug.Assert(singletonClassOf != null || type != null, "Singleton classes don't have a type"); | |
| 134 | Debug.Assert(singletonClassOf != null || !isSingletonClass, "Singleton classes don't have a type"); | |
| 127 | 135 | |
| 128 | 136 | _underlyingSystemType = type; |
| 129 | 137 | _superClass = superClass; |
| 130 | _isSingletonClass = type == null; | |
| 138 | _isSingletonClass = isSingletonClass; | |
| 131 | 139 | _isRubyClass = isRubyClass; |
| 132 | 140 | _singletonClassOf = singletonClassOf; |
| 133 | 141 | |
| ... | ...@@ -157,10 +165,10 @@ | |
| 157 | 165 | // expect this type as "self" parameter (this is especially necessary for library types and types deriving from CLR types). |
| 158 | 166 | // - MRI duplicates Object class so that the result doesn't inherit from Object, |
| 159 | 167 | // which we don't do (we want our class hierarchy to be rooted). |
| 160 | Type type = RubyTypeBuilder.GetOrCreateType(GetUnderlyingSystemType()); | |
| 168 | Type type = RubyTypeBuilder.GetOrCreateType(GetUnderlyingSystemType(), Type.EmptyTypes); | |
| 161 | 169 | |
| 162 | 170 | RubyClass result = ExecutionContext.CreateClass(SymbolId.Empty, type, null, null, null, |
| 163 | _superClass ?? ExecutionContext.ObjectClass, null, true | |
| 171 | _superClass ?? ExecutionContext.ObjectClass, null, true, false | |
| 164 | 172 | ); |
| 165 | 173 | |
| 166 | 174 | result.InitializeFrom(this); |
| ... | ...@@ -40,7 +40,7 @@ | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | #if SIGNED || SILVERLIGHT |
| 43 | private const string IronPythonAssembly = "IronPython, Version=2.0.0.3000, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; | |
| 43 | private const string IronPythonAssembly = "IronPython, Version=2.0.0.5000, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; | |
| 44 | 44 | private const string JScriptAssembly = "Microsoft.JScript.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; |
| 45 | 45 | private const string IronRubyAssembly = "IronRuby, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; |
| 46 | 46 | private const string VisualBasicAssembly = "Microsoft.VisualBasic.Scripting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; |
| ... | ...@@ -25,7 +25,7 @@ | |
| 25 | 25 | /// <summary> |
| 26 | 26 | /// More than one method was applicable for the provided parameters and no method was considered the best. |
| 27 | 27 | /// </summary> |
| 28 | AmbigiousMatch, | |
| 28 | AmbiguousMatch, | |
| 29 | 29 | /// <summary> |
| 30 | 30 | /// There are no overloads that match the number of parameters required for the call |
| 31 | 31 | /// </summary> |
| ... | ...@@ -32,9 +32,9 @@ | |
| 32 | 32 | return EmptyReadOnlyCollection<T>.Instance; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | var roc = enumerable as ReadOnlyCollection<T>; | |
| 36 | if (roc != null) { | |
| 37 | return roc; | |
| 35 | var roCollection = enumerable as ReadOnlyCollection<T>; | |
| 36 | if (roCollection != null) { | |
| 37 | return roCollection; | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | var collection = enumerable as ICollection<T>; |
| ... | ...@@ -20,19 +20,19 @@ | |
| 20 | 20 | using System.Diagnostics; |
| 21 | 21 | |
| 22 | 22 | namespace System.Linq.Expressions { |
| 23 | // TODO: expose this to derived classes, so ctor doesn't take three booleans? | |
| 24 | [Flags] | |
| 25 | public enum NodeFlags : byte { | |
| 26 | None = 0, | |
| 27 | Reducible = 1, | |
| 28 | CanRead = 2, | |
| 29 | CanWrite = 4, | |
| 30 | } | |
| 31 | ||
| 32 | 23 | /// <summary> |
| 33 | 24 | /// Expression is the base type for all nodes in Expression Trees |
| 34 | 25 | /// </summary> |
| 35 | 26 | public abstract partial class Expression { |
| 27 | // TODO: expose this to derived classes, so ctor doesn't take three booleans? | |
| 28 | [Flags] | |
| 29 | private enum NodeFlags : byte { | |
| 30 | None = 0, | |
| 31 | Reducible = 1, | |
| 32 | CanRead = 2, | |
| 33 | CanWrite = 4, | |
| 34 | } | |
| 35 | ||
| 36 | 36 | // TODO: these two enums could be stored in one int32 |
| 37 | 37 | private readonly ExpressionType _nodeType; |
| 38 | 38 | private readonly NodeFlags _flags; |
| ... | ...@@ -574,8 +574,8 @@ | |
| 574 | 574 | [RubyMethod("included_modules")] |
| 575 | 575 | public static RubyArray/*!*/ GetIncludedModules(RubyModule/*!*/ self) { |
| 576 | 576 | RubyArray ancestors = new RubyArray(); |
| 577 | self.ForEachAncestor(false, delegate(RubyModule/*!*/ module) { | |
| 578 | if (module != self) { | |
| 577 | self.ForEachAncestor(true, delegate(RubyModule/*!*/ module) { | |
| 578 | if (!module.IsClass && !ancestors.Contains(module)) { | |
| 579 | 579 | ancestors.Add(module); |
| 580 | 580 | } |
| 581 | 581 | return false; |
| ... | ...@@ -47,9 +47,11 @@ | |
| 47 | 47 | /// Console Host entry-point .exe name. |
| 48 | 48 | /// </summary> |
| 49 | 49 | protected virtual string ExeName { |
| 50 | get { | |
| 50 | get { | |
| 51 | 51 | #if !SILVERLIGHT |
| 52 | return Assembly.GetEntryAssembly().GetName().Name; | |
| 52 | Assembly entryAssembly = Assembly.GetEntryAssembly(); | |
| 53 | //Can be null if called from unmanaged code (VS integration scenario) | |
| 54 | return entryAssembly != null ? entryAssembly.GetName().Name : "ConsoleHost"; | |
| 53 | 55 | #else |
| 54 | 56 | return "ConsoleHost"; |
| 55 | 57 | #endif |
| ... | ...@@ -59,8 +59,11 @@ | |
| 59 | 59 | private Dictionary<SymbolId, RubyMemberInfo> _methods; |
| 60 | 60 | private Dictionary<SymbolId, object> _classVariables; |
| 61 | 61 | |
| 62 | // This is stored in the order that mixins are added, but | |
| 63 | // in the reverse order from how methods/constants are searched | |
| 62 | /// <summary> | |
| 63 | /// The entire list of modules included in this one. Newly-added mixins are at the front of the array. | |
| 64 | /// When adding a module that itself contains other modules, Ruby tries to maintain the ordering of the | |
| 65 | /// contained modules so that method resolution is reasonably consistent. | |
| 66 | /// </summary> | |
| 64 | 67 | private RubyModule[]/*!*/ _mixins; |
| 65 | 68 | |
| 66 | 69 | private SymbolId _name; |
| ... | ...@@ -182,7 +185,7 @@ | |
| 182 | 185 | _methods = new Dictionary<SymbolId, RubyMemberInfo>(); |
| 183 | 186 | |
| 184 | 187 | Debug.WriteLine(SymbolTable.IdToString(_name) ?? "<anonymous>", "INITED"); |
| 185 | ||
| 188 | ||
| 186 | 189 | _state = State.Initializing; |
| 187 | 190 | try { |
| 188 | 191 | if (_initializer != null) { |
| ... | ...@@ -214,7 +217,9 @@ | |
| 214 | 217 | |
| 215 | 218 | internal void AddDependentModule(RubyModule/*!*/ dependentModule) { |
| 216 | 219 | Assert.NotNull(dependentModule); |
| 217 | _dependentModules.Add(dependentModule); | |
| 220 | if (!_dependentModules.Contains(dependentModule)) { | |
| 221 | _dependentModules.Add(dependentModule); | |
| 222 | } | |
| 218 | 223 | } |
| 219 | 224 | |
| 220 | 225 | internal void SetDependency(IList<RubyModule>/*!*/ modules) { |
| ... | ...@@ -231,7 +236,7 @@ | |
| 231 | 236 | Debug.WriteLine(String.Format("{0,-50} {1,-30} affected={2,-5} total={3,-5}", Name, reason, affectedModules, counter), "UPDATED"); |
| 232 | 237 | } |
| 233 | 238 | } |
| 234 | ||
| 239 | ||
| 235 | 240 | // TODO: optimize |
| 236 | 241 | internal int Updated(ref int affectedModules) { |
| 237 | 242 | _version = Interlocked.Increment(ref _globalVersion); |
| ... | ...@@ -284,7 +289,7 @@ | |
| 284 | 289 | |
| 285 | 290 | // dependentModules - skip |
| 286 | 291 | // tracker - skip, .NET members not copied |
| 287 | ||
| 292 | ||
| 288 | 293 | Updated("InitializeFrom"); |
| 289 | 294 | } |
| 290 | 295 | |
| ... | ...@@ -307,8 +312,8 @@ | |
| 307 | 312 | public static RubyModule/*!*/ CreateAnonymousModule(CodeContext/*!*/ context, BlockParam block) { |
| 308 | 313 | // TODO: |
| 309 | 314 | throw new NotImplementedException(); |
| 310 | } | |
| 311 | ||
| 315 | } | |
| 316 | ||
| 312 | 317 | public RubyClass/*!*/ CreateSingletonClass() { |
| 313 | 318 | //^ ensures result.IsSingletonClass && !result.IsDummySingletonClass |
| 314 | 319 | |
| ... | ...@@ -332,7 +337,7 @@ | |
| 332 | 337 | return ForEachDeclaredAncestor(action); |
| 333 | 338 | } |
| 334 | 339 | } |
| 335 | ||
| 340 | ||
| 336 | 341 | protected virtual bool ForEachAncestor(Func<RubyModule, bool>/*!*/ action) { |
| 337 | 342 | return ForEachDeclaredAncestor(action); |
| 338 | 343 | } |
| ... | ...@@ -356,7 +361,7 @@ | |
| 356 | 361 | |
| 357 | 362 | public SymbolId MakeNestedModuleName(SymbolId nestedModuleSimpleName) { |
| 358 | 363 | return ReferenceEquals(this, _executionContext.ObjectClass) || nestedModuleSimpleName.IsEmpty ? |
| 359 | nestedModuleSimpleName : | |
| 364 | nestedModuleSimpleName : | |
| 360 | 365 | SymbolTable.StringToId(_name + "::" + nestedModuleSimpleName); |
| 361 | 366 | } |
| 362 | 367 | |
| ... | ...@@ -364,7 +369,7 @@ | |
| 364 | 369 | ForEachAncestor(inherited, delegate(RubyModule/*!*/ module) { |
| 365 | 370 | // notification that we entered the module (it could have no constant): |
| 366 | 371 | if (action(module, SymbolId.Empty, Missing.Value)) return true; |
| 367 | ||
| 372 | ||
| 368 | 373 | return module.EnumerateConstants(action); |
| 369 | 374 | }); |
| 370 | 375 | } |
| ... | ...@@ -376,7 +381,7 @@ | |
| 376 | 381 | EnsureInitialized(); |
| 377 | 382 | _constants[name] = value; |
| 378 | 383 | } |
| 379 | ||
| 384 | ||
| 380 | 385 | // TODO: we don't do dynamic constant lookup, so there is no need to update the class |
| 381 | 386 | // Updated("SetConstant"); |
| 382 | 387 | } |
| ... | ...@@ -434,10 +439,10 @@ | |
| 434 | 439 | } |
| 435 | 440 | |
| 436 | 441 | EnsureInitialized(); |
| 437 | ||
| 442 | ||
| 438 | 443 | if (_constants != null && _constants.TryGetValue(name, out value)) { |
| 439 | 444 | return true; |
| 440 | } | |
| 445 | } | |
| 441 | 446 | |
| 442 | 447 | if (_clrConstants != null && _clrConstants.TryGetValue(name, out value)) { |
| 443 | 448 | value = TrackerToModule(value); |
| ... | ...@@ -453,7 +458,7 @@ | |
| 453 | 458 | if (typeGroup != null) { |
| 454 | 459 | return value; |
| 455 | 460 | } |
| 456 | ||
| 461 | ||
| 457 | 462 | // TypeTracker retrieved from namespace tracker should behave like a RubyClass/RubyModule: |
| 458 | 463 | TypeTracker typeTracker = value as TypeTracker; |
| 459 | 464 | if (typeTracker != null) { |
| ... | ...@@ -505,7 +510,7 @@ | |
| 505 | 510 | // skip interfaces (methods declared on interfaces have already been looked for in the class); |
| 506 | 511 | // if 'this' is an interface, we want to visit all interface methods: |
| 507 | 512 | if (module.IsInterface && !this.IsInterface) return false; |
| 508 | ||
| 513 | ||
| 509 | 514 | // notification that we entered the module (it could have no method): |
| 510 | 515 | if (action(module, SymbolId.Empty, null)) return true; |
| 511 | 516 | |
| ... | ...@@ -530,24 +535,24 @@ | |
| 530 | 535 | // Update only if the current method overrides/redefines another one higher in the inheritance hierarchy. |
| 531 | 536 | // Method lookup failures are not cached in dynamic sites. |
| 532 | 537 | // Therefore a future invocation of the method will trigger resolution in binder that will find just added method. |
| 533 | // If, on the other hand, a method is overriden there might be a dynamic site that caches a method call to that method. | |
| 538 | // If, on the other hand, a method is overridden there might be a dynamic site that caches a method call to that method. | |
| 534 | 539 | // In that case we need to update version to invalidate the site. |
| 535 | ||
| 536 | RubyMemberInfo overridenMethod = ResolveMethodUsedInDynamicSite(name); | |
| 537 | ||
| 540 | ||
| 541 | RubyMemberInfo overriddenMethod = ResolveMethodUsedInDynamicSite(name); | |
| 542 | ||
| 538 | 543 | // TODO: cache this? (definition of method_missing could updated all subclasses): |
| 539 | if (overridenMethod == null) { | |
| 540 | overridenMethod = ResolveMethodUsedInDynamicSite(Symbols.MethodMissing); | |
| 544 | if (overriddenMethod == null) { | |
| 545 | overriddenMethod = ResolveMethodUsedInDynamicSite(Symbols.MethodMissing); | |
| 541 | 546 | // TODO: better check for builtin method |
| 542 | if (overridenMethod != null && overridenMethod.DeclaringModule == ExecutionContext.KernelModule && overridenMethod is RubyMethodGroupInfo) { | |
| 543 | overridenMethod = null; | |
| 547 | if (overriddenMethod != null && overriddenMethod.DeclaringModule == ExecutionContext.KernelModule && overriddenMethod is RubyMethodGroupInfo) { | |
| 548 | overriddenMethod = null; | |
| 544 | 549 | } |
| 545 | 550 | } |
| 546 | 551 | |
| 547 | 552 | EnsureInitialized(); |
| 548 | 553 | _methods[name] = method; |
| 549 | 554 | |
| 550 | if (overridenMethod != null) { | |
| 555 | if (overriddenMethod != null) { | |
| 551 | 556 | // TODO: stop updating if a module that defines a method of the same name is reached: |
| 552 | 557 | Updated("SetMethod: " + name); |
| 553 | 558 | } |
| ... | ...@@ -584,7 +589,7 @@ | |
| 584 | 589 | _methods[name] = RubyMethodInfo.HiddenMethod; |
| 585 | 590 | Updated("HideMethod"); |
| 586 | 591 | } |
| 587 | ||
| 592 | ||
| 588 | 593 | public void HideMethod(string/*!*/ name) { |
| 589 | 594 | HideMethod(SymbolTable.StringToId(name)); |
| 590 | 595 | } |
| ... | ...@@ -789,46 +794,110 @@ | |
| 789 | 794 | Debug.Assert(_mixins.Length == 0); |
| 790 | 795 | Debug.Assert(modules != null && CollectionUtils.TrueForAll(modules, delegate(RubyModule m) { return m != null && !m.IsClass; })); |
| 791 | 796 | |
| 792 | List<RubyModule> allModules = new List<RubyModule>(); | |
| 793 | GetMixinsRecursive(allModules, modules); | |
| 794 | SetDependency(modules); | |
| 795 | ||
| 796 | 797 | // do not initialize modules: |
| 797 | _mixins = allModules.ToArray(); | |
| 798 | _mixins = MakeNewMixins(EmptyArray, modules); | |
| 799 | SetDependency(_mixins); | |
| 798 | 800 | Updated("SetMixins"); |
| 799 | 801 | } |
| 800 | 802 | |
| 801 | 803 | public void IncludeModules(params RubyModule[]/*!*/ modules) { |
| 802 | 804 | Debug.Assert(CollectionUtils.TrueForAll(modules, delegate(RubyModule m) { return m != null && !m.IsClass; })); |
| 803 | 805 | |
| 804 | // transitively include modules: | |
| 805 | List<RubyModule> allModules = new List<RubyModule>(); | |
| 806 | RubyModule[] tmp = MakeNewMixins(_mixins, modules); | |
| 806 | 807 | |
| 807 | for (int i = 0; i < modules.Length; i++) { | |
| 808 | allModules.Add(modules[i]); | |
| 809 | GetMixinsRecursive(allModules, modules[i]._mixins); | |
| 808 | foreach (RubyModule module in tmp) { | |
| 809 | if (module.IsInterface) { | |
| 810 | // Can't include generic interfaces | |
| 811 | if (module.Tracker.Type.ContainsGenericParameters) { | |
| 812 | throw RubyExceptions.CreateTypeError(String.Format( | |
| 813 | "{0}: cannot extend with open generic instantiation {1}. Only closed instantiations are supported.", | |
| 814 | Name, module.Name | |
| 815 | )); | |
| 816 | } | |
| 817 | ||
| 818 | if (!CanIncludeClrInterface) { | |
| 819 | bool alreadyIncluded = false; | |
| 820 | foreach (RubyModule includedModule in _mixins) { | |
| 821 | if (includedModule == module) { | |
| 822 | alreadyIncluded = true; | |
| 823 | break; | |
| 824 | } | |
| 825 | } | |
| 826 | if (!alreadyIncluded) { | |
| 827 | throw new InvalidOperationException(String.Format( | |
| 828 | "Interface {0} cannot be included in class {1} because its underlying type has already been created.", | |
| 829 | module.Name, Name | |
| 830 | )); | |
| 831 | } | |
| 832 | } | |
| 833 | } | |
| 810 | 834 | } |
| 811 | 835 | |
| 812 | SetDependency(allModules); | |
| 836 | SetDependency(tmp); | |
| 813 | 837 | |
| 814 | 838 | // initialize added modules: |
| 815 | 839 | if (_state == State.Initialized) { |
| 816 | for (int i = 0; i < allModules.Count; i++) { | |
| 817 | allModules[i].EnsureInitialized(); | |
| 840 | foreach (RubyModule module in tmp) { | |
| 841 | module.EnsureInitialized(); | |
| 818 | 842 | } |
| 819 | 843 | } |
| 820 | 844 | |
| 821 | // new modules are inserted at the beginning so they come first in MRO | |
| 822 | _mixins = ArrayUtils.InsertAt(_mixins, 0, allModules.ToArray()); | |
| 845 | _mixins = tmp; | |
| 823 | 846 | |
| 824 | 847 | Updated("IncludeModules"); |
| 825 | 848 | } |
| 826 | 849 | |
| 827 | internal static void GetMixinsRecursive(List<RubyModule>/*!*/ result, IList<RubyModule>/*!*/ modules) { | |
| 828 | for (int i = 0; i < modules.Count; i++) { | |
| 829 | result.Add(modules[i]); | |
| 830 | GetMixinsRecursive(result, modules[i]._mixins); | |
| 850 | /// <summary> | |
| 851 | /// Build a new list of mixins based on an original list and a list of added modules | |
| 852 | /// </summary> | |
| 853 | private RubyModule[]/*!*/ MakeNewMixins(RubyModule[]/*!*/ original, IList<RubyModule/*!*/>/*!*/ updates) { | |
| 854 | Assert.NotNull(original); | |
| 855 | Assert.NotNull(updates); | |
| 856 | ||
| 857 | List<RubyModule> tmp = new List<RubyModule>(original); | |
| 858 | AddMixins(tmp, 0, updates, true); | |
| 859 | return tmp.ToArray(); | |
| 860 | } | |
| 861 | ||
| 862 | private int AddMixins(List<RubyModule/*!*/>/*!*/ list, int index, IList<RubyModule/*!*/>/*!*/ updates, bool recursive) { | |
| 863 | foreach (RubyModule module in updates) { | |
| 864 | Assert.NotNull(module); | |
| 865 | ||
| 866 | if (module == this) { | |
| 867 | throw RubyExceptions.CreateArgumentError("cyclic include detected"); | |
| 868 | } | |
| 869 | int newIndex = list.IndexOf(module); | |
| 870 | if (newIndex < 0) { | |
| 871 | // Module is not yet present in _mixins | |
| 872 | // Recursively insert module dependencies at the insertion point, then insert module itself | |
| 873 | newIndex = AddMixins(list, index, module._mixins, false); | |
| 874 | list.Insert(index, module); | |
| 875 | index = newIndex + 1; | |
| 876 | } else { | |
| 877 | // Module is already present in _mixins | |
| 878 | // Update the insertion point so that we retain ordering of dependencies | |
| 879 | // If we're still in the initial level of recursion, repeat for module's mixins | |
| 880 | index = newIndex + 1; | |
| 881 | if (recursive) { | |
| 882 | index = AddMixins(list, index, module._mixins, false); | |
| 883 | } | |
| 884 | } | |
| 831 | 885 | } |
| 886 | return index; | |
| 887 | } | |
| 888 | ||
| 889 | protected virtual bool CanIncludeClrInterface { | |
| 890 | get { return true; } | |
| 891 | } | |
| 892 | ||
| 893 | protected List<Type> GetClrInterfaces() { | |
| 894 | List<Type> interfaces = new List<Type>(); | |
| 895 | foreach (RubyModule m in _mixins) { | |
| 896 | if (m.IsInterface && !interfaces.Contains(m.Tracker.Type)) { | |
| 897 | interfaces.Add(m.Tracker.Type); | |
| 898 | } | |
| 899 | } | |
| 900 | return interfaces; | |
| 832 | 901 | } |
| 833 | 902 | |
| 834 | 903 | internal void IncludeTrait(Action<RubyModule>/*!*/ trait) { |
| ... | ...@@ -848,7 +917,7 @@ | |
| 848 | 917 | |
| 849 | 918 | internal void IncludeLibraryModule(Action<RubyModule> instanceTrait, Action<RubyModule> classTrait, RubyModule[]/*!*/ mixins) { |
| 850 | 919 | Assert.NotNull(mixins); |
| 851 | ||
| 920 | ||
| 852 | 921 | IncludeModules(mixins); |
| 853 | 922 | |
| 854 | 923 | if (instanceTrait != null) { |
| ... | ...@@ -865,7 +934,7 @@ | |
| 865 | 934 | internal void AddFullVersionTest(MetaObjectBuilder/*!*/ metaBuilder, MSA.Expression/*!*/ codeContextExpression) { |
| 866 | 935 | Assert.NotNull(metaBuilder); |
| 867 | 936 | EnsureInitialized(); // Initialization changes the version number, so ensure that the module is initialized |
| 868 | ||
| 937 | ||
| 869 | 938 | // TODO: runtime check could be a restriction |
| 870 | 939 | metaBuilder.AddCondition(AstFactory.OpCall("CheckVersionAndRuntime", |
| 871 | 940 | codeContextExpression, |
| ... | ...@@ -463,7 +463,11 @@ | |
| 463 | 463 | doc = REXML::Document.new(File.open(cs_proj_files.first)) |
| 464 | 464 | result = doc.elements.collect("/Project/ItemGroup/Compile") { |c| "\"#{c.attributes['Include']}\"" } |
| 465 | 465 | result.delete_if { |e| e =~ /Silverlight\\SilverlightVersion.cs/ } |
| 466 | result | |
| 466 | if ENV['mono'].nil? | |
| 467 | result | |
| 468 | else | |
| 469 | result.map { |p| p.gsub('\\', '/') } | |
| 470 | end | |
| 467 | 471 | else |
| 468 | 472 | raise ArgumentError.new("Found more than one .csproj file in directory! #{cs_proj_files.join(", ")}") |
| 469 | 473 | end |
| ... | ...@@ -484,11 +488,9 @@ | |
| 484 | 488 | args[:resources].each_value { |res| cs_args << "resource:\"#{build_path + res}\"" } |
| 485 | 489 | end |
| 486 | 490 | |
| 487 | cs_args << "recurse:*.cs" | |
| 488 | ||
| 489 | 491 | switches = '' |
| 490 | 492 | cs_args.each { |opt| switches << ' /' + opt } |
| 491 | cmd = CS_COMPILER + switches | |
| 493 | cmd = CS_COMPILER + switches + ' ' + get_compile_path_list.join(" ") | |
| 492 | 494 | exec cmd |
| 493 | 495 | end |
| 494 | 496 | end |
| ... | ...@@ -717,7 +719,6 @@ | |
| 717 | 719 | cmd = %Q{"#{UserEnvironment.mri_binary}" "#{UserEnvironment.mspec}/bin/mspec" ci -t #{ruby} -fm -V -B "#{UserEnvironment.config}" "#{UserEnvironment.rubyspec}/1.8/core/#{klass}"} |
| 718 | 720 | cmd += "/#{method}_spec.rb" unless method.nil? |
| 719 | 721 | cmd += " > #{tempdir}/out.txt" |
| 720 | puts cmd | |
| 721 | 722 | system cmd |
| 722 | 723 | File.open("#{tempdir}/out.txt", 'r') do |f| |
| 723 | 724 | lines = f.readlines |
| ... | ...@@ -823,8 +824,6 @@ | |
| 823 | 824 | unless defined?(UserEnvironment::MRI) |
| 824 | 825 | ruby_exe_paths = UserEnvironment.find_executable 'ruby' |
| 825 | 826 | unless ruby_exe_paths.empty? |
| 826 | puts ">>>" | |
| 827 | puts ruby_exe_paths.first | |
| 828 | 827 | UserEnvironment.const_set(:MRI, Pathname.new(ruby_exe_paths.first + '\..\\')) |
| 829 | 828 | else |
| 830 | 829 | raise ArgumentError.new("Could not find ruby.exe on your path") |
| ... | ...@@ -57,7 +57,7 @@ | |
| 57 | 57 | [assembly: InternalsVisibleTo("TestInternalDLR, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] |
| 58 | 58 | |
| 59 | 59 | #if !SILVERLIGHT |
| 60 | [assembly: AssemblyVersion("1.0.0.3000")] | |
| 60 | [assembly: AssemblyVersion("1.0.0.5000")] | |
| 61 | 61 | [assembly: AssemblyFileVersion("1.0.0.00")] |
| 62 | 62 | [assembly: AssemblyInformationalVersion("1.0")] |
| 63 | 63 | [assembly: AllowPartiallyTrustedCallers] |
| ... | ...@@ -90,7 +90,7 @@ | |
| 90 | 90 | SymbolId toMethodName = ToMethodName; |
| 91 | 91 | string targetClassName = SymbolTable.IdToString(ec.GetClassOf(args.Target).Name); |
| 92 | 92 | |
| 93 | // Kernel#respond_to? method is not overriden => we could optimize | |
| 93 | // Kernel#respond_to? method is not overridden => we could optimize | |
| 94 | 94 | RubyMemberInfo respondToMethod = ec.ResolveMethodForSite(args.Target, Symbols.RespondTo); |
| 95 | 95 | if (respondToMethod == null || |
| 96 | 96 | // the method is defined in library, hasn't been replaced by user defined method (TODO: maybe we should make this check better) |
| ... | ...@@ -0,0 +1,109 @@ | |
| 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 | ||
| 16 | using System; | |
| 17 | using System.Collections.Generic; | |
| 18 | using Microsoft.Scripting.Utils; | |
| 19 | ||
| 20 | namespace Ruby.Compiler.Generation { | |
| 21 | ||
| 22 | /// <summary> | |
| 23 | /// TypeDescription captures the minimal information required by TypeBuilder to define a distinct CLS type | |
| 24 | /// </summary> | |
| 25 | internal class TypeDescription { | |
| 26 | // The CLI base-type. | |
| 27 | private readonly Type/*!*/ _baseType; | |
| 28 | ||
| 29 | private readonly List<Type/*!*/>/*!*/ _interfaceTypes; | |
| 30 | protected int? _hash; | |
| 31 | ||
| 32 | public TypeDescription(Type/*!*/ baseType) | |
| 33 | : this(baseType, Type.EmptyTypes) { | |
| 34 | } | |
| 35 | ||
| 36 | public TypeDescription(Type/*!*/ baseType, IList<Type>/*!*/ interfaceTypes) { | |
| 37 | Assert.NotNull(baseType); | |
| 38 | Assert.NotNull(interfaceTypes); | |
| 39 | ||
| 40 | _baseType = baseType; | |
| 41 | _interfaceTypes = new List<Type>(interfaceTypes.Count); | |
| 42 | foreach (Type t in interfaceTypes) { | |
| 43 | AddInterface(t); | |
| 44 | } | |
| 45 | SortInterfaces(); | |
| 46 | } | |
| 47 | ||
| 48 | public Type/*!*/ BaseType { | |
| 49 | get { return _baseType; } | |
| 50 | } | |
| 51 | ||
| 52 | public IList<Type/*!*/>/*!*/ InterfaceTypes { | |
| 53 | get { return _interfaceTypes; } | |
| 54 | } | |
| 55 | ||
| 56 | protected void AddInterface(Type/*!*/ type) { | |
| 57 | Assert.NotNull(type); | |
| 58 | Assert.Equals(true, type.IsInterface && !type.ContainsGenericParameters); | |
| 59 | ||
| 60 | for (int i = 0; i < _interfaceTypes.Count; i++) { | |
| 61 | Type t = _interfaceTypes[i]; | |
| 62 | if (t == type || type.IsAssignableFrom(t)) { | |
| 63 | // This interface is already included in the list | |
| 64 | return; | |
| 65 | } | |
| 66 | if (t.IsAssignableFrom(type)) { | |
| 67 | // We are going to supercede this interface | |
| 68 | _interfaceTypes.RemoveAt(i--); | |
| 69 | } | |
| 70 | } | |
| 71 | _interfaceTypes.Add(type); | |
| 72 | _hash = null; | |
| 73 | } | |
| 74 | ||
| 75 | protected void SortInterfaces() { | |
| 76 | _interfaceTypes.Sort(delegate(Type a, Type b) { return a.FullName.CompareTo(b.FullName); }); | |
| 77 | } | |
| 78 | ||
| 79 | public override int GetHashCode() { | |
| 80 | if (_hash == null) { | |
| 81 | int hashCode = _baseType.GetHashCode(); | |
| 82 | for (int i = 0; i < _interfaceTypes.Count; i++) { | |
| 83 | hashCode ^= _interfaceTypes[i].GetHashCode(); | |
| 84 | } | |
| 85 | _hash = hashCode; | |
| 86 | } | |
| 87 | ||
| 88 | return _hash.Value; | |
| 89 | } | |
| 90 | ||
| 91 | public override bool Equals(object obj) { | |
| 92 | TypeDescription other = obj as TypeDescription; | |
| 93 | if (other == null) return false; | |
| 94 | ||
| 95 | if (_baseType.Equals(other._baseType) && | |
| 96 | _interfaceTypes.Count == other._interfaceTypes.Count) { | |
| 97 | ||
| 98 | for (int i = 0; i < _interfaceTypes.Count; i++) { | |
| 99 | if (!_interfaceTypes[i].Equals(other._interfaceTypes[i])) { | |
| 100 | return false; | |
| 101 | } | |
| 102 | } | |
| 103 | ||
| 104 | return true; | |
| 105 | } | |
| 106 | return false; | |
| 107 | } | |
| 108 | } | |
| 109 | } |
| ... | ...@@ -300,7 +300,11 @@ | |
| 300 | 300 | RubyClass theClass = _rubyContext.GetClassOf(obj); |
| 301 | 301 | TestForAnonymous(theClass); |
| 302 | 302 | WriteSymbol(theClass.Name); |
| 303 | WriteString(_DumpSite.Target(_DumpSite, _context, obj, _recursionLimit)); | |
| 303 | MutableString dumpResult = (_DumpSite.Target(_DumpSite, _context, obj, _recursionLimit) as MutableString); | |
| 304 | if (dumpResult == null) { | |
| 305 | throw RubyExceptions.CreateTypeError("_dump() must return string"); | |
| 306 | } | |
| 307 | WriteString(dumpResult); | |
| 304 | 308 | } |
| 305 | 309 | |
| 306 | 310 | void WriteUsingMarshalDump(object/*!*/ obj) { |
| ... | ...@@ -57,7 +57,7 @@ | |
| 57 | 57 | /// $KCODE |
| 58 | 58 | /// </summary> |
| 59 | 59 | private static KCode _kcode; |
| 60 | ||
| 60 | ||
| 61 | 61 | /// <summary> |
| 62 | 62 | /// $/, $-O |
| 63 | 63 | /// </summary> |
| ... | ...@@ -183,7 +183,7 @@ | |
| 183 | 183 | ); |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | site.Target(site, context, obj, methodName); | |
| 186 | site.Target(site, context, obj, methodName); | |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | private void ClassInheritedEvent(RubyClass/*!*/ superClass, RubyClass/*!*/ subClass) { |
| ... | ...@@ -201,8 +201,8 @@ | |
| 201 | 201 | #endregion |
| 202 | 202 | |
| 203 | 203 | public Exception CurrentException { |
| 204 | get { return _currentException; } | |
| 205 | set { _currentException = value; } | |
| 204 | get { return _currentException; } | |
| 205 | set { _currentException = value; } | |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | public |