public void AddAdditionalActionOf(string pName, string pType, FunctionPointer pAction) { // [2013:4:19:MOON] Added StateGame aObj = (StateGame) GetObjectNameOf (pName); //(" HtStateArray :: AddAdditionalActionOf " + aObj.mName).HtLog (); aObj.AddAnActionTo (pType, pAction); }
public void AddExitAction(FunctionPointer pCond) { StateGame lastGame = (StateGame)arrState [arrState.Count - 1]; //if (pCond == null) // lastGame.mExitCondition = ReturnFalse; lastGame.mExitAction = pCond; }
public void AddAMemberAndEntryAction(string pName, float pTimerSet, string pType, FunctionPointer pEntry) { StateGame newObj; if (pType == "Packet") newObj = new StatePacket (pName, pTimerSet); else newObj = new StateGame (pName, pTimerSet); arrState.Add (newObj); StateGame lastGame = (StateGame)arrState [arrState.Count - 1]; lastGame.mEntryAction = pEntry; }
public void float4_sincos_burst() { FunctionPointer <float4_sincos.TestFunction> testFunction = BurstCompiler.CompileFunctionPointer <float4_sincos.TestFunction>(float4_sincos.BurstTestFunction); var args = new float4_sincos.Arguments(); args.Init(); Measure.Method(() => { testFunction.Invoke(ref args); }) .Definition(sampleUnit: SampleUnit.Microsecond) .WarmupCount(1) .MeasurementCount(10) .Run(); args.Dispose(); }
public void Random_NextUint_burst() { FunctionPointer <Random_NextUint.TestFunction> testFunction = BurstCompiler.CompileFunctionPointer <Random_NextUint.TestFunction>(Random_NextUint.BurstTestFunction); var args = new Random_NextUint.Arguments(); args.Init(); var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => { testFunction.Invoke(ref args); }) .SampleGroup(burstSampleGroup) .WarmupCount(1) .MeasurementCount(10) .Run(); args.Dispose(); }
public void quaternion_to_RigidTransform_burst() { FunctionPointer <quaternion_to_RigidTransform.TestFunction> testFunction = BurstCompiler.CompileFunctionPointer <quaternion_to_RigidTransform.TestFunction>(quaternion_to_RigidTransform.BurstTestFunction); var args = new quaternion_to_RigidTransform.Arguments(); args.Init(); var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => { testFunction.Invoke(ref args); }) .SampleGroup(burstSampleGroup) .WarmupCount(1) .MeasurementCount(10) .Run(); args.Dispose(); }
public void float4x4_EulerXYZ_burst() { FunctionPointer <float4x4_EulerXYZ.TestFunction> testFunction = BurstCompiler.CompileFunctionPointer <float4x4_EulerXYZ.TestFunction>(float4x4_EulerXYZ.BurstTestFunction); var args = new float4x4_EulerXYZ.Arguments(); args.Init(); var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => { testFunction.Invoke(ref args); }) .SampleGroup(burstSampleGroup) .WarmupCount(1) .MeasurementCount(10) .Run(); args.Dispose(); }
public void orthonormal_basis_double_burst() { FunctionPointer <orthonormal_basis_double.TestFunction> testFunction = BurstCompiler.CompileFunctionPointer <orthonormal_basis_double.TestFunction>(orthonormal_basis_double.BurstTestFunction); var args = new orthonormal_basis_double.Arguments(); args.Init(); var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => { testFunction.Invoke(ref args); }) .SampleGroup(burstSampleGroup) .WarmupCount(1) .MeasurementCount(10) .Run(); args.Dispose(); }
internal static void RemoveManagedReferences(EntityDataAccess *mgr, int *sharedIndex, int count) { #if !UNITY_IOS if (!UseDelegate()) { #if ENABLE_UNITY_COLLECTIONS_CHECKS if (_bfp_RemoveManagedReferences.Data == IntPtr.Zero) { throw new InvalidOperationException("Burst Interop Classes must be initialized manually"); } #endif var fp = new FunctionPointer <Managed._dlg_RemoveManagedReferences>(_bfp_RemoveManagedReferences.Data); fp.Invoke((IntPtr)mgr, (IntPtr)sharedIndex, count); return; } #endif _RemoveManagedReferences(mgr, sharedIndex, count); }
static void Main(string[] args) { // This is the instance of the delegate to which our function // pointer will point. FunctionPointer printInConsoleDelegate; // Create the delegate object "MyFunctionPointer" that references printInConsoleDelegate = new FunctionPointer(printInConsole); // Get a pointer to the delegate that can be passed to the C lib IntPtr printInConsolePtr = Marshal.GetFunctionPointerForDelegate(printInConsoleDelegate); Console.WriteLine( "Call C++ which's calling back C# func \"printInConsole\""); // Call C++ which calls C# callCSharpFunction(printInConsolePtr); // Stop the console until user's pressing Enter Console.ReadLine(); }
//--------------------------------------------------- // BarRaider's Hall Of Fame // CyberlightGames - 1 Gifted Subs //--------------------------------------------------- // Honorary Mention // Marbles On Stream winner: xntss //--------------------------------------------------- public static void HandleFunctionRequest(string functionData, Dictionary <string, string> dicVariables) { if (dicVariables == null) { Logger.Instance.LogMessage(TracingLevel.WARN, $"HandleFunctionRequest Dictionary is null"); return; } string[] parameters = functionData.Split(':'); if (parameters.Length < 3) { Logger.Instance.LogMessage(TracingLevel.WARN, $"HandleFunctionRequest Invalid number of params {functionData}"); return; } // Handle the incoming parameters string functionName = parameters[0].ToUpperInvariant(); string outputVariable = parameters[1].ToUpperInvariant(); for (int currentParam = 2; currentParam < parameters.Length; currentParam++) { parameters[currentParam] = ExtendedMacroHandler.TryExtractVariable(parameters[currentParam]); } // Try and figure out the right function to call FunctionPointer requestedFunction = RetreiveRequestedFunction(functionName); if (requestedFunction == null) { Logger.Instance.LogMessage(TracingLevel.WARN, $"HandleFunctionRequest Invalid function name {functionName}"); return; } string result = requestedFunction(parameters.Skip(2).ToArray()); if (result == null) { Logger.Instance.LogMessage(TracingLevel.WARN, $"HandleFunctionRequest Invalid result from {functionName}"); return; } dicVariables[outputVariable] = result; }
protected override void OnStartRunning() { base.OnStartRunning(); Stand = CompileFunction(VelocityStates.Standing); Run = CompileFunction(VelocityStates.Running); Jump = CompileFunction(VelocityStates.Running); Fall = CompileFunction(VelocityStates.Standing); Standing = new VelocityState { Name = VelocityStates.Standing, VelocityFunction = Stand }; Running = new VelocityState { Name = VelocityStates.Running, VelocityFunction = Run }; Jumping = new VelocityState { Name = VelocityStates.Jumping, VelocityFunction = Jump }; Falling = new VelocityState { Name = VelocityStates.Falling, VelocityFunction = Fall }; _transitions = new NativeArray <VelocityState>(new VelocityState[16] { // Run Stand Jump Fall Running, Standing, Jumping, Falling, // Standing Running, Standing, Jumping, Falling, // Running Jumping, Standing, Jumping, Falling, // Jumping Falling, Standing, Falling, Falling // Falling }, Allocator.Persistent); }
public static string FullName(FunctionPointer fp) { StringBuilder sb = new StringBuilder(); // CciHelper's FullName only returns the return type of the function pointer, not the parameters sb.Append(fp.FullName); sb.Append("("); for (int i = 0; i < fp.ParameterTypes.Count; i++) { sb.Append(fp.ParameterTypes[i].FullName); if (i == fp.ParameterTypes.Count - 1) { sb.Append(")"); } else { sb.Append(","); } } return(sb.ToString()); }
public void ProblemWithFunctionPointer() { Assert.Throws <ArgumentException>(() => { GenericDelegate <int> d = (int i) => i++; IntPtr pFunc = Marshal.GetFunctionPointerForDelegate(d); var dmd = Marshal.GetDelegateForFunctionPointer <GenericDelegate <int> >(pFunc); int r = dmd.Invoke(1); Assert.AreEqual(2, r); Debug.Log(r); FunctionPointerDuplicate <GenericDelegate <int> > fpFuncDup = new FunctionPointerDuplicate <GenericDelegate <int> >(pFunc); r = fpFuncDup.InvokeWithGenericMarshalFunc(1); Assert.AreEqual(2, r); Debug.Log(r); FunctionPointer <GenericDelegate <int> > fpFunc = new FunctionPointer <GenericDelegate <int> >(pFunc); r = fpFunc.Invoke(1); Assert.AreEqual(2, r); Debug.Log(r); }); }
static void Main() { string[] names = { "Philips", "PIC", "BLR", "BSDK", "CHN" }; FindString("P", names); FindString("B", names); FindString("p", names); FindString("b", names); FunctionPointer _pointer1 = new FunctionPointer(CheckStringLength_3); FindString(_pointer1, names); FunctionPointer _pointer2 = new FunctionPointer(CheckStringLength_3); FindString(_pointer2, names); int[] numbers = { 1, 2, 3, 4, 56, 7 }; FunctionPointerGeneric <int> _pointer3 = new FunctionPointerGeneric <int>(CheckNumberEvenOrOdd); Find <int>(_pointer3, numbers); FunctionPointerGeneric <string> _pointer4 = new FunctionPointerGeneric <string>(CheckStringStartsWithP); Find <string>(_pointer4, names); List <string> nameList = names.ToList(); List <string> _result = Find <string>(_pointer4, nameList); for (int i = 0; i < _result.Count; i++) { Console.WriteLine(_result[i]); } foreach (string item in _result) { Console.WriteLine(_result[i]); } }
private static string memberbinding2str(MemberBinding mb) { StringBuilder sb = new StringBuilder(); if (mb.TargetObject == null) { if (mb.BoundMember.DeclaringType != null) { sb.Append(mb.BoundMember.DeclaringType.FullName); } else if (mb.BoundMember is FunctionPointer) { FunctionPointer fp = (FunctionPointer)mb.BoundMember; return(FullName(fp)); } else { return("(memberbinding2str found unknown memberbinding)"); } } else { sb.Append(expression2str(mb.TargetObject, false)); } sb.Append("."); Member member = mb.BoundMember; if ((member is Method) && (mb.TargetObject != null)) { sb.Append("{"); sb.Append(member.DeclaringType.FullName); sb.Append("}"); } sb.Append(mb.BoundMember.Name); return(sb.ToString()); }
public void AddDuringAction(FunctionPointer pCond) { StateGame lastGame = (StateGame)arrState [arrState.Count - 1]; lastGame.mDuringAction = pCond; }
public AutoFunction(FunctionPointer fp, float endTime, float updateTime, FunctionPointer endfp) : this(fp, endTime, updateTime) { endFunctionPointer = endfp; }
// arrEtry, arrDuri, arrExit; public void AddAnActionTo(string pType, FunctionPointer pAction) { // [2013:4:19:MOON] Added List<FunctionPointer> curArr = GetArrAction (pType); curArr.Add (pAction); }
private static void CompileFunctions() { _equalsTrueDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(EqualsTrueDecorator); _equalsFalseDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(EqualsFalseDecorator); }
public void AddAnActionTo(string pType, FunctionPointer pAction) // arrEtry, arrDuri, arrExit; { // [2013:4:19:MOON] Added List <FunctionPointer> curArr = GetArrAction(pType); curArr.Add(pAction); }
private static void CompileFunctions() { _addFloatEffectorFunction = BurstCompiler.CompileFunctionPointer <EffectorDelegate>(AddFloatEffector); _addIntegerEffectorFunction = BurstCompiler.CompileFunctionPointer <EffectorDelegate>(AddIntegerEffector); }
private static void CompileFunctions() { _decoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(Decorator); _invertedDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(InvertedDecorator); }
/// <summary> /// We treat this kind of call as non analyzable /// Not support for Function Pointers Yet /// </summary> /// <param name="dest"></param> /// <param name="callee"></param> /// <param name="receiver"></param> /// <param name="arguments"></param> /// <param name="fp"></param> /// <param name="stat"></param> /// <param name="arg"></param> /// <returns></returns> protected override object VisitCallIndirect(Variable dest, Variable callee, Variable receiver, Variable[] arguments, FunctionPointer fp, Statement stat, object arg) { PointsToState cState = (PointsToState)arg; Label lb = new Label(stat, cState.Method); ExpressionList expList = new ExpressionList(); foreach (Variable v in arguments) expList.Add(v); InterProcMapping ipm; cState.ApplyNonAnalyzableCall(dest,null, receiver, expList, lb, out ipm); // cState.ApplyNonAnalyzableCallBasic(dest, null, receiver, expList, lb); return cState; //return base.VisitCallIndirect(dest, callee, receiver, arguments, fp, stat, arg); }
static public (FunctionPointer <LifeFunction> shouldDie, FunctionPointer <LifeFunction> shouldComeToLife) GetRuleFunctions(RuleSet rules) { FunctionPointer <LifeFunction> shouldDie = default; FunctionPointer <LifeFunction> shouldComeToLife = default; switch (rules) { case RuleSet.Life: shouldDie = CompileDelegate(Life.ShouldDie); shouldComeToLife = CompileDelegate(Life.ComeToLife); break; case RuleSet.Replicator: shouldDie = CompileDelegate(Replicator.ShouldDie); shouldComeToLife = CompileDelegate(Replicator.ComeToLife); break; case RuleSet.Seeds: shouldDie = CompileDelegate(Seeds.ShouldDie); shouldComeToLife = CompileDelegate(Seeds.ComeToLife); break; case RuleSet.Unnamed: shouldDie = CompileDelegate(Unnamed.ShouldDie); shouldComeToLife = CompileDelegate(Unnamed.ComeToLife); break; case RuleSet.LifeWithoutDeath: shouldDie = CompileDelegate(LifeWithoutDeath.ShouldDie); shouldComeToLife = CompileDelegate(LifeWithoutDeath.ComeToLife); break; case RuleSet.Life34: shouldDie = CompileDelegate(Life34.ShouldDie); shouldComeToLife = CompileDelegate(Life34.ComeToLife); break; case RuleSet.Diamoeba: shouldDie = CompileDelegate(Diamoeba.ShouldDie); shouldComeToLife = CompileDelegate(Diamoeba.ComeToLife); break; case RuleSet.TwoByTwo: shouldDie = CompileDelegate(TwoByTwo.ShouldDie); shouldComeToLife = CompileDelegate(TwoByTwo.ComeToLife); break; case RuleSet.HighLife: shouldDie = CompileDelegate(HighLife.ShouldDie); shouldComeToLife = CompileDelegate(HighLife.ComeToLife); break; case RuleSet.DayAndNight: shouldDie = CompileDelegate(DayAndNight.ShouldDie); shouldComeToLife = CompileDelegate(DayAndNight.ComeToLife); break; case RuleSet.Morley: shouldDie = CompileDelegate(Morley.ShouldDie); shouldComeToLife = CompileDelegate(Morley.ComeToLife); break; case RuleSet.Anneal: shouldDie = CompileDelegate(Anneal.ShouldDie); shouldComeToLife = CompileDelegate(Morley.ComeToLife); break; } return(shouldDie, shouldComeToLife); }
protected override object VisitCallIndirect(Variable dest, Variable callee, Variable receiver, Variable[] arguments, FunctionPointer fp, Statement stat, object arg) { InitializedVariables iv=(InitializedVariables)arg; CheckUse(iv, callee, stat); CheckUse(iv, receiver, stat); foreach (Variable v in arguments) { CheckUse(iv, v, stat); } iv.SetLocationAssigned(dest); iv.SetNonDelayedRef(dest); return arg; }
public static void RegisterNamedEvent(string name, /*double*/ float scheduleTime, FunctionPointer functionPointer) { Remove(name); lock (_events) { _events.Add(new ScheduledEvent(name, functionPointer, scheduleTime)); } }
/// <summary> /// Unscrambles a method target. /// </summary> /// <param name="call">The method call node to unscramble</param> /// <param name="receiver">Returns the receiver expression. Maybe null.</param> /// <param name="callee">Returns the method, if target is a method, otherwise null.</param> /// <param name="fpointer">Returns the function pointer if target is a function pointer, otherwise null.</param> private void GetReceiverAndCallee ( MethodCall call, out Variable receiver, out Method callee, out FunctionPointer fpointer ) { MemberBinding mb = (MemberBinding) call.Callee; receiver = (Variable) mb.TargetObject; callee = mb.BoundMember as Method; fpointer = mb.BoundMember as FunctionPointer; }
public static int Conclude(FunctionPointer p) { //run the function irrespective of whether it is run / event run p.Invoke(); throw new NotImplementedException(); }
protected override object VisitCallIndirect (Variable dest, Variable callee, Variable receiver, Variable[] arguments, FunctionPointer fp, Statement stat, object arg) { return ((arg == null) ? "CALLI: " : (arg + "; ")) + ((dest != null) ? (CciHelper.Name(dest) + " := ") : "") + CciHelper.Name(callee) + "(" + ((receiver != null) ? ("this:" + CciHelper.Name(receiver) + ((arguments.Length>0) ? "," : "")) : "") + CodePrinter.vararray2str(arguments) + ")"; }
protected override object VisitCallIndirect(Variable dest, Variable callee, Variable receiver, Variable[] arguments, FunctionPointer fp, Statement stat, object arg) { // don't do anything here, since this is not verifiable code return(arg); }
/// <summary> /// dest := (*callee)([receiver], arguments) -- call indirect function pointer. /// </summary> /// <param name="dest">Variable that stores the result of the call. <c>null</c> if the called method /// return type is <c>void</c>.</param> /// <param name="callee">Function pointer value.</param> /// <param name="receiver">Receiver for virtual calls. <c>null</c> in the case of a static call /// (warning: static call and call to a static method are different things: you can call a virtual method /// without using dynamic dispatch).</param> /// <param name="arguments">Call arguments; does not include the value for the "this" argument; that value is /// the given by the receiver (if any). All elements of this list are Variables.</param> /// <param name="fp">Function pointer signature.</param> protected virtual object VisitCallIndirect (Variable dest, Variable callee, Variable receiver, Variable[] arguments, FunctionPointer fp, Statement stat, object arg) { return DefaultVisit(stat, arg); }
public static bool IsFunctionPointerValid <TDelegate>(ref FunctionPointer <TDelegate> functionPointer) where TDelegate : class { return(*(IntPtr *)UnsafeUtility.AddressOf(ref functionPointer) != IntPtr.Zero); }
private object visit_calli (Variable dest, Variable receiver, MethodCall call, FunctionPointer fpointer, Statement stat, object arg) { Variable[] parameters = new Variable[call.Operands.Count-1]; // last operand is function pointer. for (int i=0; i<call.Operands.Count-1; i++) { parameters[i]=(Variable)call.Operands[i]; } Variable fpvar = (Variable)call.Operands[call.Operands.Count-1]; return VisitCallIndirect(dest, fpvar, receiver, parameters, fpointer, stat, arg); }
public void AddTimeOutProcess(float pLimitTime, FunctionPointer pTimeout) { StateGame lastGame = (StateGame)arrState [arrState.Count - 1]; lastGame.mfLimitTime = pLimitTime; lastGame.mfnTimeOutProcess = pTimeout; }
internal void Initialize() { executePointer = BurstCompiler.CompileFunctionPointer <JobExecute>(OnExecute); }
public AutoFunction(FunctionPointer fp, float endTime, float updateTime) : this(fp, endTime) { this.updateTime = updateTime; }
private static void CompileFunctions() { _effectorFunction = BurstCompiler.CompileFunctionPointer <EffectorDelegate>(Effector); }
public void AddEntryAction(FunctionPointer pEntry) { StateGame lastGame = (StateGame)arrState [arrState.Count - 1]; lastGame.mEntryAction = pEntry; }
//public FileWrite fwrite1; // constructor public DifferentialEvolution(FunctionPointer minimizingfunction_)// string fileLoc) { minimizingfunction = minimizingfunction_; //fwrite1 = new FileWrite(fileLoc); }
protected override object VisitCallIndirect(Variable dest, Variable callee, Variable receiver, Variable[] arguments, FunctionPointer fp, Statement stat, object arg) { CheckVariable(receiver, arg as NNArrayStatus); CheckArguments(arguments, arg as NNArrayStatus); return arg; }
public ComputationProject(IntPtr ptr) { this.DisplayMethod = (FunctionPointer)Marshal.GetDelegateForFunctionPointer(ptr, typeof(FunctionPointer)); }
public static string FullName(FunctionPointer fp) { StringBuilder sb = new StringBuilder(); // CciHelper's FullName only returns the return type of the function pointer, not the parameters sb.Append(fp.FullName); sb.Append("("); for(int i=0; i < fp.ParameterTypes.Count; i++) { sb.Append(fp.ParameterTypes[i].FullName); if (i==fp.ParameterTypes.Count-1) { sb.Append(")"); } else { sb.Append(","); } } return sb.ToString(); }
public static void RegisterEvent(/*double*/ float scheduleTime, FunctionPointer functionPointer) { RegisterNamedEvent(string.Empty, scheduleTime, functionPointer); }
public BurstFunc(FunctionPointer <Func <TResult> > functionPointer) { this.functionPointer = functionPointer; burstEnabled = true; value = default; }
private static void CompileFunctions() { _multiplyFloatEffectorFunction = BurstCompiler.CompileFunctionPointer <EffectorDelegate>(MultiplyFloatEffector); _multiplyIntegerEffectorFunction = BurstCompiler.CompileFunctionPointer <EffectorDelegate>(MultiplyIntegerEffector); }