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 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 RetryMeElse() { AbstractMachineState state = SetupMachine(); RetryMeElseInstruction i = new RetryMeElseInstruction(); AMProgram program = (AMProgram)state.Program; AMTrail trail = (AMTrail)state.Trail; Choicepoint b = new Choicepoint(); b.CE = new EnvironmentFrame(); b.B = new Choicepoint(); b.CP = new ProgramNode(); b.TR = 1; b.NextClause = new ProgramClause(); state.B = b; program.AddLabel("foobar/2", new ProgramClause()); object[] args = { "foobar/2" }; i.Process(args); i.Execute(state); Assert.AreEqual("retry_me_else", i.Name()); Assert.AreEqual(1, i.NumberOfArguments()); Assert.AreSame(state.E, b.CE); Assert.AreEqual(b.TR, trail.TR); Assert.AreEqual(state.B.NextClause, program["foobar/2"]); }
public void TryMeElse() { AbstractMachineState state = SetupMachine(); AMProgram program = (AMProgram)state.Program; AMTrail trail = (AMTrail)state.Trail; program.AddLabel("foobar/2", new ProgramClause()); TryMeElseInstruction i = new TryMeElseInstruction(); object[] args = { "foobar/2" }; i.Process(args); program.NumberOfArguments = 2; i.Execute(state); Assert.AreEqual("try_me_else", i.Name()); Assert.AreEqual(1, i.NumberOfArguments()); Assert.AreEqual(2, state.B.Arity); Assert.IsNull(state.B.B); Assert.AreSame(state.B.CE, state.E); Assert.AreSame(state.B.CP, program.CP); Assert.AreSame(state.B.NextClause, program["foobar/2"]); Assert.AreEqual(state.B.TR, trail.TR); }
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 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); }