Esempio n. 1
0
        public string OutputInstruction(int idx, OPCodes.Codes code, IEnumerable <string> args)
        {
            List <string> strs = new List <string>();

            strs.Add(Print("[{0}] {1} {2}", idx, code.ToString(), String.Join(" ", args)));

            return(BuildMerge(strs));
        }
Esempio n. 2
0
        public void ReadProgram()
        {
            int fctId = 0;

            while (!Reader.IsOver())
            {
                int idx        = Reader.GetCounter();
                int checkIndex = Reader.GetCounter() - (Defines.SIZE_INT * (FuncsIdx.Count + 1));

                if (FuncsIdx.Contains(checkIndex))
                {
                    Output.OutputFunctionStart(idx - Defines.SIZE_INT * (FuncsIdx.Count + 1), fctId++, Reader.NextInt());
                }
                else
                {
                    OPCodes.Codes code = (OPCodes.Codes)Reader.NextInt();
                    List <string> args = ExtractArgs(code);

                    Output.OutputInstruction(idx - Defines.SIZE_INT * (FuncsIdx.Count + 1), code, args);
                }
            }
        }
Esempio n. 3
0
        public void ExecNextOp()
        {
            Registers.JumpCarry = false;

            if (!Stack.Any())
            {
                Running = false;
                return;
            }

            ActiveStackContainer = Stack.Peek();
            int counter = ActiveStackContainer.ProgramCounter;

            OPCodes.Codes code   = GetOPCode(counter);
            ProgramReader reader = new ProgramReader(this, counter);

            reader.NextInt();

            if (ActiveStackContainer is LibStackContainer)
            {
                ProgramReader r = new ProgramReader(ActiveStackContainer.Memory.Memory, 0);

                ActiveStackContainer.As <LibStackContainer>().Invoke(LibraryHandler, r);
                OPCalls.Functions.FunctionPop(this, reader);
            }
            else
            {
                Func <Processor, ProgramReader, int> fct = OPCodesActions.Actions[code];
                counter += fct(this, reader);
            }

            if (!Registers.JumpCarry)
            {
                ActiveStackContainer.ProgramCounter = counter;
            }
        }
Esempio n. 4
0
 public GenericInstruction(OPCodes.Codes code)
 {
     Code = code;
 }
Esempio n. 5
0
        public List <string> ExtractArgs(OPCodes.Codes code)
        {
            List <string> args = new List <string>();
            List <int>    read = new List <int>();

            if (!Args.ContainsKey(code))
            {
                args.Add("Unknown OP code");
            }

            ArgumentType[] toExtract = Args.ContainsKey(code) ? Args[code] : new ArgumentType[] {};

            foreach (ArgumentType i in toExtract)
            {
                int    size  = 0;
                byte[] bytes = null;

                if (i.IsStatic())
                {
                    bytes = Reader.NextArray(i.Size);
                    size  = i.Size;

                    try
                    {
                        read.Add(BitConverter.ToInt32(bytes));
                    }
                    catch (Exception e)
                    {
                        read.Add(-1);
                    }
                }
                else
                {
                    bytes = Reader.NextArray(read[i.Idx]);
                    size  = read[i.Idx];
                    read.Add(size);
                }



                if (i is Int)
                {
                    args.Add("INT[" + BitConverter.ToInt32(bytes) + "]");
                }

                if (i is Ptr)
                {
                    args.Add("PTR[" + BitConverter.ToInt32(bytes) + "]");
                }

                if (i is Array)
                {
                    List <string> strs = new List <string>();

                    foreach (byte b in bytes)
                    {
                        strs.Add(b.ToString());
                    }

                    args.Add("ARRAY[" + String.Join(", ", strs) + "]");
                }

                if (i is CharArray)
                {
                    List <byte> strs = new List <byte>();

                    foreach (byte b in bytes)
                    {
                        strs.Add(b);
                    }

                    args.Add("STRING[" + Encoding.ASCII.GetString(strs.ToArray()) + "]");
                }

                if (i is ConditionFlag)
                {
                    args.Add(i.As <ConditionFlag>().GetFlag(BitConverter.ToInt32(bytes)));
                }

                if (i is TypeFlag)
                {
                    args.Add(i.As <TypeFlag>().GetFlag(BitConverter.ToInt32(bytes)));
                }

                if (i is TargetFlag)
                {
                    args.Add(i.As <TargetFlag>().GetFlag(bytes[0]));
                }
            }

            return(args);
        }
Esempio n. 6
0
 private byte[] OPCall(OPCodes.Codes c)
 {
     return(BitConverter.GetBytes((int)c));
 }
Esempio n. 7
0
 public void Add(OPCodes.Codes code)
 {
     Bytes.Add(BitConverter.GetBytes((int)code));
 }