예제 #1
0
파일: Misc.cs 프로젝트: dewiniaid/KOS
 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");
     }
 }
예제 #2
0
    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;
        }
    }
예제 #3
0
        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");
            }
        }
예제 #4
0
 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;
     }
 }
예제 #5
0
 public RstSequence(LineCol location) : base(location)
 {
     // Used by serializer
 }
예제 #6
0
파일: RstText.cs 프로젝트: thygrrr/rant3
 public RstText(LineCol location, string text) : base(location)
 {
     Text = text ?? string.Empty;
 }
예제 #7
0
 public RstQuery(LineCol location) : base(location)
 {
     // Used by serializer
 }
예제 #8
0
        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];
                }
            }
        }
예제 #9
0
        public KOSCompileException(LineCol location, string message)
        {
            Location = location;

            this.message = message;
        }
예제 #10
0
 public RstFunction(LineCol location) : base(location)
 {
     // Used by serializer
 }
예제 #11
0
 public KOSReturnInvalidHereException(LineCol location) :
     base(location, "RETURN", "outside a FUNCTION", "in a FUNCTION body")
 {
 }
예제 #12
0
 public RstSubroutineBase(string name, LineCol location)
     : base(location)
 {
     Name = name;
 }
예제 #13
0
 /// <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))
 {
 }
예제 #14
0
파일: RST.cs 프로젝트: thygrrr/rant3
 public RST(LineCol location)
 {
     Location = location;
 }
예제 #15
0
 public KOSOnceInvalidHereException(LineCol location) :
     base(location, "ONCE", "from the terminal interpreter", "inside a program")
 {
 }
예제 #16
0
파일: RstEscape.cs 프로젝트: thygrrr/rant3
 public RstEscape(LineCol location) : base(location)
 {
     // Used by serializer
 }
예제 #17
0
 public KOSPreserveInvalidHereException(LineCol location) :
     base(location, "PRESERVE", "not in a trigger body", "in triggers")
 {
 }
예제 #18
0
 public RstReplacer(LineCol location, Regex regex, RST rstSource, RST rstMatchEval) : base(location)
 {
     _regex        = regex;
     _rstSource    = rstSource;
     _rstMatchEval = rstMatchEval;
 }
예제 #19
0
 public RstBlock(LineCol location) : base(location)
 {
     // Used by serializer
 }
예제 #20
0
 public RstReplacer(LineCol location) : base(location)
 {
     // Used by serializer
 }
예제 #21
0
 public RstQuery(Query query, LineCol location)
     : base(location)
 {
     _query = query;
 }
예제 #22
0
 public KOSBreakInvalidHereException(LineCol location) :
     base(location, "BREAK", "outside a loop", "in a loop body")
 {
 }
예제 #23
0
 public RstDefineSubroutine(LineCol location) : base(location)
 {
     // Used by serializer
 }
예제 #24
0
파일: RstText.cs 프로젝트: thygrrr/rant3
 public RstText(string value, LineCol location) : base(location)
 {
     Text = value ?? string.Empty;
 }