Exemplo n.º 1
0
        public override void GenerateCode(Emit.ILGenerator ilg, ExecutionContext ec)
        {
            /*
             * Check for two things:
             * 1) Is it an argument?
             * 2) Is it a local variable (or global)
             */
            var arg = ec.GetParameter(varName);
            if (arg != null)
            {
                //This is an argument - we need to store it in its index.
                ilg.Emit(Emit.OpCodes.Starg, arg.Position);
                return;
            }

            var varDec = ec.GetVariable(varName);
            if (varDec == null)
            {
                //The person wants this to be a local variable. It has not been declared, so we must do it for them.
                varDec = ilg.DeclareLocal(e.GetEvaluatedType(ec));
                ec.AddVariable(varName, varDec);
            }

            e.Push(ilg, ec);
            ilg.Emit(Emit.OpCodes.Stloc, varDec); //Store the result of the expression.
        }
Exemplo n.º 2
0
        //Almacena el valor del tope de la pila en el nombre de variable proporcionado (no maneja ambito)
        public static void Almacenar(string nombre, Emit.ILGenerator _il)
        {
            if (!TablaDireccionesSimbolos.ContainsKey(nombre))
            {
                TablaDireccionesSimbolos[nombre] = _il.DeclareLocal(typeof(System.Int32));  //Solo variables enteras
            }

            Emit.LocalBuilder variableLocal = TablaDireccionesSimbolos[nombre];

            if (!variableLocal.LocalType.HasElementType) //(es una variable simple) verdadero solo en caso de vectores o matrices
            {
                _il.Emit(Emit.OpCodes.Stloc, TablaDireccionesSimbolos[nombre]);
            }
            else //es una matriz o vector y actuo acorde
            {
                throw new System.Exception("No se soportan arrays o matrices en las asignaciones");
            }
        }