ScriptStack 1.0.5
Loading...
Searching...
No Matches
ScriptStack.Runtime.Operand Class Reference

Public Member Functions

override string ToString ()

Static Public Member Functions

static Operand Literal (object val)
static Operand Variable (string identifier)
static Operand MemberVariable (string identifier, object val)
static Operand CreatePointer (string identifier, string pointer)
static Operand AllocateInstructionPointer (Instruction instruction)
static Operand AllocateFunctionPointer (Function function)
static Operand AllocateRoutinePointer (Routine routine)

Properties

OperandType Type [get, set]
object Value [get]
object Member [get, set]
string Pointer [get, set]
Instruction InstructionPointer [get, set]
Function FunctionPointer [get, set]
Routine RoutinePointer [get, set]

Private Member Functions

 Operand (OperandType operandType, object objectValue, object objectIndex)
string ToString (object objectValue)
string ToLiteral (string input)

Private Attributes

OperandType m_operandType
object m_objectValue
object m_objectIndex

Detailed Description

Definition at line 22 of file Operand.cs.

Constructor & Destructor Documentation

◆ Operand()

ScriptStack.Runtime.Operand.Operand ( OperandType operandType,
object objectValue,
object objectIndex )
private

Definition at line 35 of file Operand.cs.

36 {
37 m_operandType = operandType;
38 m_objectValue = objectValue;
39 m_objectIndex = objectIndex;
40 }

References m_objectIndex, m_objectValue, and m_operandType.

Referenced by AllocateFunctionPointer(), AllocateInstructionPointer(), AllocateRoutinePointer(), CreatePointer(), Literal(), MemberVariable(), and Variable().

Member Function Documentation

◆ AllocateFunctionPointer()

Operand ScriptStack.Runtime.Operand.AllocateFunctionPointer ( Function function)
static

Definition at line 79 of file Operand.cs.

80 {
81 return new Operand(OperandType.FunctionPointer, function, null);
82 }

References Operand().

Referenced by ScriptStack.Compiler.Parser.FunctionCall().

◆ AllocateInstructionPointer()

Operand ScriptStack.Runtime.Operand.AllocateInstructionPointer ( Instruction instruction)
static

◆ AllocateRoutinePointer()

Operand ScriptStack.Runtime.Operand.AllocateRoutinePointer ( Routine routine)
static

Definition at line 84 of file Operand.cs.

85 {
86 return new Operand(OperandType.RoutinePointer, routine, null);
87 }

References Operand().

Referenced by ScriptStack.Compiler.Parser.RoutineCall().

◆ CreatePointer()

Operand ScriptStack.Runtime.Operand.CreatePointer ( string identifier,
string pointer )
static

◆ Literal()

◆ MemberVariable()

Operand ScriptStack.Runtime.Operand.MemberVariable ( string identifier,
object val )
static

◆ ToLiteral()

string ScriptStack.Runtime.Operand.ToLiteral ( string input)
private

Definition at line 93 of file Operand.cs.

94 {
95
96 var literal = new StringBuilder(input.Length + 2);
97
98 foreach (var c in input)
99 {
100
101 switch (c)
102 {
103
104 case '\"':
105 literal.Append("\\\"");
106 break;
107
108 case '\a':
109 literal.Append("\\a");
110 break;
111
112 case '\b':
113 literal.Append("\\b");
114 break;
115
116 case '\n':
117 literal.Append("\\n");
118 break;
119
120 case '\r':
121 literal.Append("\\r");
122 break;
123
124 case '\t':
125 literal.Append("\\t");
126 break;
127
128 default:
129 if (char.GetUnicodeCategory(c) != System.Globalization.UnicodeCategory.Control)
130 literal.Append(c);
131 else
132 {
133 literal.Append(@"\u");
134 literal.Append(((ushort)c).ToString("x4"));
135 }
136 break;
137
138 }
139
140 }
141
142 return literal.ToString();
143
144 }

References ToString().

Referenced by ToString().

◆ ToString() [1/2]

override string ScriptStack.Runtime.Operand.ToString ( )

Definition at line 146 of file Operand.cs.

