BadScript 2
Loading...
Searching...
No Matches
BadNegationExpression.cs
Go to the documentation of this file.
6
8
13{
19 public BadNegationExpression(BadSourcePosition position, BadExpression expression) : base(
20 expression.IsConstant,
21 position
22 )
23 {
24 Expression = expression;
25 }
26
30 public BadExpression Expression { get; }
31
33 public override IEnumerable<BadExpression> GetDescendants()
34 {
36 }
37
46 public static IEnumerable<BadObject> NegateWithOverride(
47 BadExecutionContext? context,
48 BadObject left,
49 BadSourcePosition position)
50 {
52 {
54 left,
55 left,
56 context!,
58 position
59 ))
60 {
61 yield return o;
62 }
63 }
64 else
65 {
66 yield return Negate(left, position);
67 }
68 }
69
78 {
79 if (obj is IBadNumber num)
80 {
81 return BadObject.Wrap(-num.Value);
82 }
83
84 throw new BadRuntimeException($"Can not apply operator '-' to {obj}", pos);
85 }
86
88 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
89 {
91
92 foreach (BadObject o in Expression.Execute(context))
93 {
94 left = o;
95
96 yield return o;
97 }
98
99 left = left.Dereference();
100
101 foreach (BadObject o in NegateWithOverride(context, left, Position))
102 {
103 yield return o;
104 }
105 }
106
107
109 public override string ToString()
110 {
111 return $"-{Expression}";
112 }
113}
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.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
BadNegationExpression(BadSourcePosition position, BadExpression expression)
Creates a new Negation Expression.
static IEnumerable< BadObject > NegateWithOverride(BadExecutionContext? context, BadObject left, BadSourcePosition position)
Executes the Operator.
static BadObject Negate(BadObject obj, BadSourcePosition pos)
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 Interface for Native Numbers.
Definition IBadNumber.cs:7
Contains Shared Data Structures and Functionality.
Contains the 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.