BadScript 2
Loading...
Searching...
No Matches
BadModulusExpression.cs
Go to the documentation of this file.
6
8
13{
21 left,
22 right,
23 position
24 ) { }
25
27 protected override string GetSymbol()
28 {
29 return "%";
30 }
31
40 public static BadObject Mod(BadObject left, BadObject right, BadSourcePosition pos)
41 {
42 if (left is IBadNumber lNum && right is IBadNumber rNum)
43 {
44 return BadObject.Wrap(lNum.Value % rNum.Value);
45 }
46
47 throw new BadRuntimeException($"Can not apply operator '%' to {left} and {right}", pos);
48 }
49
59 public static IEnumerable<BadObject> ModWithOverride(
60 BadExecutionContext? context,
61 BadObject left,
62 BadObject right,
63 BadSourcePosition position)
64 {
66 {
68 left,
69 right,
70 context!,
72 position
73 ))
74 {
75 yield return o;
76 }
77 }
78 else
79 {
80 yield return Mod(left, right, position);
81 }
82 }
83
85 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
86 {
88
89 foreach (BadObject o in Left.Execute(context))
90 {
91 left = o;
92
93 yield return o;
94 }
95
96 left = left.Dereference();
97 BadObject right = BadObject.Null;
98
99 foreach (BadObject o in Right.Execute(context))
100 {
101 right = o;
102
103 yield return o;
104 }
105
106 right = right.Dereference();
107
108 foreach (BadObject? o in ModWithOverride(context, left, right, Position))
109 {
110 yield return o;
111 }
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.
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.
BadModulusExpression(BadExpression left, BadExpression right, BadSourcePosition position)
Constructor of the Modulus Expression.
static BadObject Mod(BadObject left, BadObject right, BadSourcePosition pos)
Performs the Modulus Operation on left and right.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
static IEnumerable< BadObject > ModWithOverride(BadExecutionContext? context, BadObject left, BadObject right, BadSourcePosition position)
Executes the Operator with operator overrides.
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.