147 {
148
149 switch (m_operandType)
150 {
151
152 case OperandType.Literal:
153 {
154
155 // \todo improve
156 if (m_objectValue.GetType().ToString() == "System.String")
157 return ToLiteral((string)m_objectValue);
158
159 else if (m_objectValue.GetType().ToString() == "System.Char")
160 return ToLiteral("" + (char)m_objectValue);
161
162 else
163 return ToString(m_objectValue);
164
165 }
166
167 case OperandType.Variable:
168 return m_objectValue.ToString();
169
170 case OperandType.Member:
171 return m_objectValue + "[" + ToString(m_objectIndex) + "]";
172
173 case OperandType.Pointer:
174 return m_objectValue + "[" + m_objectIndex + "]";
175
176 case OperandType.InstructionPointer:
177 return "[" + ((Instruction) m_objectValue).Address.ToString("X8") + "]";
178
179 case OperandType.FunctionPointer:
180 {
181 Function scriptFunction = (Function)m_objectValue;
182 return "<" + scriptFunction.Name + "@" + scriptFunction.EntryPoint.Address.ToString("X8") + ">";
183 }
184
185 case OperandType.RoutinePointer:
186 return m_objectValue.ToString();
187
188 default:
189 return ToLiteral(m_operandType.ToString());
190
191 }
192 }

References ScriptStack.Runtime.Instruction.Address, ScriptStack.Runtime.Function.EntryPoint, m_objectIndex, m_objectValue, m_operandType, ToLiteral(), and ToString().

Referenced by ToLiteral(), and ToString().

◆ ToString() [2/2]

string ScriptStack.Runtime.Operand.ToString ( object objectValue)
private

Definition at line 42 of file Operand.cs.

43 {
44 if (objectValue.GetType() == typeof(string))
45 return "\"" + objectValue + "\"";
46 else
47 return objectValue.ToString();
48 }

◆ Variable()

Operand ScriptStack.Runtime.Operand.Variable ( string identifier)
static

Definition at line 59 of file Operand.cs.

60 {
61 return new Operand(OperandType.Variable, identifier, null);
62 }

References Operand().

Referenced by ScriptStack.Compiler.Parser.AccessChain(), ScriptStack.Compiler.Parser.AccessChainAssignment(), ScriptStack.Compiler.Parser.AllocateVariable(), ScriptStack.Compiler.Parser.And(), ScriptStack.Compiler.Parser.Arithmetic(), ScriptStack.Compiler.Parser.ArrayAssignment(), ScriptStack.Compiler.Parser.Atom(), ScriptStack.Compiler.Parser.BinaryAnd(), ScriptStack.Compiler.Parser.BinaryNot(), ScriptStack.Compiler.Parser.BinaryNotAssign(), ScriptStack.Compiler.Parser.BinaryOr(), ScriptStack.Compiler.Parser.BitwiseAnd(), ScriptStack.Compiler.Parser.BitwiseOr(), ScriptStack.Compiler.Parser.BitwiseXor(), ScriptStack.Compiler.Parser.BraceArray(), ScriptStack.Compiler.Parser.BracketArray(), ScriptStack.Compiler.Parser.Factor(), ScriptStack.Compiler.Parser.For(), ScriptStack.Compiler.Parser.ForEach(), ScriptStack.Compiler.Parser.FunctionCall(), ScriptStack.Compiler.Parser.FunctionDeclaration(), ScriptStack.Compiler.Parser.If(), ScriptStack.Compiler.Parser.LockedStatementList(), ScriptStack.Compiler.Parser.Member(), ScriptStack.Compiler.Parser.MemberAssignment(), ScriptStack.Compiler.Parser.Not(), ScriptStack.Compiler.Parser.Notify(), ScriptStack.Compiler.Parser.Or(), ScriptStack.Compiler.Parser.Pointer(), ScriptStack.Compiler.Parser.PostDecrement(), ScriptStack.Compiler.Parser.PostIncrement(), ScriptStack.Compiler.Parser.PreDecrement(), ScriptStack.Compiler.Parser.PreIncrement(), ScriptStack.Compiler.Parser.Relation(), ScriptStack.Compiler.Parser.Return(), ScriptStack.Compiler.Parser.RoutineCall(), ScriptStack.Compiler.Parser.ShiftLeft(), ScriptStack.Compiler.Parser.ShiftRight(), ScriptStack.Compiler.Parser.Switch(), ScriptStack.Compiler.Parser.Term(), ScriptStack.Compiler.Parser.VariableAssignment(), ScriptStack.Compiler.Parser.VariableDeclaration(), ScriptStack.Compiler.Parser.Wait(), ScriptStack.Compiler.Parser.While(), and ScriptStack.Compiler.Parser.Xor().

