/// <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); }
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); }