blob: 5a2f9bef090e4211355c4264882e306fa758929a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSO
{
public partial class LSL_BaseClass
{
/*
* OPCODES
*
* These are internal "assembly" commands,
* basic operators like "ADD", "PUSH" and "POP"
*
* It also contains managed stack and keeps track of internal variables, etc.
*
*/
public void StoreToLocal(UInt32 index)
{
// TODO: How to determine local?
Common.SendToDebug("::StoreToLocal " + index);
if (LocalVariables.ContainsKey(index))
LocalVariables.Remove(index);
LocalVariables.Add(index, LSLStack.Peek());
}
public void StoreToGlobal(UInt32 index)
{
Common.SendToDebug("::StoreToGlobal " + index);
if (GlobalVariables.ContainsKey(index))
GlobalVariables.Remove(index);
GlobalVariables.Add(index, LSLStack.Peek());
}
public void StoreToStatic(UInt32 index)
{
Common.SendToDebug("::StoreToStatic " + index);
//if (StaticVariables.ContainsKey(index))
// StaticVariables.Remove(index);
StaticVariables.Add(index, LSLStack.Peek());
}
public void GetFromLocal(UInt32 index)
{
// TODO: How to determine local?
Common.SendToDebug("::GetFromLocal " + index);
object ret;
LocalVariables.TryGetValue(index, out ret);
LSLStack.Push(ret);
//return ret;
}
public void GetFromGlobal(UInt32 index)
{
Common.SendToDebug("::GetFromGlobal " + index);
object ret;
GlobalVariables.TryGetValue(index, out ret);
LSLStack.Push(ret);
//return ret;
}
public void GetFromStatic(UInt32 index)
{
Common.SendToDebug("::GetFromStatic " + index);
object ret;
StaticVariables.TryGetValue(index, out ret);
Common.SendToDebug("::GetFromStatic - ObjectType: " + ret.GetType().ToString());
LSLStack.Push(ret);
//return ret;
}
public object POPToStack()
{
Common.SendToDebug("::POPToStack");
//return LSLStack.Pop();
object p = LSLStack.Pop();
if (p.GetType() == typeof(UInt32))
return (UInt32)p;
if (p.GetType() == typeof(string))
return (string)p;
if (p.GetType() == typeof(Int32))
return (Int32)p;
if (p.GetType() == typeof(UInt16))
return (UInt16)p;
if (p.GetType() == typeof(float))
return (float)p;
if (p.GetType() == typeof(LSO_Enums.Vector))
return (LSO_Enums.Vector)p;
if (p.GetType() == typeof(LSO_Enums.Rotation))
return (LSO_Enums.Rotation)p;
if (p.GetType() == typeof(LSO_Enums.Key))
return (LSO_Enums.Key)p;
return p;
}
//public object POPToStack(UInt32 count)
//{
// // POP NUMBER FROM TOP OF STACK
// //LSLStack.SetLength(LSLStack.Length - 4);
// Common.SendToDebug("::POPToStack " + count);
// if (count < 2)
// return LSLStack.Pop();
// Stack<object> s = new Stack<object>();
// for (int i = 0; i < count; i++)
// {
// s.Push(LSLStack.Pop);
// }
//}
public void POP()
{
// POP NUMBER FROM TOP OF STACK
//LSLStack.SetLength(LSLStack.Length - 4);
Common.SendToDebug("::POP");
if (LSLStack.Count < 1)
{
//TODO: Temporary fix
Common.SendToDebug("ERROR: TRYING TO POP EMPTY STACK!");
}
else
{
LSLStack.Pop();
}
}
public void PUSH(object Param)
{
if (Param == null)
{
Common.SendToDebug("::PUSH: <null>");
}
else
{
//Common.SendToDebug("::PUSH: " + Param.GetType());
}
LSLStack.Push(Param);
}
public void ADD(UInt32 Param)
{
Common.SendToDebug("::ADD: " + Param);
object o2 = LSLStack.Pop();
object o1 = LSLStack.Pop();
Common.SendToDebug("::ADD: Debug: o1: " + o1.GetType() + " (" + o1.ToString() + "), o2: " + o2.GetType() + " (" + o2.ToString() + ")");
if (o2.GetType() == typeof(string))
{
LSLStack.Push((string)o1 + (string)o2);
return;
}
if (o2.GetType() == typeof(UInt32))
{
LSLStack.Push((UInt32)o1 + (UInt32)o2);
return;
}
}
public void SUB(UInt32 Param)
{
Common.SendToDebug("::SUB: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 - i2));
}
public void MUL(UInt32 Param)
{
Common.SendToDebug("::SUB: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 * i2));
}
public void DIV(UInt32 Param)
{
Common.SendToDebug("::DIV: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 / i2));
}
public void MOD(UInt32 Param)
{
Common.SendToDebug("::MOD: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 % i2));
}
public void EQ(UInt32 Param)
{
Common.SendToDebug("::EQ: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
if (i1 == i2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void NEQ(UInt32 Param)
{
Common.SendToDebug("::NEQ: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
if (i1 != i2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void LEQ(UInt32 Param)
{
Common.SendToDebug("::LEQ: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
if (i1 <= i2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void GEQ(UInt32 Param)
{
Common.SendToDebug("::GEQ: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
if (i1 >= i2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void LESS(UInt32 Param)
{
Common.SendToDebug("::LESS: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
if (i1 < i2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void GREATER(UInt32 Param)
{
Common.SendToDebug("::GREATER: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
if (i1 > i2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void BITAND()
{
Common.SendToDebug("::BITAND");
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 & i2));
}
public void BITOR()
{
Common.SendToDebug("::BITOR");
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 | i2));
}
public void BITXOR()
{
Common.SendToDebug("::BITXOR");
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 ^ i2));
}
public void BOOLAND()
{
Common.SendToDebug("::BOOLAND");
bool b2 = bool.Parse((string)LSLStack.Pop());
bool b1 = bool.Parse((string)LSLStack.Pop());
if (b1 && b2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void BOOLOR()
{
Common.SendToDebug("::BOOLOR");
bool b2 = bool.Parse((string)LSLStack.Pop());
bool b1 = bool.Parse((string)LSLStack.Pop());
if (b1 || b2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void NEG(UInt32 Param)
{
Common.SendToDebug("::NEG: " + Param);
//UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 * -1));
}
public void BITNOT()
{
//Common.SendToDebug("::BITNOT");
//UInt32 i2 = (UInt32)LSLStack.Pop();
//UInt32 i1 = (UInt32)LSLStack.Pop();
//LSLStack.Push((UInt32)(i1 / i2));
}
public void BOOLNOT()
{
//Common.SendToDebug("::BOOLNOT");
////UInt32 i2 = (UInt32)LSLStack.Pop();
//UInt32 i1 = (UInt32)LSLStack.Pop();
//LSLStack.Push((UInt32)(i1));
}
}
}
|