BadScript 2
Loading...
Searching...
No Matches
BadPostDecrementExpression.cs
Go to the documentation of this file.
6
11
16{
20 public readonly BadExpression Left;
21
28 position
29 )
30 {
31 Left = left;
32 }
33
34
36 public override IEnumerable<BadExpression> GetDescendants()
37 {
39 }
40
41
49 public static BadObject Decrement(BadObjectReference reference, BadSourcePosition position)
50 {
51 BadObject value = reference.Dereference(position);
52
53 if (value is not IBadNumber leftNumber)
54 {
55 throw new BadRuntimeException("Left side of -- must be a number", position);
56 }
57
58 reference.Set(leftNumber.Value - 1, position);
59
60 return value;
61 }
62
71 public static IEnumerable<BadObject> DecrementWithOverride(BadExecutionContext? context,
72 BadObjectReference leftRef,
73 BadSourcePosition position)
74 {
75 BadObject left = leftRef.Dereference(position);
76
78 {
79 foreach (BadObject o in ExecuteOperatorOverride(left,
80 context!,
82 position
83 ))
84 {
85 yield return o;
86 }
87 }
88 else
89 {
90 yield return Decrement(leftRef, position);
91 }
92 }
93
95 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
96 {
98
99 foreach (BadObject o in Left.Execute(context))
100 {
101 left = o;
102
103 yield return o;
104 }
105
106 if (left is not BadObjectReference leftRef)
107 {
108 throw new BadRuntimeException("Left side of -- must be a reference", Position);
109 }
110
111 foreach (BadObject o in DecrementWithOverride(context, leftRef, Position))
112 {
113 yield return o;
114 }
115 }
116}
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.
IEnumerable< BadExpression > GetDescendantsAndSelf()
Returns all Descendants of the Expression and the Expression itself.
BadSourcePosition Position
The source Position of the Expression.
IEnumerable< BadObject > Execute(BadExecutionContext context)
Evaluates the Expression within the current Execution Context.
bool IsConstant
Indicates if the expression stays constant at all times.
Implements the Post Decrement Expression.
override IEnumerable< BadExpression > GetDescendants()
static BadObject Decrement(BadObjectReference reference, BadSourcePosition position)
Executes the Operator.
BadPostDecrementExpression(BadExpression left, BadSourcePosition position)
Constructor of the Post Decrement Expression.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
static IEnumerable< BadObject > DecrementWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadSourcePosition position)
Executes the Operator.
readonly BadExpression Left
Left side of the expression.
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 Atomic 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.