1414using System . Linq ;
1515using System . Reflection ;
1616using System . Reflection . Emit ;
17+ using System . Transactions ;
1718
1819namespace clojure . lang . CljCompiler . Ast
1920{
20- public class FnExpr : ObjExpr
21+ public class FnExpr ( object tag ) : ObjExpr ( tag )
2122 {
2223 #region Data
2324
2425 static readonly Keyword KW_ONCE = Keyword . intern ( null , "once" ) ;
2526
2627 FnMethod _variadicMethod = null ;
27- public FnMethod VariadicMethod { get { return _variadicMethod ; } }
28- bool IsVariadic { get { return _variadicMethod != null ; } }
28+ public FnMethod VariadicMethod => _variadicMethod ;
29+ bool IsVariadic => _variadicMethod is not null ;
2930
3031 bool _hasMeta ;
31- protected override bool SupportsMeta { get { return _hasMeta ; } }
32+ protected override bool SupportsMeta => _hasMeta ;
3233
3334 bool _hasEnclosingMethod ;
3435
3536 private readonly int _dynMethodMapKey = RT . nextID ( ) ;
36- public int DynMethodMapKey { get { return _dynMethodMapKey ; } }
37+ public int DynMethodMapKey => _dynMethodMapKey ;
3738
3839 Type _cachedType ;
3940
4041 #endregion
4142
42- #region Ctors
43-
44- public FnExpr ( object tag )
45- : base ( tag )
46- {
47- }
48-
49- #endregion
50-
5143 #region Misc
5244
5345 // This naming convention drawn from the Java code.
5446 internal void ComputeNames ( ISeq form , string name )
5547 {
5648 ObjMethod enclosingMethod = ( ObjMethod ) Compiler . MethodVar . deref ( ) ;
5749
58- string baseName = enclosingMethod != null
50+ string baseName = enclosingMethod is not null
5951 ? enclosingMethod . Objx . Name
6052 : Compiler . munge ( Compiler . CurrentNamespace . Name . Name ) + "$" ;
6153
@@ -67,7 +59,7 @@ internal void ComputeNames(ISeq form, string name)
6759 }
6860 else
6961 {
70- if ( name == null )
62+ if ( name is null )
7163 name = "fn__" + RT . nextID ( ) ;
7264 else if ( enclosingMethod != null )
7365 name += "__" + RT . nextID ( ) ;
@@ -83,20 +75,13 @@ internal void ComputeNames(ISeq form, string name)
8375
8476 #region Type munging
8577
86- public override bool HasClrType
87- {
88- get
89- {
90- return true ;
91- }
92- }
78+ public override bool HasClrType => true ;
9379
9480 public override Type ClrType
9581 {
9682 get
9783 {
98- if ( _cachedType == null )
99- _cachedType = _tag != null ? HostExpr . TagToType ( _tag ) : typeof ( AFunction ) ;
84+ _cachedType ??= _tag is not null ? HostExpr . TagToType ( _tag ) : typeof ( AFunction ) ;
10085 return _cachedType ;
10186 }
10287 }
@@ -127,7 +112,7 @@ public static Expr Parse(ParserContext pcon, ISeq form, string name)
127112
128113 fn . ComputeNames ( form , name ) ;
129114
130- List < string > prims = new ( ) ;
115+ List < string > prims = [ ] ;
131116
132117 //arglist might be preceded by symbol naming this fn
133118 Symbol nm = RT . second ( form ) as Symbol ;
@@ -148,7 +133,6 @@ public static Expr Parse(ParserContext pcon, ISeq form, string name)
148133 GenContext newContext = context . WithNewDynInitHelper ( fn . InternalName + "__dynInitHelper_" + RT . nextID ( ) . ToString ( ) ) ;
149134 Var . pushThreadBindings ( RT . map ( Compiler . CompilerContextVar , newContext ) ) ;
150135
151-
152136 try
153137 {
154138 try
@@ -162,7 +146,7 @@ public static Expr Parse(ParserContext pcon, ISeq form, string name)
162146 Compiler . ProtocolCallsitesVar , PersistentVector . EMPTY ,
163147 Compiler . VarCallsitesVar , Compiler . EmptyVarCallSites ( ) ,
164148 Compiler . NoRecurVar , null ) ) ;
165- SortedDictionary < int , FnMethod > methods = new ( ) ;
149+ SortedDictionary < int , FnMethod > methods = [ ] ;
166150 FnMethod variadicMethod = null ;
167151 bool usesThis = false ;
168152
@@ -205,7 +189,7 @@ public static Expr Parse(ParserContext pcon, ISeq form, string name)
205189 for ( ISeq s = RT . seq ( allMethods ) ; s != null ; s = s . next ( ) )
206190 {
207191 FnMethod fm = s . first ( ) as FnMethod ;
208- if ( fm . Locals != null )
192+ if ( fm . Locals is not null )
209193 {
210194 for ( ISeq sl = RT . seq ( RT . keys ( fm . Locals ) ) ; sl != null ; sl = sl . next ( ) )
211195 {
@@ -235,7 +219,7 @@ public static Expr Parse(ParserContext pcon, ISeq form, string name)
235219
236220
237221 IPersistentMap fmeta = RT . meta ( origForm ) ;
238- if ( fmeta != null )
222+ if ( fmeta is not null )
239223 fmeta = fmeta . without ( RT . LineKey ) . without ( RT . ColumnKey ) . without ( RT . SourceSpanKey ) . without ( RT . FileKey ) . without ( retKey ) ;
240224 fn . _hasMeta = RT . count ( fmeta ) > 0 ;
241225
@@ -259,7 +243,7 @@ public static Expr Parse(ParserContext pcon, ISeq form, string name)
259243 }
260244 finally
261245 {
262- if ( newContext != null )
246+ if ( newContext is not null )
263247 Var . popThreadBindings ( ) ;
264248 }
265249 }
@@ -269,26 +253,13 @@ internal void AddMethod(FnMethod method)
269253 Methods = RT . conj ( Methods , method ) ;
270254 }
271255
272-
273- //static bool HasPrimDecls(ISeq forms)
274- //{
275- // for (ISeq s = forms; s != null; s = RT.next(s))
276- // if (FnMethod.HasPrimInterface((ISeq)RT.first(s)))
277- // return true;
278-
279- // return false;
280- //}
281-
282- //static readonly MethodInfo Method_FnExpr_GetDynMethod = typeof(FnExpr).GetMethod("GetDynMethod");
283- //static readonly MethodInfo Method_FnExpr_GetCompiledConstants = typeof(FnExpr).GetMethod("GetCompiledConstants");
284-
285- static readonly Dictionary < int , Dictionary < int , DynamicMethod > > DynMethodMap = new ( ) ;
286- static readonly Dictionary < int , object [ ] > ConstantsMap = new ( ) ;
256+ static readonly Dictionary < int , Dictionary < int , DynamicMethod > > DynMethodMap = [ ] ;
257+ static readonly Dictionary < int , object [ ] > ConstantsMap = [ ] ;
287258
288259 public static DynamicMethod GetDynMethod ( int key , int arity )
289260 {
290261 DynamicMethod dm = DynMethodMap [ key ] [ arity ] ;
291- if ( dm == null )
262+ if ( dm is null )
292263 Console . WriteLine ( "Bad dynmeth retrieval" ) ;
293264 return dm ;
294265 // Dictionary<int, WeakReference > dict = DynMethodMap[key];
@@ -299,49 +270,19 @@ public static DynamicMethod GetDynMethod(int key, int arity)
299270 public static object [ ] GetCompiledConstants ( int key )
300271 {
301272 return ConstantsMap [ key ] ;
302- //WeakReference wr = ConstantsMap[key];
303- //return (object[])wr.Target;
304273 }
305274
306- //private static int GetMethodKey(FnMethod method)
307- //{
308- // int arity = method.IsVariadic
309- // ? method.RequiredArity + 1 // to avoid the non-variadics, the last of which may have NumParams == this method RequireArity
310- // : method.NumParams;
311-
312- // return arity;
313- //}
314-
315- //private void EmitGetDynMethod(int arity, CljILGen ilg)
316- //{
317- // ilg.EmitInt(DynMethodMapKey);
318- // ilg.EmitInt(arity);
319- // ilg.Emit(OpCodes.Call,Method_FnExpr_GetDynMethod);
320- //}
321-
322- //private void EmitGetCompiledConstants(CljILGen ilg)
323- //{
324- // ilg.EmitInt(DynMethodMapKey);
325- // ilg.Emit(OpCodes.Call, Method_FnExpr_GetCompiledConstants);
326- //}
327-
328275 #endregion
329276
330277 #region eval
331278
332- public override object Eval ( )
333- {
334- return base . Eval ( ) ;
335- }
279+ public override object Eval ( ) => base . Eval ( ) ;
336280
337281 #endregion
338282
339283 #region Code generation
340284
341- internal void EmitForDefn ( ObjExpr objx , CljILGen ilg )
342- {
343- Emit ( RHC . Expression , objx , ilg ) ;
344- }
285+ internal void EmitForDefn ( ObjExpr objx , CljILGen ilg ) => Emit ( RHC . Expression , objx , ilg ) ;
345286
346287 protected override void EmitMethods ( TypeBuilder tb )
347288 {
@@ -354,7 +295,7 @@ protected override void EmitMethods(TypeBuilder tb)
354295 if ( IsVariadic )
355296 EmitGetRequiredArityMethod ( TypeBuilder , _variadicMethod . RequiredArity ) ;
356297
357- List < int > supportedArities = new ( ) ;
298+ List < int > supportedArities = [ ] ;
358299 for ( ISeq s = RT . seq ( Methods ) ; s != null ; s = s . next ( ) )
359300 {
360301 FnMethod method = ( FnMethod ) s . first ( ) ;
0 commit comments