Esempio n. 1
0
 public ProgramContext(bool interpreterContext)
 {
     Program = new List<Opcode>();
     InstructionPointer = 0;
     Triggers = new List<int>();
     builder = interpreterContext ? new ProgramBuilderInterpreter() : new ProgramBuilder();
     _flyByWire = new Dictionary<string, bool>();
 }
Esempio n. 2
0
File: Misc.cs Progetto: WazWaz/KOS
        public override void Execute(SharedObjects shared)
        {
            object volumeId = shared.Cpu.PopValue();
            string fileName = shared.Cpu.PopValue().ToString();

            if (shared.VolumeMgr == null) return;
            if (shared.VolumeMgr.CurrentVolume == null) throw new Exception("Volume not found");

            ProgramFile file = shared.VolumeMgr.CurrentVolume.GetByName(fileName);
            if (file == null) throw new Exception(string.Format("File '{0}' not found", fileName));

            if (shared.ScriptHandler != null)
            {
                if (volumeId != null)
                {
                    Volume targetVolume = shared.VolumeMgr.GetVolume(volumeId);
                    if (targetVolume != null)
                    {
                        if (shared.ProcessorMgr != null)
                        {
                            List<CodePart> parts = shared.ScriptHandler.Compile(file.Content);
                            ProgramBuilder builder = new ProgramBuilder();
                            builder.AddRange(parts);
                            List<Opcode> program = builder.BuildProgram();
                            shared.ProcessorMgr.RunProgramOn(program, targetVolume);
                        }
                    }
                    else
                    {
                        throw new Exception("Volume not found");
                    }
                }
                else
                {
                    // clear the "program" compilation context
                    shared.ScriptHandler.ClearContext("program");

                    var programContext = shared.Cpu.GetProgramContext();
                    CompilerOptions options = new CompilerOptions();
                    options.LoadProgramsInSameAddressSpace = true;
                    List<CodePart> parts = shared.ScriptHandler.Compile(file.Content, "program", options);
                    programContext.AddParts(parts);
                }
            }
        }
Esempio n. 3
0
File: CPU.cs Progetto: kevin-ye/KOS
        public void OnLoad(ConfigNode node)
        {
            try
            {
                var scriptBuilder = new StringBuilder();

                foreach (ConfigNode contextNode in node.GetNodes("context"))
                {
                    foreach (ConfigNode varNode in contextNode.GetNodes("variables"))
                    {
                        foreach (ConfigNode.Value value in varNode.values)
                        {
                            string varValue = Persistence.ProgramFile.DecodeLine(value.value);
                            scriptBuilder.AppendLine(string.Format("set {0} to {1}.", value.name, varValue));
                        }
                    }
                }

                if (shared.ScriptHandler != null && scriptBuilder.Length > 0)
                {
                    var programBuilder = new ProgramBuilder();
                    programBuilder.AddRange(shared.ScriptHandler.Compile(scriptBuilder.ToString()));
                    List<Opcode> program = programBuilder.BuildProgram();
                    RunProgram(program, true);
                }
            }
            catch (Exception e)
            {
                if (shared.Logger != null) shared.Logger.Log(e);
            }
        }