BadScript 2
Loading...
Searching...
No Matches
BadNamedExportExpression.cs
Go to the documentation of this file.
6
8
13{
20 public BadNamedExportExpression(string? name, BadExpression expression, BadSourcePosition position) :
21 base(false, position)
22 {
23 Expression = expression;
24 Name = name;
25 }
26
30 public BadExpression Expression { get; private set; }
31
35 public string? Name { get; }
36
38 public override IEnumerable<BadExpression> GetDescendants()
39 {
41 }
42
44 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
45 {
46 if (string.IsNullOrEmpty(Name))
47 {
48 throw BadRuntimeException.Create(context.Scope, "Exported objects must have a name", Position);
49 }
50
51 BadObject? result = BadObject.Null;
52
53 foreach (BadObject o in Expression.Execute(context))
54 {
55 result = o;
56
57 yield return o;
58 }
59
60 result = result.Dereference(Position);
61
62 context.Scope.AddExport(Name!, result);
63
64 yield return result;
65 }
66
68 public override void Optimize()
69 {
71 }
72
74 public override string ToString()
75 {
76 return $"export {Expression}";
77 }
78}
Describes a specific position inside a source file.
static BadExpression Optimize(BadExpression expr)
Optimizes the given expression.
Base Implementation for all Expressions used inside the Script.
IEnumerable< BadExpression > GetDescendantsAndSelf()
Returns all Descendants of the Expression and the Expression itself.
BadSourcePosition Position
The source Position of the Expression.
IEnumerable< BadObject > Execute(BadExecutionContext context)
Evaluates the Expression within the current Execution Context.
BadNamedExportExpression(string? name, BadExpression expression, BadSourcePosition position)
Creates a new Named Export Expression.
override void Optimize()
Uses the Constant Folding Optimizer to optimize the expression.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
static BadRuntimeException Create(BadScope? scope, string message)
Creates a new BadScriptException.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Contains Shared Data Structures and Functionality.
Contains the BadScript2 Constant Folding Optimizations.
Contains the Error Objects for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.