BadScript 2
Loading...
Searching...
No Matches
BadPreDecrementExpression.cs
Go to the documentation of this file.
6
8
13{
17 public readonly BadExpression Right;
18
25 right.IsConstant,
26 position
27 )
28 {
29 Right = right;
30 }
31
33 public override IEnumerable<BadExpression> GetDescendants()
34 {
36 }
37
45 public static BadObject Decrement(BadObjectReference reference, BadSourcePosition position)
46 {
47 BadObject right = reference.Dereference();
48
49 if (right is not IBadNumber leftNumber)
50 {
51 throw new BadRuntimeException("Right side of -- must be a number", position);
52 }
53
54 BadObject r = leftNumber.Value - 1;
55 reference.Set(r);
56
57 return r;
58 }
59
61 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
62 {
63 BadObject right = BadObject.Null;
64
65 foreach (BadObject o in Right.Execute(context))
66 {
67 right = o;
68
69 yield return o;
70 }
71
72 if (right is not BadObjectReference rightRef)
73 {
74 throw new BadRuntimeException("Right side of -- must be a reference", Position);
75 }
76
77 foreach (BadObject o in DecrementWithOverride(context, rightRef, Position))
78 {
79 yield return o;
80 }
81 }
82
91 public static IEnumerable<BadObject> DecrementWithOverride(
92 BadExecutionContext? context,
93 BadObjectReference leftRef,
94 BadSourcePosition position)
95 {
96 BadObject left = leftRef.Dereference();
97
99 {
101 left,
102 context!,
104 position
105 ))
106 {
107 yield return o;
108 }
109 }
110 else
111 {
112 yield return Decrement(leftRef, position);
113 }
114 }
115}
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.
static BadObject Decrement(BadObjectReference reference, BadSourcePosition position)
Executes the Operator.
BadPreDecrementExpression(BadExpression right, BadSourcePosition position)
Constructor of the Pre Decrement Expression.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
static IEnumerable< BadObject > DecrementWithOverride(BadExecutionContext? context, BadObjectReference leftRef, BadSourcePosition position)
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 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.