62 BadLogger.
Log($
"Substituting {expr} => {constant}",
"Optimize");
68 binExpr.SetRight(
Substitute(scope, binExpr.Right));
82 private static IEnumerable<BadExpression>
Optimize(
84 IEnumerable<BadExpression> expressions)
97 proto.SetStaticBody(newStaticBody);
103 proto.SetBody(newBody);
113 whileExpr.SetBody(newBody);
115 yield
return whileExpr;
123 forExpr.SetBody(newBody);
125 yield
return forExpr;
133 forEachExpr.SetBody(newBody);
135 yield
return forEachExpr;
145 ifExpr.ConditionalBranches[branch.Key] = newBody;
148 if (ifExpr.ElseBranch !=
null)
152 ifExpr.SetElseBranch(newBody);
165 switchExpr.Cases[branch.Key] = newBody;
168 if (switchExpr.DefaultCase !=
null)
172 switchExpr.SetDefaultCase(newBody);
175 yield
return switchExpr;
181 List<BadExpression> args = (from arg in invoc.Arguments
182 let childScope = scope.CreateChildScope()
192 select newBody[0]).ToList();
204 func.SetBody(newBody);
216 BadLogger.
Log($
"Optimizing Expression: '{expr}' with Constant Substitution",
"Optimize");
218 BadLogger.
Log($
"Optimized Expression: '{expr}' => '{obj}' using Constant Substitution",
"Optimize");
233 BadLogger.
Log($
"Optimizing Expression: '{expr}' with Constant Substitution",
"Optimize");
235 BadLogger.
Log($
"Optimized Expression: '{expr}' => '{obj}' using Constant Substitution",
"Optimize");
247 BadLogger.
Log($
"Optimizing Expression: '{expr}' with Constant Substitution",
"Optimize");
249 BadLogger.
Log($
"Optimized Expression: '{expr}' => '{obj}' using Constant Substitution",
"Optimize");
253 if (vDef.IsReadOnly && canBeOptimized)
255 scope.AddConstant(vDef.Name, vAssign.Right);
271 public static IEnumerable<BadExpression>
Optimize(IEnumerable<BadExpression> expressions)
Public facing interface for a logger.
static void Log(string message)
Writes a Log to the Message Handler.
Contains the Implementation of the Constant Substitution Optimization This optimization replaces expr...
static bool OnlyContainsConstantsAndConstantVariables(BadConstantSubstitutionOptimizerScope scope, BadExpression expr)
static IEnumerable< BadExpression > Optimize(IEnumerable< BadExpression > expressions)
Runs the Constant Substitution Optimization on the given expressions.
static BadExpression Substitute(BadConstantSubstitutionOptimizerScope scope, BadExpression expr)
Substitutes all variables in the expression with their constant value.
static IEnumerable< BadExpression > Optimize(BadConstantSubstitutionOptimizerScope scope, IEnumerable< BadExpression > expressions)
Substitutes all variables in the expressions with their constant value.
The scope of the Constant Substitution Optimizer.
BadExpression GetConstant(string name)
Returns a constant from this scope or a parent scope.
BadConstantSubstitutionOptimizerScope CreateChildScope()
Creates a child scope.
Base Implementation for all Expressions used inside the Script.
IEnumerable< BadExpression > GetDescendantsAndSelf()
Returns all Descendants of the Expression and the Expression itself.
IEnumerable< BadObject > Execute(BadExecutionContext context)
Evaluates the Expression within the current Execution Context.
bool IsConstant
Indicates if the expression stays constant at all times.
Implements the Assign Expression LEFT = RIGHT.
Base Implementation of all Binary Expressions.
void SetLeft(BadExpression expr)
Sets the Left side of the Expression.
Implements the If Statement Expression.
Implements the Switch Statement Expression.
Implements the For Each Expression.
Implements the For Loop Expression.
Implements the While Expression.
Base Class of all Constant Expressions.
Implements the Return expression that is used to exit the current function with an Optional Return Va...
Implements the Function Expression.
Implements the Invocation Expression.
void SetArgs(IEnumerable< BadExpression > exprs)
Sets the arguments of the invocation.
Implements the Class Prototype Expression.
Implements the Variable Definition Expression.
Implements the Variable Expression.
The Base Class for all BadScript Objects.
Gets implemented by all Constant/Native Expressions to provide fast access to the value without unwra...
Contains Logging system for the BadScript Runtime.
Contains the BadScript2 Constant Substitution Optimizations.
Contains the Binary Expressions for the BadScript2 Language.
Contains the Loop Expressions for the BadScript2 Language.
Contains the Block Expressions for the BadScript2 Language.
Contains the Constant Expressions for the BadScript2 Language.
Contains the Controlflow Expressions for the BadScript2 Language.
Contains the Function Expressions for the BadScript2 Language.
Contains the Type Expressions for the BadScript2 Language.
Contains the Variable Expressions for the BadScript2 Language.
Contains the Expressions for the BadScript2 Language.
Contains the Runtime Objects.