本文整理汇总了C#中Jurassic.Compiler.OptimizationInfo类的典型用法代码示例。如果您正苦于以下问题:C# OptimizationInfo类的具体用法?C# OptimizationInfo怎么用?C# OptimizationInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OptimizationInfo类属于Jurassic.Compiler命名空间,在下文中一共展示了OptimizationInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateCode
/// <summary>
/// Generates CIL for the statement.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
public override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
{
// Generate code for the start of the statement.
var statementLocals = new StatementLocals() { NonDefaultBreakStatementBehavior = true, NonDefaultDebugInfoBehavior = true };
GenerateStartOfStatement(generator, optimizationInfo, statementLocals);
// Construct a loop expression.
// var enumerator = TypeUtilities.EnumeratePropertyNames(rhs).GetEnumerator();
// while (true) {
// continue-target:
// if (enumerator.MoveNext() == false)
// goto break-target;
// lhs = enumerator.Current;
//
// <body statements>
// }
// break-target:
// Call IEnumerable<string> EnumeratePropertyNames(ScriptEngine engine, object obj)
EmitHelpers.LoadScriptEngine(generator);
this.TargetObject.GenerateCode(generator, optimizationInfo);
EmitConversion.ToAny(generator, this.TargetObject.ResultType);
generator.Call(ReflectionHelpers.TypeUtilities_EnumeratePropertyNames);
// Call IEnumerable<string>.GetEnumerator()
generator.Call(ReflectionHelpers.IEnumerable_GetEnumerator);
// Store the enumerator in a temporary variable.
var enumerator = generator.CreateTemporaryVariable(typeof(IEnumerator<string>));
generator.StoreVariable(enumerator);
var breakTarget = generator.CreateLabel();
var continueTarget = generator.DefineLabelPosition();
// Emit debugging information.
if (optimizationInfo.DebugDocument != null)
generator.MarkSequencePoint(optimizationInfo.DebugDocument, this.VariableDebugInfo);
// if (enumerator.MoveNext() == false)
// goto break-target;
generator.LoadVariable(enumerator);
generator.Call(ReflectionHelpers.IEnumerator_MoveNext);
generator.BranchIfFalse(breakTarget);
// lhs = enumerator.Current;
generator.LoadVariable(enumerator);
generator.Call(ReflectionHelpers.IEnumerator_Current);
this.Variable.GenerateSet(generator, optimizationInfo, PrimitiveType.String, false);
// Emit the body statement(s).
optimizationInfo.PushBreakOrContinueInfo(this.Labels, breakTarget, continueTarget, labelledOnly: false);
this.Body.GenerateCode(generator, optimizationInfo);
optimizationInfo.PopBreakOrContinueInfo();
generator.Branch(continueTarget);
generator.DefineLabelPosition(breakTarget);
// Generate code for the end of the statement.
GenerateEndOfStatement(generator, optimizationInfo, statementLocals);
}
示例2: GenerateCode
/// <summary>
/// Generates CIL for the statement.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
public override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
{
// Generate code for the start of the statement.
var statementLocals = new StatementLocals();
GenerateStartOfStatement(generator, optimizationInfo, statementLocals);
// Create the scope.
this.Scope.GenerateScopeCreation(generator, optimizationInfo);
// Make sure the scope is reverted even if an exception is thrown.
generator.BeginExceptionBlock();
// Setting the InsideTryCatchOrFinally flag converts BR instructions into LEAVE
// instructions so that the finally block is executed correctly.
var previousInsideTryCatchOrFinally = optimizationInfo.InsideTryCatchOrFinally;
optimizationInfo.InsideTryCatchOrFinally = true;
// Generate code for the body statements.
this.Body.GenerateCode(generator, optimizationInfo);
// Reset the InsideTryCatchOrFinally flag.
optimizationInfo.InsideTryCatchOrFinally = previousInsideTryCatchOrFinally;
// Revert the scope.
generator.BeginFinallyBlock();
this.Scope.GenerateScopeDestruction(generator, optimizationInfo);
generator.EndExceptionBlock();
// Generate code for the end of the statement.
GenerateEndOfStatement(generator, optimizationInfo, statementLocals);
}
示例3: GenerateCode
/// <summary>
/// Generates CIL for the statement.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
public override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
{
// Generate code for the start of the statement.
var statementLocals = new StatementLocals();
GenerateStartOfStatement(generator, optimizationInfo, statementLocals);
if (this.ContributesToEvalResult == true && optimizationInfo.EvalResult != null)
{
// Emit the expression.
this.Expression.GenerateCode(generator, optimizationInfo);
// Store the result.
EmitConversion.ToAny(generator, this.Expression.ResultType);
generator.StoreVariable(optimizationInfo.EvalResult);
}
else
{
// Emit the expression.
this.Expression.GenerateCode(generator, optimizationInfo);
generator.Pop();
}
// Generate code for the end of the statement.
GenerateEndOfStatement(generator, optimizationInfo, statementLocals);
}
示例4: GenerateCode
/// <summary>
/// Generates IL for the script.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
protected override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
{
// Declare a variable to store the eval result.
optimizationInfo.EvalResult = generator.DeclareVariable(typeof(object));
if (this.StrictMode == true)
{
// Create a new scope.
this.InitialScope.GenerateScopeCreation(generator, optimizationInfo);
}
// Verify the scope is correct.
VerifyScope(generator);
// Initialize any declarations.
this.InitialScope.GenerateDeclarations(generator, optimizationInfo);
// Generate the main body of code.
this.AbstractSyntaxTree.GenerateCode(generator, optimizationInfo);
// Make the return value from the method the eval result.
generator.LoadVariable(optimizationInfo.EvalResult);
// If the result is null, convert it to undefined.
var end = generator.CreateLabel();
generator.Duplicate();
generator.BranchIfNotNull(end);
generator.Pop();
EmitHelpers.EmitUndefined(generator);
generator.DefineLabelPosition(end);
}
示例5: GenerateCode
/// <summary>
/// Generates CIL for the expression.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
public override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
{
// This code is only used for untagged template literals.
// Tagged template literals are handled by FunctionCallExpression.
// Load the values array onto the stack.
generator.LoadInt32(this.Strings.Count + this.Values.Count);
generator.NewArray(typeof(string));
for (int i = 0; i < this.Strings.Count; i++)
{
// Operands for StoreArrayElement() are: an array (string[]), index (int), value (string).
// Store the string.
generator.Duplicate();
generator.LoadInt32(i * 2);
generator.LoadString(this.Strings[i]);
generator.StoreArrayElement(typeof(string));
if (i == this.Strings.Count - 1)
break;
// Store the value.
generator.Duplicate();
generator.LoadInt32(i * 2 + 1);
this.Values[i].GenerateCode(generator, optimizationInfo);
EmitConversion.ToString(generator, this.Values[i].ResultType);
generator.StoreArrayElement(typeof(string));
}
// Call String.Concat(string[])
generator.CallStatic(ReflectionHelpers.String_Concat);
}
示例6: GenerateDelete
/// <summary>
/// Deletes the reference and pushes <c>true</c> if the delete succeeded, or <c>false</c>
/// if the delete failed.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
public void GenerateDelete(ILGenerator generator, OptimizationInfo optimizationInfo)
{
// Load the left-hand side and convert to an object instance.
var lhs = this.GetOperand(0);
lhs.GenerateCode(generator, optimizationInfo);
EmitConversion.ToObject(generator, lhs.ResultType);
// Load the property name and convert to a string.
var rhs = this.GetOperand(1);
if (this.OperatorType == OperatorType.MemberAccess && rhs is NameExpression)
generator.LoadString((rhs as NameExpression).Name);
else
{
rhs.GenerateCode(generator, optimizationInfo);
EmitConversion.ToString(generator, rhs.ResultType);
}
// Call Delete()
generator.LoadBoolean(optimizationInfo.StrictMode);
generator.Call(ReflectionHelpers.ObjectInstance_Delete);
// If the return value is not wanted then pop it from the stack.
//if (optimizationInfo.SuppressReturnValue == true)
// generator.Pop();
}
示例7: GenerateCode
/// <summary>
/// Generates CIL for the expression.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
public override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
{
// Generate a new method.
this.context.GenerateCode();
// Add the generated method to the nested function list.
if (optimizationInfo.NestedFunctions == null)
optimizationInfo.NestedFunctions = new List<GeneratedMethod>();
optimizationInfo.NestedFunctions.Add(this.context.GeneratedMethod);
// Add all the nested methods to the parent list.
if (this.context.GeneratedMethod.Dependencies != null)
{
foreach (var nestedFunctionExpression in this.context.GeneratedMethod.Dependencies)
optimizationInfo.NestedFunctions.Add(nestedFunctionExpression);
}
// Store the generated method in the cache.
long generatedMethodID = GeneratedMethod.Save(this.context.GeneratedMethod);
// Create a UserDefinedFunction.
// prototype
EmitHelpers.LoadScriptEngine(generator);
generator.Call(ReflectionHelpers.ScriptEngine_Function);
generator.Call(ReflectionHelpers.FunctionInstance_InstancePrototype);
// name
generator.LoadString(this.FunctionName);
// argumentNames
generator.LoadInt32(this.ArgumentNames.Count);
generator.NewArray(typeof(string));
for (int i = 0; i < this.ArgumentNames.Count; i++)
{
generator.Duplicate();
generator.LoadInt32(i);
generator.LoadString(this.ArgumentNames[i]);
generator.StoreArrayElement(typeof(string));
}
// scope
EmitHelpers.LoadScope(generator);
// bodyText
generator.LoadString(this.BodyText);
// body
generator.LoadInt64(generatedMethodID);
generator.Call(ReflectionHelpers.GeneratedMethod_Load);
// strictMode
generator.LoadBoolean(this.context.StrictMode);
// new UserDefinedFunction(ObjectInstance prototype, string name, IList<string> argumentNames, DeclarativeScope scope, Func<Scope, object, object[], object> body, bool strictMode)
generator.NewObject(ReflectionHelpers.UserDefinedFunction_Constructor);
}
示例8: GenerateCode
/// <summary>
/// Generates CIL for the statement.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
public override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
{
// Generate code for the start of the statement.
var statementLocals = new StatementLocals() { NonDefaultSourceSpanBehavior = true };
GenerateStartOfStatement(generator, optimizationInfo, statementLocals);
// Generate code for the end of the statement.
GenerateEndOfStatement(generator, optimizationInfo, statementLocals);
}
示例9: GenerateCode
/// <summary>
/// Generates CIL for the statement.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
public override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
{
// Generate code for the start of the statement.
var statementLocals = new StatementLocals();
GenerateStartOfStatement(generator, optimizationInfo, statementLocals);
// Generate code for the end of the statement.
GenerateEndOfStatement(generator, optimizationInfo, statementLocals);
}
示例10: GenerateCode
/// <summary>
/// Generates IL for the script.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
protected override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
{
// Initialize any function or variable declarations.
this.InitialScope.GenerateDeclarations(generator, optimizationInfo);
// Generate code for the source code.
this.AbstractSyntaxTree.GenerateCode(generator, optimizationInfo);
// Code in the global context always returns undefined.
EmitHelpers.EmitUndefined(generator);
}
示例11: GenerateCode
/// <summary>
/// Generates CIL for the statement.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
public override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
{
// Generate code for the start of the statement.
var statementLocals = new StatementLocals();
GenerateStartOfStatement(generator, optimizationInfo, statementLocals);
// Emit an unconditional branch.
// Note: the continue statement might be branching from inside a try { } or finally { }
// block to outside. EmitLongJump() handles this.
optimizationInfo.EmitLongJump(generator, optimizationInfo.GetContinueTarget(this.Label));
// Generate code for the end of the statement.
GenerateEndOfStatement(generator, optimizationInfo, statementLocals);
}
示例12: GenerateCode
/// <summary>
/// Generates CIL for the expression.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
public override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
{
// Get an array of comma-delimited expressions.
var items = this.Items;
for (int i = 0; i < items.Count - 1; i++)
{
// Generate code for the item, evaluating the side-effects but not producing any values.
items[i].GenerateCode(generator, optimizationInfo); //.AddFlags(OptimizationFlags.SuppressReturnValue));
generator.Pop();
}
// Generate code for the last item and return the value.
items[items.Count - 1].GenerateCode(generator, optimizationInfo);
}
示例13: GenerateEndOfStatement
/// <summary>
/// Generates CIL for the end of every statement.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
/// <param name="locals"> Variables common to both GenerateStartOfStatement() and GenerateEndOfStatement(). </param>
public void GenerateEndOfStatement(ILGenerator generator, OptimizationInfo optimizationInfo, StatementLocals locals)
{
if (locals.NonDefaultBreakStatementBehavior == false && this.HasLabels == true)
{
// Revert the information needed by the break statement.
generator.DefineLabelPosition(locals.EndOfStatement);
optimizationInfo.PopBreakOrContinueInfo();
}
#if DEBUG && !SILVERLIGHT && !XBOX
// Check that the stack count is zero.
if (generator is DynamicILGenerator && ((DynamicILGenerator)generator).StackSize != locals.OriginalStackSize)
throw new InvalidOperationException("Encountered unexpected stack imbalance.");
#endif
}
示例14: GenerateCode
/// <summary>
/// Generates CIL for the statement.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
public override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
{
// Generate code for the start of the statement.
var statementLocals = new StatementLocals();
GenerateStartOfStatement(generator, optimizationInfo, statementLocals);
// Emit code to throw the given value.
this.Value.GenerateCode(generator, optimizationInfo);
EmitConversion.ToAny(generator, this.Value.ResultType);
generator.LoadInt32(0);
generator.LoadNull();
generator.NewObject(ReflectionHelpers.JavaScriptException_Constructor_Object);
generator.Throw();
// Generate code for the end of the statement.
GenerateEndOfStatement(generator, optimizationInfo, statementLocals);
}
示例15: GenerateCode
/// <summary>
/// Generates CIL for the statement.
/// </summary>
/// <param name="generator"> The generator to output the CIL to. </param>
/// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
public override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
{
// Generate code for the start of the statement.
var statementLocals = new StatementLocals();
GenerateStartOfStatement(generator, optimizationInfo, statementLocals);
// Inserts a breakpoint into the IL.
generator.Breakpoint();
// When the debugger stops, it stops at the first instruction after the breakpoint. By
// inserting a no-op operation the debugger will highlight the "debugger" statement
// instead of the statement after the "debugger" statement.
generator.NoOperation();
// Generate code for the end of the statement.
GenerateEndOfStatement(generator, optimizationInfo, statementLocals);
}