Esempio n. 1
0
        public static void EmitIsAlive(_ATHProgram program, ILGenerator ilGenerator, Tuple <string, Colour> name) // bool()
        {
            var getProcessesByName = ((Func <string, Process[]>)Process.GetProcessesByName).Method;

            ilGenerator.Emit(OpCodes.Ldstr, name.Item1);
            ilGenerator.EmitCall(OpCodes.Call, getProcessesByName, null);
            ilGenerator.Emit(OpCodes.Ldlen);
        }
Esempio n. 2
0
 public override void EmitIL(_ATHProgram program, Colour expressionColour, ILGenerator ilGenerator, Dictionary <string, ImportHandle> importHandles, Dictionary <Tuple <string, Colour>, ImportHandle> objects)
 {
     foreach (var expression in _expressions)
     {
         expression.EmitIL(program, expressionColour, ilGenerator, importHandles, objects);
         program.EmitDieIfKilled(ilGenerator, expressionColour);
     }
 }
Esempio n. 3
0
        public static void EmitDie(_ATHProgram program, ILGenerator ilGenerator, Tuple <string, Colour> name) // void()
        {
            var getProcessesByName = ((Func <string, Process[]>)Process.GetProcessesByName).Method;
            var killProcess        = typeof(Process).GetMethod("Kill");

            ilGenerator.Emit(OpCodes.Ldstr, name.Item1);
            ilGenerator.EmitCall(OpCodes.Call, getProcessesByName, null);
            ilGenerator.Emit(OpCodes.Ldc_I4_0);
            ilGenerator.Emit(OpCodes.Ldelem_Ref);
            ilGenerator.EmitCall(OpCodes.Callvirt, killProcess, null);
        }
Esempio n. 4
0
 public override void EmitIL(_ATHProgram program, Colour expressionColour, ILGenerator ilGenerator, Dictionary <string, ImportHandle> importHandles, Dictionary <Tuple <string, Colour>, ImportHandle> objects)
 {
     if (Target == "THIS")
     {
         program.EmitKillTHIS(ilGenerator, TargetColour ?? expressionColour);
     }
     else
     {
         var target = Tuple.Create(Target, TargetColour ?? expressionColour);
         objects[target].EmitDie(program, ilGenerator, target);
     }
 }
Esempio n. 5
0
        public override void EmitIL(_ATHProgram program, Colour expressionColour, ILGenerator ilGenerator, Dictionary <string, ImportHandle> importHandles, Dictionary <Tuple <string, Colour>, ImportHandle> objects)
        {
            var importHandle = importHandles[Type];
            var colouredName = Tuple.Create(Name, NameColour ?? expressionColour);

            if (objects.ContainsKey(colouredName))
            {
                if (objects[colouredName] != importHandle)
                {
                    throw new _ATHParserException("Tried to use same object name and colour with different import types.");
                }
            }
            else
            {
                objects[colouredName] = importHandle;
            }

            importHandle.EmitImport(program, ilGenerator, TypeColour ?? expressionColour, colouredName);
        }
Esempio n. 6
0
        public override void EmitIL(_ATHProgram program, Colour expressionColour, ILGenerator ilGenerator, Dictionary <string, ImportHandle> importHandles, Dictionary <Tuple <string, Colour>, ImportHandle> objects)
        {
            var startLabel = ilGenerator.DefineLabel();
            var endLabel   = ilGenerator.DefineLabel();

            ilGenerator.MarkLabel(startLabel);

            if (Target == "THIS")
            {
                program.EmitIsTHISAlive(ilGenerator, TargetColour ?? expressionColour);

                if (Not)
                {
                    ilGenerator.Emit(OpCodes.Brtrue, endLabel);
                }
                else
                {
                    ilGenerator.Emit(OpCodes.Brfalse, endLabel);
                }
            }
            else
            {
                var target = Tuple.Create(Target, TargetColour ?? expressionColour);
                objects[target].EmitIsAlive(program, ilGenerator, target);
                if (Not)
                {
                    ilGenerator.Emit(OpCodes.Brtrue, endLabel);
                }
                else
                {
                    ilGenerator.Emit(OpCodes.Brfalse, endLabel);
                }
            }

            foreach (var expression in _loopExpressions)
            {
                program.EmitDieIfKilled(ilGenerator, expressionColour);

                expression.EmitIL(program, expressionColour, ilGenerator, importHandles, objects);
            }

#if !NODELAY
            var threadSleep = ((Action <int>)Thread.Sleep).Method;

            ilGenerator.Emit(OpCodes.Ldc_I4, 100);
            ilGenerator.EmitCall(OpCodes.Call, threadSleep, null);
#endif

            ilGenerator.Emit(OpCodes.Br, startLabel);

            ilGenerator.MarkLabel(endLabel);

            if (ExecuteExpression != null)
            {
                if (ExecuteExpression is NULLExpression)
                {
                    // Empty.
                }
                else
                {
                    program.EmitDieIfKilled(ilGenerator, expressionColour);

                    ExecuteExpression.EmitIL(program, expressionColour, ilGenerator, importHandles, objects);
                }
            }
            else
            {
                var getFullPath  = ((Func <string, string>)Path.GetFullPath).Method;
                var startProcess = ((Func <string, Process>)Process.Start).Method;

                ilGenerator.Emit(OpCodes.Ldstr, ExecuteCommand);
                ilGenerator.EmitCall(OpCodes.Call, getFullPath, null);
                ilGenerator.EmitCall(OpCodes.Call, startProcess, null);
                ilGenerator.Emit(OpCodes.Pop);
            }
        }
