@@ -113,113 +113,6 @@ namespace Microsoft.FSharp.Compiler.SimpleSourceCodeServices
113
113
let checker = InteractiveChecker.Create()
114
114
let fileversion = 0
115
115
let loadTime = DateTime.Now
116
-
117
- let mkCompilationErorHandlers () =
118
- let errors = ResizeArray<_>()
119
-
120
- let errorSink warn exn =
121
- let mainError , relatedErrors = SplitRelatedErrors exn
122
- let oneError trim e = errors.Add( ErrorInfo.CreateFromException ( e, warn, trim, Range.range0))
123
- oneError false mainError
124
- List.iter ( oneError true ) relatedErrors
125
-
126
- let errorLogger =
127
- { new ErrorLogger( " CompileAPI" ) with
128
- member x.WarnSinkImpl ( exn ) = errorSink true exn
129
- member x.ErrorSinkImpl ( exn ) = errorSink false exn
130
- member x.ErrorCount = errors |> Seq.filter ( fun e -> e.Severity = FSharpErrorSeverity.Error) |> Seq.length }
131
-
132
- let loggerProvider =
133
- { new ErrorLoggerProvider() with
134
- member x.CreateErrorLoggerThatQuitsAfterMaxErrors ( _tcConfigBuilder , _exiter ) = errorLogger }
135
- errors, errorLogger, loggerProvider
136
-
137
- let tryCompile errorLogger f =
138
- use unwindParsePhase = PushThreadBuildPhaseUntilUnwind ( BuildPhase.Parse)
139
- use unwindEL_2 = PushErrorLoggerPhaseUntilUnwind ( fun _ -> errorLogger)
140
- let exiter = { new Exiter with member x.Exit n = raise StopProcessing }
141
- try
142
- f exiter
143
- 0
144
- with e ->
145
- stopProcessingRecovery e Range.range0
146
- 1
147
-
148
- /// Compile using the given flags. Source files names are resolved via the FileSystem API. The output file must be given by a -o flag.
149
- let compileFromArgs ( argv : string [], tcImportsCapture , dynamicAssemblyCreator ) =
150
-
151
- let errors , errorLogger , loggerProvider = mkCompilationErorHandlers()
152
- let result =
153
- tryCompile errorLogger ( fun exiter ->
154
- mainCompile ( argv, (* bannerAlreadyPrinted*) true , (* openBinariesInMemory*) true , exiter, loggerProvider, tcImportsCapture, dynamicAssemblyCreator) )
155
-
156
- errors.ToArray(), result
157
-
158
- let compileFromAsts ( asts , assemblyName , outFile , dependencies , noframework , pdbFile , executable , tcImportsCapture , dynamicAssemblyCreator ) =
159
-
160
- let errors , errorLogger , loggerProvider = mkCompilationErorHandlers()
161
-
162
- let executable = defaultArg executable true
163
- let target = if executable then CompilerTarget.ConsoleExe else CompilerTarget.Dll
164
-
165
- let result =
166
- tryCompile errorLogger ( fun exiter ->
167
- compileOfAst ( (* openBinariesInMemory=*) true , assemblyName, target, outFile, pdbFile, dependencies, noframework, exiter, loggerProvider, asts, tcImportsCapture, dynamicAssemblyCreator))
168
-
169
- errors.ToArray(), result
170
-
171
- let dynamicAssemblyCreator ( debugInfo : bool , tcImportsRef : TcImports option ref , execute : _ option , assemblyBuilderRef : _ option ref ) ( _tcConfig , ilGlobals , _errorLogger , outfile , _pdbfile , ilxMainModule , _signingInfo ) =
172
-
173
- // Create an assembly builder
174
- let assemblyName = System.Reflection.AssemblyName( System.IO.Path.GetFileNameWithoutExtension outfile)
175
- let flags = System.Reflection.Emit.AssemblyBuilderAccess.Run
176
- #if FX_ NO_ APP_ DOMAINS
177
- let assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly( assemblyName, flags)
178
- let moduleBuilder = assemblyBuilder.DefineDynamicModule( " IncrementalModule" )
179
- #else
180
- let assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly( assemblyName, flags)
181
- let moduleBuilder = assemblyBuilder.DefineDynamicModule( " IncrementalModule" , debugInfo)
182
- #endif
183
- // Omit resources in dynamic assemblies, because the module builder is constructed without a filename the module
184
- // is tagged as transient and as such DefineManifestResource will throw an invalid operation if resources are present.
185
- //
186
- // Also, the dynamic assembly creator can't currently handle types called "<Module>" from statically linked assemblies.
187
- let ilxMainModule =
188
- { ilxMainModule with
189
- TypeDefs = ilxMainModule.TypeDefs.AsList |> List.filter ( fun td -> not ( isTypeNameForGlobalFunctions td.Name)) |> mkILTypeDefs
190
- Resources= mkILResources [] }
191
-
192
- // The function used to resolve typees while emitting the code
193
- let assemblyResolver s =
194
- match tcImportsRef.Value.Value.TryFindExistingFullyQualifiedPathFromAssemblyRef s with
195
- | Some res -> Some ( Choice1Of2 res)
196
- | None -> None
197
-
198
- // Emit the code
199
- let _emEnv , execs = ILRuntimeWriter.emitModuleFragment( ilGlobals, ILRuntimeWriter.emEnv0, assemblyBuilder, moduleBuilder, ilxMainModule, debugInfo, assemblyResolver)
200
-
201
- // Execute the top-level initialization, if requested
202
- if execute.IsSome then
203
- for exec in execs do
204
- match exec() with
205
- | None -> ()
206
- | Some exn -> raise exn
207
-
208
- // Register the reflected definitions for the dynamically generated assembly
209
- for resource in ilxMainModule.Resources.AsList do
210
- if IsReflectedDefinitionsResource resource then
211
- Quotations.Expr.RegisterReflectedDefinitions( assemblyBuilder, moduleBuilder.Name, resource.Bytes)
212
-
213
- // Save the result
214
- assemblyBuilderRef := Some assemblyBuilder
215
-
216
- let setOutputStreams execute =
217
- // Set the output streams, if requested
218
- match execute with
219
- | Some ( writer, error) ->
220
- System.Console.SetOut writer
221
- System.Console.SetError error
222
- | None -> ()
223
116
224
117
225
118
/// Tokenize a single line, returning token information and a tokenization state represented by an integer
@@ -278,14 +171,14 @@ namespace Microsoft.FSharp.Compiler.SimpleSourceCodeServices
278
171
checker.ParseAndCheckProject( options)
279
172
280
173
member x.Compile ( argv : string []) =
281
- compileFromArgs ( argv, None, None)
174
+ CompileHelpers. compileFromArgs ( argv, None, None)
282
175
283
176
member x.Compile ( ast : ParsedInput list , assemblyName : string , outFile : string , dependencies : string list , ? pdbFile : string , ? executable : bool , ? noframework : bool ) =
284
177
let noframework = defaultArg noframework false
285
- compileFromAsts ( ast, assemblyName, outFile, dependencies, noframework, pdbFile, executable, None, None)
178
+ CompileHelpers. compileFromAsts ( ast, assemblyName, outFile, dependencies, noframework, pdbFile, executable, None, None)
286
179
287
180
member x.CompileToDynamicAssembly ( otherFlags : string [], execute : ( TextWriter * TextWriter ) option ) =
288
- setOutputStreams execute
181
+ CompileHelpers. setOutputStreams execute
289
182
290
183
// References used to capture the results of compilation
291
184
let tcImportsRef = ref ( None: TcImports option)
@@ -294,10 +187,10 @@ namespace Microsoft.FSharp.Compiler.SimpleSourceCodeServices
294
187
295
188
// Function to generate and store the results of compilation
296
189
let debugInfo = otherFlags |> Array.exists ( fun arg -> arg = " -g" || arg = " --debug:+" || arg = " /debug:+" )
297
- let dynamicAssemblyCreator = Some ( dynamicAssemblyCreator ( debugInfo, tcImportsRef, execute, assemblyBuilderRef))
190
+ let dynamicAssemblyCreator = Some ( CompileHelpers. dynamicAssemblyCreator ( debugInfo, tcImportsRef, execute, assemblyBuilderRef))
298
191
299
192
// Perform the compilation, given the above capturing function.
300
- let errorsAndWarnings , result = compileFromArgs ( otherFlags, tcImportsCapture, dynamicAssemblyCreator)
193
+ let errorsAndWarnings , result = CompileHelpers. compileFromArgs ( otherFlags, tcImportsCapture, dynamicAssemblyCreator)
301
194
302
195
// Retrieve and return the results
303
196
let assemblyOpt =
@@ -308,7 +201,7 @@ namespace Microsoft.FSharp.Compiler.SimpleSourceCodeServices
308
201
errorsAndWarnings, result, assemblyOpt
309
202
310
203
member x.CompileToDynamicAssembly ( asts : ParsedInput list , assemblyName : string , dependencies : string list , execute : ( TextWriter * TextWriter ) option , ? debug : bool , ? noframework : bool ) =
311
- setOutputStreams execute
204
+ CompileHelpers. setOutputStreams execute
312
205
313
206
// References used to capture the results of compilation
314
207
let tcImportsRef = ref ( None: TcImports option)
@@ -323,11 +216,11 @@ namespace Microsoft.FSharp.Compiler.SimpleSourceCodeServices
323
216
let outFile = Path.Combine( location, assemblyName + " .dll" )
324
217
325
218
// Function to generate and store the results of compilation
326
- let dynamicAssemblyCreator = Some ( dynamicAssemblyCreator ( debugInfo, tcImportsRef, execute, assemblyBuilderRef))
219
+ let dynamicAssemblyCreator = Some ( CompileHelpers. dynamicAssemblyCreator ( debugInfo, tcImportsRef, execute, assemblyBuilderRef))
327
220
328
221
// Perform the compilation, given the above capturing function.
329
222
let errorsAndWarnings , result =
330
- compileFromAsts ( asts, assemblyName, outFile, dependencies, noframework, None, Some execute.IsSome, tcImportsCapture, dynamicAssemblyCreator)
223
+ CompileHelpers. compileFromAsts ( asts, assemblyName, outFile, dependencies, noframework, None, Some execute.IsSome, tcImportsCapture, dynamicAssemblyCreator)
331
224
332
225
// Retrieve and return the results
333
226
let assemblyOpt =
0 commit comments