Esempio n. 1
0
File: CPU.cs Progetto: victorb/KOS
        private void PushInterpreterContext()
        {
            var interpreterContext = new ProgramContext(true);

            // initialize the context with an empty program
            interpreterContext.AddParts(new List <CodePart>());
            PushContext(interpreterContext);
        }
Esempio n. 2
0
File: CPU.cs Progetto: silky/KOS
 public void RunProgram(List <Opcode> program, bool silent)
 {
     if (program.Count > 0)
     {
         ProgramContext newContext = new ProgramContext(false, program);
         newContext.Silent = silent;
         PushContext(newContext);
     }
 }
Esempio n. 3
0
File: CPU.cs Progetto: silky/KOS
        private void PushContext(ProgramContext context)
        {
            UnityEngine.Debug.Log("kOS: Pushing context staring with: " + context.GetCodeFragment(1).FirstOrDefault());
            _contexts.Add(context);
            _currentContext = _contexts.Last();

            if (_contexts.Count > 1)
            {
                _shared.Interpreter.SetInputLock(true);
            }
        }
Esempio n. 4
0
File: CPU.cs Progetto: jenden0/KOS
        private void PushContext(ProgramContext context)
        {
            SafeHouse.Logger.Log("Pushing context staring with: " + context.GetCodeFragment(0).FirstOrDefault());
            SaveAndClearPointers();
            contexts.Add(context);
            currentContext = contexts.Last();

            if (contexts.Count > 1)
            {
                shared.Interpreter.SetInputLock(true);
            }
        }
Esempio n. 5
0
        public void RunProgram(List <Opcode> program, bool silent)
        {
            if (!program.Any())
            {
                return;
            }

            var newContext = new ProgramContext(false, program)
            {
                Silent = silent
            };

            PushContext(newContext);
        }
Esempio n. 6
0
        private bool ExecuteInstruction(ProgramContext context)
        {
            Opcode opcode = context.Program[context.InstructionPointer];

            if (!(opcode is OpcodeEOF || opcode is OpcodeEOP))
            {
                opcode.Execute(this);
                context.InstructionPointer += opcode.DeltaInstructionPointer;
                return(true);
            }
            if (opcode is OpcodeEOP)
            {
                BreakExecution(false);
                UnityEngine.Debug.LogWarning("kOS: Execution Broken");
            }
            return(false);
        }
Esempio n. 7
0
File: CPU.cs Progetto: kevin-ye/KOS
 private void PushInterpreterContext()
 {
     var interpreterContext = new ProgramContext(true);
     // initialize the context with an empty program
     interpreterContext.AddParts(new List<CodePart>());
     PushContext(interpreterContext);
 }
Esempio n. 8
0
File: CPU.cs Progetto: kevin-ye/KOS
        private void PushContext(ProgramContext context)
        {
            UnityEngine.Debug.Log("kOS: Pushing context staring with: " + context.GetCodeFragment(0).FirstOrDefault());
            SaveAndClearPointers();
            contexts.Add(context);
            currentContext = contexts.Last();

            if (contexts.Count > 1)
            {
                shared.Interpreter.SetInputLock(true);
            }
        }
Esempio n. 9
0
File: CPU.cs Progetto: kevin-ye/KOS
        private void PopContext()
        {
            UnityEngine.Debug.Log("kOS: Popping context " + contexts.Count);
            if (contexts.Any())
            {
                // remove the last context
                var contextRemove = contexts.Last();
                contexts.Remove(contextRemove);
                contextRemove.DisableActiveFlyByWire(shared.BindingMgr);
                UnityEngine.Debug.Log("kOS: Removed Context " + contextRemove.GetCodeFragment(0).FirstOrDefault());

                if (contexts.Any())
                {
                    currentContext = contexts.Last();
                    currentContext.EnableActiveFlyByWire(shared.BindingMgr);
                    RestorePointers();
                    UnityEngine.Debug.Log("kOS: New current context " + currentContext.GetCodeFragment(0).FirstOrDefault());
                }
                else
                {
                    currentContext = null;
                }

                if (contexts.Count == 1)
                {
                    shared.Interpreter.SetInputLock(false);
                }
            }
        }
Esempio n. 10
0
File: CPU.cs Progetto: kevin-ye/KOS
 private bool ExecuteInstruction(ProgramContext context)
 {
     Opcode opcode = context.Program[context.InstructionPointer];
     if (!(opcode is OpcodeEOF || opcode is OpcodeEOP))
     {
         opcode.Execute(this);
         context.InstructionPointer += opcode.DeltaInstructionPointer;
         return true;
     }
     if (opcode is OpcodeEOP)
     {
         BreakExecution(false);
         UnityEngine.Debug.LogWarning("kOS: Execution Broken");
     }
     return false;
 }
Esempio n. 11
0
File: CPU.cs Progetto: kevin-ye/KOS
        public void RunProgram(List<Opcode> program, bool silent)
        {
            if (!program.Any()) return;

            var newContext = new ProgramContext(false, program) {Silent = silent};
            PushContext(newContext);
        }
