BadScript 2
Loading...
Searching...
No Matches
BadExponentiationAssignExpression.cs
Go to the documentation of this file.
6
8
13{
21 base(left, right, position) { }
22
33 public static BadObject Exp(
34 BadObjectReference leftRef,
35 BadObject left,
36 BadObject right,
37 BadSourcePosition position,
38 string symbol)
39 {
40 if (left is not IBadNumber lNum || right is not IBadNumber rNum)
41 {
42 throw new BadRuntimeException($"Can not apply operator '{symbol}' to {left} and {right}", position);
43 }
44
45 BadObject r = BadObject.Wrap(System.Math.Pow((double)lNum.Value, (double)rNum.Value));
46 leftRef.Set(r);
47
48 return r;
49 }
50
60 public static IEnumerable<BadObject> ExpWithOverride(
61 BadExecutionContext? context,
62 BadObjectReference leftRef,
63 BadObject right,
64 BadSourcePosition position,
65 string symbol)
66 {
67 BadObject left = leftRef.Dereference();
68
70 {
72 left,
73 right,
74 context!,
76 position
77 ))
78 {
79 yield return o;
80 }
81 }
82 else
83 {
84 yield return Exp(leftRef, left, right, position, symbol);
85 }
86 }
87
89 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
90 {
92
93 foreach (BadObject o in Left.Execute(context))
94 {
95 left = o;
96
97 yield return o;
98 }
99
100 if (left is not BadObjectReference leftRef)
101 {
102 throw new BadRuntimeException($"Left side of {GetSymbol()} must be a reference", Position);
103 }
104
105 BadObject right = BadObject.Null;
106
107 foreach (BadObject o in Right.Execute(context))
108 {
109 right = o;
110
111 yield return o;
112 }
113
114 right = right.Dereference();
115
116 foreach (BadObject o in ExpWithOverride(context, leftRef, right, Position, GetSymbol()))
117 {
118 yield return o;
119 }
120 }
121
123 protected override string GetSymbol()
124 {
125 return "**=";
126 }
127}
Describes a specific position inside a source file.
Contains Static Data for the BadScript Language.
const string EXPONENTIATION_ASSIGN_OPERATOR_NAME
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.
BadExponentiationAssignExpression(BadExpression left, BadExpression right, BadSourcePosition position)
Creates a new Exponentiation Assign Expression.
static BadObject Exp(BadObjectReference leftRef, BadObject left, BadObject right, BadSourcePosition position, string symbol)
Implements the logic of the Exponentiation Operator.
static IEnumerable< BadObject > ExpWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadObject right, BadSourcePosition position, string symbol)
Runs the Exponentiation Operator on the given objects.
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.