BadScript 2
Loading...
Searching...
No Matches
BadMultiplyExpression.cs
Go to the documentation of this file.
6
8
13{
20 public BadMultiplyExpression(BadExpression left, BadExpression right, BadSourcePosition position) : base(left,
21 right,
22 position
23 ) { }
24
26 protected override string GetSymbol()
27 {
28 return "*";
29 }
30
39 public static BadObject Mul(BadObject left, BadObject right, BadSourcePosition pos)
40 {
41 if (left is not IBadNumber lNum)
42 {
43 throw new BadRuntimeException($"Can not apply operator '*' to {left} and {right}", pos);
44 }
45
46 if (right is IBadNumber rNum)
47 {
48 return BadObject.Wrap(lNum.Value * rNum.Value);
49 }
50
51 throw new BadRuntimeException($"Can not apply operator '*' to {left} and {right}", pos);
52 }
53
55 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
56 {
58
59 foreach (BadObject o in Left.Execute(context))
60 {
61 left = o;
62
63 yield return o;
64 }
65
66 left = left.Dereference(Position);
67 BadObject right = BadObject.Null;
68
69 foreach (BadObject o in Right.Execute(context))
70 {
71 right = o;
72
73 yield return o;
74 }
75
76 right = right.Dereference(Position);
77
78 foreach (BadObject? o in MulWithOverride(context, left, right, Position))
79 {
80 yield return o;
81 }
82 }
83
93 public static IEnumerable<BadObject> MulWithOverride(BadExecutionContext? context,
94 BadObject left,
95 BadObject right,
96 BadSourcePosition position)
97 {
99 {
100 foreach (BadObject o in ExecuteOperatorOverride(left,
101 right,
102 context!,
104 position
105 ))
106 {
107 yield return o;
108 }
109 }
110 else
111 {
112 yield return Mul(left, right, 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.
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: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.