static public void EmitDynamicCallPreamble(DynamicExpression dyn, IPersistentMap spanMap, string methodName, Type returnType, List <ParameterExpression> paramExprs, Type[] paramTypes, CljILGen ilg, out LambdaExpression lambda, out Type delType, out MethodBuilder mbLambda)
{
Expression call = dyn;
GenContext context = Compiler.CompilerContextVar.deref() as GenContext;
if (context != null && context.DynInitHelper != null)
{
call = context.DynInitHelper.ReduceDyn(dyn);
}
if (returnType == typeof(void))
{
call = Expression.Block(call, Expression.Default(typeof(object)));
returnType = typeof(object);
}
else if (returnType != call.Type)
{
call = Expression.Convert(call, returnType);
}
call = GenContext.AddDebugInfo(call, spanMap);
delType = Microsoft.Scripting.Generation.Snippets.Shared.DefineDelegate("__interop__", returnType, paramTypes);
lambda = Expression.Lambda(delType, call, paramExprs);
mbLambda = null;
if (context == null)
{
// light compile
Delegate d = lambda.Compile();
int key = RT.nextID();
CacheDelegate(key, d);
ilg.EmitInt(key);
ilg.Emit(OpCodes.Call, Method_MethodExpr_GetDelegate);
ilg.Emit(OpCodes.Castclass, delType);
}
else
{
mbLambda = context.TB.DefineMethod(methodName, MethodAttributes.Static | MethodAttributes.Public, CallingConventions.Standard, returnType, paramTypes);
lambda.CompileToMethod(mbLambda);
}
}