示例#1
0
 public PrtEventNode(PrtValue e, PrtValue payload, string senderMachineName, string senderMachineStateName)
 {
     ev  = e;
     arg = payload.Clone();
     this.senderMachineName      = senderMachineName;
     this.senderMachineStateName = senderMachineStateName;
 }
示例#2
0
        public override bool IsEqual(PrtValue val)
        {
            Debug.Assert(val is PrtSeqValue, "Error in type checking, invalid equals invocation");
            var seqVal = val as PrtSeqValue;

            if (seqVal.elements.Count != this.elements.Count)
            {
                return(false);
            }
            else
            {
                int index = 0;
                while (index < this.elements.Count)
                {
                    if (!this.elements[index].IsEqual(seqVal.elements[index]))
                    {
                        return(false);
                    }

                    index++;
                }
            }

            return(true);
        }
示例#3
0
        public void EnqueueEvent(PrtValue e, PrtValue arg)
        {
            Debug.Assert(e is PrtEventValue, "Illegal enqueue of null event");
            PrtEventValue ev = e as PrtEventValue;

            if (ev.evt.maxInstances == PrtEvent.DefaultMaxInstances)
            {
                events.Add(new PrtEventNode(e, arg));
            }
            else
            {
                if (CalculateInstances(e) == ev.evt.maxInstances)
                {
                    if (ev.evt.doAssume)
                    {
                        throw new PrtAssumeFailureException();
                    }
                    else
                    {
                        throw new PrtMaxEventInstancesExceededException(
                                  String.Format(@"< Exception > Attempting to enqueue event {0} more than max instance of {1}\n", ev.evt.name, ev.evt.maxInstances));
                    }
                }
                else
                {
                    events.Add(new PrtEventNode(e, arg));
                }
            }
        }
示例#4
0
 public PrtContinuation()
 {
     reason    = PrtContinuationReason.Return;
     retVal    = PrtValue.@null;
     nondet    = false;
     retLocals = new List <PrtValue>();
 }
示例#5
0
        public PrtValue UpdateAndReturnOldValue(PrtValue index, PrtValue val)
        {
            var oldVal = Lookup(index);

            Update(index, val);
            return(oldVal);
        }
示例#6
0
 public static PrtValue PrtConvertValue(PrtValue value, PrtType type)
 {
     //cast for interface types is implemented as reduce.
     if (type is PrtInterfaceType)
     {
         return((type as PrtInterfaceType).PrtReduceValue(value));
     }
     else if (type is PrtIntType)
     {
         if (value is PrtIntValue)
         {
             return(new PrtIntValue((value as PrtIntValue).nt));
         }
         else
         {
             return(new PrtIntValue((Int64)(value as PrtFloatValue).ft));
         }
     }
     else if (type is PrtFloatType)
     {
         if (value is PrtIntValue)
         {
             return(new PrtFloatValue((value as PrtIntValue).nt));
         }
         else
         {
             return(new PrtFloatValue((Int64)(value as PrtFloatValue).ft));
         }
     }
     else
     {
         throw new PrtInternalException("unexpected type in convert operation");
     }
 }
示例#7
0
        public PrtValue UpdateAndReturnOldValue(int index, PrtValue val)
        {
            var oldVal = fieldValues[index];

            fieldValues[index] = val;
            return(oldVal);
        }
