@@ -193,7 +193,8 @@ internal static int ColumnVarDeref()
193193
194194 internal static readonly Var CompilerContextVar = Var . create ( null ) . setDynamic ( ) ;
195195 internal static readonly Var CompilerActiveVar = Var . create ( false ) . setDynamic ( ) ;
196-
196+ internal static readonly Var DirectLinkingMapVar = Var . create ( null ) . setDynamic ( ) ;
197+
197198 public static Var CompilerOptionsVar ;
198199
199200 public static object GetCompilerOption ( Keyword k )
@@ -1687,7 +1688,8 @@ public static object Compile(GenContext context,TextReader rdr, string sourceDir
16871688 RT . WarnOnReflectionVar , RT . WarnOnReflectionVar . deref ( ) ,
16881689 RT . DataReadersVar , RT . DataReadersVar . deref ( ) ,
16891690 CompilerContextVar , context ,
1690- CompilerActiveVar , true
1691+ CompilerActiveVar , true ,
1692+ DirectLinkingMapVar , new Dictionary < Var , Type > ( )
16911693 ) ) ;
16921694
16931695 try
@@ -1772,7 +1774,17 @@ private static void Compile1(TypeBuilder tb, CljILGen ilg, ObjExpr objx, object
17721774 objx . EmitConstantFieldDefs ( tb ) ;
17731775 expr . Emit ( RHC . Expression , objx , ilg ) ;
17741776 ilg . Emit ( OpCodes . Pop ) ;
1777+
1778+ if ( expr is DefExpr dex && dex . Init is FnExpr fnx )
1779+ {
1780+ ( ( Dictionary < Var , Type > ) DirectLinkingMapVar . deref ( ) ) [ dex . Var ] = fnx . CompiledType ;
1781+ }
1782+
1783+ #if NET9_0_OR_GREATER
1784+ DoSeparateEval ( evPC , form ) ;
1785+ #else
17751786 expr . Eval ( ) ;
1787+ #endif
17761788 }
17771789 }
17781790 finally
@@ -1781,8 +1793,40 @@ private static void Compile1(TypeBuilder tb, CljILGen ilg, ObjExpr objx, object
17811793 }
17821794 }
17831795
1796+ private static void DoSeparateEval ( ParserContext evPC , Object form )
1797+ {
1798+ // Reset the environment to avoid leaking the compile environment
1799+
1800+ Var . pushThreadBindings ( RT . mapUniqueKeys (
1801+ MethodVar , null ,
1802+ LocalEnvVar , null ,
1803+ LoopLocalsVar , null ,
1804+ NextLocalNumVar , 0 ,
1805+ //RT.ReadEvalVar, true /* RT.T */,
1806+ //RT.CurrentNSVar, RT.CurrentNSVar.deref(), Do not reset this -- we need to see changes to this that might happen, e.g. with (ns ..) or (in-ns ...) calls
1807+ ConstantsVar , PersistentVector . EMPTY ,
1808+ ConstantIdsVar , new IdentityHashMap ( ) ,
1809+ KeywordsVar , PersistentHashMap . EMPTY ,
1810+ VarsVar , PersistentHashMap . EMPTY ,
1811+ //RT.UncheckedMathVar, RT.UncheckedMathVar.deref(),
1812+ //RT.WarnOnReflectionVar, RT.WarnOnReflectionVar.deref(),
1813+ //RT.DataReadersVar, RT.DataReadersVar.deref(),
1814+ CompilerContextVar , null ,
1815+ CompilerActiveVar , false ,
1816+ DirectLinkingMapVar , null // we do not want to have the evaluated version try to direct link to functions in the compile assembly
1817+ ) ) ;
1818+ try
1819+ {
1820+ Compiler . eval ( form ) ;
1821+ }
1822+ finally
1823+ {
1824+ Var . popThreadBindings ( ) ;
1825+ }
1826+ }
1827+
17841828 #endregion
1785-
1829+
17861830 #region Loading
17871831
17881832 internal static void LoadAssembly ( FileInfo assyInfo , string relativePath )
0 commit comments