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
58 BadInstruction[] instructions,
59 bool useOverrides,
60 BadScope parentScope,
61 BadSourcePosition position,
62 BadWordToken? name,
63 bool isConstant,
64 bool isStatic,
65 BadMetaData? metaData,
66 BadClassPrototype returnType,
67 bool isSingleLine,
68 params BadFunctionParameter[] parameters) : base(
69 name,
70 isConstant,
71 isStatic,
72 returnType,
73 isSingleLine,
74 parameters
75 )
76 {
77 m_Instructions = instructions;
78 m_UseOverrides = useOverrides;
79 m_ParentScope = parentScope;
80 m_Position = position;
81 MetaData = metaData ?? BadMetaData.Empty;
83 }
84
86 public override BadMetaData MetaData { get; }
87
89 {
92 "Compiled Function",
93 caller.Scope,
94 null,
95 BadScopeFlags.Returnable | BadScopeFlags.AllowThrow | BadScopeFlags.CaptureThrow
96 )
97 );
98 ApplyParameters(ctx, args, m_Position);
99 return ctx;
100 }
101
103 protected override IEnumerable<BadObject> InvokeBlock(BadObject[] args, BadExecutionContext caller)
104 {
105 using BadExecutionContext ctx = CreateExecutionContext(caller, args);
106
107 if (m_Instructions.Length == 0)
108 {
109 yield return Null;
110
111 yield break;
112 }
113
115
116 foreach (BadObject o in vm.Execute(ctx))
117 {
118 yield return o;
119 }
120
121 if (ctx.Scope.ReturnValue != null)
122 {
123 yield return ctx.Scope.ReturnValue;
124 }
125 else
126 {
127 yield return Null;
128 }
129
130 }
131
136 private string MakeSignature()
137 {
138 string str = base.ToString() + " at " + m_Position.GetPositionInfo() + '\n';
139
140 for (int i = 0; i < m_Instructions.Length; i++)
141 {
142 str += i + ":\t" + m_Instructions[i] + '\n';
143 }
144
145 return str;
146 }
147
149 public override string ToString()
150 {
151 return m_StringSignature;
152 }
153}
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:238
BadScope CreateChild(string name, BadScope? caller, bool? useVisibility, BadScopeFlags flags=BadScopeFlags.RootScope)
Creates a subscope of the current scope.
Definition BadScope.cs:792
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.