88 * You must not remove this notice, or any other, from this software.
99 **/
1010
11- using clojure . lang . CljCompiler . Ast ;
1211using clojure . lang . Runtime ;
1312using Microsoft . Scripting . Generation ;
1413using System ;
1514using System . Collections ;
16- using System . Collections . Concurrent ;
1715using System . Collections . Generic ;
1816using System . Diagnostics . SymbolStore ;
1917using System . Linq . Expressions ;
@@ -27,8 +25,8 @@ public sealed class GenContext
2725 {
2826 #region Data
2927
30- readonly MyAssemblyGen _assyGen ;
31- public MyAssemblyGen AssemblyGen
28+ readonly AssemblyGen _assyGen ;
29+ public AssemblyGen AssemblyGen
3230 {
3331 get { return _assyGen ; }
3432 }
@@ -75,16 +73,27 @@ public ISymbolDocumentWriter DocWriter
7573
7674 #region C-tors & factory methods
7775
78- private readonly static ConcurrentDictionary < Assembly , bool > _internalAssemblies = new ConcurrentDictionary < Assembly , bool > ( ) ;
79- private static void AddInternalAssembly ( Assembly a ) => _internalAssemblies [ a ] = true ;
80- public static bool IsInternalAssembly ( Assembly a ) => _internalAssemblies . ContainsKey ( a ) ;
76+ private readonly static Dictionary < Assembly , bool > InternalAssemblies = new Dictionary < Assembly , bool > ( ) ;
8177
82- enum AssemblyType { Internal , External }
78+ private static void AddInternalAssembly ( Assembly a )
79+ {
80+ lock ( ( ( ICollection ) InternalAssemblies ) . SyncRoot )
81+ {
82+ InternalAssemblies [ a ] = true ;
83+ }
84+ }
8385
86+ public static bool IsInternalAssembly ( Assembly a )
87+ {
88+ lock ( ( ( ICollection ) InternalAssemblies ) . SyncRoot )
89+ {
90+ return InternalAssemblies . ContainsKey ( a ) ;
91+ }
92+ }
8493
8594 public static GenContext CreateWithInternalAssembly ( string assyName , bool createDynInitHelper )
8695 {
87- GenContext ctx = CreateGenContext ( AssemblyType . Internal , assyName , assyName , ".dll" , null , createDynInitHelper ) ;
96+ GenContext ctx = CreateGenContext ( assyName , assyName , ".dll" , null , createDynInitHelper ) ;
8897 AddInternalAssembly ( ctx . AssemblyBuilder ) ;
8998 return ctx ;
9099 }
@@ -99,15 +108,15 @@ public static GenContext CreateWithInternalAssembly(string assyName, bool create
99108 public static GenContext CreateWithExternalAssembly ( string sourceName , string assyName , string extension , bool createDynInitHelper )
100109 {
101110 string path = Compiler . CompilePathVar . deref ( ) as string ;
102- return CreateGenContext ( AssemblyType . External , sourceName , assyName , extension , path ?? System . IO . Directory . GetCurrentDirectory ( ) , createDynInitHelper ) ;
111+ return CreateGenContext ( sourceName , assyName , extension , path ?? System . IO . Directory . GetCurrentDirectory ( ) , createDynInitHelper ) ;
103112 }
104113
105114 public static GenContext CreateWithExternalAssembly ( string assyName , string extension , bool createDynInitHelper )
106115 {
107116 return CreateWithExternalAssembly ( assyName , assyName , extension , createDynInitHelper ) ;
108117 }
109118
110- private static GenContext CreateGenContext ( AssemblyType assemblyType , string sourceName , string assyName , string extension , string directory , bool createDynInitHelper )
119+ private static GenContext CreateGenContext ( string sourceName , string assyName , string extension , string directory , bool createDynInitHelper )
111120 {
112121 if ( directory != null )
113122 {
@@ -116,10 +125,10 @@ private static GenContext CreateGenContext(AssemblyType assemblyType, string sou
116125 }
117126
118127 AssemblyName aname = new AssemblyName ( assyName ) ;
119- return new GenContext ( assemblyType , directory , aname , extension , createDynInitHelper , sourceName ) ;
128+ return new GenContext ( directory , aname , extension , createDynInitHelper , sourceName ) ;
120129 }
121130
122- private GenContext ( AssemblyType assemblyType , string directory , AssemblyName aname , string extension , bool createDynInitHelper , string sourceName )
131+ private GenContext ( string directory , AssemblyName aname , string extension , bool createDynInitHelper , string sourceName )
123132 {
124133 // TODO: Make this settable from a *debug* flag
125134#if DEBUG
@@ -128,22 +137,7 @@ private GenContext(AssemblyType assemblyType, string directory, AssemblyName ana
128137 _isDebuggable = false ;
129138#endif
130139
131- #if NETFRAMEWORK || NET9_0_OR_GREATER
132- switch ( assemblyType )
133- {
134- case AssemblyType . Internal :
135- _assyGen = new MyAssemblyGen ( aname , _isDebuggable ) ;
136- break ;
137- case AssemblyType . External :
138- _assyGen = new MyAssemblyGen ( aname , directory , extension , _isDebuggable ) ;
139- break ;
140- default :
141- throw new InvalidOperationException ( "Unknown AssemblyType" ) ;
142- }
143- #else
144- _assyGen = new MyAssemblyGen ( aname , _isDebuggable ) ;
145- #endif
146-
140+ _assyGen = new AssemblyGen ( aname , directory , extension , _isDebuggable ) ;
147141 if ( createDynInitHelper )
148142 _dynInitHelper = new DynInitHelper ( _assyGen , GenerateName ( ) ) ;
149143
@@ -156,9 +150,6 @@ private GenContext(AssemblyType assemblyType, string directory, AssemblyName ana
156150#if NETFRAMEWORK
157151 if ( _isDebuggable )
158152 _docWriter = ModuleBuilder . DefineDocument ( sourceName , ClojureContext . Default . LanguageGuid , ClojureContext . Default . VendorGuid , Guid . Empty ) ;
159- #elif NET9_0_OR_GREATER
160- if ( _isDebuggable && assemblyType == AssemblyType . External )
161- _docWriter = ModuleBuilder . DefineDocument ( sourceName , ClojureContext . Default . LanguageGuid ) ;
162153#endif
163154 }
164155
@@ -248,22 +239,22 @@ public Expression MaybeAddDebugInfo(Expression expr, IPersistentMap spanMap)
248239 return expr ;
249240 }
250241
251- public static void EmitDebugInfo ( CljILGen ilg , IPersistentMap spanMap )
242+ public static void EmitDebugInfo ( ILGen ilg , IPersistentMap spanMap )
252243 {
253244 if ( Compiler . CompilerContextVar . deref ( ) is GenContext context )
254245 context . MaybeEmitDebugInfo ( ilg , spanMap ) ;
255246 }
256247
257- public void MaybeEmitDebugInfo ( CljILGen ilg , IPersistentMap spanMap )
248+ public void MaybeEmitDebugInfo ( ILGen ilg , IPersistentMap spanMap )
258249 {
259- #if NETFRAMEWORK || NET9_0_OR_GREATER
250+ #if NETFRAMEWORK
260251 if ( _docWriter != null && spanMap != null )
261252 {
262253 if ( Compiler . GetLocations ( spanMap , out int startLine , out int startCol , out int finishLine , out int finishCol ) )
263254 {
264255 try
265256 {
266- ilg . ILGenerator . MarkSequencePoint ( _docWriter , startLine , startCol , finishLine , finishCol ) ;
257+ ilg . MarkSequencePoint ( _docWriter , startLine , startCol , finishLine , finishCol ) ;
267258 }
268259 catch ( NotSupportedException )
269260 {
0 commit comments