public void Transition()
        {
            while (!Stop())
            {
                AbstractInstruction next = _program.CurrentInstruction();
                AMHeap heap = (AMHeap)_dataArea;

                next.Execute(this);
            }
        }
Example #2
0
        public AbstractInstruction CreateInstruction(string instructionName, string arg1, string arg2, string arg3, string arg4)
        {
            string[]            arguments           = { arg1, arg2, arg3, arg4 };
            AbstractInstruction a                   = (AbstractInstruction)_instructions[instructionName];
            AbstractInstruction abstractInstruction = (AbstractInstruction)Activator.CreateInstance(a.GetType());

            abstractInstruction.Process(arguments);

            return(abstractInstruction);
        }
Example #3
0
 public void AddInstruction(AbstractInstruction instruction)
 {
     if (_program == null)
     {
         _program    = new ProgramNode(instruction);
         _programTop = _program;
         _p          = _program;
         return;
     }
     _programTop.Next = new ProgramNode(instruction);
     _programTop      = _programTop.Next;
 }
Example #4
0
 public void AddInstruction(AbstractInstruction instruction)
 {
     if (_program == null)
     {
         _program = new ProgramNode(instruction);
         _programTop = _program;
         _p = _program;
         return;
     }
     _programTop.Next = new ProgramNode(instruction);
     _programTop = _programTop.Next;
 }
Example #5
0
 private static void WriteXmlInstructionArguments(XmlTextWriter xmltw, AbstractInstruction cinst)
 {
     switch (cinst.NumberOfArguments())
     {
         case 0:
             xmltw.WriteStartElement(cinst.Name());
             xmltw.WriteEndElement();
             break;
         case 1:
             xmltw.WriteStartElement(cinst.Name());
             xmltw.WriteAttributeString("arg1", cinst.ToString().Split(new char[] { ' ' })[1]);
             xmltw.WriteEndElement();
             break;
         case 2:
             xmltw.WriteStartElement(cinst.Name());
             if (cinst.Name() == "put_structure")
             {
                 string args = cinst.ToString().Split(new char[] { ' ' })[1];
                 xmltw.WriteAttributeString("arg1", args.Split(new char[] { ',' })[0]);
                 xmltw.WriteAttributeString("arg2", args.Split(new char[] { ',' })[1]);
                 xmltw.WriteEndElement();
             }
             else
             {
                 if (cinst.ToString().IndexOf('"') != -1)
                 {
                     // put_constant "Hello, World", X0
                     string instStr = cinst.ToString();
                     string arg1 = instStr.Substring(instStr.IndexOf('"'), instStr.LastIndexOf('"') - instStr.IndexOf('"') + 1);
                     string arg2 = instStr.Substring(instStr.LastIndexOf('"') + 2);
                     xmltw.WriteAttributeString("arg1", arg1);
                     xmltw.WriteAttributeString("arg2", arg2);
                     xmltw.WriteEndElement();
                 }
                 else if (cinst.ToString().IndexOf('\'') != -1)
                 {
                     // put_constant 'Hello, World', X0
                     string instStr = cinst.ToString();
                     string arg1 = instStr.Substring(instStr.IndexOf('\''), instStr.LastIndexOf('\'') - instStr.IndexOf('\'') + 1);
                     string arg2 = instStr.Substring(instStr.LastIndexOf('\'') + 2);
                     xmltw.WriteAttributeString("arg1", arg1);
                     xmltw.WriteAttributeString("arg2", arg2);
                     xmltw.WriteEndElement();
                 }
                 else
                 {
                     string args = cinst.ToString().Split(new char[] { ' ' })[1];
                     xmltw.WriteAttributeString("arg1", args.Split(new char[] { ',' })[0]);
                     xmltw.WriteAttributeString("arg2", args.Split(new char[] { ',' })[1]);
                     xmltw.WriteEndElement();
                 }
             }
             break;
     }
 }
Example #6
0
 private static void WriteXmlInstruction(XmlTextWriter xmltw, AbstractInstruction cinst)
 {
     switch (cinst.Name())
     {
         case "call":
         case "execute":
         case "bcall":
             xmltw.WriteStartElement(cinst.Name());
             xmltw.WriteAttributeString("name", cinst.ToString().Split(new char[] { ' ' })[1]);
             xmltw.WriteEndElement();
             break;
         case "fcall":
             FCallInstruction fcinst = (FCallInstruction)cinst;
             xmltw.WriteStartElement(cinst.Name());
             xmltw.WriteAttributeString("assembly", fcinst._assemblyName);
             xmltw.WriteAttributeString("class", fcinst._classType);
             xmltw.WriteAttributeString("method", fcinst._methodName);
             xmltw.WriteAttributeString("predicate", fcinst._predicateName);
             break;
         default:
             WriteXmlInstructionArguments(xmltw, cinst);
             break;
     }
 }
Example #7
0
 public ProgramNode(AbstractInstruction instruction, ProgramNode next)
 {
     _instruction = instruction;
     _next        = next;
 }
Example #8
0
 public ProgramNode(AbstractInstruction instruction)
 {
     _instruction = instruction;
     _next        = null;
 }
Example #9
0
 public ProgramNode()
 {
     _instruction = null;
     _next        = null;
 }
Example #10
0
        private string GetInstructionStatement(AbstractInstruction inst)
        {
            string statement = "program.Add(iset.CreateInstruction(";
            if (inst.Name() == "procedure")
            {
                ProcedureInstruction pi = (ProcedureInstruction)inst;
                statement += "\"procedure\", \"" + pi.ProcedureName + "\", \"" + pi.Arity + "\"";
            }
            else
            {
                if (inst._arguments == null || inst._arguments.Length == 0)
                {
                    statement += "\"" + inst.Name() + "\"";
                }
                else
                {
                    statement += "\"" + inst.Name() + "\", ";
                    for (int i = 0; i < inst._arguments.Length; i++)
                    {
                        statement += "\"" + inst._arguments[i] + "\"";
                        if (i != (inst._arguments.Length - 1))
                        {
                            statement += ", ";
                        }
                    }
                }
            }

            statement += "));";

            return statement;
        }
Example #11
0
 public ProgramClause(string name, int arity, AbstractInstruction instruction)
 {
     _instruction = instruction;
     _name = name;
     _arity = arity;
 }
Example #12
0
 public ProgramClause(string name, int arity, AbstractInstruction instruction)
 {
     _instruction = instruction;
     _name        = name;
     _arity       = arity;
 }
Example #13
0
 public ProgramNode(AbstractInstruction instruction, ProgramNode next)
 {
     _instruction = instruction;
     _next = next;
 }
Example #14
0
 public ProgramNode(AbstractInstruction instruction)
 {
     _instruction = instruction;
     _next = null;
 }
Example #15
0
 public ProgramNode()
 {
     _instruction = null;
     _next = null;
 }
Example #16
0
 private bool CompareInstructions(AbstractInstruction i1, AbstractInstruction i2)
 {
     return i1.ToString() == i2.ToString();
 }