public override void Execute(SharedObjects shared) { AssertArgBottomAndConsume(shared); if (StageManager.CanSeparate && shared.Vessel.isActiveVessel) { StageManager.ActivateNextStage(); } else if (!StageManager.CanSeparate) { SafeHouse.Logger.Log("FAIL SILENT: Stage is called before it is ready, Use STAGE:READY to check first if staging rapidly"); } else if (!shared.Vessel.isActiveVessel) { throw new KOSCommandInvalidHereException(LineCol.Unknown(), "STAGE", "a non-active SHIP, KSP does not support this", "Core is on the active vessel"); } }
public void PruneWhiteSpace(ReadOnlySpan <byte> content) { var pos = new LineCol(0, 0); foreach (var info in Infos) { var wasWhiteSpace = true; while (pos < info.Start && !content.IsEmpty) { AdvanceRune(ref content, ref pos, out wasWhiteSpace); } if (content.IsEmpty) { return; } if (pos != info.Start) { continue; } var firstNonWhiteSpace = pos; while (pos < info.End && !content.IsEmpty && wasWhiteSpace) { firstNonWhiteSpace = pos; AdvanceRune(ref content, ref pos, out wasWhiteSpace); } if (pos >= info.End) { continue; } info.Start = firstNonWhiteSpace; var lastNonWhiteSpace = pos; while (pos < info.End && !content.IsEmpty) { AdvanceRune(ref content, ref pos, out wasWhiteSpace); if (!wasWhiteSpace) { lastNonWhiteSpace = pos; } } info.End = lastNonWhiteSpace; } }
private void ControlFrom() { ThrowIfNotCPUVessel(); var dockingModule = Part.Modules.OfType <ModuleDockingNode>().FirstOrDefault(); var commandModule = Part.Modules.OfType <ModuleCommand>().FirstOrDefault(); if (commandModule != null) { commandModule.MakeReference(); } else if (dockingModule != null) { dockingModule.MakeReferenceTransform(); } else { throw new KOSCommandInvalidHereException(LineCol.Unknown(), "CONTROLFROM", "a generic part value", "a docking port or command part"); } }
public RstBlock(LineCol location, List <RST> items, List <_ <int, RST> > dynamicWeights, List <_ <int, double> > constantWeights) : base(location) { _elements.AddRange(items); _count = items.Count; if (dynamicWeights != null && constantWeights != null) { _dynamicWeights = dynamicWeights; _weights = new double[_count]; for (int i = 0; i < _count; i++) { _weights[i] = 1; } foreach (var cw in constantWeights) { _weights[cw.Item1] = cw.Item2; } _constantWeightSum = _weights.Sum() - _dynamicWeights.Count; _weighted = true; } }
public RstSequence(LineCol location) : base(location) { // Used by serializer }
public RstText(LineCol location, string text) : base(location) { Text = text ?? string.Empty; }
public RstQuery(LineCol location) : base(location) { // Used by serializer }
private void ReplaceLabels(List <Opcode> program) { var labels = new Dictionary <string, int>(); // get the index of every label for (int index = 0; index < program.Count; index++) { if (program[index].Label != string.Empty) { if (labels.ContainsKey(program[index].Label)) { if (program[index].Label.EndsWith("-default")) { continue; } // This is one of those "should never happen" errors that if it happens // it means kOS devs screwed up - so dump the partially relabeled program // to the log just to help in diagnosing the bug report that may happen: // Utilities.SafeHouse.Logger.LogError("=====Relabeled Program so far is: ========="); Utilities.SafeHouse.Logger.LogError(Utilities.Debug.GetCodeFragment(program)); throw new Exceptions.KOSCompileException(LineCol.Unknown(), string.Format( "ProgramBuilder.ReplaceLabels: Cannot add label {0}, label already exists. Opcode: {1}", program[index].Label, program[index].ToString())); } labels.Add(program[index].Label, index); } } // replace destination labels with the corresponding index for (int index = 0; index < program.Count; index++) { Opcode opcode = program[index]; if (string.IsNullOrEmpty(opcode.DestinationLabel)) { continue; } if (!labels.ContainsKey(opcode.DestinationLabel)) { Utilities.SafeHouse.Logger.LogError("=====Relabeled Program so far is: ========="); Utilities.SafeHouse.Logger.LogError(Utilities.Debug.GetCodeFragment(program)); throw new Exceptions.KOSCompileException(LineCol.Unknown(), string.Format( "ProgramBuilder.ReplaceLabels: Cannot find label {0}. Opcode: {1}", opcode.DestinationLabel, opcode.ToString())); } int destinationIndex = labels[opcode.DestinationLabel]; if (opcode is BranchOpcode) { ((BranchOpcode)opcode).Distance = destinationIndex - index; } else if (opcode is OpcodePushRelocateLater) { // Replace the OpcodePushRelocateLater with the proper OpcodePush: Opcode newOp; if (opcode is OpcodePushDelegateRelocateLater) { newOp = new OpcodePushDelegate(destinationIndex, ((OpcodePushDelegateRelocateLater)opcode).WithClosure); } else { newOp = new OpcodePush(destinationIndex); } newOp.SourcePath = opcode.SourcePath; newOp.SourceLine = opcode.SourceLine; newOp.SourceColumn = opcode.SourceColumn; newOp.Label = opcode.Label; program[index] = newOp; } else if (opcode is OpcodeCall) { ((OpcodeCall)opcode).Destination = destinationIndex; } } // complete the entry point address of all the objects foreach (var objectFile in objectFiles.Values) { if (objectFile.EntryPointLabel != string.Empty) { objectFile.EntryPointAddress = labels[objectFile.EntryPointLabel]; } } }
public KOSCompileException(LineCol location, string message) { Location = location; this.message = message; }
public RstFunction(LineCol location) : base(location) { // Used by serializer }
public KOSReturnInvalidHereException(LineCol location) : base(location, "RETURN", "outside a FUNCTION", "in a FUNCTION body") { }
public RstSubroutineBase(string name, LineCol location) : base(location) { Name = name; }
/// <summary> /// Describe the condition under which the invalidity is happening. /// </summary> /// <param name="location">current line and column position of the problem</param> /// <param name="command">string name of the invalid command</param> /// <param name="badPlace">describing where in code the it's not being allowed. /// Use a phrasing that starts with a preposition, i.e. "in a loop", "outside a loop"</param> /// <param name="goodPlace">describing what sort of code the it is meant to be used in instead. /// Use a phrasing that starts with a preposition, i.e. "in a loop", "outside a loop"</param> public KOSCommandInvalidHereException(LineCol location, string command, string badPlace, string goodPlace) : base(location, string.Format(TERSE_MSG_FMT, command, badPlace, goodPlace)) { }
public RST(LineCol location) { Location = location; }
public KOSOnceInvalidHereException(LineCol location) : base(location, "ONCE", "from the terminal interpreter", "inside a program") { }
public RstEscape(LineCol location) : base(location) { // Used by serializer }
public KOSPreserveInvalidHereException(LineCol location) : base(location, "PRESERVE", "not in a trigger body", "in triggers") { }
public RstReplacer(LineCol location, Regex regex, RST rstSource, RST rstMatchEval) : base(location) { _regex = regex; _rstSource = rstSource; _rstMatchEval = rstMatchEval; }
public RstBlock(LineCol location) : base(location) { // Used by serializer }
public RstReplacer(LineCol location) : base(location) { // Used by serializer }
public RstQuery(Query query, LineCol location) : base(location) { _query = query; }
public KOSBreakInvalidHereException(LineCol location) : base(location, "BREAK", "outside a loop", "in a loop body") { }
public RstDefineSubroutine(LineCol location) : base(location) { // Used by serializer }
public RstText(string value, LineCol location) : base(location) { Text = value ?? string.Empty; }