BadScript 2
Loading...
Searching...
No Matches
BadMultiplyAssignExpression.cs
Go to the documentation of this file.
6
8
13{
21 left,
22 right,
23 position
24 ) { }
25
36 public static BadObject Multiply(
37 BadObjectReference leftRef,
38 BadObject left,
39 BadObject right,
40 BadSourcePosition position,
41 string symbol)
42 {
43 if (left is not IBadNumber lNum || right is not IBadNumber rNum)
44 {
45 throw new BadRuntimeException($"Can not apply operator '{symbol}' to {left} and {right}", position);
46 }
47
48 BadObject r = BadObject.Wrap(lNum.Value * rNum.Value);
49 leftRef.Set(r);
50
51 return r;
52 }
53
63 public static IEnumerable<BadObject> MultiplyWithOverride(
64 BadExecutionContext? context,
65 BadObjectReference leftRef,
66 BadObject right,
67 BadSourcePosition position,
68 string symbol)
69 {
70 BadObject left = leftRef.Dereference();
71
73 {
75 left,
76 right,
77 context!,
79 position
80 ))
81 {
82 yield return o;
83 }
84 }
85 else
86 {
87 yield return Multiply(leftRef, left, right, position, symbol);
88 }
89 }
90
92 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
93 {
95
96 foreach (BadObject o in Left.Execute(context))
97 {
98 left = o;
99
100 yield return o;
101 }
102
103 if (left is not BadObjectReference leftRef)
104 {
105 throw new BadRuntimeException($"Left side of {GetSymbol()} must be a reference", Position);
106 }
107
108 BadObject right = BadObject.Null;
109
110 foreach (BadObject o in Right.Execute(context))
111 {
112 right = o;
113
114 yield return o;
115 }
116
117 right = right.Dereference();
118
119 foreach (BadObject o in MultiplyWithOverride(context, leftRef, right, Position, GetSymbol()))
120 {
121 yield return o;
122 }
123 }
124
126 protected override string GetSymbol()
127 {
128 return "*=";
129 }
130}
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.
static IEnumerable< BadObject > MultiplyWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadObject right, BadSourcePosition position, string symbol)
Executes the Operator with operator override.
BadMultiplyAssignExpression(BadExpression left, BadExpression right, BadSourcePosition position)
Constructor of the Multiply Assignment Expression.
static BadObject Multiply(BadObjectReference leftRef, BadObject left, BadObject right, BadSourcePosition position, string symbol)
Executes the Operator.
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.
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:118
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, BadPropertyInfo? info=null, bool noChangeEvent=false)
Sets the Referenced Object to a new Value.
Implements the Interface for Native Numbers.
Definition IBadNumber.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.