BadScript 2
Loading...
Searching...
No Matches
BadAddAssignExpression.cs
Go to the documentation of this file.
6
11
16{
23 public BadAddAssignExpression(BadExpression left, BadExpression right, BadSourcePosition position) : base(left,
24 right,
25 position
26 ) { }
27
28
39 public static BadObject Add(BadObjectReference leftRef,
40 BadObject left,
41 BadObject right,
42 BadSourcePosition position,
43 string symbol)
44 {
45 switch (left)
46 {
47 case IBadString lStr:
48 {
49 if (right is not IBadNative rNative)
50 {
51 throw new BadRuntimeException($"Can not apply operator '{symbol}' to {left} and {right}", position);
52 }
53
54 BadObject r = BadObject.Wrap(lStr.Value + rNative.Value);
55 leftRef.Set(r, position);
56
57 return r;
58 }
59 case IBadNumber lNum when right is IBadString rStr:
60 {
61 BadObject r = BadObject.Wrap(lNum.Value + rStr.Value);
62 leftRef.Set(r, position);
63
64 return r;
65 }
66 case IBadNumber lNum when right is IBadNumber rNum:
67 {
68 BadObject r = BadObject.Wrap(lNum.Value + rNum.Value);
69 leftRef.Set(r, position);
70
71 return r;
72 }
73 case IBadBoolean lBool when right is IBadString rStr:
74 {
75 BadObject r = BadObject.Wrap(lBool.Value + rStr.Value);
76 leftRef.Set(r, position);
77
78 return r;
79 }
80 default:
81 throw new BadRuntimeException($"Can not apply operator '{symbol}' to {left} and {right}", position);
82 }
83 }
84
94 public static IEnumerable<BadObject> AddWithOverride(BadExecutionContext? context,
95 BadObjectReference leftRef,
96 BadObject right,
97 BadSourcePosition position,
98 string symbol)
99 {
100 BadObject left = leftRef.Dereference(position);
101
103 {
104 foreach (BadObject o in ExecuteOperatorOverride(left,
105 right,
106 context!,
108 position
109 ))
110 {
111 yield return o;
112 }
113 }
114 else
115 {
116 yield return Add(leftRef, left, right, position, symbol);
117 }
118 }
119
121 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
122 {
123 BadObject left = BadObject.Null;
124
125 foreach (BadObject o in Left.Execute(context))
126 {
127 left = o;
128
129 yield return o;
130 }
131
132 if (left is not BadObjectReference leftRef)
133 {
134 throw new BadRuntimeException($"Left side of {GetSymbol()} must be a reference", Position);
135 }
136
137 BadObject right = BadObject.Null;
138
139 foreach (BadObject o in Right.Execute(context))
140 {
141 right = o;
142
143 yield return o;
144 }
145
146 right = right.Dereference(Position);
147
148 foreach (BadObject o in AddWithOverride(context, leftRef, right, Position, GetSymbol()))
149 {
150 yield return o;
151 }
152 }
153
155 protected override string GetSymbol()
156 {
157 return "+=";
158 }
159}
Describes a specific position inside a source file.
Contains Static Data for the BadScript Language.
Base Implementation for all Expressions used inside the Script.
static IEnumerable< BadObject > ExecuteOperatorOverride(BadObject left, BadObject right, BadExecutionContext context, string name, BadSourcePosition position)
Helper function that executes an operator override function if implemented.
BadSourcePosition Position
The source Position of the Expression.
IEnumerable< BadObject > Execute(BadExecutionContext context)
Evaluates the Expression within the current Execution Context.
Base Implementation of all Binary Expressions.
BadExpression Right
Right side of the Expression.
BadAddAssignExpression(BadExpression left, BadExpression right, BadSourcePosition position)
Constructor of the Add Assignment Expression.
static IEnumerable< BadObject > AddWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadObject right, BadSourcePosition position, string symbol)
Executes the Operator with operator override.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
static BadObject Add(BadObjectReference leftRef, BadObject left, BadObject right, BadSourcePosition position, string symbol)
Executes the Add Assignment Operator.
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
virtual bool HasProperty(string propName, BadScope? caller=null)
Returns true if the object contains a given property or there exists an extension for the current Ins...
Definition BadObject.cs:130
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements the base functionality for a BadScript Reference.
void Set(BadObject obj, BadSourcePosition? position, BadPropertyInfo? info=null, bool noChangeEvent=false)
Sets the Referenced Object to a new Value.
Implements the Interface for Native Boolean.
Definition IBadBoolean.cs:7
Defines properties for Native Types.
Definition IBadNative.cs:7
Implements the Interface for Native Numbers.
Definition IBadNumber.cs:7
Implements the Interface for Native Strings.
Definition IBadString.cs:7
Contains Shared Data Structures and Functionality.
Contains the Self-Assigning Math Expressions for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.
Contains the Native Runtime Objects.
Definition BadBoolean.cs:6
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.