public void Pop_an_empty_heap() { AMHeap heap = new AMHeap(); object top = heap.Pop(); Assert.IsNull(top); }
public void Push_AbstractTerm() { AMHeap heap = new AMHeap(); AbstractTerm term = new AbstractTerm(); heap.Push(term); Assert.AreSame(heap.Top(), term); }
public void Transition() { while (!Stop()) { AbstractInstruction next = _program.CurrentInstruction(); AMHeap heap = (AMHeap)_dataArea; next.Execute(this); } }
public void Push_ConstantTerm() { AMHeap heap = new AMHeap(); ConstantTerm con = new ConstantTerm("Hello, World!"); heap.Push(con); Assert.AreSame(con, heap.Top()); }
public void Initialize() { AMHeap heap = new AMHeap(); AbstractMachineState state = new AbstractMachineState(new AMFactory()); heap.Initialize(state); Assert.IsNull(heap.H); Assert.IsNull(heap.Top()); }
public void Pop_one_item() { AMHeap heap = new AMHeap(); ConstantTerm con = new ConstantTerm("ali"); heap.Push(con); heap.Pop(); Assert.IsNull(heap.Top()); }
public void Pop_two_items() { AMHeap heap = new AMHeap(); ConstantTerm con = new ConstantTerm("ali"); ConstantTerm first = new ConstantTerm("foo"); heap.Push(first); heap.Push(con); heap.Pop(); Assert.AreSame(first, heap.Top()); }
private object GetRegisterValue(string registerName) { switch (registerName[0]) { case 'Y': return(GetPermanentRegister(registerName)); case 'X': return(GetDataRegister(registerName)); case 'H': AMHeap heap = (AMHeap)_dataArea; return(heap.H); } return(null); }
public bool Call(string predicatename, int arity, object[] args, bool more) { AMProgram program = (AMProgram)_program; AMHeap heap = (AMHeap)_dataArea; AMInstructionSet iset = new AMInstructionSet(); // argument indexes ArrayList argumentIndexes = new ArrayList(); if (!more) { _passedVariables = new ArrayList(); } for (int i = 0; i < args.Length; i++) { if (args[i] != null) { switch (args[i].GetType().ToString()) { case "System.String": case "System.Int32": case "System.Boolean": if (!more) { AbstractTerm var = new ConstantTerm(args[i].ToString()); heap.Push(var); _passedVariables.Add(-1); AbstractTerm Xn = (AbstractTerm)this["X" + i]; Xn.Assign(var); } break; case "Axiom.Runtime.AbstractTerm": if (!more) { AbstractTerm heapVariable = new AbstractTerm(); heap.Push(heapVariable); _passedVariables.Add(heapVariable); AbstractTerm Xn = (AbstractTerm)this["X" + i]; Xn.Assign(heapVariable); } break; } } } if (!more) { program.P = new ProgramNode(iset.CreateInstruction("call", predicatename, arity.ToString())); program.AddProgramNode(program.P); program.AddInstruction(iset.CreateInstruction("halt")); } // Execute the program Transition(); for (int i = 0; i < _passedVariables.Count; i++) { if (!(_passedVariables[i] is int)) { AbstractTerm v = (AbstractTerm)_passedVariables[i]; AbstractTerm argumentVariable = (AbstractTerm)args[i]; argumentVariable.Assign(v.Dereference()); } } return(!_fail); }
public bool Call(string predicateName, int arity, object[] args) { AMProgram program = (AMProgram)_program; AMHeap heap = (AMHeap)_dataArea; AMInstructionSet iset = new AMInstructionSet(); if (!program.IsDefined(predicateName + "/" + arity)) { return(false); } ArrayList a = new ArrayList(); ProgramNode entryPoint = null; for (int i = 0; i < args.Length; i++) { switch (args[i].GetType().ToString()) { case "System.String": case "System.Int32": case "System.Boolean": if (entryPoint == null) { entryPoint = new ProgramNode(iset.CreateInstruction("put_constant", args[i].ToString(), "X" + i.ToString())); program.AddProgramNode(entryPoint); } else { program.AddInstruction(iset.CreateInstruction("put_constant", args[i].ToString(), "X" + i.ToString())); } break; case "Axiom.Runtime.AbstractTerm": a.Add(i); if (entryPoint == null) { entryPoint = new ProgramNode(iset.CreateInstruction("put_variable", "X" + args[i].ToString(), "X" + i.ToString())); program.AddProgramNode(entryPoint); } else { program.AddInstruction(iset.CreateInstruction("put_variable", "X" + args[i].ToString(), "X" + args[i].ToString())); } break; } } // Add the call instruction program.AddInstruction(iset.CreateInstruction("call", predicateName, arity.ToString())); // Add the halt insturction program.AddInstruction(iset.CreateInstruction("halt")); program.P = entryPoint; // Execute the program Transition(); foreach (int argumentNumber in a) { AbstractTerm var = (AbstractTerm)args[argumentNumber]; var.Assign((AbstractTerm)this["X" + argumentNumber.ToString()]); } return(!_fail); }
public void Push_ListTerm() { AMHeap heap = new AMHeap(); ListTerm con = new ListTerm(); heap.Push(con); Assert.AreSame(con, heap.Top()); }
public void Stop() { AMHeap heap = new AMHeap(); Assert.IsTrue(heap.Stop()); }
public void Push_StructureTerm() { AMHeap heap = new AMHeap(); StructureTerm con = new StructureTerm("Hello, World!", 2); heap.Push(con); Assert.AreSame(con, heap.Top()); }
public void Push_ObjectTerm() { AMHeap heap = new AMHeap(); ObjectTerm con = new ObjectTerm(); heap.Push(con); Assert.AreSame(con, heap.Top()); }