Esempio n. 7
0
 public override void EmitIL(_ATHProgram program, Colour expressionColour, ILGenerator ilGenerator, Dictionary <string, ImportHandle> importHandles, Dictionary <Tuple <string, Colour>, ImportHandle> objects)
 {
     // Empty.
 }
Esempio n. 8
0
 public override void EmitIL(_ATHProgram program, Colour expressionColour, ILGenerator ilGenerator, Dictionary <string, ImportHandle> importHandles, Dictionary <Tuple <string, Colour>, ImportHandle> objects)
 {
     ilGenerator.ThrowException(typeof(NullReferenceException));
 }
Esempio n. 9
0
 public override void EmitIL(_ATHProgram program, Colour expressionColour, ILGenerator ilGenerator, Dictionary <string, ImportHandle> importHandles, Dictionary <Tuple <string, Colour>, ImportHandle> objects)
 {
     throw new _ATHParserException("THIS list DIE expression not valid at this position.");
 }
Esempio n. 10
0
 public static void EmitImport(_ATHProgram program, ILGenerator ilGenerator, Colour importColour, Tuple <string, Colour> name) // void()
 {
     // Empty.
 }
Esempio n. 11
0
        public override void EmitIL(_ATHProgram program, Colour expressionColour, ILGenerator ilGenerator, Dictionary <string, ImportHandle> importHandles, Dictionary <Tuple <string, Colour>, ImportHandle> objects)
        {
            EnsureTHISListDIEMatch(expressionColour, ColouredExpressions[ColouredExpressions.Length - 1]);

            MethodBuilder[] methodBuilders;

            {
                List <_ATHExpression>[] sortedExpressions = new List <_ATHExpression> [Colours.Length];
                for (int i = 0; i < sortedExpressions.Length; i++)
                {
                    sortedExpressions[i] = new List <_ATHExpression>();
                }

                methodBuilders = new MethodBuilder[Colours.Length];
                ILGenerator[] methodILGenerators = new ILGenerator[Colours.Length];
                for (int i = 0; i < methodBuilders.Length; i++)
                {
                    methodBuilders[i]     = program.CreateTHISMethod(Colours[i]);
                    methodILGenerators[i] = methodBuilders[i].GetILGenerator();
                }

                for (int ice = 0; ice < ColouredExpressions.Length - 1; ice++)
                {
                    var colour     = ColouredExpressions[ice].Item1;
                    var expression = ColouredExpressions[ice].Item2;

                    if (expression is CommentExpression)
                    {
                        //Optimization
                        continue;
                    }

                    var matched = false;
                    for (int ic = 0; ic < Colours.Length; ic++)
                    {
                        if (Colours[ic] == colour || expressionColour == colour)
                        {
                            program.EmitDieIfKilled(methodILGenerators[ic], Colours[ic]);

                            expression.EmitIL(program, colour, methodILGenerators[ic], importHandles, objects);
                            matched = true;
                        }
                    }

                    if (matched == false)
                    {
                        throw new _ATHParserException("Unknown expression colour #" + colour.HexString + ".");
                    }
                }

                for (int ic = 0; ic < Colours.Length; ic++)
                {
                    program.EmitDieIfKilled(methodILGenerators[ic], Colours[ic]);
                    program.EmitKillTHIS(methodILGenerators[ic], Colours[ic]);
                    program.EmitDieIfKilled(methodILGenerators[ic], Colours[ic]);
                    methodILGenerators[ic].ThrowException(typeof(InvalidProgramException));
                }
            }

            program.EmitTHISFork(ilGenerator, Colours, methodBuilders);

            program.EmitTHISJoin(ilGenerator, expressionColour, Colours);
        }