Initialize() public method

public Initialize ( ArrayList instructions ) : void
instructions System.Collections.ArrayList
return void
Ejemplo n.º 1
0
        public void Call()
        {
            ArrayList prog = new ArrayList();
            prog.Add(new NopInstruction());
            prog.Add(new HaltInstruction());

            AbstractMachineState state = new AbstractMachineState(new AMFactory());
            state.Initialize(prog);

            AMProgram program = (AMProgram)state.Program;

            ArrayList predicateCode = new ArrayList();

            AMInstructionSet iset = new AMInstructionSet();

            // say_hello(X) :- write(X).

            predicateCode.Add(iset.CreateInstruction("bcall", "write/1"));
            predicateCode.Add(iset.CreateInstruction("proceed"));

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

            X0.Assign(new ConstantTerm("Hello, World!"));

            program.AssertFirst("say_hello", 1, predicateCode);

            Assert.IsTrue(state.Call("say_hello", 1, new object[] { "Hello man" }));
        }
        public void Call()
        {
            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);

            CallInstruction i = new CallInstruction();

            object[] args = { "male", "2" };

            i.Process(args);

            i.Execute(state);
            Assert.AreEqual("call", i.Name());
            Assert.AreEqual(2, i.NumberOfArguments());
            Assert.AreSame(clause, program.P);
            Assert.AreEqual("halt", program.CP.Instruction.Name());
        }
Ejemplo n.º 3
0
        public AbstractMachineState SetupMachine()
        {
            AbstractMachineState state = new AbstractMachineState(new AMFactory());
            ArrayList prog = new ArrayList();
            prog.Add(new HaltInstruction());

            state.Initialize(prog);

            return state;
        }
Ejemplo n.º 4
0
        public void Initialize()
        {
            ArrayList prog = new ArrayList();
            prog.Add(new NopInstruction());
            prog.Add(new HaltInstruction());

            AbstractMachineState state = new AbstractMachineState(new AMFactory());

            state.Initialize(prog);

            Assert.IsNotNull(state.Program);
            Assert.IsNotNull(state.DataArea);
        }
Ejemplo n.º 5
0
        public InteractiveCompiler(string filename)
        {
            PrologCodeProvider provider = new PrologCodeProvider();
            IPrologCompiler compiler = provider.CreateCompiler();
            PrologCompilerParameters parameters = new PrologCompilerParameters();
            PrologCompilerResults results = compiler.CompileAbstractCodeFromFile(parameters, "boot.pro");

            /* Run */
            AbstractMachineState runtime = new AbstractMachineState(new AMFactory());
            //runtime.Init(results.AbstractInstructions, results.ForeignMethods, results.Namespaces, results.AssemblyFiles);
            runtime.Initialize(results.AbstractInstructions);

            runtime.Transition();
        }
Ejemplo n.º 6
0
        public void Transition()
        {
            ArrayList prog = new ArrayList();
            prog.Add(new NopInstruction());
            prog.Add(new HaltInstruction());

            AbstractMachineState state = new AbstractMachineState(new AMFactory());

            state.Initialize(prog);
            state.Transition();

            Assert.IsTrue(state.Stop());
        }
Ejemplo n.º 7
0
        public void SaveRegisters()
        {
            AbstractMachineState state = new AbstractMachineState(new AMFactory());
            ArrayList prog = new ArrayList();
            prog.Add(new HaltInstruction());
            state.Initialize(prog);

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

            X0.Assign(new ConstantTerm("ali"));
            X1.Assign(new ConstantTerm("samir"));
            X2.Assign(new ConstantTerm("moe"));

            Choicepoint c = new Choicepoint();

            c.SaveRegisters(state, 3);

            Assert.AreEqual("ali", c["X0"].Data());
            Assert.AreEqual("samir", c["X1"].Data());
            Assert.AreEqual("moe", c["X2"].Data());
        }