本文整理汇总了C#中clojure.lang.CljCompiler.Ast.CljILGen.MaybeEmitVolatileOp方法的典型用法代码示例。如果您正苦于以下问题:C# CljILGen.MaybeEmitVolatileOp方法的具体用法?C# CljILGen.MaybeEmitVolatileOp怎么用?C# CljILGen.MaybeEmitVolatileOp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clojure.lang.CljCompiler.Ast.CljILGen
的用法示例。
在下文中一共展示了CljILGen.MaybeEmitVolatileOp方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitLocal
internal void EmitLocal(CljILGen ilg, LocalBinding lb)
{
Type primType = lb.PrimitiveType;
if (Closes.containsKey(lb))
{
ilg.Emit(OpCodes.Ldarg_0); // this
FieldBuilder fb = _closedOverFieldsMap[lb];
ilg.MaybeEmitVolatileOp(IsVolatile(lb));
ilg.Emit(OpCodes.Ldfld, fb);
if (primType != null)
HostExpr.EmitBoxReturn(this, ilg, primType);
// TODO: ONCEONLY?
}
else
{
if (lb.IsArg)
{
//int argOffset = IsStatic ? 1 : 0;
//ilg.Emit(OpCodes.Ldarg, lb.Index - argOffset);
ilg.EmitLoadArg(lb.Index);
}
else if (lb.IsThis)
{
ilg.EmitLoadArg(0);
}
else
{
ilg.Emit(OpCodes.Ldloc, lb.LocalVar);
}
if (primType != null)
HostExpr.EmitBoxReturn(this, ilg, primType);
}
}
示例2: EmitUnboxedLocal
internal void EmitUnboxedLocal(CljILGen ilg, LocalBinding lb)
{
if (Closes.containsKey(lb))
{
ilg.Emit(OpCodes.Ldarg_0); // this
FieldBuilder fb = _closedOverFieldsMap[lb];
ilg.MaybeEmitVolatileOp(IsVolatile(lb));
ilg.Emit(OpCodes.Ldfld, fb);
}
else if (lb.IsArg)
{
//int argOffset = IsStatic ? 0 : 1;
//ilg.Emit(OpCodes.Ldarg, lb.Index + argOffset);
ilg.EmitLoadArg(lb.Index);
}
else if (lb.IsThis)
{
ilg.EmitLoadArg(0);
}
else
ilg.Emit(OpCodes.Ldloc, lb.LocalVar);
}
示例3: EmitConstant
internal void EmitConstant(CljILGen ilg, int id, object val)
{
FieldBuilder fb = null;
if ( ConstantFields != null && ConstantFields.TryGetValue(id, out fb))
{
ilg.MaybeEmitVolatileOp(fb);
ilg.Emit(OpCodes.Ldsfld, fb);
}
else
EmitValue(val, ilg);
}
示例4: EmitLetFnInits
internal void EmitLetFnInits(CljILGen ilg, LocalBuilder localBuilder, ObjExpr objx, IPersistentSet letFnLocals)
{
if (_typeBuilder != null)
{
// Full compile
ilg.Emit(OpCodes.Castclass, _typeBuilder);
for (ISeq s = RT.keys(Closes); s != null; s = s.next())
{
LocalBinding lb = (LocalBinding)s.first();
if (letFnLocals.contains(lb))
{
FieldBuilder fb;
_closedOverFieldsMap.TryGetValue(lb, out fb);
Type primt = lb.PrimitiveType;
ilg.Emit(OpCodes.Dup); // this
if (primt != null)
{
objx.EmitUnboxedLocal(ilg, lb);
ilg.MaybeEmitVolatileOp(IsVolatile(lb));
ilg.Emit(OpCodes.Stfld, fb);
}
else
{
objx.EmitLocal(ilg, lb);
ilg.MaybeEmitVolatileOp(IsVolatile(lb));
ilg.Emit(OpCodes.Stfld, fb);
}
}
}
ilg.Emit(OpCodes.Pop);
}
}
示例5: EmitMetaFunctions
private void EmitMetaFunctions(TypeBuilder fnTB)
{
// IPersistentMap meta()
MethodBuilder metaMB = fnTB.DefineMethod("meta", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.ReuseSlot, typeof(IPersistentMap), Type.EmptyTypes);
CljILGen gen = new CljILGen(metaMB.GetILGenerator());
if (SupportsMeta)
{
gen.EmitLoadArg(0);
gen.EmitFieldGet(_metaField);
}
else
gen.EmitNull();
gen.Emit(OpCodes.Ret);
// IObj withMeta(IPersistentMap)
MethodBuilder withMB = fnTB.DefineMethod("withMeta", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.ReuseSlot, typeof(IObj), new Type[] { typeof(IPersistentMap) });
gen = new CljILGen(withMB.GetILGenerator());
if (SupportsMeta)
{
gen.EmitLoadArg(1); // meta arg
foreach (FieldBuilder fb in _closedOverFields)
{
gen.EmitLoadArg(0);
gen.MaybeEmitVolatileOp(fb);
gen.EmitFieldGet(fb);
}
gen.EmitNew(_ctorInfo);
}
else
gen.EmitLoadArg(0); //this
gen.Emit(OpCodes.Ret);
}
示例6: EmitAssignLocal
internal void EmitAssignLocal(CljILGen ilg, LocalBinding lb, Expr val)
{
if (!IsMutable(lb))
throw new ArgumentException("Cannot assign to non-mutable: ", lb.Name);
FieldBuilder fb = null;
bool hasField = _closedOverFieldsMap.TryGetValue(lb, out fb);
ilg.Emit(OpCodes.Ldarg_0); // this
Type primt = lb.PrimitiveType;
if (primt != null)
{
MaybePrimitiveExpr mbe = val as MaybePrimitiveExpr;
if (!(mbe != null && mbe.CanEmitPrimitive))
throw new ArgumentException("Must assign primitive to primitive mutable", lb.Name);
mbe.EmitUnboxed(RHC.Expression, this, ilg);
}
else
{
val.Emit(RHC.Expression, this, ilg);
}
if (hasField)
{
ilg.MaybeEmitVolatileOp(IsVolatile(lb));
ilg.Emit(OpCodes.Stfld, fb);
}
else
ilg.Emit(OpCodes.Stloc, lb.LocalVar);
}
示例7: EmitExposers
private static void EmitExposers(TypeBuilder proxyTB, Type superClass, IPersistentMap exposesFields)
{
for ( ISeq s = RT.seq(exposesFields); s != null; s = s.next() )
{
IMapEntry me = (IMapEntry)s.first();
Symbol protectedFieldSym = (Symbol)me.key();
IPersistentMap accessMap = (IPersistentMap)me.val();
string fieldName = protectedFieldSym.Name;
Symbol getterSym = (Symbol)accessMap.valAt(_getKw, null);
Symbol setterSym = (Symbol)accessMap.valAt(_setKW, null);
FieldInfo fld = null;
if ( getterSym != null || setterSym != null )
fld = superClass.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Instance);
if (getterSym != null)
{
MethodAttributes attribs = MethodAttributes.Public;
if (fld.IsStatic)
attribs |= MethodAttributes.Static;
MethodBuilder mb = proxyTB.DefineMethod(getterSym.Name, attribs, fld.FieldType, Type.EmptyTypes);
CljILGen gen = new CljILGen(mb.GetILGenerator());
//if (fld.IsStatic)
// gen.Emit(OpCodes.Ldsfld, fld);
//else
//{
// gen.Emit(OpCodes.Ldarg_0);
// gen.Emit(OpCodes.Ldfld, fld);
//}
if (!fld.IsStatic)
gen.EmitLoadArg(0);
gen.MaybeEmitVolatileOp(fld);
gen.EmitFieldGet(fld);
gen.Emit(OpCodes.Ret);
}
if (setterSym != null)
{
MethodAttributes attribs = MethodAttributes.Public;
if (fld.IsStatic)
attribs |= MethodAttributes.Static;
MethodBuilder mb = proxyTB.DefineMethod(setterSym.Name, attribs, typeof(void), new Type[] { fld.FieldType });
CljILGen gen = new CljILGen(mb.GetILGenerator());
if (fld.IsStatic)
{
gen.Emit(OpCodes.Ldarg_0);
//gen.Emit(OpCodes.Stsfld, fld);
}
else
{
gen.Emit(OpCodes.Ldarg_0);
gen.Emit(OpCodes.Ldarg_1);
//gen.Emit(OpCodes.Stfld, fld);
}
gen.MaybeEmitVolatileOp(fld);
gen.EmitFieldSet(fld);
gen.Emit(OpCodes.Ret);
}
}
}
示例8: EmitConstructor
private ConstructorBuilder EmitConstructor(TypeBuilder fnTB, Type baseType)
{
ConstructorBuilder cb = fnTB.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, CtorTypes());
CljILGen gen = new CljILGen(cb.GetILGenerator());
GenContext.EmitDebugInfo(gen, SpanMap);
//Call base constructor
ConstructorInfo baseCtorInfo = baseType.GetConstructor(BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.Public,null,Type.EmptyTypes,null);
if (baseCtorInfo == null)
throw new InvalidOperationException("Unable to find default constructor for " + baseType.FullName);
gen.EmitLoadArg(0);
gen.Emit(OpCodes.Call, baseCtorInfo);
// Store Meta
if (SupportsMeta)
{
gen.EmitLoadArg(0);
gen.EmitLoadArg(1);
gen.Emit(OpCodes.Castclass, typeof(IPersistentMap));
gen.EmitFieldSet(_metaField);
}
// store closed-overs in their fields
int a = 0;
int offset = !SupportsMeta ? 1 : 2;
for (ISeq s = RT.keys(Closes); s != null; s = s.next(), a++)
{
//LocalBinding lb = (LocalBinding)s.first();
FieldBuilder fb = _closedOverFields[a];
bool isVolatile = IsVolatile(_closedOverFieldsToBindingsMap[fb]);
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
gen.EmitLoadArg(a + offset); // gen.Emit(OpCodes.Ldarg, a + 1);
gen.MaybeEmitVolatileOp(isVolatile);
gen.Emit(OpCodes.Stfld, fb);
}
gen.Emit(OpCodes.Ret);
return cb;
}
示例9: DefineBaseClassClosedOverConstructors
private void DefineBaseClassClosedOverConstructors(Type super, TypeBuilder tb)
{
// ctor that takes closed-overs and does nothing
if (CtorTypes().Length > 0)
{
ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis,CtorTypes());
CljILGen ilg = new CljILGen(cb.GetILGenerator());
ilg.EmitLoadArg(0);
ilg.Emit(OpCodes.Call, super.GetConstructor(Type.EmptyTypes));
// store closed-overs in their fields
int a = 0;
for (ISeq s = RT.keys(Closes); s != null; s = s.next(), a++)
{
FieldBuilder fb = ClosedOverFields[a];
bool isVolatile = IsVolatile(ClosedOverFieldsToBindingsMap[fb]);
ilg.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
ilg.EmitLoadArg(a + 1); // gen.Emit(OpCodes.Ldarg, a + 1);
ilg.MaybeEmitVolatileOp(isVolatile);
ilg.Emit(OpCodes.Stfld, fb);
}
ilg.Emit(OpCodes.Ret);
if (AltCtorDrops > 0)
{
Type[] ctorTypes = CtorTypes();
int newLen = ctorTypes.Length - AltCtorDrops;
if (newLen > 0)
{
Type[] altCtorTypes = new Type[newLen];
for (int i = 0; i < altCtorTypes.Length; i++)
altCtorTypes[i] = ctorTypes[i];
ConstructorBuilder cb2 = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, altCtorTypes);
CljILGen ilg2 = new CljILGen(cb2.GetILGenerator());
ilg2.EmitLoadArg(0);
for (int i = 0; i < newLen; i++)
ilg2.EmitLoadArg(i + 1);
for (int i = 0; i < AltCtorDrops; i++)
ilg2.EmitNull();
ilg2.Emit(OpCodes.Call, cb);
ilg2.Emit(OpCodes.Ret);
}
}
}
}
示例10: LightEmit
void LightEmit(RHC rhc, ObjExpr objx, CljILGen ilg)
{
//emitting a Fn means constructing an instance, feeding closed-overs from enclosing scope, if any
//objx arg is enclosing objx, not this
// Create the function instance
LocalBuilder fnLocal = ilg.DeclareLocal(CompiledType);
if (CompiledType == typeof(RestFnImpl))
{
ilg.EmitInt(_variadicMethod.RequiredArity);
ilg.EmitNew(Compiler.Ctor_RestFnImpl_1);
}
else
{
ilg.EmitNew(Compiler.Ctor_AFnImpl);
}
ilg.Emit(OpCodes.Stloc, fnLocal);
//ilg.EmitString(String.Format("Creating fn {0}", Name));
//ilg.Emit(OpCodes.Call, typeof(System.Console).GetMethod("WriteLine", new Type[] { typeof(string) }));
// Set up the methods
for (ISeq s = RT.seq(_methods); s != null; s = s.next())
{
FnMethod method = (FnMethod)s.first();
int key = GetMethodKey(method);
string fieldName = IsVariadic && method.IsVariadic
? "_fnDo" + (key - 1) // because key is arity+1 for variadic
: "_fn" + key;
FieldInfo fi = CompiledType.GetField(fieldName);
ilg.Emit(OpCodes.Ldloc, fnLocal);
EmitGetDynMethod(key, ilg);
ilg.EmitType(fi.FieldType);
ilg.Emit(OpCodes.Ldloc, fnLocal);
ilg.Emit(OpCodes.Callvirt, Method_DynamicMethod_CreateDelegate);
ilg.Emit(OpCodes.Castclass, fi.FieldType);
ilg.MaybeEmitVolatileOp(fi);
ilg.EmitFieldSet(fi);
}
// setup the constants and locals
ilg.Emit(OpCodes.Ldloc, fnLocal);
if (Constants.count() > 0)
{
EmitGetCompiledConstants(ilg);
}
else
{
ilg.EmitInt(0);
ilg.EmitArray(typeof(Object[]));
}
if (Closes.count() > 0)
{
int maxIndex = Closes.Max(c => ((LocalBinding)c.key()).Index);
ilg.EmitInt(maxIndex + 1);
ilg.Emit(OpCodes.Newarr, typeof(object));
for (ISeq s = RT.keys(Closes); s != null; s = s.next())
{
LocalBinding lb = (LocalBinding)s.first();
ilg.Emit(OpCodes.Dup);
ilg.EmitInt(lb.Index);
objx.EmitLocal(ilg, lb);
ilg.EmitStoreElement(typeof(object));
}
}
else
{
ilg.EmitInt(0);
ilg.EmitArray(typeof(Object[]));
}
// Create the closure
ilg.EmitNew(Compiler.Ctor_Closure_2);
// Assign the clojure
ilg.EmitCall(Compiler.Method_IFnClosure_SetClosure);
// Leave the instance on the stack.
ilg.Emit(OpCodes.Ldloc, fnLocal);
}
示例11: EmitUnboxedLocal
internal void EmitUnboxedLocal(CljILGen ilg, LocalBinding lb)
{
if (Closes.containsKey(lb))
{
if (_fnMode == FnMode.Full)
{
ilg.Emit(OpCodes.Ldarg_0); // this
FieldBuilder fb = _closedOverFieldsMap[lb];
ilg.MaybeEmitVolatileOp(IsVolatile(lb));
ilg.Emit(OpCodes.Ldfld, fb);
}
else
{
ilg.Emit(OpCodes.Ldarg_0); // this
ilg.Emit(OpCodes.Castclass, typeof(IFnClosure));
ilg.EmitCall(Compiler.Method_IFnClosure_GetClosure);
ilg.EmitFieldGet(Compiler.Field_Closure_Locals);
ilg.EmitInt(lb.Index);
ilg.EmitLoadElement(typeof(Object));
if (lb.PrimitiveType != null)
ilg.Emit(OpCodes.Unbox, lb.PrimitiveType);
}
}
else if (lb.IsArg)
{
//int argOffset = IsStatic ? 0 : 1;
//ilg.Emit(OpCodes.Ldarg, lb.Index + argOffset);
ilg.EmitLoadArg(lb.Index);
}
else if (lb.IsThis)
{
ilg.EmitLoadArg(0);
}
else
ilg.Emit(OpCodes.Ldloc, lb.LocalVar);
}
示例12: EmitLocal
internal void EmitLocal(CljILGen ilg, LocalBinding lb)
{
Type primType = lb.PrimitiveType;
if (Closes.containsKey(lb))
{
if (_fnMode == FnMode.Full)
{
ilg.Emit(OpCodes.Ldarg_0); // this
FieldBuilder fb = _closedOverFieldsMap[lb];
ilg.MaybeEmitVolatileOp(IsVolatile(lb));
ilg.Emit(OpCodes.Ldfld, fb);
if (primType != null)
HostExpr.EmitBoxReturn(this, ilg, primType);
// TODO: ONCEONLY?
}
else // FnMode.Light
{
ilg.Emit(OpCodes.Ldarg_0); // this
ilg.Emit(OpCodes.Castclass, typeof(IFnClosure));
ilg.EmitCall(Compiler.Method_IFnClosure_GetClosure);
ilg.EmitFieldGet(Compiler.Field_Closure_Locals);
ilg.EmitInt(lb.Index);
ilg.EmitLoadElement(typeof(Object));
}
}
else
{
if (lb.IsArg)
{
//int argOffset = IsStatic ? 1 : 0;
//ilg.Emit(OpCodes.Ldarg, lb.Index - argOffset);
ilg.EmitLoadArg(lb.Index);
}
else if (lb.IsThis)
{
ilg.EmitLoadArg(0);
}
else
{
ilg.Emit(OpCodes.Ldloc, lb.LocalVar);
}
if (primType != null)
HostExpr.EmitBoxReturn(this, ilg, primType);
}
}
示例13: EmitConstant
internal void EmitConstant(CljILGen ilg, int id, object val)
{
if (_fnMode == Ast.FnMode.Light)
{
if (val == null)
{
ilg.EmitNull();
}
if (val.GetType().IsPrimitive)
{
EmitPrimitive(ilg, val);
ilg.Emit(OpCodes.Box,val.GetType());
}
else
{
ilg.Emit(OpCodes.Ldarg_0); // this
ilg.Emit(OpCodes.Castclass, typeof(IFnClosure));
ilg.EmitCall(Compiler.Method_IFnClosure_GetClosure);
ilg.EmitFieldGet(Compiler.Field_Closure_Constants);
ilg.EmitInt(id);
ilg.EmitLoadElement(typeof(Object));
ilg.Emit(OpCodes.Castclass, ConstantType(id));
}
}
else
{
FieldBuilder fb = null;
if (_fnMode == FnMode.Full && ConstantFields != null && ConstantFields.TryGetValue(id, out fb))
{
ilg.MaybeEmitVolatileOp(fb);
ilg.Emit(OpCodes.Ldsfld, fb);
}
else
EmitValue(val, ilg);
}
}