BadScript 2
Loading...
Searching...
No Matches
BadMultiplyExpression.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 Mul(BadObject left, BadObject right, BadSourcePosition pos)
41 {
42 if (left is not IBadNumber lNum)
43 {
44 throw new BadRuntimeException($"Can not apply operator '*' to {left} and {right}", pos);
45 }
46
47 if (right is IBadNumber rNum)
48 {
49 return BadObject.Wrap(lNum.Value * rNum.Value);
50 }
51
52 throw new BadRuntimeException($"Can not apply operator '*' to {left} and {right}", pos);
53 }
54
56 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
57 {
59
60 foreach (BadObject o in Left.Execute(context))
61 {
62 left = o;
63
64 yield return o;
65 }
66
67 left = left.Dereference();
68 BadObject right = BadObject.Null;
69
70 foreach (BadObject o in Right.Execute(context))
71 {
72 right = o;
73
74 yield return o;
75 }
76
77 right = right.Dereference();
78
79 foreach (BadObject? o in MulWithOverride(context, left, right, Position))
80 {
81 yield return o;
82 }
83 }
84
94 public static IEnumerable<BadObject> MulWithOverride(
95 BadExecutionContext? context,
96 BadObject left,
97 BadObject right,
98 BadSourcePosition position)
99 {
101 {
103 left,
104 right,
105 context!,
107 position
108 ))
109 {
110 yield return o;
111 }
112 }
113 else
114 {
115 yield return Mul(left, right, position);
116 }
117 }
118}
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.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
BadMultiplyExpression(BadExpression left, BadExpression right, BadSourcePosition position)
Constructor of the Multiply Expression.
static IEnumerable< BadObject > MulWithOverride(BadExecutionContext? context, BadObject left, BadObject right, BadSourcePosition position)
Executes the Operator with operator overrides.
static BadObject Mul(BadObject left, BadObject right, BadSourcePosition pos)
Performs the Multiplication Operation on left and right.
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.