Esempio n. 1
0
        public void Call()
        {
            ArrayList prog = new ArrayList();

            prog.Add(new NopInstruction());
            prog.Add(new HaltInstruction());

            AbstractMachineState state = new AbstractMachineState(new AMFactory());

            state.Initialize(prog);

            AMProgram program = (AMProgram)state.Program;

            ArrayList predicateCode = new ArrayList();

            AMInstructionSet iset = new AMInstructionSet();

            // say_hello(X) :- write(X).

            predicateCode.Add(iset.CreateInstruction("bcall", "write/1"));
            predicateCode.Add(iset.CreateInstruction("proceed"));

            AbstractTerm X0 = (AbstractTerm)state["X0"];

            X0.Assign(new ConstantTerm("Hello, World!"));

            program.AssertFirst("say_hello", 1, predicateCode);

            Assert.IsTrue(state.Call("say_hello", 1, new object[] { "Hello man" }));
        }
Esempio n. 2
0
        public void IsValidInstruction()
        {
            AMInstructionSet am = new AMInstructionSet();

            foreach (string s in instructions)
            {
                Assert.IsTrue(am.IsValidInstruction(s));
                Assert.IsTrue(am.isValidInstruction(s));
            }
        }
Esempio n. 3
0
        public void CreateInstruction()
        {
            AMInstructionSet am = new AMInstructionSet();

            foreach (string s in instructions)
            {
                AbstractInstruction i = null;

                if (s == "set_void" || s == "unify_void")
                {
                    i = am.CreateInstruction(s, "1");
                    Assert.AreEqual(s, i.Name());
                }
                else
                {
                    i = am.CreateInstruction(s, "f/1", "1", "X2", "X3");
                    Assert.AreEqual(s, i.Name());
                }
            }
        }