// Use this for initialization void Start() { programBlock = GetComponent <ProgramBlock> (); programBlock.SetProgramBlockName("If"); trueFalseBlock = ProgramFile.AddProgramBlock <ProgramTrueFalseBlock> (gameObject).GetComponent <ProgramTrueFalseBlock> (); assignVariableBlock = ProgramFile.AddProgramBlock <ProgramAssignVariableBlock> (gameObject).GetComponent <ProgramAssignVariableBlock> (); }
public void TestFileProcessor_ProcessFile_1() { string inputFileText = "public virtual (int x, int y) Move(int direction, int seconds)" + "\r\n{" + "\r\n\tif (direction == 0) // move north" + "\r\n\t\tLocationY += seconds * Speed;" + "\r\n\telse if (direction == 1) // move east" + "\r\n\t\tLocationX += seconds * Speed;" + "\r\n\telse if (direction == 2) // move south" + "\r\n\t\tLocationY -= seconds * Speed;" + "\r\n\telse if (direction == 3) // move west" + "\r\n\t\tLocationX -= seconds * Speed;" + "\r\n\treturn (LocationX, LocationY);" + "\r\n}"; string[] expectedFileTextDataArray = { "public", "virtual", "(", "int", "x", ",", "int", "y", ")", "Move", "(", "int", "direction", ",", "int", "seconds", ")", " ", "{", " ", "if", "(", "direction", "==", "0", ")", "//", "move", "north", " ", "LocationY", "+=", "seconds", "*", "Speed", ";", " ", "else", "if", "(", "direction", "==", "1", ")", "//", "move", "east", " ", "LocationX", "+=", "seconds", "*", "Speed", ";", " ", "else","if", "(", "direction", "==", "2", ")", "//", "move", "south", " ", "LocationY", "-=", "seconds", "*", "Speed", ";", " ", "else", "if", "(", "direction", "==", "3", ")", "//", "move", "west", " ", "LocationX", "-=", "seconds", "*", "Speed", ";", " ", "return", "(", "LocationX", ",", "LocationY", ")", ";", " ", "}", " " }; List <string> expectedFileTextData = new List <string>(); List <string> actualFileTextData; ProgramFile testProgramFile = new ProgramFile("C:\\filepath1", "TestFileName1.cs", inputFileText); expectedFileTextData.AddRange(expectedFileTextDataArray); FileProcessor fileProcessor = new FileProcessor(testProgramFile); fileProcessor.ProcessFile(); actualFileTextData = testProgramFile.FileTextData; CollectionAssert.AreEqual(expectedFileTextData, actualFileTextData); }
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(); CompilerOptions options = new CompilerOptions(); options.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 static ProgramFile ToProgramFile(this ConfigNode configNode) { var filename = configNode.GetValue(FILENAME_VALUE_STRING); var toReturn = new ProgramFile(filename); Decode(toReturn, configNode.GetValue("line")); return toReturn; }
// Use this for initialization void Start() { programBlock = GetComponent <ProgramBlock> (); programBlock.SetProgramBlockName("Assign Variable"); programVariableReference = ProgramFile.AddProgramBlock <ProgramVariableReference> (gameObject).GetComponent <ProgramVariableReference>(); programNumber = ProgramFile.AddProgramBlock <ProgramNumber> (gameObject).GetComponent <ProgramNumber>(); }
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) { return; } if (volumeId != null) { Volume targetVolume = shared.VolumeMgr.GetVolume(volumeId); if (targetVolume != null) { if (shared.ProcessorMgr != null) { string filePath = string.Format("{0}/{1}", shared.VolumeMgr.GetVolumeRawIdentifier(targetVolume), fileName); List <CodePart> parts = shared.ScriptHandler.Compile(filePath, 1, file.Content); var 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"); string filePath = shared.VolumeMgr.GetVolumeRawIdentifier(shared.VolumeMgr.CurrentVolume) + "/" + fileName; var options = new CompilerOptions { LoadProgramsInSameAddressSpace = true }; List <CodePart> parts = shared.ScriptHandler.Compile(filePath, 1, file.Content, "program", options); var programContext = shared.Cpu.GetProgramContext(); programContext.AddParts(parts); } }
public void InitObjects() { Debug.LogWarning("kOS: InitObjects: " + (shared == null)); shared = new SharedObjects(); CreateFactory(); shared.Vessel = vessel; shared.Processor = this; shared.UpdateHandler = new UpdateHandler(); shared.BindingMgr = new BindingManager(shared); shared.Interpreter = shared.Factory.CreateInterpreter(shared); shared.Screen = shared.Interpreter; shared.ScriptHandler = new Compilation.KS.KSScript(); shared.Logger = new KSPLogger(shared); shared.VolumeMgr = new VolumeManager(shared); shared.ProcessorMgr = new ProcessorManager(); shared.Cpu = new Execution.CPU(shared); // Make the window that is going to correspond to this kOS part: var gObj = new GameObject("kOSTermWindow", typeof(kOS.Screen.TermWindow)); DontDestroyOnLoad(gObj); shared.Window = (kOS.Screen.TermWindow)gObj.GetComponent(typeof(kOS.Screen.TermWindow)); shared.Window.AttachTo(shared); // initialize archive var archive = shared.Factory.CreateArchive(); shared.VolumeMgr.Add(archive); // initialize harddisk if (HardDisk == null && archive.CheckRange(vessel)) { HardDisk = new Harddisk(Mathf.Min(diskSpace, PROCESSOR_HARD_CAP)); var bootProgramFile = archive.GetByName(bootFile); if (bootProgramFile != null) { // Copy to HardDisk as "boot". var boot = new ProgramFile(bootProgramFile) { Filename = "boot" }; HardDisk.Add(boot); } } shared.VolumeMgr.Add(HardDisk); // process setting if (!Config.Instance.StartOnArchive) { shared.VolumeMgr.SwitchTo(HardDisk); } shared.Cpu.Boot(); }
/// <summary> /// Gets the absolute path to the specified program. /// </summary> /// <param name="program">The program whose absolute path is being retrieved.</param> /// <returns>The absolute path of the program.</returns> /// <remarks>This method is not symmetric with SetProgramPath -- it returns the absolute path to the requested program in full.</remarks> public string GetProgramPath(ProgramFile program) { string programPath; if (_programPaths.TryGetValue(program, out programPath)) { programPath = System.IO.Path.Combine(programPath, program.ProgramName()) + ProgramSuffix; IRomHelpers.SetConfigurationEntry(program.ToString(), programPath); // ensure it's registered w/ INTV.Core } return(programPath); }
public void Execute(ProgramFile program) { if (UsesRegister) { Console.WriteLine(Register.Value); } else { Console.WriteLine(program.Strings[StringKey]); } }
public void Execute(ProgramFile program) { switch (Condition) { case JumpCondition.LessThan: if (RegisterOne.Value < RegisterTwo.Value) { program.Jump(Label); } break; case JumpCondition.LessThanOrEqual: if (RegisterOne.Value <= RegisterTwo.Value) { program.Jump(Label); } break; case JumpCondition.Equal: if (RegisterOne.Value == RegisterTwo.Value) { program.Jump(Label); } break; case JumpCondition.GreaterThanOrEqual: if (RegisterOne.Value >= RegisterTwo.Value) { program.Jump(Label); } break; case JumpCondition.GreaterThan: if (RegisterOne.Value > RegisterTwo.Value) { program.Jump(Label); } break; case JumpCondition.NotEqual: if (RegisterOne.Value != RegisterTwo.Value) { program.Jump(Label); } break; } }
public void TestFunctionSignature_F() { ProgramFile programFile = new ProgramFile("path", "name", "text"); ProgramClassTypeCollection expectedClassTypeCollection = new ProgramClassTypeCollection(); ProgramClassTypeCollection actualClassTypeCollection = new ProgramClassTypeCollection(); CodeProcessor codeProcessor = new CodeProcessor(programFile, actualClassTypeCollection); ProgramClass expectedProgramClass; ProgramClass actualProgramClass; ProgramFunction expectedProgramFunction; ProgramFunction actualProgramFunction; string[] fileTextDataArray = { "class", "ClassName", " ", "{", " ", "public", "virtual", "(", "List", "<", "int", ">", ",", "bool", ",", "float",")", "Test", "<", "Object", ">", "(", "double", "n", ",", "double", "m", ")", " ", "{", " ", "return", "(", "0", ",", "0",")", ";", " ", "}", " ", "}" }; programFile.FileTextData.AddRange(fileTextDataArray); string name = "Test"; List <string> empty = new List <string>(); List <string> ModF = new List <string>(); List <string> RetF = new List <string>(); List <string> GenF = new List <string>(); List <string> ParF = new List <string>(); ModF.Add("public"); ModF.Add("virtual"); RetF.Add("List"); RetF.Add("<"); RetF.Add("int"); RetF.Add(">"); RetF.Add(","); RetF.Add("bool"); RetF.Add(","); RetF.Add("float"); GenF.Add("Object"); ParF.Add("double"); ParF.Add("n"); ParF.Add(","); ParF.Add("double"); ParF.Add("m"); expectedProgramClass = new ProgramClass("ClassName", empty, empty); expectedProgramFunction = new ProgramFunction(name, ModF, RetF, GenF, ParF, empty); expectedProgramClass.ChildList.Add(expectedProgramFunction); expectedClassTypeCollection.Add(expectedProgramClass); codeProcessor.ProcessFileCode(); CollectionAssert.AreEqual(expectedClassTypeCollection, actualClassTypeCollection); actualProgramClass = (ProgramClass)actualClassTypeCollection[0]; Assert.AreEqual(expectedProgramClass.ChildList.Count, actualProgramClass.ChildList.Count); actualProgramFunction = (ProgramFunction)actualProgramClass.ChildList[0]; Assert.AreEqual(expectedProgramFunction.Name, actualProgramFunction.Name); CollectionAssert.AreEqual(expectedProgramFunction.Modifiers, actualProgramFunction.Modifiers); CollectionAssert.AreEqual(expectedProgramFunction.ReturnTypes, actualProgramFunction.ReturnTypes); CollectionAssert.AreEqual(expectedProgramFunction.Generics, actualProgramFunction.Generics); CollectionAssert.AreEqual(expectedProgramFunction.Parameters, actualProgramFunction.Parameters); }
public override void Execute(SharedObjects shared) { object volumeId = PopValueAssert(shared, true); string direction = PopValueAssert(shared).ToString(); string fileName = PopValueAssert(shared, true).ToString(); AssertArgBottomAndConsume(shared); SafeHouse.Logger.Log(string.Format("FunctionCopy: Volume: {0} Direction: {1} Filename: {2}", volumeId, direction, fileName)); if (shared.VolumeMgr != null) { Volume origin; Volume destination; if (direction == "from") { origin = volumeId is Volume ? volumeId as Volume : shared.VolumeMgr.GetVolume(volumeId); destination = shared.VolumeMgr.CurrentVolume; } else { origin = shared.VolumeMgr.CurrentVolume; destination = volumeId is Volume ? volumeId as Volume : shared.VolumeMgr.GetVolume(volumeId); } if (origin != null && destination != null) { if (origin == destination) { throw new Exception("Cannot copy from a volume to the same volume."); } ProgramFile file = origin.GetByName(fileName); if (file != null) { if (!destination.SaveFile(new ProgramFile(file))) { throw new Exception("File copy failed"); } } else { throw new Exception(string.Format("File '{0}' not found", fileName)); } } else { throw new Exception(string.Format("Volume {0} not found", volumeId)); } } }
public GameObject AddProgramFile(ProgramFile programFile) { GameObject newProgramFileGraphic = GameObject.Instantiate(programFileGraphicPrefab); ProgramGUIProgramFileGraphic newGraphic = newProgramFileGraphic.GetComponent <ProgramGUIProgramFileGraphic> (); programFileGraphics.Add(newGraphic); newProgramFileGraphic.GetComponent <RectTransform> ().parent = programFileParent; newProgramFileGraphic.GetComponent <RectTransform> ().anchoredPosition = new Vector2( 0, 150 + (-100 * (programFileGraphics.Count - 1))); return(newProgramFileGraphic); }
public override void Execute(SharedObjects shared) { object volumeId = shared.Cpu.PopValue(); string direction = shared.Cpu.PopValue().ToString(); string fileName = shared.Cpu.PopValue().ToString(); if (shared.VolumeMgr != null) { Volume origin; Volume destination; if (direction == "from") { origin = shared.VolumeMgr.GetVolume(volumeId); destination = shared.VolumeMgr.CurrentVolume; } else { origin = shared.VolumeMgr.CurrentVolume; destination = shared.VolumeMgr.GetVolume(volumeId); } if (origin != null && destination != null) { if (origin == destination) { throw new Exception("Cannot copy from a volume to the same volume."); } else { ProgramFile file = origin.GetByName(fileName); if (file != null) { if (!destination.SaveFile(new ProgramFile(file))) { throw new Exception("File copy failed"); } } else { throw new Exception(string.Format("File '{0}' not found", fileName)); } } } else { throw new Exception(string.Format("Volume {0} not found", volumeId)); } } }
public void TestFunctionSignature_B() { ProgramFile programFile = new ProgramFile("path", "name", "text"); ProgramClassTypeCollection expectedClassTypeCollection = new ProgramClassTypeCollection(); ProgramClassTypeCollection actualClassTypeCollection = new ProgramClassTypeCollection(); CodeProcessor codeProcessor = new CodeProcessor(programFile, actualClassTypeCollection); ProgramClass expectedProgramClass; ProgramClass actualProgramClass; ProgramFunction expectedProgramFunction; ProgramFunction actualProgramFunction; string[] fileTextDataArray = { "class", "ClassName", " ", "{", " ", "void", "Test", "<", "V", ",", "W", ">", "(", "int", "x", ")", " ", "{"," ","return", "(", "0", ",", "0", ")", ";", " ", "}", " ", "}" }; programFile.FileTextData.AddRange(fileTextDataArray); string name = "Test"; List <string> empty = new List <string>(); List <string> RetB = new List <string>(); List <string> GenB = new List <string>(); List <string> ParB = new List <string>(); RetB.Add("void"); GenB.Add("V"); GenB.Add(","); GenB.Add("W"); ParB.Add("int"); ParB.Add("x"); expectedProgramClass = new ProgramClass("ClassName", empty, empty); expectedProgramFunction = new ProgramFunction(name, empty, RetB, GenB, ParB, empty); expectedProgramClass.ChildList.Add(expectedProgramFunction); expectedClassTypeCollection.Add(expectedProgramClass); codeProcessor.ProcessFileCode(); CollectionAssert.AreEqual(expectedClassTypeCollection, actualClassTypeCollection); actualProgramClass = (ProgramClass)actualClassTypeCollection[0]; Assert.AreEqual(expectedProgramClass.ChildList.Count, actualProgramClass.ChildList.Count); actualProgramFunction = (ProgramFunction)actualProgramClass.ChildList[0]; Assert.AreEqual(expectedProgramFunction.Name, actualProgramFunction.Name); CollectionAssert.AreEqual(expectedProgramFunction.Modifiers, actualProgramFunction.Modifiers); CollectionAssert.AreEqual(expectedProgramFunction.ReturnTypes, actualProgramFunction.ReturnTypes); CollectionAssert.AreEqual(expectedProgramFunction.Generics, actualProgramFunction.Generics); CollectionAssert.AreEqual(expectedProgramFunction.Parameters, actualProgramFunction.Parameters); }
public void TestFunctionSignature_O() { ProgramFile programFile = new ProgramFile("path", "name", "text"); ProgramClassTypeCollection expectedClassTypeCollection = new ProgramClassTypeCollection(); ProgramClassTypeCollection actualClassTypeCollection = new ProgramClassTypeCollection(); CodeProcessor codeProcessor = new CodeProcessor(programFile, actualClassTypeCollection); ProgramClass expectedProgramClass; ProgramClass actualProgramClass; ProgramFunction expectedProgramFunction; ProgramFunction actualProgramFunction; string[] fileTextDataArray = { "class", "ClassName", " ", "{", " ", "public", "static", "Test", ".", "NewType", "TestFunc", "(", ")", " ", "{"," ", "return", "(", "0", ",", "0", ")", ";", " ", "}", " ", "}" }; programFile.FileTextData.AddRange(fileTextDataArray); string name = "TestFunc"; List <string> empty = new List <string>(); List <string> ModO = new List <string>(); List <string> RetO = new List <string>(); ModO.Add("public"); ModO.Add("static"); RetO.Add("Test"); RetO.Add("."); RetO.Add("NewType"); expectedProgramClass = new ProgramClass("ClassName", empty, empty); expectedProgramFunction = new ProgramFunction(name, ModO, RetO, empty, empty, empty); expectedProgramClass.ChildList.Add(expectedProgramFunction); expectedClassTypeCollection.Add(expectedProgramClass); codeProcessor.ProcessFileCode(); CollectionAssert.AreEqual(expectedClassTypeCollection, actualClassTypeCollection); actualProgramClass = (ProgramClass)actualClassTypeCollection[0]; Assert.AreEqual(expectedProgramClass.ChildList.Count, actualProgramClass.ChildList.Count); actualProgramFunction = (ProgramFunction)actualProgramClass.ChildList[0]; Assert.AreEqual(expectedProgramFunction.Name, actualProgramFunction.Name); CollectionAssert.AreEqual(expectedProgramFunction.Modifiers, actualProgramFunction.Modifiers); CollectionAssert.AreEqual(expectedProgramFunction.ReturnTypes, actualProgramFunction.ReturnTypes); CollectionAssert.AreEqual(expectedProgramFunction.Generics, actualProgramFunction.Generics); CollectionAssert.AreEqual(expectedProgramFunction.Parameters, actualProgramFunction.Parameters); }
public void SaveContents() { var file = new ProgramFile(fileName); file.StringContent = contents; if (!volume.SaveFile(file)) { // For some reason the normal trap that prints exceptions on // the terminal doesn't work here in this part of the code, // thus the two messages: term.Print("[File Save failed. Check space on device?]"); throw new Exception("File Save Failed from Text Editor."); } isDirty = false; term.Print("[Saved changes to " + fileName + "]"); }
protected static void DelegateLoadContents(KOSTextEditPopup me) { me.volume = me.loadingVolume; me.fileName = me.loadingFileName; ProgramFile file = me.volume.GetByName(me.fileName); if (file == null) { me.term.Print("[New File]"); me.contents = ""; } else { me.contents = file.Content; } me.isDirty = false; }
private static void FilterUnusedCode( ProgramFile entryFile, ICollection <ProgramFile> programFiles) { if (_usedCode.Contains(entryFile)) { return; } _usedCode.Add(entryFile); foreach (var import in entryFile.ApplicationImports) { foreach (var file in programFiles.Where(file => file.Namespace == import)) { FilterUnusedCode(file, programFiles); } } }
public void TestFileProcessor_ProcessFile_2() { string inputFileText = "for (int j = 0; j < 5; j++)" + "\r\n{" + "\r\n\tif (pipelinedInstructions[i, j] != 0)" + "\r\n\t{" + "\r\n\t\tLabel label = FindLabel(ConvertToLabelName(i + 1, pipelinedInstructions[i, j]));" + "\r\n\t\tif (label != null)" + "\r\n\t\t{" + "\r\n\t\t\tswitch (j)" + "\r\n\t\t\t{" + "\r\n\t\t\t\tcase 0: label.Content = \" IF\"; break;" + "\r\n\t\t\t\tcase 1: label.Content = \"ID\"; break;" + "\r\n\t\t\t\tcase 2: label.Content = \"EX\"; break;" + "\r\n\t\t\t\tcase 3: label.Content = \" M\"; break;" + "\r\n\t\t\t\tcase 4: label.Content = \"WB\"; break;" + "\r\n\t\t\t}" + "\r\n\t\t}" + "\r\n\t}" + "\r\n}"; string[] expectedFileTextDataArray = { "for", "(", "int", "j", "=", "0", ";", "j", "<", "5", ";", "j", "++", ")", " ", "{", " ", "if", "(", "pipelinedInstructions", "[", "i", ",", "j", "]", "!=", "0", ")", " ", "{", " ", "Label", "label", "=", "FindLabel", "(", "ConvertToLabelName", "(", "i", "+", "1", ",", "pipelinedInstructions", "[", "i", ",", "j", "]", ")", ")", ";", " ", "if", "(", "label", "!=", "null", ")", " ", "{", " ", "switch", "(", "j", ")", " ", "{", " ", "case", "0", ":", "label", ".", "Content", "=", "\"", "IF", "\"", ";", "break", ";", " ", "case", "1", ":", "label", ".", "Content", "=", "\"", "ID", "\"", ";", "break", ";", " ", "case", "2", ":", "label", ".", "Content", "=", "\"", "EX", "\"", ";", "break", ";", " ", "case", "3", ":", "label", ".", "Content", "=", "\"", "M", "\"", ";", "break", ";", " ", "case", "4", ":", "label", ".", "Content", "=", "\"", "WB", "\"", ";", "break", ";", " ", "}", " ", "}", " ", "}", " ", "}", " " }; List <string> expectedFileTextData = new List <string>(); List <string> actualFileTextData; ProgramFile testProgramFile = new ProgramFile("C:\\filepath2", "TestFileName2.cs", inputFileText); expectedFileTextData.AddRange(expectedFileTextDataArray); FileProcessor fileProcessor = new FileProcessor(testProgramFile); fileProcessor.ProcessFile(); actualFileTextData = testProgramFile.FileTextData; CollectionAssert.AreEqual(expectedFileTextData, actualFileTextData); }
/// <summary> /// Given a <see cref="ProgramFile"/>, return the format of the ROM produced by the program, if applicable. /// </summary> /// <param name="program">The support program for which the output ROM format is desired.</param> /// <returns>The resulting ROM produced by the program, or <see cref="RomFormat.None"/> if not applicable.</returns> public static RomFormat OutputFormat(this ProgramFile program) { var outputFormat = RomFormat.None; switch (program) { case ProgramFile.Bin2Luigi: case ProgramFile.Rom2Luigi: outputFormat = RomFormat.Luigi; break; case ProgramFile.Bin2Rom: case ProgramFile.RomMerge: outputFormat = RomFormat.Rom; break; case ProgramFile.Rom2Bin: case ProgramFile.Luigi2Bin: outputFormat = RomFormat.Bin; break; } return(outputFormat); }
public void OpenProgram(ProgramFile programFile) { }
public void RunProgram(ProgramFile programFile) { programFile.StartRunningProgramFile(); }
public void DeleteProgram(ProgramFile programFile) { }
public void InitObjects() { SafeHouse.Logger.LogWarning("InitObjects: " + (shared == null)); shared = new SharedObjects(); CreateFactory(); shared.Vessel = vessel; shared.Processor = this; shared.KSPPart = part; shared.UpdateHandler = new UpdateHandler(); shared.BindingMgr = new BindingManager(shared); shared.Interpreter = shared.Factory.CreateInterpreter(shared); shared.Screen = shared.Interpreter; shared.ScriptHandler = new KSScript(); shared.Logger = new KSPLogger(shared); shared.VolumeMgr = shared.Factory.CreateVolumeManager(shared); shared.ProcessorMgr = new ProcessorManager(); shared.FunctionManager = new FunctionManager(shared); shared.TransferManager = new TransferManager(shared); shared.Cpu = new CPU(shared); shared.SoundMaker = Sound.SoundMaker.Instance; // Make the window that is going to correspond to this kOS part: var gObj = new GameObject("kOSTermWindow", typeof(Screen.TermWindow)); DontDestroyOnLoad(gObj); shared.Window = (Screen.TermWindow)gObj.GetComponent(typeof(Screen.TermWindow)); shared.Window.AttachTo(shared); // initialize archive var archive = shared.Factory.CreateArchive(); shared.VolumeMgr.Add(archive); // initialize harddisk if (HardDisk == null) { HardDisk = new Harddisk(Mathf.Min(diskSpace, PROCESSOR_HARD_CAP)); if (!String.IsNullOrEmpty(Tag)) { HardDisk.Name = Tag; } // populate it with the boot file, but only if using a new disk and in PRELAUNCH situation: if (vessel.situation == Vessel.Situations.PRELAUNCH && bootFile != "None" && !Config.Instance.StartOnArchive) { var bootProgramFile = archive.GetByName(bootFile); if (bootProgramFile != null) { // Copy to HardDisk as "boot". var boot = new ProgramFile(bootProgramFile) { Filename = bootFile }; HardDisk.Add(boot); } } } shared.VolumeMgr.Add(HardDisk); // process setting if (!Config.Instance.StartOnArchive) { shared.VolumeMgr.SwitchTo(HardDisk); } InitProcessorTracking(); }
public void InitObjects() { SafeHouse.Logger.LogWarning("InitObjects: " + (shared == null)); shared = new SharedObjects(); CreateFactory(); shared.Vessel = vessel; shared.Processor = this; shared.KSPPart = part; shared.UpdateHandler = new UpdateHandler(); shared.BindingMgr = new BindingManager(shared); shared.Interpreter = shared.Factory.CreateInterpreter(shared); shared.Screen = shared.Interpreter; shared.ScriptHandler = new KSScript(); shared.Logger = new KSPLogger(shared); shared.VolumeMgr = shared.Factory.CreateVolumeManager(shared); shared.ProcessorMgr = new ProcessorManager(); shared.FunctionManager = new FunctionManager(shared); shared.TransferManager = new TransferManager(shared); shared.Cpu = new CPU(shared); shared.SoundMaker = Sound.SoundMaker.Instance; // Make the window that is going to correspond to this kOS part: var gObj = new GameObject("kOSTermWindow", typeof(Screen.TermWindow)); DontDestroyOnLoad(gObj); shared.Window = (Screen.TermWindow)gObj.GetComponent(typeof(Screen.TermWindow)); shared.Window.AttachTo(shared); // initialize archive var archive = shared.Factory.CreateArchive(); shared.VolumeMgr.Add(archive); // initialize harddisk if (HardDisk == null) { HardDisk = new Harddisk(Mathf.Min(diskSpace, PROCESSOR_HARD_CAP)); // populate it with the boot file, but only if using a new disk and in PRELAUNCH situation: if (vessel.situation == Vessel.Situations.PRELAUNCH && bootFile != "None" && !Config.Instance.StartOnArchive) { var bootProgramFile = archive.GetByName(bootFile); if (bootProgramFile != null) { // Copy to HardDisk as "boot". var boot = new ProgramFile(bootProgramFile) { Filename = bootFile }; HardDisk.Add(boot); } } } shared.VolumeMgr.Add(HardDisk); // process setting if (!Config.Instance.StartOnArchive) { shared.VolumeMgr.SwitchTo(HardDisk); } InitProcessorTracking(); }
private static void Decode(ProgramFile programFile, string input) { try { string decodedString; try { // base64 encoding // Fix for issue #429. See comment up in EncodeBase64() method above for an explanation: string massagedInput = input.Replace(',','/'); byte[] decodedBuffer = DecodeBase64ToBinary(massagedInput); FileCategory whatKind = PersistenceUtilities.IdentifyCategory(decodedBuffer); if (whatKind == FileCategory.ASCII || whatKind == FileCategory.KERBOSCRIPT) { decodedString = Encoding.ASCII.GetString(decodedBuffer); programFile.StringContent = decodedString; } else { programFile.BinaryContent = decodedBuffer; } } catch (FormatException) { // standard encoding decodedString = PersistenceUtilities.DecodeLine(input); programFile.StringContent = decodedString; } } catch (Exception e) { SafeHouse.Logger.Log(string.Format("Exception decoding: {0} | {1}", e, e.Message)); } }
public void Execute(ProgramFile program) { RegisterOut.Value = RegisterOne.Value / RegisterTwo.Value; }
public static GameObject StaticAddProgramFile(ProgramFile programFile) { return(programGUIManager.AddProgramFile(programFile)); }
public override void Execute(SharedObjects shared) { bool defaultOutput = false; bool justCompiling = false; // is this load() happening to compile, or to run? string fileNameOut = null; object topStack = PopValueAssert(shared, true); // null if there's no output file (output file means compile, not run). if (topStack != null) { justCompiling = true; string outputArg = topStack.ToString(); if (outputArg.Equals("-default-compile-out-")) { defaultOutput = true; } else { fileNameOut = PersistenceUtilities.CookedFilename(outputArg, Volume.KOS_MACHINELANGUAGE_EXTENSION); } } string fileName = null; topStack = PopValueAssert(shared, true); if (topStack != null) { fileName = topStack.ToString(); } AssertArgBottomAndConsume(shared); if (fileName == null) { throw new KOSFileException("No filename to load was given."); } ProgramFile file = shared.VolumeMgr.CurrentVolume.GetByName(fileName, (!justCompiling)); // if running, look for KSM first. If compiling look for KS first. if (file == null) { throw new KOSFileException(string.Format("Can't find file '{0}'.", fileName)); } fileName = file.Filename; // just in case GetByName picked an extension that changed it. // filename is now guaranteed to have an extension. To make default output name, replace the extension with KSM: if (defaultOutput) { fileNameOut = fileName.Substring(0, fileName.LastIndexOf('.')) + "." + Volume.KOS_MACHINELANGUAGE_EXTENSION; } if (fileNameOut != null && fileName == fileNameOut) { throw new KOSFileException("Input and output filenames must differ."); } if (shared.VolumeMgr == null) { return; } if (shared.VolumeMgr.CurrentVolume == null) { throw new KOSFileException("Volume not found"); } if (shared.ScriptHandler != null) { var options = new CompilerOptions { LoadProgramsInSameAddressSpace = true, FuncManager = shared.FunctionManager }; string filePath = shared.VolumeMgr.GetVolumeRawIdentifier(shared.VolumeMgr.CurrentVolume) + "/" + fileName; // add this program to the address space of the parent program, // or to a file to save: if (justCompiling) { List <CodePart> compileParts = shared.ScriptHandler.Compile(filePath, 1, file.StringContent, String.Empty, options); bool success = shared.VolumeMgr.CurrentVolume.SaveObjectFile(fileNameOut, compileParts); if (!success) { throw new KOSFileException("Can't save compiled file: not enough space or access forbidden"); } } else { var programContext = ((CPU)shared.Cpu).SwitchToProgramContext(); List <CodePart> parts; if (file.Category == FileCategory.KSM) { string prefix = programContext.Program.Count.ToString(); parts = shared.VolumeMgr.CurrentVolume.LoadObjectFile(filePath, prefix, file.BinaryContent); } else { parts = shared.ScriptHandler.Compile(filePath, 1, file.StringContent, "program", options); } 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) { // run() is strange. It needs two levels of args - the args to itself, and the args it is meant to // pass on to the program it's invoking. First, these are the args to run itself: object volumeId = PopValueAssert(shared, true); string fileName = PopValueAssert(shared, true).ToString(); AssertArgBottomAndConsume(shared); // Now the args it is going to be passing on to the program: var progArgs = new List <Object>(); int argc = CountRemainingArgs(shared); for (int i = 0; i < argc; ++i) { progArgs.Add(PopValueAssert(shared, true)); } AssertArgBottomAndConsume(shared); if (shared.VolumeMgr == null) { return; } if (shared.VolumeMgr.CurrentVolume == null) { throw new Exception("Volume not found"); } ProgramFile file = shared.VolumeMgr.CurrentVolume.GetByName(fileName, true); if (file == null) { throw new Exception(string.Format("File '{0}' not found", fileName)); } if (shared.ScriptHandler == null) { return; } if (volumeId != null) { Volume targetVolume = shared.VolumeMgr.GetVolume(volumeId); if (targetVolume != null) { if (shared.ProcessorMgr != null) { string filePath = string.Format("{0}/{1}", shared.VolumeMgr.GetVolumeRawIdentifier(targetVolume), fileName); var options = new CompilerOptions { LoadProgramsInSameAddressSpace = true, FuncManager = shared.FunctionManager }; List <CodePart> parts = shared.ScriptHandler.Compile(filePath, 1, file.StringContent, "program", options); var builder = new ProgramBuilder(); builder.AddRange(parts); List <Opcode> program = builder.BuildProgram(); shared.ProcessorMgr.RunProgramOn(program, targetVolume); } } else { throw new KOSFileException("Volume not found"); } } else { // clear the "program" compilation context shared.ScriptHandler.ClearContext("program"); string filePath = shared.VolumeMgr.GetVolumeRawIdentifier(shared.VolumeMgr.CurrentVolume) + "/" + fileName; var options = new CompilerOptions { LoadProgramsInSameAddressSpace = true, FuncManager = shared.FunctionManager }; var programContext = ((CPU)shared.Cpu).SwitchToProgramContext(); List <CodePart> codeParts; if (file.Category == FileCategory.KSM) { string prefix = programContext.Program.Count.ToString(); codeParts = shared.VolumeMgr.CurrentVolume.LoadObjectFile(filePath, prefix, file.BinaryContent); } else { try { codeParts = shared.ScriptHandler.Compile(filePath, 1, file.StringContent, "program", options); } catch (Exception) { // If it died due to a compile error, then we won't really be able to switch to program context // as was implied by calling Cpu.SwitchToProgramContext() up above. The CPU needs to be // told that it's still in interpreter context, or else it fails to advance the interpreter's // instruction pointer and it will just try the "call run()" instruction again: shared.Cpu.BreakExecution(false); throw; } } programContext.AddParts(codeParts); } // Because run() returns FIRST, and THEN the CPU jumps to the new program's first instruction that it set up, // it needs to put the return stack in a weird order. Its return value needs to be buried UNDER the args to the // program it's calling: UsesAutoReturn = false; shared.Cpu.PushStack(0); // dummy return that all functions have. // Put the args for the program being called back on in the same order they were in before (so read the list backward): for (int i = argc - 1; i >= 0; --i) { shared.Cpu.PushStack(progArgs[i]); } }
public void Execute(ProgramFile program) { Register.Value = Value; }
/// <summary> /// Sets the directory that should contain the specified program. /// </summary> /// <param name="program">The program whose directory is being specified.</param> /// <param name="directoryContainingProgram">The directory that contains the program.</param> public void SetProgramPath(ProgramFile program, string directoryContainingProgram) { _programPaths[program] = directoryContainingProgram; }