示例#1
0
 public override Compilation UpdateCompilationParts(IEnumerable<CompilationPart> parts) {
   SmallBasicAssembly/*?*/ oldAssembly = this.Result as SmallBasicAssembly;
   if (oldAssembly != null) {
     SmallBasicAssembly newAssembly = new SmallBasicAssembly(oldAssembly.Name, oldAssembly.Location, this.HostEnvironment, this.options, oldAssembly.AssemblyReferences, oldAssembly.ModuleReferences, parts);
     return (Compilation)newAssembly.Compilation;
   }
   //^ assume this.Result is Module; //follows from constructor precondition and immutability.
   SmallBasicModule oldModule = (SmallBasicModule)this.Result;
   SmallBasicModule newModule = new SmallBasicModule(oldModule.Name, oldModule.Location, this.HostEnvironment, this.options, Dummy.Assembly, oldModule.AssemblyReferences, oldModule.ModuleReferences, parts);
   return newModule.Compilation;
 }
示例#2
0
 private static void Compile(string fileName) {
   HostEnvironment hostEnvironment = new HostEnvironment();
   IName name = hostEnvironment.NameTable.GetNameFor(fileName);
   IDictionary<string, string> options = new Dictionary<string, string>();
   List<IAssemblyReference> assemblyReferences = new List<IAssemblyReference>();
   List<IModuleReference> moduleReferences = new List<IModuleReference>();
   assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.CoreAssemblySymbolicIdentity));
   assemblyReferences.Add((IAssembly)hostEnvironment.LoadUnitFrom(typeof(Microsoft.SmallBasic.Library.ConsoleWindow).Assembly.Location));
   StreamReader instream = File.OpenText(fileName);
   List<SmallBasicDocument> programSources = new List<SmallBasicDocument>(1);
   SmallBasicAssembly assem = new SmallBasicAssembly(name, Path.GetFullPath(fileName), hostEnvironment, options, assemblyReferences, moduleReferences, programSources);
   SmallBasicCompilationHelper helper = new SmallBasicCompilationHelper(assem.Compilation);
   programSources.Add(new SmallBasicDocument(helper, name, Path.GetFullPath(fileName), instream));
   var exeFile = File.Create(Path.ChangeExtension(fileName, "exe"));
   var sourceLocationProvider = assem.Compilation.SourceLocationProvider;
   //var localScopeProvider = assem.Compilation.LocalScopeProvider;
   using (var pdbWriter = new PdbWriter(Path.ChangeExtension(fileName, "pdb"), sourceLocationProvider)) {
     PeWriter.WritePeToStream(assem, hostEnvironment, exeFile, sourceLocationProvider, null, pdbWriter);
   }
 }
示例#3
0
 private static void RunTest(HostEnvironment hostEnvironment, string suiteName, string test, StringBuilder actualOutput, List<string> compilerParameters, List<string> testCaseParameters) {
   IName name = hostEnvironment.NameTable.GetNameFor(suiteName);
   IDictionary<string, string> options = new Dictionary<string, string>();
   List<IAssemblyReference> assemblyReferences = new List<IAssemblyReference>();
   List<IModuleReference> moduleReferences = new List<IModuleReference>();
   assemblyReferences.Add(hostEnvironment.LoadAssembly(hostEnvironment.CoreAssemblySymbolicIdentity));
   assemblyReferences.Add((IAssembly)hostEnvironment.LoadUnitFrom(typeof(Microsoft.SmallBasic.Library.ConsoleWindow).Assembly.Location));
   SmallBasicAssembly/*?*/ assem = null;
   SmallBasicCompilationHelper helper;
   List<SmallBasicDocument> programSources = new List<SmallBasicDocument>(1);
   assem = new SmallBasicAssembly(name, "", hostEnvironment, options, assemblyReferences, moduleReferences, programSources);
   helper = new SmallBasicCompilationHelper(assem.Compilation);
   programSources.Add(/*hostEnvironment.previousDocument = */new SmallBasicDocument(helper, name, "", test));
   var memStream = new MemoryStream();
   PeWriter.WritePeToStream(assem, hostEnvironment, memStream);
   var runtimeAssembly = System.Reflection.Assembly.Load(memStream.ToArray());
   runtimeAssembly.EntryPoint.Invoke(null, null);
 }