示例#1
0
        /// <summary>
        /// Link an input pin of an instruction to an output pin of another in a specific function
        /// </summary>
        /// <param name="functionID">Identifier of the function in which retreive the instructions</param>
        /// <param name="fromID">Identifier of the instruction from which link the output</param>
        /// <param name="outputName">Name of the output to link</param>
        /// <param name="toID">Identifier of the instruction to which link to input</param>
        /// <param name="intputName">Name of the input to link</param>
        public void LinkInstructionData(UInt32 functionID, UInt32 fromID, string outputName, UInt32 toID, string inputName)
        {
            CorePackage.Entity.Function func = entity_factory.FindDefinitionOfType <CorePackage.Entity.Function>(functionID);

            func.LinkInstructionData(fromID, outputName, toID, inputName);
            //func.findInstruction<CorePackage.Execution.Instruction>(toID).GetInput(intputName).LinkTo(func.findInstruction<CorePackage.Execution.Instruction>(fromID), outputName);
        }
示例#2
0
        /// <summary>
        /// Link an execution pin of an instruction to another in a specific function
        /// </summary>
        /// <param name="functionID">Identifier of the function in which retreive the instructions</param>
        /// <param name="fromID">Instruction from which link the execution pin</param>
        /// <param name="outIndex">Index of the pin used for the link</param>
        /// <param name="toID">Instruction to link</param>
        public void LinkInstructionExecution(UInt32 functionID, UInt32 fromID, UInt32 outIndex, UInt32 toID)
        {
            CorePackage.Entity.Function func = entity_factory.FindDefinitionOfType <CorePackage.Entity.Function>(functionID);

            func.LinkInstructionExecution(fromID, outIndex, toID);
            //func.findInstruction<CorePackage.Execution.ExecutionRefreshInstruction>(fromID).LinkTo(outIndex, func.findInstruction<CorePackage.Execution.ExecutionRefreshInstruction>(toID));
        }
示例#3
0
        /// <summary>
        /// Add an instruction to a specific function
        /// </summary>
        /// <param name="functionID">Identifier of a specific function</param>
        /// <param name="to_create">Type of instruction to add</param>
        /// <param name="crea_args">List of entities' identifier to send to the instruction constructor</param>
        /// <returns>The identifier of the created instruction</returns>
        public UInt32 AddInstruction(UInt32 functionID, InstructionFactory.INSTRUCTION_ID to_create, List <UInt32> crea_args)
        {
            CorePackage.Entity.Function           func             = entity_factory.FindDefinitionOfType <CorePackage.Entity.Function>(functionID);
            List <CorePackage.Global.IDefinition> crea_definitions = new List <CorePackage.Global.IDefinition>();

            foreach (UInt32 definitionID in crea_args)
            {
                crea_definitions.Add(entity_factory.Find(definitionID));
            }
            return(func.addInstruction(InstructionFactory.CreateInstruction(to_create, crea_definitions)));
        }
示例#4
0
        public void DumpFunctionInto(UInt32 funcId, string directory)
        {
            CorePackage.Entity.Function func = entity_factory.FindDefinitionOfType <CorePackage.Entity.Function>(funcId);
            System.IO.FileStream        file = new System.IO.FileStream(directory + "/" + func.Name + ".dot", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);

            if (file.CanWrite)
            {
                string dat = func.ToDotFile();

                file.Write(Encoding.ASCII.GetBytes(dat), 0, dat.Length);
                file.Close();
            }
            else
            {
                throw new InvalidOperationException("Couldn't write data in file");
            }
        }
