public void IsConstant() { ConstantTerm t = new ConstantTerm(); AbstractTerm a = new ConstantTerm(); Assert.IsTrue(t.IsConstant); Assert.IsTrue(a.IsConstant); }
public void IsObject() { ConstantTerm t = new ConstantTerm(); AbstractTerm a = new ConstantTerm(); Assert.IsFalse(t.IsObject); Assert.IsFalse(a.IsObject); }
public void IsReference() { ConstantTerm t = new ConstantTerm(); AbstractTerm a = new ConstantTerm(); Assert.IsFalse(t.IsReference); Assert.IsFalse(a.IsReference); }
public void Bind() { ConstantTerm term = new ConstantTerm(); ConstantTerm term2 = new ConstantTerm(); term.Bind(term2); Assert.AreSame(term, term.Reference()); }
public void Push_ConstantTerm() { AMHeap heap = new AMHeap(); ConstantTerm con = new ConstantTerm("Hello, World!"); heap.Push(con); Assert.AreSame(con, heap.Top()); }
public void Dereference() { ConstantTerm term1 = new ConstantTerm(); ConstantTerm term2 = new ConstantTerm(); ConstantTerm term3 = new ConstantTerm(); term2.Bind(term3); term1.Bind(term2); Assert.AreSame(term1, term1.Dereference()); }
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()); }
public void Assign() { AbstractTerm term = new AbstractTerm(); ConstantTerm con = new ConstantTerm("ali"); term.Assign(con); Assert.AreSame(term.Dereference(), con); Assert.AreSame(term.Dereference(), con.Dereference()); Assert.AreEqual(term.Data(), con.Data()); Assert.AreSame(term.Reference(), con.Reference()); Assert.IsFalse(term.IsList); Assert.IsFalse(term.IsObject); Assert.IsFalse(term.IsReference); Assert.IsFalse(term.IsStructure); Assert.IsTrue(term.IsConstant); }
public void Unify_after_assignment() { AbstractTerm term = new AbstractTerm(); ConstantTerm con = new ConstantTerm("test"); term.Assign(con); Assert.AreEqual(term.Unify(con), con.Unify(term)); }
public void Unbind() { AbstractTerm term = new AbstractTerm(); ConstantTerm con = new ConstantTerm("ali"); term.Assign(con); term.Unbind(); Assert.AreNotSame(term.Reference(), con.Reference()); }
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 void IsStructure() { ConstantTerm t = new ConstantTerm(); AbstractTerm a = new ConstantTerm(); Assert.IsFalse(t.IsStructure); Assert.IsFalse(a.IsStructure); }
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 void Unify_lis_con() { ListTerm list = new ListTerm(); ConstantTerm con = new ConstantTerm(); Assert.IsFalse(list.Unify(con)); }
public void Unify_con_lis() { ConstantTerm con = new ConstantTerm("ali"); ListTerm term = new ListTerm(); Assert.IsFalse(con.Unify(term)); }
private bool InvokeMethod(AbstractTerm obj, AbstractTerm method, AbstractTerm returnObject, AbstractMachineState state) { if (obj.IsConstant) { // invoke a static method Assembly asm = GetRequiredAssembly(obj.Data() as string, state); Type type = asm.GetType(obj.Data() as string); if (type == null) { return false; } ArrayList paramArray = new ArrayList(); GetTypes(type.GetMethod(method.Data() as string), method, ref paramArray, obj); object[] arguments = paramArray.ToArray(); object res = type.InvokeMember(method.Data() as string, BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod, null, null, arguments); switch (res.GetType().ToString()) { case "System.Char": case "System.String": case "System.Int32": case "System.Boolean": returnObject.Assign(new ConstantTerm(res.ToString())); break; default: returnObject.Assign(new ObjectTerm(res)); break; } SetTypes(method, arguments); } else { // invoke an instance method ArrayList paramArray = new ArrayList(); GetTypes(obj.Data().GetType().GetMethod(method.Data() as string), method, ref paramArray, obj); object classObject = obj.Data(); MethodInfo omi = classObject.GetType().GetMethod(method.Data() as string); object[] arguments = paramArray.ToArray(); object res = obj.Data().GetType().InvokeMember(method.Data() as string, BindingFlags.Default | BindingFlags.ExactBinding | BindingFlags.InvokeMethod, null, obj.Data(), arguments); if (res != null) { switch (res.GetType().ToString()) { case "System.String": ConstantTerm rC = new ConstantTerm(res.ToString()); if (!returnObject.Unify(rC)) { return false; } break; case "System.Char": case "System.Int32": case "System.Boolean": ConstantTerm returnConstant = new ConstantTerm(res.ToString()); if (!returnObject.Unify(returnConstant)) { return false; } break; default: returnObject.Assign(new ObjectTerm(res)); break; } } SetTypes(method, arguments); } return true; }
public void Data() { ConstantTerm t = new ConstantTerm(); Assert.IsNull(t.Data()); }
public void UnifyLocalValue() { AbstractMachineState state = SetupMachine(); UnifyLocalValueInstruction i = new UnifyLocalValueInstruction(); ConstantTerm con = new ConstantTerm("ali"); state.S = con; object[] args = { "X0" }; i.Process(args); i.Execute(state); Assert.AreEqual("unify_local_value", i.Name()); Assert.AreEqual(1, i.NumberOfArguments()); AbstractTerm X0 = (AbstractTerm)state["X0"]; Assert.AreEqual("ali", X0.Dereference().Data()); }
public void Unify_con_str() { ConstantTerm con = new ConstantTerm("ali"); StructureTerm term = new StructureTerm("samir", 2); Assert.IsFalse(con.Unify(term)); }
public void Unify_con_ref() { AbstractTerm term = new AbstractTerm(); ConstantTerm con = new ConstantTerm("ali"); Assert.IsTrue(con.Unify(term)); Assert.AreSame(term.Data(), con.Data()); }
public void Unify_con_ne_con() { ConstantTerm con = new ConstantTerm("ali"); ConstantTerm term = new ConstantTerm("samir"); Assert.IsFalse(con.Unify(term)); }
public void Unify_ref_con() { AbstractTerm term = new AbstractTerm(); ConstantTerm con = new ConstantTerm(); Assert.IsTrue(term.Unify(con)); Assert.AreEqual(term.Data(), con.Data()); Assert.AreSame(term.Reference(), con.Reference()); Assert.IsTrue(term.IsConstant); Assert.IsFalse(term.IsReference); }
public void Unify_str_con() { ConstantTerm term = new ConstantTerm("ali"); StructureTerm s = new StructureTerm("s", 2); Assert.IsFalse(s.Unify(term)); }
public void Unify_con_eq_con() { ConstantTerm con = new ConstantTerm("ali"); ConstantTerm term = new ConstantTerm("ali"); Assert.IsTrue(con.Unify(term)); }
public bool Getproperty(AbstractTerm obj, AbstractTerm method, AbstractTerm returnObject) { if (obj.IsConstant) { // invoke a static get property Assembly asm = GetRequiredAssembly(obj.Data() as string, runtime); ; Type type = asm.GetType(obj.Data() as string); if (type == null) { return false; } if (type.GetProperty(method.Data() as string) == null) { return false; } object res = type.InvokeMember(method.Data() as string, BindingFlags.GetProperty | BindingFlags.Static | BindingFlags.Public, null, null, null); switch (res.GetType().ToString()) { case "System.String": AbstractTerm rC = new ConstantTerm(res.ToString()); if (!returnObject.Unify(rC)) { return false; } break; case "System.Char": case "System.Int32": case "System.Boolean": AbstractTerm returnConstant = new ConstantTerm(res.ToString()); if (!returnObject.Unify(returnConstant)) { return false; } break; default: returnObject.Unify(new ObjectTerm(res)); break; } } else { if (obj.Data().GetType().GetProperty(method.Data() as string) == null) { return false; } // invoke an instance get property object res = obj.Data().GetType().InvokeMember(method.Data() as string, BindingFlags.Default | BindingFlags.ExactBinding | BindingFlags.GetProperty, null, obj.Data(), null); switch (res.GetType().ToString()) { case "System.Char": case "System.String": case "System.Int32": case "System.Boolean": returnObject.Unify(new ConstantTerm(res.ToString())); break; default: returnObject.Unify(new ObjectTerm(res)); break; } } return true; }
public void ConstantTerm() { ConstantTerm c = new ConstantTerm("Ali"); Assert.AreEqual("Ali", c.Data()); }