BadScript 2
Loading...
Searching...
No Matches
BadTableExpression.cs
Go to the documentation of this file.
6
8
13{
17 private readonly Dictionary<BadWordToken, BadExpression> m_Table;
18
24 public BadTableExpression(Dictionary<BadWordToken, BadExpression> table, BadSourcePosition position) : base(
25 false,
26 position
27 )
28 {
29 m_Table = table;
30 }
31
35 public int Length => m_Table.Count;
36
40 public IDictionary<BadWordToken, BadExpression> Table => m_Table;
41
43 public override IEnumerable<BadExpression> GetDescendants()
44 {
45 return m_Table.SelectMany(kvp => kvp.Value.GetDescendantsAndSelf());
46 }
47
49 public override void Optimize()
50 {
51 KeyValuePair<BadWordToken, BadExpression>[] branches = m_Table.ToArray();
52 m_Table.Clear();
53
54 foreach (KeyValuePair<BadWordToken, BadExpression> branch in branches)
55 {
56 m_Table[branch.Key] = BadConstantFoldingOptimizer.Optimize(branch.Value);
57 }
58 }
59
61 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
62 {
63 Dictionary<string, BadObject> table = new Dictionary<string, BadObject>();
64
65 foreach (KeyValuePair<BadWordToken, BadExpression> entry in m_Table)
66 {
67 BadObject value = BadObject.Null;
68
69 foreach (BadObject o in entry.Value.Execute(context))
70 {
71 value = o;
72
73 yield return o;
74 }
75
76 value = value.Dereference();
77
78 table[entry.Key.Text] = value;
79 }
80
81 yield return new BadTable(table);
82 }
83}
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.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
BadTableExpression(Dictionary< BadWordToken, BadExpression > table, BadSourcePosition position)
Constructor of the Table Expression.
readonly Dictionary< BadWordToken, BadExpression > m_Table
The Initializer List of the Table.
override IEnumerable< BadExpression > GetDescendants()
override void Optimize()
Uses the Constant Folding Optimizer to optimize the expression.
IDictionary< BadWordToken, BadExpression > Table
The Initializer List of the Table.
The Execution Context. Every execution of a script needs a context the script is running in....
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
Implements a Table Structure for the BadScript Language.
Definition BadTable.cs:14
Contains Shared Data Structures and Functionality.
Contains the BadScript2 Constant Folding Optimizations.
Contains the Constant Expressions for the BadScript2 Language.
Contains the Reader Tokens for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.