本文整理汇总了C#中CodeGen.EmitPosition方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGen.EmitPosition方法的具体用法?C# CodeGen.EmitPosition怎么用?C# CodeGen.EmitPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGen
的用法示例。
在下文中一共展示了CodeGen.EmitPosition方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
public override void Emit(CodeGen cg)
{
bool eoiused = false;
Label eoi = cg.DefineLabel();
foreach (IfStatementTest t in _tests) {
Label next = cg.DefineLabel();
if (t.Test.Span.IsValid)
{
cg.EmitPosition(t.Test.Start, t.Test.End);
}
t.Test.EmitBranchFalse(cg, next);
t.Body.Emit(cg);
// optimize no else case
if (IsNotIfOrReturn(t.Body))
{
eoiused = true;
cg.Emit(OpCodes.Br, eoi);
}
cg.MarkLabel(next);
}
if (_else != null) {
_else.Emit(cg);
}
if (eoiused)
{
cg.MarkLabel(eoi);
}
}
示例2: Emit
internal override void Emit(CodeGen cg)
{
if (Options.DebugMode) {
cg.EmitPosition(this);
cg.EmitTestTrue(test);
Label endLabel = cg.DefineLabel();
cg.Emit(OpCodes.Brtrue, endLabel);
cg.EmitExprOrNone(message);
cg.EmitConvertFromObject(typeof(string));
cg.EmitCall(typeof(Ops), "AssertionError", new Type[] { typeof(string) });
cg.Emit(OpCodes.Throw);
cg.MarkLabel(endLabel);
}
}
示例3: Emit
internal override void Emit(CodeGen cg)
{
cg.EmitPosition(Start, header);
CodeGen icg = CreateClassMaker(cg);
try {
// emit call to MakeClass(ICallerContext mod, string modName, string name, Tuple bases, IDictionary<object, object> vars)
// ICallerContext mod
cg.EmitModuleInstance();
// string modName (can't pull from context, could be changed)
cg.EmitGetGlobal(SymbolTable.Name);
cg.Emit(OpCodes.Castclass, typeof(string));
// class name
cg.EmitString(name.GetString());
// bases array
cg.EmitObjectArray(bases);
cg.EmitCall(typeof(Ops), "MakeTuple");
// vars
cg.EmitEnvironmentOrNull();
cg.EmitContextOrNull();
cg.EmitCall(icg.MethodInfo);
cg.EmitCall(typeof(Ops), "MakeClass");
// store result to class name
cg.EmitSet(name);
} finally {
icg.Dispose();
}
}
示例4: Emit
internal override void Emit(CodeGen cg)
{
cg.EmitPosition(Start, header);
SignatureInfo sigInfo = GetSignature(cg);
FlowChecker.Check(this);
string mname = name.GetString() + "$f" + counter++;
// create the new method & setup it's locals
CodeGen impl = cg.DefineMethod(mname, typeof(object), sigInfo.ParamTypes, sigInfo.ParamNames);
impl.Names = CodeGen.CreateLocalNamespace(impl);
impl.Context = cg.Context;
for (int arg = sigInfo.HasContext ? 1 : 0; arg < sigInfo.ParamNames.Length; arg++) {
impl.Names.SetSlot(sigInfo.ParamNames[arg], impl.GetArgumentSlot(arg));
}
if (sigInfo.HasContext) {
if (IsClosure) {
impl.StaticLinkSlot = impl.GetArgumentSlot(0);
}
impl.ContextSlot = impl.GetArgumentSlot(0);
impl.ModuleSlot = new PropertySlot(impl.ContextSlot, typeof(ICallerContext).GetProperty("Module"));
}
// then generate the actual method
EmitFunctionImplementation(impl, cg);
impl.Finish();
if (NeedsWrapperMethod()) impl = MakeWrapperMethodN(cg, impl.MethodInfo, sigInfo.HasContext);
// Create instance of the Function? object
Type funcType, targetType;
using (impl) {
GetFunctionType(out funcType, out targetType);
cg.EmitModuleInstance();
cg.EmitString(name.GetString());
cg.EmitDelegate(impl, targetType, sigInfo.ContextSlot);
}
int first = sigInfo.HasContext ? 1 : 0;
// Emit string array (minus the first environment argument)
cg.EmitInt(sigInfo.ParamNames.Length - first);
cg.Emit(OpCodes.Newarr, typeof(string));
for (int i = first; i < sigInfo.ParamNames.Length; i++) {
cg.Emit(OpCodes.Dup);
cg.EmitInt(i - first);
cg.EmitStringOrNull(sigInfo.ParamNames[i].GetString());
cg.Emit(OpCodes.Stelem_Ref);
}
cg.EmitObjectArray(defaults);
if (flags == FunctionAttributes.None) {
cg.Emit(OpCodes.Newobj, funcType.GetConstructor(
new Type[] { typeof(PythonModule), typeof(string), targetType, typeof(string[]), typeof(object[]) }));
} else {
cg.EmitInt((int)flags);
cg.Emit(OpCodes.Newobj, funcType.GetConstructor(
new Type[] { typeof(PythonModule), typeof(string), targetType, typeof(string[]), typeof(object[]), typeof(FunctionAttributes) }));
}
string doc = Body.Documentation;
if (doc != null) {
cg.Emit(OpCodes.Dup);
cg.EmitString(doc);
cg.EmitCall(typeof(PythonFunction).GetProperty("Documentation").GetSetMethod());
}
// update func_code w/ appropriate state.
cg.Emit(OpCodes.Dup);
Slot functionCode = cg.GetLocalTmp(typeof(FunctionCode));
cg.EmitCall(typeof(PythonFunction).GetProperty("FunctionCode").GetGetMethod());
cg.Emit(OpCodes.Castclass, typeof(FunctionCode));
cg.Emit(OpCodes.Dup);
functionCode.EmitSet(cg);
if (IsExternal) {
cg.EmitInt(this.ExternalStart.Line);
} else {
cg.EmitInt(this.Start.Line);
}
cg.EmitCall(typeof(FunctionCode), "SetLineNumber");
functionCode.EmitGet(cg);
if (IsExternal) {
cg.EmitString(ExternalInfo.OriginalFileName);
} else {
cg.EmitString(this.filename);
}
cg.EmitCall(typeof(FunctionCode), "SetFilename");
// Only codegen the call into SetFlags if there are flags to set.
FunctionCode.FuncCodeFlags codeFlags = 0;
if (cg.Context.TrueDivision) codeFlags |= FunctionCode.FuncCodeFlags.FutureDivision;
if (this.yieldCount > 0) codeFlags |= FunctionCode.FuncCodeFlags.Generator;
if (codeFlags != 0) {
functionCode.EmitGet(cg);
//.........这里部分代码省略.........
示例5: EmitLocation
protected virtual void EmitLocation(CodeGen cg)
{
if (IsValidLocation)
{
cg.EmitPosition(_start, _end);
//cg.Emit(OpCodes.Nop);
}
}
示例6: Emit
public override void Emit(CodeGen cg)
{
if (Span.IsValid)
{
cg.EmitPosition(Start, End);
if (ScriptDomainManager.Options.LightweightDebugging)
{
if (!cg.IsDynamicMethod)
{
var s = SpanToLong(Span);
cg.EmitConstant(s);
cg.EmitCall(Debugging.DebugMethods.ExpressionInTail); // not really but will do for LW debugger
}
}
}
if (_statement != null) {
cg.CheckAndPushTargets(_statement);
}
cg.EmitContinue();
if (_statement != null) {
cg.PopTargets();
}
}