Ejemplo n.º 1
0
        private void MakeNumericMove(bool patternMove)
        {
            double delta = 0.0;
            short  dir   = this.direction;
            int    index = this.index;

            if (patternMove)
            {
                dir   = this.lastDirection;
                index = this.lastIndex;
            }

            SafeDebug.Assert(index < this.variableInfos.Count, "this.index < this.variableInfos.Count");

            var  variableInfo    = this.variableInfos[index];
            var  currentVariable = variableInfo.variable;
            Term newValue        = null;

            delta = (double)dir * Math.Pow(10, -variableInfo.precision) * Math.Pow(2, this.patternMoves);

            if (TryAddDoubleToTerm(currentVariable.Term, delta, out newValue))
            {
                base.modelBuilder.TryAssign(currentVariable, this.bestModel.GetValue(newValue));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a thread.
        /// </summary>
        /// <returns>ThreadId</returns>
        public int CreateThread()
        {
            int threadId;

            if (!this.DestroyedExecutionMonitorIds.TryDequeue(out threadId))
            {
                threadId = this.ThreadExecutionMonitors.Count;
                this.ThreadExecutionMonitors.Add(null);
            }

            SafeDebug.Assert(this.ThreadExecutionMonitors[threadId] == null,
                             "this.destroyedExecutionMonitorIds[threadId] == null");

            SafeList <IThreadExecutionMonitor> childExecutionMonitors =
                new SafeList <IThreadExecutionMonitor>(2); // all callbacks

            foreach (var monitorFactory in this.MonitorFactories)
            {
                IThreadExecutionMonitor monitor;
                if (monitorFactory.TryCreateThreadMonitor(threadId, out monitor))
                {
                    childExecutionMonitors.Add(monitor);
                }
            }

            this.ThreadExecutionMonitors[threadId] =
                new ThreadExecutionMonitorMultiplexer(childExecutionMonitors);

            return(threadId);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves the defined field
        /// </summary>
        /// <param name="method"></param>
        /// <param name="definedField"></param>
        /// <returns></returns>
        public static bool TryGetFieldOfSetter(Method method, out Field definedField)
        {
            SafeDebug.Assert(method.ShortName.StartsWith("set_"), "");
            definedField = null;
            MethodBodyEx body;

            if (!method.TryGetBody(out body) || !body.HasInstructions)
            {
                return(false);
            }

            int         offset = 0;
            Instruction instruction;
            OpCode      prevOpcode = OpCodes.Nop;

            while (body.TryGetInstruction(offset, out instruction))
            {
                SafeDebug.AssumeNotNull(instruction, "instruction");
                OpCode opCode = instruction.OpCode;
                if (opCode == OpCodes.Stfld || opCode == OpCodes.Stsfld)
                {
                    definedField = instruction.Field;
                    return(true);
                }
                offset = instruction.NextOffset;
            }

            return(false);
        }
Ejemplo n.º 4
0
 public override void Shutdown(int code)
 {
     // finalizers
     IsInitialized = false;
     syncVarManager.ReleaseGCAddresses();
     this.ExitCode = (ChessExitCode)code;
     SafeDebug.Assert(this.exitCallback != null, "this.exitCallBack != null");
     this.exitCallback((ChessExitCode)code, null);
 }
Ejemplo n.º 5
0
        public void DestroyThread(int index)
        {
            SafeDebug.Assert(this.executionMonitors[index] != null, "this.executionMonitors[index] != null");
            IThreadExecutionMonitor m = this.executionMonitors[index];

            m.Destroy();
            this.destroyedExecutionMonitorIds.Enqueue(index);
            this.executionMonitors[index] = null;
        }
Ejemplo n.º 6
0
        public override void Shutdown(Exception e)
        {
            // finalizers
            IsInitialized = false;
            syncVarManager.ReleaseGCAddresses();
            this.ExitCode = ChessExitCode.TestFailure;
            SafeDebug.Assert(this.exitCallback != null, "this.exitCallBack != null");

            MChessChess.LeaveChess();
            this.exitCallback(ChessExitCode.TestFailure, e);
        }
Ejemplo n.º 7
0
 private static void CheckThreadReadyForMonitoring()
 {
     SafeDebug.Assert(_ThreadContext.IsReady, "_ThreadContext.IsReady");
     //var context = _ThreadContext.Current;
     //if (context == null)
     //{
     //    // SafeDebugger.Break();
     //    context = _ThreadContext.Current;
     //}
     using (_ThreadContext.Acquire())
     {
         // just checking whether everything is okay with this thread for monitoring
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns a method call for a PUT. This should be of certain characteristics,
        /// It should contain only one method call as generated by us
        /// </summary>
        /// <param name="putmethod"></param>
        /// <returns></returns>
        public static bool TryRetrieveMethodCall(Method putmethod, out Method assocmethod)
        {
            SafeDebug.AssumeNotNull(putmethod, "putmethod");
            assocmethod = null;

            MethodBodyEx mbodyex;
            bool         bresult = putmethod.TryGetBody(out mbodyex);

            SafeDebug.Assert(bresult, "Failed to get the body");

            int         offset = 0;
            Instruction instruction;

            List <Method> allCalledMethods = new List <Method>();

            while (mbodyex.TryGetInstruction(offset, out instruction))
            {
                SafeDebug.AssumeNotNull(instruction, "instruction");
                OpCode opCode = instruction.OpCode;

                if (opCode == OpCodes.Call || opCode == OpCodes.Callvirt)
                {
                    SafeDebug.Assume(opCode.OperandType == OperandType.InlineMethod,
                                     "opCode.OperandType == OperandType.InlineMethod");
                    allCalledMethods.Add(instruction.Method);
                }

                offset = instruction.NextOffset;
            }

            if (allCalledMethods.Count != 1)
            {
                return(false);
            }

            assocmethod = allCalledMethods[0];
            return(true);
        }