本文整理汇总了C#中clojure.lang.CljCompiler.Ast.CljILGen.EmitString方法的典型用法代码示例。如果您正苦于以下问题:C# CljILGen.EmitString方法的具体用法?C# CljILGen.EmitString怎么用?C# CljILGen.EmitString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clojure.lang.CljCompiler.Ast.CljILGen
的用法示例。
在下文中一共展示了CljILGen.EmitString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitValue
protected void EmitValue(object value, CljILGen ilg)
{
bool partial = true;
if (value == null)
ilg.Emit(OpCodes.Ldnull);
else if (value is String)
ilg.Emit(OpCodes.Ldstr, (String)value);
else if (value is Boolean)
{
ilg.EmitBoolean((Boolean)value);
ilg.Emit(OpCodes.Box,typeof(bool));
}
else if (value is Int32)
{
ilg.EmitInt((int)value);
ilg.Emit(OpCodes.Box, typeof(int));
}
else if (value is Int64)
{
ilg.EmitLong((long)value);
ilg.Emit(OpCodes.Box, typeof(long));
}
else if (value is Double)
{
ilg.EmitDouble((double)value);
ilg.Emit(OpCodes.Box, typeof(double));
}
else if (value is Char)
{
ilg.EmitChar((char)value);
ilg.Emit(OpCodes.Box,typeof(char));
}
else if (value is Type)
{
Type t = (Type)value;
if (t.IsValueType)
ilg.EmitType(t);
else
{
//ilg.EmitString(Compiler.DestubClassName(((Type)value).FullName));
ilg.EmitString(((Type)value).FullName);
ilg.EmitCall(Compiler.Method_RT_classForName);
}
}
else if (value is Symbol)
{
Symbol sym = (Symbol)value;
if (sym.Namespace == null)
ilg.EmitNull();
else
ilg.EmitString(sym.Namespace);
ilg.EmitString(sym.Name);
ilg.EmitCall(Compiler.Method_Symbol_intern2);
}
else if (value is Keyword)
{
Keyword keyword = (Keyword)value;
if (keyword.Namespace == null)
ilg.EmitNull();
else
ilg.EmitString(keyword.Namespace);
ilg.EmitString(keyword.Name);
ilg.EmitCall(Compiler.Method_RT_keyword);
}
else if (value is Var)
{
Var var = (Var)value;
ilg.EmitString(var.Namespace.Name.ToString());
ilg.EmitString(var.Symbol.Name.ToString());
ilg.EmitCall(Compiler.Method_RT_var2);
}
else if (value is IType)
{
IPersistentVector fields = (IPersistentVector)Reflector.InvokeStaticMethod(value.GetType(), "getBasis", Type.EmptyTypes);
for (ISeq s = RT.seq(fields); s != null; s = s.next())
{
Symbol field = (Symbol)s.first();
Type k = Compiler.TagType(Compiler.TagOf(field));
object val = Reflector.GetInstanceFieldOrProperty(value, field.Name);
EmitValue(val, ilg);
if (k.IsPrimitive)
{
ilg.Emit(OpCodes.Castclass, k);
}
}
ConstructorInfo cinfo = value.GetType().GetConstructors()[0];
ilg.EmitNew(cinfo);
}
else if (value is IRecord)
{
//MethodInfo[] minfos = value.GetType().GetMethods(BindingFlags.Static | BindingFlags.Public);
EmitValue(PersistentArrayMap.create((IDictionary)value), ilg);
MethodInfo createMI = value.GetType().GetMethod("create", BindingFlags.Static | BindingFlags.Public, null, CallingConventions.Standard, new Type[] { typeof(IPersistentMap) }, null);
ilg.EmitCall(createMI);
}
//.........这里部分代码省略.........
示例2: EmitUnsupported
private static void EmitUnsupported(CljILGen gen, string name)
{
gen.EmitString(name); // gen.Emit(OpCodes.Ldstr, name);
gen.EmitNew(CtorInfo_NotImplementedException_1); // gen.Emit(OpCodes.Newobj, CtorInfo_NotImplementedException_1);
gen.Emit(OpCodes.Throw);
}
示例3: GenerateProxyMethod
private static void GenerateProxyMethod(
TypeBuilder proxyTB,
FieldBuilder mapField,
MethodInfo m,
HashSet<MethodBuilder> specialMethods)
{
MethodAttributes attribs = m.Attributes;
bool callBaseMethod;
if ( (attribs & MethodAttributes.Abstract) == MethodAttributes.Abstract )
{
attribs &= ~MethodAttributes.Abstract;
callBaseMethod = false;
}
else
{
callBaseMethod = true;
}
attribs &= ~MethodAttributes.NewSlot;
attribs |= MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.Public;
//Console.Write("Generating proxy method {0}(", m.Name);
//foreach (ParameterInfo p in m.GetParameters())
// Console.Write("{0}, ", p.ParameterType.FullName);
//Console.Write(") ");
//Console.WriteLine(attribs.ToString());
MethodBuilder proxym = proxyTB.DefineMethod(
m.Name,
attribs,
m.CallingConvention,
m.ReturnType,
m.GetParameters().Select<ParameterInfo, Type>(p => p.ParameterType).ToArray<Type>());
if (m.IsSpecialName)
specialMethods.Add(proxym);
CljILGen gen = new CljILGen(proxym.GetILGenerator());
Label elseLabel = gen.DefineLabel();
Label endLabel = gen.DefineLabel();
//// Print a little message, for debugging purposes
//gen.Emit(OpCodes.Ldstr, String.Format("Calling {0} / {1}", proxyTB.FullName, m.ToString()));
//gen.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine",
// new Type[] { typeof(string) }));
//gen.Emit(OpCodes.Call, typeof(Console).GetMethod("get_Out"));
//gen.Emit(OpCodes.Call, typeof(System.IO.TextWriter).GetMethod("Flush"));
// Lookup method name in map
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
gen.EmitFieldGet(mapField); // gen.Emit(OpCodes.Ldfld, mapField);
gen.EmitString(m.Name); // gen.Emit(OpCodes.Ldstr, m.Name);
gen.EmitCall(Method_RT_get); // gen.Emit(OpCodes.Call, Method_RT_get);
gen.Emit(OpCodes.Dup);
gen.EmitNull(); // gen.Emit(OpCodes.Ldnull);
gen.Emit(OpCodes.Beq_S, elseLabel);
// map entry found
ParameterInfo[] pinfos = m.GetParameters();
gen.Emit(OpCodes.Castclass, typeof(IFn));
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0); // push implicit 'this' arg.
for (int i = 0; i < pinfos.Length; i++)
{
gen.EmitLoadArg(i + 1); // gen.Emit(OpCodes.Ldarg, i + 1);
if (m.GetParameters()[i].ParameterType.IsValueType)
gen.Emit(OpCodes.Box,pinfos[i].ParameterType);
}
int parmCount = pinfos.Length;
gen.EmitCall(GetIFnInvokeMethodInfo(parmCount+1)); // gen.Emit(OpCodes.Call, GetIFnInvokeMethodInfo(parmCount + 1));
if (m.ReturnType == typeof(void))
gen.Emit(OpCodes.Pop);
else
gen.Emit(OpCodes.Unbox_Any, m.ReturnType);
gen.Emit(OpCodes.Br_S,endLabel);
// map entry not found
gen.MarkLabel(elseLabel);
gen.Emit(OpCodes.Pop); // get rid of null leftover from the 'get'
if ( callBaseMethod )
{
gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0);
for (int i = 0; i < parmCount; i++)
gen.EmitLoadArg(i + 1); // gen.Emit(OpCodes.Ldarg, i + 1);
gen.Emit(OpCodes.Call, m); // gen.EmitCall(m) improperly emits a callvirt in some cases
}
else
{
gen.EmitString(m.Name); // gen.Emit(OpCodes.Ldstr, m.Name);
gen.EmitNew(CtorInfo_NotImplementedException_1); // gen.Emit(OpCodes.Newobj, CtorInfo_NotImplementedException_1);
gen.Emit(OpCodes.Throw);
}
gen.MarkLabel(endLabel);
//.........这里部分代码省略.........
示例4: DefineStaticCtor
/// <summary>
/// Set up Var fields and (maybe) load assembly for the namespace.
/// </summary>
/// <param name="proxyTB"></param>
/// <param name="varMap"></param>
/// <param name="loadImplNameSpace"></param>
/// <param name="implNamespace"></param>
private static void DefineStaticCtor(TypeBuilder proxyTB, string prefix, Dictionary<string, FieldBuilder> varMap, bool loadImplNameSpace, string implNamespace, string implCname)
{
ConstructorBuilder cb = proxyTB.DefineConstructor(MethodAttributes.Static, CallingConventions.Standard,Type.EmptyTypes);
CljILGen gen = new CljILGen(cb.GetILGenerator());
foreach (KeyValuePair<string, FieldBuilder> pair in varMap)
{
gen.EmitString(implNamespace); // gen.Emit(OpCodes.Ldstr, implNamespace);
gen.EmitString(prefix + pair.Key); // gen.Emit(OpCodes.Ldstr, prefix + pair.Key);
gen.EmitCall(Method_Var_internPrivate); // gen.Emit(OpCodes.Call, Method_Var_internPrivate);
gen.Emit(OpCodes.Stsfld, pair.Value);
}
if (loadImplNameSpace)
{
gen.EmitString("clojure.core"); // gen.Emit(OpCodes.Ldstr, "clojure.core");
gen.EmitString("load"); // gen.Emit(OpCodes.Ldstr, "load");
gen.EmitCall(Method_RT_var2); // gen.Emit(OpCodes.Call, Method_RT_var2);
gen.EmitString("/" + implCname); // gen.Emit(OpCodes.Ldstr, "/" + implCname);
gen.EmitCall(Compiler.Methods_IFn_invoke[1]); // gen.Emit(OpCodes.Call, Compiler.Methods_IFn_invoke[1]);
gen.Emit(OpCodes.Pop);
}
gen.Emit(OpCodes.Ret);
}
示例5: EmitLoadNsInitForDeftype
private void EmitLoadNsInitForDeftype(CljILGen ilg)
{
string nsname = ((Symbol)RT.second(_src)).Namespace;
if ( !nsname.Equals("clojure.core"))
{
ilg.EmitString("clojure.core");
ilg.EmitString("require");
ilg.EmitCall(Compiler.Method_RT_var2);
ilg.EmitCall(Compiler.Method_Var_getRawRoot);
ilg.Emit(OpCodes.Castclass, typeof(IFn));
ilg.EmitNull();
ilg.EmitString(nsname);
ilg.EmitCall(Compiler.Method_Symbol_intern2);
ilg.EmitCall(Compiler.Methods_IFn_invoke[1]);
ilg.Emit(OpCodes.Pop);
}
}
示例6: EmitStatics
protected override void EmitStatics(TypeBuilder tb)
{
if (IsDefType)
{
// getBasis()
{
MethodBuilder mbg = tb.DefineMethod("getBasis", MethodAttributes.Public | MethodAttributes.Static, typeof(IPersistentVector), Type.EmptyTypes);
CljILGen ilg = new CljILGen(mbg.GetILGenerator());
EmitValue(HintedFields, ilg);
ilg.Emit(OpCodes.Ret);
}
if (Fields.count() > HintedFields.count())
{
// create(IPersistentMap)
MethodBuilder mbc = tb.DefineMethod("create", MethodAttributes.Public | MethodAttributes.Static, tb, new Type[] { typeof(IPersistentMap) });
CljILGen gen = new CljILGen(mbc.GetILGenerator());
LocalBuilder kwLocal = gen.DeclareLocal(typeof(Keyword));
List<LocalBuilder> locals = new List<LocalBuilder>();
for (ISeq s = RT.seq(HintedFields); s != null; s = s.next())
{
string bName = ((Symbol)s.first()).Name;
Type t = Compiler.TagType(Compiler.TagOf(s.first()));
// local_kw = Keyword.intern(bname)
// local_i = arg_0.valAt(kw,null)
gen.EmitLoadArg(0);
gen.EmitString(bName);
gen.EmitCall(Compiler.Method_Keyword_intern_string);
gen.Emit(OpCodes.Dup);
gen.Emit(OpCodes.Stloc, kwLocal.LocalIndex);
gen.EmitNull();
gen.EmitCall(Compiler.Method_IPersistentMap_valAt2);
LocalBuilder lb = gen.DeclareLocal(t);
locals.Add(lb);
if (t.IsPrimitive)
gen.EmitUnbox(t);
gen.Emit(OpCodes.Stloc, lb.LocalIndex);
// arg_0 = arg_0.without(local_kw);
gen.EmitLoadArg(0);
gen.Emit(OpCodes.Ldloc, kwLocal.LocalIndex);
gen.EmitCall(Compiler.Method_IPersistentMap_without);
gen.EmitStoreArg(0);
}
foreach (LocalBuilder lb in locals)
gen.Emit(OpCodes.Ldloc, lb.LocalIndex);
gen.EmitNull();
gen.EmitLoadArg(0);
gen.EmitCall(Compiler.Method_RT_seqOrElse);
gen.EmitNew(CtorInfo);
gen.Emit(OpCodes.Ret);
}
}
}
示例7: Emit
public override void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
{
if (rhc != RHC.Statement)
ilg.EmitString(_str);
}
示例8: EmitProtoLight
// TODO: Eliminate common code between EmitProtoLight and EmitProtoFull
void EmitProtoLight(RHC rhc, ObjExpr objx, CljILGen ilg)
{
Label endLabel = ilg.DefineLabel();
Var v = ((VarExpr)_fexpr).Var;
Expr e = (Expr)_args.nth(0);
e.Emit(RHC.Expression, objx, ilg); // target
LocalBuilder targetTemp = ilg.DeclareLocal(typeof(Object));
GenContext.SetLocalName(targetTemp, "target");
ilg.Emit(OpCodes.Stloc, targetTemp); // (targetTemp <= target)
ilg.EmitString(String.Format("In Light Proto for {0}",v.Symbol.ToString()));
ilg.Emit(OpCodes.Call,typeof(Console).GetMethod("WriteLine",new Type[] { typeof(string) }));
//if (_protocolOn != null)
//{
// ilg.Emit(OpCodes.Ldloc, targetTemp); // target
// ilg.Emit(OpCodes.Isinst, _protocolOn); // (target or null)
// ilg.Emit(OpCodes.Ldnull); // (target or null), null
// ilg.Emit(OpCodes.Cgt_Un); // (0 or 1)
// ilg.Emit(OpCodes.Brtrue, onLabel);
//}
objx.EmitVar(ilg, v); // var
ilg.Emit(OpCodes.Call, Compiler.Method_Var_getRawRoot); // proto-fn
ilg.Emit(OpCodes.Dup);
ilg.Emit(OpCodes.Call, typeof(Object).GetMethod("GetType"));
ilg.Emit(OpCodes.Callvirt, typeof(Object).GetMethod("ToString"));
ilg.EmitString("Expected AFunction, got ");
ilg.Emit(OpCodes.Call, typeof(Console).GetMethod("Write", new Type[] { typeof(String) }));
ilg.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }));
ilg.Emit(OpCodes.Castclass, typeof(AFunction));
ilg.EmitString("Castclass worked ");
ilg.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }));
ilg.Emit(OpCodes.Ldloc, targetTemp); // proto-fn, target
EmitArgsAndCall(1, rhc, objx, ilg);
ilg.EmitString("gen'd args and called");
ilg.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }));
ilg.Emit(OpCodes.Br, endLabel);
//ilg.MarkLabel(onLabel);
//ilg.Emit(OpCodes.Ldloc, targetTemp); // target
//if (_protocolOn != null)
//{
// ilg.Emit(OpCodes.Castclass, _protocolOn);
// MethodExpr.EmitTypedArgs(objx, ilg, _onMethod.GetParameters(), RT.subvec(_args, 1, _args.count()));
// //if (rhc == RHC.Return)
// //{
// // ObjMethod2 method = (ObjMethod)Compiler.MethodVar.deref();
// // method.EmitClearLocals(context);
// //}
// ilg.Emit(OpCodes.Callvirt,_onMethod);
// HostExpr.EmitBoxReturn(objx, ilg, _onMethod.ReturnType);
//}
ilg.MarkLabel(endLabel);
}