Beispiel #1
0
        public IPrtValue TryRandom(IPrtValue param)
        {
            switch (param)
            {
            case PrtInt maxValue:
                return((PrtInt)TryRandomInt(maxValue));

            case PrtSeq seq:
            {
                TryAssert(seq.Any(), "Trying to choose from an empty sequence!");
                return(seq[TryRandomInt(seq.Count)]);
            }

            case PrtSet set:
            {
                TryAssert(set.Any(), "Trying to choose from an empty set!");
                return(set.ElementAt(TryRandomInt(set.Count)));
            }

            case PrtMap map:
            {
                TryAssert(map.Any(), "Trying to choose from an empty map!");
                return(map.Keys.ElementAt(TryRandomInt(map.Keys.Count)));
            }

            default:
                throw new PInternalException("This is an unexpected (internal) P exception. Please report to the P Developers");
            }
        }
Beispiel #2
0
 public void GotoState <T>(IPrtValue payload = null) where T : MachineState
 {
     gotoPayload = payload;
     Goto <T>();
     throw new PNonStandardReturnException {
               ReturnKind = NonStandardReturn.Goto
     };
 }
Beispiel #3
0
 public void TryGotoState <T>(IPrtValue payload = null) where T : State
 {
     gotoPayload = payload;
     base.GotoState <T>();
     throw new PNonStandardReturnException {
               ReturnKind = NonStandardReturn.Goto
     };
 }
Beispiel #4
0
        public static IPrtValue PrtCastValue(IPrtValue value, PrtType type)
        {
            //todo: Needs to be fixed for better error message

            /*if (!PrtInhabitsType(value, type))
             *  throw new PrtInhabitsTypeException(
             *      $"value {value.ToString()} is not a member of type {type.ToString()}");*/
            return(value.Clone());
        }
Beispiel #5
0
        public PMachineValue CreateInterface <T>(PMachine creator, IPrtValue payload = null)
            where T : PMachineValue
        {
            var createdInterface = PModule.linkMap[creator.interfaceName][typeof(T).Name];

            Assert(creates.Contains(createdInterface),
                   $"Machine {GetType().Name} cannot create interface {createdInterface}, not in its creates set");
            var createMachine = PModule.interfaceDefinitionMap[createdInterface];
            var machineId     = CreateMachine(createMachine, createdInterface.Substring(2),
                                              new InitializeParametersEvent(new InitializeParameters(createdInterface, payload)));

            return(new PMachineValue(machineId, PInterfaces.GetPermissions(createdInterface)));
        }
Beispiel #6
0
 protected override Event GetConstructorEvent(IPrtValue value)
 {
     return(new ConstructorEvent((PrtTuple <PMachineValue, PMachineValue>)value));
 }
Beispiel #7
0
 public static PrtBool SafeEquals(IPrtValue val1, IPrtValue val2)
 {
     return(ReferenceEquals(val1, val2) || val1 != null && val1.Equals(val2));
 }
Beispiel #8
0
 public eObjectEncountered(IPrtValue payload) : base(payload)
 {
 }
Beispiel #9
0
 protected override Event GetConstructorEvent(IPrtValue value)
 {
     return(new ConstructorEvent(value));
 }
Beispiel #10
0
 public Success(IPrtValue payload) : base(payload)
 {
 }
Beispiel #11
0
 public bool Equals(IPrtValue other)
 {
     throw new NotImplementedException();
 }
Beispiel #12
0
 public bool Equals(IPrtValue other)
 {
     return(this == other);
 }
Beispiel #13
0
 public eCloseDoor(IPrtValue payload) : base(payload)
 {
 }
Beispiel #14
0
 public e4(IPrtValue payload) : base(payload)
 {
 }
Beispiel #15
0
 public eResetDoor(IPrtValue payload) : base(payload)
 {
 }
Beispiel #16
0
 public Transition TryGotoState <T>(IPrtValue payload = null) where T : State
 {
     gotoPayload = payload;
     return(base.GotoState <T>());
 }
Beispiel #17
0
 public eDoorClosed(IPrtValue payload) : base(payload)
 {
 }
Beispiel #18
0
 public eDoorOpened(IPrtValue payload) : base(payload)
 {
 }
Beispiel #19
0
 public bool Equals(IPrtValue other)
 {
     return(other is PrtFloat f && value == f.value);
 }
Beispiel #20
0
 public PEvent(IPrtValue payload) : base()
 {
     Payload = payload;
 }
Beispiel #21
0
 public InitializeParameters(string interfaceName, IPrtValue payload)
 {
     InterfaceName = interfaceName;
     Payload       = payload;
 }
Beispiel #22
0
 public bool Equals(IPrtValue other)
 {
     return(other != null && GetType().FullName.Equals(other.GetType().FullName));
 }
Beispiel #23
0
 protected virtual Event GetConstructorEvent(IPrtValue value)
 {
     throw new NotImplementedException();
 }
Beispiel #24
0
 public PHalt(IPrtValue payload) : base(payload)
 {
 }
Beispiel #25
0
 public Pong(IPrtValue payload) : base(payload)
 {
 }
Beispiel #26
0
 public class ConstructorEvent : PEvent { public ConstructorEvent(IPrtValue val) : base(val)
                                          {
                                          }
Beispiel #27
0
 public ConstructorEvent(IPrtValue val) : base(val)
 {
 }
Beispiel #28
0
 public bool Equals(IPrtValue other)
 {
     return(other is PrtInt i && value == i.value);
 }
Beispiel #29
0
 public bool Equals(IPrtValue other)
 {
     return(other is PMachineValue machine && Equals(Id, machine.Id));
 }
Beispiel #30
0
 public eStartTimer(IPrtValue payload) : base(payload)
 {
 }