diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/LSO_Parser.cs | 208 |
1 files changed, 107 insertions, 101 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/LSO_Parser.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/LSO_Parser.cs index ba97375..a0b4977f 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/LSO_Parser.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/LSO_Parser.cs | |||
@@ -27,15 +27,16 @@ | |||
27 | */ | 27 | */ |
28 | /* Original code: Tedd Hansen */ | 28 | /* Original code: Tedd Hansen */ |
29 | using System; | 29 | using System; |
30 | using System.Collections; | ||
30 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
31 | using System.Text; | ||
32 | using System.IO; | 32 | using System.IO; |
33 | using System.Reflection; | 33 | using System.Reflection; |
34 | using System.Reflection.Emit; | 34 | using System.Reflection.Emit; |
35 | using System.Text; | ||
35 | 36 | ||
36 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | 37 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO |
37 | { | 38 | { |
38 | partial class LSO_Parser | 39 | internal partial class LSO_Parser |
39 | { | 40 | { |
40 | private string FileName; | 41 | private string FileName; |
41 | private FileStream fs; | 42 | private FileStream fs; |
@@ -45,7 +46,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
45 | //private System.Collections.Hashtable StaticBlocks = new System.Collections.Hashtable(); | 46 | //private System.Collections.Hashtable StaticBlocks = new System.Collections.Hashtable(); |
46 | 47 | ||
47 | private TypeBuilder typeBuilder; | 48 | private TypeBuilder typeBuilder; |
48 | private System.Collections.Generic.List<string> EventList = new System.Collections.Generic.List<string>(); | 49 | private List<string> EventList = new List<string>(); |
49 | 50 | ||
50 | public LSO_Parser(string _FileName, TypeBuilder _typeBuilder) | 51 | public LSO_Parser(string _FileName, TypeBuilder _typeBuilder) |
51 | { | 52 | { |
@@ -59,11 +60,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
59 | Common.SendToDebug("Opening filename: " + FileName); | 60 | Common.SendToDebug("Opening filename: " + FileName); |
60 | fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.Read); | 61 | fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.Read); |
61 | br = new BinaryReader(fs, Encoding.BigEndianUnicode); | 62 | br = new BinaryReader(fs, Encoding.BigEndianUnicode); |
62 | |||
63 | } | 63 | } |
64 | |||
64 | internal void CloseFile() | 65 | internal void CloseFile() |
65 | { | 66 | { |
66 | |||
67 | // Close | 67 | // Close |
68 | br.Close(); | 68 | br.Close(); |
69 | fs.Close(); | 69 | fs.Close(); |
@@ -75,9 +75,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
75 | /// </summary> | 75 | /// </summary> |
76 | public void Parse() | 76 | public void Parse() |
77 | { | 77 | { |
78 | |||
79 | |||
80 | |||
81 | // The LSO Format consist of 6 major blocks: header, statics, functions, states, heap, and stack. | 78 | // The LSO Format consist of 6 major blocks: header, statics, functions, states, heap, and stack. |
82 | 79 | ||
83 | 80 | ||
@@ -148,14 +145,14 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
148 | LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock(); | 145 | LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock(); |
149 | myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0); | 146 | myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0); |
150 | myStaticBlock.ObjectType = br_read(1)[0]; | 147 | myStaticBlock.ObjectType = br_read(1)[0]; |
151 | Common.SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString()); | 148 | Common.SendToDebug("Static Block ObjectType: " + |
149 | ((LSO_Enums.Variable_Type_Codes) myStaticBlock.ObjectType).ToString()); | ||
152 | myStaticBlock.Unknown = br_read(1)[0]; | 150 | myStaticBlock.Unknown = br_read(1)[0]; |
153 | // Size of datatype varies -- what about strings? | 151 | // Size of datatype varies -- what about strings? |
154 | if (myStaticBlock.ObjectType != 0) | 152 | if (myStaticBlock.ObjectType != 0) |
155 | myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType)); | 153 | myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType)); |
156 | 154 | ||
157 | StaticBlocks.Add((UInt32)startReadPos, myStaticBlock); | 155 | StaticBlocks.Add((UInt32) startReadPos, myStaticBlock); |
158 | |||
159 | } | 156 | } |
160 | Common.SendToDebug("Number of Static Blocks read: " + StaticBlockCount); | 157 | Common.SendToDebug("Number of Static Blocks read: " + StaticBlockCount); |
161 | 158 | ||
@@ -183,7 +180,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
183 | // TODO: ADD TO FUNCTION LIST (How do we identify it later?) | 180 | // TODO: ADD TO FUNCTION LIST (How do we identify it later?) |
184 | // Note! Absolute position | 181 | // Note! Absolute position |
185 | myFunctionBlock.CodeChunkPointer[i] = BitConverter.ToUInt32(br_read(4), 0) + myHeader.GFR; | 182 | myFunctionBlock.CodeChunkPointer[i] = BitConverter.ToUInt32(br_read(4), 0) + myHeader.GFR; |
186 | Common.SendToDebug("Fuction " + i + " code chunk position: " + myFunctionBlock.CodeChunkPointer[i]); | 183 | Common.SendToDebug("Fuction " + i + " code chunk position: " + |
184 | myFunctionBlock.CodeChunkPointer[i]); | ||
187 | } | 185 | } |
188 | } | 186 | } |
189 | } | 187 | } |
@@ -204,14 +202,14 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
204 | Common.SendToDebug("Reading STATE POINTER BLOCK " + (i + 1) + " at: " + fs.Position); | 202 | Common.SendToDebug("Reading STATE POINTER BLOCK " + (i + 1) + " at: " + fs.Position); |
205 | // Position is relative to state frame | 203 | // Position is relative to state frame |
206 | myStateFrameBlock.StatePointer[i].Location = myHeader.SR + BitConverter.ToUInt32(br_read(4), 0); | 204 | myStateFrameBlock.StatePointer[i].Location = myHeader.SR + BitConverter.ToUInt32(br_read(4), 0); |
207 | myStateFrameBlock.StatePointer[i].EventMask = new System.Collections.BitArray(br_read(8)); | 205 | myStateFrameBlock.StatePointer[i].EventMask = new BitArray(br_read(8)); |
208 | Common.SendToDebug("Pointer: " + myStateFrameBlock.StatePointer[i].Location); | 206 | Common.SendToDebug("Pointer: " + myStateFrameBlock.StatePointer[i].Location); |
209 | Common.SendToDebug("Total potential EventMask bits: " + myStateFrameBlock.StatePointer[i].EventMask.Count); | 207 | Common.SendToDebug("Total potential EventMask bits: " + |
208 | myStateFrameBlock.StatePointer[i].EventMask.Count); | ||
210 | 209 | ||
211 | //// Read STATE BLOCK | 210 | //// Read STATE BLOCK |
212 | //long CurPos = fs.Position; | 211 | //long CurPos = fs.Position; |
213 | //fs.Seek(CurPos, SeekOrigin.Begin); | 212 | //fs.Seek(CurPos, SeekOrigin.Begin); |
214 | |||
215 | } | 213 | } |
216 | } | 214 | } |
217 | 215 | ||
@@ -224,19 +222,20 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
224 | // Go through all State Frame Pointers found | 222 | // Go through all State Frame Pointers found |
225 | for (int i = 0; i < myStateFrameBlock.StateCount; i++) | 223 | for (int i = 0; i < myStateFrameBlock.StateCount; i++) |
226 | { | 224 | { |
227 | |||
228 | fs.Seek(myStateFrameBlock.StatePointer[i].Location, SeekOrigin.Begin); | 225 | fs.Seek(myStateFrameBlock.StatePointer[i].Location, SeekOrigin.Begin); |
229 | Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " at: " + fs.Position); | 226 | Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " at: " + fs.Position); |
230 | 227 | ||
231 | // READ: STATE BLOCK HEADER | 228 | // READ: STATE BLOCK HEADER |
232 | myStateFrameBlock.StatePointer[i].StateBlock = new LSO_Struct.StateBlock(); | 229 | myStateFrameBlock.StatePointer[i].StateBlock = new LSO_Struct.StateBlock(); |
233 | myStateFrameBlock.StatePointer[i].StateBlock.StartPos = (UInt32)fs.Position; // Note | 230 | myStateFrameBlock.StatePointer[i].StateBlock.StartPos = (UInt32) fs.Position; // Note |
234 | myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize = BitConverter.ToUInt32(br_read(4), 0); | 231 | myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize = BitConverter.ToUInt32(br_read(4), 0); |
235 | myStateFrameBlock.StatePointer[i].StateBlock.Unknown = br_read(1)[0]; | 232 | myStateFrameBlock.StatePointer[i].StateBlock.Unknown = br_read(1)[0]; |
236 | myStateFrameBlock.StatePointer[i].StateBlock.EndPos = (UInt32)fs.Position; // Note | 233 | myStateFrameBlock.StatePointer[i].StateBlock.EndPos = (UInt32) fs.Position; // Note |
237 | Common.SendToDebug("State block Start Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.StartPos); | 234 | Common.SendToDebug("State block Start Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.StartPos); |
238 | Common.SendToDebug("State block Header Size: " + myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize); | 235 | Common.SendToDebug("State block Header Size: " + |
239 | Common.SendToDebug("State block Header End Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.EndPos); | 236 | myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize); |
237 | Common.SendToDebug("State block Header End Pos: " + | ||
238 | myStateFrameBlock.StatePointer[i].StateBlock.EndPos); | ||
240 | 239 | ||
241 | // We need to count number of bits flagged in EventMask? | 240 | // We need to count number of bits flagged in EventMask? |
242 | 241 | ||
@@ -245,27 +244,36 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
245 | 244 | ||
246 | // ADDING TO ALL RIGHT NOW, SHOULD LIMIT TO ONLY THE ONES IN USE | 245 | // ADDING TO ALL RIGHT NOW, SHOULD LIMIT TO ONLY THE ONES IN USE |
247 | //TODO: Create event hooks | 246 | //TODO: Create event hooks |
248 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers = new LSO_Struct.StateBlockHandler[myStateFrameBlock.StatePointer[i].EventMask.Count - 1]; | 247 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers = |
248 | new LSO_Struct.StateBlockHandler[myStateFrameBlock.StatePointer[i].EventMask.Count - 1]; | ||
249 | for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++) | 249 | for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++) |
250 | { | 250 | { |
251 | |||
252 | if (myStateFrameBlock.StatePointer[i].EventMask.Get(ii) == true) | 251 | if (myStateFrameBlock.StatePointer[i].EventMask.Get(ii) == true) |
253 | { | 252 | { |
254 | // We got an event | 253 | // We got an event |
255 | // READ: STATE BLOCK HANDLER | 254 | // READ: STATE BLOCK HANDLER |
256 | Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER matching EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") at: " + fs.Position); | 255 | Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER matching EVENT MASK " + ii + |
257 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer = myStateFrameBlock.StatePointer[i].StateBlock.EndPos + BitConverter.ToUInt32(br_read(4), 0); | 256 | " (" + ((LSO_Enums.Event_Mask_Values) ii).ToString() + ") at: " + |
258 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize = BitConverter.ToUInt32(br_read(4), 0); | 257 | fs.Position); |
259 | Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") Code Chunk Pointer: " + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer); | 258 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer = |
260 | Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") Call Frame Size: " + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize); | 259 | myStateFrameBlock.StatePointer[i].StateBlock.EndPos + |
260 | BitConverter.ToUInt32(br_read(4), 0); | ||
261 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize = | ||
262 | BitConverter.ToUInt32(br_read(4), 0); | ||
263 | Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + | ||
264 | ((LSO_Enums.Event_Mask_Values) ii).ToString() + ") Code Chunk Pointer: " + | ||
265 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii]. | ||
266 | CodeChunkPointer); | ||
267 | Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + | ||
268 | ((LSO_Enums.Event_Mask_Values) ii).ToString() + ") Call Frame Size: " + | ||
269 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii]. | ||
270 | CallFrameSize); | ||
261 | } | 271 | } |
262 | } | 272 | } |
263 | } | 273 | } |
264 | } | 274 | } |
265 | 275 | ||
266 | 276 | ||
267 | |||
268 | |||
269 | //// READ FUNCTION CODE CHUNKS | 277 | //// READ FUNCTION CODE CHUNKS |
270 | //// Functions + Function start pos (GFR) | 278 | //// Functions + Function start pos (GFR) |
271 | //// TODO: Somehow be able to identify and reference this | 279 | //// TODO: Somehow be able to identify and reference this |
@@ -291,37 +299,32 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
291 | // two level search ain't no good | 299 | // two level search ain't no good |
292 | for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++) | 300 | for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++) |
293 | { | 301 | { |
294 | |||
295 | |||
296 | if (myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer > 0) | 302 | if (myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer > 0) |
297 | { | 303 | { |
298 | Common.SendToDebug("Reading Event Code Chunk state " + i + ", event " + (LSO_Enums.Event_Mask_Values)ii); | 304 | Common.SendToDebug("Reading Event Code Chunk state " + i + ", event " + |
305 | (LSO_Enums.Event_Mask_Values) ii); | ||
299 | 306 | ||
300 | 307 | ||
301 | // Override a Method / Function | 308 | // Override a Method / Function |
302 | string eventname = i + "_event_" + (LSO_Enums.Event_Mask_Values)ii; | 309 | string eventname = i + "_event_" + (LSO_Enums.Event_Mask_Values) ii; |
303 | Common.SendToDebug("Event Name: " + eventname); | 310 | Common.SendToDebug("Event Name: " + eventname); |
304 | if (Common.IL_ProcessCodeChunks) | 311 | if (Common.IL_ProcessCodeChunks) |
305 | { | 312 | { |
306 | EventList.Add(eventname); | 313 | EventList.Add(eventname); |
307 | 314 | ||
308 | // JUMP TO CODE PROCESSOR | 315 | // JUMP TO CODE PROCESSOR |
309 | ProcessCodeChunk(myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer, typeBuilder, eventname); | 316 | ProcessCodeChunk( |
317 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer, | ||
318 | typeBuilder, eventname); | ||
310 | } | 319 | } |
311 | } | 320 | } |
312 | |||
313 | } | 321 | } |
314 | |||
315 | } | 322 | } |
316 | |||
317 | } | 323 | } |
318 | 324 | ||
319 | 325 | ||
320 | |||
321 | |||
322 | if (Common.IL_CreateFunctionList) | 326 | if (Common.IL_CreateFunctionList) |
323 | IL_INSERT_FUNCTIONLIST(); | 327 | IL_INSERT_FUNCTIONLIST(); |
324 | |||
325 | } | 328 | } |
326 | 329 | ||
327 | internal LSO_Struct.HeapBlock GetHeap(UInt32 pos) | 330 | internal LSO_Struct.HeapBlock GetHeap(UInt32 pos) |
@@ -342,11 +345,13 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
342 | 345 | ||
343 | 346 | ||
344 | Common.SendToDebug("Heap Block Data Block Size: " + myHeapBlock.DataBlockSize); | 347 | Common.SendToDebug("Heap Block Data Block Size: " + myHeapBlock.DataBlockSize); |
345 | Common.SendToDebug("Heap Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myHeapBlock.ObjectType).ToString()); | 348 | Common.SendToDebug("Heap Block ObjectType: " + |
349 | ((LSO_Enums.Variable_Type_Codes) myHeapBlock.ObjectType).ToString()); | ||
346 | Common.SendToDebug("Heap Block Reference Count: " + myHeapBlock.ReferenceCount); | 350 | Common.SendToDebug("Heap Block Reference Count: " + myHeapBlock.ReferenceCount); |
347 | 351 | ||
348 | return myHeapBlock; | 352 | return myHeapBlock; |
349 | } | 353 | } |
354 | |||
350 | private byte[] br_read(int len) | 355 | private byte[] br_read(int len) |
351 | { | 356 | { |
352 | if (len <= 0) | 357 | if (len <= 0) |
@@ -365,6 +370,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
365 | throw (e); | 370 | throw (e); |
366 | } | 371 | } |
367 | } | 372 | } |
373 | |||
368 | //private byte[] br_read_smallendian(int len) | 374 | //private byte[] br_read_smallendian(int len) |
369 | //{ | 375 | //{ |
370 | // byte[] bytes = new byte[len]; | 376 | // byte[] bytes = new byte[len]; |
@@ -373,29 +379,38 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
373 | //} | 379 | //} |
374 | private Type getLLObjectType(byte objectCode) | 380 | private Type getLLObjectType(byte objectCode) |
375 | { | 381 | { |
376 | switch ((LSO_Enums.Variable_Type_Codes)objectCode) | 382 | switch ((LSO_Enums.Variable_Type_Codes) objectCode) |
377 | { | 383 | { |
378 | case LSO_Enums.Variable_Type_Codes.Void: return typeof(void); | 384 | case LSO_Enums.Variable_Type_Codes.Void: |
379 | case LSO_Enums.Variable_Type_Codes.Integer: return typeof(UInt32); | 385 | return typeof (void); |
380 | case LSO_Enums.Variable_Type_Codes.Float: return typeof(float); | 386 | case LSO_Enums.Variable_Type_Codes.Integer: |
381 | case LSO_Enums.Variable_Type_Codes.String: return typeof(string); | 387 | return typeof (UInt32); |
382 | case LSO_Enums.Variable_Type_Codes.Key: return typeof(string); | 388 | case LSO_Enums.Variable_Type_Codes.Float: |
383 | case LSO_Enums.Variable_Type_Codes.Vector: return typeof(LSO_Enums.Vector); | 389 | return typeof (float); |
384 | case LSO_Enums.Variable_Type_Codes.Rotation: return typeof(LSO_Enums.Rotation); | 390 | case LSO_Enums.Variable_Type_Codes.String: |
391 | return typeof (string); | ||
392 | case LSO_Enums.Variable_Type_Codes.Key: | ||
393 | return typeof (string); | ||
394 | case LSO_Enums.Variable_Type_Codes.Vector: | ||
395 | return typeof (LSO_Enums.Vector); | ||
396 | case LSO_Enums.Variable_Type_Codes.Rotation: | ||
397 | return typeof (LSO_Enums.Rotation); | ||
385 | case LSO_Enums.Variable_Type_Codes.List: | 398 | case LSO_Enums.Variable_Type_Codes.List: |
386 | Common.SendToDebug("TODO: List datatype not implemented yet!"); | 399 | Common.SendToDebug("TODO: List datatype not implemented yet!"); |
387 | return typeof(System.Collections.ArrayList); | 400 | return typeof (ArrayList); |
388 | case LSO_Enums.Variable_Type_Codes.Null: | 401 | case LSO_Enums.Variable_Type_Codes.Null: |
389 | Common.SendToDebug("TODO: Datatype null is not implemented, using string instead.!"); | 402 | Common.SendToDebug("TODO: Datatype null is not implemented, using string instead.!"); |
390 | return typeof(string); | 403 | return typeof (string); |
391 | default: | 404 | default: |
392 | Common.SendToDebug("Lookup of LSL datatype " + objectCode + " to .Net datatype failed: Unknown LSL datatype. Defaulting to object."); | 405 | Common.SendToDebug("Lookup of LSL datatype " + objectCode + |
393 | return typeof(object); | 406 | " to .Net datatype failed: Unknown LSL datatype. Defaulting to object."); |
407 | return typeof (object); | ||
394 | } | 408 | } |
395 | } | 409 | } |
410 | |||
396 | private int getObjectSize(byte ObjectType) | 411 | private int getObjectSize(byte ObjectType) |
397 | { | 412 | { |
398 | switch ((LSO_Enums.Variable_Type_Codes)ObjectType) | 413 | switch ((LSO_Enums.Variable_Type_Codes) ObjectType) |
399 | { | 414 | { |
400 | case LSO_Enums.Variable_Type_Codes.Integer: | 415 | case LSO_Enums.Variable_Type_Codes.Integer: |
401 | case LSO_Enums.Variable_Type_Codes.Float: | 416 | case LSO_Enums.Variable_Type_Codes.Float: |
@@ -411,13 +426,14 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
411 | return 0; | 426 | return 0; |
412 | } | 427 | } |
413 | } | 428 | } |
429 | |||
414 | private string Read_String() | 430 | private string Read_String() |
415 | { | 431 | { |
416 | string ret = ""; | 432 | string ret = ""; |
417 | byte reader = br_read(1)[0]; | 433 | byte reader = br_read(1)[0]; |
418 | while (reader != 0x000) | 434 | while (reader != 0x000) |
419 | { | 435 | { |
420 | ret += (char)reader; | 436 | ret += (char) reader; |
421 | reader = br_read(1)[0]; | 437 | reader = br_read(1)[0]; |
422 | } | 438 | } |
423 | return ret; | 439 | return ret; |
@@ -431,7 +447,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
431 | /// <param name="eventname">Name of event (function) to generate</param> | 447 | /// <param name="eventname">Name of event (function) to generate</param> |
432 | private void ProcessCodeChunk(UInt32 pos, TypeBuilder typeBuilder, string eventname) | 448 | private void ProcessCodeChunk(UInt32 pos, TypeBuilder typeBuilder, string eventname) |
433 | { | 449 | { |
434 | |||
435 | LSO_Struct.CodeChunk myCodeChunk = new LSO_Struct.CodeChunk(); | 450 | LSO_Struct.CodeChunk myCodeChunk = new LSO_Struct.CodeChunk(); |
436 | 451 | ||
437 | Common.SendToDebug("Reading Function Code Chunk at: " + pos); | 452 | Common.SendToDebug("Reading Function Code Chunk at: " + pos); |
@@ -442,12 +457,13 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
442 | myCodeChunk.Comment = Read_String(); | 457 | myCodeChunk.Comment = Read_String(); |
443 | Common.SendToDebug("Function comment: " + myCodeChunk.Comment); | 458 | Common.SendToDebug("Function comment: " + myCodeChunk.Comment); |
444 | myCodeChunk.ReturnTypePos = br_read(1)[0]; | 459 | myCodeChunk.ReturnTypePos = br_read(1)[0]; |
445 | myCodeChunk.ReturnType = GetStaticBlock((long)myCodeChunk.ReturnTypePos + (long)myHeader.GVR); | 460 | myCodeChunk.ReturnType = GetStaticBlock((long) myCodeChunk.ReturnTypePos + (long) myHeader.GVR); |
446 | Common.SendToDebug("Return type #" + myCodeChunk.ReturnType.ObjectType + ": " + ((LSO_Enums.Variable_Type_Codes)myCodeChunk.ReturnType.ObjectType).ToString()); | 461 | Common.SendToDebug("Return type #" + myCodeChunk.ReturnType.ObjectType + ": " + |
462 | ((LSO_Enums.Variable_Type_Codes) myCodeChunk.ReturnType.ObjectType).ToString()); | ||
447 | 463 | ||
448 | 464 | ||
449 | // TODO: How to determine number of codechunks -- does this method work? | 465 | // TODO: How to determine number of codechunks -- does this method work? |
450 | myCodeChunk.CodeChunkArguments = new System.Collections.Generic.List<LSO_Struct.CodeChunkArgument>(); | 466 | myCodeChunk.CodeChunkArguments = new List<LSO_Struct.CodeChunkArgument>(); |
451 | byte reader = br_read(1)[0]; | 467 | byte reader = br_read(1)[0]; |
452 | reader = br_read(1)[0]; | 468 | reader = br_read(1)[0]; |
453 | 469 | ||
@@ -464,14 +480,17 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
464 | CCA.NullString = reader; | 480 | CCA.NullString = reader; |
465 | CCA.FunctionReturnType = GetStaticBlock(CCA.FunctionReturnTypePos + myHeader.GVR); | 481 | CCA.FunctionReturnType = GetStaticBlock(CCA.FunctionReturnTypePos + myHeader.GVR); |
466 | myCodeChunk.CodeChunkArguments.Add(CCA); | 482 | myCodeChunk.CodeChunkArguments.Add(CCA); |
467 | Common.SendToDebug("Code Chunk Argument " + ccount + " type #" + CCA.FunctionReturnType.ObjectType + ": " + (LSO_Enums.Variable_Type_Codes)CCA.FunctionReturnType.ObjectType); | 483 | Common.SendToDebug("Code Chunk Argument " + ccount + " type #" + CCA.FunctionReturnType.ObjectType + |
484 | ": " + (LSO_Enums.Variable_Type_Codes) CCA.FunctionReturnType.ObjectType); | ||
468 | } | 485 | } |
469 | // Create string array | 486 | // Create string array |
470 | Type[] MethodArgs = new Type[myCodeChunk.CodeChunkArguments.Count]; | 487 | Type[] MethodArgs = new Type[myCodeChunk.CodeChunkArguments.Count]; |
471 | for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++) | 488 | for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++) |
472 | { | 489 | { |
473 | MethodArgs[_ic] = getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType.ObjectType); | 490 | MethodArgs[_ic] = getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType.ObjectType); |
474 | Common.SendToDebug("Method argument " + _ic + ": " + getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType.ObjectType).ToString()); | 491 | Common.SendToDebug("Method argument " + _ic + ": " + |
492 | getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType.ObjectType). | ||
493 | ToString()); | ||
475 | } | 494 | } |
476 | // End marker is 0x000 | 495 | // End marker is 0x000 |
477 | myCodeChunk.EndMarker = reader; | 496 | myCodeChunk.EndMarker = reader; |
@@ -483,9 +502,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
483 | 502 | ||
484 | Common.SendToDebug("CLR:" + eventname + ":MethodBuilder methodBuilder = typeBuilder.DefineMethod..."); | 503 | Common.SendToDebug("CLR:" + eventname + ":MethodBuilder methodBuilder = typeBuilder.DefineMethod..."); |
485 | MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname, | 504 | MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname, |
486 | MethodAttributes.Public, | 505 | MethodAttributes.Public, |
487 | typeof(void), | 506 | typeof (void), |
488 | new Type[] { typeof(object) }); | 507 | new Type[] {typeof (object)}); |
489 | //MethodArgs); | 508 | //MethodArgs); |
490 | //typeof(void), //getLLObjectType(myCodeChunk.ReturnType), | 509 | //typeof(void), //getLLObjectType(myCodeChunk.ReturnType), |
491 | // new Type[] { typeof(object) }, //); | 510 | // new Type[] { typeof(object) }, //); |
@@ -504,7 +523,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
504 | IL_INSERT_TRY(il, eventname); | 523 | IL_INSERT_TRY(il, eventname); |
505 | 524 | ||
506 | 525 | ||
507 | |||
508 | // Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!"); | 526 | // Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!"); |
509 | //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); | 527 | //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); |
510 | //il.Emit(OpCodes.Call, typeof(Console).GetMethod | 528 | //il.Emit(OpCodes.Call, typeof(Console).GetMethod |
@@ -520,7 +538,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
520 | } | 538 | } |
521 | 539 | ||
522 | 540 | ||
523 | |||
524 | // | 541 | // |
525 | // CALLING OPCODE PROCESSOR, one command at the time TO GENERATE IL | 542 | // CALLING OPCODE PROCESSOR, one command at the time TO GENERATE IL |
526 | // | 543 | // |
@@ -538,12 +555,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
538 | il.Emit(OpCodes.Ret); | 555 | il.Emit(OpCodes.Ret); |
539 | 556 | ||
540 | return; | 557 | return; |
541 | |||
542 | } | 558 | } |
543 | 559 | ||
544 | private void IL_INSERT_FUNCTIONLIST() | 560 | private void IL_INSERT_FUNCTIONLIST() |
545 | { | 561 | { |
546 | |||
547 | Common.SendToDebug("Creating function list"); | 562 | Common.SendToDebug("Creating function list"); |
548 | 563 | ||
549 | 564 | ||
@@ -557,11 +572,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
557 | //FieldBuilder mem = typeBuilder.DefineField("mem", typeof(Array), FieldAttributes.Private); | 572 | //FieldBuilder mem = typeBuilder.DefineField("mem", typeof(Array), FieldAttributes.Private); |
558 | 573 | ||
559 | 574 | ||
560 | |||
561 | MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname, | 575 | MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname, |
562 | MethodAttributes.Public, | 576 | MethodAttributes.Public, |
563 | typeof(string[]), | 577 | typeof (string[]), |
564 | null); | 578 | null); |
565 | 579 | ||
566 | //typeBuilder.DefineMethodOverride(methodBuilder, | 580 | //typeBuilder.DefineMethodOverride(methodBuilder, |
567 | // typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname)); | 581 | // typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname)); |
@@ -569,8 +583,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
569 | ILGenerator il = methodBuilder.GetILGenerator(); | 583 | ILGenerator il = methodBuilder.GetILGenerator(); |
570 | 584 | ||
571 | 585 | ||
572 | |||
573 | |||
574 | // IL_INSERT_TRY(il, eventname); | 586 | // IL_INSERT_TRY(il, eventname); |
575 | 587 | ||
576 | // // Push string to stack | 588 | // // Push string to stack |
@@ -586,37 +598,34 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
586 | 598 | ||
587 | ////il.Emit(OpCodes.Ldarg_0); | 599 | ////il.Emit(OpCodes.Ldarg_0); |
588 | 600 | ||
589 | il.DeclareLocal(typeof(string[])); | 601 | il.DeclareLocal(typeof (string[])); |
590 | 602 | ||
591 | ////il.Emit(OpCodes.Ldarg_0); | 603 | ////il.Emit(OpCodes.Ldarg_0); |
592 | il.Emit(OpCodes.Ldc_I4, EventList.Count); // Specify array length | 604 | il.Emit(OpCodes.Ldc_I4, EventList.Count); // Specify array length |
593 | il.Emit(OpCodes.Newarr, typeof(String)); // create new string array | 605 | il.Emit(OpCodes.Newarr, typeof (String)); // create new string array |
594 | il.Emit(OpCodes.Stloc_0); // Store array as local variable 0 in stack | 606 | il.Emit(OpCodes.Stloc_0); // Store array as local variable 0 in stack |
595 | ////SetFunctionList | 607 | ////SetFunctionList |
596 | 608 | ||
597 | for (int lv = 0; lv < EventList.Count; lv++) | 609 | for (int lv = 0; lv < EventList.Count; lv++) |
598 | { | 610 | { |
599 | il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack | 611 | il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack |
600 | il.Emit(OpCodes.Ldc_I4, lv); // Push index position | 612 | il.Emit(OpCodes.Ldc_I4, lv); // Push index position |
601 | il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value | 613 | il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value |
602 | il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value | 614 | il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value |
603 | 615 | ||
604 | //il.Emit(OpCodes.Ldarg_0); | 616 | //il.Emit(OpCodes.Ldarg_0); |
605 | //il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value | 617 | //il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value |
606 | //il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("AddFunction", new Type[] { typeof(string) })); | 618 | //il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("AddFunction", new Type[] { typeof(string) })); |
607 | |||
608 | } | 619 | } |
609 | 620 | ||
610 | 621 | ||
611 | |||
612 | // IL_INSERT_END_TRY(il, eventname); | 622 | // IL_INSERT_END_TRY(il, eventname); |
613 | 623 | ||
614 | 624 | ||
615 | il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack | 625 | il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack |
616 | // il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("SetFunctionList", new Type[] { typeof(Array) })); | 626 | // il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("SetFunctionList", new Type[] { typeof(Array) })); |
617 | 627 | ||
618 | il.Emit(OpCodes.Ret); // Return | 628 | il.Emit(OpCodes.Ret); // Return |
619 | |||
620 | } | 629 | } |
621 | 630 | ||
622 | 631 | ||
@@ -631,7 +640,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
631 | // Push "Hello World!" string to stack | 640 | // Push "Hello World!" string to stack |
632 | //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr..."); | 641 | //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr..."); |
633 | //il.Emit(OpCodes.Ldstr, "Starting CLR dynamic execution of: " + eventname); | 642 | //il.Emit(OpCodes.Ldstr, "Starting CLR dynamic execution of: " + eventname); |
634 | |||
635 | } | 643 | } |
636 | 644 | ||
637 | private void IL_INSERT_END_TRY(ILGenerator il, string eventname) | 645 | private void IL_INSERT_END_TRY(ILGenerator il, string eventname) |
@@ -640,7 +648,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
640 | * CATCH | 648 | * CATCH |
641 | */ | 649 | */ |
642 | Common.SendToDebug("CLR:" + eventname + ":il.BeginCatchBlock(typeof(Exception));"); | 650 | Common.SendToDebug("CLR:" + eventname + ":il.BeginCatchBlock(typeof(Exception));"); |
643 | il.BeginCatchBlock(typeof(Exception)); | 651 | il.BeginCatchBlock(typeof (Exception)); |
644 | 652 | ||
645 | // Push "Hello World!" string to stack | 653 | // Push "Hello World!" string to stack |
646 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr..."); | 654 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr..."); |
@@ -648,18 +656,18 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
648 | 656 | ||
649 | //call void [mscorlib]System.Console::WriteLine(string) | 657 | //call void [mscorlib]System.Console::WriteLine(string) |
650 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); | 658 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); |
651 | il.Emit(OpCodes.Call, typeof(Console).GetMethod | 659 | il.Emit(OpCodes.Call, typeof (Console).GetMethod |
652 | ("Write", new Type[] { typeof(string) })); | 660 | ("Write", new Type[] {typeof (string)})); |
653 | 661 | ||
654 | //callvirt instance string [mscorlib]System.Exception::get_Message() | 662 | //callvirt instance string [mscorlib]System.Exception::get_Message() |
655 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Callvirt..."); | 663 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Callvirt..."); |
656 | il.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod | 664 | il.Emit(OpCodes.Callvirt, typeof (Exception).GetMethod |
657 | ("get_Message")); | 665 | ("get_Message")); |
658 | 666 | ||
659 | //call void [mscorlib]System.Console::WriteLine(string) | 667 | //call void [mscorlib]System.Console::WriteLine(string) |
660 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); | 668 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); |
661 | il.Emit(OpCodes.Call, typeof(Console).GetMethod | 669 | il.Emit(OpCodes.Call, typeof (Console).GetMethod |
662 | ("WriteLine", new Type[] { typeof(string) })); | 670 | ("WriteLine", new Type[] {typeof (string)})); |
663 | 671 | ||
664 | /* | 672 | /* |
665 | * CLR END TRY | 673 | * CLR END TRY |
@@ -673,7 +681,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
673 | long FirstPos = fs.Position; | 681 | long FirstPos = fs.Position; |
674 | try | 682 | try |
675 | { | 683 | { |
676 | UInt32 position = (UInt32)pos; | 684 | UInt32 position = (UInt32) pos; |
677 | // STATIC BLOCK | 685 | // STATIC BLOCK |
678 | Common.SendToDebug("Reading STATIC BLOCK at: " + position); | 686 | Common.SendToDebug("Reading STATIC BLOCK at: " + position); |
679 | fs.Seek(position, SeekOrigin.Begin); | 687 | fs.Seek(position, SeekOrigin.Begin); |
@@ -683,7 +691,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
683 | Common.SendToDebug("Found cached STATIC BLOCK"); | 691 | Common.SendToDebug("Found cached STATIC BLOCK"); |
684 | 692 | ||
685 | 693 | ||
686 | |||
687 | return StaticBlocks[pos]; | 694 | return StaticBlocks[pos]; |
688 | } | 695 | } |
689 | 696 | ||
@@ -699,7 +706,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
699 | LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock(); | 706 | LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock(); |
700 | myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0); | 707 | myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0); |
701 | myStaticBlock.ObjectType = br_read(1)[0]; | 708 | myStaticBlock.ObjectType = br_read(1)[0]; |
702 | Common.SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString()); | 709 | Common.SendToDebug("Static Block ObjectType: " + |
710 | ((LSO_Enums.Variable_Type_Codes) myStaticBlock.ObjectType).ToString()); | ||
703 | myStaticBlock.Unknown = br_read(1)[0]; | 711 | myStaticBlock.Unknown = br_read(1)[0]; |
704 | // Size of datatype varies | 712 | // Size of datatype varies |
705 | if (myStaticBlock.ObjectType != 0) | 713 | if (myStaticBlock.ObjectType != 0) |
@@ -715,8 +723,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | |||
715 | // Go back to original read pos | 723 | // Go back to original read pos |
716 | fs.Seek(FirstPos, SeekOrigin.Begin); | 724 | fs.Seek(FirstPos, SeekOrigin.Begin); |
717 | } | 725 | } |
718 | |||
719 | } | 726 | } |
720 | |||
721 | } | 727 | } |
722 | } | 728 | } \ No newline at end of file |