BadScript 2
Loading...
Searching...
No Matches
BadVariableExpression.cs
Go to the documentation of this file.
7
9
14{
20 public BadVariableExpression(string name, BadSourcePosition position, params BadExpression[] genericParameters) : base(false, position)
21 {
22 Name = name;
23 GenericParameters = genericParameters;
24 }
25
29 public string Name { get; }
30
31 public IReadOnlyList<BadExpression> GenericParameters { get; }
32
34 public string? GetName()
35 {
36 return Name;
37 }
38
43 public override string ToString()
44 {
45 return Name;
46 }
47
49 public override IEnumerable<BadExpression> GetDescendants()
50 {
51 yield break;
52 }
53
55 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
56 {
57 if (!context.Scope.HasVariable(Name, context.Scope))
58 {
59 throw BadRuntimeException.Create(context.Scope, $"Variable '{Name}' is not defined", Position);
60 }
61 BadObjectReference obj = context.Scope.GetVariable(Name, context.Scope);
62
63 if (GenericParameters.Count != 0)
64 {
65 if (obj.Dereference() is not IBadGenericObject genType)
66 throw BadRuntimeException.Create(context.Scope, "Type is not generic", Position);
67
68 BadObject[] genParams = new BadObject[GenericParameters.Count];
69 for (int i = 0; i < GenericParameters.Count; i++)
70 {
71 foreach (BadObject? o in GenericParameters[i].Execute(context))
72 {
73 genParams[i] = o;
74 }
75
76 genParams[i] = genParams[i].Dereference();
77 }
78
79 yield return genType.CreateGeneric(genParams);
80 }
81 else
82 {
83 yield return obj;
84 }
85 }
86}
Describes a specific position inside a source file.
Base Implementation for all Expressions used inside the Script.
BadSourcePosition Position
The source Position of the Expression.
IEnumerable< BadObject > Execute(BadExecutionContext context)
Evaluates the Expression within the current Execution Context.
string? GetName()
Returns the Name of the Expression.The Name of the Expression
BadVariableExpression(string name, BadSourcePosition position, params BadExpression[] genericParameters)
Constructor of the Variable Expression.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
override string ToString()
Returns the String representation of the Variable Expression.
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
BadObjectReference GetVariable(string name, BadScope caller)
Returns the variable reference of the specified variable.
Definition BadScope.cs:1018
bool HasVariable(string name, BadScope caller)
returns true if the specified variable is defined in the current scope or any parent scope
Definition BadScope.cs:1072
static BadRuntimeException Create(BadScope? scope, string message)
Creates a new BadScriptException.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
Implements the base functionality for a BadScript Reference.
Gets inherited by all Expressions that have a Name(e.g. Variable Definitions, Function Definitions,...
Contains Shared Data Structures and Functionality.
Contains the Variable Expressions for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.
Contains Runtime Interface Objects.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.