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(BadObjectReference leftRef,
34 BadObject left,
35 BadObject right,
36 BadSourcePosition position,
37 string symbol)
38 {
39 if (left is not IBadNumber lNum || right is not IBadNumber rNum)
40 {
41 throw new BadRuntimeException($"Can not apply operator '{symbol}' to {left} and {right}", position);
42 }
43
44 BadObject r = BadObject.Wrap(System.Math.Pow((double)lNum.Value, (double)rNum.Value));
45 leftRef.Set(r, position);
46
47 return r;
48 }
49
59 public static IEnumerable<BadObject> ExpWithOverride(BadExecutionContext? context,
60 BadObjectReference leftRef,
61 BadObject right,
62 BadSourcePosition position,
63 string symbol)
64 {
65 BadObject left = leftRef.Dereference(position);
66
68 {
69 foreach (BadObject o in ExecuteOperatorOverride(left,
70 right,
71 context!,
73 position
74 ))
75 {
76 yield return o;
77 }
78 }
79 else
80 {
81 yield return Exp(leftRef, left, right, position, symbol);
82 }
83 }
84
86 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
87 {
89
90 foreach (BadObject o in Left.Execute(context))
91 {
92 left = o;
93
94 yield return o;
95 }
96
97 if (left is not BadObjectReference leftRef)
98 {
99 throw new BadRuntimeException($"Left side of {GetSymbol()} must be a reference", Position);
100 }
101
102 BadObject right = BadObject.Null;
103
104 foreach (BadObject o in Right.Execute(context))
105 {
106 right = o;
107
108 yield return o;
109 }
110
111 right = right.Dereference(Position);
112
113 foreach (BadObject o in ExpWithOverride(context, leftRef, right, Position, GetSymbol()))
114 {
115 yield return o;
116 }
117 }
118
120 protected override string GetSymbol()
121 {
122 return "**=";
123 }
124}
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: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 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.