2008-04-24 Jb Evain <jbevain@novell.com>
authorJb Evain <jbevain@gmail.com>
Thu, 24 Apr 2008 11:58:05 +0000 (11:58 -0000)
committerJb Evain <jbevain@gmail.com>
Thu, 24 Apr 2008 11:58:05 +0000 (11:58 -0000)
* UnaryExpression.cs, EmitContext.cs: implement compilation
of Quote as a global load.

svn path=/trunk/mcs/; revision=101668

mcs/class/System.Core/System.Linq.Expressions/ChangeLog
mcs/class/System.Core/System.Linq.Expressions/EmitContext.cs
mcs/class/System.Core/System.Linq.Expressions/UnaryExpression.cs

index 92cb11af9f99126c1fb7cdc3016a1a3c78ec5c39..4f86c8cf89794b9178700da1e3e71005168be48e 100644 (file)
@@ -1,3 +1,8 @@
+2008-04-24  Jb Evain  <jbevain@novell.com>
+
+       * UnaryExpression.cs, EmitContext.cs: implement compilation
+       of Quote as a global load.
+
 2008-04-23  Jb Evain  <jbevain@novell.com>
 
        * UnaryExpression.cs: start implementing EmitConvert.
index 5ce94394e2d1c959657b3435b455124f5207351e..d952c0c3af2c5b5675c1e95d5874c3938d22bfba 100644 (file)
@@ -172,6 +172,11 @@ namespace System.Linq.Expressions {
                }
 
                public void EmitReadGlobal (object global)
+               {
+                       EmitReadGlobal (global, global.GetType ());
+               }
+
+               public void EmitReadGlobal (object global, Type type)
                {
                        EmitScope ();
 
@@ -184,10 +189,10 @@ namespace System.Linq.Expressions {
                        ig.Emit (OpCodes.Ldc_I4, index);
                        ig.Emit (OpCodes.Ldelem, typeof (object));
 
-                       var type = global.GetType ().MakeStrongBoxType ();
+                       var strongbox = type.MakeStrongBoxType ();
 
-                       ig.Emit (OpCodes.Isinst, type);
-                       ig.Emit (OpCodes.Ldfld, type.GetField ("Value"));
+                       ig.Emit (OpCodes.Isinst, strongbox);
+                       ig.Emit (OpCodes.Ldfld, strongbox.GetField ("Value"));
                }
        }
 
@@ -209,14 +214,28 @@ namespace System.Linq.Expressions {
                        Visit (expression);
                }
 
-               protected override void VisitConstant (ConstantExpression constant)
+               protected override void VisitUnary (UnaryExpression unary)
                {
-                       if (constant.Value == null)
+                       if (unary.NodeType != ExpressionType.Quote) {
+                               base.VisitUnary (unary);
                                return;
+                       }
+
+                       AddGlobal (unary.Operand, typeof (Expression));
+               }
 
+               protected override void VisitConstant (ConstantExpression constant)
+               {
                        var value = constant.Value;
-                       var type = value.GetType ();
 
+                       if (value == null)
+                               return;
+
+                       AddGlobal (value, value.GetType ());
+               }
+
+               void AddGlobal (object value, Type type)
+               {
                        if (Type.GetTypeCode (type) != TypeCode.Object)
                                return;
 
index 7735051b2bbbce05a065cf9610e2bdb690c7e8a9..72cac6e658564b134e9671b5472f0214c7f60090 100644 (file)
@@ -166,6 +166,9 @@ namespace System.Linq.Expressions {
                        case ExpressionType.ConvertChecked:
                                EmitConvert (ec);
                                return;
+                       case ExpressionType.Quote:
+                               ec.EmitReadGlobal (operand, typeof (Expression));
+                               return;
                        default:
                                throw new NotImplementedException (this.NodeType.ToString ());
                        }