示例#8
0
文件: PrtValue.cs 项目: up1/P
        public override bool Equals(PrtValue val)
        {
            var tup = val as PrtNamedTupleValue;

            if (tup == null)
            {
                return(false);
            }
            if (tup.fieldValues.Count != this.fieldValues.Count)
            {
                return(false);
            }
            for (int i = 0; i < tup.fieldValues.Count; i++)
            {
                if (this.fieldNames[i] != tup.fieldNames[i])
                {
                    return(false);
                }
                if (!this.fieldValues[i].Equals(tup.fieldValues[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#9
0
文件: PrtValue.cs 项目: up1/P
        public override bool Equals(PrtValue val)
        {
            if (val is PrtNamedTupleValue)
            {
                return(false);
            }
            var tupValue = (val as PrtTupleValue);

            if (tupValue == null)
            {
                return(false);
            }
            if (tupValue.fieldValues.Count != this.fieldValues.Count)
            {
                return(false);
            }
            for (int i = 0; i < fieldValues.Count; i++)
            {
                if (!this.fieldValues[i].Equals(tupValue.fieldValues[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#10
0
        public PrtValue UpdateAndReturnOldValue(PrtValue key, PrtValue val)
        {
            var oldVal = Lookup(key);

            Update(key, val);
            return(oldVal);
        }
示例#11
0
文件: PStateImpl.cs 项目: sizzles/P
        public void Announce(PrtEventValue ev, PrtValue payload, PrtMachine parent)
        {
            if (ev.Equals(PrtValue.@null))
            {
                throw new PrtIllegalEnqueueException("Enqueued event must not be null");
            }

            PrtType prtType = ev.evt.payloadType;

            //assertion to check if argument passed inhabits the payload type.
            if (prtType is PrtNullType)
            {
                if (!payload.Equals(PrtValue.@null))
                {
                    throw new PrtIllegalEnqueueException("Did not expect a payload value");
                }
            }
            else if (!PrtValue.PrtInhabitsType(payload, prtType))
            {
                throw new PrtInhabitsTypeException(String.Format("Payload <{0}> does not match the expected type <{1}> with event <{2}>", payload.ToString(), prtType.ToString(), ev.evt.name));
            }

            var allSpecMachines = GetSpecMachines(parent.renamedName);

            foreach (var mon in allSpecMachines)
            {
                if (mon.observes.Contains(ev))
                {
                    TraceLine("<AnnounceLog> Enqueued Event <{0}, {1}> to Spec Machine {2}", ev, payload, mon.Name);
                    mon.PrtEnqueueEvent(ev, payload, parent);
                }
            }
        }
示例#12
0
        public override bool IsEqual(PrtValue val)
        {
            Debug.Assert(val is PrtMapValue, "Error in type checking, invalid equals invocation");
            var mapVal = val as PrtMapValue;

            if (mapVal.keys.Count != this.keys.Count)
            {
                return(false);
            }
            else
            {
                foreach (var k in this.keys)
                {
                    if (!mapVal.Contains(k))
                    {
                        return(false);
                    }
                    else
                    {
                        var index  = this.keys.FindIndex(_k => _k.IsEqual(k));
                        var _index = mapVal.keys.FindIndex(_k => _k.IsEqual(k));
                        if (this.values[index].IsEqual(mapVal.values[_index]))
                        {
                            return(false);
                        }
                    }
                }

                return(true);
            }
        }
示例#13
0
 public void Announce(PrtValue ev, PrtValue payload, PrtMachine parent)
 {
     foreach (var spec in specObservers[ev])
     {
         spec.PrtEnqueueEvent(ev, payload, parent);
     }
 }
示例#14
0
 public PrtValue Lookup(PrtValue key)
 {
     if (!Contains(key))
     {
         throw new PrtAssertFailureException("Illegal key in Lookup");
     }
     return(keyToValueMap.Where(x => x.Key.key.Equals(key)).Select(y => y.Value).First());
 }
示例#15
0
文件: PrtValue.cs 项目: up1/P
 public PrtValue Lookup(PrtValue key)
 {
     if (!Contains(key))
     {
         throw new PrtAssertFailureException("Illegal key in Lookup");
     }
     return(keyToValueMap[new PrtMapKey(key, 0)]);
 }
示例#16
0
        public PrtValue UpdateAndReturnOldValue(PrtValue key, PrtValue val)
        {
            var prtKey = new PrtMapKey(key, 0);
            var oldVal = keyToValueMap[prtKey];

            keyToValueMap[prtKey] = val;
            return(oldVal);
        }
示例#17
0
 public void Remove(PrtValue key)
 {
     if (!Contains(key))
     {
         throw new PrtAssertFailureException("Illegal key in Remove");
     }
     keyToValueMap.Remove(new PrtMapKey(key, 0));
 }
示例#18
0
 public void Insert(Int64 index, PrtValue val)
 {
     if (index < 0 || index > elements.Count)
     {
         throw new PrtAssertFailureException("Illegal index for Insert");
     }
     elements.Insert((int)index, val);
 }
示例#19
0
 public PrtValue Lookup(PrtValue key)
 {
     if (!Contains(key))
     {
         throw new PrtAssertFailureException(string.Format("Illegal key ({0}) in Lookup", key.ToString()));
     }
     return(keyToValueMap[new PrtMapKey(key, 0)]);
 }
示例#20
0
 public static PrtValue PrtCastValue(PrtValue value, PrtType type)
 {
     if (!PrtInhabitsType(value, type))
     {
         throw new PrtInhabitsTypeException(String.Format("value {0} is not a member of type {1}", value.ToString(), type.ToString()));
     }
     return(value.Clone());
 }
示例#21
0
        public override void PrtEnqueueEvent(PrtValue e, PrtValue arg, PrtMachine source)
        {
            if (e is PrtNullValue)
            {
                throw new PrtIllegalEnqueueException("Enqueued event must be non-null");
            }
            PrtType       prtType;
            PrtEventValue ev = e as PrtEventValue;


            //assertion to check if argument passed inhabits the payload type.
            prtType = ev.evt.payloadType;

            if (!(prtType is PrtNullType) && !PrtValue.PrtInhabitsType(arg, prtType))
            {
                throw new PrtInhabitsTypeException(String.Format("Payload <{0}> does not match the expected type <{1}> with event <{2}>", arg.GetString(), prtType.GetString(), ev.evt.name));
            }
            else if (prtType is PrtNullType && !(arg is PrtNullValue))
            {
                throw new PrtIllegalEnqueueException("Did not expect a payload value");
            }

            if (currentStatus == PrtMachineStatus.Halted)
            {
                stateImpl.Trace(
                    @"<EnqueueLog> {0}-{1} Machine has been halted and Event {2} is dropped",
                    this.Name, this.instanceNumber, ev.evt.name);
            }
            else
            {
                stateImpl.Trace(
                    @"<EnqueueLog> Enqueued Event <{0}, {1}> in {2}-{3} by {4}-{5}",
                    ev.evt.name, arg.GetString(), this.Name, this.instanceNumber, source.Name, source.instanceNumber);

                this.eventQueue.EnqueueEvent(e, arg);
                if (this.maxBufferSize != -1 && this.eventQueue.Size() > this.maxBufferSize)
                {
                    if (this.doAssume)
                    {
                        throw new PrtAssumeFailureException();
                    }
                    else
                    {
                        throw new PrtMaxBufferSizeExceededException(
                                  String.Format(@"<EXCEPTION> Event Buffer Size Exceeded {0} in Machine {1}-{2}",
                                                this.maxBufferSize, this.Name, this.instanceNumber));
                    }
                }
                if (currentStatus == PrtMachineStatus.Blocked && this.eventQueue.IsEnabled(this))
                {
                    currentStatus = PrtMachineStatus.Enabled;
                }
            }

            //Announce it to all the monitors
            stateImpl.Announce(e, arg, source);
        }
示例#22
0
 public PrtContinuation()
 {
     reason         = PrtContinuationReason.Return;
     createdMachine = null;
     retVal         = null;
     nondet         = false;
     retLocals      = new List <PrtValue>();
     receiveIndex   = -1;
 }
示例#23
0
文件: PrtValue.cs 项目: up1/P
        public override bool Equals(PrtValue val)
        {
            var intVal = val as PrtIntValue;

            if (intVal == null)
            {
                return(false);
            }
            return(this.nt == intVal.nt);
        }
示例#24
0
文件: PrtValue.cs 项目: up1/P
        public override bool Equals(PrtValue val)
        {
            var eventVal = val as PrtEventValue;

            if (eventVal == null)
            {
                return(false);
            }
            return(this.evt.name == eventVal.evt.name);
        }
示例#25
0
文件: PrtValue.cs 项目: up1/P
        public override bool Equals(PrtValue val)
        {
            var machineVal = val as PrtMachineValue;

            if (machineVal == null)
            {
                return(false);
            }
            return(this.mach == machineVal.mach);
        }
示例#26
0
        public void Remove(PrtValue index)
        {
            var intIndex = (index as PrtIntValue).nt;

            if (intIndex < 0 || intIndex >= elements.Count)
            {
                throw new PrtAssertFailureException("Illegal index for Remove");
            }
            elements.RemoveAt(intIndex);
        }
示例#27
0
文件: PrtValue.cs 项目: up1/P
        public override bool Equals(PrtValue val)
        {
            var boolVal = val as PrtBoolValue;

            if (boolVal == null)
            {
                return(false);
            }
            return(this.bl == boolVal.bl);
        }
示例#28
0
        public void Update(PrtValue key, PrtValue val)
        {
            if (!Contains(key))
            {
                //TODO: raise an exception for invalid update
            }
            var index = keys.FindIndex((k => k.Equals(key)));

            values[index] = val.Clone();
        }
示例#29
0
文件: PrtImplMachine.cs 项目: up1/P
 public bool PrtIsPushTransitionPresent(PrtValue ev)
 {
     if (CurrentState.transitions.ContainsKey(ev))
     {
         return(CurrentState.transitions[ev].isPushTran);
     }
     else
     {
         return(false);
     }
 }
示例#30
0
        public void Remove(PrtValue key)
        {
            if (!Contains(key))
            {
                //TODO: raise an exception for invalid remove
            }
            var index = keys.FindIndex((k => k.Equals(key)));

            keys.RemoveAt(index);
            values.RemoveAt(index);
        }