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"); } }
public void GotoState <T>(IPrtValue payload = null) where T : MachineState { gotoPayload = payload; Goto <T>(); throw new PNonStandardReturnException { ReturnKind = NonStandardReturn.Goto }; }
public void TryGotoState <T>(IPrtValue payload = null) where T : State { gotoPayload = payload; base.GotoState <T>(); throw new PNonStandardReturnException { ReturnKind = NonStandardReturn.Goto }; }
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()); }
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))); }
protected override Event GetConstructorEvent(IPrtValue value) { return(new ConstructorEvent((PrtTuple <PMachineValue, PMachineValue>)value)); }
public static PrtBool SafeEquals(IPrtValue val1, IPrtValue val2) { return(ReferenceEquals(val1, val2) || val1 != null && val1.Equals(val2)); }
public eObjectEncountered(IPrtValue payload) : base(payload) { }
protected override Event GetConstructorEvent(IPrtValue value) { return(new ConstructorEvent(value)); }
public Success(IPrtValue payload) : base(payload) { }
public bool Equals(IPrtValue other) { throw new NotImplementedException(); }
public bool Equals(IPrtValue other) { return(this == other); }
public eCloseDoor(IPrtValue payload) : base(payload) { }
public e4(IPrtValue payload) : base(payload) { }
public eResetDoor(IPrtValue payload) : base(payload) { }
public Transition TryGotoState <T>(IPrtValue payload = null) where T : State { gotoPayload = payload; return(base.GotoState <T>()); }
public eDoorClosed(IPrtValue payload) : base(payload) { }
public eDoorOpened(IPrtValue payload) : base(payload) { }
public bool Equals(IPrtValue other) { return(other is PrtFloat f && value == f.value); }
public PEvent(IPrtValue payload) : base() { Payload = payload; }
public InitializeParameters(string interfaceName, IPrtValue payload) { InterfaceName = interfaceName; Payload = payload; }
public bool Equals(IPrtValue other) { return(other != null && GetType().FullName.Equals(other.GetType().FullName)); }
protected virtual Event GetConstructorEvent(IPrtValue value) { throw new NotImplementedException(); }
public PHalt(IPrtValue payload) : base(payload) { }
public Pong(IPrtValue payload) : base(payload) { }
public class ConstructorEvent : PEvent { public ConstructorEvent(IPrtValue val) : base(val) { }
public ConstructorEvent(IPrtValue val) : base(val) { }
public bool Equals(IPrtValue other) { return(other is PrtInt i && value == i.value); }
public bool Equals(IPrtValue other) { return(other is PMachineValue machine && Equals(Id, machine.Id)); }
public eStartTimer(IPrtValue payload) : base(payload) { }