本文整理汇总了C#中CodeGen.EmitStaticLinkOrNull方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGen.EmitStaticLinkOrNull方法的具体用法?C# CodeGen.EmitStaticLinkOrNull怎么用?C# CodeGen.EmitStaticLinkOrNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGen
的用法示例。
在下文中一共展示了CodeGen.EmitStaticLinkOrNull方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitGeneratorBody
private void EmitGeneratorBody(CodeGen cg, CodeGen ocg)
{
// Create the GenerateNext function
CodeGen ncg = cg.DefineMethod(name.GetString() + "$g" + counter++, typeof(bool),
new Type[] { typeof(Generator), typeof(object).MakeByRefType() },
new String[] { "$gen", "$ret" });
ncg.Context = cg.Context;
PromoteLocalsToEnvironment();
ncg.FuncOrClassName = name.ToString();
ncg.EmitSetTraceBackUpdateStatus(false);
// Namespace without er factory - all locals must exist ahead of time
ncg.Names = new Namespace(null);
Slot generator = ncg.GetArgumentSlot(0);
ncg.StaticLinkSlot = new FieldSlot(generator, typeof(Generator).GetField("staticLink"));
if (HasEnvironment) {
cg.EnvironmentSlot = CreateEnvironment(cg);
EnvironmentFactory ef = this.environmentFactory;
Slot envSlotCast = new CastSlot(
new FieldSlot(generator, typeof(Generator).GetField("environment")),
ef.EnvironmentType
);
Slot envSlot = ncg.GetLocalTmp(ef.EnvironmentType);
// setup the environment and static link slots
ncg.EnvironmentSlot = envSlot;
ncg.ContextSlot = envSlot;
// pull the environment into typed local variable
envSlot.EmitSet(ncg, envSlotCast);
InheritEnvironment(ncg);
CreateGeneratorTemps(ef, ncg);
} else {
ncg.ContextSlot = ncg.StaticLinkSlot;
}
ncg.ModuleSlot = new PropertySlot(ncg.ContextSlot, typeof(ICallerContext).GetProperty("Module"));
CreateClosureSlots(ncg);
CreateGlobalSlots(ncg, ocg);
// Emit the generator body using the typed er
EmitGenerator(ncg);
// Initialize the generator
EmitTupleParams(cg);
// Create instance of the generator
cg.EmitStaticLinkOrNull();
cg.EmitEnvironmentOrNull();
cg.EmitDelegate(ncg, typeof(Generator.NextTarget), null);
cg.EmitNew(typeof(Generator), new Type[] { typeof(FunctionEnvironmentDictionary), typeof(FunctionEnvironmentDictionary), typeof(Generator.NextTarget) });
cg.EmitReturn();
}
示例2: CreateEnvironment
internal Slot CreateEnvironment(CodeGen cg)
{
// Get the environment size
int size = CalculateEnvironmentSize();
// Find the right environment type
ConstructorInfo ctor;
EnvironmentFactory esf;
Type envType = GetEnvironmentType(size, cg, out ctor, out esf);
// Emit the static link for the environment constructor
cg.EmitStaticLinkOrNull();
cg.EmitCallerContext();
// Emit the names array for the environment constructor
EmitEnvironmentIDs(cg);
EmitOuterLocalIDs(cg);
cg.EmitNew(ctor);
// Store the environment reference in the local
Slot environmentSlot = cg.GetFrameSlot(envType);
environmentSlot.EmitSet(cg);
// Remember the environment factory for parent access
environmentFactory = esf;
// Create environment references
environment = new Dictionary<SymbolId, EnvironmentReference>();
foreach (KeyValuePair<SymbolId, Binding> kv in names) {
if (!kv.Value.IsEnvironment) continue;
SymbolId name = kv.Key;
EnvironmentReference er = esf.MakeEnvironmentReference(name);
Slot slot = er.CreateSlot(environmentSlot);
Slot current;
if (cg.Names.Slots.TryGetValue(name, out current)) {
slot.EmitSet(cg, current);
} else {
slot.EmitSetUninitialized(cg, name);
}
// The full slot goes to the codegen's namespace
cg.Names.SetSlot(name, slot);
// Environment reference goes to the environment
environment[name] = er;
}
return environmentSlot;
}