BadScript 2
Loading...
Searching...
No Matches
BadConstantFoldingOptimizer.cs
Go to the documentation of this file.
5
10
14public static class BadConstantFoldingOptimizer
15{
22 {
23 if (expr is not IBadNativeExpression && expr.IsConstant)
24 {
25 BadLogger.Log($"Optimizing Expression: '{expr}' with Constant Folding", "Optimize");
26 BadObject obj = expr.Execute(null!).Last();
27
28 return new BadConstantExpression(expr.Position, obj);
29 }
30
31 expr.Optimize();
32
33 return expr;
34 }
35
41 public static IEnumerable<BadExpression> Optimize(IEnumerable<BadExpression> exprs)
42 {
43 return exprs.Select(Optimize);
44 }
45}
Public facing interface for a logger.
Definition BadLogger.cs:7
static void Log(string message)
Writes a Log to the Message Handler.
Definition BadLogger.cs:26
static BadExpression Optimize(BadExpression expr)
Optimizes the given expression.
static IEnumerable< BadExpression > Optimize(IEnumerable< BadExpression > exprs)
Optimizes a list of expressions.
Base Implementation for all Expressions used inside the Script.
virtual void Optimize()
Uses the Constant Folding Optimizer to optimize the expression.
BadSourcePosition Position
The source Position of the Expression.
IEnumerable< BadObject > Execute(BadExecutionContext context)
Evaluates the Expression within the current Execution Context.
bool IsConstant
Indicates if the expression stays constant at all times.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
Gets implemented by all Constant/Native Expressions to provide fast access to the value without unwra...
Contains Logging system for the BadScript Runtime.
Definition BadLog.cs:6
Contains the BadScript2 Constant Folding Optimizations.
Contains the Constant Expressions for the BadScript2 Language.
Contains the Expressions for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10