Esempio n. 12
0
File: CPU.cs Progetto: kevin-ye/KOS
        public void Boot()
        {
            // break all running programs
            currentContext = null;
            contexts.Clear();
            PushInterpreterContext();
            currentStatus = Status.Running;
            currentTime = 0;
            timeWaitUntil = 0;
            // clear stack
            stack.Clear();
            // clear variables
            vars.Clear();
            // clear interpreter
            if (shared.Interpreter != null) shared.Interpreter.Reset();
            // load functions
            LoadFunctions();
            // load bindings
            if (shared.BindingMgr != null) shared.BindingMgr.LoadBindings();
            // Booting message
            if (shared.Screen != null)
            {
                shared.Screen.ClearScreen();
                string bootMessage = "kOS Operating System\n" +
                                     "KerboScript v" + Core.VersionInfo + "\n \n" +
                                     "Proceed.\n ";
                shared.Screen.Print(bootMessage);
            }

            if (shared.VolumeMgr == null) { UnityEngine.Debug.Log("kOS: No volume mgr"); }
            else if (shared.VolumeMgr.CurrentVolume == null) { UnityEngine.Debug.Log("kOS: No current volume"); }
            else if (shared.ScriptHandler == null) { UnityEngine.Debug.Log("kOS: No script handler"); }
            else if (shared.VolumeMgr.CurrentVolume.GetByName("boot") != null)
            {
                shared.ScriptHandler.ClearContext("program");

                var programContext = shared.Cpu.GetProgramContext();
                programContext.Silent = true;
                var options = new CompilerOptions {LoadProgramsInSameAddressSpace = true};
                List<CodePart> parts = shared.ScriptHandler.Compile("run boot.", "program", options);
                programContext.AddParts(parts);
            }
        }
Esempio n. 13
0
File: CPU.cs Progetto: jenden0/KOS
        public void Boot()
        {
            // break all running programs
            currentContext = null;
            contexts.Clear();
            PushInterpreterContext();
            currentStatus = Status.Running;
            currentTime   = 0;
            timeWaitUntil = 0;
            // clear stack
            stack.Clear();
            // clear variables
            variables.Clear();
            // clear interpreter
            if (shared.Interpreter != null)
            {
                shared.Interpreter.Reset();
            }
            // load functions
            if (shared.FunctionManager != null)
            {
                shared.FunctionManager.Load();
            }
            // load bindings
            if (shared.BindingMgr != null)
            {
                shared.BindingMgr.Load();
            }
            // Booting message
            if (shared.Screen != null)
            {
                shared.Screen.ClearScreen();
                string        bootMessage = string.Format("kOS Operating System\n" + "KerboScript v{0}\n \n" + "Proceed.\n", Core.VersionInfo);
                List <string> nags        = Safe.Utilities.Debug.GetPendingNags();
                if (nags.Count > 0)
                {
                    bootMessage +=
                        "##################################################\n" +
                        "#               NAG MESSAGES                     #\n" +
                        "##################################################\n" +
                        "# Further details about these important messages #\n" +
                        "# can be found in the KSP error log.  If you see #\n" +
                        "# this, then read the error log.  It's important.#\n" +
                        "--------------------------------------------------\n";

                    bootMessage  = nags.Aggregate(bootMessage, (current, msg) => current + (msg + "\n"));
                    bootMessage += "##################################################\n";
                }
                shared.Screen.Print(bootMessage);
            }

            if (shared.VolumeMgr == null)
            {
                SafeHouse.Logger.Log("No volume mgr");
            }
            else if (!shared.VolumeMgr.CheckCurrentVolumeRange(shared.Vessel))
            {
                SafeHouse.Logger.Log("Boot volume not in range");
            }
            else if (shared.VolumeMgr.CurrentVolume == null)
            {
                SafeHouse.Logger.Log("No current volume");
            }
            else if (shared.ScriptHandler == null)
            {
                SafeHouse.Logger.Log("No script handler");
            }
            else if (shared.VolumeMgr.CurrentVolume.GetByName("boot") == null)
            {
                SafeHouse.Logger.Log("Boot File is Missing");
            }
            else
            {
                shared.ScriptHandler.ClearContext("program");

                var programContext = ((CPU)shared.Cpu).GetProgramContext();
                programContext.Silent = true;
                var options = new CompilerOptions {
                    LoadProgramsInSameAddressSpace = true
                };
                string          filePath = shared.VolumeMgr.GetVolumeRawIdentifier(shared.VolumeMgr.CurrentVolume) + "/" + "boot";
                List <CodePart> parts    = shared.ScriptHandler.Compile(filePath, 1, "run boot.", "program", options);
                programContext.AddParts(parts);
            }
        }
Esempio n. 14
0
 public void RunProgram(List<Opcode> program, bool silent)
 {
     if (program.Count > 0)
     {
         ProgramContext newContext = new ProgramContext(false, program);
         newContext.Silent = silent;
         PushContext(newContext);
     }
 }
Esempio n. 15
0
 public void Boot()
 {
     // break all running programs
     _currentContext = null;
     _contexts.Clear();
     PushInterpreterContext();
     _currentStatus = Status.Running;
     _currentTime = 0;
     _timeWaitUntil = 0;
     // clear stack
     _stack.Clear();
     // clear variables
     _vars.Clear();
     // clear interpreter
     if (_shared.Interpreter != null) _shared.Interpreter.Reset();
     // load functions
     LoadFunctions();
     // load bindings
     if (_shared.BindingMgr != null) _shared.BindingMgr.LoadBindings();
     // Booting message
     if (_shared.Screen != null)
     {
         _shared.Screen.ClearScreen();
         string bootMessage = "kOS Operating System\n" +
                              "KerboScript v" + Core.VersionInfo.ToString() + "\n \n" +
                              "Proceed.\n ";
         _shared.Screen.Print(bootMessage);
     }
 }