61 BadLogger.
Log($
"Substituting {expr} => {constant}",
"Optimize");
67 binExpr.SetRight(
Substitute(scope, binExpr.Right));
82 IEnumerable<BadExpression> expressions)
96 proto.SetStaticBody(newStaticBody);
103 proto.SetBody(newBody);
115 whileExpr.SetBody(newBody);
117 yield
return whileExpr;
127 forExpr.SetBody(newBody);
129 yield
return forExpr;
139 forEachExpr.SetBody(newBody);
141 yield
return forEachExpr;
148 ifExpr.ConditionalBranches.ToArray())
154 ifExpr.ConditionalBranches[branch.Key] = newBody;
157 if (ifExpr.ElseBranch !=
null)
163 ifExpr.SetElseBranch(newBody);
178 switchExpr.Cases[branch.Key] = newBody;
181 if (switchExpr.DefaultCase !=
null)
187 switchExpr.SetDefaultCase(newBody);
190 yield
return switchExpr;
196 List<BadExpression> args = (from arg in invoc.Arguments
197 let childScope = scope.CreateChildScope()
203 select newBody[0]).ToList();
217 func.SetBody(newBody);
229 BadLogger.
Log($
"Optimizing Expression: '{expr}' with Constant Substitution",
"Optimize");
235 BadLogger.
Log($
"Optimized Expression: '{expr}' => '{obj}' using Constant Substitution",
252 BadLogger.
Log($
"Optimizing Expression: '{expr}' with Constant Substitution",
"Optimize");
258 BadLogger.
Log($
"Optimized Expression: '{expr}' => '{obj}' using Constant Substitution",
272 BadLogger.
Log($
"Optimizing Expression: '{expr}' with Constant Substitution",
"Optimize");
278 BadLogger.
Log($
"Optimized Expression: '{expr}' => '{obj}' using Constant Substitution",
284 if (vDef.IsReadOnly && canBeOptimized)
286 scope.AddConstant(vDef.Name, vAssign.Right);
302 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.