BadScript 2
Loading...
Searching...
No Matches
BadDivideAssignExpression.cs
Go to the documentation of this file.
6
8
13{
21 right,
22 position
23 ) { }
24
25
36 public static BadObject Divide(BadObjectReference leftRef,
37 BadObject left,
38 BadObject right,
39 BadSourcePosition position,
40 string symbol)
41 {
42 if (left is not IBadNumber lNum || right is not IBadNumber rNum)
43 {
44 throw new BadRuntimeException($"Can not apply operator '{symbol}' to {left} and {right}", position);
45 }
46
47 BadObject r = BadObject.Wrap(lNum.Value / rNum.Value);
48 leftRef.Set(r, position);
49
50 return r;
51 }
52
62 public static IEnumerable<BadObject> DivideWithOverride(BadExecutionContext? context,
63 BadObjectReference leftRef,
64 BadObject right,
65 BadSourcePosition position,
66 string symbol)
67 {
68 BadObject left = leftRef.Dereference(position);
69
71 {
72 foreach (BadObject o in ExecuteOperatorOverride(left,
73 right,
74 context!,
76 position
77 ))
78 {
79 yield return o;
80 }
81 }
82 else
83 {
84 yield return Divide(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(Position);
115
116 foreach (BadObject o in DivideWithOverride(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.
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.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
BadDivideAssignExpression(BadExpression left, BadExpression right, BadSourcePosition position)
Constructor of the Divide Assignment Expression.
static IEnumerable< BadObject > DivideWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadObject right, BadSourcePosition position, string symbol)
Executes the Operator with operator override.
static BadObject Divide(BadObjectReference leftRef, BadObject left, BadObject right, BadSourcePosition position, string symbol)
Executes the 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 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.