aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/Engine.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/Engine.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/Engine.cs149
1 files changed, 70 insertions, 79 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/Engine.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/Engine.cs
index f060f06..97981cc 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/Engine.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/Engine.cs
@@ -27,20 +27,19 @@
27*/ 27*/
28/* Original code: Tedd Hansen */ 28/* Original code: Tedd Hansen */
29using System; 29using System;
30using System.IO;
30using System.Reflection; 31using System.Reflection;
31using System.Reflection.Emit; 32using System.Reflection.Emit;
33using System.Text;
32using System.Threading; 34using System.Threading;
33 35
34
35namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO 36namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
36{ 37{
37
38
39 public class Engine 38 public class Engine
40 { 39 {
41 //private string LSO_FileName = @"LSO\AdditionTest.lso"; 40 //private string LSO_FileName = @"LSO\AdditionTest.lso";
42 private string LSO_FileName;// = @"LSO\CloseToDefault.lso"; 41 private string LSO_FileName; // = @"LSO\CloseToDefault.lso";
43 AppDomain appDomain; 42 private AppDomain appDomain;
44 43
45 public string Compile(string LSOFileName) 44 public string Compile(string LSOFileName)
46 { 45 {
@@ -52,20 +51,19 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
52 51
53 // Create Assembly Name 52 // Create Assembly Name
54 AssemblyName asmName = new AssemblyName(); 53 AssemblyName asmName = new AssemblyName();
55 asmName.Name = System.IO.Path.GetFileNameWithoutExtension(LSO_FileName); 54 asmName.Name = Path.GetFileNameWithoutExtension(LSO_FileName);
56 //asmName.Name = "TestAssembly"; 55 //asmName.Name = "TestAssembly";
57 56
58 string DLL_FileName = asmName.Name + ".dll"; 57 string DLL_FileName = asmName.Name + ".dll";
59 string DLL_FileName_WithPath = System.IO.Path.GetDirectoryName(LSO_FileName) + @"\" + DLL_FileName; 58 string DLL_FileName_WithPath = Path.GetDirectoryName(LSO_FileName) + @"\" + DLL_FileName;
60 59
61 Common.SendToLog("LSO File Name: " + System.IO.Path.GetFileName(LSO_FileName)); 60 Common.SendToLog("LSO File Name: " + Path.GetFileName(LSO_FileName));
62 Common.SendToLog("Assembly name: " + asmName.Name); 61 Common.SendToLog("Assembly name: " + asmName.Name);
63 Common.SendToLog("Assembly File Name: " + asmName.Name + ".dll"); 62 Common.SendToLog("Assembly File Name: " + asmName.Name + ".dll");
64 Common.SendToLog("Starting processing of LSL ByteCode..."); 63 Common.SendToLog("Starting processing of LSL ByteCode...");
65 Common.SendToLog(""); 64 Common.SendToLog("");
66 65
67 66
68
69 // Create Assembly 67 // Create Assembly
70 AssemblyBuilder asmBuilder = appDomain.DefineDynamicAssembly( 68 AssemblyBuilder asmBuilder = appDomain.DefineDynamicAssembly(
71 asmName, 69 asmName,
@@ -78,15 +76,15 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
78 76
79 // Create a module (and save to disk) 77 // Create a module (and save to disk)
80 ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule 78 ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule
81 (asmName.Name, 79 (asmName.Name,
82 DLL_FileName); 80 DLL_FileName);
83 81
84 //Common.SendToDebug("asmName.Name is still \"" + asmName.Name + "\""); 82 //Common.SendToDebug("asmName.Name is still \"" + asmName.Name + "\"");
85 // Create a Class (/Type) 83 // Create a Class (/Type)
86 TypeBuilder typeBuilder = modBuilder.DefineType( 84 TypeBuilder typeBuilder = modBuilder.DefineType(
87 "LSL_ScriptObject", 85 "LSL_ScriptObject",
88 TypeAttributes.Public | TypeAttributes.BeforeFieldInit, 86 TypeAttributes.Public | TypeAttributes.BeforeFieldInit,
89 typeof(OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass)); 87 typeof (LSL_BaseClass));
90 //, 88 //,
91 // typeof()); 89 // typeof());
92 //, typeof(LSL_BuiltIn_Commands_Interface)); 90 //, typeof(LSL_BuiltIn_Commands_Interface));
@@ -95,7 +93,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
95 // new Type[] { typeof(LSL_CLRInterface.LSLScript) }); 93 // new Type[] { typeof(LSL_CLRInterface.LSLScript) });
96 94
97 95
98
99 /* 96 /*
100 * Generate the IL itself 97 * Generate the IL itself
101 */ 98 */
@@ -123,7 +120,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
123 asmBuilder.Save(DLL_FileName); 120 asmBuilder.Save(DLL_FileName);
124 121
125 Common.SendToLog("Returning assembly filename: " + DLL_FileName); 122 Common.SendToLog("Returning assembly filename: " + DLL_FileName);
126 123
127 124
128 return DLL_FileName; 125 return DLL_FileName;
129 126
@@ -135,9 +132,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
135 //object MyScript = (object)Activator.CreateInstance(type); 132 //object MyScript = (object)Activator.CreateInstance(type);
136 133
137 134
138
139
140
141 //System.Reflection.MemberInfo[] Members = type.GetMembers(); 135 //System.Reflection.MemberInfo[] Members = type.GetMembers();
142 136
143 //Common.SendToLog("Members of assembly " + type.ToString() + ":"); 137 //Common.SendToLog("Members of assembly " + type.ToString() + ":");
@@ -165,29 +159,25 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
165 // type.InvokeMember(s, BindingFlags.InvokeMethod, null, MyScript, new object[] { "Test" }); 159 // type.InvokeMember(s, BindingFlags.InvokeMethod, null, MyScript, new object[] { "Test" });
166 160
167 //} 161 //}
168
169
170 } 162 }
171 163
172 164
173 private static void IL_CREATE_CONSTRUCTOR(TypeBuilder typeBuilder, LSO_Parser LSOP) 165 private static void IL_CREATE_CONSTRUCTOR(TypeBuilder typeBuilder, LSO_Parser LSOP)
174 { 166 {
175
176
177 Common.SendToDebug("IL_CREATE_CONSTRUCTOR()"); 167 Common.SendToDebug("IL_CREATE_CONSTRUCTOR()");
178 //ConstructorBuilder constructor = typeBuilder.DefineConstructor( 168 //ConstructorBuilder constructor = typeBuilder.DefineConstructor(
179 // MethodAttributes.Public, 169 // MethodAttributes.Public,
180 // CallingConventions.Standard, 170 // CallingConventions.Standard,
181 // new Type[0]); 171 // new Type[0]);
182 ConstructorBuilder constructor = typeBuilder.DefineConstructor( 172 ConstructorBuilder constructor = typeBuilder.DefineConstructor(
183 MethodAttributes.Public | 173 MethodAttributes.Public |
184 MethodAttributes.SpecialName | 174 MethodAttributes.SpecialName |
185 MethodAttributes.RTSpecialName, 175 MethodAttributes.RTSpecialName,
186 CallingConventions.Standard, 176 CallingConventions.Standard,
187 new Type[0]); 177 new Type[0]);
188 178
189 //Define the reflection ConstructorInfor for System.Object 179 //Define the reflection ConstructorInfor for System.Object
190 ConstructorInfo conObj = typeof(LSL_BaseClass).GetConstructor(new Type[0]); 180 ConstructorInfo conObj = typeof (LSL_BaseClass).GetConstructor(new Type[0]);
191 181
192 //call constructor of base object 182 //call constructor of base object
193 ILGenerator il = constructor.GetILGenerator(); 183 ILGenerator il = constructor.GetILGenerator();
@@ -230,58 +220,61 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
230 LSO_Struct.StaticBlock sb; 220 LSO_Struct.StaticBlock sb;
231 LSOP.StaticBlocks.TryGetValue(pos, out sb); 221 LSOP.StaticBlocks.TryGetValue(pos, out sb);
232 222
233 if (sb.ObjectType > 0 && sb.ObjectType < 8) { // We don't want void or null's 223 if (sb.ObjectType > 0 && sb.ObjectType < 8)
234
235 il.Emit(OpCodes.Ldarg_0);
236 // Push position to stack
237 il.Emit(OpCodes.Ldc_I4, pos);
238 //il.Emit(OpCodes.Box, typeof(UInt32));
239
240
241 Type datatype = null;
242
243 // Push data to stack
244 Common.SendToDebug("Adding to static (" + pos + ") type: " + ((LSO_Enums.Variable_Type_Codes)sb.ObjectType).ToString() + " (" + sb.ObjectType + ")");
245 switch ((LSO_Enums.Variable_Type_Codes)sb.ObjectType)
246 { 224 {
247 case LSO_Enums.Variable_Type_Codes.Float: 225 // We don't want void or null's
248 case LSO_Enums.Variable_Type_Codes.Integer: 226
249 //UInt32 227 il.Emit(OpCodes.Ldarg_0);
250 il.Emit(OpCodes.Ldc_I4, BitConverter.ToUInt32(sb.BlockVariable, 0)); 228 // Push position to stack
251 datatype = typeof(UInt32); 229 il.Emit(OpCodes.Ldc_I4, pos);
252 il.Emit(OpCodes.Box, datatype); 230 //il.Emit(OpCodes.Box, typeof(UInt32));
253 break; 231
254 case LSO_Enums.Variable_Type_Codes.String: 232
255 case LSO_Enums.Variable_Type_Codes.Key: 233 Type datatype = null;
256 //String 234
257 LSO_Struct.HeapBlock hb = LSOP.GetHeap(LSOP.myHeader.HR + BitConverter.ToUInt32(sb.BlockVariable, 0) - 1); 235 // Push data to stack
258 il.Emit(OpCodes.Ldstr, System.Text.Encoding.UTF8.GetString(hb.Data)); 236 Common.SendToDebug("Adding to static (" + pos + ") type: " +
259 datatype = typeof(string); 237 ((LSO_Enums.Variable_Type_Codes) sb.ObjectType).ToString() + " (" + sb.ObjectType +
260 break; 238 ")");
261 case LSO_Enums.Variable_Type_Codes.Vector: 239 switch ((LSO_Enums.Variable_Type_Codes) sb.ObjectType)
262 datatype = typeof(LSO_Enums.Vector); 240 {
263 //TODO: Not implemented 241 case LSO_Enums.Variable_Type_Codes.Float:
264 break; 242 case LSO_Enums.Variable_Type_Codes.Integer:
265 case LSO_Enums.Variable_Type_Codes.Rotation: 243 //UInt32
266 //Object 244 il.Emit(OpCodes.Ldc_I4, BitConverter.ToUInt32(sb.BlockVariable, 0));
267 //TODO: Not implemented 245 datatype = typeof (UInt32);
268 datatype = typeof(LSO_Enums.Rotation); 246 il.Emit(OpCodes.Box, datatype);
269 break; 247 break;
270 default: 248 case LSO_Enums.Variable_Type_Codes.String:
271 datatype = typeof(object); 249 case LSO_Enums.Variable_Type_Codes.Key:
272 break; 250 //String
273 } 251 LSO_Struct.HeapBlock hb =
274 252 LSOP.GetHeap(LSOP.myHeader.HR + BitConverter.ToUInt32(sb.BlockVariable, 0) - 1);
275 253 il.Emit(OpCodes.Ldstr, Encoding.UTF8.GetString(hb.Data));
276 // Make call 254 datatype = typeof (string);
277 il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("AddToStatic", new Type[] { typeof(UInt32), datatype })); 255 break;
256 case LSO_Enums.Variable_Type_Codes.Vector:
257 datatype = typeof (LSO_Enums.Vector);
258 //TODO: Not implemented
259 break;
260 case LSO_Enums.Variable_Type_Codes.Rotation:
261 //Object
262 //TODO: Not implemented
263 datatype = typeof (LSO_Enums.Rotation);
264 break;
265 default:
266 datatype = typeof (object);
267 break;
268 }
269
270
271 // Make call
272 il.Emit(OpCodes.Call,
273 typeof (LSL_BaseClass).GetMethod("AddToStatic", new Type[] {typeof (UInt32), datatype}));
278 } 274 }
279
280 } 275 }
281 276
282 277
283
284
285 ////il.Emit(OpCodes.Newobj, typeof(UInt32)); 278 ////il.Emit(OpCodes.Newobj, typeof(UInt32));
286 //il.Emit(OpCodes.Starg_0); 279 //il.Emit(OpCodes.Starg_0);
287 //// Create LSL function library 280 //// Create LSL function library
@@ -293,8 +286,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO
293 } 286 }
294 287
295 288
296
297
298 // End of class 289 // End of class
299 } 290 }
300} 291} \ No newline at end of file