示例#5
0
        public void TestObjectActions()
        {
            CorePackage.Entity.Type.ObjectType type    = new CorePackage.Entity.Type.ObjectType();
            CorePackage.Entity.DataType        integer = CorePackage.Entity.Type.Scalar.Integer;

            type.AddAttribute("x", integer, CorePackage.Global.AccessMode.EXTERNAL);
            type.AddAttribute("y", integer, CorePackage.Global.AccessMode.EXTERNAL);
            type.AddAttribute("z", integer, CorePackage.Global.AccessMode.EXTERNAL);

            CorePackage.Entity.Function getAttrSum = new CorePackage.Entity.Function();
            type.Declare(getAttrSum, "getAttrSum", CorePackage.Global.AccessMode.EXTERNAL);
            type.SetFunctionAsMember("getAttrSum");

            CorePackage.Entity.Variable res = new CorePackage.Entity.Variable(CorePackage.Entity.Type.Scalar.Integer);
            res.Name = "res";
            getAttrSum.Declare(res, "res", CorePackage.Global.AccessMode.EXTERNAL);
            getAttrSum.SetVariableAs("res", CorePackage.Entity.Function.VariableRole.RETURN);

            Dictionary <string, dynamic> t = type.Instantiate();

            Assert.IsTrue(t.ContainsKey("x") && t.ContainsKey("y") && t.ContainsKey("z"));

            CorePackage.Entity.Variable tvar = new CorePackage.Entity.Variable(type);

            tvar.Value["x"] = 3;
            tvar.Value["y"] = 42;
            tvar.Value["z"] = -29;

            //show fields

            uint getT = getAttrSum.addInstruction(new CorePackage.Execution.Getter(getAttrSum.GetParameter("this")));

            uint getAttrs = getAttrSum.addInstruction(new CorePackage.Execution.GetAttributes(type));

            getAttrSum.LinkInstructionData(getT, "reference", getAttrs, "this");

            uint setRes = getAttrSum.addInstruction(new CorePackage.Execution.Setter(res));

            //x + y
            uint xPy = getAttrSum.addInstruction(new CorePackage.Execution.Operators.Add(CorePackage.Entity.Type.Scalar.Integer, CorePackage.Entity.Type.Scalar.Integer, CorePackage.Entity.Type.Scalar.Integer));

            getAttrSum.LinkInstructionData(getAttrs, "x", xPy, CorePackage.Global.Operator.Left);
            getAttrSum.LinkInstructionData(getAttrs, "y", xPy, CorePackage.Global.Operator.Right);

            //x + y + z
            uint xPyPz = getAttrSum.addInstruction(new CorePackage.Execution.Operators.Add(CorePackage.Entity.Type.Scalar.Integer, CorePackage.Entity.Type.Scalar.Integer, CorePackage.Entity.Type.Scalar.Integer));

            getAttrSum.LinkInstructionData(xPy, CorePackage.Global.Operator.Result, xPyPz, CorePackage.Global.Operator.Left);
            getAttrSum.LinkInstructionData(getAttrs, "z", xPyPz, CorePackage.Global.Operator.Right);

            getAttrSum.LinkInstructionData(xPyPz, CorePackage.Global.Operator.Result, setRes, "value");

            getAttrSum.setEntryPoint(setRes);

            //System.IO.File.WriteAllText("toto.dot", getAttrSum.ToDotFile());
            getAttrSum.Call(new Dictionary <string, dynamic> {
                { "this", tvar.Value }
            });

            Console.WriteLine(getAttrSum.GetReturnValue("res"));
            Assert.IsTrue(getAttrSum.GetReturnValue("res") == 16);

            CorePackage.Entity.Function addOp = (CorePackage.Entity.Function)type.Declare(new CorePackage.Entity.Function(), "Add", CorePackage.Global.AccessMode.EXTERNAL);

            // Object Add(Object this, Objet RightOperand);
            type.SetFunctionAsMember("Add");
            CorePackage.Entity.Variable rgt = new CorePackage.Entity.Variable(type);
            rgt.Name = CorePackage.Global.Operator.Right;

            addOp.Declare(rgt, CorePackage.Global.Operator.Right, CorePackage.Global.AccessMode.EXTERNAL);
            addOp.SetVariableAs(CorePackage.Global.Operator.Right, CorePackage.Entity.Function.VariableRole.PARAMETER);

            CorePackage.Entity.Variable rs = new CorePackage.Entity.Variable(type);
            rs.Name = CorePackage.Global.Operator.Result;

            addOp.Declare(rs, CorePackage.Global.Operator.Result, CorePackage.Global.AccessMode.EXTERNAL);
            addOp.SetVariableAs(CorePackage.Global.Operator.Result, CorePackage.Entity.Function.VariableRole.RETURN);

            type.OverloadOperator(CorePackage.Global.Operator.Name.ADD, "Add");

            /*
             *
             * result.x = this.x + RightOperand.x;
             * result.y = this.y + RightOperand.y;
             * result.z = this.z + RightOperand.z;
             *
             */

            uint getThis   = addOp.addInstruction(new CorePackage.Execution.Getter(addOp.GetParameter("this")));
            uint splitThis = addOp.addInstruction(new CorePackage.Execution.GetAttributes(type));

            addOp.LinkInstructionData(getThis, "reference", splitThis, "this");

            uint getROP   = addOp.addInstruction(new CorePackage.Execution.Getter(addOp.GetParameter(CorePackage.Global.Operator.Right)));
            uint splitROP = addOp.addInstruction(new CorePackage.Execution.GetAttributes(type));

            addOp.LinkInstructionData(getROP, "reference", splitROP, "this");

            //this.x + RightOperand.x
            uint addX = addOp.addInstruction(new CorePackage.Execution.Operators.Add(integer, integer, integer));

            addOp.LinkInstructionData(splitThis, "x", addX, CorePackage.Global.Operator.Left);
            addOp.LinkInstructionData(splitROP, "x", addX, CorePackage.Global.Operator.Right);

            //this.y + RightOperand.y
            uint addY = addOp.addInstruction(new CorePackage.Execution.Operators.Add(integer, integer, integer));

            addOp.LinkInstructionData(splitThis, "y", addY, CorePackage.Global.Operator.Left);
            addOp.LinkInstructionData(splitROP, "y", addY, CorePackage.Global.Operator.Right);

            //this.z + RightOperand.z
            uint addZ = addOp.addInstruction(new CorePackage.Execution.Operators.Add(integer, integer, integer));

            addOp.LinkInstructionData(splitThis, "z", addZ, CorePackage.Global.Operator.Left);
            addOp.LinkInstructionData(splitROP, "z", addZ, CorePackage.Global.Operator.Right);

            uint getRes   = addOp.addInstruction(new CorePackage.Execution.Getter(addOp.GetReturn(CorePackage.Global.Operator.Result)));
            uint splitRes = addOp.addInstruction(new CorePackage.Execution.GetAttributes(type));

            addOp.LinkInstructionData(getRes, "reference", splitRes, "this");

            uint setResult = addOp.addInstruction(new CorePackage.Execution.SetAttribute(type));

            addOp.LinkInstructionData(getRes, "reference", setResult, "this");
            addOp.LinkInstructionData(addX, CorePackage.Global.Operator.Result, setResult, "x");
            addOp.LinkInstructionData(addY, CorePackage.Global.Operator.Result, setResult, "y");
            addOp.LinkInstructionData(addZ, CorePackage.Global.Operator.Result, setResult, "z");

            addOp.setEntryPoint(setResult);

            var toadd = type.Instantiate();

            toadd["x"] = 12;
            toadd["y"] = 20;
            toadd["z"] = -42;

            tvar.Value["x"] = 3;
            tvar.Value["y"] = 42;
            tvar.Value["z"] = -29;

            var addition = type.OperatorAdd(toadd, tvar.Value);

            Assert.IsTrue(addition["x"] == 15);
            Assert.IsTrue(addition["y"] == 62);
            Assert.IsTrue(addition["z"] == -71);
        }
示例#6
0
        /// <summary>
        /// Set an input value of an instruction in a specific function
        /// </summary>
        /// <param name="functionID">Identifier of the function from which retreive the instruction</param>
        /// <param name="instruction">Identifier of the instruction that contains the input to set</param>
        /// <param name="inputname">Name of the input to which set the value</param>
        /// <param name="inputValue">Value to set to the input</param>
        public void SetInstructionInputValue(UInt32 functionID, UInt32 instruction, string inputname, dynamic inputValue)
        {
            CorePackage.Entity.Function func = entity_factory.FindDefinitionOfType <CorePackage.Entity.Function>(functionID);

            func.findInstruction <CorePackage.Execution.Instruction>(instruction).SetInputValue(inputname, inputValue);
        }