public void ExecuteVar() { AbstractMachineState state = SetupMachine(); ExecuteVariableInstruction i = new ExecuteVariableInstruction(); i.Process(new string[] { "X0" }); AMProgram program = (AMProgram)state.Program; ProgramClause x = new ProgramClause("male", 1); program.AddLabel("male/1", x); AbstractTerm X0 = (AbstractTerm)state["X0"]; StructureTerm s = new StructureTerm("male", 1); s.Next = new ConstantTerm("ali"); X0.Assign(s); i.Execute(state); Assert.AreSame(program.P, x); Assert.AreEqual("executevar", i.Name()); Assert.AreEqual(1, i.NumberOfArguments()); }
public void call_1() { AbstractMachineState state = SetupMachine(); AMProgram program = (AMProgram)state.Program; _p = new CallPredicate(); Verify("call", 1); AbstractTerm X0 = (AbstractTerm)state["X0"]; StructureTerm goal = new StructureTerm("male", 1); goal.Next = new ConstantTerm("ali"); program.AddLabel("male/1", new ProgramClause("male", 1)); X0.Assign(goal); _p.Execute(state); Assert.AreEqual(X0.Data(), "ali"); ProgramClause p = (ProgramClause)program.P; Assert.AreEqual(p.Name, "male"); Assert.AreEqual(p.Arity, 1); }
public void Execute() { AbstractMachineState state = new AbstractMachineState(new AMFactory()); ArrayList prog = new ArrayList(); prog.Add(new PutConstantInstruction()); prog.Add(new HaltInstruction()); state.Initialize(prog); AMProgram program = (AMProgram)state.Program; ProgramClause clause = new ProgramClause("male", 2); program.AddLabel("male/2", clause); ExecuteInstruction i = new ExecuteInstruction(); object[] args = { "male", "2" }; i.Process(args); i.Execute(state); Assert.AreEqual("execute", i.Name()); Assert.AreEqual(2, i.NumberOfArguments()); Assert.AreSame(clause, program.P); }
public void AddLabel_2() { ArrayList p = new ArrayList(); HaltInstruction hi = new HaltInstruction(); p.Add(hi); AMProgram program = new AMProgram(); program.Initialize(p); program.AddLabel("male/1", new ProgramClause("male", 1)); program.AddLabel("male/1", new ProgramClause("male", 1)); ProgramClause male1 = program["male/1"]; ProgramClause male2 = male1.NextPredicate; Assert.AreEqual(male1.Name, "male"); Assert.AreEqual(male1.Arity, 1); Assert.AreEqual(male1.Instruction.Name(), "try_me_else"); Assert.AreEqual(male2.Name, "male%1/1"); Assert.AreEqual(male2.Arity, 1); Assert.AreEqual(male2.Instruction.Name(), "trust_me"); }
public void lessthan_2() { AbstractMachineState state = SetupMachine(); AMProgram program = (AMProgram)state.Program; _p = new LessThanPredicate(); Verify("<", 2); AbstractTerm X0 = (AbstractTerm)state["X0"]; AbstractTerm X1 = (AbstractTerm)state["X1"]; Choicepoint b = new Choicepoint(); ProgramClause nextClause = new ProgramClause(); state.B = new Choicepoint(0, null, null, b, nextClause, 2, null); X0.Assign(new ConstantTerm("5")); X1.Assign(new ConstantTerm("1")); // X0 < X1 _p.Execute(state); Assert.AreSame(nextClause, program.P); }
public void AssertFirst_2() { ArrayList p = new ArrayList(); HaltInstruction hi = new HaltInstruction(); p.Add(hi); AMProgram program = new AMProgram(); program.Initialize(p); program.AssertFirst("male", 1, p); ProgramClause oldFirst = program["male/1"]; program.AssertFirst("male", 1, p); ProgramClause newFirst = program["male/1"]; Assert.AreEqual(newFirst.Name, "male"); Assert.AreEqual(newFirst.Arity, 1); Assert.AreEqual(newFirst.Instruction.Name(), "try_me_else"); Assert.AreEqual(oldFirst.Name, "male%1/1"); Assert.AreEqual(oldFirst.Arity, 1); Assert.AreEqual(oldFirst.Instruction.Name(), "trust_me"); }
public void NextClause() { Choicepoint c = new Choicepoint(); ProgramClause clause = new ProgramClause(); c.NextClause = clause; Assert.AreSame(clause, c.NextClause); }
public override void Execute(AbstractMachineState state) { AMProgram program = (AMProgram)state.Program; AMTrail trail = (AMTrail)state.Trail; AMHeap heap = (AMHeap)state.DataArea; ProgramClause nextClause = program[_label]; Choicepoint B = new Choicepoint(program.NumberOfArguments, state.E, program.CP, state.B, nextClause, trail.TR, heap.H); B.SaveRegisters(state, program.NumberOfArguments); state.B = B; program.Next(); }
public void Backtrack() { AbstractMachineState state = new AbstractMachineState(new AMFactory()); AMProgram program = (AMProgram)state.Program; state.Backtrack(); Assert.IsNotNull(program.P); ProgramClause nextClause = new ProgramClause(); state.B = new Choicepoint(2, null, null, null, nextClause, 3, null); state.Backtrack(); Assert.AreSame(program.P, nextClause); }
public void Custom() { HeapNode h = new HeapNode(); EnvironmentFrame ce = new EnvironmentFrame(); ProgramClause clause = new ProgramClause(); Choicepoint b = new Choicepoint(); ProgramNode cp = new ProgramNode(); Choicepoint c = new Choicepoint(2, ce, cp, b, clause, 3, h); Assert.AreSame(h, c.H); Assert.AreEqual(2, c.Arity); Assert.AreSame(ce, c.CE); Assert.AreSame(cp, c.CP); Assert.AreSame(b, c.B); Assert.AreSame(clause, c.NextClause); Assert.AreEqual(3, c.TR); }
public void bound_1_bound() { AbstractMachineState state = SetupMachine(); AMProgram program = (AMProgram)state.Program; _p = new BoundPredicate(); AbstractTerm X0 = (AbstractTerm)state["X0"]; Choicepoint b = new Choicepoint(); ProgramClause nextClause = new ProgramClause(); state.B = new Choicepoint(0, null, null, b, nextClause, 2, null); Verify("bound", 1); _p.Execute(state); Assert.AreNotSame(nextClause, program.P); }
public void AssertFirst_1() { ArrayList p = new ArrayList(); HaltInstruction hi = new HaltInstruction(); p.Add(hi); AMProgram program = new AMProgram(); program.Initialize(p); program.AssertFirst("male", 1, p); ProgramClause male1 = program["male/1"]; Assert.AreEqual(male1.Name, "male"); Assert.AreEqual(male1.Arity, 1); Assert.AreEqual(male1.Instruction.Name(), "nop"); }
public void var_1_bound() { AbstractMachineState state = SetupMachine(); AMProgram program = (AMProgram)state.Program; _p = new VarPredicate(); AbstractTerm X0 = (AbstractTerm)state["X0"]; X0.Assign(new ConstantTerm("ali")); Choicepoint b = new Choicepoint(); ProgramClause nextClause = new ProgramClause(); state.B = new Choicepoint(0, null, null, b, nextClause, 2, null); Verify("var", 1); _p.Execute(state); Assert.AreSame(nextClause, program.P); }
public void atom_1_struct() { AbstractMachineState state = SetupMachine(); AMProgram program = (AMProgram)state.Program; _p = new AtomPredicate(); AbstractTerm X0 = (AbstractTerm)state["X0"]; X0.Assign(new StructureTerm("f", 1)); Choicepoint b = new Choicepoint(); ProgramClause nextClause = new ProgramClause(); state.B = new Choicepoint(0, null, null, b, nextClause, 2, null); Verify("atom", 1); _p.Execute(state); Assert.AreSame(nextClause, program.P); }
public void notunifiable_2() { AbstractMachineState state = SetupMachine(); AMProgram program = (AMProgram)state.Program; _p = new NotUnifiablePredicate(); AbstractTerm X0 = (AbstractTerm)state["X0"]; AbstractTerm X1 = (AbstractTerm)state["X1"]; X0.Assign(new ConstantTerm("ali")); X1.Assign(new ConstantTerm("ali")); Choicepoint b = new Choicepoint(); ProgramClause nextClause = new ProgramClause(); state.B = new Choicepoint(0, null, null, b, nextClause, 2, null); Verify("\\=", 2); _p.Execute(state); Assert.AreSame(nextClause, program.P); }
public void AssertFirst_3() { ArrayList p = new ArrayList(); HaltInstruction hi = new HaltInstruction(); p.Add(hi); AMProgram program = new AMProgram(); program.Initialize(p); program.AssertFirst("male", 1, p); ProgramClause male3 = program["male/1"]; program.AssertFirst("male", 1, p); ProgramClause male2 = program["male/1"]; program.AssertFirst("male", 1, p); ProgramClause male1 = program["male/1"]; Assert.AreEqual(male1.Name, "male"); Assert.AreEqual(male1.Arity, 1); Assert.AreEqual(male1.Instruction.Name(), "try_me_else"); Assert.AreEqual(male2.Name, "male%1/1"); Assert.AreEqual(male2.Arity, 1); Assert.AreEqual(male2.Instruction.Name(), "retry_me_else"); Assert.AreEqual(male3.Name, "male%2/1"); Assert.AreEqual(male3.Arity, 1); Assert.AreEqual(male3.Instruction.Name(), "trust_me"); }