示例#1
0
        public override void Execute(AbstractMachineState state)
        {
            AMPredicateSet pset = AMPredicateSet.Instance;

            if (pset.IsValidPredicate(_builtinName))
            {
                IAbstractMachinePredicate p = (IAbstractMachinePredicate)pset.CreatePredicate(_builtinName);
                // determine if p is a non-deterministic predicate
                Type pType = p.GetType();
                if (pType.IsInstanceOfType(new AbstractNonDeterministicPredicate()))
                {
                    ((AbstractNonDeterministicPredicate)p).IncrementCallID();
                }
                p.Execute(state);
            }
        }
        private void InstallExternalPredicates()
        {
            AMPluginManager p = new AMPluginManager();

            foreach (ExternalPredicate e in p.Plugins)
            {
                IAbstractMachinePredicate predicate = LoadExternalPredicate(e.Path, e.Name);
                if (predicate == null)
                {
                    throw new Exception("Remote predicate " + e.Name + " does not implement correct interface.");
                }

                if (!e.Name.Equals(predicate.Name() + "/" + predicate.Arity().ToString()))
                {
                    throw new Exception("Cannot install corrupted remote predicate: " + e.Name);
                }

                // Add new external predicate
                _predicates[e.Name] = predicate;
            }
        }
        public void assertz_1()
        {
            AMPredicateSet set = AMPredicateSet.Instance;

            AbstractMachineState state = SetupMachine();

            IAbstractMachinePredicate pred = set.CreatePredicate("assertz/1");

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

            X0.Assign(new ConstantTerm("it_is_sunny"));

            Assert.AreEqual("assertz", pred.Name());
            Assert.AreEqual(1, pred.Arity());

            pred.Execute(state);

            AMProgram program = (AMProgram)state.Program;

            Assert.IsNotNull(program["it_is_sunny/0"]);
        }
示例#4
0
 public void EmitBCall(IAbstractMachinePredicate pred)
 {
     _instructions.Add(_instructionSet.CreateInstruction("bcall", pred.Name() + "/" + pred.Arity()));
 }
        public IAbstractMachinePredicate CreatePredicate(string predicateName)
        {
            IAbstractMachinePredicate p = (IAbstractMachinePredicate)_predicates[predicateName];

            return((IAbstractMachinePredicate)Activator.CreateInstance(p.GetType()));
        }
示例#6
0
 public void EmitBCall(IAbstractMachinePredicate pred)
 {
     _instructions.Add(_instructionSet.CreateInstruction("bcall", pred.Name() + "/" + pred.Arity()));
 }