本文整理汇总了C#中Scope.EmitLocals方法的典型用法代码示例。如果您正苦于以下问题:C# Scope.EmitLocals方法的具体用法?C# Scope.EmitLocals怎么用?C# Scope.EmitLocals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scope
的用法示例。
在下文中一共展示了Scope.EmitLocals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildMainMethod
public JsMain BuildMainMethod(BoundProgram program)
{
if (program == null)
throw new ArgumentNullException("program");
var method = _scriptBuilder.CreateFunction(typeof(JsMain), MainMethodName, null);
_scope = new Scope(
this,
method.GetILBuilder(),
false,
program.Body,
null,
_scriptBuilder,
null
);
_scope.EmitLocals(program.Body.TypeManager);
if (program.Body.Closure != null)
EmitClosureSetup(program.Body);
EmitInitializeArguments(program.Body);
EmitStatements(program.Body.Body);
// Ensure that we return something.
EmitReturn(new BoundReturn(null, SourceLocation.Missing));
// Emit the exceptional return block if we need it.
EmitExceptionalReturn();
_scriptBuilder.Commit();
return (JsMain)Delegate.CreateDelegate(typeof(JsMain), method.Method);
}
示例2: DeclareFunction
private IFunctionBuilder DeclareFunction(BoundFunction function, ITypeBuilder typeBuilder, string sourceCode)
{
var method = typeBuilder.CreateFunction(typeof(JsFunction), function.Name, sourceCode);
var argumentsReferenced = (function.Body.Flags & BoundBodyFlags.ArgumentsReferenced) != 0;
BoundClosureField argumentsClosureField = null;
var il = method.GetILBuilder();
if (argumentsReferenced && function.Body.Closure != null)
function.Body.Closure.Fields.TryGetValue(BoundClosure.ArgumentsFieldName, out argumentsClosureField);
_scope = new Scope(
this,
il,
true,
function.Body,
argumentsClosureField,
typeBuilder,
_scope
);
_scope.EmitLocals(function.Body.TypeManager);
// Instantiate the closure if we own it.
if (function.Body.Closure != null)
EmitClosureSetup(function.Body);
EmitInitializeArguments(function.Body);
// Build the arguments object when we need it.
if (argumentsReferenced)
{
// Initialize the arguments array.
_scope.ArgumentsEmitter.EmitSetValue(new BoundEmitExpression(
BoundValueType.Object,
() =>
{
_scope.EmitLoad(SpecialLocal.Runtime);
_scope.EmitLoad(SpecialLocal.Callee);
_scope.EmitLoad(SpecialLocal.ArgumentsRaw);
IL.EmitCall(_runtimeCreateArguments);
}
));
}
// Emit the body.
EmitStatements(function.Body.Body);
// Ensure that we return something.
EmitReturn(new BoundReturn(null, SourceLocation.Missing));
// Emit the exceptional return block if we need it.
EmitExceptionalReturn();
// Put a debug location at the end of the function.
if (function.Location != null)
{
IL.MarkSequencePoint(new SourceLocation(
function.Location.EndOffset,
function.Location.EndLine,
function.Location.EndColumn,
function.Location.EndOffset + 1,
function.Location.EndLine,
function.Location.EndColumn + 1,
null
));
}
_scope = _scope.Parent;
return method;
}