BadScript 2
Loading...
Searching...
No Matches
BadCompiledFunction.cs
Go to the documentation of this file.
7
12
17{
21 private readonly BadInstruction[] m_Instructions;
22
26 private readonly BadScope m_ParentScope;
27
31 private readonly BadSourcePosition m_Position;
32
36 private readonly string m_StringSignature;
37
41 private readonly bool m_UseOverrides;
42
57 public BadCompiledFunction(BadInstruction[] instructions,
58 bool useOverrides,
59 BadScope parentScope,
60 BadSourcePosition position,
61 BadWordToken? name,
62 bool isConstant,
63 bool isStatic,
64 BadMetaData? metaData,
65 BadClassPrototype returnType,
66 bool isSingleLine,
67 params BadFunctionParameter[] parameters) : base(name,
68 isConstant,
69 isStatic,
70 returnType,
71 isSingleLine,
72 parameters
73 )
74 {
75 m_Instructions = instructions;
76 m_UseOverrides = useOverrides;
77 m_ParentScope = parentScope;
78 m_Position = position;
79 MetaData = metaData ?? BadMetaData.Empty;
81 }
82
84 public override BadMetaData MetaData { get; }
85
87 {
89 caller.Scope,
90 null,
91 BadScopeFlags.Returnable |
92 BadScopeFlags.AllowThrow |
93 BadScopeFlags.CaptureThrow
94 )
95 );
96 ApplyParameters(ctx, args, m_Position);
97
98 return ctx;
99 }
100
102 protected override IEnumerable<BadObject> InvokeBlock(BadObject[] args, BadExecutionContext caller)
103 {
104 using BadExecutionContext ctx = CreateExecutionContext(caller, args);
105
106 if (m_Instructions.Length == 0)
107 {
108 yield return Null;
109
110 yield break;
111 }
112
114
115 foreach (BadObject o in vm.Execute(ctx))
116 {
117 yield return o;
118 }
119
120 if (ctx.Scope.ReturnValue != null)
121 {
122 yield return ctx.Scope.ReturnValue;
123 }
124 else
125 {
126 yield return Null;
127 }
128 }
129
134 private string MakeSignature()
135 {
136 string str = base.ToString() + " at " + m_Position.GetPositionInfo() + '\n';
137
138 for (int i = 0; i < m_Instructions.Length; i++)
139 {
140 str += i + ":\t" + m_Instructions[i] + '\n';
141 }
142
143 return str;
144 }
145
147 public override string ToString()
148 {
149 return m_StringSignature;
150 }
151}
Describes a specific position inside a source file.
string GetPositionInfo()
Returns position info. Format: file://[FileName] : Line [Line].
Implements a Meta Data container for an expression.
static readonly BadMetaData Empty
An empty Meta Data object.
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
Implements the Scope for the Script Engine.
Definition BadScope.cs:16
BadScope CreateChild(string name, BadScope? caller, bool? useVisibility, BadScopeFlags flags=BadScopeFlags.RootScope)
Creates a subscope of the current scope.
Definition BadScope.cs:597
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements a function that can be called from the script.
static void ApplyParameters(string funcStr, BadFunctionParameter[] parameters, BadExecutionContext context, BadObject[] args, BadSourcePosition? position=null)
Applies the function arguments to the context of the function.
Implements a Class Prototype for the BadScript Language.
readonly bool m_UseOverrides
Indicates if the Function should use Operator Overrides.
BadExecutionContext CreateExecutionContext(BadExecutionContext caller, BadObject[] args)
string MakeSignature()
Creates a Signature for this Function.
readonly BadScope m_ParentScope
The Compiled Function's Parent Scope.
readonly BadSourcePosition m_Position
The Original Source Position.
BadCompiledFunction(BadInstruction[] instructions, bool useOverrides, BadScope parentScope, BadSourcePosition position, BadWordToken? name, bool isConstant, bool isStatic, BadMetaData? metaData, BadClassPrototype returnType, bool isSingleLine, params BadFunctionParameter[] parameters)
Creates a new BadCompiledFunction instance.
readonly BadInstruction[] m_Instructions
The Compiled Function's Instructions.
override IEnumerable< BadObject > InvokeBlock(BadObject[] args, BadExecutionContext caller)
Implements a Virtual Machine for the BadScript Language.
Contains Shared Data Structures and Functionality.
Contains the Parser for the BadScript2 Language.
Contains the Reader Tokens for the BadScript2 Language.
Contains Runtime Function Objects.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Virtual Machine Implementation.
BadScopeFlags
Defines Different Behaviours for the Current Scope.
Implements a single instruction for the BadVirtualMachine.