示例#1
0
        private void CodeSetArray(SetArrayValueExpression set, List<LocalVariable> locals, List<GlobalVariable> globals, FuncParam[] parameters, ILGenerator il, List<Function> allFuncs, LocalBuilder tmpVar)
        {
            var vname = GetVariableName(set);
            Type t;
            if (locals.Any(x => x.Name == vname))
            {
                var loc = locals.First(x => x.Name == vname);
                t = loc.Type;
                il.Emit(OpCodes.Ldloc, loc.Info);
            }
            else if (globals.Any(x => x.Name == vname))
            {
                var glo = globals.First(x => x.Name == vname);
                t = glo.Type;
                il.Emit(OpCodes.Ldsfld, glo.FieldInfo);
            }
            else
            {
                var par = parameters.First(x => x.Name == vname);
                t = par.Type;
                il.Emit(OpCodes.Ldarg_S, (byte)par.Index);
            }

            CodeExpression(set.Index, locals, globals, parameters, il, allFuncs, tmpVar);
            CodeExpression(set.Value, locals, globals, parameters, il, allFuncs, tmpVar);
            il.Emit(OpCodes.Dup);
            il.Emit(OpCodes.Stloc, tmpVar);

            if (t == typeof (byte[]))
                il.Emit(OpCodes.Stelem_I1);
            else
                il.Emit(OpCodes.Stelem_I4);
            il.Emit(OpCodes.Ldloc, tmpVar);
        }
示例#2
0
        private void CodeRead(ReadStatement readStatement, List<LocalVariable> locals, List<GlobalVariable> globals, FuncParam[] parameters, ILGenerator il)
        {
            il.Emit(OpCodes.Call, typeof(Console).GetMethod("ReadLine", new Type[0]));
            il.Emit(OpCodes.Call, typeof(Convert).GetMethod("ToInt32", new Type[]{typeof(string)}));

            var vname = GetVariableName(readStatement);
            if (locals.Any(x => x.Name == vname))
            {
                var loc = locals.First(x => x.Name == vname);
                il.Emit(OpCodes.Stloc, loc.Info);
            }
            else if (globals.Any(x => x.Name == vname))
            {
                var glo = globals.First(x => x.Name == vname);
                il.Emit(OpCodes.Stsfld, glo.FieldInfo);
            }
            else
            {
                var par = parameters.First(x => x.Name == vname);
                il.Emit(OpCodes.Starg_S, (byte)par.Index);
            }
        }
示例#3
0
 private void CodeSet(SetValueExpression set, List<LocalVariable> locals, List<GlobalVariable> globals, FuncParam[] parameters, ILGenerator il, List<Function> allFuncs, LocalBuilder tmpVar)
 {
     CodeExpression(set.Value, locals, globals, parameters, il, allFuncs, tmpVar);
     il.Emit(OpCodes.Dup);
     var vname = GetVariableName(set);
     if (locals.Any(x => x.Name == vname))
     {
         var loc = locals.First(x => x.Name == vname);
         il.Emit(OpCodes.Stloc, loc.Info);
     }
     else if (globals.Any(x => x.Name == vname))
     {
         var glo = globals.First(x => x.Name == vname);
         il.Emit(OpCodes.Stsfld, glo.FieldInfo);
     }
     else
     {
         var par = parameters.First(x => x.Name == vname);
         il.Emit(OpCodes.Starg_S, (byte)par.Index);
     }
 }
示例#4
0
 private void CodeGet(GetValueExpression get, List<LocalVariable> locals, List<GlobalVariable> globals, FuncParam[] parameters, ILGenerator il)
 {
     var vname = GetVariableName(get);
     if (locals.Any(x => x.Name == vname))
     {
         var loc = locals.First(x => x.Name == vname);
         il.Emit(OpCodes.Ldloc, loc.Info);
     }
     else if (globals.Any(x => x.Name == vname))
     {
         var glo = globals.First(x => x.Name == vname);
         il.Emit(OpCodes.Ldsfld, glo.FieldInfo);
     }
     else
     {
         var par = parameters.First(x => x.Name == vname);
         il.Emit(OpCodes.Ldarg_S, (byte)par.Index);
     }
 }