24 private readonly List<BadExpression>
m_Body;
52 List<BadFunctionParameter> parameter,
53 List<BadExpression> block,
139 public void SetBody(IEnumerable<BadExpression> body)
148 for (
int i = 0; i <
m_Body.Count; i++)
162 BadFunctionCompileLevel.Compiled =>
"compiled ",
163 BadFunctionCompileLevel.CompiledFast =>
"compiled fast",
168 $
"{level}{BadStaticKeys.FUNCTION_KEY} {Name?.ToString() ?? "<anonymous>
"}({string.Join(",
", Parameters.Cast<object>())})";
175 StringBuilder sb =
new StringBuilder(
GetHeader());
181 sb.AppendLine($
"\t{expression}");
186 return sb.ToString();
196 yield
return typeExpr;
209 yield
return typeExpr;
215 yield
return descendant;
234 obj = obj.Dereference();
239 $
"Expected class prototype, but got {obj.GetType().Name}",
251 m_Parameters.Select(x => x.Initialize(context)).ToArray(),
269 var attributes =
new List<BadObject>();
287 "Anonymous functions cannot have attributes",
Describes a specific position inside a source file.
Implements a simple constant folding optimization.
static BadExpression Optimize(BadExpression expr)
Optimizes the given expression.
Base Implementation for all Expressions used inside the Script.
IEnumerable< BadObject > ComputeAttributes(BadExecutionContext ctx, List< BadObject > attributes)
IEnumerable< BadExpression > GetDescendantsAndSelf()
Returns all Descendants of the Expression and the Expression itself.
IEnumerable< BadExpression > Attributes
BadSourcePosition Position
The source Position of the Expression.
IEnumerable< BadObject > Execute(BadExecutionContext context)
Evaluates the Expression within the current Execution Context.
Implements the Function Expression.
override IEnumerable< BadExpression > GetDescendants()
BadFunctionExpression(BadWordToken? name, List< BadFunctionParameter > parameter, List< BadExpression > block, BadSourcePosition position, bool isConstant, BadMetaData? metaData, bool isSingleLine, bool isStatic, BadFunctionCompileLevel compileLevel=BadFunctionCompileLevel.None, BadExpression? typeExpr=null)
Constructor of the Function Expression.
BadFunctionCompileLevel CompileLevel
The Compile Level of the Function.
IEnumerable< BadFunctionParameter > Parameters
The Function Parameters.
BadExpression? TypeExpression
The (optional) Type Expression that is used to type-check the return value.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
bool IsSingleLine
Indicates if the function is a single line function(e.g. a lambda expression)?
bool IsStatic
Indicates if the function is static.
string? GetName()
Returns the Name of the Expression.The Name of the Expression
readonly? BadMetaData m_MetaData
The Meta data of the Function.
readonly List< BadFunctionParameter > m_Parameters
The Function parameters.
string GetHeader()
Returns the Header of the Function.
readonly List< BadExpression > m_Body
The Function Body.
void SetName(string name)
void SetCompileLevel(BadFunctionCompileLevel level)
Sets the Compile Level of the Function.
BadWordToken? Name
The (optional) Function Name.
override void Optimize()
Uses the Constant Folding Optimizer to optimize the expression.
void SetBody(IEnumerable< BadExpression > body)
Sets the Body of the Function.
bool IsConstantFunction
Indicates if this function can not be overwritten by another object.
IEnumerable< BadExpression > Body
The Function Body.
override string ToString()
string Text
The Text Representation of the Token.
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
void DefineVariable(string name, BadObject value, BadScope? caller=null, BadPropertyInfo? info=null, BadObject[]? attributes=null)
Defines a new Variable in the current scope.
Gets thrown by the runtime.
The Base Class for all BadScript Objects.
static readonly BadObject Null
The Null Value for the BadScript Language.
Stores Meta Information about a Property.
The Expression Function Implementation used if a function gets defined in the Source Code.
Implements a function that can be called from the script.
override BadClassPrototype GetPrototype()
Provides function parameter info.
BadExpression? TypeExpr
The Expression that returns the type of the parameter if evaluated.
The Any Prototype, Base type for all types.
static readonly BadAnyPrototype Instance
The Instance of the BadAnyPrototype.
Implements a Class Prototype for the BadScript Language.
Implements an API for the Compiler.
static BadCompiledFunction CompileFunction(BadExpressionFunction func, bool useOverride)
Compiles a Function.
Gets inherited by all Expressions that have a Name(e.g. Variable Definitions, Function Definitions,...
Contains Shared Data Structures and Functionality.
Contains the BadScript2 Constant Folding Optimizations.
Contains the Function Expressions for the BadScript2 Language.
BadFunctionCompileLevel
The BadFunctionCompileLevel enum defines the different levels of compilation for a function.
Contains the Reader Tokens for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.
Contains Runtime Function Objects.
Contains Runtime Type Objects.
Contains the Runtime Objects.
Contains the Compiler for the BadVirtualMachine.
Contains the Runtime Implementation.