BadScript 2
Loading...
Searching...
No Matches
BadDivideAssignExpression.cs
Go to the documentation of this file.
6
8
13{
21 left,
22 right,
23 position
24 ) { }
25
26
37 public static BadObject Divide(
38 BadObjectReference leftRef,
39 BadObject left,
40 BadObject right,
41 BadSourcePosition position,
42 string symbol)
43 {
44 if (left is not IBadNumber lNum || right is not IBadNumber rNum)
45 {
46 throw new BadRuntimeException($"Can not apply operator '{symbol}' to {left} and {right}", position);
47 }
48
49 BadObject r = BadObject.Wrap(lNum.Value / rNum.Value);
50 leftRef.Set(r);
51
52 return r;
53 }
54
64 public static IEnumerable<BadObject> DivideWithOverride(
65 BadExecutionContext? context,
66 BadObjectReference leftRef,
67 BadObject right,
68 BadSourcePosition position,
69 string symbol)
70 {
71 BadObject left = leftRef.Dereference();
72
74 {
76 left,
77 right,
78 context!,
80 position
81 ))
82 {
83 yield return o;
84 }
85 }
86 else
87 {
88 yield return Divide(leftRef, left, right, position, symbol);
89 }
90 }
91
93 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
94 {
96
97 foreach (BadObject o in Left.Execute(context))
98 {
99 left = o;
100
101 yield return o;
102 }
103
104 if (left is not BadObjectReference leftRef)
105 {
106 throw new BadRuntimeException($"Left side of {GetSymbol()} must be a reference", Position);
107 }
108
109 BadObject right = BadObject.Null;
110
111 foreach (BadObject o in Right.Execute(context))
112 {
113 right = o;
114
115 yield return o;
116 }
117
118 right = right.Dereference();
119
120 foreach (BadObject o in DivideWithOverride(context, leftRef, right, Position, GetSymbol()))
121 {
122 yield return o;
123 }
124 }
125
127 protected override string GetSymbol()
128 {
129 return "/=";
130 }
131}
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: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.