2001-11-18 Ravi Pratap <ravi@ximian.com>
[mono.git] / mcs / mcs / expression.cs
index 18e89d085f5413c4f5b6f3dd7df6adbd2c1d6f56..5cf7fdb86541dfc754c26b3f3b46d4565786a7e5 100755 (executable)
@@ -16,6 +16,65 @@ namespace CIR {
        using System.Reflection.Emit;
        using System.Text;
 
+       // <summary>
+       //   This is just a helper class, it is generated by Unary, UnaryMutator
+       //   when an overloaded method has been found.  It just emits the code for a
+       //   static call.
+       // </summary>
+       public class StaticCallExpr : ExpressionStatement {
+               ArrayList args;
+               MethodInfo mi;
+
+               StaticCallExpr (MethodInfo m, ArrayList a)
+               {
+                       mi = m;
+                       args = a;
+
+                       type = m.ReturnType;
+                       eclass = ExprClass.Value;
+               }
+
+               public override Expression DoResolve (EmitContext ec)
+               {
+                       //
+                       // We are born fully resolved
+                       //
+                       return this;
+               }
+
+               public override void Emit (EmitContext ec)
+               {
+                       if (args != null) 
+                               Invocation.EmitArguments (ec, mi, args);
+
+                       ec.ig.Emit (OpCodes.Call, mi);
+                       return;
+               }
+               
+               static public Expression MakeSimpleCall (EmitContext ec, MethodGroupExpr mg,
+                                                        Expression e, Location loc)
+               {
+                       ArrayList args;
+                       MethodBase method;
+                       
+                       args = new ArrayList (1);
+                       args.Add (new Argument (e, Argument.AType.Expression));
+                       method = Invocation.OverloadResolve (ec, (MethodGroupExpr) mg, args, loc);
+
+                       if (method == null)
+                               return null;
+
+                       return new StaticCallExpr ((MethodInfo) method, args);
+               }
+
+               public override void EmitStatement (EmitContext ec)
+               {
+                       Emit (ec);
+                       if (type != TypeManager.void_type)
+                               ec.ig.Emit (OpCodes.Pop);
+               }
+       }
+       
        // <summary>
        //   Unary expressions.  
        // </summary>
@@ -25,17 +84,14 @@ namespace CIR {
        //   ExpressionStatement becuase the pre/post increment/decrement
        //   operators can be used in a statement context.
        // </remarks>
-       public class Unary : ExpressionStatement {
-               public enum Operator {
+       public class Unary : Expression {
+               public enum Operator : byte {
                        UnaryPlus, UnaryNegation, LogicalNot, OnesComplement,
-                       Indirection, AddressOf, PreIncrement,
-                       PreDecrement, PostIncrement, PostDecrement 
+                       Indirection, AddressOf, 
                }
 
                Operator   oper;
                Expression expr;
-               ArrayList  Arguments;
-               MethodBase method;
                Location   loc;
                
                public Unary (Operator op, Expression expr, Location loc)
@@ -83,23 +139,11 @@ namespace CIR {
                                return "&";
                        case Operator.Indirection:
                                return "*";
-                       case Operator.PreIncrement : case Operator.PostIncrement :
-                               return "++";
-                       case Operator.PreDecrement : case Operator.PostDecrement :
-                               return "--";
                        }
 
                        return oper.ToString ();
                }
 
-               Expression ForceConversion (EmitContext ec, Expression expr, Type target_type)
-               {
-                       if (expr.Type == target_type)
-                               return expr;
-
-                       return ConvertImplicit (ec, expr, target_type, new Location (-1));
-               }
-
                void error23 (Type t)
                {
                        Report.Error (
@@ -108,28 +152,6 @@ namespace CIR {
                                TypeManager.CSharpName (t) + "'");
                }
 
-               // <summary>
-               //   Returns whether an object of type `t' can be incremented
-               //   or decremented with add/sub (ie, basically whether we can
-               //   use pre-post incr-decr operations on it, but it is not a
-               //   System.Decimal, which we test elsewhere)
-               // </summary>
-               static bool IsIncrementableNumber (Type t)
-               {
-                       return (t == TypeManager.sbyte_type) ||
-                               (t == TypeManager.byte_type) ||
-                               (t == TypeManager.short_type) ||
-                               (t == TypeManager.ushort_type) ||
-                               (t == TypeManager.int32_type) ||
-                               (t == TypeManager.uint32_type) ||
-                               (t == TypeManager.int64_type) ||
-                               (t == TypeManager.uint64_type) ||
-                               (t == TypeManager.char_type) ||
-                               (t.IsSubclassOf (TypeManager.enum_type)) ||
-                               (t == TypeManager.float_type) ||
-                               (t == TypeManager.double_type);
-               }
-
                static Expression TryReduceNegative (Expression expr)
                {
                        Expression e = null;
@@ -160,12 +182,7 @@ namespace CIR {
                        Expression mg;
                        string op_name;
                        
-                       if (oper == Operator.PostIncrement || oper == Operator.PreIncrement)
-                               op_name = "op_Increment";
-                       else if (oper == Operator.PostDecrement || oper == Operator.PreDecrement)
-                               op_name = "op_Decrement";
-                       else
-                               op_name = "op_" + oper;
+                       op_name = "op_" + oper;
 
                        mg = MemberLookup (ec, expr_type, op_name, false, loc);
                        
@@ -173,20 +190,15 @@ namespace CIR {
                                mg = MemberLookup (ec, expr_type.BaseType, op_name, false, loc);
                        
                        if (mg != null) {
-                               Arguments = new ArrayList ();
-                               Arguments.Add (new Argument (expr, Argument.AType.Expression));
-                               
-                               method = Invocation.OverloadResolve (ec, (MethodGroupExpr) mg,
-                                                                    Arguments, loc);
-                               if (method != null) {
-                                       MethodInfo mi = (MethodInfo) method;
-                                       type = mi.ReturnType;
-                                       return this;
-                               } else {
+                               Expression e = StaticCallExpr.MakeSimpleCall (
+                                       ec, (MethodGroupExpr) mg, expr, loc);
+
+                               if (e == null){
                                        error23 (expr_type);
                                        return null;
                                }
-                                       
+                               
+                               return e;
                        }
 
                        //
@@ -194,7 +206,7 @@ namespace CIR {
                        //
 
                        // Only perform numeric promotions on:
-                       // +, -, ++, --
+                       // +, - 
 
                        if (expr_type == null)
                                return null;
@@ -311,47 +323,19 @@ namespace CIR {
                                return null;
                        }
 
-                       //
-                       // The operand of the prefix/postfix increment decrement operators
-                       // should be an expression that is classified as a variable,
-                       // a property access or an indexer access
-                       //
-                       if (oper == Operator.PreDecrement || oper == Operator.PreIncrement ||
-                           oper == Operator.PostDecrement || oper == Operator.PostIncrement){
-                               if (expr.ExprClass == ExprClass.Variable){
-                                       if (IsIncrementableNumber (expr_type) ||
-                                           expr_type == TypeManager.decimal_type){
-                                               type = expr_type;
-                                               return this;
-                                       }
-                               } else if (expr.ExprClass == ExprClass.IndexerAccess){
-                                       //
-                                       // FIXME: Verify that we have both get and set methods
-                                       //
-                                       throw new Exception ("Implement me");
-                               } else if (expr.ExprClass == ExprClass.PropertyAccess){
-                                       PropertyExpr pe = (PropertyExpr) expr;
-                                       
-                                       if (pe.VerifyAssignable ())
-                                               return this;
-                                       return null;
-                               } else {
-                                       report118 (loc, expr, "variable, indexer or property access");
-                               }
-                       }
-
                        if (oper == Operator.AddressOf){
                                if (expr.ExprClass != ExprClass.Variable){
-                                       Error (211, "Cannot take the address of non-variables");
+                                       Error (211, loc, "Cannot take the address of non-variables");
                                        return null;
                                }
                                type = Type.GetType (expr.Type.ToString () + "*");
+
+                               return this;
                        }
                        
-                       Error (187, "No such operator '" + OperName () + "' defined for type '" +
+                       Error (187, loc, "No such operator '" + OperName () + "' defined for type '" +
                               TypeManager.CSharpName (expr_type) + "'");
                        return null;
-
                }
 
                public override Expression DoResolve (EmitContext ec)
@@ -369,41 +353,6 @@ namespace CIR {
                {
                        ILGenerator ig = ec.ig;
                        Type expr_type = expr.Type;
-                       ExprClass eclass;
-                       
-                       if (method != null) {
-
-                               // Note that operators are static anyway
-                               
-                               if (Arguments != null) 
-                                       Invocation.EmitArguments (ec, Arguments);
-
-                               //
-                               // Post increment/decrement operations need a copy at this
-                               // point.
-                               //
-                               if (oper == Operator.PostDecrement || oper == Operator.PostIncrement)
-                                       ig.Emit (OpCodes.Dup);
-                               
-
-                               ig.Emit (OpCodes.Call, (MethodInfo) method);
-
-                               //
-                               // Pre Increment and Decrement operators
-                               //
-                               if (oper == Operator.PreIncrement || oper == Operator.PreDecrement){
-                                       ig.Emit (OpCodes.Dup);
-                               }
-                               
-                               //
-                               // Increment and Decrement should store the result
-                               //
-                               if (oper == Operator.PreDecrement || oper == Operator.PreIncrement ||
-                                   oper == Operator.PostDecrement || oper == Operator.PostIncrement){
-                                       ((IStackStore) expr).Store (ec);
-                               }
-                               return;
-                       }
                        
                        switch (oper) {
                        case Operator.UnaryPlus:
@@ -432,51 +381,6 @@ namespace CIR {
                        case Operator.Indirection:
                                throw new Exception ("Not implemented yet");
                                
-                       case Operator.PreIncrement:
-                       case Operator.PreDecrement:
-                               if (expr.ExprClass == ExprClass.Variable){
-                                       //
-                                       // Resolve already verified that it is an "incrementable"
-                                       // 
-                                       expr.Emit (ec);
-                                       ig.Emit (OpCodes.Ldc_I4_1);
-                                       
-                                       if (oper == Operator.PreDecrement)
-                                               ig.Emit (OpCodes.Sub);
-                                       else
-                                               ig.Emit (OpCodes.Add);
-                                       ig.Emit (OpCodes.Dup);
-                                       ((IStackStore) expr).Store (ec);
-                               } else {
-                                       throw new Exception ("Handle Indexers and Properties here");
-                               }
-                               break;
-                               
-                       case Operator.PostIncrement:
-                       case Operator.PostDecrement:
-                               eclass = expr.ExprClass;
-                               if (eclass == ExprClass.Variable){
-                                       //
-                                       // Resolve already verified that it is an "incrementable"
-                                       // 
-                                       expr.Emit (ec);
-                                       ig.Emit (OpCodes.Dup);
-                                       ig.Emit (OpCodes.Ldc_I4_1);
-                                       
-                                       if (oper == Operator.PostDecrement)
-                                               ig.Emit (OpCodes.Sub);
-                                       else
-                                               ig.Emit (OpCodes.Add);
-                                       ((IStackStore) expr).Store (ec);
-                               } else if (eclass == ExprClass.PropertyAccess){
-                                       throw new Exception ("Handle Properties here");
-                               } else if (eclass == ExprClass.IndexerAccess) {
-                                       throw new Exception ("Handle Indexers here");
-                               } else {
-                                       Console.WriteLine ("Unknown exprclass: " + eclass);
-                               }
-                               break;
-                               
                        default:
                                throw new Exception ("This should not happen: Operator = "
                                                     + oper.ToString ());
@@ -495,27 +399,10 @@ namespace CIR {
                        expr.Emit (ec);
                }
                
-               public override void EmitStatement (EmitContext ec)
-               {
-                       //
-                       // FIXME: we should rewrite this code to generate
-                       // better code for ++ and -- as we know we wont need
-                       // the values on the stack
-                       //
-                       Emit (ec);
-                       ec.ig.Emit (OpCodes.Pop);
-               }
-
                public override Expression Reduce (EmitContext ec)
                {
                        Expression e;
                        
-                       //
-                       // We can not reduce expressions that invoke operator overloaded functions.
-                       //
-                       if (method != null)
-                               return this;
-
                        //
                        // First, reduce our child.  Note that although we handle 
                        //
@@ -541,18 +428,245 @@ namespace CIR {
                        case Operator.OnesComplement:
                                Type et = expr.Type;
                                
-                               if (et == TypeManager.int32_type)
-                                       return new IntLiteral (~ ((IntLiteral) expr).Value);
-                               if (et == TypeManager.uint32_type)
-                                       return new UIntLiteral (~ ((UIntLiteral) expr).Value);
-                               if (et == TypeManager.int64_type)
-                                       return new LongLiteral (~ ((LongLiteral) expr).Value);
-                               if (et == TypeManager.uint64_type)
-                                       return new ULongLiteral (~ ((ULongLiteral) expr).Value);
+                               if (et == TypeManager.int32_type)
+                                       return new IntLiteral (~ ((IntLiteral) expr).Value);
+                               if (et == TypeManager.uint32_type)
+                                       return new UIntLiteral (~ ((UIntLiteral) expr).Value);
+                               if (et == TypeManager.int64_type)
+                                       return new LongLiteral (~ ((LongLiteral) expr).Value);
+                               if (et == TypeManager.uint64_type)
+                                       return new ULongLiteral (~ ((ULongLiteral) expr).Value);
+                               break;
+                       }
+                       return this;
+               }
+       }
+
+       // <summary>
+       //   Unary Mutator expressions (pre and post ++ and --)
+       // </summary>
+       //
+       // <remarks>
+       //   UnaryMutator implements ++ and -- expressions.   It derives from
+       //   ExpressionStatement becuase the pre/post increment/decrement
+       //   operators can be used in a statement context.
+       // </remarks>
+       //
+       // FIXME: Idea, we could split this up in two classes, one simpler
+       // for the common case, and one with the extra fields for more complex
+       // classes (indexers require temporary access;  overloaded require method)
+       //
+       // Maybe we should have classes PreIncrement, PostIncrement, PreDecrement,
+       // PostDecrement, that way we could save the `Mode' byte as well.  
+       //
+       public class UnaryMutator : ExpressionStatement {
+               public enum Mode : byte {
+                       PreIncrement, PreDecrement, PostIncrement, PostDecrement
+               }
+               
+               Mode mode;
+               Location loc;
+               Expression expr;
+               LocalTemporary temp_storage;
+
+               //
+               // This is expensive for the simplest case.
+               //
+               Expression method;
+                       
+               public UnaryMutator (Mode m, Expression e, Location l)
+               {
+                       mode = m;
+                       loc = l;
+                       expr = e;
+               }
+
+               string OperName ()
+               {
+                       return (mode == Mode.PreIncrement || mode == Mode.PostIncrement) ?
+                               "++" : "--";
+               }
+               
+               void error23 (Type t)
+               {
+                       Report.Error (
+                               23, loc, "Operator " + OperName () + 
+                               " cannot be applied to operand of type `" +
+                               TypeManager.CSharpName (t) + "'");
+               }
+
+               // <summary>
+               //   Returns whether an object of type `t' can be incremented
+               //   or decremented with add/sub (ie, basically whether we can
+               //   use pre-post incr-decr operations on it, but it is not a
+               //   System.Decimal, which we require operator overloading to catch)
+               // </summary>
+               static bool IsIncrementableNumber (Type t)
+               {
+                       return (t == TypeManager.sbyte_type) ||
+                               (t == TypeManager.byte_type) ||
+                               (t == TypeManager.short_type) ||
+                               (t == TypeManager.ushort_type) ||
+                               (t == TypeManager.int32_type) ||
+                               (t == TypeManager.uint32_type) ||
+                               (t == TypeManager.int64_type) ||
+                               (t == TypeManager.uint64_type) ||
+                               (t == TypeManager.char_type) ||
+                               (t.IsSubclassOf (TypeManager.enum_type)) ||
+                               (t == TypeManager.float_type) ||
+                               (t == TypeManager.double_type);
+               }
+
+               Expression ResolveOperator (EmitContext ec)
+               {
+                       Type expr_type = expr.Type;
+
+                       //
+                       // Step 1: Perform Operator Overload location
+                       //
+                       Expression mg;
+                       string op_name;
+                       
+                       if (mode == Mode.PreIncrement || mode == Mode.PostIncrement)
+                               op_name = "op_Increment";
+                       else 
+                               op_name = "op_Decrement";
+
+                       mg = MemberLookup (ec, expr_type, op_name, false, loc);
+
+                       if (mg == null && expr_type.BaseType != null)
+                               mg = MemberLookup (ec, expr_type.BaseType, op_name, false, loc);
+                       
+                       if (mg != null) {
+                               method = StaticCallExpr.MakeSimpleCall (
+                                       ec, (MethodGroupExpr) mg, expr, loc);
+
+                               type = method.Type;
+                               return this;
+                       }
+
+                       //
+                       // The operand of the prefix/postfix increment decrement operators
+                       // should be an expression that is classified as a variable,
+                       // a property access or an indexer access
+                       //
+                       type = expr_type;
+                       if (expr.ExprClass == ExprClass.Variable){
+                               if (IsIncrementableNumber (expr_type) ||
+                                   expr_type == TypeManager.decimal_type){
+                                       return this;
+                               }
+                       } else if (expr.ExprClass == ExprClass.IndexerAccess){
+                               IndexerAccess ia = (IndexerAccess) expr;
+                               
+                               temp_storage = new LocalTemporary (ec, expr.Type);
+                               
+                               expr = ia.ResolveLValue (ec, temp_storage);
+                               if (expr == null)
+                                       return null;
+
+                               return this;
+                       } else if (expr.ExprClass == ExprClass.PropertyAccess){
+                               PropertyExpr pe = (PropertyExpr) expr;
+
+                               if (pe.VerifyAssignable ())
+                                       return this;
+
+                               return null;
+                       } else {
+                               report118 (loc, expr, "variable, indexer or property access");
+                               return null;
+                       }
+
+                       Error (187, loc, "No such operator '" + OperName () + "' defined for type '" +
+                              TypeManager.CSharpName (expr_type) + "'");
+                       return null;
+               }
+
+               public override Expression DoResolve (EmitContext ec)
+               {
+                       expr = expr.Resolve (ec);
+                       
+                       if (expr == null)
+                               return null;
+
+                       eclass = ExprClass.Value;
+                       return ResolveOperator (ec);
+               }
+               
+
+               //
+               // FIXME: We need some way of avoiding the use of temp_storage
+               // for some types of storage (parameters, local variables,
+               // static fields) and single-dimension array access.
+               //
+               void EmitCode (EmitContext ec, bool is_expr)
+               {
+                       ILGenerator ig = ec.ig;
+                       IAssignMethod ia = (IAssignMethod) expr;
+
+                       if (temp_storage == null)
+                               temp_storage = new LocalTemporary (ec, expr.Type);
+                       
+                       switch (mode){
+                       case Mode.PreIncrement:
+                       case Mode.PreDecrement:
+                               if (method == null){
+                                       expr.Emit (ec);
+
+                                       ig.Emit (OpCodes.Ldc_I4_1);
+                               
+                                       if (mode == Mode.PreDecrement)
+                                               ig.Emit (OpCodes.Sub);
+                                       else
+                                               ig.Emit (OpCodes.Add);
+                               } else
+                                       method.Emit (ec);
+                               
+                               temp_storage.Store (ec);
+                               ia.EmitAssign (ec, temp_storage);
+                               if (is_expr)
+                                       temp_storage.Emit (ec);
+                               break;
+                               
+                       case Mode.PostIncrement:
+                       case Mode.PostDecrement:
+                               if (is_expr)
+                                       expr.Emit (ec);
+                               
+                               if (method == null){
+                                       if (!is_expr)
+                                               expr.Emit (ec);
+                                       else
+                                               ig.Emit (OpCodes.Dup);
+
+                                       ig.Emit (OpCodes.Ldc_I4_1);
+                               
+                                       if (mode == Mode.PostDecrement)
+                                               ig.Emit (OpCodes.Sub);
+                                       else
+                                               ig.Emit (OpCodes.Add);
+                               } else {
+                                       method.Emit (ec);
+                               }
+                               
+                               temp_storage.Store (ec);
+                               ia.EmitAssign (ec, temp_storage);
                                break;
                        }
-                       return this;
                }
+
+               public override void Emit (EmitContext ec)
+               {
+                       EmitCode (ec, true);
+                       
+               }
+               
+               public override void EmitStatement (EmitContext ec)
+               {
+                       EmitCode (ec, false);
+               }
+
        }
        
        public class Probe : Expression {
@@ -561,7 +675,7 @@ namespace CIR {
                Expression expr;
                Type probe_type;
                
-               public enum Operator {
+               public enum Operator : byte {
                        Is, As
                }
                
@@ -669,7 +783,7 @@ namespace CIR {
        }
 
        public class Binary : Expression {
-               public enum Operator {
+               public enum Operator : byte {
                        Multiply, Division, Modulus,
                        Addition, Subtraction,
                        LeftShift, RightShift,
@@ -784,7 +898,7 @@ namespace CIR {
                // Note that handling the case l == Decimal || r == Decimal
                // is taken care of by the Step 1 Operator Overload resolution.
                //
-               void DoNumericPromotions (EmitContext ec, Type l, Type r)
+               bool DoNumericPromotions (EmitContext ec, Type l, Type r)
                {
                        if (l == TypeManager.double_type || r == TypeManager.double_type){
                                //
@@ -895,21 +1009,20 @@ namespace CIR {
                                Expression l_tmp, r_tmp;
 
                                l_tmp = ForceConversion (ec, left, TypeManager.int32_type);
-                               if (l_tmp == null) {
-                                       error19 ();
-                                       left = l_tmp;
-                                       return;
-                               }
+                               if (l_tmp == null)
+                                       return false;
                                
                                r_tmp = ForceConversion (ec, right, TypeManager.int32_type);
-                               if (r_tmp == null) {
-                                       error19 ();
-                                       right = r_tmp;
-                                       return;
-                               }
+                               if (r_tmp == null)
+                                       return false;
+
+                               left = l_tmp;
+                               right = r_tmp;
                                
                                type = TypeManager.int32_type;
                        }
+
+                       return true;
                }
 
                void error19 ()
@@ -973,7 +1086,7 @@ namespace CIR {
                                Arguments = new ArrayList ();
                                Arguments.Add (new Argument (left, Argument.AType.Expression));
                                Arguments.Add (new Argument (right, Argument.AType.Expression));
-                               
+
                                method = Invocation.OverloadResolve (ec, union, Arguments, loc);
                                if (method != null) {
                                        MethodInfo mi = (MethodInfo) method;
@@ -1062,16 +1175,39 @@ namespace CIR {
                                        type = TypeManager.bool_type;
                                        return this;
                                }
-                               //
-                               // fall here.
-                               //
+
                        }
 
                        //
                        // We are dealing with numbers
                        //
 
-                       DoNumericPromotions (ec, l, r);
+                       if (!DoNumericPromotions (ec, l, r)){
+                               // Attempt:
+                               //
+                               // operator != (object a, object b)
+                               // operator == (object a, object b)
+                               //
+
+                               if (oper == Operator.Equality || oper == Operator.Inequality){
+                                       Expression li, ri;
+                                       li = ConvertImplicit (ec, left, TypeManager.object_type, loc);
+                                       if (li != null){
+                                               ri = ConvertImplicit (ec, right, TypeManager.object_type,
+                                                                     loc);
+                                               if (ri != null){
+                                                       left = li;
+                                                       right = ri;
+                                                       
+                                                       type = TypeManager.bool_type;
+                                                       return this;
+                                               }
+                                       }
+                               }
+
+                               error19 ();
+                               return null;
+                       }
 
                        if (left == null || right == null)
                                return null;
@@ -1221,7 +1357,7 @@ namespace CIR {
                                // Note that operators are static anyway
                                
                                if (Arguments != null) 
-                                       Invocation.EmitArguments (ec, Arguments);
+                                       Invocation.EmitArguments (ec, method, Arguments);
                                
                                if (method is MethodInfo)
                                        ig.Emit (OpCodes.Call, (MethodInfo) method);
@@ -1354,7 +1490,6 @@ namespace CIR {
                // </summary>
                public override Expression Reduce (EmitContext ec)
                {
-                       Console.WriteLine ("Reduce called");
                        
                        left = left.Reduce (ec);
                        right = right.Reduce (ec);
@@ -1490,7 +1625,7 @@ namespace CIR {
                }
        }
 
-       public class LocalVariableReference : Expression, IStackStore, IMemoryLocation {
+       public class LocalVariableReference : Expression, IAssignMethod, IMemoryLocation {
                public readonly string Name;
                public readonly Block Block;
 
@@ -1580,21 +1715,23 @@ namespace CIR {
                                break;
                        }
                }
-               
-               public void Store (EmitContext ec)
+
+               public void EmitAssign (EmitContext ec, Expression source)
                {
                        ILGenerator ig = ec.ig;
                        VariableInfo vi = VariableInfo;
 
                        vi.Assigned = true;
 
-                       // Funny seems the above generates optimal code for us, but
+                       source.Emit (ec);
+                       
+                       // Funny seems the code below generates optimal code for us, but
                        // seems to take too long to generate what we need.
                        // ig.Emit (OpCodes.Stloc, vi.LocalBuilder);
 
                        Store (ig, vi.Idx);
                }
-
+               
                public void AddressOf (EmitContext ec)
                {
                        VariableInfo vi = VariableInfo;
@@ -1610,7 +1747,7 @@ namespace CIR {
                }
        }
 
-       public class ParameterReference : Expression, IStackStore, IMemoryLocation {
+       public class ParameterReference : Expression, IAssignMethod, IMemoryLocation {
                public readonly Parameters Pars;
                public readonly String Name;
                public readonly int Idx;
@@ -1645,8 +1782,10 @@ namespace CIR {
                                ec.ig.Emit (OpCodes.Ldarg, arg_idx);
                }
 
-               public void Store (EmitContext ec)
+               public void EmitAssign (EmitContext ec, Expression source)
                {
+                       source.Emit (ec);
+                       
                        if (arg_idx <= 255)
                                ec.ig.Emit (OpCodes.Starg_S, (byte) arg_idx);
                        else
@@ -1667,7 +1806,7 @@ namespace CIR {
        //   Used for arguments to New(), Invocation()
        // </summary>
        public class Argument {
-               public enum AType {
+               public enum AType : byte {
                        Expression,
                        Ref,
                        Out
@@ -1675,7 +1814,7 @@ namespace CIR {
 
                public readonly AType ArgType;
                public Expression expr;
-
+               
                public Argument (Expression expr, AType type)
                {
                        this.expr = expr;
@@ -1711,29 +1850,34 @@ namespace CIR {
 
                public static string FullDesc (Argument a)
                {
-                       StringBuilder sb = new StringBuilder ();
-
-                       if (a.ArgType == AType.Ref)
-                               sb.Append ("ref ");
-
-                       if (a.ArgType == AType.Out)
-                               sb.Append ("out ");
-
-                       sb.Append (TypeManager.CSharpName (a.Expr.Type));
-
-                       return sb.ToString ();
+                       return (a.ArgType == AType.Ref ? "ref " :
+                               (a.ArgType == AType.Out ? "out " : "")) +
+                               TypeManager.CSharpName (a.Expr.Type);
                }
                
-               public bool Resolve (EmitContext ec)
+               public bool Resolve (EmitContext ec, Location loc)
                {
                        expr = expr.Resolve (ec);
 
+                       if (ArgType == AType.Expression)
+                               return expr != null;
+
+                       if (expr.ExprClass != ExprClass.Variable){
+                               Report.Error (206, loc,
+                                             "A property or indexer can not be passed as an out or ref " +
+                                             "parameter");
+                               return false;
+                       }
+                               
                        return expr != null;
                }
 
                public void Emit (EmitContext ec)
                {
-                       expr.Emit (ec);
+                       if (ArgType == AType.Ref || ArgType == AType.Out)
+                               ((IMemoryLocation)expr).AddressOf (ec);
+                       else
+                               expr.Emit (ec);
                }
        }
 
@@ -1742,7 +1886,7 @@ namespace CIR {
        // </summary>
        public class Invocation : ExpressionStatement {
                public readonly ArrayList Arguments;
-               public readonly Location Location;
+               Location loc;
 
                Expression expr;
                MethodBase method = null;
@@ -1765,7 +1909,7 @@ namespace CIR {
                {
                        this.expr = expr;
                        Arguments = arguments;
-                       Location = l;
+                       loc = l;
                }
 
                public Expression Expr {
@@ -2266,7 +2410,7 @@ namespace CIR {
                                argument_count = 0;
                        else
                                argument_count = Arguments.Count;
-
+                       
                        //
                        // Now we see if we can find params functions, applicable in their expanded form
                        // since if they were applicable in their normal form, they would have been selected
@@ -2334,11 +2478,9 @@ namespace CIR {
                                        Expression conv;
                                        
                                        if (use_standard)
-                                               conv = ConvertImplicitStandard (ec, a_expr, parameter_type,
-                                                                               Location.Null);
+                                               conv = ConvertImplicitStandard (ec, a_expr, parameter_type, Location.Null);
                                        else
-                                               conv = ConvertImplicit (ec, a_expr, parameter_type,
-                                                                       Location.Null);
+                                               conv = ConvertImplicit (ec, a_expr, parameter_type, Location.Null);
 
                                        if (conv == null) {
                                                if (!Location.IsNull (loc)) {
@@ -2409,12 +2551,12 @@ namespace CIR {
                                        bool IsDelegate = TypeManager.IsDelegateType (expr_type);
                                        if (IsDelegate)
                                                return (new DelegateInvocation (
-                                                       this.expr, Arguments, Location)).Resolve (ec);
+                                                       this.expr, Arguments, loc)).Resolve (ec);
                                }
                        }
 
                        if (!(expr is MethodGroupExpr)){
-                               report118 (Location, this.expr, "method group");
+                               report118 (loc, this.expr, "method group");
                                return null;
                        }
 
@@ -2426,16 +2568,15 @@ namespace CIR {
                                        --i;
                                        Argument a = (Argument) Arguments [i];
 
-                                       if (!a.Resolve (ec))
+                                       if (!a.Resolve (ec, loc))
                                                return null;
                                }
                        }
 
-                       method = OverloadResolve (ec, (MethodGroupExpr) this.expr, Arguments,
-                                                 Location);
+                       method = OverloadResolve (ec, (MethodGroupExpr) this.expr, Arguments, loc);
 
                        if (method == null){
-                               Error (-6, Location,
+                               Error (-6, loc,
                                       "Could not find any applicable function for this argument list");
                                return null;
                        }
@@ -2447,18 +2588,69 @@ namespace CIR {
                        return this;
                }
 
-               public static void EmitArguments (EmitContext ec, ArrayList Arguments)
+               // <summary>
+               //   Emits the list of arguments as an array
+               // </summary>
+               static void EmitParams (EmitContext ec, int idx, ArrayList arguments)
+               {
+                       ILGenerator ig = ec.ig;
+                       int count = arguments.Count - idx;
+                       Argument a = (Argument) arguments [idx];
+                       Type t = a.expr.Type;
+                       string array_type = t.FullName + "[]";
+                       LocalBuilder array;
+                       
+                       array = ig.DeclareLocal (Type.GetType (array_type));
+                       IntLiteral.EmitInt (ig, count);
+                       ig.Emit (OpCodes.Newarr, t);
+                       ig.Emit (OpCodes.Stloc, array);
+
+                       int top = arguments.Count;
+                       for (int j = idx; j < top; j++){
+                               a = (Argument) arguments [j];
+                               
+                               ig.Emit (OpCodes.Ldloc, array);
+                               IntLiteral.EmitInt (ig, j - idx);
+                               a.Emit (ec);
+                               
+                               ArrayAccess.EmitStoreOpcode (ig, t);
+                       }
+                       ig.Emit (OpCodes.Ldloc, array);
+               }
+               
+               // <summary>
+               //   Emits a list of resolved Arguments that are in the arguments
+               //   ArrayList.
+               // 
+               //   The MethodBase argument might be null if the
+               //   emission of the arguments is known not to contain
+               //   a `params' field (for example in constructors or other routines
+               //   that keep their arguments in this structure
+               // </summary>
+               
+               public static void EmitArguments (EmitContext ec, MethodBase mb, ArrayList arguments)
                {
+                       ParameterData pd = null;
                        int top;
 
-                       if (Arguments != null)
-                               top = Arguments.Count;
+                       if (arguments != null)
+                               top = arguments.Count;
                        else
                                top = 0;
 
+                       if (mb != null)
+                                pd = GetParameterData (mb);
+
                        for (int i = 0; i < top; i++){
-                               Argument a = (Argument) Arguments [i];
+                               Argument a = (Argument) arguments [i];
 
+                               if (pd != null){
+                                       if (pd.ParameterModifier (i) == Parameter.Modifier.PARAMS){
+                                               EmitParams (ec, i, arguments);
+                                               return;
+                                       }
+                               }
+                                           
                                a.Emit (ec);
                        }
                }
@@ -2497,7 +2689,7 @@ namespace CIR {
                                                        Type t = instance_expr.Type;
                                                        
                                                        instance_expr.Emit (ec);
-                                                       LocalBuilder temp = ec.GetTemporaryStorage (t);
+                                                       LocalBuilder temp = ig.DeclareLocal (t);
                                                        ig.Emit (OpCodes.Stloc, temp);
                                                        ig.Emit (OpCodes.Ldloca, temp);
                                                }
@@ -2507,7 +2699,7 @@ namespace CIR {
                        }
 
                        if (Arguments != null)
-                               EmitArguments (ec, Arguments);
+                               EmitArguments (ec, method, Arguments);
 
                        if (is_static || struct_call){
                                if (method is MethodInfo)
@@ -2546,7 +2738,7 @@ namespace CIR {
                public readonly ArrayList Arguments;
                public readonly string    RequestedType;
 
-               Location Location;
+               Location loc;
                MethodBase method = null;
 
                //
@@ -2555,11 +2747,11 @@ namespace CIR {
                //
                Expression value_target;
                
-               public New (string requested_type, ArrayList arguments, Location loc)
+               public New (string requested_type, ArrayList arguments, Location l)
                {
                        RequestedType = requested_type;
                        Arguments = arguments;
-                       Location = loc;
+                       loc = l;
                }
 
                public Expression ValueTypeVariable {
@@ -2582,19 +2774,19 @@ namespace CIR {
                        bool IsDelegate = TypeManager.IsDelegateType (type);
                        
                        if (IsDelegate)
-                               return (new NewDelegate (type, Arguments, Location)).Resolve (ec);
+                               return (new NewDelegate (type, Arguments, loc)).Resolve (ec);
                        
                        Expression ml;
                        
                        ml = MemberLookup (ec, type, ".ctor", false,
-                                          MemberTypes.Constructor, AllBindingsFlags, Location);
+                                          MemberTypes.Constructor, AllBindingsFlags, loc);
                        
                        bool is_struct = false;
                        is_struct = type.IsSubclassOf (TypeManager.value_type);
                        
                        if (! (ml is MethodGroupExpr)){
                                if (!is_struct){
-                                       report118 (Location, ml, "method group");
+                                       report118 (loc, ml, "method group");
                                        return null;
                                }
                        }
@@ -2605,17 +2797,17 @@ namespace CIR {
                                                --i;
                                                Argument a = (Argument) Arguments [i];
                                                
-                                               if (!a.Resolve (ec))
+                                               if (!a.Resolve (ec, loc))
                                                        return null;
                                        }
                                }
 
                                method = Invocation.OverloadResolve (ec, (MethodGroupExpr) ml,
-                                                                    Arguments, Location);
+                                                                    Arguments, loc);
                        }
                        
                        if (method == null && !is_struct) {
-                               Error (-6, Location,
+                               Error (-6, loc,
                                       "New invocation: Can not find a constructor for " +
                                       "this argument list");
                                return null;
@@ -2643,7 +2835,7 @@ namespace CIR {
 
                                ml.AddressOf (ec);
                        } else {
-                               Invocation.EmitArguments (ec, Arguments);
+                               Invocation.EmitArguments (ec, method, Arguments);
                                ec.ig.Emit (OpCodes.Newobj, (ConstructorInfo) method);
                                return true;
                        }
@@ -2690,7 +2882,7 @@ namespace CIR {
                string RequestedType;
                string Rank;
                ArrayList Initializers;
-               Location  Location;
+               Location  loc;
                ArrayList Arguments;
 
                MethodBase method = null;
@@ -2699,13 +2891,15 @@ namespace CIR {
                
                bool IsBuiltinType = false;
 
+               int dimensions = 0;
+
                public ArrayCreation (string requested_type, ArrayList exprs,
                                      string rank, ArrayList initializers, Location l)
                {
                        RequestedType = requested_type;
                        Rank          = rank;
                        Initializers  = initializers;
-                       Location      = l;
+                       loc = l;
 
                        Arguments = new ArrayList ();
 
@@ -2717,9 +2911,14 @@ namespace CIR {
                public ArrayCreation (string requested_type, string rank, ArrayList initializers, Location l)
                {
                        RequestedType = requested_type;
-                       Rank = rank;
                        Initializers = initializers;
-                       Location = l;
+                       loc = l;
+
+                       Rank = rank.Substring (0, rank.LastIndexOf ("["));
+
+                       string tmp = rank.Substring (rank.LastIndexOf ("["));
+
+                       dimensions = tmp.Length - 1;
                }
 
                public static string FormArrayType (string base_type, int idx_count, string rank)
@@ -2751,12 +2950,111 @@ namespace CIR {
 
                        return val.Substring (0, val.LastIndexOf ("["));
                }
+
+               void error178 ()
+               {
+                       Report.Error (178, loc, "Incorrectly structured array initializer");
+               }
+
+               bool ValidateInitializers (EmitContext ec)
+               {
+                       if (Initializers == null)
+                               return true;
+
+                       Type underlying_type = ec.TypeContainer.LookupType (RequestedType, false);
+
+                       ArrayList probe = Initializers;
+
+                       if (Arguments != null) {
+                               for (int i = 0; i < Arguments.Count; i++) {
+                                       Argument a = (Argument) Arguments [i];
+                                       
+                                       Expression e = Expression.Reduce (ec, a.Expr);
+                                       
+                                       if (!(e is Literal)) {
+                                               Report.Error (150, loc, "A constant value is expected");
+                                               return false;
+                                       }
+                                       
+                                       int value = (int) ((Literal) e).GetValue ();
                
+                                       if (probe == null) {
+                                               error178 ();
+                                               return false;
+                                       }
+                                               
+                                       if (value != probe.Count) {
+                                               error178 ();
+                                               return false;
+                                       }
+
+                                       if (probe [0] is ArrayList)
+                                               probe = (ArrayList) probe [0];
+                                       else {
+                                               for (int j = 0; j < probe.Count; ++j) {
+                                                       Expression tmp = (Expression) probe [j];
+                                                       
+                                                       tmp = tmp.Resolve (ec);
+
+                                                       Expression conv = ConvertImplicitRequired (ec, tmp,
+                                                                                                  underlying_type, loc);
+
+                                                       if (conv == null)
+                                                               return false;
+                                               }
+
+                                               probe = null;
+                                       }
+                               }
+
+                       } else {
+                               //
+                               // Here is where we update dimension info in the case
+                               // that the user skips doing that
+                               //
+
+                               Arguments = new ArrayList ();
+                               
+                               for (probe = Initializers; probe != null; ) {
+                                       Expression e = new IntLiteral (probe.Count);
+
+                                       Arguments.Add (new Argument (e, Argument.AType.Expression));
+
+                                       if (probe [0] is ArrayList)
+                                               probe = (ArrayList) probe [0];
+                                       else {
+                                               for (int j = 0; j < probe.Count; ++j) {
+                                                       Expression tmp = (Expression) probe [j];
+                                                       
+                                                       tmp = tmp.Resolve (ec);
+
+                                                       Expression conv = ConvertImplicitRequired (ec, tmp,
+                                                                                                  underlying_type, loc);
+
+                                                       if (conv == null)
+                                                               return false;
+                                               }
+                                               
+                                               probe = null;
+                                       }
+                               }
+
+                               if (Arguments.Count != dimensions) {
+                                       error178 ();
+                                       return false;
+                               }
+                       }
 
+                       return true;
+               }
+               
                public override Expression DoResolve (EmitContext ec)
                {
                        int arg_count;
-                       
+
+                       if (!ValidateInitializers (ec))
+                               return null;
+
                        if (Arguments == null)
                                arg_count = 0;
                        else
@@ -2786,15 +3084,15 @@ namespace CIR {
                                Expression ml;
                                
                                ml = MemberLookup (ec, type, ".ctor", false, MemberTypes.Constructor,
-                                                  AllBindingsFlags, Location);
+                                                  AllBindingsFlags, loc);
                                
                                if (!(ml is MethodGroupExpr)){
-                                       report118 (Location, ml, "method group");
+                                       report118 (loc, ml, "method group");
                                        return null;
                                }
                                
                                if (ml == null) {
-                                       Report.Error (-6, Location, "New invocation: Can not find a constructor for " +
+                                       Report.Error (-6, loc, "New invocation: Can not find a constructor for " +
                                                      "this argument list");
                                        return null;
                                }
@@ -2804,15 +3102,15 @@ namespace CIR {
                                                --i;
                                                Argument a = (Argument) Arguments [i];
                                                
-                                               if (!a.Resolve (ec))
+                                               if (!a.Resolve (ec, loc))
                                                        return null;
                                        }
                                }
                                
-                               method = Invocation.OverloadResolve (ec, (MethodGroupExpr) ml, Arguments, Location);
+                               method = Invocation.OverloadResolve (ec, (MethodGroupExpr) ml, Arguments, loc);
                                
                                if (method == null) {
-                                       Report.Error (-6, Location, "New invocation: Can not find a constructor for " +
+                                       Report.Error (-6, loc, "New invocation: Can not find a constructor for " +
                                                      "this argument list");
                                        return null;
                                }
@@ -2830,7 +3128,7 @@ namespace CIR {
                                                --i;
                                                Argument a = (Argument) Arguments [i];
                                                
-                                               if (!a.Resolve (ec))
+                                               if (!a.Resolve (ec, loc))
                                                        return null;
                                                
                                                args.Add (a.Type);
@@ -2848,7 +3146,7 @@ namespace CIR {
                                                            arg_types);
                                
                                if (method == null) {
-                                       Report.Error (-6, Location, "New invocation: Can not find a constructor for " +
+                                       Report.Error (-6, loc, "New invocation: Can not find a constructor for " +
                                                      "this argument list");
                                        return null;
                                }
@@ -2861,19 +3159,34 @@ namespace CIR {
 
                public override void Emit (EmitContext ec)
                {
+                       ILGenerator ig = ec.ig;
+                       
                        if (IsOneDimensional) {
-                               Invocation.EmitArguments (ec, Arguments);
-                               ec.ig.Emit (OpCodes.Newarr, array_element_type);
+                               Invocation.EmitArguments (ec, null, Arguments);
+                               ig.Emit (OpCodes.Newarr, array_element_type);
                                
                        } else {
-                               Invocation.EmitArguments (ec, Arguments);
+                               Invocation.EmitArguments (ec, null, Arguments);
 
                                if (IsBuiltinType)
-                                       ec.ig.Emit (OpCodes.Newobj, (ConstructorInfo) method);
+                                       ig.Emit (OpCodes.Newobj, (ConstructorInfo) method);
                                else
-                                       ec.ig.Emit (OpCodes.Newobj, (MethodInfo) method);
+                                       ig.Emit (OpCodes.Newobj, (MethodInfo) method);
+                       }
+
+                       if (Initializers != null){
+                               FieldBuilder fb;
+
+                               // FIXME: This is just sample data, need to fill with
+                               // real values.
+                               byte [] a = new byte [4] { 1, 2, 3, 4 };
+                               
+                               fb = ec.TypeContainer.RootContext.MakeStaticData (a);
+
+                               ig.Emit (OpCodes.Dup);
+                               ig.Emit (OpCodes.Ldtoken, fb);
+                               ig.Emit (OpCodes.Call, TypeManager.void_initializearray_array_fieldhandle);
                        }
-                       
                }
                
                public override void EmitStatement (EmitContext ec)
@@ -2887,7 +3200,7 @@ namespace CIR {
        //
        // Represents the `this' construct
        //
-       public class This : Expression, IStackStore, IMemoryLocation {
+       public class This : Expression, IAssignMethod, IMemoryLocation {
                Location loc;
                
                public This (Location loc)
@@ -2926,8 +3239,9 @@ namespace CIR {
                        ec.ig.Emit (OpCodes.Ldarg_0);
                }
 
-               public void Store (EmitContext ec)
+               public void EmitAssign (EmitContext ec, Expression source)
                {
+                       source.Emit (ec);
                        ec.ig.Emit (OpCodes.Starg, 0);
                }
 
@@ -3029,7 +3343,7 @@ namespace CIR {
 
                        if (expr is SimpleName){
                                SimpleName child_expr = (SimpleName) expr;
-                               
+
                                expr = new SimpleName (child_expr.Name + "." + Identifier, loc);
 
                                return expr.Resolve (ec);
@@ -3073,7 +3387,33 @@ namespace CIR {
 
                        if (member_lookup is FieldExpr){
                                FieldExpr fe = (FieldExpr) member_lookup;
+                               FieldInfo fi = fe.FieldInfo;
+
+                               if (fi.IsLiteral) {
+                                       Type t = fi.FieldType;
+                                       object o;
+
+                                       if (fi is FieldBuilder)
+                                               o = TypeManager.GetValue ((FieldBuilder) fi);
+                                       else
+                                               o = fi.GetValue (fi);
+                                       
+                                       if (t.IsSubclassOf (TypeManager.enum_type)) {
+                                               Expression enum_member = MemberLookup (ec, t, "value__", false, loc); 
+                                               Type underlying_type = enum_member.Type;
+                                               
+                                               Expression e = Literalize (o, underlying_type);
+                                               e.Resolve (ec);
+                                       
+                                               return new EnumLiteral (e, t);
+                                       }
 
+                                       Expression exp = Literalize (o, t);
+                                       exp.Resolve (ec);
+                                       
+                                       return exp;
+                               }
+                               
                                if (expr is TypeExpr){
                                        if (!fe.FieldInfo.IsStatic){
                                                error176 (loc, fe.FieldInfo.Name);
@@ -3188,7 +3528,6 @@ namespace CIR {
        }
 
        public class ElementAccess : Expression {
-               
                public ArrayList  Arguments;
                public Expression Expr;
                public Location   loc;
@@ -3218,7 +3557,7 @@ namespace CIR {
                                --i;
                                Argument a = (Argument) Arguments [i];
                                
-                               if (!a.Resolve (ec))
+                               if (!a.Resolve (ec, loc))
                                        return false;
                        }
 
@@ -3236,7 +3575,7 @@ namespace CIR {
                        //
                        // I am experimenting with this pattern.
                        //
-                       if (Expr.Type == TypeManager.array_type)
+                       if (Expr.Type.IsSubclassOf (TypeManager.array_type))
                                return (new ArrayAccess (this)).Resolve (ec);
                        else
                                return (new IndexerAccess (this)).Resolve (ec);
@@ -3247,7 +3586,7 @@ namespace CIR {
                        if (!CommonResolve (ec))
                                return null;
 
-                       if (Expr.Type == TypeManager.array_type)
+                       if (Expr.Type.IsSubclassOf (TypeManager.array_type))
                                return (new ArrayAccess (this)).ResolveLValue (ec, right_side);
                        else
                                return (new IndexerAccess (this)).ResolveLValue (ec, right_side);
@@ -3259,7 +3598,10 @@ namespace CIR {
                }
        }
 
-       public class ArrayAccess : Expression, IStackStore {
+       //
+       // Implements array access 
+       //
+       public class ArrayAccess : Expression, IAssignMethod {
                //
                // Points to our "data" repository
                //
@@ -3269,38 +3611,155 @@ namespace CIR {
                {
                        ea = ea_data;
                        eclass = ExprClass.Variable;
-
-                       //
-                       // FIXME: Figure out the type here
-                       //
                }
 
-               Expression CommonResolve (EmitContext ec)
-               {
-                       return this;
-               }
-               
                public override Expression DoResolve (EmitContext ec)
                {
                        if (ea.Expr.ExprClass != ExprClass.Variable) {
                                report118 (ea.loc, ea.Expr, "variable");
                                return null;
                        }
-                       
-                       throw new Exception ("Implement me");
+
+                       Type t = ea.Expr.Type;
+
+                       if (t.GetArrayRank () != ea.Arguments.Count){
+                               Report.Error (22, ea.loc,
+                                             "Incorrect number of indexes for array " +
+                                             " expected: " + t.GetArrayRank () + " got: " +
+                                             ea.Arguments.Count);
+                               return null;
+                       }
+                       type = t.GetElementType ();
+                       eclass = ExprClass.Variable;
+
+                       return this;
                }
 
-               public void Store (EmitContext ec)
-               {
-                       throw new Exception ("Implement me !");
+               // <summary>
+               //    Emits the right opcode to load an object of Type `t'
+               //    from an array of T
+               // </summary>
+               static public void EmitLoadOpcode (ILGenerator ig, Type type)
+               {
+                       if (type == TypeManager.byte_type)
+                               ig.Emit (OpCodes.Ldelem_I1);
+                       else if (type == TypeManager.sbyte_type)
+                               ig.Emit (OpCodes.Ldelem_U1);
+                       else if (type == TypeManager.short_type)
+                               ig.Emit (OpCodes.Ldelem_I2);
+                       else if (type == TypeManager.ushort_type)
+                               ig.Emit (OpCodes.Ldelem_U2);
+                       else if (type == TypeManager.int32_type)
+                               ig.Emit (OpCodes.Ldelem_I4);
+                       else if (type == TypeManager.uint32_type)
+                               ig.Emit (OpCodes.Ldelem_U4);
+                       else if (type == TypeManager.uint64_type)
+                               ig.Emit (OpCodes.Ldelem_I8);
+                       else if (type == TypeManager.int64_type)
+                               ig.Emit (OpCodes.Ldelem_I8);
+                       else if (type == TypeManager.float_type)
+                               ig.Emit (OpCodes.Ldelem_R4);
+                       else if (type == TypeManager.double_type)
+                               ig.Emit (OpCodes.Ldelem_R8);
+                       else if (type == TypeManager.intptr_type)
+                               ig.Emit (OpCodes.Ldelem_I);
+                       else
+                               ig.Emit (OpCodes.Ldelem_Ref);
                }
 
+               // <summary>
+               //    Emits the right opcode to store an object of Type `t'
+               //    from an array of T.  
+               // </summary>
+               static public void EmitStoreOpcode (ILGenerator ig, Type t)
+               {
+                       if (t == TypeManager.byte_type || t == TypeManager.sbyte_type)
+                               ig.Emit (OpCodes.Stelem_I1);
+                       else if (t == TypeManager.short_type || t == TypeManager.ushort_type)
+                               ig.Emit (OpCodes.Stelem_I2);
+                       else if (t == TypeManager.int32_type || t == TypeManager.uint32_type)
+                               ig.Emit (OpCodes.Stelem_I4);
+                       else if (t == TypeManager.int64_type || t == TypeManager.uint64_type)
+                               ig.Emit (OpCodes.Stelem_I8);
+                       else if (t == TypeManager.float_type)
+                               ig.Emit (OpCodes.Stelem_R4);
+                       else if (t == TypeManager.double_type)
+                               ig.Emit (OpCodes.Stelem_R8);
+                       else if (t == TypeManager.intptr_type)
+                               ig.Emit (OpCodes.Stelem_I);
+                       else
+                               ig.Emit (OpCodes.Stelem_Ref);
+               }
+               
                public override void Emit (EmitContext ec)
                {
-                       throw new Exception ("Implement me !");
+                       int rank = ea.Expr.Type.GetArrayRank ();
+                       ILGenerator ig = ec.ig;
+
+                       ea.Expr.Emit (ec);
+
+                       foreach (Argument a in ea.Arguments)
+                               a.Expr.Emit (ec);
+
+                       if (rank == 1)
+                               EmitLoadOpcode (ig, type);
+                       else {
+                               ModuleBuilder mb = ec.TypeContainer.RootContext.ModuleBuilder;
+                               Type [] args = new Type [ea.Arguments.Count];
+                               MethodInfo get;
+                               
+                               int i = 0;
+                               
+                               foreach (Argument a in ea.Arguments)
+                                       args [i++] = a.Type;
+                               
+                               get = mb.GetArrayMethod (
+                                       ea.Expr.Type, "Get",
+                                       CallingConventions.HasThis |
+                                       CallingConventions.Standard,
+                                       type, args);
+                               
+                               ig.Emit (OpCodes.Call, get);
+                       }
                }
-       }
 
+               public void EmitAssign (EmitContext ec, Expression source)
+               {
+                       int rank = ea.Expr.Type.GetArrayRank ();
+                       ILGenerator ig = ec.ig;
+
+                       ea.Expr.Emit (ec);
+
+                       foreach (Argument a in ea.Arguments)
+                               a.Expr.Emit (ec);
+
+                       source.Emit (ec);
+
+                       Type t = source.Type;
+                       if (rank == 1)
+                               EmitStoreOpcode (ig, t);
+                       else {
+                               ModuleBuilder mb = ec.TypeContainer.RootContext.ModuleBuilder;
+                               Type [] args = new Type [ea.Arguments.Count + 1];
+                               MethodInfo set;
+                               
+                               int i = 0;
+                               
+                               foreach (Argument a in ea.Arguments)
+                                       args [i++] = a.Type;
+
+                               args [i] = type;
+                               
+                               set = mb.GetArrayMethod (
+                                       ea.Expr.Type, "Set",
+                                       CallingConventions.HasThis |
+                                       CallingConventions.Standard,
+                                       TypeManager.void_type, args);
+                               
+                               ig.Emit (OpCodes.Call, set);
+                       }
+               }
+       }
        class Indexers {
                public ArrayList getters, setters;
                static Hashtable map;
@@ -3358,7 +3817,10 @@ namespace CIR {
                        return ix;
                }
        }
-       
+
+       // <summary>
+       //   Expressions that represent an indexer call.
+       // </summary>
        public class IndexerAccess : Expression, IAssignMethod {
                //
                // Points to our "data" repository
@@ -3374,11 +3836,6 @@ namespace CIR {
                        eclass = ExprClass.Value;
                }
 
-               public bool VerifyAssignable (Expression source)
-               {
-                       throw new Exception ("Implement me!");
-               }
-
                public override Expression DoResolve (EmitContext ec)
                {
                        Type indexer_type = ea.Expr.Type;
@@ -3392,7 +3849,11 @@ namespace CIR {
                        if (ilist == null)
                                ilist = Indexers.GetIndexersForType (
                                        indexer_type, ec.TypeContainer.RootContext.TypeManager, ea.loc);
-                       
+
+
+                       //
+                       // Step 2: find the proper match
+                       //
                        if (ilist != null && ilist.getters != null && ilist.getters.Count > 0)
                                get = (MethodInfo) Invocation.OverloadResolve (
                                        ec, new MethodGroupExpr (ilist.getters), ea.Arguments, ea.loc);
@@ -3401,11 +3862,11 @@ namespace CIR {
                                Report.Error (154, ea.loc,
                                              "indexer can not be used in this context, because " +
                                              "it lacks a `get' accessor");
-                                       return null;
+                               return null;
                        }
-                               
+
                        type = get.ReturnType;
-                       eclass = ExprClass.Value;
+                       eclass = ExprClass.IndexerAccess;
                        return this;
                }
 
@@ -3456,7 +3917,7 @@ namespace CIR {
        
        public class BaseAccess : Expression {
 
-               public enum BaseAccessType {
+               public enum BaseAccessType : byte {
                        Member,
                        Indexer
                };
@@ -3501,6 +3962,12 @@ namespace CIR {
                        eclass = ExprClass.Value;
                }
 
+               public EmptyExpression (Type t)
+               {
+                       type = t;
+                       eclass = ExprClass.Value;
+               }
+               
                public override Expression DoResolve (EmitContext ec)
                {
                        return this;