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(expression.IsConstant,
20 position
21 )
22 {
23 Expression = expression;
24 }
25
29 public BadExpression Expression { get; }
30
32 public override IEnumerable<BadExpression> GetDescendants()
33 {
35 }
36
45 public static IEnumerable<BadObject> NegateWithOverride(BadExecutionContext? context,
46 BadObject left,
47 BadSourcePosition position)
48 {
50 {
51 foreach (BadObject o in ExecuteOperatorOverride(left,
52 left,
53 context!,
55 position
56 ))
57 {
58 yield return o;
59 }
60 }
61 else
62 {
63 yield return Negate(left, position);
64 }
65 }
66
75 {
76 if (obj is IBadNumber num)
77 {
78 return BadObject.Wrap(-num.Value);
79 }
80
81 throw new BadRuntimeException($"Can not apply operator '-' to {obj}", pos);
82 }
83
85 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
86 {
88
89 foreach (BadObject o in Expression.Execute(context))
90 {
91 left = o;
92
93 yield return o;
94 }
95
96 left = left.Dereference(Position);
97
98 foreach (BadObject o in NegateWithOverride(context, left, Position))
99 {
100 yield return o;
101 }
102 }
103
104
106 public override string ToString()
107 {
108 return $"-{Expression}";
109 }
110}
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:130
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.