| CODENOTIFIER | HelpYou are not signed inSign in |
Project: IronRuby
Revision: 137
Author: jlam
Date: 22 Aug 2008 17:18:41
Changes:FXCop work + misc rubyforge bug fixes
Files:| ... | ...@@ -568,13 +568,8 @@ | |
| 568 | 568 | private static readonly Type IEnumerableType = typeof(IEnumerable); |
| 569 | 569 | private static readonly Type ValueTypeType = typeof(ValueType); |
| 570 | 570 | private static readonly Type TypeType = typeof(Type); |
| 571 | #if !SILVERLIGHT | |
| 572 | private static readonly Type ArrayListType = typeof(ArrayList); | |
| 573 | private static readonly Type HashtableType = typeof(Hashtable); | |
| 574 | #endif | |
| 575 | 571 | private static readonly Type NullableOfTType = typeof(Nullable<>); |
| 576 | 572 | private static readonly Type IListOfTType = typeof(System.Collections.Generic.IList<>); |
| 577 | private static readonly Type ListOfTType = typeof(System.Collections.Generic.List<>); | |
| 578 | 573 | private static readonly Type IDictOfTType = typeof(System.Collections.Generic.IDictionary<,>); |
| 579 | 574 | private static readonly Type IEnumerableOfTType = typeof(System.Collections.Generic.IEnumerable<>); |
| 580 | 575 | private static readonly Type IListOfObjectType = typeof(System.Collections.Generic.IList<object>); |
| ... | ...@@ -13,6 +13,7 @@ | |
| 13 | 13 | * |
| 14 | 14 | * ***************************************************************************/ |
| 15 | 15 | |
| 16 | using System.Collections.Generic; | |
| 16 | 17 | using System.Collections.ObjectModel; |
| 17 | 18 | using System.Diagnostics; |
| 18 | 19 | using System.Reflection; |
| ... | ...@@ -77,6 +78,10 @@ | |
| 77 | 78 | case ExpressionType.Call: |
| 78 | 79 | AddressOf((MethodCallExpression)node, type); |
| 79 | 80 | break; |
| 81 | ||
| 82 | case ExpressionType.Index: | |
| 83 | AddressOf((IndexExpression)node, type); | |
| 84 | break; | |
| 80 | 85 | } |
| 81 | 86 | } |
| 82 | 87 | |
| ... | ...@@ -233,6 +238,22 @@ | |
| 233 | 238 | } |
| 234 | 239 | } |
| 235 | 240 | |
| 241 | private void AddressOf(IndexExpression node, Type type) { | |
| 242 | if (type != node.Type || node.Indexer != null) { | |
| 243 | EmitExpressionAddress(node, type); | |
| 244 | return; | |
| 245 | } | |
| 246 | ||
| 247 | if (node.Arguments.Count == 1) { | |
| 248 | EmitExpression(node.Object); | |
| 249 | EmitExpression(node.Arguments[0]); | |
| 250 | _ilg.Emit(OpCodes.Ldelema, node.Type); | |
| 251 | } else { | |
| 252 | var address = node.Object.Type.GetMethod("Address", BindingFlags.Public | BindingFlags.Instance); | |
| 253 | EmitMethodCall(node.Object, address, node.Arguments); | |
| 254 | } | |
| 255 | } | |
| 256 | ||
| 236 | 257 | private void AddressOf(UnaryExpression node, Type type) { |
| 237 | 258 | Debug.Assert(node.NodeType == ExpressionType.Unbox); |
| 238 | 259 | Debug.Assert(type.IsValueType && !TypeUtils.IsNullableType(type)); |
| ... | ...@@ -251,5 +272,123 @@ | |
| 251 | 272 | _ilg.Emit(OpCodes.Ldloca, tmp); |
| 252 | 273 | _ilg.FreeLocal(tmp); |
| 253 | 274 | } |
| 275 | ||
| 276 | ||
| 277 | // Emits the address of the expression, returning the write back if necessary | |
| 278 | // | |
| 279 | // For properties, we want to write back into the property if it's | |
| 280 | // passed byref. | |
| 281 | // | |
| 282 | // Note: ExpressionCompiler thinks it needs to writeback | |
| 283 | // fields, but as far as I can tell, that code path is | |
| 284 | // unreachable because fields can always emit their address | |
| 285 | private WriteBack EmitAddressWriteBack(Expression node, Type type) { | |
| 286 | WriteBack result = null; | |
| 287 | if (type == node.Type) { | |
| 288 | switch (node.NodeType) { | |
| 289 | case ExpressionType.MemberAccess: | |
| 290 | result = AddressOfWriteBack((MemberExpression)node); | |
| 291 | break; | |
| 292 | case ExpressionType.Index: | |
| 293 | result = AddressOfWriteBack((IndexExpression)node); | |
| 294 | break; | |
| 295 | } | |
| 296 | } | |
| 297 | if (result == null) { | |
| 298 | EmitAddress(node, type); | |
| 299 | } | |
| 300 | return result; | |
| 301 | } | |
| 302 | ||
| 303 | private WriteBack AddressOfWriteBack(MemberExpression node) { | |
| 304 | if (!node.CanWrite || node.Member.MemberType != MemberTypes.Property) { | |
| 305 | return null; | |
| 306 | } | |
| 307 | ||
| 308 | // emit instance, if any | |
| 309 | LocalBuilder instanceLocal = null; | |
| 310 | Type instanceType = null; | |
| 311 | if (node.Expression != null) { | |
| 312 | EmitInstance(node.Expression, instanceType = node.Expression.Type); | |
| 313 | // store in local | |
| 314 | _ilg.Emit(OpCodes.Dup); | |
| 315 | _ilg.Emit(OpCodes.Stloc, instanceLocal = _ilg.GetLocal(instanceType)); | |
| 316 | } | |
| 317 | ||
| 318 | PropertyInfo pi = (PropertyInfo)node.Member; | |
| 319 | ||
| 320 | // emit the get | |
| 321 | EmitCall(instanceType, pi.GetGetMethod(true)); | |
| 322 | ||
| 323 | // emit the address of the value | |
| 324 | var valueLocal = _ilg.GetLocal(node.Type); | |
| 325 | _ilg.Emit(OpCodes.Stloc, valueLocal); | |
| 326 | _ilg.Emit(OpCodes.Ldloca, valueLocal); | |
| 327 | ||
| 328 | // Set the property after the method call | |
| 329 | // don't re-evaluate anything | |
| 330 | return delegate() { | |
| 331 | if (instanceLocal != null) { | |
| 332 | _ilg.Emit(OpCodes.Ldloc, instanceLocal); | |
| 333 | _ilg.FreeLocal(instanceLocal); | |
| 334 | } | |
| 335 | _ilg.Emit(OpCodes.Ldloc, valueLocal); | |
| 336 | _ilg.FreeLocal(valueLocal); | |
| 337 | EmitCall(instanceType, pi.GetSetMethod(true)); | |
| 338 | }; | |
| 339 | } | |
| 340 | ||
| 341 | private WriteBack AddressOfWriteBack(IndexExpression node) { | |
| 342 | if (!node.CanWrite || node.Indexer == null) { | |
| 343 | return null; | |
| 344 | } | |
| 345 | ||
| 346 | // emit instance, if any | |
| 347 | LocalBuilder instanceLocal = null; | |
| 348 | Type instanceType = null; | |
| 349 | if (node.Object != null) { | |
| 350 | EmitInstance(node.Object, instanceType = node.Object.Type); | |
| 351 | ||
| 352 | _ilg.Emit(OpCodes.Dup); | |
| 353 | _ilg.Emit(OpCodes.Stloc, instanceLocal = _ilg.GetLocal(instanceType)); | |
| 354 | } | |
| 355 | ||
| 356 | // Emit indexes. We don't allow byref args, so no need to worry | |
| 357 | // about writebacks or EmitAddress | |
| 358 | List<LocalBuilder> args = new List<LocalBuilder>(); | |
| 359 | foreach (var arg in node.Arguments) { | |
| 360 | EmitExpression(arg); | |
| 361 | ||
| 362 | var argLocal = _ilg.GetLocal(arg.Type); | |
| 363 | _ilg.Emit(OpCodes.Dup); | |
| 364 | _ilg.Emit(OpCodes.Stloc, argLocal); | |
| 365 | args.Add(argLocal); | |
| 366 | } | |
| 367 | ||
| 368 | // emit the get | |
| 369 | EmitGetIndexCall(node, instanceType); | |
| 370 | ||
| 371 | // emit the address of the value | |
| 372 | var valueLocal = _ilg.GetLocal(node.Type); | |
| 373 | _ilg.Emit(OpCodes.Stloc, valueLocal); | |
| 374 | _ilg.Emit(OpCodes.Ldloca, valueLocal); | |
| 375 | ||
| 376 | // Set the property after the method call | |
| 377 | // don't re-evaluate anything | |
| 378 | return delegate() { | |
| 379 | if (instanceLocal != null) { | |
| 380 | _ilg.Emit(OpCodes.Ldloc, instanceLocal); | |
| 381 | _ilg.FreeLocal(instanceLocal); | |
| 382 | } | |
| 383 | foreach (var arg in args) { | |
| 384 | _ilg.Emit(OpCodes.Ldloc, arg); | |
| 385 | _ilg.FreeLocal(arg); | |
| 386 | } | |
| 387 | _ilg.Emit(OpCodes.Ldloc, valueLocal); | |
| 388 | _ilg.FreeLocal(valueLocal); | |
| 389 | ||
| 390 | EmitSetIndexCall(node, instanceType); | |
| 391 | }; | |
| 392 | } | |
| 254 | 393 | } |
| 255 | 394 | } |
| ... | ...@@ -326,7 +326,9 @@ | |
| 326 | 326 | #if !SILVERLIGHT |
| 327 | 327 | internal sealed class DebugView { |
| 328 | 328 | private readonly RubyScope/*!*/ _scope; |
| 329 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] | |
| 329 | 330 | private readonly string/*!*/ _selfClassName; |
| 331 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] | |
| 330 | 332 | private readonly string/*!*/ _matchClassName; |
| 331 | 333 | |
| 332 | 334 | public DebugView(RubyScope/*!*/ scope) { |
| ... | ...@@ -477,7 +479,6 @@ | |
| 477 | 479 | public override ScopeKind Kind { get { return ScopeKind.TopLevel; } } |
| 478 | 480 | public override bool InheritsLocalVariables { get { return false; } } |
| 479 | 481 | |
| 480 | private readonly bool _isMain; | |
| 481 | 482 | private readonly GlobalScopeExtension/*!*/ _globalScope; |
| 482 | 483 | private RubyModule _definitionsModule; |
| 483 | 484 | |
| ... | ...@@ -497,11 +498,10 @@ | |
| 497 | 498 | get { return _definitionsModule ?? _globalScope.ExecutionContext.ObjectClass; } |
| 498 | 499 | } |
| 499 | 500 | |
| 500 | internal RubyTopLevelScope(GlobalScopeExtension/*!*/ globalScope, bool isMain, RubyModule definitionsModule, IAttributesCollection/*!*/ frame) | |
| 501 | internal RubyTopLevelScope(GlobalScopeExtension/*!*/ globalScope, RubyModule definitionsModule, IAttributesCollection/*!*/ frame) | |
| 501 | 502 | : base(globalScope.ExecutionContext.Context, frame) { |
| 502 | 503 | Assert.NotNull(globalScope); |
| 503 | 504 | _globalScope = globalScope; |
| 504 | _isMain = isMain; | |
| 505 | 505 | _definitionsModule = definitionsModule; |
| 506 | 506 | } |
| 507 | 507 |
| ... | ...@@ -26,7 +26,9 @@ | |
| 26 | 26 | using AstFactory = IronRuby.Compiler.Ast.AstFactory; |
| 27 | 27 | |
| 28 | 28 | public abstract class RubyAttributeAccessorInfo : RubyMemberInfo { |
| 29 | protected readonly SymbolId _instanceVariableName; | |
| 29 | private readonly SymbolId _instanceVariableName; | |
| 30 | ||
| 31 | protected SymbolId InstanceVariableName { get { return _instanceVariableName; } } | |
| 30 | 32 | |
| 31 | 33 | protected RubyAttributeAccessorInfo(RubyMethodVisibility visibility, RubyModule/*!*/ declaringModule, string/*!*/ name) |
| 32 | 34 | : base(visibility, declaringModule) { |
| ... | ...@@ -45,7 +47,7 @@ | |
| 45 | 47 | metaBuilder.Result = AstFactory.OpCall("GetInstanceVariable", |
| 46 | 48 | args.CodeContextExpression, |
| 47 | 49 | Ast.Convert(args.TargetExpression, typeof(object)), |
| 48 | AstUtils.Constant(_instanceVariableName) | |
| 50 | AstUtils.Constant(InstanceVariableName) | |
| 49 | 51 | ); |
| 50 | 52 | } |
| 51 | 53 | } |
| ... | ...@@ -64,7 +66,7 @@ | |
| 64 | 66 | Ast.Convert(actualArgs[0], typeof(object)), |
| 65 | 67 | Ast.Convert(actualArgs[1], typeof(object)), |
| 66 | 68 | args.CodeContextExpression, |
| 67 | AstUtils.Constant(_instanceVariableName) | |
| 69 | AstUtils.Constant(InstanceVariableName) | |
| 68 | 70 | ); |
| 69 | 71 | } |
| 70 | 72 | } |
| ... | ...@@ -19,6 +19,7 @@ | |
| 19 | 19 | using Microsoft.Scripting.Utils; |
| 20 | 20 | using IronRuby.Runtime; |
| 21 | 21 | using IronRuby.Runtime.Calls; |
| 22 | using System.Security.Permissions; | |
| 22 | 23 | |
| 23 | 24 | namespace IronRuby.Builtins { |
| 24 | 25 | public partial class RubyObject : IRubyObject, ISerializable { |
| ... | ...@@ -37,6 +38,7 @@ | |
| 37 | 38 | RubyOps.DeserializeObject(out _instanceData, out _class, info); |
| 38 | 39 | } |
| 39 | 40 | |
| 41 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] | |
| 40 | 42 | public void GetObjectData(SerializationInfo/*!*/ info, StreamingContext context) { |
| 41 | 43 | RubyOps.SerializeObject(_instanceData, _class, info); |
| 42 | 44 | } |
| ... | ...@@ -53,8 +53,8 @@ | |
| 53 | 53 | |
| 54 | 54 | #region constructors, compile |
| 55 | 55 | |
| 56 | private static readonly CallSite<DynamicSiteTarget<CodeContext, RubyClass, MutableString, object, object, RubyRegex>>/*!*/ NewCallSite3 = | |
| 57 | CallSite<DynamicSiteTarget<CodeContext, RubyClass, MutableString, object, object, RubyRegex>>.Create(RubySites.InstanceCallAction("new")); | |
| 56 | private static readonly CallSite<Func<CallSite, CodeContext, RubyClass, MutableString, object, object, RubyRegex>>/*!*/ NewCallSite3 = | |
| 57 | CallSite<Func<CallSite, CodeContext, RubyClass, MutableString, object, object, RubyRegex>>.Create(RubySites.InstanceCallAction("new")); | |
| 58 | 58 | |
| 59 | 59 | [RubyConstructor] |
| 60 | 60 | public static RubyRegex/*!*/ Create([NotNull]RubyRegex/*!*/ other) { |
| ... | ...@@ -25,8 +25,7 @@ | |
| 25 | 25 | /// VariableExpression |
| 26 | 26 | /// ParameterExpression |
| 27 | 27 | /// MemberExpression with writable property/field |
| 28 | /// BinaryExpression with NodeType == ArrayIndex | |
| 29 | /// IndexedPropertyExpression | |
| 28 | /// IndexExpression | |
| 30 | 29 | /// |
| 31 | 30 | /// TODO: merge into BinaryExpression |
| 32 | 31 | /// </summary> |
| ... | ...@@ -77,6 +76,7 @@ | |
| 77 | 76 | return new AssignmentExpression(annotations, left, right); |
| 78 | 77 | } |
| 79 | 78 | |
| 79 | // TODO: remove? | |
| 80 | 80 | /// <summary> |
| 81 | 81 | /// Creates MemberExpression representing field access, instance or static. |
| 82 | 82 | /// For static field, expression must be null and FieldInfo.IsStatic == true |
| ... | ...@@ -90,6 +90,7 @@ | |
| 90 | 90 | return Assign(Field(expression, field), value); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | // TODO: remove? | |
| 93 | 94 | /// <summary> |
| 94 | 95 | /// Creates MemberExpression representing property access, instance or static. |
| 95 | 96 | /// For static properties, expression must be null and property.IsStatic == true. |
| ... | ...@@ -103,8 +104,9 @@ | |
| 103 | 104 | return Assign(Property(expression, property), value); |
| 104 | 105 | } |
| 105 | 106 | |
| 107 | // TODO: remove or rename to 'AssignArrayAccess', allow multiple indexes | |
| 106 | 108 | public static AssignmentExpression AssignArrayIndex(Expression array, Expression index, Expression value) { |
| 107 | return Assign(ArrayIndex(array, index), value); | |
| 109 | return Assign(ArrayAccess(array, index), value); | |
| 108 | 110 | } |
| 109 | 111 | } |
| 110 | 112 | } |
| ... | ...@@ -105,8 +105,7 @@ | |
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | // TODO: private (tests) | |
| 109 | public BigInteger/*!*/ ParseDefault(int digitCount, uint @base) { | |
| 108 | internal BigInteger/*!*/ ParseDefault(int digitCount, uint @base) { | |
| 110 | 109 | uint wordBase = 1; |
| 111 | 110 | int digitsPerWord = 0; |
| 112 | 111 | while (true) { |
| ... | ...@@ -47,7 +47,7 @@ | |
| 47 | 47 | builder.Append("Invoke("); |
| 48 | 48 | _lambda.BuildString(builder); |
| 49 | 49 | for (int i = 0, n = _arguments.Count; i < n; i++) { |
| 50 | builder.Append(","); | |
| 50 | builder.Append(", "); | |
| 51 | 51 | _arguments[i].BuildString(builder); |
| 52 | 52 | } |
| 53 | 53 | builder.Append(")"); |
| ... | ...@@ -15,11 +15,14 @@ | |
| 15 | 15 | |
| 16 | 16 | using System; |
| 17 | 17 | using System.Collections.Generic; |
| 18 | using System.Collections.ObjectModel; | |
| 18 | 19 | using System.Diagnostics; |
| 20 | using System.Linq.Expressions; | |
| 19 | 21 | using System.Runtime.Remoting; |
| 20 | 22 | using System.Runtime.Serialization; |
| 21 | using Microsoft.Scripting.Utils; | |
| 23 | using System.Scripting.Actions; | |
| 22 | 24 | using Microsoft.Scripting.Runtime; |
| 25 | using Microsoft.Scripting.Utils; | |
| 23 | 26 | |
| 24 | 27 | namespace Microsoft.Scripting.Hosting { |
| 25 | 28 | /// <summary> |
| ... | ...@@ -33,10 +36,10 @@ | |
| 33 | 36 | /// Hosting API counterpart for <see cref="Scope"/>. |
| 34 | 37 | /// </summary> |
| 35 | 38 | #if SILVERLIGHT |
| 36 | public sealed class ScriptScope { | |
| 39 | public sealed class ScriptScope : IDynamicObject { | |
| 37 | 40 | #else |
| 38 | 41 | [DebuggerTypeProxy(typeof(ScriptScope.DebugView))] |
| 39 | public sealed class ScriptScope : MarshalByRefObject { | |
| 42 | public sealed class ScriptScope : MarshalByRefObject, IDynamicObject { | |
| 40 | 43 | #endif |
| 41 | 44 | private readonly Scope _scope; |
| 42 | 45 | private readonly ScriptEngine _engine; |
| ... | ...@@ -259,5 +262,140 @@ | |
| 259 | 262 | } |
| 260 | 263 | #endif |
| 261 | 264 | #endregion |
| 265 | ||
| 266 | #region IDynamicObject implementation | |
| 267 | ||
| 268 | MetaObject IDynamicObject.GetMetaObject(Expression parameter) { | |
| 269 | return new Meta(parameter, this); | |
| 270 | } | |
| 271 | ||
| 272 | private sealed class Meta : MetaObject { | |
| 273 | internal Meta(Expression parameter, ScriptScope scope) | |
| 274 | : base(parameter, Restrictions.Empty, scope) { | |
| 275 | } | |
| 276 | ||
| 277 | // TODO: support for IgnoreCase in underlying ScriptScope APIs | |
| 278 | public override MetaObject GetMember(GetMemberAction action, MetaObject[] args) { | |
| 279 | var result = Expression.Variable(typeof(object), "result"); | |
| 280 | var fallback = action.Fallback(args); | |
| 281 | var instance = Restrict(typeof(ScriptScope)); | |
| 282 | return new MetaObject( | |
| 283 | Expression.Scope( | |
| 284 | Expression.Condition( | |
| 285 | Expression.Call( | |
| 286 | instance.Expression, | |
| 287 | typeof(ScriptScope).GetMethod("TryGetVariable"), | |
| 288 | Expression.Constant(action.Name), | |
| 289 | result | |
| 290 | ), | |
| 291 | result, | |
| 292 | Expression.Convert(fallback.Expression, typeof(object)) | |
| 293 | ), | |
| 294 | result | |
| 295 | ), | |
| 296 | instance.Restrictions.Merge(Restrictions.Combine(args)).Merge(fallback.Restrictions) | |
| 297 | ); | |
| 298 | } | |
| 299 | ||
| 300 | // TODO: support for IgnoreCase in underlying ScriptScope APIs | |
| 301 | public override MetaObject SetMember(SetMemberAction action, MetaObject[] args) { | |
| 302 | var instance = Restrict(typeof(ScriptScope)); | |
| 303 | return new MetaObject( | |
| 304 | Expression.Call( | |
| 305 | instance.Expression, | |
| 306 | typeof(ScriptScope).GetMethod("SetVariable", new[] { typeof(string), typeof(object) }), | |
| 307 | Expression.Constant(action.Name), | |
| 308 | Expression.Convert(args[1].Expression, typeof(object)) | |
| 309 | ), | |
| 310 | instance.Restrictions.Merge(Restrictions.Combine(args)) | |
| 311 | ); | |
| 312 | } | |
| 313 | ||
| 314 | // TODO: support for IgnoreCase in underlying ScriptScope APIs | |
| 315 | public override MetaObject DeleteMember(DeleteMemberAction action, MetaObject[] args) { | |
| 316 | var fallback = action.Fallback(args); | |
| 317 | var instance = Restrict(typeof(ScriptScope)); | |
| 318 | return new MetaObject( | |
| 319 | Expression.Condition( | |
| 320 | Expression.Call( | |
| 321 | instance.Expression, | |
| 322 | typeof(ScriptScope).GetMethod("RemoveVariable"), | |
| 323 | Expression.Constant(action.Name) | |
| 324 | ), | |
| 325 | Expression.Empty(), | |
| 326 | Expression.Convert(fallback.Expression, typeof(void)) | |
| 327 | ), | |
| 328 | instance.Restrictions.Merge(Restrictions.Combine(args)).Merge(fallback.Restrictions) | |
| 329 | ); | |
| 330 | } | |
| 331 | ||
| 332 | // helper class for FallbackInvoke | |
| 333 | private sealed class InvokeAdapter : InvokeAction { | |
| 334 | private readonly CallAction _call; | |
| 335 | ||
| 336 | internal InvokeAdapter(CallAction call) | |
| 337 | : base(RemoveFirst(call.Arguments)) { | |
| 338 | _call = call; | |
| 339 | } | |
| 340 | ||
| 341 | private static ReadOnlyCollection<Argument> RemoveFirst(ReadOnlyCollection<Argument> args) { | |
| 342 | if (args.Count == 0) { | |
| 343 | return args; | |
| 344 | } | |
| 345 | var result = new Argument[args.Count - 1]; | |
| 346 | for (int i = 0, n = result.Length; i < n; i++) { | |
| 347 | result[i] = args[i + 1]; | |
| 348 | } | |
| 349 | return new ReadOnlyCollection<Argument>(result); | |
| 350 | } | |
| 351 | ||
| 352 | public override MetaObject Fallback(MetaObject[] args, MetaObject onBindingError) { | |
| 353 | return _call.FallbackInvoke(args, onBindingError); | |
| 354 | } | |
| 355 | ||
| 356 | public override object HashCookie { | |
| 357 | get { return this; } | |
| 358 | } | |
| 359 | ||
| 360 | public override bool Equals(object obj) { | |
| 361 | var other = obj as InvokeAdapter; | |
| 362 | return other != null && _call.Equals(other._call) && base.Equals(obj); | |
| 363 | } | |
| 364 | ||
| 365 | public override int GetHashCode() { | |
| 366 | return base.GetHashCode() ^ _call.GetHashCode(); | |
| 367 | } | |
| 368 | } | |
| 369 | ||
| 370 | // TODO: support for IgnoreCase in underlying ScriptScope APIs | |
| 371 | public override MetaObject Call(CallAction action, MetaObject[] args) { | |
| 372 | var fallback = action.Fallback(args); | |
| 373 | var result = Expression.Variable(typeof(object), "result"); | |
| 374 | ||
| 375 | var invokeArgs = (MetaObject[])args.Clone(); | |
| 376 | invokeArgs[0] = new MetaObject(result, Restrictions.Empty); | |
| 377 | var fallbackInvoke = new InvokeAdapter(action).Defer(invokeArgs); | |
| 378 | ||
| 379 | var instance = Restrict(typeof(ScriptScope)); | |
| 380 | return new MetaObject( | |
| 381 | Expression.Scope( | |
| 382 | Expression.Condition( | |
| 383 | Expression.Call( | |
| 384 | instance.Expression, | |
| 385 | typeof(ScriptScope).GetMethod("TryGetVariable"), | |
| 386 | Expression.Constant(action.Name), | |
| 387 | result | |
| 388 | ), | |
| 389 | Expression.Convert(fallbackInvoke.Expression, typeof(object)), | |
| 390 | Expression.Convert(fallback.Expression, typeof(object)) | |
| 391 | ), | |
| 392 | result | |
| 393 | ), | |
| 394 | instance.Restrictions.Merge(Restrictions.Combine(args)).Merge(fallback.Restrictions) | |
| 395 | ); | |
| 396 | } | |
| 397 | } | |
| 398 | ||
| 399 | #endregion | |
| 262 | 400 | } |
| 263 | 401 | } |
| ... | ...@@ -251,9 +251,9 @@ | |
| 251 | 251 | case ExpressionType.Extension: |
| 252 | 252 | EmitExtensionExpression(this, node); |
| 253 | 253 | break; |
| 254 | // IndexedProperty | |
| 255 | case ExpressionType.IndexedProperty: | |
| 256 | EmitIndexedPropertyExpression(this, node); | |
| 254 | // Index | |
| 255 | case ExpressionType.Index: | |
| 256 | EmitIndexExpression(this, node); | |
| 257 | 257 | break; |
| 258 | 258 | // LabeledStatement |
| 259 | 259 | case ExpressionType.LabeledStatement: |
| ... | ...@@ -1,4 +1,4 @@ | |
| 1 | /* **************************************************************************** | |
| 1 | /* **************************************************************************** | |
| 2 | 2 | * |
| 3 | 3 | * Copyright (c) Microsoft Corporation. |
| 4 | 4 | * |
| ... | ...@@ -1760,6 +1760,13 @@ | |
| 1760 | 1760 | } |
| 1761 | 1761 | |
| 1762 | 1762 | /// <summary> |
| 1763 | /// A string like "Unexpected VarArgs call to method '{0}'" | |
| 1764 | /// </summary> | |
| 1765 | internal static string UnexpectedVarArgsCall(object p0) { | |
| 1766 | return FormatString("Unexpected VarArgs call to method '{0}'", p0); | |
| 1767 | } | |
| 1768 | ||
| 1769 | /// <summary> | |
| 1763 | 1770 | /// A string like "missing parameter value not yet supported" |
| 1764 | 1771 | /// </summary> |
| 1765 | 1772 | internal static string MissingValueNotSupported { |
| ... | ...@@ -2806,6 +2813,13 @@ | |
| 2806 | 2813 | } |
| 2807 | 2814 | |
| 2808 | 2815 | /// <summary> |
| 2816 | /// InvalidOperationException with message like "Unexpected VarArgs call to method '{0}'" | |
| 2817 | /// </summary> | |
| 2818 | internal static Exception UnexpectedVarArgsCall(object p0) { | |
| 2819 | return new InvalidOperationException(Strings.UnexpectedVarArgsCall(p0)); | |
| 2820 | } | |
| 2821 | ||
| 2822 | /// <summary> | |
| 2809 | 2823 | /// NotSupportedException with message like "missing parameter value not yet supported" |
| 2810 | 2824 | /// </summary> |
| 2811 | 2825 | internal static Exception MissingValueNotSupported() { |
| ... | ...@@ -30,7 +30,7 @@ | |
| 30 | 30 | |
| 31 | 31 | protected MutableStringStream Data { |
| 32 | 32 | get { |
| 33 | MutableStringStream stream = (_stream as MutableStringStream); | |
| 33 | MutableStringStream stream = (Stream as MutableStringStream); | |
| 34 | 34 | if (stream == null) { |
| 35 | 35 | throw RubyExceptions.CreateArgumentError("stream is not a StringIO"); |
| 36 | 36 | } |
| ... | ...@@ -195,9 +195,9 @@ | |
| 195 | 195 | // Extension |
| 196 | 196 | case ExpressionType.Extension: |
| 197 | 197 | return DefaultVisitExtensionExpression(node); |
| 198 | // IndexedProperty | |
| 199 | case ExpressionType.IndexedProperty: | |
| 200 | return DefaultVisitIndexedPropertyExpression(node); | |
| 198 | // Index | |
| 199 | case ExpressionType.Index: | |
| 200 | return DefaultVisitIndexExpression(node); | |
| 201 | 201 | // LabeledStatement |
| 202 | 202 | case ExpressionType.LabeledStatement: |
| 203 | 203 | return DefaultVisitLabeledStatement(node); |
| ... | ...@@ -299,9 +299,9 @@ | |
| 299 | 299 | return Visit((EmptyStatement)node); |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | // IndexedPropertyExpression | |
| 303 | private Expression DefaultVisitIndexedPropertyExpression(Expression node) { | |
| 304 | return Visit((IndexedPropertyExpression)node); | |
| 302 | // IndexExpression | |
| 303 | private Expression DefaultVisitIndexExpression(Expression node) { | |
| 304 | return Visit((IndexExpression)node); | |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // InvocationExpression |
| ... | ...@@ -58,13 +58,9 @@ | |
| 58 | 58 | /// Provides the ContextId which includes members that should only be shown for this LanguageContext. |
| 59 | 59 | /// |
| 60 | 60 | /// ContextId's are used for filtering by Scope's. |
| 61 | /// | |
| 62 | /// TODO: Not virtual, TestContext currently depends on being able to override. | |
| 63 | 61 | /// </summary> |
| 64 | public virtual ContextId ContextId { | |
| 65 | get { | |
| 66 | return _id; | |
| 67 | } | |
| 62 | public ContextId ContextId { | |
| 63 | get { return _id; } | |
| 68 | 64 | } |
| 69 | 65 | |
| 70 | 66 | /// <summary> |
| ... | ...@@ -19,6 +19,7 @@ | |
| 19 | 19 | using Microsoft.Scripting.Actions; |
| 20 | 20 | using IronRuby.Builtins; |
| 21 | 21 | using System.Scripting.Actions; |
| 22 | using System; | |
| 22 | 23 | |
| 23 | 24 | namespace IronRuby.Runtime { |
| 24 | 25 | // Even though Ruby types overload Equals & GetHashCode, we can't use them |
| ... | ...@@ -28,10 +29,10 @@ | |
| 28 | 29 | public class EqualityComparer : IEqualityComparer<object> { |
| 29 | 30 | private readonly CodeContext/*!*/ _context; |
| 30 | 31 | |
| 31 | private static readonly CallSite<DynamicSiteTarget<CodeContext, object, int>>/*!*/ _HashSharedSite = CallSite<DynamicSiteTarget<CodeContext, object, int>>.Create( | |
| 32 | private static readonly CallSite<Func<CallSite, CodeContext, object, int>>/*!*/ _HashSharedSite = CallSite<Func<CallSite, CodeContext, object, int>>.Create( | |
| 32 | 33 | RubySites.InstanceCallAction("hash")); |
| 33 | 34 | |
| 34 | private static readonly CallSite<DynamicSiteTarget<CodeContext, object, object, bool>>/*!*/ _EqlSharedSite = CallSite<DynamicSiteTarget<CodeContext, object, object, bool>>.Create( | |
| 35 | private static readonly CallSite<Func<CallSite, CodeContext, object, object, bool>>/*!*/ _EqlSharedSite = CallSite<Func<CallSite, CodeContext, object, object, bool>>.Create( | |
| 35 | 36 | RubySites.InstanceCallAction("eql?", 1)); |
| 36 | 37 | |
| 37 | 38 | // friend: RubyContext |
| ... | ...@@ -187,7 +187,7 @@ | |
| 187 | 187 | // rewrite the node... |
| 188 | 188 | return VisitNode( |
| 189 | 189 | Expression.ConvertHelper( |
| 190 | Expression.ArrayIndex(_constantPool, Expression.Constant(_constants.Count - 1)), | |
| 190 | Expression.ArrayAccess(_constantPool, Expression.Constant(_constants.Count - 1)), | |
| 191 | 191 | siteType |
| 192 | 192 | ) |
| 193 | 193 | ); |
| ... | ...@@ -40,7 +40,7 @@ | |
| 40 | 40 | |
| 41 | 41 | internal override MSA.Expression/*!*/ Transform(AstGenerator/*!*/ gen) { |
| 42 | 42 | Assert.NotNull(gen); |
| 43 | return Ast.ActionExpression( | |
| 43 | return Ast.Dynamic( | |
| 44 | 44 | ConvertToProcAction.Instance, |
| 45 | 45 | typeof(Proc), |
| 46 | 46 | gen.CurrentScopeVariable, _expression.TransformRead(gen) |
| ... | ...@@ -24,6 +24,7 @@ | |
| 24 | 24 | public partial class Finalizer : Expression { |
| 25 | 25 | // END { body } |
| 26 | 26 | |
| 27 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] // TODO | |
| 27 | 28 | private readonly LexicalScope/*!*/ _definedScope; |
| 28 | 29 | |
| 29 | 30 | // TODO: |
| ... | ...@@ -145,11 +145,11 @@ | |
| 145 | 145 | return self; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 |