|
12 | 12 | * Author: David Miller |
13 | 13 | **/ |
14 | 14 |
|
| 15 | +using clojure.lang.CljCompiler.Context; |
15 | 16 | using System; |
16 | 17 | using System.Collections.Generic; |
17 | 18 | using System.Reflection; |
@@ -85,8 +86,16 @@ public static Expr Parse(Var v, ISeq args, object tag) |
85 | 86 | Type target = v.get().GetType(); |
86 | 87 |
|
87 | 88 | { |
88 | | - var directLinkMap = Compiler.DirectLinkingMapVar.deref() as Dictionary<Var, Type>; |
89 | | - if (directLinkMap != null && directLinkMap.TryGetValue(v, out Type t)) |
| 89 | + // DirectLinkingMap only contains Var -> Type mappings for Types that have been compiled. |
| 90 | + // That is, types that are residing in a PersistedAssemblyBuilder. |
| 91 | + // We do not want to direct link to if we going into a non-PersistedAssemblyBuilder assembly -- |
| 92 | + // this throws an exception when generating the method call IL in the StaticInvokeExpr.Emit |
| 93 | + |
| 94 | + if ( Compiler.IsCompiling && |
| 95 | + Compiler.DirectLinkingMapVar.deref() is Dictionary<Var, Type> directLinkMap && |
| 96 | + Compiler.CompilerContextVar.deref() is GenContext context && |
| 97 | + ! GenContext.IsInternalAssembly(context.AssemblyBuilder) && |
| 98 | + directLinkMap.TryGetValue(v, out Type t)) |
90 | 99 | { |
91 | 100 | if (t != null) |
92 | 101 | target = t; |
@@ -183,11 +192,19 @@ public void EmitUnboxed(RHC rhc, ObjExpr objx, CljILGen ilg) |
183 | 192 | else |
184 | 193 | MethodExpr.EmitTypedArgs(objx, ilg, _method.GetParameters(), _args); |
185 | 194 |
|
186 | | - Console.WriteLine($"{_method.DeclaringType.FullName} . {_method.Name}, {_method.ToString()}"); |
187 | | - ilg.EmitCall(_method); |
| 195 | + |
| 196 | + //ilg.EmitCall(_method); |
| 197 | + if (_method.IsVirtual) |
| 198 | + { |
| 199 | + ilg.Emit(OpCodes.Callvirt, _method); |
| 200 | + } |
| 201 | + else |
| 202 | + { |
| 203 | + ilg.Emit(OpCodes.Call, _method); |
| 204 | + } |
188 | 205 | } |
189 | 206 |
|
190 | | - #endregion |
| 207 | +#endregion |
191 | 208 |
|
192 | 209 | #region MaybePrimitiveExpr Members |
193 | 210 |
|
|
0 commit comments