Member Data Documentation

◆ m_objectIndex

object ScriptStack.Runtime.Operand.m_objectIndex
private

Definition at line 29 of file Operand.cs.

Referenced by Operand(), and ToString().

◆ m_objectValue

object ScriptStack.Runtime.Operand.m_objectValue
private

Definition at line 28 of file Operand.cs.

Referenced by Operand(), and ToString().

◆ m_operandType

OperandType ScriptStack.Runtime.Operand.m_operandType
private

Definition at line 27 of file Operand.cs.

Referenced by Operand(), and ToString().

Property Documentation

◆ FunctionPointer

Function ScriptStack.Runtime.Operand.FunctionPointer
getset

Definition at line 259 of file Operand.cs.

260 {
261 get
262 {
263 if (m_operandType != OperandType.FunctionPointer)
264 throw new ParserException("Error in function call.");
265
266 return (Function)m_objectValue;
267 }
268 set
269 {
270 if (m_operandType != OperandType.FunctionPointer)
271 throw new ParserException("Error in function call.");
272
273 m_objectValue = value;
274 }
275 }

◆ InstructionPointer

Instruction ScriptStack.Runtime.Operand.InstructionPointer
getset

Definition at line 241 of file Operand.cs.

242 {
243 get
244 {
245 if (m_operandType != OperandType.InstructionPointer)
246 throw new ParserException("Error in instruction access.");
247
248 return (Instruction) m_objectValue;
249 }
250 set
251 {
252 if (m_operandType != OperandType.InstructionPointer)
253 throw new ParserException("Error in instruction access.");
254
255 m_objectValue = value;
256 }
257 }

Referenced by ScriptStack.Runtime.Executable.Clean().

◆ Member

object ScriptStack.Runtime.Operand.Member
getset

Definition at line 209 of file Operand.cs.

210 {
211 get
212 {
213 if (m_operandType != OperandType.Member)
214 throw new ExecutionException("Error in member access.");
215 return m_objectIndex;
216 }
217 set
218 {
219 if (m_operandType != OperandType.Member)
220 throw new ExecutionException("Error in member access.");
221 m_objectIndex = value;
222 }
223 }

Referenced by ScriptStack.Runtime.Interpreter.Assignment(), and ScriptStack.Runtime.Interpreter.Evaluate().

◆ Pointer

string ScriptStack.Runtime.Operand.Pointer
getset

Definition at line 225 of file Operand.cs.

226 {
227 get
228 {
229 if (m_operandType != OperandType.Pointer)
230 throw new ExecutionException("Error in array access.");
231 return (string) m_objectIndex;
232 }
233 set
234 {
235 if (m_operandType != OperandType.Pointer)
236 throw new ExecutionException("Error in array access.");
237 m_objectIndex = value;
238 }
239 }

Referenced by ScriptStack.Runtime.Interpreter.Assignment(), and ScriptStack.Runtime.Interpreter.Evaluate().

◆ RoutinePointer

Routine ScriptStack.Runtime.Operand.RoutinePointer
getset

Definition at line 277 of file Operand.cs.

278 {
279
280 get
281 {
282 if (m_operandType != OperandType.RoutinePointer)
283 throw new ParserException("Error in routine access.");
284
285 return (Routine)m_objectValue;
286 }
287 set
288 {
289 if (m_operandType != OperandType.RoutinePointer)
290 throw new ParserException("Error in routine access.");
291
292 m_objectValue = value;
293 }
294
295 }

◆ Type

◆ Value


The documentation for this class was generated from the following file: