public override void Execute(SharedObjects shared) { 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) { var programContext = shared.Cpu.GetProgramContext(); var options = new CompilerOptions {LoadProgramsInSameAddressSpace = true}; List<CodePart> parts = shared.ScriptHandler.Compile(file.Content, "program", options); // add this program to the address space of the parent program int programAddress = programContext.AddObjectParts(parts); // push the entry point address of the new program onto the stack shared.Cpu.PushStack(programAddress); } }
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); } } }
public virtual List<CodePart> Compile(string scriptText, string contextId, CompilerOptions options) { return new List<CodePart>(); }
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); } }