diff options
author | Tedd Hansen | 2007-08-08 14:05:13 +0000 |
---|---|---|
committer | Tedd Hansen | 2007-08-08 14:05:13 +0000 |
commit | 2a0e157985d790e6cbd83d61690da2709dfab9dd (patch) | |
tree | e9c38c11773796111fb4ff222429605bdd76fd5e /OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL | |
parent | * Got SimpleApp working again (diff) | |
download | opensim-SC_OLD-2a0e157985d790e6cbd83d61690da2709dfab9dd.zip opensim-SC_OLD-2a0e157985d790e6cbd83d61690da2709dfab9dd.tar.gz opensim-SC_OLD-2a0e157985d790e6cbd83d61690da2709dfab9dd.tar.bz2 opensim-SC_OLD-2a0e157985d790e6cbd83d61690da2709dfab9dd.tar.xz |
Added ScriptEngine.DotNetEngine
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL')
19 files changed, 7437 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Common.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Common.cs new file mode 100644 index 0000000..1f24d9b --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Common.cs | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
34 | { | ||
35 | public static class Common | ||
36 | { | ||
37 | static public bool Debug = true; | ||
38 | static public bool IL_UseTryCatch = true; | ||
39 | static public bool IL_CreateConstructor = true; | ||
40 | static public bool IL_CreateFunctionList = true; | ||
41 | static public bool IL_ProcessCodeChunks = true; | ||
42 | |||
43 | public delegate void SendToDebugEventDelegate(string Message); | ||
44 | public delegate void SendToLogEventDelegate(string Message); | ||
45 | static public event SendToDebugEventDelegate SendToDebugEvent; | ||
46 | static public event SendToLogEventDelegate SendToLogEvent; | ||
47 | |||
48 | static public void SendToDebug(string Message) | ||
49 | { | ||
50 | //if (Debug == true) | ||
51 | Console.WriteLine("COMPILER:Debug: " + Message); | ||
52 | SendToDebugEvent("\r\n" + DateTime.Now.ToString("[HH:mm:ss] ") + Message); | ||
53 | } | ||
54 | static public void SendToLog(string Message) | ||
55 | { | ||
56 | //if (Debug == true) | ||
57 | Console.WriteLine("COMPILER:LOG: " + Message); | ||
58 | SendToLogEvent("\r\n" + DateTime.Now.ToString("[HH:mm:ss] ") + Message); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | // TEMPORARY TEST THINGIES | ||
63 | public static class IL_Helper | ||
64 | { | ||
65 | public static string ReverseFormatString(string text1, string format) | ||
66 | { | ||
67 | Common.SendToDebug("ReverseFormatString text1: " + text1); | ||
68 | Common.SendToDebug("ReverseFormatString format: " + format); | ||
69 | return string.Format(format, text1); | ||
70 | } | ||
71 | public static string ReverseFormatString(string text1, UInt32 text2, string format) | ||
72 | { | ||
73 | Common.SendToDebug("ReverseFormatString text1: " + text1); | ||
74 | Common.SendToDebug("ReverseFormatString text2: " + text2.ToString()); | ||
75 | Common.SendToDebug("ReverseFormatString format: " + format); | ||
76 | return string.Format(format, text1, text2.ToString()); | ||
77 | } | ||
78 | public static string Cast_ToString(object obj) | ||
79 | { | ||
80 | Common.SendToDebug("OBJECT TO BE CASTED: " + obj.GetType().ToString()); | ||
81 | return "ABCDEFGIHJKLMNOPQ123"; | ||
82 | } | ||
83 | } | ||
84 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Engine.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Engine.cs new file mode 100644 index 0000000..80394b1 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Engine.cs | |||
@@ -0,0 +1,300 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Reflection; | ||
31 | using System.Reflection.Emit; | ||
32 | using System.Threading; | ||
33 | using System.Windows.Forms; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
36 | { | ||
37 | |||
38 | |||
39 | public class Engine | ||
40 | { | ||
41 | //private string LSO_FileName = @"LSO\AdditionTest.lso"; | ||
42 | private string LSO_FileName;// = @"LSO\CloseToDefault.lso"; | ||
43 | AppDomain appDomain; | ||
44 | |||
45 | public string Compile(string LSOFileName) | ||
46 | { | ||
47 | LSO_FileName = LSOFileName; | ||
48 | |||
49 | |||
50 | //appDomain = AppDomain.CreateDomain("AlternateAppDomain"); | ||
51 | appDomain = Thread.GetDomain(); | ||
52 | |||
53 | // Create Assembly Name | ||
54 | AssemblyName asmName = new AssemblyName(); | ||
55 | asmName.Name = System.IO.Path.GetFileNameWithoutExtension(LSO_FileName); | ||
56 | //asmName.Name = "TestAssembly"; | ||
57 | |||
58 | string DLL_FileName = asmName.Name + ".dll"; | ||
59 | string DLL_FileName_WithPath = System.IO.Path.GetDirectoryName(LSO_FileName) + @"\" + DLL_FileName; | ||
60 | |||
61 | Common.SendToLog("LSO File Name: " + System.IO.Path.GetFileName(LSO_FileName)); | ||
62 | Common.SendToLog("Assembly name: " + asmName.Name); | ||
63 | Common.SendToLog("Assembly File Name: " + asmName.Name + ".dll"); | ||
64 | Common.SendToLog("Starting processing of LSL ByteCode..."); | ||
65 | Common.SendToLog(""); | ||
66 | |||
67 | |||
68 | |||
69 | // Create Assembly | ||
70 | AssemblyBuilder asmBuilder = appDomain.DefineDynamicAssembly( | ||
71 | asmName, | ||
72 | AssemblyBuilderAccess.RunAndSave | ||
73 | ); | ||
74 | //// Create Assembly | ||
75 | //AssemblyBuilder asmBuilder = | ||
76 | // Thread.GetDomain().DefineDynamicAssembly | ||
77 | //(asmName, AssemblyBuilderAccess.RunAndSave); | ||
78 | |||
79 | // Create a module (and save to disk) | ||
80 | ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule | ||
81 | (asmName.Name, | ||
82 | DLL_FileName); | ||
83 | |||
84 | //Common.SendToDebug("asmName.Name is still \"" + asmName.Name + "\""); | ||
85 | // Create a Class (/Type) | ||
86 | TypeBuilder typeBuilder = modBuilder.DefineType( | ||
87 | "LSL_ScriptObject", | ||
88 | TypeAttributes.Public | TypeAttributes.BeforeFieldInit, | ||
89 | typeof(OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass)); | ||
90 | //, | ||
91 | // typeof()); | ||
92 | //, typeof(LSL_BuiltIn_Commands_Interface)); | ||
93 | //, | ||
94 | // typeof(object), | ||
95 | // new Type[] { typeof(LSL_CLRInterface.LSLScript) }); | ||
96 | |||
97 | |||
98 | |||
99 | /* | ||
100 | * Generate the IL itself | ||
101 | */ | ||
102 | |||
103 | LSO_Parser LSOP = new LSO_Parser(LSO_FileName, typeBuilder); | ||
104 | LSOP.OpenFile(); | ||
105 | LSOP.Parse(); | ||
106 | |||
107 | // Constructor has to be created AFTER LSO_Parser because of accumulated variables | ||
108 | if (Common.IL_CreateConstructor) | ||
109 | IL_CREATE_CONSTRUCTOR(typeBuilder, LSOP); | ||
110 | |||
111 | LSOP.CloseFile(); | ||
112 | /* | ||
113 | * Done generating. Create a type and run it. | ||
114 | */ | ||
115 | |||
116 | |||
117 | Common.SendToLog("Attempting to compile assembly..."); | ||
118 | // Compile it | ||
119 | Type type = typeBuilder.CreateType(); | ||
120 | Common.SendToLog("Compilation successful!"); | ||
121 | |||
122 | Common.SendToLog("Saving assembly: " + DLL_FileName); | ||
123 | asmBuilder.Save(DLL_FileName); | ||
124 | |||
125 | Common.SendToLog("Returning assembly filename: " + DLL_FileName); | ||
126 | |||
127 | |||
128 | return DLL_FileName; | ||
129 | |||
130 | |||
131 | //Common.SendToLog("Creating an instance of new assembly..."); | ||
132 | //// Create an instance we can play with | ||
133 | ////LSLScript hello = (LSLScript)Activator.CreateInstance(type); | ||
134 | ////LSL_CLRInterface.LSLScript MyScript = (LSL_CLRInterface.LSLScript)Activator.CreateInstance(type); | ||
135 | //object MyScript = (object)Activator.CreateInstance(type); | ||
136 | |||
137 | |||
138 | |||
139 | |||
140 | |||
141 | //System.Reflection.MemberInfo[] Members = type.GetMembers(); | ||
142 | |||
143 | //Common.SendToLog("Members of assembly " + type.ToString() + ":"); | ||
144 | //foreach (MemberInfo member in Members) | ||
145 | // Common.SendToLog(member.ToString()); | ||
146 | |||
147 | |||
148 | //// Play with it | ||
149 | ////MyScript.event_state_entry("Test"); | ||
150 | //object[] args = { null }; | ||
151 | ////System.Collections.Generic.List<string> Functions = (System.Collections.Generic.List<string>)type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, MyScript, null); | ||
152 | |||
153 | //string[] ret = { }; | ||
154 | //if (Common.IL_CreateFunctionList) | ||
155 | // ret = (string[])type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, MyScript, null); | ||
156 | |||
157 | //foreach (string s in ret) | ||
158 | //{ | ||
159 | // Common.SendToLog(""); | ||
160 | // Common.SendToLog("*** Executing LSL Server Event: " + s); | ||
161 | // //object test = type.GetMember(s); | ||
162 | // //object runner = type.InvokeMember(s, BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, MyScript, args); | ||
163 | // //runner(); | ||
164 | // //objBooks_Late = type.InvokeMember(s, BindingFlags.CreateInstance, null, objApp_Late, null); | ||
165 | // type.InvokeMember(s, BindingFlags.InvokeMethod, null, MyScript, new object[] { "Test" }); | ||
166 | |||
167 | //} | ||
168 | |||
169 | |||
170 | } | ||
171 | |||
172 | |||
173 | private static void IL_CREATE_CONSTRUCTOR(TypeBuilder typeBuilder, LSO_Parser LSOP) | ||
174 | { | ||
175 | |||
176 | |||
177 | Common.SendToDebug("IL_CREATE_CONSTRUCTOR()"); | ||
178 | //ConstructorBuilder constructor = typeBuilder.DefineConstructor( | ||
179 | // MethodAttributes.Public, | ||
180 | // CallingConventions.Standard, | ||
181 | // new Type[0]); | ||
182 | ConstructorBuilder constructor = typeBuilder.DefineConstructor( | ||
183 | MethodAttributes.Public | | ||
184 | MethodAttributes.SpecialName | | ||
185 | MethodAttributes.RTSpecialName, | ||
186 | CallingConventions.Standard, | ||
187 | new Type[0]); | ||
188 | |||
189 | //Define the reflection ConstructorInfor for System.Object | ||
190 | ConstructorInfo conObj = typeof(LSL_BaseClass).GetConstructor(new Type[0]); | ||
191 | |||
192 | //call constructor of base object | ||
193 | ILGenerator il = constructor.GetILGenerator(); | ||
194 | |||
195 | il.Emit(OpCodes.Ldarg_0); | ||
196 | il.Emit(OpCodes.Call, conObj); | ||
197 | |||
198 | |||
199 | //Common.SendToDebug("IL_CREATE_CONSTRUCTOR: Creating global: UInt32 State = 0;"); | ||
200 | //string FieldName; | ||
201 | //// Create state object | ||
202 | //FieldName = "State"; | ||
203 | //FieldBuilder State_fb = typeBuilder.DefineField( | ||
204 | // FieldName, | ||
205 | // typeof(UInt32), | ||
206 | // FieldAttributes.Public); | ||
207 | //il.Emit(OpCodes.Ldarg_0); | ||
208 | //il.Emit(OpCodes.Ldc_I4, 0); | ||
209 | //il.Emit(OpCodes.Stfld, State_fb); | ||
210 | |||
211 | |||
212 | //Common.SendToDebug("IL_CREATE_CONSTRUCTOR: Creating global: LSL_BuiltIn_Commands_TestImplementation LSL_BuiltIns = New LSL_BuiltIn_Commands_TestImplementation();"); | ||
213 | ////Type objType1 = typeof(object); | ||
214 | //Type objType1 = typeof(LSL_BuiltIn_Commands_TestImplementation); | ||
215 | |||
216 | //FieldName = "LSL_BuiltIns"; | ||
217 | //FieldBuilder LSL_BuiltIns_fb = typeBuilder.DefineField( | ||
218 | // FieldName, | ||
219 | // objType1, | ||
220 | // FieldAttributes.Public); | ||
221 | |||
222 | ////LSL_BuiltIn_Commands_TestImplementation _ti = new LSL_BuiltIn_Commands_TestImplementation(); | ||
223 | //il.Emit(OpCodes.Ldarg_0); | ||
224 | ////il.Emit(OpCodes.Ldstr, "Test 123"); | ||
225 | //il.Emit(OpCodes.Newobj, objType1.GetConstructor(new Type[] { })); | ||
226 | //il.Emit(OpCodes.Stfld, LSL_BuiltIns_fb); | ||
227 | |||
228 | foreach (UInt32 pos in LSOP.StaticBlocks.Keys) | ||
229 | { | ||
230 | LSO_Struct.StaticBlock sb; | ||
231 | LSOP.StaticBlocks.TryGetValue(pos, out sb); | ||
232 | |||
233 | if (sb.ObjectType > 0 && sb.ObjectType < 8) { // We don't want void or null's | ||
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 | { | ||
247 | case LSO_Enums.Variable_Type_Codes.Float: | ||
248 | case LSO_Enums.Variable_Type_Codes.Integer: | ||
249 | //UInt32 | ||
250 | il.Emit(OpCodes.Ldc_I4, BitConverter.ToUInt32(sb.BlockVariable, 0)); | ||
251 | datatype = typeof(UInt32); | ||
252 | il.Emit(OpCodes.Box, datatype); | ||
253 | break; | ||
254 | case LSO_Enums.Variable_Type_Codes.String: | ||
255 | case LSO_Enums.Variable_Type_Codes.Key: | ||
256 | //String | ||
257 | LSO_Struct.HeapBlock hb = LSOP.GetHeap(LSOP.myHeader.HR + BitConverter.ToUInt32(sb.BlockVariable, 0) - 1); | ||
258 | il.Emit(OpCodes.Ldstr, System.Text.Encoding.UTF8.GetString(hb.Data)); | ||
259 | datatype = typeof(string); | ||
260 | break; | ||
261 | case LSO_Enums.Variable_Type_Codes.Vector: | ||
262 | datatype = typeof(LSO_Enums.Vector); | ||
263 | //TODO: Not implemented | ||
264 | break; | ||
265 | case LSO_Enums.Variable_Type_Codes.Rotation: | ||
266 | //Object | ||
267 | //TODO: Not implemented | ||
268 | datatype = typeof(LSO_Enums.Rotation); | ||
269 | break; | ||
270 | default: | ||
271 | datatype = typeof(object); | ||
272 | break; | ||
273 | } | ||
274 | |||
275 | |||
276 | // Make call | ||
277 | il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("AddToStatic", new Type[] { typeof(UInt32), datatype })); | ||
278 | } | ||
279 | |||
280 | } | ||
281 | |||
282 | |||
283 | |||
284 | |||
285 | ////il.Emit(OpCodes.Newobj, typeof(UInt32)); | ||
286 | //il.Emit(OpCodes.Starg_0); | ||
287 | //// Create LSL function library | ||
288 | //FieldBuilder LSL_BuiltIns_fb = typeBuilder.DefineField("LSL_BuiltIns", typeof(LSL_BuiltIn_Commands_Interface), FieldAttributes.Public); | ||
289 | //il.Emit(OpCodes.Newobj, typeof(LSL_BuiltIn_Commands_Interface)); | ||
290 | //il.Emit(OpCodes.Stloc_1); | ||
291 | |||
292 | il.Emit(OpCodes.Ret); | ||
293 | } | ||
294 | |||
295 | |||
296 | |||
297 | |||
298 | // End of class | ||
299 | } | ||
300 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/IL_common_functions.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/IL_common_functions.cs new file mode 100644 index 0000000..76738b8 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/IL_common_functions.cs | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using System.Reflection; | ||
33 | using System.Reflection.Emit; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
36 | { | ||
37 | partial class LSO_Parser | ||
38 | { | ||
39 | private static TypeBuilder CreateType(ModuleBuilder modBuilder, string typeName) | ||
40 | { | ||
41 | TypeBuilder typeBuilder = modBuilder.DefineType(typeName, | ||
42 | TypeAttributes.Public | | ||
43 | TypeAttributes.Class | | ||
44 | TypeAttributes.AutoClass | | ||
45 | TypeAttributes.AnsiClass | | ||
46 | TypeAttributes.BeforeFieldInit | | ||
47 | TypeAttributes.AutoLayout, | ||
48 | typeof(object), | ||
49 | new Type[] { typeof(object) }); | ||
50 | return typeBuilder; | ||
51 | |||
52 | } | ||
53 | |||
54 | |||
55 | } | ||
56 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_BaseClass.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_BaseClass.cs new file mode 100644 index 0000000..b88a905 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_BaseClass.cs | |||
@@ -0,0 +1,58 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using System.IO; | ||
5 | |||
6 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
7 | { | ||
8 | public partial class LSL_BaseClass | ||
9 | { | ||
10 | //public MemoryStream LSLStack = new MemoryStream(); | ||
11 | public Stack<object> LSLStack = new Stack<object>(); | ||
12 | public Dictionary<UInt32, object> StaticVariables = new Dictionary<UInt32, object>(); | ||
13 | public Dictionary<UInt32, object> GlobalVariables = new Dictionary<UInt32, object>(); | ||
14 | public Dictionary<UInt32, object> LocalVariables = new Dictionary<UInt32, object>(); | ||
15 | //public System.Collections.Generic.List<string> FunctionList = new System.Collections.Generic.List<string>(); | ||
16 | //public void AddFunction(String x) { | ||
17 | // FunctionList.Add(x); | ||
18 | //} | ||
19 | //public Stack<StackItemStruct> LSLStack = new Stack<StackItemStruct>; | ||
20 | //public struct StackItemStruct | ||
21 | //{ | ||
22 | // public LSO_Enums.Variable_Type_Codes ItemType; | ||
23 | // public object Data; | ||
24 | //} | ||
25 | public UInt32 State = 0; | ||
26 | public LSL_BuiltIn_Commands_Interface LSL_Builtins; | ||
27 | public LSL_BuiltIn_Commands_Interface GetLSL_BuiltIn() | ||
28 | { | ||
29 | return LSL_Builtins; | ||
30 | } | ||
31 | |||
32 | |||
33 | public LSL_BaseClass() { } | ||
34 | |||
35 | |||
36 | public virtual int OverrideMe() | ||
37 | { | ||
38 | return 0; | ||
39 | } | ||
40 | public void Start(LSL_BuiltIn_Commands_Interface LSLBuiltins) | ||
41 | { | ||
42 | LSL_Builtins = LSLBuiltins; | ||
43 | |||
44 | Common.SendToLog("OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass.Start() called"); | ||
45 | //LSL_Builtins.llSay(0, "Test"); | ||
46 | return; | ||
47 | } | ||
48 | |||
49 | public void AddToStatic(UInt32 index, object obj) | ||
50 | { | ||
51 | Common.SendToDebug("AddToStatic: " + index + " type: " + obj.GetType()); | ||
52 | StaticVariables.Add(index, obj); | ||
53 | } | ||
54 | |||
55 | |||
56 | |||
57 | } | ||
58 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_BaseClass_Builtins.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_BaseClass_Builtins.cs new file mode 100644 index 0000000..d6f9a88 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_BaseClass_Builtins.cs | |||
@@ -0,0 +1,373 @@ | |||
1 | //using System; | ||
2 | //using System.Collections.Generic; | ||
3 | //using System.Text; | ||
4 | |||
5 | //namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
6 | //{ | ||
7 | // public partial class LSL_BaseClass | ||
8 | // { | ||
9 | |||
10 | |||
11 | // public float llSin() { | ||
12 | // float f = (float)LSLStack.Pop(); | ||
13 | // return LSL_Builtins.llSin(f); | ||
14 | // } | ||
15 | // public float llCos() { | ||
16 | // float f = (float)LSLStack.Pop(); | ||
17 | // return LSL_Builtins.llCos(f); | ||
18 | // } | ||
19 | // public float llTan() { | ||
20 | // float f = (float)LSLStack.Pop(); | ||
21 | // return LSL_Builtins.llTan(f); | ||
22 | // } | ||
23 | // public float llAtan2() { | ||
24 | // float x = (float)LSLStack.Pop(); | ||
25 | // float y = (float)LSLStack.Pop(); | ||
26 | // return LSL_Builtins.llAtan2(x, y); | ||
27 | // } | ||
28 | // public float llSqrt() { | ||
29 | // float f = (float)LSLStack.Pop(); | ||
30 | // return LSL_Builtins.llSqrt(f); | ||
31 | // } | ||
32 | // float llPow() | ||
33 | // { | ||
34 | // float fexponent = (float)LSLStack.Pop(); | ||
35 | // float fbase = (float)LSLStack.Pop(); | ||
36 | // return LSL_Builtins.llPow(fbase, fexponent); | ||
37 | // } | ||
38 | // //UInt32 llAbs(UInt32 i){ return; } | ||
39 | // //float llFabs(float f){ return; } | ||
40 | // //float llFrand(float mag){ return; } | ||
41 | // //UInt32 llFloor(float f){ return; } | ||
42 | // //UInt32 llCeil(float f){ return; } | ||
43 | // //UInt32 llRound(float f){ return; } | ||
44 | // //float llVecMag(LSO_Enums.Vector v){ return; } | ||
45 | // //LSO_Enums.Vector llVecNorm(LSO_Enums.Vector v){ return; } | ||
46 | // //float llVecDist(LSO_Enums.Vector a, LSO_Enums.Vector b){ return; } | ||
47 | // //LSO_Enums.Vector llRot2Euler(LSO_Enums.Rotation r){ return; } | ||
48 | // //LSO_Enums.Rotation llEuler2Rot(LSO_Enums.Vector v){ return; } | ||
49 | // //LSO_Enums.Rotation llAxes2Rot(LSO_Enums.Vector fwd, LSO_Enums.Vector left, LSO_Enums.Vector up){ return; } | ||
50 | // //LSO_Enums.Vector llRot2Fwd(LSO_Enums.Rotation r){ return; } | ||
51 | // //LSO_Enums.Vector llRot2Left(LSO_Enums.Rotation r){ return; } | ||
52 | // //LSO_Enums.Vector llRot2Up(LSO_Enums.Rotation r){ return; } | ||
53 | // //LSO_Enums.Rotation llRotBetween(LSO_Enums.Vector start, LSO_Enums.Vector end){ return; } | ||
54 | // public void llWhisper() | ||
55 | // { | ||
56 | // UInt16 i = (UInt16)LSLStack.Pop(); | ||
57 | // string s = (string)LSLStack.Pop(); | ||
58 | // LSL_Builtins.llWhisper(i, s); | ||
59 | // } | ||
60 | // public void llSay() | ||
61 | // { | ||
62 | // UInt16 i = (UInt16)LSLStack.Pop(); | ||
63 | // string s = (string)LSLStack.Pop(); | ||
64 | // LSL_Builtins.llSay(i, s); | ||
65 | // } | ||
66 | // //void llShout(UInt16 channelID, string text); | ||
67 | // //UInt32 llListen(UInt16 channelID, string name, LSO_Enums.Key ID, string msg); | ||
68 | // //void llListenControl(UInt32 number, UInt32 active); | ||
69 | // //void llListenRemove(UInt32 number); | ||
70 | // //void llSensor(string name, LSO_Enums.Key id, UInt32 type, float range, float arc); | ||
71 | // //void llSensorRepeat(string name, LSO_Enums.Key id, UInt32 type, float range, float arc, float rate); | ||
72 | // //void llSensorRemove(); | ||
73 | // //string llDetectedName(UInt32 number); | ||
74 | // //LSO_Enums.Key llDetectedKey(UInt32 number); | ||
75 | // //LSO_Enums.Key llDetectedOwner(UInt32 number); | ||
76 | // //UInt32 llDetectedType(UInt32 number); | ||
77 | // //LSO_Enums.Vector llDetectedPos(UInt32 number); | ||
78 | // //LSO_Enums.Vector llDetectedVel(UInt32 number); | ||
79 | // //LSO_Enums.Vector llDetectedGrab(UInt32 number); | ||
80 | // //LSO_Enums.Rotation llDetectedRot(UInt32 number); | ||
81 | // //UInt32 llDetectedGroup(UInt32 number); | ||
82 | // //UInt32 llDetectedLinkNumber(UInt32 number); | ||
83 | // //void llDie(); | ||
84 | // //float llGround(LSO_Enums.Vector offset); | ||
85 | // //float llCloud(LSO_Enums.Vector offset); | ||
86 | // //LSO_Enums.Vector llWind(LSO_Enums.Vector offset); | ||
87 | // //void llSetStatus(UInt32 status, UInt32 value); | ||
88 | // //UInt32 llGetStatus(UInt32 status); | ||
89 | // //void llSetScale(LSO_Enums.Vector scale); | ||
90 | // //LSO_Enums.Vector llGetScale(); | ||
91 | // //void llSetColor(); | ||
92 | // //float llGetAlpha(); | ||
93 | // //void llSetAlpha(); | ||
94 | // //LSO_Enums.Vector llGetColor(); | ||
95 | // //void llSetTexture(); | ||
96 | // //void llScaleTexture(); | ||
97 | // //void llOffsetTexture(); | ||
98 | // //void llRotateTexture(); | ||
99 | // //string llGetTexture(); | ||
100 | // //void llSetPos(); | ||
101 | |||
102 | // public void llGetPos() { } | ||
103 | // public void llGetLocalPos() { } | ||
104 | // public void llSetRot() { } | ||
105 | // public void llGetRot() { } | ||
106 | // public void llGetLocalRot() { } | ||
107 | // public void llSetForce() { } | ||
108 | // public void llGetForce() { } | ||
109 | // public void llTarget() { } | ||
110 | // public void llTargetRemove() { } | ||
111 | // public void llRotTarget() { } | ||
112 | // public void llRotTargetRemove() { } | ||
113 | // public void llMoveToTarget() { } | ||
114 | // public void llStopMoveToTarget() { } | ||
115 | // public void llApplyImpulse() { } | ||
116 | // public void llApplyRotationalImpulse() { } | ||
117 | // public void llSetTorque() { } | ||
118 | // public void llGetTorque() { } | ||
119 | // public void llSetForceAndTorque() { } | ||
120 | // public void llGetVel() { } | ||
121 | // public void llGetAccel() { } | ||
122 | // public void llGetOmega() { } | ||
123 | // public void llGetTimeOfDay() { } | ||
124 | // public void llGetWallclock() { } | ||
125 | // public void llGetTime() { } | ||
126 | // public void llResetTime() { } | ||
127 | // public void llGetAndResetTime() { } | ||
128 | // public void llSound() { } | ||
129 | // public void llPlaySound() { } | ||
130 | // public void llLoopSound() { } | ||
131 | // public void llLoopSoundMaster() { } | ||
132 | // public void llLoopSoundSlave() { } | ||
133 | // public void llPlaySoundSlave() { } | ||
134 | // public void llTriggerSound() { } | ||
135 | // public void llStopSound() { } | ||
136 | // public void llPreloadSound() { } | ||
137 | // public void llGetSubString() { } | ||
138 | // public void llDeleteSubString() { } | ||
139 | // public void llInsertString() { } | ||
140 | // public void llToUpper() { } | ||
141 | // public void llToLower() { } | ||
142 | // public void llGiveMoney() { } | ||
143 | // public void llMakeExplosion() { } | ||
144 | // public void llMakeFountain() { } | ||
145 | // public void llMakeSmoke() { } | ||
146 | // public void llMakeFire() { } | ||
147 | // public void llRezObject() { } | ||
148 | // public void llLookAt() { } | ||
149 | // public void llStopLookAt() { } | ||
150 | // public void llSetTimerEvent() { } | ||
151 | // public void llSleep() { } | ||
152 | // public void llGetMass() { } | ||
153 | // public void llCollisionFilter() { } | ||
154 | // public void llTakeControls() { } | ||
155 | // public void llReleaseControls() { } | ||
156 | // public void llAttachToAvatar() { } | ||
157 | // public void llDetachFromAvatar() { } | ||
158 | // public void llTakeCamera() { } | ||
159 | // public void llReleaseCamera() { } | ||
160 | // public void llGetOwner() { } | ||
161 | // public void llInstantMessage() { } | ||
162 | // public void llEmail() { } | ||
163 | // public void llGetNextEmail() { } | ||
164 | // public void llGetKey() { } | ||
165 | // public void llSetBuoyancy() { } | ||
166 | // public void llSetHoverHeight() { } | ||
167 | // public void llStopHover() { } | ||
168 | // public void llMinEventDelay() { } | ||
169 | // public void llSoundPreload() { } | ||
170 | // public void llRotLookAt() { } | ||
171 | // public void llStringLength() { } | ||
172 | // public void llStartAnimation() { } | ||
173 | // public void llStopAnimation() { } | ||
174 | // public void llPointAt() { } | ||
175 | // public void llStopPointAt() { } | ||
176 | // public void llTargetOmega() { } | ||
177 | // public void llGetStartParameter() { } | ||
178 | // public void llGodLikeRezObject() { } | ||
179 | // public void llRequestPermissions() { } | ||
180 | // public void llGetPermissionsKey() { } | ||
181 | // public void llGetPermissions() { } | ||
182 | // public void llGetLinkNumber() { } | ||
183 | // public void llSetLinkColor() { } | ||
184 | // public void llCreateLink() { } | ||
185 | // public void llBreakLink() { } | ||
186 | // public void llBreakAllLinks() { } | ||
187 | // public void llGetLinkKey() { } | ||
188 | // public void llGetLinkName() { } | ||
189 | // public void llGetInventoryNumber() { } | ||
190 | // public void llGetInventoryName() { } | ||
191 | // public void llSetScriptState() { } | ||
192 | // public void llGetEnergy() { } | ||
193 | // public void llGiveInventory() { } | ||
194 | // public void llRemoveInventory() { } | ||
195 | // public void llSetText() { } | ||
196 | // public void llWater() { } | ||
197 | // public void llPassTouches() { } | ||
198 | // public void llRequestAgentData() { } | ||
199 | // public void llRequestInventoryData() { } | ||
200 | // public void llSetDamage() { } | ||
201 | // public void llTeleportAgentHome() { } | ||
202 | // public void llModifyLand() { } | ||
203 | // public void llCollisionSound() { } | ||
204 | // public void llCollisionSprite() { } | ||
205 | // public void llGetAnimation() { } | ||
206 | // public void llResetScript() { } | ||
207 | // public void llMessageLinked() { } | ||
208 | // public void llPushObject() { } | ||
209 | // public void llPassCollisions() { } | ||
210 | // public void llGetScriptName() { } | ||
211 | // public void llGetNumberOfSides() { } | ||
212 | // public void llAxisAngle2Rot() { } | ||
213 | // public void llRot2Axis() { } | ||
214 | // public void llRot2Angle() { } | ||
215 | // public void llAcos() { } | ||
216 | // public void llAsin() { } | ||
217 | // public void llAngleBetween() { } | ||
218 | // public void llGetInventoryKey() { } | ||
219 | // public void llAllowInventoryDrop() { } | ||
220 | // public void llGetSunDirection() { } | ||
221 | // public void llGetTextureOffset() { } | ||
222 | // public void llGetTextureScale() { } | ||
223 | // public void llGetTextureRot() { } | ||
224 | // public void llSubStringIndex() { } | ||
225 | // public void llGetOwnerKey() { } | ||
226 | // public void llGetCenterOfMass() { } | ||
227 | // public void llListSort() { } | ||
228 | // public void llGetListLength() { } | ||
229 | // public void llList2Integer() { } | ||
230 | // public void llList2Float() { } | ||
231 | // public void llList2String() { } | ||
232 | // public void llList2Key() { } | ||
233 | // public void llList2Vector() { } | ||
234 | // public void llList2Rot() { } | ||
235 | // public void llList2List() { } | ||
236 | // public void llDeleteSubList() { } | ||
237 | // public void llGetListEntryType() { } | ||
238 | // public void llList2CSV() { } | ||
239 | // public void llCSV2List() { } | ||
240 | // public void llListRandomize() { } | ||
241 | // public void llList2ListStrided() { } | ||
242 | // public void llGetRegionCorner() { } | ||
243 | // public void llListInsertList() { } | ||
244 | // public void llListFindList() { } | ||
245 | // public void llGetObjectName() { } | ||
246 | // public void llSetObjectName() { } | ||
247 | // public void llGetDate() { } | ||
248 | // public void llEdgeOfWorld() { } | ||
249 | // public void llGetAgentInfo() { } | ||
250 | // public void llAdjustSoundVolume() { } | ||
251 | // public void llSetSoundQueueing() { } | ||
252 | // public void llSetSoundRadius() { } | ||
253 | // public void llKey2Name() { } | ||
254 | // public void llSetTextureAnim() { } | ||
255 | // public void llTriggerSoundLimited() { } | ||
256 | // public void llEjectFromLand() { } | ||
257 | // public void llParseString2List() { } | ||
258 | // public void llOverMyLand() { } | ||
259 | // public void llGetLandOwnerAt() { } | ||
260 | // public void llGetNotecardLine() { } | ||
261 | // public void llGetAgentSize() { } | ||
262 | // public void llSameGroup() { } | ||
263 | // public void llUnSit() { } | ||
264 | // public void llGroundSlope() { } | ||
265 | // public void llGroundNormal() { } | ||
266 | // public void llGroundContour() { } | ||
267 | // public void llGetAttached() { } | ||
268 | // public void llGetFreeMemory() { } | ||
269 | // public void llGetRegionName() { } | ||
270 | // public void llGetRegionTimeDilation() { } | ||
271 | // public void llGetRegionFPS() { } | ||
272 | // public void llParticleSystem() { } | ||
273 | // public void llGroundRepel() { } | ||
274 | // public void llGiveInventoryList() { } | ||
275 | // public void llSetVehicleType() { } | ||
276 | // public void llSetVehicleFloatParam() { } | ||
277 | // public void llSetVehicleVectorParam() { } | ||
278 | // public void llSetVehicleRotationParam() { } | ||
279 | // public void llSetVehicleFlags() { } | ||
280 | // public void llRemoveVehicleFlags() { } | ||
281 | // public void llSitTarget() { } | ||
282 | // public void llAvatarOnSitTarget() { } | ||
283 | // public void llAddToLandPassList() { } | ||
284 | // public void llSetTouchText() { } | ||
285 | // public void llSetSitText() { } | ||
286 | // public void llSetCameraEyeOffset() { } | ||
287 | // public void llSetCameraAtOffset() { } | ||
288 | // public void llDumpList2String() { } | ||
289 | // public void llScriptDanger() { } | ||
290 | // public void llDialog() { } | ||
291 | // public void llVolumeDetect() { } | ||
292 | // public void llResetOtherScript() { } | ||
293 | // public void llGetScriptState() { } | ||
294 | // public void llRemoteLoadScript() { } | ||
295 | // public void llSetRemoteScriptAccessPin() { } | ||
296 | // public void llRemoteLoadScriptPin() { } | ||
297 | // public void llOpenRemoteDataChannel() { } | ||
298 | // public void llSendRemoteData() { } | ||
299 | // public void llRemoteDataReply() { } | ||
300 | // public void llCloseRemoteDataChannel() { } | ||
301 | // public void llMD5String() { } | ||
302 | // public void llSetPrimitiveParams() { } | ||
303 | // public void llStringToBase64() { } | ||
304 | // public void llBase64ToString() { } | ||
305 | // public void llXorBase64Strings() { } | ||
306 | // public void llRemoteDataSetRegion() { } | ||
307 | // public void llLog10() { } | ||
308 | // public void llLog() { } | ||
309 | // public void llGetAnimationList() { } | ||
310 | // public void llSetParcelMusicURL() { } | ||
311 | // public void llGetRootPosition() { } | ||
312 | // public void llGetRootRotation() { } | ||
313 | // public void llGetObjectDesc() { } | ||
314 | // public void llSetObjectDesc() { } | ||
315 | // public void llGetCreator() { } | ||
316 | // public void llGetTimestamp() { } | ||
317 | // public void llSetLinkAlpha() { } | ||
318 | // public void llGetNumberOfPrims() { } | ||
319 | // public void llGetNumberOfNotecardLines() { } | ||
320 | // public void llGetBoundingBox() { } | ||
321 | // public void llGetGeometricCenter() { } | ||
322 | // public void llGetPrimitiveParams() { } | ||
323 | // public void llIntegerToBase64() { } | ||
324 | // public void llBase64ToInteger() { } | ||
325 | // public void llGetGMTclock() { } | ||
326 | // public void llGetSimulatorHostname() { } | ||
327 | // public void llSetLocalRot() { } | ||
328 | // public void llParseStringKeepNulls() { } | ||
329 | // public void llRezAtRoot() { } | ||
330 | // public void llGetObjectPermMask() { } | ||
331 | // public void llSetObjectPermMask() { } | ||
332 | // public void llGetInventoryPermMask() { } | ||
333 | // public void llSetInventoryPermMask() { } | ||
334 | // public void llGetInventoryCreator() { } | ||
335 | // public void llOwnerSay() { } | ||
336 | // public void llRequestSimulatorData() { } | ||
337 | // public void llForceMouselook() { } | ||
338 | // public void llGetObjectMass() { } | ||
339 | // public void llListReplaceList() { } | ||
340 | // public void llLoadURL() { } | ||
341 | // public void llParcelMediaCommandList() { } | ||
342 | // public void llParcelMediaQuery() { } | ||
343 | // public void llModPow() { } | ||
344 | // public void llGetInventoryType() { } | ||
345 | // public void llSetPayPrice() { } | ||
346 | // public void llGetCameraPos() { } | ||
347 | // public void llGetCameraRot() { } | ||
348 | // public void llSetPrimURL() { } | ||
349 | // public void llRefreshPrimURL() { } | ||
350 | // public void llEscapeURL() { } | ||
351 | // public void llUnescapeURL() { } | ||
352 | // public void llMapDestination() { } | ||
353 | // public void llAddToLandBanList() { } | ||
354 | // public void llRemoveFromLandPassList() { } | ||
355 | // public void llRemoveFromLandBanList() { } | ||
356 | // public void llSetCameraParams() { } | ||
357 | // public void llClearCameraParams() { } | ||
358 | // public void llListStatistics() { } | ||
359 | // public void llGetUnixTime() { } | ||
360 | // public void llGetParcelFlags() { } | ||
361 | // public void llGetRegionFlags() { } | ||
362 | // public void llXorBase64StringsCorrect() { } | ||
363 | // public void llHTTPRequest() { } | ||
364 | // public void llResetLandBanList() { } | ||
365 | // public void llResetLandPassList() { } | ||
366 | // public void llGetParcelPrimCount() { } | ||
367 | // public void llGetParcelPrimOwners() { } | ||
368 | // public void llGetObjectPrimCount() { } | ||
369 | // public void llGetParcelMaxPrims() { } | ||
370 | // public void llGetParcelDetails() { } | ||
371 | |||
372 | // } | ||
373 | //} | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_BaseClass_OPCODES.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_BaseClass_OPCODES.cs new file mode 100644 index 0000000..b771678 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_BaseClass_OPCODES.cs | |||
@@ -0,0 +1,342 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
6 | { | ||
7 | public partial class LSL_BaseClass | ||
8 | { | ||
9 | |||
10 | |||
11 | |||
12 | public void StoreToLocal(UInt32 index) | ||
13 | { | ||
14 | // TODO: How to determine local? | ||
15 | Common.SendToDebug("::StoreToLocal " + index); | ||
16 | if (LocalVariables.ContainsKey(index)) | ||
17 | LocalVariables.Remove(index); | ||
18 | LocalVariables.Add(index, LSLStack.Peek()); | ||
19 | } | ||
20 | public void StoreToGlobal(UInt32 index) | ||
21 | { | ||
22 | Common.SendToDebug("::StoreToGlobal " + index); | ||
23 | if (GlobalVariables.ContainsKey(index)) | ||
24 | GlobalVariables.Remove(index); | ||
25 | GlobalVariables.Add(index, LSLStack.Peek()); | ||
26 | } | ||
27 | public void StoreToStatic(UInt32 index) | ||
28 | { | ||
29 | Common.SendToDebug("::StoreToStatic " + index); | ||
30 | //if (StaticVariables.ContainsKey(index)) | ||
31 | // StaticVariables.Remove(index); | ||
32 | StaticVariables.Add(index, LSLStack.Peek()); | ||
33 | } | ||
34 | public void GetFromLocal(UInt32 index) | ||
35 | { | ||
36 | // TODO: How to determine local? | ||
37 | Common.SendToDebug("::GetFromLocal " + index); | ||
38 | object ret; | ||
39 | LocalVariables.TryGetValue(index, out ret); | ||
40 | LSLStack.Push(ret); | ||
41 | //return ret; | ||
42 | } | ||
43 | public void GetFromGlobal(UInt32 index) | ||
44 | { | ||
45 | Common.SendToDebug("::GetFromGlobal " + index); | ||
46 | object ret; | ||
47 | GlobalVariables.TryGetValue(index, out ret); | ||
48 | LSLStack.Push(ret); | ||
49 | //return ret; | ||
50 | } | ||
51 | public void GetFromStatic(UInt32 index) | ||
52 | { | ||
53 | Common.SendToDebug("::GetFromStatic " + index); | ||
54 | object ret; | ||
55 | StaticVariables.TryGetValue(index, out ret); | ||
56 | Common.SendToDebug("::GetFromStatic - ObjectType: " + ret.GetType().ToString()); | ||
57 | LSLStack.Push(ret); | ||
58 | //return ret; | ||
59 | } | ||
60 | |||
61 | public object POPToStack() | ||
62 | { | ||
63 | Common.SendToDebug("::POPToStack"); | ||
64 | //return LSLStack.Pop(); | ||
65 | object p = LSLStack.Pop(); | ||
66 | if (p.GetType() == typeof(UInt32)) | ||
67 | return (UInt32)p; | ||
68 | if (p.GetType() == typeof(string)) | ||
69 | return (string)p; | ||
70 | if (p.GetType() == typeof(Int32)) | ||
71 | return (Int32)p; | ||
72 | if (p.GetType() == typeof(UInt16)) | ||
73 | return (UInt16)p; | ||
74 | if (p.GetType() == typeof(float)) | ||
75 | return (float)p; | ||
76 | if (p.GetType() == typeof(LSO_Enums.Vector)) | ||
77 | return (LSO_Enums.Vector)p; | ||
78 | if (p.GetType() == typeof(LSO_Enums.Rotation)) | ||
79 | return (LSO_Enums.Rotation)p; | ||
80 | if (p.GetType() == typeof(LSO_Enums.Key)) | ||
81 | return (LSO_Enums.Key)p; | ||
82 | |||
83 | return p; | ||
84 | } | ||
85 | |||
86 | //public object POPToStack(UInt32 count) | ||
87 | //{ | ||
88 | // // POP NUMBER FROM TOP OF STACK | ||
89 | // //LSLStack.SetLength(LSLStack.Length - 4); | ||
90 | // Common.SendToDebug("::POPToStack " + count); | ||
91 | // if (count < 2) | ||
92 | // return LSLStack.Pop(); | ||
93 | |||
94 | // Stack<object> s = new Stack<object>(); | ||
95 | // for (int i = 0; i < count; i++) | ||
96 | // { | ||
97 | // s.Push(LSLStack.Pop); | ||
98 | |||
99 | // } | ||
100 | |||
101 | //} | ||
102 | |||
103 | public void POP() | ||
104 | { | ||
105 | // POP NUMBER FROM TOP OF STACK | ||
106 | //LSLStack.SetLength(LSLStack.Length - 4); | ||
107 | Common.SendToDebug("::POP"); | ||
108 | if (LSLStack.Count < 1) | ||
109 | { | ||
110 | //TODO: Temporary fix | ||
111 | Common.SendToDebug("ERROR: TRYING TO POP EMPTY STACK!"); | ||
112 | } | ||
113 | else | ||
114 | { | ||
115 | LSLStack.Pop(); | ||
116 | } | ||
117 | } | ||
118 | public void PUSH(object Param) | ||
119 | { | ||
120 | if (Param == null) | ||
121 | { | ||
122 | Common.SendToDebug("::PUSH: <null>"); | ||
123 | } | ||
124 | else | ||
125 | { | ||
126 | |||
127 | //Common.SendToDebug("::PUSH: " + Param.GetType()); | ||
128 | } | ||
129 | |||
130 | LSLStack.Push(Param); | ||
131 | } | ||
132 | public void ADD(UInt32 Param) | ||
133 | { | ||
134 | Common.SendToDebug("::ADD: " + Param); | ||
135 | object o2 = LSLStack.Pop(); | ||
136 | object o1 = LSLStack.Pop(); | ||
137 | Common.SendToDebug("::ADD: Debug: o1: " + o1.GetType() + " (" + o1.ToString() + "), o2: " + o2.GetType() + " (" + o2.ToString() + ")"); | ||
138 | if (o2.GetType() == typeof(string)) | ||
139 | { | ||
140 | LSLStack.Push((string)o1 + (string)o2); | ||
141 | return; | ||
142 | } | ||
143 | if (o2.GetType() == typeof(UInt32)) | ||
144 | { | ||
145 | LSLStack.Push((UInt32)o1 + (UInt32)o2); | ||
146 | return; | ||
147 | } | ||
148 | |||
149 | } | ||
150 | public void SUB(UInt32 Param) | ||
151 | { | ||
152 | Common.SendToDebug("::SUB: " + Param); | ||
153 | UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
154 | UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
155 | LSLStack.Push((UInt32)(i1 - i2)); | ||
156 | } | ||
157 | public void MUL(UInt32 Param) | ||
158 | { | ||
159 | Common.SendToDebug("::SUB: " + Param); | ||
160 | UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
161 | UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
162 | LSLStack.Push((UInt32)(i1 * i2)); | ||
163 | } | ||
164 | public void DIV(UInt32 Param) | ||
165 | { | ||
166 | Common.SendToDebug("::DIV: " + Param); | ||
167 | UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
168 | UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
169 | LSLStack.Push((UInt32)(i1 / i2)); | ||
170 | } | ||
171 | |||
172 | |||
173 | public void MOD(UInt32 Param) | ||
174 | { | ||
175 | Common.SendToDebug("::MOD: " + Param); | ||
176 | UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
177 | UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
178 | LSLStack.Push((UInt32)(i1 % i2)); | ||
179 | } | ||
180 | public void EQ(UInt32 Param) | ||
181 | { | ||
182 | Common.SendToDebug("::EQ: " + Param); | ||
183 | UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
184 | UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
185 | if (i1 == i2) | ||
186 | { | ||
187 | LSLStack.Push((UInt32)1); | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | LSLStack.Push((UInt32)0); | ||
192 | } | ||
193 | } | ||
194 | public void NEQ(UInt32 Param) | ||
195 | { | ||
196 | Common.SendToDebug("::NEQ: " + Param); | ||
197 | UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
198 | UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
199 | if (i1 != i2) | ||
200 | { | ||
201 | LSLStack.Push((UInt32)1); | ||
202 | } | ||
203 | else | ||
204 | { | ||
205 | LSLStack.Push((UInt32)0); | ||
206 | } | ||
207 | } | ||
208 | public void LEQ(UInt32 Param) | ||
209 | { | ||
210 | Common.SendToDebug("::LEQ: " + Param); | ||
211 | UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
212 | UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
213 | if (i1 <= i2) | ||
214 | { | ||
215 | LSLStack.Push((UInt32)1); | ||
216 | } | ||
217 | else | ||
218 | { | ||
219 | LSLStack.Push((UInt32)0); | ||
220 | } | ||
221 | } | ||
222 | public void GEQ(UInt32 Param) | ||
223 | { | ||
224 | Common.SendToDebug("::GEQ: " + Param); | ||
225 | UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
226 | UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
227 | if (i1 >= i2) | ||
228 | { | ||
229 | LSLStack.Push((UInt32)1); | ||
230 | } | ||
231 | else | ||
232 | { | ||
233 | LSLStack.Push((UInt32)0); | ||
234 | } | ||
235 | } | ||
236 | public void LESS(UInt32 Param) | ||
237 | { | ||
238 | Common.SendToDebug("::LESS: " + Param); | ||
239 | UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
240 | UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
241 | if (i1 < i2) | ||
242 | { | ||
243 | LSLStack.Push((UInt32)1); | ||
244 | } | ||
245 | else | ||
246 | { | ||
247 | LSLStack.Push((UInt32)0); | ||
248 | } | ||
249 | } | ||
250 | public void GREATER(UInt32 Param) | ||
251 | { | ||
252 | Common.SendToDebug("::GREATER: " + Param); | ||
253 | UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
254 | UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
255 | if (i1 > i2) | ||
256 | { | ||
257 | LSLStack.Push((UInt32)1); | ||
258 | } | ||
259 | else | ||
260 | { | ||
261 | LSLStack.Push((UInt32)0); | ||
262 | } | ||
263 | } | ||
264 | |||
265 | |||
266 | |||
267 | public void BITAND() | ||
268 | { | ||
269 | Common.SendToDebug("::BITAND"); | ||
270 | UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
271 | UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
272 | LSLStack.Push((UInt32)(i1 & i2)); | ||
273 | } | ||
274 | public void BITOR() | ||
275 | { | ||
276 | Common.SendToDebug("::BITOR"); | ||
277 | UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
278 | UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
279 | LSLStack.Push((UInt32)(i1 | i2)); | ||
280 | } | ||
281 | public void BITXOR() | ||
282 | { | ||
283 | Common.SendToDebug("::BITXOR"); | ||
284 | UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
285 | UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
286 | LSLStack.Push((UInt32)(i1 ^ i2)); | ||
287 | } | ||
288 | public void BOOLAND() | ||
289 | { | ||
290 | Common.SendToDebug("::BOOLAND"); | ||
291 | bool b2 = bool.Parse((string)LSLStack.Pop()); | ||
292 | bool b1 = bool.Parse((string)LSLStack.Pop()); | ||
293 | if (b1 && b2) | ||
294 | { | ||
295 | LSLStack.Push((UInt32)1); | ||
296 | } | ||
297 | else | ||
298 | { | ||
299 | LSLStack.Push((UInt32)0); | ||
300 | } | ||
301 | } | ||
302 | public void BOOLOR() | ||
303 | { | ||
304 | Common.SendToDebug("::BOOLOR"); | ||
305 | bool b2 = bool.Parse((string)LSLStack.Pop()); | ||
306 | bool b1 = bool.Parse((string)LSLStack.Pop()); | ||
307 | |||
308 | if (b1 || b2) | ||
309 | { | ||
310 | LSLStack.Push((UInt32)1); | ||
311 | } | ||
312 | else | ||
313 | { | ||
314 | LSLStack.Push((UInt32)0); | ||
315 | } | ||
316 | |||
317 | } | ||
318 | public void NEG(UInt32 Param) | ||
319 | { | ||
320 | Common.SendToDebug("::NEG: " + Param); | ||
321 | //UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
322 | UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
323 | LSLStack.Push((UInt32)(i1 * -1)); | ||
324 | } | ||
325 | public void BITNOT() | ||
326 | { | ||
327 | //Common.SendToDebug("::BITNOT"); | ||
328 | //UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
329 | //UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
330 | //LSLStack.Push((UInt32)(i1 / i2)); | ||
331 | } | ||
332 | public void BOOLNOT() | ||
333 | { | ||
334 | //Common.SendToDebug("::BOOLNOT"); | ||
335 | ////UInt32 i2 = (UInt32)LSLStack.Pop(); | ||
336 | //UInt32 i1 = (UInt32)LSLStack.Pop(); | ||
337 | //LSLStack.Push((UInt32)(i1)); | ||
338 | } | ||
339 | |||
340 | |||
341 | } | ||
342 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_CLRInterface.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_CLRInterface.cs new file mode 100644 index 0000000..84cb20c --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_CLRInterface.cs | |||
@@ -0,0 +1,79 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
34 | { | ||
35 | public class LSL_CLRInterface | ||
36 | { | ||
37 | public interface LSLScript | ||
38 | { | ||
39 | //public virtual void Run(object arg) | ||
40 | //{ | ||
41 | //} | ||
42 | //void Run(object arg); | ||
43 | |||
44 | //void event_state_entry(object arg); | ||
45 | //void event_state_exit(); | ||
46 | //void event_touch_start(object arg); | ||
47 | //void event_touch(); | ||
48 | //void event_touch_end(); | ||
49 | //void event_collision_start(); | ||
50 | //void event_collision(); | ||
51 | //void event_collision_end(); | ||
52 | //void event_land_collision_start(); | ||
53 | //void event_land_collision(); | ||
54 | //void event_land_collision_end(); | ||
55 | //void event_timer(); | ||
56 | //void event_listen(); | ||
57 | //void event_on_rez(); | ||
58 | //void event_sensor(); | ||
59 | //void event_no_sensor(); | ||
60 | //void event_control(); | ||
61 | //void event_money(); | ||
62 | //void event_email(); | ||
63 | //void event_at_target(); | ||
64 | //void event_not_at_target(); | ||
65 | //void event_at_rot_target(); | ||
66 | //void event_not_at_rot_target(); | ||
67 | //void event_run_time_permissions(); | ||
68 | //void event_changed(); | ||
69 | //void event_attach(); | ||
70 | //void event_dataserver(); | ||
71 | //void event_link_message(); | ||
72 | //void event_moving_start(); | ||
73 | //void event_moving_end(); | ||
74 | //void event_object_rez(); | ||
75 | //void event_remote_data(); | ||
76 | //void event_http_response(); | ||
77 | } | ||
78 | } | ||
79 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_OPCODE_IL_processor.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_OPCODE_IL_processor.cs new file mode 100644 index 0000000..8836195 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSL_OPCODE_IL_processor.cs | |||
@@ -0,0 +1,435 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using System.Reflection; | ||
33 | using System.Reflection.Emit; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
36 | { | ||
37 | partial class LSO_Parser | ||
38 | { | ||
39 | //internal Stack<Type> ILStack = new Stack<Type>(); | ||
40 | //LSO_Enums MyLSO_Enums = new LSO_Enums(); | ||
41 | |||
42 | internal bool LSL_PROCESS_OPCODE(ILGenerator il) | ||
43 | { | ||
44 | |||
45 | byte bp1; | ||
46 | UInt32 u32p1; | ||
47 | float fp1; | ||
48 | UInt16 opcode = br_read(1)[0]; | ||
49 | Common.SendToDebug("OPCODE: " + ((LSO_Enums.Operation_Table)opcode).ToString()); | ||
50 | string idesc = ((LSO_Enums.Operation_Table)opcode).ToString(); | ||
51 | switch ((LSO_Enums.Operation_Table)opcode) | ||
52 | { | ||
53 | |||
54 | /*************** | ||
55 | * IMPLEMENTED * | ||
56 | ***************/ | ||
57 | case LSO_Enums.Operation_Table.NOOP: | ||
58 | break; | ||
59 | case LSO_Enums.Operation_Table.PUSHSP: | ||
60 | // Push Stack Top (Memory Address) to stack | ||
61 | Common.SendToDebug("Instruction " + idesc); | ||
62 | Common.SendToDebug("Instruction " + idesc + ": Description: Pushing Stack Top (Memory Address from header) to stack"); | ||
63 | IL_Push(il, (UInt32)myHeader.SP); | ||
64 | break; | ||
65 | // BYTE | ||
66 | case LSO_Enums.Operation_Table.PUSHARGB: | ||
67 | Common.SendToDebug("Param1: " + br_read(1)[0]); | ||
68 | break; | ||
69 | // INTEGER | ||
70 | case LSO_Enums.Operation_Table.PUSHARGI: | ||
71 | u32p1 = BitConverter.ToUInt32(br_read(4), 0); | ||
72 | Common.SendToDebug("Instruction " + idesc + ", Param1: " + u32p1); | ||
73 | IL_Push(il, u32p1); | ||
74 | break; | ||
75 | // FLOAT | ||
76 | case LSO_Enums.Operation_Table.PUSHARGF: | ||
77 | fp1 = BitConverter.ToUInt32(br_read(4), 0); | ||
78 | Common.SendToDebug("Instruction " + idesc + ", Param1: " + fp1); | ||
79 | IL_Push(il, fp1); | ||
80 | break; | ||
81 | // STRING | ||
82 | case LSO_Enums.Operation_Table.PUSHARGS: | ||
83 | string s = Read_String(); | ||
84 | Common.SendToDebug("Instruction " + idesc + ", Param1: " + s); | ||
85 | IL_Debug(il, "OPCODE: " + idesc + ":" + s); | ||
86 | IL_Push(il, s); | ||
87 | break; | ||
88 | // VECTOR z,y,x | ||
89 | case LSO_Enums.Operation_Table.PUSHARGV: | ||
90 | LSO_Enums.Vector v = new LSO_Enums.Vector(); | ||
91 | v.Z = BitConverter.ToUInt32(br_read(4), 0); | ||
92 | v.Y = BitConverter.ToUInt32(br_read(4), 0); | ||
93 | v.X = BitConverter.ToUInt32(br_read(4), 0); | ||
94 | Common.SendToDebug("Param1 Z: " + v.Z); | ||
95 | Common.SendToDebug("Param1 Y: " + v.Y); | ||
96 | Common.SendToDebug("Param1 X: " + v.X); | ||
97 | IL_Push(il, v); | ||
98 | break; | ||
99 | // ROTATION s,z,y,x | ||
100 | case LSO_Enums.Operation_Table.PUSHARGQ: | ||
101 | LSO_Enums.Rotation r = new LSO_Enums.Rotation(); | ||
102 | r.S = BitConverter.ToUInt32(br_read(4), 0); | ||
103 | r.Z = BitConverter.ToUInt32(br_read(4), 0); | ||
104 | r.Y = BitConverter.ToUInt32(br_read(4), 0); | ||
105 | r.X = BitConverter.ToUInt32(br_read(4), 0); | ||
106 | Common.SendToDebug("Param1 S: " + r.S); | ||
107 | Common.SendToDebug("Param1 Z: " + r.Z); | ||
108 | Common.SendToDebug("Param1 Y: " + r.Y); | ||
109 | Common.SendToDebug("Param1 X: " + r.X); | ||
110 | IL_Push(il, r); | ||
111 | break; | ||
112 | |||
113 | case LSO_Enums.Operation_Table.PUSHE: | ||
114 | IL_Push(il, (UInt32)0); | ||
115 | break; | ||
116 | |||
117 | case LSO_Enums.Operation_Table.PUSHARGE: | ||
118 | u32p1 = BitConverter.ToUInt32(br_read(4), 0); | ||
119 | Common.SendToDebug("Param1: " + u32p1); | ||
120 | //IL_Push(il, new string(" ".ToCharArray()[0], Convert.ToInt32(u32p1))); | ||
121 | IL_Push(il, u32p1); | ||
122 | break; | ||
123 | // BYTE | ||
124 | case LSO_Enums.Operation_Table.ADD: | ||
125 | case LSO_Enums.Operation_Table.SUB: | ||
126 | case LSO_Enums.Operation_Table.MUL: | ||
127 | case LSO_Enums.Operation_Table.DIV: | ||
128 | case LSO_Enums.Operation_Table.EQ: | ||
129 | case LSO_Enums.Operation_Table.NEQ: | ||
130 | case LSO_Enums.Operation_Table.LEQ: | ||
131 | case LSO_Enums.Operation_Table.GEQ: | ||
132 | case LSO_Enums.Operation_Table.LESS: | ||
133 | case LSO_Enums.Operation_Table.GREATER: | ||
134 | case LSO_Enums.Operation_Table.NEG: | ||
135 | case LSO_Enums.Operation_Table.MOD: | ||
136 | bp1 = br_read(1)[0]; | ||
137 | Common.SendToDebug("Param1: " + bp1); | ||
138 | IL_CallBaseFunction(il, idesc, (UInt32)bp1); | ||
139 | break; | ||
140 | |||
141 | // NO ARGUMENTS | ||
142 | case LSO_Enums.Operation_Table.BITAND: | ||
143 | case LSO_Enums.Operation_Table.BITOR: | ||
144 | case LSO_Enums.Operation_Table.BITXOR: | ||
145 | case LSO_Enums.Operation_Table.BOOLAND: | ||
146 | case LSO_Enums.Operation_Table.BOOLOR: | ||
147 | case LSO_Enums.Operation_Table.BITNOT: | ||
148 | case LSO_Enums.Operation_Table.BOOLNOT: | ||
149 | IL_CallBaseFunction(il, idesc); | ||
150 | break; | ||
151 | // SHORT | ||
152 | case LSO_Enums.Operation_Table.CALLLIB_TWO_BYTE: | ||
153 | // TODO: What is size of short? | ||
154 | UInt16 U16p1 = BitConverter.ToUInt16(br_read(2), 0); | ||
155 | Common.SendToDebug("Instruction " + idesc + ": Builtin Command: " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString()); | ||
156 | //Common.SendToDebug("Param1: " + U16p1); | ||
157 | string fname = ((LSO_Enums.BuiltIn_Functions)U16p1).ToString(); | ||
158 | |||
159 | bool cmdFound = false; | ||
160 | foreach (MethodInfo mi in typeof(LSL_BuiltIn_Commands_Interface).GetMethods()) | ||
161 | { | ||
162 | // Found command | ||
163 | if (mi.Name == fname) | ||
164 | { | ||
165 | il.Emit(OpCodes.Ldarg_0); | ||
166 | il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("GetLSL_BuiltIn", new Type[] { })); | ||
167 | // Pop required number of items from my stack to .Net stack | ||
168 | IL_PopToStack(il, mi.GetParameters().Length); | ||
169 | il.Emit(OpCodes.Callvirt, mi); | ||
170 | cmdFound = true; | ||
171 | break; | ||
172 | } | ||
173 | } | ||
174 | if (cmdFound == false) | ||
175 | { | ||
176 | Common.SendToDebug("ERROR: UNABLE TO LOCATE OPCODE " + idesc + " IN BASECLASS"); | ||
177 | } | ||
178 | |||
179 | break; | ||
180 | |||
181 | // RETURN | ||
182 | case LSO_Enums.Operation_Table.RETURN: | ||
183 | |||
184 | Common.SendToDebug("OPCODE: RETURN"); | ||
185 | return true; | ||
186 | |||
187 | case LSO_Enums.Operation_Table.POP: | ||
188 | case LSO_Enums.Operation_Table.POPS: | ||
189 | case LSO_Enums.Operation_Table.POPL: | ||
190 | case LSO_Enums.Operation_Table.POPV: | ||
191 | case LSO_Enums.Operation_Table.POPQ: | ||
192 | // Pops a specific datatype from the stack | ||
193 | // We just ignore the datatype for now | ||
194 | IL_Pop(il); | ||
195 | break; | ||
196 | |||
197 | // LONG | ||
198 | case LSO_Enums.Operation_Table.STORE: | ||
199 | case LSO_Enums.Operation_Table.STORES: | ||
200 | case LSO_Enums.Operation_Table.STOREL: | ||
201 | case LSO_Enums.Operation_Table.STOREV: | ||
202 | case LSO_Enums.Operation_Table.STOREQ: | ||
203 | u32p1 = BitConverter.ToUInt32(br_read(4), 0); | ||
204 | Common.SendToDebug("Param1: " + u32p1.ToString()); | ||
205 | IL_CallBaseFunction(il, "StoreToLocal", u32p1); | ||
206 | break; | ||
207 | |||
208 | case LSO_Enums.Operation_Table.STOREG: | ||
209 | case LSO_Enums.Operation_Table.STOREGS: | ||
210 | case LSO_Enums.Operation_Table.STOREGL: | ||
211 | case LSO_Enums.Operation_Table.STOREGV: | ||
212 | case LSO_Enums.Operation_Table.STOREGQ: | ||
213 | u32p1 = BitConverter.ToUInt32(br_read(4), 0); | ||
214 | Common.SendToDebug("Param1: " + u32p1.ToString()); | ||
215 | IL_CallBaseFunction(il, "StoreToGlobal", u32p1); | ||
216 | break; | ||
217 | |||
218 | case LSO_Enums.Operation_Table.LOADP: | ||
219 | case LSO_Enums.Operation_Table.LOADSP: | ||
220 | case LSO_Enums.Operation_Table.LOADLP: | ||
221 | case LSO_Enums.Operation_Table.LOADVP: | ||
222 | case LSO_Enums.Operation_Table.LOADQP: | ||
223 | u32p1 = BitConverter.ToUInt32(br_read(4), 0); | ||
224 | Common.SendToDebug("Param1: " + u32p1.ToString()); | ||
225 | IL_CallBaseFunction(il, "StoreToLocal", u32p1); | ||
226 | IL_Pop(il); | ||
227 | break; | ||
228 | |||
229 | case LSO_Enums.Operation_Table.LOADGP: | ||
230 | case LSO_Enums.Operation_Table.LOADGSP: | ||
231 | case LSO_Enums.Operation_Table.LOADGLP: | ||
232 | case LSO_Enums.Operation_Table.LOADGVP: | ||
233 | case LSO_Enums.Operation_Table.LOADGQP: | ||
234 | u32p1 = BitConverter.ToUInt32(br_read(4), 0); | ||
235 | Common.SendToDebug("Param1: " + u32p1.ToString()); | ||
236 | IL_CallBaseFunction(il, "StoreToStatic", u32p1 - 6 + myHeader.GVR); | ||
237 | IL_Pop(il); | ||
238 | break; | ||
239 | |||
240 | // PUSH FROM LOCAL FRAME | ||
241 | case LSO_Enums.Operation_Table.PUSH: | ||
242 | case LSO_Enums.Operation_Table.PUSHS: | ||
243 | case LSO_Enums.Operation_Table.PUSHL: | ||
244 | case LSO_Enums.Operation_Table.PUSHV: | ||
245 | case LSO_Enums.Operation_Table.PUSHQ: | ||
246 | u32p1 = BitConverter.ToUInt32(br_read(4), 0); | ||
247 | Common.SendToDebug("Param1: " + u32p1.ToString()); | ||
248 | IL_CallBaseFunction(il, "GetFromLocal", u32p1); | ||
249 | |||
250 | break; | ||
251 | |||
252 | // PUSH FROM STATIC FRAME | ||
253 | case LSO_Enums.Operation_Table.PUSHG: | ||
254 | case LSO_Enums.Operation_Table.PUSHGS: | ||
255 | case LSO_Enums.Operation_Table.PUSHGL: | ||
256 | case LSO_Enums.Operation_Table.PUSHGV: | ||
257 | case LSO_Enums.Operation_Table.PUSHGQ: | ||
258 | u32p1 = BitConverter.ToUInt32(br_read(4), 0); | ||
259 | Common.SendToDebug("Param1: " + u32p1.ToString()); | ||
260 | IL_CallBaseFunction(il, "GetFromStatic", u32p1 - 6 + myHeader.GVR); | ||
261 | break; | ||
262 | |||
263 | |||
264 | /*********************** | ||
265 | * NOT IMPLEMENTED YET * | ||
266 | ***********************/ | ||
267 | |||
268 | |||
269 | |||
270 | case LSO_Enums.Operation_Table.POPIP: | ||
271 | case LSO_Enums.Operation_Table.POPSP: | ||
272 | case LSO_Enums.Operation_Table.POPSLR: | ||
273 | case LSO_Enums.Operation_Table.POPARG: | ||
274 | case LSO_Enums.Operation_Table.POPBP: | ||
275 | //Common.SendToDebug("Instruction " + idesc + ": Ignored"); | ||
276 | Common.SendToDebug("Instruction " + idesc + ": Description: Drop x bytes from the stack (TODO: Only popping 1)"); | ||
277 | //Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
278 | IL_Pop(il); | ||
279 | break; | ||
280 | |||
281 | |||
282 | |||
283 | // None | ||
284 | case LSO_Enums.Operation_Table.PUSHIP: | ||
285 | // PUSH INSTRUCTION POINTER | ||
286 | break; | ||
287 | case LSO_Enums.Operation_Table.PUSHBP: | ||
288 | |||
289 | case LSO_Enums.Operation_Table.PUSHEV: | ||
290 | break; | ||
291 | case LSO_Enums.Operation_Table.PUSHEQ: | ||
292 | break; | ||
293 | |||
294 | |||
295 | // LONG | ||
296 | case LSO_Enums.Operation_Table.JUMP: | ||
297 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
298 | break; | ||
299 | // BYTE, LONG | ||
300 | case LSO_Enums.Operation_Table.JUMPIF: | ||
301 | case LSO_Enums.Operation_Table.JUMPNIF: | ||
302 | Common.SendToDebug("Param1: " + br_read(1)[0]); | ||
303 | Common.SendToDebug("Param2: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
304 | break; | ||
305 | // LONG | ||
306 | case LSO_Enums.Operation_Table.STATE: | ||
307 | bp1 = br_read(1)[0]; | ||
308 | //il.Emit(OpCodes.Ld); // Load local variable 0 onto stack | ||
309 | //il.Emit(OpCodes.Ldc_I4, 0); // Push index position | ||
310 | //il.Emit(OpCodes.Ldstr, EventList[p1]); // Push value | ||
311 | //il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value | ||
312 | break; | ||
313 | case LSO_Enums.Operation_Table.CALL: | ||
314 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
315 | Common.SendToDebug("ERROR: Function CALL not implemented yet."); | ||
316 | break; | ||
317 | // BYTE | ||
318 | case LSO_Enums.Operation_Table.CAST: | ||
319 | bp1 = br_read(1)[0]; | ||
320 | Common.SendToDebug("Instruction " + idesc + ": Cast to type: " + ((LSO_Enums.OpCode_Cast_TypeDefs)bp1)); | ||
321 | Common.SendToDebug("Param1: " + bp1); | ||
322 | switch ((LSO_Enums.OpCode_Cast_TypeDefs)bp1) | ||
323 | { | ||
324 | case LSO_Enums.OpCode_Cast_TypeDefs.String: | ||
325 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Box, ILStack.Pop());"); | ||
326 | break; | ||
327 | default: | ||
328 | Common.SendToDebug("Instruction " + idesc + ": Unknown cast type!"); | ||
329 | break; | ||
330 | } | ||
331 | break; | ||
332 | // LONG | ||
333 | case LSO_Enums.Operation_Table.STACKTOS: | ||
334 | case LSO_Enums.Operation_Table.STACKTOL: | ||
335 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
336 | break; | ||
337 | // BYTE | ||
338 | case LSO_Enums.Operation_Table.PRINT: | ||
339 | case LSO_Enums.Operation_Table.CALLLIB: | ||
340 | Common.SendToDebug("Param1: " + br_read(1)[0]); | ||
341 | break; | ||
342 | } | ||
343 | return false; | ||
344 | } | ||
345 | |||
346 | private void IL_PopToStack(ILGenerator il) | ||
347 | { | ||
348 | IL_PopToStack(il, 1); | ||
349 | } | ||
350 | private void IL_PopToStack(ILGenerator il, int count) | ||
351 | { | ||
352 | Common.SendToDebug("IL_PopToStack();"); | ||
353 | for (int i = 0; i < count; i++) | ||
354 | { | ||
355 | IL_CallBaseFunction(il, "POPToStack"); | ||
356 | //il.Emit(OpCodes.Ldarg_0); | ||
357 | //il.Emit(OpCodes.Call, | ||
358 | // typeof(LSL_BaseClass).GetMethod("POPToStack", | ||
359 | // new Type[] { })); | ||
360 | } | ||
361 | } | ||
362 | private void IL_Pop(ILGenerator il) | ||
363 | { | ||
364 | Common.SendToDebug("IL_Pop();"); | ||
365 | IL_CallBaseFunction(il, "POP"); | ||
366 | } | ||
367 | private void IL_Debug(ILGenerator il, string text) | ||
368 | { | ||
369 | il.Emit(OpCodes.Ldstr, text); | ||
370 | il.Emit(OpCodes.Call, typeof(Common).GetMethod("SendToDebug", | ||
371 | new Type[] { typeof(string) } | ||
372 | )); | ||
373 | } | ||
374 | private void IL_CallBaseFunction(ILGenerator il, string methodname) | ||
375 | { | ||
376 | il.Emit(OpCodes.Ldarg_0); | ||
377 | il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod(methodname, new Type[] { })); | ||
378 | } | ||
379 | private void IL_CallBaseFunction(ILGenerator il, string methodname, object data) | ||
380 | { | ||
381 | il.Emit(OpCodes.Ldarg_0); | ||
382 | if (data.GetType() == typeof(string)) | ||
383 | il.Emit(OpCodes.Ldstr, (string)data); | ||
384 | if (data.GetType() == typeof(UInt32)) | ||
385 | il.Emit(OpCodes.Ldc_I4, (UInt32)data); | ||
386 | il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod(methodname, new Type[] { data.GetType() })); | ||
387 | } | ||
388 | |||
389 | private void IL_Push(ILGenerator il, object data) | ||
390 | { | ||
391 | il.Emit(OpCodes.Ldarg_0); | ||
392 | Common.SendToDebug("PUSH datatype: " + data.GetType()); | ||
393 | |||
394 | IL_PushDataTypeToILStack(il, data); | ||
395 | |||
396 | il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("PUSH", new Type[] { data.GetType() })); | ||
397 | |||
398 | } | ||
399 | |||
400 | private void IL_PushDataTypeToILStack(ILGenerator il, object data) | ||
401 | { | ||
402 | if (data.GetType() == typeof(UInt16)) | ||
403 | { | ||
404 | il.Emit(OpCodes.Ldc_I4, (UInt16)data); | ||
405 | il.Emit(OpCodes.Box, data.GetType()); | ||
406 | } | ||
407 | if (data.GetType() == typeof(UInt32)) | ||
408 | { | ||
409 | il.Emit(OpCodes.Ldc_I4, (UInt32)data); | ||
410 | il.Emit(OpCodes.Box, data.GetType()); | ||
411 | } | ||
412 | if (data.GetType() == typeof(Int32)) | ||
413 | { | ||
414 | il.Emit(OpCodes.Ldc_I4, (Int32)data); | ||
415 | il.Emit(OpCodes.Box, data.GetType()); | ||
416 | } | ||
417 | if (data.GetType() == typeof(float)) | ||
418 | { | ||
419 | il.Emit(OpCodes.Ldc_I4, (float)data); | ||
420 | il.Emit(OpCodes.Box, data.GetType()); | ||
421 | } | ||
422 | if (data.GetType() == typeof(string)) | ||
423 | il.Emit(OpCodes.Ldstr, (string)data); | ||
424 | //if (data.GetType() == typeof(LSO_Enums.Rotation)) | ||
425 | // il.Emit(OpCodes.Ldobj, (LSO_Enums.Rotation)data); | ||
426 | //if (data.GetType() == typeof(LSO_Enums.Vector)) | ||
427 | // il.Emit(OpCodes.Ldobj, (LSO_Enums.Vector)data); | ||
428 | //if (data.GetType() == typeof(LSO_Enums.Key)) | ||
429 | // il.Emit(OpCodes.Ldobj, (LSO_Enums.Key)data); | ||
430 | |||
431 | } | ||
432 | |||
433 | |||
434 | } | ||
435 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSO_Enums.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSO_Enums.cs new file mode 100644 index 0000000..f3eef3d --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSO_Enums.cs | |||
@@ -0,0 +1,557 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
34 | { | ||
35 | public static class LSO_Enums | ||
36 | { | ||
37 | //public System.Collections.Generic.Dictionary<Byte, Type> OpCode_Add_Types; | ||
38 | |||
39 | //LSO_Enums() { | ||
40 | // OpCode_Add_Types.Add(51, typeof(String)); | ||
41 | // OpCode_Add_Types.Add(17, typeof(UInt32)); | ||
42 | //} | ||
43 | |||
44 | [Serializable] | ||
45 | public enum OpCode_Add_TypeDefs | ||
46 | { | ||
47 | String = 51, | ||
48 | UInt32 = 17 | ||
49 | } | ||
50 | [Serializable] | ||
51 | public enum OpCode_Cast_TypeDefs | ||
52 | { | ||
53 | String = 19 | ||
54 | } | ||
55 | |||
56 | [Serializable] | ||
57 | public struct Key | ||
58 | { | ||
59 | public string KeyString; | ||
60 | } | ||
61 | |||
62 | [Serializable] | ||
63 | public struct Vector | ||
64 | { | ||
65 | public UInt32 Z; | ||
66 | public UInt32 Y; | ||
67 | public UInt32 X; | ||
68 | } | ||
69 | [Serializable] | ||
70 | public struct Rotation | ||
71 | { | ||
72 | public UInt32 S; | ||
73 | public UInt32 Z; | ||
74 | public UInt32 Y; | ||
75 | public UInt32 X; | ||
76 | } | ||
77 | [Serializable] | ||
78 | public enum Variable_Type_Codes | ||
79 | { | ||
80 | Void = 0, | ||
81 | Integer = 1, | ||
82 | Float = 2, | ||
83 | String = 3, | ||
84 | Key = 4, | ||
85 | Vector = 5, | ||
86 | Rotation = 6, | ||
87 | List = 7, | ||
88 | Null = 8 | ||
89 | } | ||
90 | [Serializable] | ||
91 | public enum Event_Mask_Values | ||
92 | { | ||
93 | state_entry = 0, | ||
94 | state_exit = 1, | ||
95 | touch_start = 2, | ||
96 | touch = 3, | ||
97 | touch_end = 4, | ||
98 | collision_start = 5, | ||
99 | collision = 6, | ||
100 | collision_end = 7, | ||
101 | land_collision_start = 8, | ||
102 | land_collision = 9, | ||
103 | land_collision_end = 10, | ||
104 | timer = 11, | ||
105 | listen = 12, | ||
106 | on_rez = 13, | ||
107 | sensor = 14, | ||
108 | no_sensor = 15, | ||
109 | control = 16, | ||
110 | money = 17, | ||
111 | email = 18, | ||
112 | at_target = 19, | ||
113 | not_at_target = 20, | ||
114 | at_rot_target = 21, | ||
115 | not_at_rot_target = 22, | ||
116 | run_time_permissions = 23, | ||
117 | changed = 24, | ||
118 | attach = 25, | ||
119 | dataserver = 26, | ||
120 | link_message = 27, | ||
121 | moving_start = 28, | ||
122 | moving_end = 29, | ||
123 | object_rez = 30, | ||
124 | remote_data = 31, | ||
125 | http_response = 32 | ||
126 | } | ||
127 | [Serializable] | ||
128 | public enum Operation_Table | ||
129 | { | ||
130 | NOOP = 0x0, | ||
131 | POP = 0x1, | ||
132 | POPS = 0x2, | ||
133 | POPL = 0x3, | ||
134 | POPV = 0x4, | ||
135 | POPQ = 0x5, | ||
136 | POPARG = 0x6, | ||
137 | POPIP = 0x7, | ||
138 | POPBP = 0x8, | ||
139 | POPSP = 0x9, | ||
140 | POPSLR = 0xa, | ||
141 | DUP = 0x20, | ||
142 | DUPS = 0x21, | ||
143 | DUPL = 0x22, | ||
144 | DUPV = 0x23, | ||
145 | DUPQ = 0x24, | ||
146 | STORE = 0x30, | ||
147 | STORES = 0x31, | ||
148 | STOREL = 0x32, | ||
149 | STOREV = 0x33, | ||
150 | STOREQ = 0x34, | ||
151 | STOREG = 0x35, | ||
152 | STOREGS = 0x36, | ||
153 | STOREGL = 0x37, | ||
154 | STOREGV = 0x38, | ||
155 | STOREGQ = 0x39, | ||
156 | LOADP = 0x3a, | ||
157 | LOADSP = 0x3b, | ||
158 | LOADLP = 0x3c, | ||
159 | LOADVP = 0x3d, | ||
160 | LOADQP = 0x3e, | ||
161 | LOADGP = 0x3f, | ||
162 | LOADGSP = 0x40, | ||
163 | LOADGLP = 0x41, | ||
164 | LOADGVP = 0x42, | ||
165 | LOADGQP = 0x43, | ||
166 | PUSH = 0x50, | ||
167 | PUSHS = 0x51, | ||
168 | PUSHL = 0x52, | ||
169 | PUSHV = 0x53, | ||
170 | PUSHQ = 0x54, | ||
171 | PUSHG = 0x55, | ||
172 | PUSHGS = 0x56, | ||
173 | PUSHGL = 0x57, | ||
174 | PUSHGV = 0x58, | ||
175 | PUSHGQ = 0x59, | ||
176 | PUSHIP = 0x5a, | ||
177 | PUSHBP = 0x5b, | ||
178 | PUSHSP = 0x5c, | ||
179 | PUSHARGB = 0x5d, | ||
180 | PUSHARGI = 0x5e, | ||
181 | PUSHARGF = 0x5f, | ||
182 | PUSHARGS = 0x60, | ||
183 | PUSHARGV = 0x61, | ||
184 | PUSHARGQ = 0x62, | ||
185 | PUSHE = 0x63, | ||
186 | PUSHEV = 0x64, | ||
187 | PUSHEQ = 0x65, | ||
188 | PUSHARGE = 0x66, | ||
189 | ADD = 0x70, | ||
190 | SUB = 0x71, | ||
191 | MUL = 0x72, | ||
192 | DIV = 0x73, | ||
193 | MOD = 0x74, | ||
194 | EQ = 0x75, | ||
195 | NEQ = 0x76, | ||
196 | LEQ = 0x77, | ||
197 | GEQ = 0x78, | ||
198 | LESS = 0x79, | ||
199 | GREATER = 0x7a, | ||
200 | BITAND = 0x7b, | ||
201 | BITOR = 0x7c, | ||
202 | BITXOR = 0x7d, | ||
203 | BOOLAND = 0x7e, | ||
204 | BOOLOR = 0x7f, | ||
205 | NEG = 0x80, | ||
206 | BITNOT = 0x81, | ||
207 | BOOLNOT = 0x82, | ||
208 | JUMP = 0x90, | ||
209 | JUMPIF = 0x91, | ||
210 | JUMPNIF = 0x92, | ||
211 | STATE = 0x93, | ||
212 | CALL = 0x94, | ||
213 | RETURN = 0x95, | ||
214 | CAST = 0xa0, | ||
215 | STACKTOS = 0xb0, | ||
216 | STACKTOL = 0xb1, | ||
217 | PRINT = 0xc0, | ||
218 | CALLLIB = 0xd0, | ||
219 | CALLLIB_TWO_BYTE = 0xd1, | ||
220 | SHL = 0xe0, | ||
221 | SHR = 0xe1 | ||
222 | } | ||
223 | [Serializable] | ||
224 | public enum BuiltIn_Functions | ||
225 | { | ||
226 | llSin = 0, | ||
227 | llCos = 1, | ||
228 | llTan = 2, | ||
229 | llAtan2 = 3, | ||
230 | llSqrt = 4, | ||
231 | llPow = 5, | ||
232 | llAbs = 6, | ||
233 | llFabs = 7, | ||
234 | llFrand = 8, | ||
235 | llFloor = 9, | ||
236 | llCeil = 10, | ||
237 | llRound = 11, | ||
238 | llVecMag = 12, | ||
239 | llVecNorm = 13, | ||
240 | llVecDist = 14, | ||
241 | llRot2Euler = 15, | ||
242 | llEuler2Rot = 16, | ||
243 | llAxes2Rot = 17, | ||
244 | llRot2Fwd = 18, | ||
245 | llRot2Left = 19, | ||
246 | llRot2Up = 20, | ||
247 | llRotBetween = 21, | ||
248 | llWhisper = 22, | ||
249 | llSay = 23, | ||
250 | llShout = 24, | ||
251 | llListen = 25, | ||
252 | llListenControl = 26, | ||
253 | llListenRemove = 27, | ||
254 | llSensor = 28, | ||
255 | llSensorRepeat = 29, | ||
256 | llSensorRemove = 30, | ||
257 | llDetectedName = 31, | ||
258 | llDetectedKey = 32, | ||
259 | llDetectedOwner = 33, | ||
260 | llDetectedType = 34, | ||
261 | llDetectedPos = 35, | ||
262 | llDetectedVel = 36, | ||
263 | llDetectedGrab = 37, | ||
264 | llDetectedRot = 38, | ||
265 | llDetectedGroup = 39, | ||
266 | llDetectedLinkNumber = 40, | ||
267 | llDie = 41, | ||
268 | llGround = 42, | ||
269 | llCloud = 43, | ||
270 | llWind = 44, | ||
271 | llSetStatus = 45, | ||
272 | llGetStatus = 46, | ||
273 | llSetScale = 47, | ||
274 | llGetScale = 48, | ||
275 | llSetColor = 49, | ||
276 | llGetAlpha = 50, | ||
277 | llSetAlpha = 51, | ||
278 | llGetColor = 52, | ||
279 | llSetTexture = 53, | ||
280 | llScaleTexture = 54, | ||
281 | llOffsetTexture = 55, | ||
282 | llRotateTexture = 56, | ||
283 | llGetTexture = 57, | ||
284 | llSetPos = 58, | ||
285 | llGetPos = 59, | ||
286 | llGetLocalPos = 60, | ||
287 | llSetRot = 61, | ||
288 | llGetRot = 62, | ||
289 | llGetLocalRot = 63, | ||
290 | llSetForce = 64, | ||
291 | llGetForce = 65, | ||
292 | llTarget = 66, | ||
293 | llTargetRemove = 67, | ||
294 | llRotTarget = 68, | ||
295 | llRotTargetRemove = 69, | ||
296 | llMoveToTarget = 70, | ||
297 | llStopMoveToTarget = 71, | ||
298 | llApplyImpulse = 72, | ||
299 | llApplyRotationalImpulse = 73, | ||
300 | llSetTorque = 74, | ||
301 | llGetTorque = 75, | ||
302 | llSetForceAndTorque = 76, | ||
303 | llGetVel = 77, | ||
304 | llGetAccel = 78, | ||
305 | llGetOmega = 79, | ||
306 | llGetTimeOfDay = 80, | ||
307 | llGetWallclock = 81, | ||
308 | llGetTime = 82, | ||
309 | llResetTime = 83, | ||
310 | llGetAndResetTime = 84, | ||
311 | llSound = 85, | ||
312 | llPlaySound = 86, | ||
313 | llLoopSound = 87, | ||
314 | llLoopSoundMaster = 88, | ||
315 | llLoopSoundSlave = 89, | ||
316 | llPlaySoundSlave = 90, | ||
317 | llTriggerSound = 91, | ||
318 | llStopSound = 92, | ||
319 | llPreloadSound = 93, | ||
320 | llGetSubString = 94, | ||
321 | llDeleteSubString = 95, | ||
322 | llInsertString = 96, | ||
323 | llToUpper = 97, | ||
324 | llToLower = 98, | ||
325 | llGiveMoney = 99, | ||
326 | llMakeExplosion = 100, | ||
327 | llMakeFountain = 101, | ||
328 | llMakeSmoke = 102, | ||
329 | llMakeFire = 103, | ||
330 | llRezObject = 104, | ||
331 | llLookAt = 105, | ||
332 | llStopLookAt = 106, | ||
333 | llSetTimerEvent = 107, | ||
334 | llSleep = 108, | ||
335 | llGetMass = 109, | ||
336 | llCollisionFilter = 110, | ||
337 | llTakeControls = 111, | ||
338 | llReleaseControls = 112, | ||
339 | llAttachToAvatar = 113, | ||
340 | llDetachFromAvatar = 114, | ||
341 | llTakeCamera = 115, | ||
342 | llReleaseCamera = 116, | ||
343 | llGetOwner = 117, | ||
344 | llInstantMessage = 118, | ||
345 | llEmail = 119, | ||
346 | llGetNextEmail = 120, | ||
347 | llGetKey = 121, | ||
348 | llSetBuoyancy = 122, | ||
349 | llSetHoverHeight = 123, | ||
350 | llStopHover = 124, | ||
351 | llMinEventDelay = 125, | ||
352 | llSoundPreload = 126, | ||
353 | llRotLookAt = 127, | ||
354 | llStringLength = 128, | ||
355 | llStartAnimation = 129, | ||
356 | llStopAnimation = 130, | ||
357 | llPointAt = 131, | ||
358 | llStopPointAt = 132, | ||
359 | llTargetOmega = 133, | ||
360 | llGetStartParameter = 134, | ||
361 | llGodLikeRezObject = 135, | ||
362 | llRequestPermissions = 136, | ||
363 | llGetPermissionsKey = 137, | ||
364 | llGetPermissions = 138, | ||
365 | llGetLinkNumber = 139, | ||
366 | llSetLinkColor = 140, | ||
367 | llCreateLink = 141, | ||
368 | llBreakLink = 142, | ||
369 | llBreakAllLinks = 143, | ||
370 | llGetLinkKey = 144, | ||
371 | llGetLinkName = 145, | ||
372 | llGetInventoryNumber = 146, | ||
373 | llGetInventoryName = 147, | ||
374 | llSetScriptState = 148, | ||
375 | llGetEnergy = 149, | ||
376 | llGiveInventory = 150, | ||
377 | llRemoveInventory = 151, | ||
378 | llSetText = 152, | ||
379 | llWater = 153, | ||
380 | llPassTouches = 154, | ||
381 | llRequestAgentData = 155, | ||
382 | llRequestInventoryData = 156, | ||
383 | llSetDamage = 157, | ||
384 | llTeleportAgentHome = 158, | ||
385 | llModifyLand = 159, | ||
386 | llCollisionSound = 160, | ||
387 | llCollisionSprite = 161, | ||
388 | llGetAnimation = 162, | ||
389 | llResetScript = 163, | ||
390 | llMessageLinked = 164, | ||
391 | llPushObject = 165, | ||
392 | llPassCollisions = 166, | ||
393 | llGetScriptName = 167, | ||
394 | llGetNumberOfSides = 168, | ||
395 | llAxisAngle2Rot = 169, | ||
396 | llRot2Axis = 170, | ||
397 | llRot2Angle = 171, | ||
398 | llAcos = 172, | ||
399 | llAsin = 173, | ||
400 | llAngleBetween = 174, | ||
401 | llGetInventoryKey = 175, | ||
402 | llAllowInventoryDrop = 176, | ||
403 | llGetSunDirection = 177, | ||
404 | llGetTextureOffset = 178, | ||
405 | llGetTextureScale = 179, | ||
406 | llGetTextureRot = 180, | ||
407 | llSubStringIndex = 181, | ||
408 | llGetOwnerKey = 182, | ||
409 | llGetCenterOfMass = 183, | ||
410 | llListSort = 184, | ||
411 | llGetListLength = 185, | ||
412 | llList2Integer = 186, | ||
413 | llList2Float = 187, | ||
414 | llList2String = 188, | ||
415 | llList2Key = 189, | ||
416 | llList2Vector = 190, | ||
417 | llList2Rot = 191, | ||
418 | llList2List = 192, | ||
419 | llDeleteSubList = 193, | ||
420 | llGetListEntryType = 194, | ||
421 | llList2CSV = 195, | ||
422 | llCSV2List = 196, | ||
423 | llListRandomize = 197, | ||
424 | llList2ListStrided = 198, | ||
425 | llGetRegionCorner = 199, | ||
426 | llListInsertList = 200, | ||
427 | llListFindList = 201, | ||
428 | llGetObjectName = 202, | ||
429 | llSetObjectName = 203, | ||
430 | llGetDate = 204, | ||
431 | llEdgeOfWorld = 205, | ||
432 | llGetAgentInfo = 206, | ||
433 | llAdjustSoundVolume = 207, | ||
434 | llSetSoundQueueing = 208, | ||
435 | llSetSoundRadius = 209, | ||
436 | llKey2Name = 210, | ||
437 | llSetTextureAnim = 211, | ||
438 | llTriggerSoundLimited = 212, | ||
439 | llEjectFromLand = 213, | ||
440 | llParseString2List = 214, | ||
441 | llOverMyLand = 215, | ||
442 | llGetLandOwnerAt = 216, | ||
443 | llGetNotecardLine = 217, | ||
444 | llGetAgentSize = 218, | ||
445 | llSameGroup = 219, | ||
446 | llUnSit = 220, | ||
447 | llGroundSlope = 221, | ||
448 | llGroundNormal = 222, | ||
449 | llGroundContour = 223, | ||
450 | llGetAttached = 224, | ||
451 | llGetFreeMemory = 225, | ||
452 | llGetRegionName = 226, | ||
453 | llGetRegionTimeDilation = 227, | ||
454 | llGetRegionFPS = 228, | ||
455 | llParticleSystem = 229, | ||
456 | llGroundRepel = 230, | ||
457 | llGiveInventoryList = 231, | ||
458 | llSetVehicleType = 232, | ||
459 | llSetVehicleFloatParam = 233, | ||
460 | llSetVehicleVectorParam = 234, | ||
461 | llSetVehicleRotationParam = 235, | ||
462 | llSetVehicleFlags = 236, | ||
463 | llRemoveVehicleFlags = 237, | ||
464 | llSitTarget = 238, | ||
465 | llAvatarOnSitTarget = 239, | ||
466 | llAddToLandPassList = 240, | ||
467 | llSetTouchText = 241, | ||
468 | llSetSitText = 242, | ||
469 | llSetCameraEyeOffset = 243, | ||
470 | llSetCameraAtOffset = 244, | ||
471 | llDumpList2String = 245, | ||
472 | llScriptDanger = 246, | ||
473 | llDialog = 247, | ||
474 | llVolumeDetect = 248, | ||
475 | llResetOtherScript = 249, | ||
476 | llGetScriptState = 250, | ||
477 | llRemoteLoadScript = 251, | ||
478 | llSetRemoteScriptAccessPin = 252, | ||
479 | llRemoteLoadScriptPin = 253, | ||
480 | llOpenRemoteDataChannel = 254, | ||
481 | llSendRemoteData = 255, | ||
482 | llRemoteDataReply = 256, | ||
483 | llCloseRemoteDataChannel = 257, | ||
484 | llMD5String = 258, | ||
485 | llSetPrimitiveParams = 259, | ||
486 | llStringToBase64 = 260, | ||
487 | llBase64ToString = 261, | ||
488 | llXorBase64Strings = 262, | ||
489 | llRemoteDataSetRegion = 263, | ||
490 | llLog10 = 264, | ||
491 | llLog = 265, | ||
492 | llGetAnimationList = 266, | ||
493 | llSetParcelMusicURL = 267, | ||
494 | llGetRootPosition = 268, | ||
495 | llGetRootRotation = 269, | ||
496 | llGetObjectDesc = 270, | ||
497 | llSetObjectDesc = 271, | ||
498 | llGetCreator = 272, | ||
499 | llGetTimestamp = 273, | ||
500 | llSetLinkAlpha = 274, | ||
501 | llGetNumberOfPrims = 275, | ||
502 | llGetNumberOfNotecardLines = 276, | ||
503 | llGetBoundingBox = 277, | ||
504 | llGetGeometricCenter = 278, | ||
505 | llGetPrimitiveParams = 279, | ||
506 | llIntegerToBase64 = 280, | ||
507 | llBase64ToInteger = 281, | ||
508 | llGetGMTclock = 282, | ||
509 | llGetSimulatorHostname = 283, | ||
510 | llSetLocalRot = 284, | ||
511 | llParseStringKeepNulls = 285, | ||
512 | llRezAtRoot = 286, | ||
513 | llGetObjectPermMask = 287, | ||
514 | llSetObjectPermMask = 288, | ||
515 | llGetInventoryPermMask = 289, | ||
516 | llSetInventoryPermMask = 290, | ||
517 | llGetInventoryCreator = 291, | ||
518 | llOwnerSay = 292, | ||
519 | llRequestSimulatorData = 293, | ||
520 | llForceMouselook = 294, | ||
521 | llGetObjectMass = 295, | ||
522 | llListReplaceList = 296, | ||
523 | llLoadURL = 297, | ||
524 | llParcelMediaCommandList = 298, | ||
525 | llParcelMediaQuery = 299, | ||
526 | llModPow = 300, | ||
527 | llGetInventoryType = 301, | ||
528 | llSetPayPrice = 302, | ||
529 | llGetCameraPos = 303, | ||
530 | llGetCameraRot = 304, | ||
531 | llSetPrimURL = 305, | ||
532 | llRefreshPrimURL = 306, | ||
533 | llEscapeURL = 307, | ||
534 | llUnescapeURL = 308, | ||
535 | llMapDestination = 309, | ||
536 | llAddToLandBanList = 310, | ||
537 | llRemoveFromLandPassList = 311, | ||
538 | llRemoveFromLandBanList = 312, | ||
539 | llSetCameraParams = 313, | ||
540 | llClearCameraParams = 314, | ||
541 | llListStatistics = 315, | ||
542 | llGetUnixTime = 316, | ||
543 | llGetParcelFlags = 317, | ||
544 | llGetRegionFlags = 318, | ||
545 | llXorBase64StringsCorrect = 319, | ||
546 | llHTTPRequest = 320, | ||
547 | llResetLandBanList = 321, | ||
548 | llResetLandPassList = 322, | ||
549 | llGetParcelPrimCount = 323, | ||
550 | llGetParcelPrimOwners = 324, | ||
551 | llGetObjectPrimCount = 325, | ||
552 | llGetParcelMaxPrims = 326, | ||
553 | llGetParcelDetails = 327 | ||
554 | } | ||
555 | |||
556 | } | ||
557 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSO_Parser.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSO_Parser.cs new file mode 100644 index 0000000..b486c46 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSO_Parser.cs | |||
@@ -0,0 +1,722 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using System.IO; | ||
33 | using System.Reflection; | ||
34 | using System.Reflection.Emit; | ||
35 | |||
36 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
37 | { | ||
38 | partial class LSO_Parser | ||
39 | { | ||
40 | private string FileName; | ||
41 | private FileStream fs; | ||
42 | private BinaryReader br; | ||
43 | internal LSO_Struct.Header myHeader; | ||
44 | internal Dictionary<long, LSO_Struct.StaticBlock> StaticBlocks = new Dictionary<long, LSO_Struct.StaticBlock>(); | ||
45 | //private System.Collections.Hashtable StaticBlocks = new System.Collections.Hashtable(); | ||
46 | |||
47 | private TypeBuilder typeBuilder; | ||
48 | private System.Collections.Generic.List<string> EventList = new System.Collections.Generic.List<string>(); | ||
49 | |||
50 | public LSO_Parser(string _FileName, TypeBuilder _typeBuilder) | ||
51 | { | ||
52 | FileName = _FileName; | ||
53 | typeBuilder = _typeBuilder; | ||
54 | } | ||
55 | |||
56 | internal void OpenFile() | ||
57 | { | ||
58 | // Open | ||
59 | Common.SendToDebug("Opening filename: " + FileName); | ||
60 | fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.Read); | ||
61 | br = new BinaryReader(fs, Encoding.BigEndianUnicode); | ||
62 | |||
63 | } | ||
64 | internal void CloseFile() | ||
65 | { | ||
66 | |||
67 | // Close | ||
68 | br.Close(); | ||
69 | fs.Close(); | ||
70 | } | ||
71 | |||
72 | |||
73 | /// <summary> | ||
74 | /// Parse LSO file. | ||
75 | /// </summary> | ||
76 | public void Parse() | ||
77 | { | ||
78 | |||
79 | |||
80 | |||
81 | // The LSO Format consist of 6 major blocks: header, statics, functions, states, heap, and stack. | ||
82 | |||
83 | |||
84 | // HEADER BLOCK | ||
85 | Common.SendToDebug("Reading HEADER BLOCK at: 0"); | ||
86 | fs.Seek(0, SeekOrigin.Begin); | ||
87 | myHeader = new LSO_Struct.Header(); | ||
88 | myHeader.TM = BitConverter.ToUInt32(br_read(4), 0); | ||
89 | myHeader.IP = BitConverter.ToUInt32(br_read(4), 0); | ||
90 | myHeader.VN = BitConverter.ToUInt32(br_read(4), 0); | ||
91 | myHeader.BP = BitConverter.ToUInt32(br_read(4), 0); | ||
92 | myHeader.SP = BitConverter.ToUInt32(br_read(4), 0); | ||
93 | myHeader.HR = BitConverter.ToUInt32(br_read(4), 0); | ||
94 | myHeader.HP = BitConverter.ToUInt32(br_read(4), 0); | ||
95 | myHeader.CS = BitConverter.ToUInt32(br_read(4), 0); | ||
96 | myHeader.NS = BitConverter.ToUInt32(br_read(4), 0); | ||
97 | myHeader.CE = BitConverter.ToUInt32(br_read(4), 0); | ||
98 | myHeader.IE = BitConverter.ToUInt32(br_read(4), 0); | ||
99 | myHeader.ER = BitConverter.ToUInt32(br_read(4), 0); | ||
100 | myHeader.FR = BitConverter.ToUInt32(br_read(4), 0); | ||
101 | myHeader.SLR = BitConverter.ToUInt32(br_read(4), 0); | ||
102 | myHeader.GVR = BitConverter.ToUInt32(br_read(4), 0); | ||
103 | myHeader.GFR = BitConverter.ToUInt32(br_read(4), 0); | ||
104 | myHeader.PR = BitConverter.ToUInt32(br_read(4), 0); | ||
105 | myHeader.ESR = BitConverter.ToUInt32(br_read(4), 0); | ||
106 | myHeader.SR = BitConverter.ToUInt32(br_read(4), 0); | ||
107 | myHeader.NCE = BitConverter.ToUInt64(br_read(8), 0); | ||
108 | myHeader.NIE = BitConverter.ToUInt64(br_read(8), 0); | ||
109 | myHeader.NER = BitConverter.ToUInt64(br_read(8), 0); | ||
110 | |||
111 | // Print Header Block to debug | ||
112 | Common.SendToDebug("TM - Top of memory (size): " + myHeader.TM); | ||
113 | Common.SendToDebug("IP - Instruction Pointer (0=not running): " + myHeader.IP); | ||
114 | Common.SendToDebug("VN - Version number: " + myHeader.VN); | ||
115 | Common.SendToDebug("BP - Local Frame Pointer: " + myHeader.BP); | ||
116 | Common.SendToDebug("SP - Stack Pointer: " + myHeader.SP); | ||
117 | Common.SendToDebug("HR - Heap Register: " + myHeader.HR); | ||
118 | Common.SendToDebug("HP - Heap Pointer: " + myHeader.HP); | ||
119 | Common.SendToDebug("CS - Current State: " + myHeader.CS); | ||
120 | Common.SendToDebug("NS - Next State: " + myHeader.NS); | ||
121 | Common.SendToDebug("CE - Current Events: " + myHeader.CE); | ||
122 | Common.SendToDebug("IE - In Event: " + myHeader.IE); | ||
123 | Common.SendToDebug("ER - Event Register: " + myHeader.ER); | ||
124 | Common.SendToDebug("FR - Fault Register: " + myHeader.FR); | ||
125 | Common.SendToDebug("SLR - Sleep Register: " + myHeader.SLR); | ||
126 | Common.SendToDebug("GVR - Global Variable Register: " + myHeader.GVR); | ||
127 | Common.SendToDebug("GFR - Global Function Register: " + myHeader.GFR); | ||
128 | Common.SendToDebug("PR - Parameter Register: " + myHeader.PR); | ||
129 | Common.SendToDebug("ESR - Energy Supply Register: " + myHeader.ESR); | ||
130 | Common.SendToDebug("SR - State Register: " + myHeader.SR); | ||
131 | Common.SendToDebug("NCE - 64-bit Current Events: " + myHeader.NCE); | ||
132 | Common.SendToDebug("NIE - 64-bit In Events: " + myHeader.NIE); | ||
133 | Common.SendToDebug("NER - 64-bit Event Register: " + myHeader.NER); | ||
134 | Common.SendToDebug("Read position when exiting HEADER BLOCK: " + fs.Position); | ||
135 | |||
136 | // STATIC BLOCK | ||
137 | Common.SendToDebug("Reading STATIC BLOCK at: " + myHeader.GVR); | ||
138 | fs.Seek(myHeader.GVR, SeekOrigin.Begin); | ||
139 | int StaticBlockCount = 0; | ||
140 | // Read function blocks until we hit GFR | ||
141 | while (fs.Position < myHeader.GFR) | ||
142 | { | ||
143 | StaticBlockCount++; | ||
144 | long startReadPos = fs.Position; | ||
145 | Common.SendToDebug("Reading Static Block " + StaticBlockCount + " at: " + startReadPos); | ||
146 | |||
147 | //fs.Seek(myHeader.GVR, SeekOrigin.Begin); | ||
148 | LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock(); | ||
149 | myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0); | ||
150 | myStaticBlock.ObjectType = br_read(1)[0]; | ||
151 | Common.SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString()); | ||
152 | myStaticBlock.Unknown = br_read(1)[0]; | ||
153 | // Size of datatype varies -- what about strings? | ||
154 | if (myStaticBlock.ObjectType != 0) | ||
155 | myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType)); | ||
156 | |||
157 | StaticBlocks.Add((UInt32)startReadPos, myStaticBlock); | ||
158 | |||
159 | } | ||
160 | Common.SendToDebug("Number of Static Blocks read: " + StaticBlockCount); | ||
161 | |||
162 | |||
163 | // FUNCTION BLOCK | ||
164 | // Always right after STATIC BLOCK | ||
165 | LSO_Struct.FunctionBlock myFunctionBlock = new LSO_Struct.FunctionBlock(); | ||
166 | if (myHeader.GFR == myHeader.SR) | ||
167 | { | ||
168 | // If GFR and SR are at same position then there is no fuction block | ||
169 | Common.SendToDebug("No FUNCTION BLOCK found"); | ||
170 | } | ||
171 | else | ||
172 | { | ||
173 | Common.SendToDebug("Reading FUNCTION BLOCK at: " + myHeader.GFR); | ||
174 | fs.Seek(myHeader.GFR, SeekOrigin.Begin); | ||
175 | myFunctionBlock.FunctionCount = BitConverter.ToUInt32(br_read(4), 0); | ||
176 | Common.SendToDebug("Number of functions in Fuction Block: " + myFunctionBlock.FunctionCount); | ||
177 | if (myFunctionBlock.FunctionCount > 0) | ||
178 | { | ||
179 | myFunctionBlock.CodeChunkPointer = new UInt32[myFunctionBlock.FunctionCount]; | ||
180 | for (int i = 0; i < myFunctionBlock.FunctionCount; i++) | ||
181 | { | ||
182 | Common.SendToDebug("Reading function " + i + " at: " + fs.Position); | ||
183 | // TODO: ADD TO FUNCTION LIST (How do we identify it later?) | ||
184 | // Note! Absolute position | ||
185 | myFunctionBlock.CodeChunkPointer[i] = BitConverter.ToUInt32(br_read(4), 0) + myHeader.GFR; | ||
186 | Common.SendToDebug("Fuction " + i + " code chunk position: " + myFunctionBlock.CodeChunkPointer[i]); | ||
187 | } | ||
188 | } | ||
189 | } | ||
190 | |||
191 | |||
192 | // STATE FRAME BLOCK | ||
193 | // Always right after FUNCTION BLOCK | ||
194 | Common.SendToDebug("Reading STATE BLOCK at: " + myHeader.SR); | ||
195 | fs.Seek(myHeader.SR, SeekOrigin.Begin); | ||
196 | LSO_Struct.StateFrameBlock myStateFrameBlock = new LSO_Struct.StateFrameBlock(); | ||
197 | myStateFrameBlock.StateCount = BitConverter.ToUInt32(br_read(4), 0); | ||
198 | if (myStateFrameBlock.StateCount > 0) | ||
199 | { | ||
200 | // Initialize array | ||
201 | myStateFrameBlock.StatePointer = new LSO_Struct.StatePointerBlock[myStateFrameBlock.StateCount]; | ||
202 | for (int i = 0; i < myStateFrameBlock.StateCount; i++) | ||
203 | { | ||
204 | Common.SendToDebug("Reading STATE POINTER BLOCK " + (i + 1) + " at: " + fs.Position); | ||
205 | // Position is relative to state frame | ||
206 | myStateFrameBlock.StatePointer[i].Location = myHeader.SR + BitConverter.ToUInt32(br_read(4), 0); | ||
207 | myStateFrameBlock.StatePointer[i].EventMask = new System.Collections.BitArray(br_read(8)); | ||
208 | Common.SendToDebug("Pointer: " + myStateFrameBlock.StatePointer[i].Location); | ||
209 | Common.SendToDebug("Total potential EventMask bits: " + myStateFrameBlock.StatePointer[i].EventMask.Count); | ||
210 | |||
211 | //// Read STATE BLOCK | ||
212 | //long CurPos = fs.Position; | ||
213 | //fs.Seek(CurPos, SeekOrigin.Begin); | ||
214 | |||
215 | } | ||
216 | } | ||
217 | |||
218 | |||
219 | // STATE BLOCK | ||
220 | // For each StateFrameBlock there is one StateBlock with multiple event handlers | ||
221 | |||
222 | if (myStateFrameBlock.StateCount > 0) | ||
223 | { | ||
224 | // Go through all State Frame Pointers found | ||
225 | for (int i = 0; i < myStateFrameBlock.StateCount; i++) | ||
226 | { | ||
227 | |||
228 | fs.Seek(myStateFrameBlock.StatePointer[i].Location, SeekOrigin.Begin); | ||
229 | Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " at: " + fs.Position); | ||
230 | |||
231 | // READ: STATE BLOCK HEADER | ||
232 | myStateFrameBlock.StatePointer[i].StateBlock = new LSO_Struct.StateBlock(); | ||
233 | myStateFrameBlock.StatePointer[i].StateBlock.StartPos = (UInt32)fs.Position; // Note | ||
234 | myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize = BitConverter.ToUInt32(br_read(4), 0); | ||
235 | myStateFrameBlock.StatePointer[i].StateBlock.Unknown = br_read(1)[0]; | ||
236 | myStateFrameBlock.StatePointer[i].StateBlock.EndPos = (UInt32)fs.Position; // Note | ||
237 | Common.SendToDebug("State block Start Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.StartPos); | ||
238 | Common.SendToDebug("State block Header Size: " + myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize); | ||
239 | Common.SendToDebug("State block Header End Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.EndPos); | ||
240 | |||
241 | // We need to count number of bits flagged in EventMask? | ||
242 | |||
243 | |||
244 | // for each bit in myStateFrameBlock.StatePointer[i].EventMask | ||
245 | |||
246 | // ADDING TO ALL RIGHT NOW, SHOULD LIMIT TO ONLY THE ONES IN USE | ||
247 | //TODO: Create event hooks | ||
248 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers = new LSO_Struct.StateBlockHandler[myStateFrameBlock.StatePointer[i].EventMask.Count - 1]; | ||
249 | for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++) | ||
250 | { | ||
251 | |||
252 | if (myStateFrameBlock.StatePointer[i].EventMask.Get(ii) == true) | ||
253 | { | ||
254 | // We got an event | ||
255 | // 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); | ||
257 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer = myStateFrameBlock.StatePointer[i].StateBlock.EndPos + BitConverter.ToUInt32(br_read(4), 0); | ||
258 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize = BitConverter.ToUInt32(br_read(4), 0); | ||
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); | ||
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); | ||
261 | } | ||
262 | } | ||
263 | } | ||
264 | } | ||
265 | |||
266 | |||
267 | |||
268 | |||
269 | //// READ FUNCTION CODE CHUNKS | ||
270 | //// Functions + Function start pos (GFR) | ||
271 | //// TODO: Somehow be able to identify and reference this | ||
272 | //LSO_Struct.CodeChunk[] myFunctionCodeChunk; | ||
273 | //if (myFunctionBlock.FunctionCount > 0) | ||
274 | //{ | ||
275 | // myFunctionCodeChunk = new LSO_Struct.CodeChunk[myFunctionBlock.FunctionCount]; | ||
276 | // for (int i = 0; i < myFunctionBlock.FunctionCount; i++) | ||
277 | // { | ||
278 | // Common.SendToDebug("Reading Function Code Chunk " + i); | ||
279 | // myFunctionCodeChunk[i] = GetCodeChunk((UInt32)myFunctionBlock.CodeChunkPointer[i]); | ||
280 | // } | ||
281 | |||
282 | //} | ||
283 | // READ EVENT CODE CHUNKS | ||
284 | LSO_Struct.CodeChunk[] myEventCodeChunk; | ||
285 | if (myStateFrameBlock.StateCount > 0) | ||
286 | { | ||
287 | myEventCodeChunk = new LSO_Struct.CodeChunk[myStateFrameBlock.StateCount]; | ||
288 | for (int i = 0; i < myStateFrameBlock.StateCount; i++) | ||
289 | { | ||
290 | // TODO: Somehow organize events and functions so they can be found again, | ||
291 | // two level search ain't no good | ||
292 | for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++) | ||
293 | { | ||
294 | |||
295 | |||
296 | if (myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer > 0) | ||
297 | { | ||
298 | Common.SendToDebug("Reading Event Code Chunk state " + i + ", event " + (LSO_Enums.Event_Mask_Values)ii); | ||
299 | |||
300 | |||
301 | // Override a Method / Function | ||
302 | string eventname = i + "_event_" + (LSO_Enums.Event_Mask_Values)ii; | ||
303 | Common.SendToDebug("Event Name: " + eventname); | ||
304 | if (Common.IL_ProcessCodeChunks) | ||
305 | { | ||
306 | EventList.Add(eventname); | ||
307 | |||
308 | // JUMP TO CODE PROCESSOR | ||
309 | ProcessCodeChunk(myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer, typeBuilder, eventname); | ||
310 | } | ||
311 | } | ||
312 | |||
313 | } | ||
314 | |||
315 | } | ||
316 | |||
317 | } | ||
318 | |||
319 | |||
320 | |||
321 | |||
322 | if (Common.IL_CreateFunctionList) | ||
323 | IL_INSERT_FUNCTIONLIST(); | ||
324 | |||
325 | } | ||
326 | |||
327 | internal LSO_Struct.HeapBlock GetHeap(UInt32 pos) | ||
328 | { | ||
329 | // HEAP BLOCK | ||
330 | // TODO:? Special read for strings/keys (null terminated) and lists (pointers to other HEAP entries) | ||
331 | Common.SendToDebug("Reading HEAP BLOCK at: " + pos); | ||
332 | fs.Seek(pos, SeekOrigin.Begin); | ||
333 | |||
334 | LSO_Struct.HeapBlock myHeapBlock = new LSO_Struct.HeapBlock(); | ||
335 | myHeapBlock.DataBlockSize = BitConverter.ToInt32(br_read(4), 0); | ||
336 | myHeapBlock.ObjectType = br_read(1)[0]; | ||
337 | myHeapBlock.ReferenceCount = BitConverter.ToUInt16(br_read(2), 0); | ||
338 | //myHeapBlock.Data = br_read(getObjectSize(myHeapBlock.ObjectType)); | ||
339 | // Don't read it reversed | ||
340 | myHeapBlock.Data = new byte[myHeapBlock.DataBlockSize - 1]; | ||
341 | br.Read(myHeapBlock.Data, 0, myHeapBlock.DataBlockSize - 1); | ||
342 | |||
343 | |||
344 | Common.SendToDebug("Heap Block Data Block Size: " + myHeapBlock.DataBlockSize); | ||
345 | Common.SendToDebug("Heap Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myHeapBlock.ObjectType).ToString()); | ||
346 | Common.SendToDebug("Heap Block Reference Count: " + myHeapBlock.ReferenceCount); | ||
347 | |||
348 | return myHeapBlock; | ||
349 | } | ||
350 | private byte[] br_read(int len) | ||
351 | { | ||
352 | if (len <= 0) | ||
353 | return null; | ||
354 | |||
355 | try | ||
356 | { | ||
357 | byte[] bytes = new byte[len]; | ||
358 | for (int i = len - 1; i > -1; i--) | ||
359 | bytes[i] = br.ReadByte(); | ||
360 | return bytes; | ||
361 | } | ||
362 | catch (Exception e) | ||
363 | { | ||
364 | Common.SendToDebug("Exception: " + e.ToString()); | ||
365 | throw (e); | ||
366 | } | ||
367 | } | ||
368 | //private byte[] br_read_smallendian(int len) | ||
369 | //{ | ||
370 | // byte[] bytes = new byte[len]; | ||
371 | // br.Read(bytes,0, len); | ||
372 | // return bytes; | ||
373 | //} | ||
374 | private Type getLLObjectType(byte objectCode) | ||
375 | { | ||
376 | switch ((LSO_Enums.Variable_Type_Codes)objectCode) | ||
377 | { | ||
378 | case LSO_Enums.Variable_Type_Codes.Void: return typeof(void); | ||
379 | case LSO_Enums.Variable_Type_Codes.Integer: return typeof(UInt32); | ||
380 | case LSO_Enums.Variable_Type_Codes.Float: return typeof(float); | ||
381 | case LSO_Enums.Variable_Type_Codes.String: return typeof(string); | ||
382 | case LSO_Enums.Variable_Type_Codes.Key: return typeof(string); | ||
383 | case LSO_Enums.Variable_Type_Codes.Vector: return typeof(LSO_Enums.Vector); | ||
384 | case LSO_Enums.Variable_Type_Codes.Rotation: return typeof(LSO_Enums.Rotation); | ||
385 | case LSO_Enums.Variable_Type_Codes.List: | ||
386 | Common.SendToDebug("TODO: List datatype not implemented yet!"); | ||
387 | return typeof(System.Collections.ArrayList); | ||
388 | case LSO_Enums.Variable_Type_Codes.Null: | ||
389 | Common.SendToDebug("TODO: Datatype null is not implemented, using string instead.!"); | ||
390 | return typeof(string); | ||
391 | default: | ||
392 | Common.SendToDebug("Lookup of LSL datatype " + objectCode + " to .Net datatype failed: Unknown LSL datatype. Defaulting to object."); | ||
393 | return typeof(object); | ||
394 | } | ||
395 | } | ||
396 | private int getObjectSize(byte ObjectType) | ||
397 | { | ||
398 | switch ((LSO_Enums.Variable_Type_Codes)ObjectType) | ||
399 | { | ||
400 | case LSO_Enums.Variable_Type_Codes.Integer: | ||
401 | case LSO_Enums.Variable_Type_Codes.Float: | ||
402 | case LSO_Enums.Variable_Type_Codes.String: | ||
403 | case LSO_Enums.Variable_Type_Codes.Key: | ||
404 | case LSO_Enums.Variable_Type_Codes.List: | ||
405 | return 4; | ||
406 | case LSO_Enums.Variable_Type_Codes.Vector: | ||
407 | return 12; | ||
408 | case LSO_Enums.Variable_Type_Codes.Rotation: | ||
409 | return 16; | ||
410 | default: | ||
411 | return 0; | ||
412 | } | ||
413 | } | ||
414 | private string Read_String() | ||
415 | { | ||
416 | string ret = ""; | ||
417 | byte reader = br_read(1)[0]; | ||
418 | while (reader != 0x000) | ||
419 | { | ||
420 | ret += (char)reader; | ||
421 | reader = br_read(1)[0]; | ||
422 | } | ||
423 | return ret; | ||
424 | } | ||
425 | |||
426 | /// <summary> | ||
427 | /// Reads a code chunk and creates IL | ||
428 | /// </summary> | ||
429 | /// <param name="pos">Absolute position in file. REMEMBER TO ADD myHeader.GFR!</param> | ||
430 | /// <param name="typeBuilder">TypeBuilder for assembly</param> | ||
431 | /// <param name="eventname">Name of event (function) to generate</param> | ||
432 | private void ProcessCodeChunk(UInt32 pos, TypeBuilder typeBuilder, string eventname) | ||
433 | { | ||
434 | |||
435 | LSO_Struct.CodeChunk myCodeChunk = new LSO_Struct.CodeChunk(); | ||
436 | |||
437 | Common.SendToDebug("Reading Function Code Chunk at: " + pos); | ||
438 | fs.Seek(pos, SeekOrigin.Begin); | ||
439 | myCodeChunk.CodeChunkHeaderSize = BitConverter.ToUInt32(br_read(4), 0); | ||
440 | Common.SendToDebug("CodeChunk Header Size: " + myCodeChunk.CodeChunkHeaderSize); | ||
441 | // Read until null | ||
442 | myCodeChunk.Comment = Read_String(); | ||
443 | Common.SendToDebug("Function comment: " + myCodeChunk.Comment); | ||
444 | myCodeChunk.ReturnTypePos = br_read(1)[0]; | ||
445 | 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()); | ||
447 | |||
448 | |||
449 | // TODO: How to determine number of codechunks -- does this method work? | ||
450 | myCodeChunk.CodeChunkArguments = new System.Collections.Generic.List<LSO_Struct.CodeChunkArgument>(); | ||
451 | byte reader = br_read(1)[0]; | ||
452 | reader = br_read(1)[0]; | ||
453 | |||
454 | // NOTE ON CODE CHUNK ARGUMENTS | ||
455 | // This determins type definition | ||
456 | int ccount = 0; | ||
457 | while (reader != 0x000) | ||
458 | { | ||
459 | ccount++; | ||
460 | Common.SendToDebug("Reading Code Chunk Argument " + ccount); | ||
461 | LSO_Struct.CodeChunkArgument CCA = new LSO_Struct.CodeChunkArgument(); | ||
462 | CCA.FunctionReturnTypePos = reader; | ||
463 | reader = br_read(1)[0]; | ||
464 | CCA.NullString = reader; | ||
465 | CCA.FunctionReturnType = GetStaticBlock(CCA.FunctionReturnTypePos + myHeader.GVR); | ||
466 | myCodeChunk.CodeChunkArguments.Add(CCA); | ||
467 | Common.SendToDebug("Code Chunk Argument " + ccount + " type #" + CCA.FunctionReturnType.ObjectType + ": " + (LSO_Enums.Variable_Type_Codes)CCA.FunctionReturnType.ObjectType); | ||
468 | } | ||
469 | // Create string array | ||
470 | Type[] MethodArgs = new Type[myCodeChunk.CodeChunkArguments.Count]; | ||
471 | for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++) | ||
472 | { | ||
473 | MethodArgs[_ic] = getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType.ObjectType); | ||
474 | Common.SendToDebug("Method argument " + _ic + ": " + getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType.ObjectType).ToString()); | ||
475 | } | ||
476 | // End marker is 0x000 | ||
477 | myCodeChunk.EndMarker = reader; | ||
478 | |||
479 | |||
480 | // | ||
481 | // Emit: START OF METHOD (FUNCTION) | ||
482 | // | ||
483 | |||
484 | Common.SendToDebug("CLR:" + eventname + ":MethodBuilder methodBuilder = typeBuilder.DefineMethod..."); | ||
485 | MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname, | ||
486 | MethodAttributes.Public, | ||
487 | typeof(void), | ||
488 | new Type[] { typeof(object) }); | ||
489 | //MethodArgs); | ||
490 | //typeof(void), //getLLObjectType(myCodeChunk.ReturnType), | ||
491 | // new Type[] { typeof(object) }, //); | ||
492 | |||
493 | //Common.SendToDebug("CLR:" + eventname + ":typeBuilder.DefineMethodOverride(methodBuilder..."); | ||
494 | //typeBuilder.DefineMethodOverride(methodBuilder, | ||
495 | // typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname)); | ||
496 | |||
497 | // Create the IL generator | ||
498 | |||
499 | Common.SendToDebug("CLR:" + eventname + ":ILGenerator il = methodBuilder.GetILGenerator();"); | ||
500 | ILGenerator il = methodBuilder.GetILGenerator(); | ||
501 | |||
502 | |||
503 | if (Common.IL_UseTryCatch) | ||
504 | IL_INSERT_TRY(il, eventname); | ||
505 | |||
506 | |||
507 | |||
508 | // Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!"); | ||
509 | //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); | ||
510 | //il.Emit(OpCodes.Call, typeof(Console).GetMethod | ||
511 | // ("WriteLine", new Type[] { typeof(string) })); | ||
512 | |||
513 | //Common.SendToDebug("STARTUP: il.Emit(OpCodes.Ldc_I4_S, 0);"); | ||
514 | |||
515 | //il.Emit(OpCodes.Ldc_I4_S, 0); | ||
516 | for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++) | ||
517 | { | ||
518 | Common.SendToDebug("PARAMS: il.Emit(OpCodes.Ldarg, " + _ic + ");"); | ||
519 | il.Emit(OpCodes.Ldarg, _ic); | ||
520 | } | ||
521 | |||
522 | |||
523 | |||
524 | // | ||
525 | // CALLING OPCODE PROCESSOR, one command at the time TO GENERATE IL | ||
526 | // | ||
527 | bool FoundRet = false; | ||
528 | while (FoundRet == false) | ||
529 | { | ||
530 | FoundRet = LSL_PROCESS_OPCODE(il); | ||
531 | } | ||
532 | |||
533 | |||
534 | if (Common.IL_UseTryCatch) | ||
535 | IL_INSERT_END_TRY(il, eventname); | ||
536 | |||
537 | // Emit: RETURN FROM METHOD | ||
538 | il.Emit(OpCodes.Ret); | ||
539 | |||
540 | return; | ||
541 | |||
542 | } | ||
543 | |||
544 | private void IL_INSERT_FUNCTIONLIST() | ||
545 | { | ||
546 | |||
547 | Common.SendToDebug("Creating function list"); | ||
548 | |||
549 | |||
550 | string eventname = "GetFunctions"; | ||
551 | |||
552 | Common.SendToDebug("Creating IL " + eventname); | ||
553 | // Define a private String field. | ||
554 | //FieldBuilder myField = myTypeBuilder.DefineField("EventList", typeof(String[]), FieldAttributes.Public); | ||
555 | |||
556 | |||
557 | //FieldBuilder mem = typeBuilder.DefineField("mem", typeof(Array), FieldAttributes.Private); | ||
558 | |||
559 | |||
560 | |||
561 | MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname, | ||
562 | MethodAttributes.Public, | ||
563 | typeof(string[]), | ||
564 | null); | ||
565 | |||
566 | //typeBuilder.DefineMethodOverride(methodBuilder, | ||
567 | // typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname)); | ||
568 | |||
569 | ILGenerator il = methodBuilder.GetILGenerator(); | ||
570 | |||
571 | |||
572 | |||
573 | |||
574 | // IL_INSERT_TRY(il, eventname); | ||
575 | |||
576 | // // Push string to stack | ||
577 | // il.Emit(OpCodes.Ldstr, "Inside " + eventname); | ||
578 | |||
579 | //// Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!"); | ||
580 | //il.Emit(OpCodes.Call, typeof(Console).GetMethod | ||
581 | // ("WriteLine", new Type[] { typeof(string) })); | ||
582 | |||
583 | //initIL.Emit(OpCodes.Newobj, typeof(string[])); | ||
584 | |||
585 | //string[] MyArray = new string[2] { "TestItem1" , "TestItem2" }; | ||
586 | |||
587 | ////il.Emit(OpCodes.Ldarg_0); | ||
588 | |||
589 | il.DeclareLocal(typeof(string[])); | ||
590 | |||
591 | ////il.Emit(OpCodes.Ldarg_0); | ||
592 | il.Emit(OpCodes.Ldc_I4, EventList.Count); // Specify array length | ||
593 | il.Emit(OpCodes.Newarr, typeof(String)); // create new string array | ||
594 | il.Emit(OpCodes.Stloc_0); // Store array as local variable 0 in stack | ||
595 | ////SetFunctionList | ||
596 | |||
597 | for (int lv = 0; lv < EventList.Count; lv++) | ||
598 | { | ||
599 | il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack | ||
600 | il.Emit(OpCodes.Ldc_I4, lv); // Push index position | ||
601 | il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value | ||
602 | il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value | ||
603 | |||
604 | //il.Emit(OpCodes.Ldarg_0); | ||
605 | //il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value | ||
606 | //il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("AddFunction", new Type[] { typeof(string) })); | ||
607 | |||
608 | } | ||
609 | |||
610 | |||
611 | |||
612 | // IL_INSERT_END_TRY(il, eventname); | ||
613 | |||
614 | |||
615 | 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) })); | ||
617 | |||
618 | il.Emit(OpCodes.Ret); // Return | ||
619 | |||
620 | } | ||
621 | |||
622 | |||
623 | private void IL_INSERT_TRY(ILGenerator il, string eventname) | ||
624 | { | ||
625 | /* | ||
626 | * CLR TRY | ||
627 | */ | ||
628 | //Common.SendToDebug("CLR:" + eventname + ":il.BeginExceptionBlock()"); | ||
629 | il.BeginExceptionBlock(); | ||
630 | |||
631 | // Push "Hello World!" string to stack | ||
632 | //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr..."); | ||
633 | //il.Emit(OpCodes.Ldstr, "Starting CLR dynamic execution of: " + eventname); | ||
634 | |||
635 | } | ||
636 | |||
637 | private void IL_INSERT_END_TRY(ILGenerator il, string eventname) | ||
638 | { | ||
639 | /* | ||
640 | * CATCH | ||
641 | */ | ||
642 | Common.SendToDebug("CLR:" + eventname + ":il.BeginCatchBlock(typeof(Exception));"); | ||
643 | il.BeginCatchBlock(typeof(Exception)); | ||
644 | |||
645 | // Push "Hello World!" string to stack | ||
646 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr..."); | ||
647 | il.Emit(OpCodes.Ldstr, "Execption executing dynamic CLR function " + eventname + ": "); | ||
648 | |||
649 | //call void [mscorlib]System.Console::WriteLine(string) | ||
650 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); | ||
651 | il.Emit(OpCodes.Call, typeof(Console).GetMethod | ||
652 | ("Write", new Type[] { typeof(string) })); | ||
653 | |||
654 | //callvirt instance string [mscorlib]System.Exception::get_Message() | ||
655 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Callvirt..."); | ||
656 | il.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod | ||
657 | ("get_Message")); | ||
658 | |||
659 | //call void [mscorlib]System.Console::WriteLine(string) | ||
660 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); | ||
661 | il.Emit(OpCodes.Call, typeof(Console).GetMethod | ||
662 | ("WriteLine", new Type[] { typeof(string) })); | ||
663 | |||
664 | /* | ||
665 | * CLR END TRY | ||
666 | */ | ||
667 | //Common.SendToDebug("CLR:" + eventname + ":il.EndExceptionBlock();"); | ||
668 | il.EndExceptionBlock(); | ||
669 | } | ||
670 | |||
671 | private LSO_Struct.StaticBlock GetStaticBlock(long pos) | ||
672 | { | ||
673 | long FirstPos = fs.Position; | ||
674 | try | ||
675 | { | ||
676 | UInt32 position = (UInt32)pos; | ||
677 | // STATIC BLOCK | ||
678 | Common.SendToDebug("Reading STATIC BLOCK at: " + position); | ||
679 | fs.Seek(position, SeekOrigin.Begin); | ||
680 | |||
681 | if (StaticBlocks.ContainsKey(position) == true) | ||
682 | { | ||
683 | Common.SendToDebug("Found cached STATIC BLOCK"); | ||
684 | |||
685 | |||
686 | |||
687 | return StaticBlocks[pos]; | ||
688 | } | ||
689 | |||
690 | //int StaticBlockCount = 0; | ||
691 | // Read function blocks until we hit GFR | ||
692 | //while (fs.Position < myHeader.GFR) | ||
693 | //{ | ||
694 | //StaticBlockCount++; | ||
695 | |||
696 | //Common.SendToDebug("Reading Static Block at: " + position); | ||
697 | |||
698 | //fs.Seek(myHeader.GVR, SeekOrigin.Begin); | ||
699 | LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock(); | ||
700 | myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0); | ||
701 | myStaticBlock.ObjectType = br_read(1)[0]; | ||
702 | Common.SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString()); | ||
703 | myStaticBlock.Unknown = br_read(1)[0]; | ||
704 | // Size of datatype varies | ||
705 | if (myStaticBlock.ObjectType != 0) | ||
706 | myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType)); | ||
707 | |||
708 | StaticBlocks.Add(position, myStaticBlock); | ||
709 | //} | ||
710 | Common.SendToDebug("Done reading Static Block."); | ||
711 | return myStaticBlock; | ||
712 | } | ||
713 | finally | ||
714 | { | ||
715 | // Go back to original read pos | ||
716 | fs.Seek(FirstPos, SeekOrigin.Begin); | ||
717 | } | ||
718 | |||
719 | } | ||
720 | |||
721 | } | ||
722 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSO_Struct.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSO_Struct.cs new file mode 100644 index 0000000..8ea618c --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSO_Struct.cs | |||
@@ -0,0 +1,135 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | |||
30 | using System; | ||
31 | using System.Collections.Generic; | ||
32 | using System.Text; | ||
33 | |||
34 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
35 | { | ||
36 | static class LSO_Struct | ||
37 | { | ||
38 | |||
39 | public struct Header | ||
40 | { | ||
41 | public UInt32 TM; | ||
42 | public UInt32 IP; | ||
43 | public UInt32 VN; | ||
44 | public UInt32 BP; | ||
45 | public UInt32 SP; | ||
46 | public UInt32 HR; | ||
47 | public UInt32 HP; | ||
48 | public UInt32 CS; | ||
49 | public UInt32 NS; | ||
50 | public UInt32 CE; | ||
51 | public UInt32 IE; | ||
52 | public UInt32 ER; | ||
53 | public UInt32 FR; | ||
54 | public UInt32 SLR; | ||
55 | public UInt32 GVR; | ||
56 | public UInt32 GFR; | ||
57 | public UInt32 PR; | ||
58 | public UInt32 ESR; | ||
59 | public UInt32 SR; | ||
60 | public UInt64 NCE; | ||
61 | public UInt64 NIE; | ||
62 | public UInt64 NER; | ||
63 | } | ||
64 | |||
65 | public struct StaticBlock | ||
66 | { | ||
67 | public UInt32 Static_Chunk_Header_Size; | ||
68 | public byte ObjectType; | ||
69 | public byte Unknown; | ||
70 | public byte[] BlockVariable; | ||
71 | } | ||
72 | /* Not actually a structure | ||
73 | public struct StaticBlockVariable | ||
74 | { | ||
75 | public UInt32 Integer1; | ||
76 | public UInt32 Float1; | ||
77 | public UInt32 HeapPointer_String; | ||
78 | public UInt32 HeapPointer_Key; | ||
79 | public byte[] Vector_12; | ||
80 | public byte[] Rotation_16; | ||
81 | public UInt32 Pointer_List_Structure; | ||
82 | } */ | ||
83 | public struct HeapBlock | ||
84 | { | ||
85 | public Int32 DataBlockSize; | ||
86 | public byte ObjectType; | ||
87 | public UInt16 ReferenceCount; | ||
88 | public byte[] Data; | ||
89 | } | ||
90 | public struct StateFrameBlock | ||
91 | { | ||
92 | public UInt32 StateCount; | ||
93 | public StatePointerBlock[] StatePointer; | ||
94 | } | ||
95 | public struct StatePointerBlock | ||
96 | { | ||
97 | public UInt32 Location; | ||
98 | public System.Collections.BitArray EventMask; | ||
99 | public StateBlock StateBlock; | ||
100 | } | ||
101 | public struct StateBlock | ||
102 | { | ||
103 | public UInt32 StartPos; | ||
104 | public UInt32 EndPos; | ||
105 | public UInt32 HeaderSize; | ||
106 | public byte Unknown; | ||
107 | public StateBlockHandler[] StateBlockHandlers; | ||
108 | } | ||
109 | public struct StateBlockHandler | ||
110 | { | ||
111 | public UInt32 CodeChunkPointer; | ||
112 | public UInt32 CallFrameSize; | ||
113 | } | ||
114 | public struct FunctionBlock | ||
115 | { | ||
116 | public UInt32 FunctionCount; | ||
117 | public UInt32[] CodeChunkPointer; | ||
118 | } | ||
119 | public struct CodeChunk | ||
120 | { | ||
121 | public UInt32 CodeChunkHeaderSize; | ||
122 | public string Comment; | ||
123 | public System.Collections.Generic.List<CodeChunkArgument> CodeChunkArguments; | ||
124 | public byte EndMarker; | ||
125 | public byte ReturnTypePos; | ||
126 | public StaticBlock ReturnType; | ||
127 | } | ||
128 | public struct CodeChunkArgument | ||
129 | { | ||
130 | public byte FunctionReturnTypePos; | ||
131 | public byte NullString; | ||
132 | public StaticBlock FunctionReturnType; | ||
133 | } | ||
134 | } | ||
135 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSOdoc.htm b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSOdoc.htm new file mode 100644 index 0000000..1f70524 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/LSOdoc.htm | |||
@@ -0,0 +1,9 @@ | |||
1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title></title> | ||
5 | </head> | ||
6 | <body> | ||
7 | |||
8 | </body> | ||
9 | </html> \ No newline at end of file | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/OPCODES.txt b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/OPCODES.txt new file mode 100644 index 0000000..50fb26c --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/OPCODES.txt | |||
@@ -0,0 +1,142 @@ | |||
1 | OPCODE IL_Processor Implemented | ||
2 | ======================================================== | ||
3 | NOOP * * | ||
4 | POP * * | ||
5 | POPS * * | ||
6 | POPL * * | ||
7 | POPV * * | ||
8 | POPQ * * | ||
9 | POPARG * * | ||
10 | POPIP | ||
11 | POPBP | ||
12 | POPSP | ||
13 | POPSLR | ||
14 | DUP | ||
15 | DUPS | ||
16 | DUPL | ||
17 | DUPV | ||
18 | DUPQ | ||
19 | STORE * * | ||
20 | STORES * * | ||
21 | STOREL * * | ||
22 | STOREV * * | ||
23 | STOREQ * * | ||
24 | STOREG * * | ||
25 | STOREGS * * | ||
26 | STOREGL * * | ||
27 | STOREGV * * | ||
28 | STOREGQ * * | ||
29 | LOADP * * | ||
30 | LOADSP * * | ||
31 | LOADLP * * | ||
32 | LOADVP * * | ||
33 | LOADQP * * | ||
34 | LOADGP * * | ||
35 | LOADGSP * * | ||
36 | LOADGLP * * | ||
37 | LOADGVP * * | ||
38 | LOADGQP * * | ||
39 | PUSH * * | ||
40 | PUSHS * * | ||
41 | PUSHL * * | ||
42 | PUSHV * * | ||
43 | PUSHQ * * | ||
44 | PUSHG * * | ||
45 | PUSHGS * * | ||
46 | PUSHGL * * | ||
47 | PUSHGV * * | ||
48 | PUSHGQ * * | ||
49 | PUSHIP | ||
50 | PUSHBP | ||
51 | PUSHSP * * | ||
52 | PUSHARGB | ||
53 | PUSHARGI * * | ||
54 | PUSHARGF * * | ||
55 | PUSHARGS * * | ||
56 | PUSHARGV | ||
57 | PUSHARGQ | ||
58 | PUSHE * * | ||
59 | PUSHEV | ||
60 | PUSHEQ | ||
61 | PUSHARGE * | ||
62 | ADD * * | ||
63 | SUB * * | ||
64 | MUL * * | ||
65 | DIV * * | ||
66 | MOD * * | ||
67 | EQ * * | ||
68 | NEQ * * | ||
69 | LEQ * * | ||
70 | GEQ * * | ||
71 | LESS * * | ||
72 | GREATER * * | ||
73 | BITAND * * | ||
74 | BITOR * * | ||
75 | BITXOR * * | ||
76 | BOOLAND * * | ||
77 | BOOLOR * * | ||
78 | NEG * * | ||
79 | BITNOT * | ||
80 | BOOLNOT * | ||
81 | JUMP | ||
82 | JUMPIF | ||
83 | JUMPNIF | ||
84 | STATE | ||
85 | CALL | ||
86 | RETURN * * | ||
87 | CAST | ||
88 | STACKTOS | ||
89 | STACKTOL | ||
90 | |||
91 | CALLLIB | ||
92 | CALLLIB_TWO_BYTE * * | ||
93 | SHL | ||
94 | SHR | ||
95 | |||
96 | |||
97 | |||
98 | |||
99 | |||
100 | |||
101 | |||
102 | IN USE: | ||
103 | |||
104 | |||
105 | Implemented | ||
106 | NOOP * | ||
107 | 26 | ||
108 | ADD * | ||
109 | BITAND * | ||
110 | CALL | ||
111 | CALLLIB_TWO_BYTE | ||
112 | CAST | ||
113 | DUP | ||
114 | EQ * | ||
115 | JUMPNIF | ||
116 | LOADLP | ||
117 | LOADSP | ||
118 | NEQ * | ||
119 | NOOP | ||
120 | POP * | ||
121 | POPBP | ||
122 | POPL | ||
123 | POPS | ||
124 | POPV | ||
125 | PUSH | ||
126 | PUSHARGB | ||
127 | PUSHARGE | ||
128 | PUSHARGF * | ||
129 | PUSHARGI * | ||
130 | PUSHARGS * | ||
131 | PUSHBP | ||
132 | PUSHE | ||
133 | PUSHG | ||
134 | PUSHGS | ||
135 | PUSHL | ||
136 | PUSHS | ||
137 | PUSHSP | ||
138 | RETURN * | ||
139 | STACKTOL | ||
140 | STOREG | ||
141 | STOREGS | ||
142 | STOREL | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/OpenSim.ScriptEngine.DotNetEngine.Compiler.LSL.csproj b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/OpenSim.ScriptEngine.DotNetEngine.Compiler.LSL.csproj new file mode 100644 index 0000000..872ca92 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/OpenSim.ScriptEngine.DotNetEngine.Compiler.LSL.csproj | |||
@@ -0,0 +1,63 @@ | |||
1 | <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
2 | <PropertyGroup> | ||
3 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
4 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
5 | <ProductVersion>8.0.50727</ProductVersion> | ||
6 | <SchemaVersion>2.0</SchemaVersion> | ||
7 | <ProjectGuid>{E56CB0C4-DBE8-4169-AC21-B6A2E8235A82}</ProjectGuid> | ||
8 | <OutputType>Library</OutputType> | ||
9 | <AppDesignerFolder>Properties</AppDesignerFolder> | ||
10 | <RootNamespace>OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL</RootNamespace> | ||
11 | <AssemblyName>OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL</AssemblyName> | ||
12 | </PropertyGroup> | ||
13 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
14 | <DebugSymbols>true</DebugSymbols> | ||
15 | <DebugType>full</DebugType> | ||
16 | <Optimize>false</Optimize> | ||
17 | <OutputPath>bin\Debug\</OutputPath> | ||
18 | <DefineConstants>DEBUG;TRACE</DefineConstants> | ||
19 | <ErrorReport>prompt</ErrorReport> | ||
20 | <WarningLevel>4</WarningLevel> | ||
21 | </PropertyGroup> | ||
22 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
23 | <DebugType>pdbonly</DebugType> | ||
24 | <Optimize>true</Optimize> | ||
25 | <OutputPath>bin\Release\</OutputPath> | ||
26 | <DefineConstants>TRACE</DefineConstants> | ||
27 | <ErrorReport>prompt</ErrorReport> | ||
28 | <WarningLevel>4</WarningLevel> | ||
29 | </PropertyGroup> | ||
30 | <ItemGroup> | ||
31 | <Reference Include="System" /> | ||
32 | <Reference Include="System.Data" /> | ||
33 | <Reference Include="System.Windows.Forms" /> | ||
34 | <Reference Include="System.Xml" /> | ||
35 | </ItemGroup> | ||
36 | <ItemGroup> | ||
37 | <Compile Include="Common.cs" /> | ||
38 | <Compile Include="Engine.cs" /> | ||
39 | <Compile Include="IL_common_functions.cs" /> | ||
40 | <Compile Include="LSL_BaseClass.cs" /> | ||
41 | <Compile Include="LSL_BaseClass_Builtins.cs" /> | ||
42 | <Compile Include="LSL_BaseClass_OPCODES.cs" /> | ||
43 | <Compile Include="Server API\LSL_BuiltIn_Commands_Interface.cs" /> | ||
44 | <Compile Include="Server API\LSL_BuiltIn_Commands_TestImplementation.cs" /> | ||
45 | <Compile Include="LSL_CLRInterface.cs" /> | ||
46 | <Compile Include="LSL_OPCODE_IL_processor.cs" /> | ||
47 | <Compile Include="LSO_Parser.cs" /> | ||
48 | <Compile Include="LSO_Enums.cs" /> | ||
49 | <Compile Include="LSO_Struct.cs" /> | ||
50 | <Compile Include="Properties\AssemblyInfo.cs" /> | ||
51 | </ItemGroup> | ||
52 | <ItemGroup> | ||
53 | <Content Include="OPCODES.txt" /> | ||
54 | </ItemGroup> | ||
55 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
56 | <!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
57 | Other similar extension points exist, see Microsoft.Common.targets. | ||
58 | <Target Name="BeforeBuild"> | ||
59 | </Target> | ||
60 | <Target Name="AfterBuild"> | ||
61 | </Target> | ||
62 | --> | ||
63 | </Project> \ No newline at end of file | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/OpenSim.ScriptEngine.DotNetEngine.Compiler.LSL.suo b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/OpenSim.ScriptEngine.DotNetEngine.Compiler.LSL.suo new file mode 100644 index 0000000..eab36ab --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/OpenSim.ScriptEngine.DotNetEngine.Compiler.LSL.suo | |||
Binary files differ | |||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Properties/AssemblyInfo.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9879d88 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,35 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("")] | ||
12 | [assembly: AssemblyProduct("OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL")] | ||
13 | [assembly: AssemblyCopyright("Copyright © 2007")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("aa5ae75e-b542-4167-8e3e-baacb7e35654")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | // You can specify all the values or you can default the Revision and Build Numbers | ||
33 | // by using the '*' as shown below: | ||
34 | [assembly: AssemblyVersion("1.0.0.0")] | ||
35 | [assembly: AssemblyFileVersion("1.0.0.0")] | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Server API/LSL_BuiltIn_Commands_Interface.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Server API/LSL_BuiltIn_Commands_Interface.cs new file mode 100644 index 0000000..b6f2889 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Server API/LSL_BuiltIn_Commands_Interface.cs | |||
@@ -0,0 +1,368 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
34 | { | ||
35 | public interface LSL_BuiltIn_Commands_Interface | ||
36 | { | ||
37 | float llSin(float f); | ||
38 | float llCos(float f); | ||
39 | float llTan(float f); | ||
40 | float llAtan2(float x, float y); | ||
41 | float llSqrt(float f); | ||
42 | float llPow(float fbase, float fexponent); | ||
43 | UInt32 llAbs(UInt32 i); | ||
44 | float llFabs(float f); | ||
45 | float llFrand(float mag); | ||
46 | UInt32 llFloor(float f); | ||
47 | UInt32 llCeil(float f); | ||
48 | UInt32 llRound(float f); | ||
49 | float llVecMag(LSO_Enums.Vector v); | ||
50 | LSO_Enums.Vector llVecNorm(LSO_Enums.Vector v); | ||
51 | float llVecDist(LSO_Enums.Vector a, LSO_Enums.Vector b); | ||
52 | LSO_Enums.Vector llRot2Euler(LSO_Enums.Rotation r); | ||
53 | LSO_Enums.Rotation llEuler2Rot(LSO_Enums.Vector v); | ||
54 | LSO_Enums.Rotation llAxes2Rot(LSO_Enums.Vector fwd, LSO_Enums.Vector left, LSO_Enums.Vector up); | ||
55 | LSO_Enums.Vector llRot2Fwd(LSO_Enums.Rotation r); | ||
56 | LSO_Enums.Vector llRot2Left(LSO_Enums.Rotation r); | ||
57 | LSO_Enums.Vector llRot2Up(LSO_Enums.Rotation r); | ||
58 | LSO_Enums.Rotation llRotBetween(LSO_Enums.Vector start, LSO_Enums.Vector end); | ||
59 | void llWhisper(UInt16 channelID, string text); | ||
60 | //void llSay(UInt32 channelID, string text); | ||
61 | void llSay(object channelID, object text); | ||
62 | void llShout(UInt16 channelID, string text); | ||
63 | UInt32 llListen(UInt16 channelID, string name, LSO_Enums.Key ID, string msg); | ||
64 | void llListenControl(UInt32 number, UInt32 active); | ||
65 | void llListenRemove(UInt32 number); | ||
66 | void llSensor(string name, LSO_Enums.Key id, UInt32 type, float range, float arc); | ||
67 | void llSensorRepeat(string name, LSO_Enums.Key id, UInt32 type, float range, float arc, float rate); | ||
68 | void llSensorRemove(); | ||
69 | string llDetectedName(UInt32 number); | ||
70 | LSO_Enums.Key llDetectedKey(UInt32 number); | ||
71 | LSO_Enums.Key llDetectedOwner(UInt32 number); | ||
72 | UInt32 llDetectedType(UInt32 number); | ||
73 | LSO_Enums.Vector llDetectedPos(UInt32 number); | ||
74 | LSO_Enums.Vector llDetectedVel(UInt32 number); | ||
75 | LSO_Enums.Vector llDetectedGrab(UInt32 number); | ||
76 | LSO_Enums.Rotation llDetectedRot(UInt32 number); | ||
77 | UInt32 llDetectedGroup(UInt32 number); | ||
78 | UInt32 llDetectedLinkNumber(UInt32 number); | ||
79 | void llDie(); | ||
80 | float llGround(LSO_Enums.Vector offset); | ||
81 | float llCloud(LSO_Enums.Vector offset); | ||
82 | LSO_Enums.Vector llWind(LSO_Enums.Vector offset); | ||
83 | void llSetStatus(UInt32 status, UInt32 value); | ||
84 | UInt32 llGetStatus(UInt32 status); | ||
85 | void llSetScale(LSO_Enums.Vector scale); | ||
86 | LSO_Enums.Vector llGetScale(); | ||
87 | void llSetColor(LSO_Enums.Vector color, UInt32 face); | ||
88 | float llGetAlpha(UInt32 face); | ||
89 | void llSetAlpha(float alpha, UInt32 face); | ||
90 | LSO_Enums.Vector llGetColor(UInt32 face); | ||
91 | void llSetTexture(string texture, UInt32 face); | ||
92 | void llScaleTexture(float u, float v, UInt32 face); | ||
93 | void llOffsetTexture(float u, float v, UInt32 face); | ||
94 | void llRotateTexture(float rotation, UInt32 face); | ||
95 | string llGetTexture(UInt32 face); | ||
96 | void llSetPos(LSO_Enums.Vector pos); | ||
97 | |||
98 | void llGetPos(); | ||
99 | void llGetLocalPos(); | ||
100 | void llSetRot(); | ||
101 | void llGetRot(); | ||
102 | void llGetLocalRot(); | ||
103 | void llSetForce(); | ||
104 | void llGetForce(); | ||
105 | void llTarget(); | ||
106 | void llTargetRemove(); | ||
107 | void llRotTarget(); | ||
108 | void llRotTargetRemove(); | ||
109 | void llMoveToTarget(); | ||
110 | void llStopMoveToTarget(); | ||
111 | void llApplyImpulse(); | ||
112 | void llApplyRotationalImpulse(); | ||
113 | void llSetTorque(); | ||
114 | void llGetTorque(); | ||
115 | void llSetForceAndTorque(); | ||
116 | void llGetVel(); | ||
117 | void llGetAccel(); | ||
118 | void llGetOmega(); | ||
119 | void llGetTimeOfDay(); | ||
120 | void llGetWallclock(); | ||
121 | void llGetTime(); | ||
122 | void llResetTime(); | ||
123 | void llGetAndResetTime(); | ||
124 | void llSound(); | ||
125 | void llPlaySound(); | ||
126 | void llLoopSound(); | ||
127 | void llLoopSoundMaster(); | ||
128 | void llLoopSoundSlave(); | ||
129 | void llPlaySoundSlave(); | ||
130 | void llTriggerSound(); | ||
131 | void llStopSound(); | ||
132 | void llPreloadSound(); | ||
133 | void llGetSubString(); | ||
134 | void llDeleteSubString(); | ||
135 | void llInsertString(); | ||
136 | void llToUpper(); | ||
137 | void llToLower(); | ||
138 | void llGiveMoney(); | ||
139 | void llMakeExplosion(); | ||
140 | void llMakeFountain(); | ||
141 | void llMakeSmoke(); | ||
142 | void llMakeFire(); | ||
143 | void llRezObject(); | ||
144 | void llLookAt(); | ||
145 | void llStopLookAt(); | ||
146 | void llSetTimerEvent(); | ||
147 | void llSleep(); | ||
148 | void llGetMass(); | ||
149 | void llCollisionFilter(); | ||
150 | void llTakeControls(); | ||
151 | void llReleaseControls(); | ||
152 | void llAttachToAvatar(); | ||
153 | void llDetachFromAvatar(); | ||
154 | void llTakeCamera(); | ||
155 | void llReleaseCamera(); | ||
156 | void llGetOwner(); | ||
157 | void llInstantMessage(); | ||
158 | void llEmail(); | ||
159 | void llGetNextEmail(); | ||
160 | void llGetKey(); | ||
161 | void llSetBuoyancy(); | ||
162 | void llSetHoverHeight(); | ||
163 | void llStopHover(); | ||
164 | void llMinEventDelay(); | ||
165 | void llSoundPreload(); | ||
166 | void llRotLookAt(); | ||
167 | void llStringLength(); | ||
168 | void llStartAnimation(); | ||
169 | void llStopAnimation(); | ||
170 | void llPointAt(); | ||
171 | void llStopPointAt(); | ||
172 | void llTargetOmega(); | ||
173 | void llGetStartParameter(); | ||
174 | void llGodLikeRezObject(); | ||
175 | void llRequestPermissions(); | ||
176 | void llGetPermissionsKey(); | ||
177 | void llGetPermissions(); | ||
178 | void llGetLinkNumber(); | ||
179 | void llSetLinkColor(); | ||
180 | void llCreateLink(); | ||
181 | void llBreakLink(); | ||
182 | void llBreakAllLinks(); | ||
183 | void llGetLinkKey(); | ||
184 | void llGetLinkName(); | ||
185 | void llGetInventoryNumber(); | ||
186 | void llGetInventoryName(); | ||
187 | void llSetScriptState(); | ||
188 | void llGetEnergy(); | ||
189 | void llGiveInventory(); | ||
190 | void llRemoveInventory(); | ||
191 | void llSetText(); | ||
192 | void llWater(); | ||
193 | void llPassTouches(); | ||
194 | void llRequestAgentData(); | ||
195 | void llRequestInventoryData(); | ||
196 | void llSetDamage(); | ||
197 | void llTeleportAgentHome(); | ||
198 | void llModifyLand(); | ||
199 | void llCollisionSound(); | ||
200 | void llCollisionSprite(); | ||
201 | void llGetAnimation(); | ||
202 | void llResetScript(); | ||
203 | void llMessageLinked(); | ||
204 | void llPushObject(); | ||
205 | void llPassCollisions(); | ||
206 | void llGetScriptName(); | ||
207 | void llGetNumberOfSides(); | ||
208 | void llAxisAngle2Rot(); | ||
209 | void llRot2Axis(); | ||
210 | void llRot2Angle(); | ||
211 | void llAcos(); | ||
212 | void llAsin(); | ||
213 | void llAngleBetween(); | ||
214 | void llGetInventoryKey(); | ||
215 | void llAllowInventoryDrop(); | ||
216 | void llGetSunDirection(); | ||
217 | void llGetTextureOffset(); | ||
218 | void llGetTextureScale(); | ||
219 | void llGetTextureRot(); | ||
220 | void llSubStringIndex(); | ||
221 | void llGetOwnerKey(); | ||
222 | void llGetCenterOfMass(); | ||
223 | void llListSort(); | ||
224 | void llGetListLength(); | ||
225 | void llList2Integer(); | ||
226 | void llList2Float(); | ||
227 | void llList2String(); | ||
228 | void llList2Key(); | ||
229 | void llList2Vector(); | ||
230 | void llList2Rot(); | ||
231 | void llList2List(); | ||
232 | void llDeleteSubList(); | ||
233 | void llGetListEntryType(); | ||
234 | void llList2CSV(); | ||
235 | void llCSV2List(); | ||
236 | void llListRandomize(); | ||
237 | void llList2ListStrided(); | ||
238 | void llGetRegionCorner(); | ||
239 | void llListInsertList(); | ||
240 | void llListFindList(); | ||
241 | void llGetObjectName(); | ||
242 | void llSetObjectName(); | ||
243 | void llGetDate(); | ||
244 | void llEdgeOfWorld(); | ||
245 | void llGetAgentInfo(); | ||
246 | void llAdjustSoundVolume(); | ||
247 | void llSetSoundQueueing(); | ||
248 | void llSetSoundRadius(); | ||
249 | void llKey2Name(); | ||
250 | void llSetTextureAnim(); | ||
251 | void llTriggerSoundLimited(); | ||
252 | void llEjectFromLand(); | ||
253 | void llParseString2List(); | ||
254 | void llOverMyLand(); | ||
255 | void llGetLandOwnerAt(); | ||
256 | void llGetNotecardLine(); | ||
257 | void llGetAgentSize(); | ||
258 | void llSameGroup(); | ||
259 | void llUnSit(); | ||
260 | void llGroundSlope(); | ||
261 | void llGroundNormal(); | ||
262 | void llGroundContour(); | ||
263 | void llGetAttached(); | ||
264 | void llGetFreeMemory(); | ||
265 | void llGetRegionName(); | ||
266 | void llGetRegionTimeDilation(); | ||
267 | void llGetRegionFPS(); | ||
268 | void llParticleSystem(); | ||
269 | void llGroundRepel(); | ||
270 | void llGiveInventoryList(); | ||
271 | void llSetVehicleType(); | ||
272 | void llSetVehicleFloatParam(); | ||
273 | void llSetVehicleVectorParam(); | ||
274 | void llSetVehicleRotationParam(); | ||
275 | void llSetVehicleFlags(); | ||
276 | void llRemoveVehicleFlags(); | ||
277 | void llSitTarget(); | ||
278 | void llAvatarOnSitTarget(); | ||
279 | void llAddToLandPassList(); | ||
280 | void llSetTouchText(); | ||
281 | void llSetSitText(); | ||
282 | void llSetCameraEyeOffset(); | ||
283 | void llSetCameraAtOffset(); | ||
284 | void llDumpList2String(); | ||
285 | void llScriptDanger(); | ||
286 | void llDialog(); | ||
287 | void llVolumeDetect(); | ||
288 | void llResetOtherScript(); | ||
289 | void llGetScriptState(); | ||
290 | void llRemoteLoadScript(); | ||
291 | void llSetRemoteScriptAccessPin(); | ||
292 | void llRemoteLoadScriptPin(); | ||
293 | void llOpenRemoteDataChannel(); | ||
294 | void llSendRemoteData(); | ||
295 | void llRemoteDataReply(); | ||
296 | void llCloseRemoteDataChannel(); | ||
297 | void llMD5String(); | ||
298 | void llSetPrimitiveParams(); | ||
299 | void llStringToBase64(); | ||
300 | void llBase64ToString(); | ||
301 | void llXorBase64Strings(); | ||
302 | void llRemoteDataSetRegion(); | ||
303 | void llLog10(); | ||
304 | void llLog(); | ||
305 | void llGetAnimationList(); | ||
306 | void llSetParcelMusicURL(); | ||
307 | void llGetRootPosition(); | ||
308 | void llGetRootRotation(); | ||
309 | void llGetObjectDesc(); | ||
310 | void llSetObjectDesc(); | ||
311 | void llGetCreator(); | ||
312 | void llGetTimestamp(); | ||
313 | void llSetLinkAlpha(); | ||
314 | void llGetNumberOfPrims(); | ||
315 | void llGetNumberOfNotecardLines(); | ||
316 | void llGetBoundingBox(); | ||
317 | void llGetGeometricCenter(); | ||
318 | void llGetPrimitiveParams(); | ||
319 | void llIntegerToBase64(); | ||
320 | void llBase64ToInteger(); | ||
321 | void llGetGMTclock(); | ||
322 | void llGetSimulatorHostname(); | ||
323 | void llSetLocalRot(); | ||
324 | void llParseStringKeepNulls(); | ||
325 | void llRezAtRoot(); | ||
326 | void llGetObjectPermMask(); | ||
327 | void llSetObjectPermMask(); | ||
328 | void llGetInventoryPermMask(); | ||
329 | void llSetInventoryPermMask(); | ||
330 | void llGetInventoryCreator(); | ||
331 | void llOwnerSay(); | ||
332 | void llRequestSimulatorData(); | ||
333 | void llForceMouselook(); | ||
334 | void llGetObjectMass(); | ||
335 | void llListReplaceList(); | ||
336 | void llLoadURL(); | ||
337 | void llParcelMediaCommandList(); | ||
338 | void llParcelMediaQuery(); | ||
339 | void llModPow(); | ||
340 | void llGetInventoryType(); | ||
341 | void llSetPayPrice(); | ||
342 | void llGetCameraPos(); | ||
343 | void llGetCameraRot(); | ||
344 | void llSetPrimURL(); | ||
345 | void llRefreshPrimURL(); | ||
346 | void llEscapeURL(); | ||
347 | void llUnescapeURL(); | ||
348 | void llMapDestination(); | ||
349 | void llAddToLandBanList(); | ||
350 | void llRemoveFromLandPassList(); | ||
351 | void llRemoveFromLandBanList(); | ||
352 | void llSetCameraParams(); | ||
353 | void llClearCameraParams(); | ||
354 | void llListStatistics(); | ||
355 | void llGetUnixTime(); | ||
356 | void llGetParcelFlags(); | ||
357 | void llGetRegionFlags(); | ||
358 | void llXorBase64StringsCorrect(); | ||
359 | void llHTTPRequest(); | ||
360 | void llResetLandBanList(); | ||
361 | void llResetLandPassList(); | ||
362 | void llGetParcelPrimCount(); | ||
363 | void llGetParcelPrimOwners(); | ||
364 | void llGetObjectPrimCount(); | ||
365 | void llGetParcelMaxPrims(); | ||
366 | void llGetParcelDetails(); | ||
367 | } | ||
368 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Server API/LSL_BuiltIn_Commands_TestImplementation.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Server API/LSL_BuiltIn_Commands_TestImplementation.cs new file mode 100644 index 0000000..bbdafad --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/Server API/LSL_BuiltIn_Commands_TestImplementation.cs | |||
@@ -0,0 +1,386 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
34 | { | ||
35 | public class LSL_BuiltIn_Commands_TestImplementation : LSL_BuiltIn_Commands_Interface | ||
36 | { | ||
37 | public LSL_BuiltIn_Commands_TestImplementation(string FullScriptID) | ||
38 | { | ||
39 | Common.SendToDebug("LSL_BuiltIn_Commands_TestImplementation: Creating object for FullScriptID: " + FullScriptID); | ||
40 | } | ||
41 | |||
42 | |||
43 | public float llSin(float f) { return 0; } | ||
44 | public float llCos(float f) { return 0; } | ||
45 | public float llTan(float f) { return 0; } | ||
46 | public float llAtan2(float x, float y) { return 0; } | ||
47 | public float llSqrt(float f) { return 0; } | ||
48 | public float llPow(float fbase, float fexponent) { return 0; } | ||
49 | public UInt32 llAbs(UInt32 i) { return 0; } | ||
50 | public float llFabs(float f) { return 0; } | ||
51 | public float llFrand(float mag) { return 0; } | ||
52 | public UInt32 llFloor(float f) { return 0; } | ||
53 | public UInt32 llCeil(float f) { return 0; } | ||
54 | public UInt32 llRound(float f) { return 0; } | ||
55 | public float llVecMag(LSO_Enums.Vector v) { return 0; } | ||
56 | public LSO_Enums.Vector llVecNorm(LSO_Enums.Vector v) { return new LSO_Enums.Vector(); } | ||
57 | public float llVecDist(LSO_Enums.Vector a, LSO_Enums.Vector b) { return 0; } | ||
58 | public LSO_Enums.Vector llRot2Euler(LSO_Enums.Rotation r) { return new LSO_Enums.Vector(); } | ||
59 | public LSO_Enums.Rotation llEuler2Rot(LSO_Enums.Vector v) { return new LSO_Enums.Rotation(); } | ||
60 | public LSO_Enums.Rotation llAxes2Rot(LSO_Enums.Vector fwd, LSO_Enums.Vector left, LSO_Enums.Vector up) { return new LSO_Enums.Rotation(); } | ||
61 | public LSO_Enums.Vector llRot2Fwd(LSO_Enums.Rotation r) { return new LSO_Enums.Vector(); } | ||
62 | public LSO_Enums.Vector llRot2Left(LSO_Enums.Rotation r) { return new LSO_Enums.Vector(); } | ||
63 | public LSO_Enums.Vector llRot2Up(LSO_Enums.Rotation r) { return new LSO_Enums.Vector(); } | ||
64 | public LSO_Enums.Rotation llRotBetween(LSO_Enums.Vector start, LSO_Enums.Vector end) { return new LSO_Enums.Rotation(); } | ||
65 | public void llWhisper(UInt16 channelID, string text) | ||
66 | { | ||
67 | Common.SendToDebug("INTERNAL FUNCTION llWhisper(" + channelID + ", \"" + text + "\");"); | ||
68 | Common.SendToLog("llWhisper Channel " + channelID + ", Text: \"" + text + "\""); | ||
69 | } | ||
70 | //public void llSay(UInt32 channelID, string text) | ||
71 | public void llSay(object channelID, object text) | ||
72 | { | ||
73 | Common.SendToDebug("INTERNAL FUNCTION llSay(" + (UInt32)channelID + ", \"" + (string)text + "\");"); | ||
74 | Common.SendToLog("llSay Channel " + (UInt32)channelID + ", Text: \"" + (string)text + "\""); | ||
75 | } | ||
76 | public void llShout(UInt16 channelID, string text) { return; } | ||
77 | public UInt32 llListen(UInt16 channelID, string name, LSO_Enums.Key ID, string msg) { return 0; } | ||
78 | public void llListenControl(UInt32 number, UInt32 active) { return; } | ||
79 | public void llListenRemove(UInt32 number) { return; } | ||
80 | public void llSensor(string name, LSO_Enums.Key id, UInt32 type, float range, float arc) { return; } | ||
81 | public void llSensorRepeat(string name, LSO_Enums.Key id, UInt32 type, float range, float arc, float rate) { return; } | ||
82 | public void llSensorRemove() { return; } | ||
83 | public string llDetectedName(UInt32 number) { return ""; } | ||
84 | public LSO_Enums.Key llDetectedKey(UInt32 number) { return new LSO_Enums.Key(); } | ||
85 | public LSO_Enums.Key llDetectedOwner(UInt32 number) { return new LSO_Enums.Key(); } | ||
86 | public UInt32 llDetectedType(UInt32 number) { return 0; } | ||
87 | public LSO_Enums.Vector llDetectedPos(UInt32 number) { return new LSO_Enums.Vector(); } | ||
88 | public LSO_Enums.Vector llDetectedVel(UInt32 number) { return new LSO_Enums.Vector(); } | ||
89 | public LSO_Enums.Vector llDetectedGrab(UInt32 number) { return new LSO_Enums.Vector(); } | ||
90 | public LSO_Enums.Rotation llDetectedRot(UInt32 number) { return new LSO_Enums.Rotation(); } | ||
91 | public UInt32 llDetectedGroup(UInt32 number) { return 0; } | ||
92 | public UInt32 llDetectedLinkNumber(UInt32 number) { return 0; } | ||
93 | public void llDie() { return; } | ||
94 | public float llGround(LSO_Enums.Vector offset) { return 0; } | ||
95 | public float llCloud(LSO_Enums.Vector offset) { return 0; } | ||
96 | public LSO_Enums.Vector llWind(LSO_Enums.Vector offset) { return new LSO_Enums.Vector(); } | ||
97 | public void llSetStatus(UInt32 status, UInt32 value) { return; } | ||
98 | public UInt32 llGetStatus(UInt32 status) { return 0; } | ||
99 | public void llSetScale(LSO_Enums.Vector scale) { return; } | ||
100 | public LSO_Enums.Vector llGetScale() { return new LSO_Enums.Vector(); } | ||
101 | public void llSetColor(LSO_Enums.Vector color, UInt32 face) { return; } | ||
102 | public float llGetAlpha(UInt32 face) { return 0; } | ||
103 | public void llSetAlpha(float alpha, UInt32 face) { return; } | ||
104 | public LSO_Enums.Vector llGetColor(UInt32 face) { return new LSO_Enums.Vector(); } | ||
105 | public void llSetTexture(string texture, UInt32 face) { return; } | ||
106 | public void llScaleTexture(float u, float v, UInt32 face) { return; } | ||
107 | public void llOffsetTexture(float u, float v, UInt32 face) { return; } | ||
108 | public void llRotateTexture(float rotation, UInt32 face) { return; } | ||
109 | public string llGetTexture(UInt32 face) { return ""; } | ||
110 | public void llSetPos(LSO_Enums.Vector pos) { return; } | ||
111 | |||
112 | |||
113 | public void llGetPos() { } | ||
114 | public void llGetLocalPos() { } | ||
115 | public void llSetRot() { } | ||
116 | public void llGetRot() { } | ||
117 | public void llGetLocalRot() { } | ||
118 | public void llSetForce() { } | ||
119 | public void llGetForce() { } | ||
120 | public void llTarget() { } | ||
121 | public void llTargetRemove() { } | ||
122 | public void llRotTarget() { } | ||
123 | public void llRotTargetRemove() { } | ||
124 | public void llMoveToTarget() { } | ||
125 | public void llStopMoveToTarget() { } | ||
126 | public void llApplyImpulse() { } | ||
127 | public void llApplyRotationalImpulse() { } | ||
128 | public void llSetTorque() { } | ||
129 | public void llGetTorque() { } | ||
130 | public void llSetForceAndTorque() { } | ||
131 | public void llGetVel() { } | ||
132 | public void llGetAccel() { } | ||
133 | public void llGetOmega() { } | ||
134 | public void llGetTimeOfDay() { } | ||
135 | public void llGetWallclock() { } | ||
136 | public void llGetTime() { } | ||
137 | public void llResetTime() { } | ||
138 | public void llGetAndResetTime() { } | ||
139 | public void llSound() { } | ||
140 | public void llPlaySound() { } | ||
141 | public void llLoopSound() { } | ||
142 | public void llLoopSoundMaster() { } | ||
143 | public void llLoopSoundSlave() { } | ||
144 | public void llPlaySoundSlave() { } | ||
145 | public void llTriggerSound() { } | ||
146 | public void llStopSound() { } | ||
147 | public void llPreloadSound() { } | ||
148 | public void llGetSubString() { } | ||
149 | public void llDeleteSubString() { } | ||
150 | public void llInsertString() { } | ||
151 | public void llToUpper() { } | ||
152 | public void llToLower() { } | ||
153 | public void llGiveMoney() { } | ||
154 | public void llMakeExplosion() { } | ||
155 | public void llMakeFountain() { } | ||
156 | public void llMakeSmoke() { } | ||
157 | public void llMakeFire() { } | ||
158 | public void llRezObject() { } | ||
159 | public void llLookAt() { } | ||
160 | public void llStopLookAt() { } | ||
161 | public void llSetTimerEvent() { } | ||
162 | public void llSleep() { } | ||
163 | public void llGetMass() { } | ||
164 | public void llCollisionFilter() { } | ||
165 | public void llTakeControls() { } | ||
166 | public void llReleaseControls() { } | ||
167 | public void llAttachToAvatar() { } | ||
168 | public void llDetachFromAvatar() { } | ||
169 | public void llTakeCamera() { } | ||
170 | public void llReleaseCamera() { } | ||
171 | public void llGetOwner() { } | ||
172 | public void llInstantMessage() { } | ||
173 | public void llEmail() { } | ||
174 | public void llGetNextEmail() { } | ||
175 | public void llGetKey() { } | ||
176 | public void llSetBuoyancy() { } | ||
177 | public void llSetHoverHeight() { } | ||
178 | public void llStopHover() { } | ||
179 | public void llMinEventDelay() { } | ||
180 | public void llSoundPreload() { } | ||
181 | public void llRotLookAt() { } | ||
182 | public void llStringLength() { } | ||
183 | public void llStartAnimation() { } | ||
184 | public void llStopAnimation() { } | ||
185 | public void llPointAt() { } | ||
186 | public void llStopPointAt() { } | ||
187 | public void llTargetOmega() { } | ||
188 | public void llGetStartParameter() { } | ||
189 | public void llGodLikeRezObject() { } | ||
190 | public void llRequestPermissions() { } | ||
191 | public void llGetPermissionsKey() { } | ||
192 | public void llGetPermissions() { } | ||
193 | public void llGetLinkNumber() { } | ||
194 | public void llSetLinkColor() { } | ||
195 | public void llCreateLink() { } | ||
196 | public void llBreakLink() { } | ||
197 | public void llBreakAllLinks() { } | ||
198 | public void llGetLinkKey() { } | ||
199 | public void llGetLinkName() { } | ||
200 | public void llGetInventoryNumber() { } | ||
201 | public void llGetInventoryName() { } | ||
202 | public void llSetScriptState() { } | ||
203 | public void llGetEnergy() { } | ||
204 | public void llGiveInventory() { } | ||
205 | public void llRemoveInventory() { } | ||
206 | public void llSetText() { } | ||
207 | public void llWater() { } | ||
208 | public void llPassTouches() { } | ||
209 | public void llRequestAgentData() { } | ||
210 | public void llRequestInventoryData() { } | ||
211 | public void llSetDamage() { } | ||
212 | public void llTeleportAgentHome() { } | ||
213 | public void llModifyLand() { } | ||
214 | public void llCollisionSound() { } | ||
215 | public void llCollisionSprite() { } | ||
216 | public void llGetAnimation() { } | ||
217 | public void llResetScript() { } | ||
218 | public void llMessageLinked() { } | ||
219 | public void llPushObject() { } | ||
220 | public void llPassCollisions() { } | ||
221 | public void llGetScriptName() { } | ||
222 | public void llGetNumberOfSides() { } | ||
223 | public void llAxisAngle2Rot() { } | ||
224 | public void llRot2Axis() { } | ||
225 | public void llRot2Angle() { } | ||
226 | public void llAcos() { } | ||
227 | public void llAsin() { } | ||
228 | public void llAngleBetween() { } | ||
229 | public void llGetInventoryKey() { } | ||
230 | public void llAllowInventoryDrop() { } | ||
231 | public void llGetSunDirection() { } | ||
232 | public void llGetTextureOffset() { } | ||
233 | public void llGetTextureScale() { } | ||
234 | public void llGetTextureRot() { } | ||
235 | public void llSubStringIndex() { } | ||
236 | public void llGetOwnerKey() { } | ||
237 | public void llGetCenterOfMass() { } | ||
238 | public void llListSort() { } | ||
239 | public void llGetListLength() { } | ||
240 | public void llList2Integer() { } | ||
241 | public void llList2Float() { } | ||
242 | public void llList2String() { } | ||
243 | public void llList2Key() { } | ||
244 | public void llList2Vector() { } | ||
245 | public void llList2Rot() { } | ||
246 | public void llList2List() { } | ||
247 | public void llDeleteSubList() { } | ||
248 | public void llGetListEntryType() { } | ||
249 | public void llList2CSV() { } | ||
250 | public void llCSV2List() { } | ||
251 | public void llListRandomize() { } | ||
252 | public void llList2ListStrided() { } | ||
253 | public void llGetRegionCorner() { } | ||
254 | public void llListInsertList() { } | ||
255 | public void llListFindList() { } | ||
256 | public void llGetObjectName() { } | ||
257 | public void llSetObjectName() { } | ||
258 | public void llGetDate() { } | ||
259 | public void llEdgeOfWorld() { } | ||
260 | public void llGetAgentInfo() { } | ||
261 | public void llAdjustSoundVolume() { } | ||
262 | public void llSetSoundQueueing() { } | ||
263 | public void llSetSoundRadius() { } | ||
264 | public void llKey2Name() { } | ||
265 | public void llSetTextureAnim() { } | ||
266 | public void llTriggerSoundLimited() { } | ||
267 | public void llEjectFromLand() { } | ||
268 | public void llParseString2List() { } | ||
269 | public void llOverMyLand() { } | ||
270 | public void llGetLandOwnerAt() { } | ||
271 | public void llGetNotecardLine() { } | ||
272 | public void llGetAgentSize() { } | ||
273 | public void llSameGroup() { } | ||
274 | public void llUnSit() { } | ||
275 | public void llGroundSlope() { } | ||
276 | public void llGroundNormal() { } | ||
277 | public void llGroundContour() { } | ||
278 | public void llGetAttached() { } | ||
279 | public void llGetFreeMemory() { } | ||
280 | public void llGetRegionName() { } | ||
281 | public void llGetRegionTimeDilation() { } | ||
282 | public void llGetRegionFPS() { } | ||
283 | public void llParticleSystem() { } | ||
284 | public void llGroundRepel() { } | ||
285 | public void llGiveInventoryList() { } | ||
286 | public void llSetVehicleType() { } | ||
287 | public void llSetVehicleFloatParam() { } | ||
288 | public void llSetVehicleVectorParam() { } | ||
289 | public void llSetVehicleRotationParam() { } | ||
290 | public void llSetVehicleFlags() { } | ||
291 | public void llRemoveVehicleFlags() { } | ||
292 | public void llSitTarget() { } | ||
293 | public void llAvatarOnSitTarget() { } | ||
294 | public void llAddToLandPassList() { } | ||
295 | public void llSetTouchText() { } | ||
296 | public void llSetSitText() { } | ||
297 | public void llSetCameraEyeOffset() { } | ||
298 | public void llSetCameraAtOffset() { } | ||
299 | public void llDumpList2String() { } | ||
300 | public void llScriptDanger() { } | ||
301 | public void llDialog() { } | ||
302 | public void llVolumeDetect() { } | ||
303 | public void llResetOtherScript() { } | ||
304 | public void llGetScriptState() { } | ||
305 | public void llRemoteLoadScript() { } | ||
306 | public void llSetRemoteScriptAccessPin() { } | ||
307 | public void llRemoteLoadScriptPin() { } | ||
308 | public void llOpenRemoteDataChannel() { } | ||
309 | public void llSendRemoteData() { } | ||
310 | public void llRemoteDataReply() { } | ||
311 | public void llCloseRemoteDataChannel() { } | ||
312 | public void llMD5String() { } | ||
313 | public void llSetPrimitiveParams() { } | ||
314 | public void llStringToBase64() { } | ||
315 | public void llBase64ToString() { } | ||
316 | public void llXorBase64Strings() { } | ||
317 | public void llRemoteDataSetRegion() { } | ||
318 | public void llLog10() { } | ||
319 | public void llLog() { } | ||
320 | public void llGetAnimationList() { } | ||
321 | public void llSetParcelMusicURL() { } | ||
322 | public void llGetRootPosition() { } | ||
323 | public void llGetRootRotation() { } | ||
324 | public void llGetObjectDesc() { } | ||
325 | public void llSetObjectDesc() { } | ||
326 | public void llGetCreator() { } | ||
327 | public void llGetTimestamp() { } | ||
328 | public void llSetLinkAlpha() { } | ||
329 | public void llGetNumberOfPrims() { } | ||
330 | public void llGetNumberOfNotecardLines() { } | ||
331 | public void llGetBoundingBox() { } | ||
332 | public void llGetGeometricCenter() { } | ||
333 | public void llGetPrimitiveParams() { } | ||
334 | public void llIntegerToBase64() { } | ||
335 | public void llBase64ToInteger() { } | ||
336 | public void llGetGMTclock() { } | ||
337 | public void llGetSimulatorHostname() { } | ||
338 | public void llSetLocalRot() { } | ||
339 | public void llParseStringKeepNulls() { } | ||
340 | public void llRezAtRoot() { } | ||
341 | public void llGetObjectPermMask() { } | ||
342 | public void llSetObjectPermMask() { } | ||
343 | public void llGetInventoryPermMask() { } | ||
344 | public void llSetInventoryPermMask() { } | ||
345 | public void llGetInventoryCreator() { } | ||
346 | public void llOwnerSay() { } | ||
347 | public void llRequestSimulatorData() { } | ||
348 | public void llForceMouselook() { } | ||
349 | public void llGetObjectMass() { } | ||
350 | public void llListReplaceList() { } | ||
351 | public void llLoadURL() { } | ||
352 | public void llParcelMediaCommandList() { } | ||
353 | public void llParcelMediaQuery() { } | ||
354 | public void llModPow() { } | ||
355 | public void llGetInventoryType() { } | ||
356 | public void llSetPayPrice() { } | ||
357 | public void llGetCameraPos() { } | ||
358 | public void llGetCameraRot() { } | ||
359 | public void llSetPrimURL() { } | ||
360 | public void llRefreshPrimURL() { } | ||
361 | public void llEscapeURL() { } | ||
362 | public void llUnescapeURL() { } | ||
363 | public void llMapDestination() { } | ||
364 | public void llAddToLandBanList() { } | ||
365 | public void llRemoveFromLandPassList() { } | ||
366 | public void llRemoveFromLandBanList() { } | ||
367 | public void llSetCameraParams() { } | ||
368 | public void llClearCameraParams() { } | ||
369 | public void llListStatistics() { } | ||
370 | public void llGetUnixTime() { } | ||
371 | public void llGetParcelFlags() { } | ||
372 | public void llGetRegionFlags() { } | ||
373 | public void llXorBase64StringsCorrect() { } | ||
374 | public void llHTTPRequest() { } | ||
375 | public void llResetLandBanList() { } | ||
376 | public void llResetLandPassList() { } | ||
377 | public void llGetParcelPrimCount() { } | ||
378 | public void llGetParcelPrimOwners() { } | ||
379 | public void llGetObjectPrimCount() { } | ||
380 | public void llGetParcelMaxPrims() { } | ||
381 | public void llGetParcelDetails() { } | ||
382 | |||
383 | |||
384 | |||
385 | } | ||
386 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/temp_rc.cs b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/temp_rc.cs new file mode 100644 index 0000000..fa7de2b --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine.Compiler.LSL/temp_rc.cs | |||
@@ -0,0 +1,3293 @@ | |||
1 | //------------------------------------------------------------------------------ | ||
2 | // <copyright file="RegexCompiler.cs" company="Microsoft"> | ||
3 | // | ||
4 | // Copyright (c) 2002 Microsoft Corporation. All rights reserved. | ||
5 | // | ||
6 | // The use and distribution terms for this software are contained in the file | ||
7 | // named license.txt, which can be found in the root of this distribution. | ||
8 | // By using this software in any fashion, you are agreeing to be bound by the | ||
9 | // terms of this license. | ||
10 | // | ||
11 | // You must not remove this notice, or any other, from this software. | ||
12 | // | ||
13 | // </copyright> | ||
14 | //------------------------------------------------------------------------------ | ||
15 | |||
16 | // The RegexCompiler class is internal to the Regex package. | ||
17 | // It translates a block of RegexCode to MSIL, and creates a | ||
18 | // subclass of the RegexRunner type. | ||
19 | // | ||
20 | #define ECMA | ||
21 | |||
22 | namespace System.Text.RegularExpressions | ||
23 | { | ||
24 | |||
25 | using System.Collections; | ||
26 | using System.Threading; | ||
27 | using System.Reflection; | ||
28 | using System.Reflection.Emit; | ||
29 | using System.Security; | ||
30 | using System.Security.Permissions; | ||
31 | using System.Diagnostics; | ||
32 | using System.Globalization; | ||
33 | |||
34 | // RegexDynamicModule | ||
35 | // | ||
36 | // Because dynamic modules are expensive and not thread-safe, we create | ||
37 | // one dynamic module per-thread, and cache as much information about it | ||
38 | // as we can. | ||
39 | // | ||
40 | // While we're at it, we just create one RegexCompiler per thread | ||
41 | // as well, and have RegexCompiler inherit from RegexDynamicModule. | ||
42 | internal class RegexDynamicModule | ||
43 | { | ||
44 | internal AssemblyBuilder _assembly; | ||
45 | internal ModuleBuilder _module; | ||
46 | |||
47 | // fields that never change (making them saves about 6% overall running time) | ||
48 | |||
49 | internal static FieldInfo _textbegF; | ||
50 | internal static FieldInfo _textendF; | ||
51 | internal static FieldInfo _textstartF; | ||
52 | internal static FieldInfo _textposF; | ||
53 | internal static FieldInfo _textF; | ||
54 | internal static FieldInfo _trackposF; | ||
55 | internal static FieldInfo _trackF; | ||
56 | internal static FieldInfo _stackposF; | ||
57 | internal static FieldInfo _stackF; | ||
58 | internal static FieldInfo _crawlposF; | ||
59 | internal static FieldInfo _crawlF; | ||
60 | internal static FieldInfo _matchF; | ||
61 | internal static FieldInfo _trackcountF; | ||
62 | |||
63 | // note some methods | ||
64 | |||
65 | internal static MethodInfo _ensurestorageM; | ||
66 | internal static MethodInfo _captureM; | ||
67 | internal static MethodInfo _transferM; | ||
68 | internal static MethodInfo _uncaptureM; | ||
69 | internal static MethodInfo _ismatchedM; | ||
70 | internal static MethodInfo _matchlengthM; | ||
71 | internal static MethodInfo _matchindexM; | ||
72 | internal static MethodInfo _isboundaryM; | ||
73 | internal static MethodInfo _isECMABoundaryM; | ||
74 | internal static MethodInfo _chartolowerM; | ||
75 | internal static MethodInfo _getcharM; | ||
76 | internal static MethodInfo _crawlposM; | ||
77 | internal static MethodInfo _charInSetM; | ||
78 | internal static MethodInfo _getCurrentCulture; | ||
79 | internal static MethodInfo _getInvariantCulture; | ||
80 | #if DBG | ||
81 | internal static MethodInfo _dumpstateM; | ||
82 | #endif | ||
83 | |||
84 | |||
85 | protected RegexDynamicModule(int moduleNum, AssemblyName an, CustomAttributeBuilder[] attribs, String resourceFile) | ||
86 | { | ||
87 | new ReflectionPermission(PermissionState.Unrestricted).Assert(); | ||
88 | try | ||
89 | { | ||
90 | if (an == null) | ||
91 | { | ||
92 | an = new AssemblyName(); | ||
93 | an.Name = "RegexAssembly" + AppDomain.CurrentDomain.GetHashCode().ToString() + "_" + moduleNum.ToString(); | ||
94 | _assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run); | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | _assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave); | ||
99 | } | ||
100 | |||
101 | _module = _assembly.DefineDynamicModule(an.Name + ".dll"); | ||
102 | |||
103 | if (attribs != null) | ||
104 | { | ||
105 | for (int i = 0; i < attribs.Length; i++) | ||
106 | { | ||
107 | _assembly.SetCustomAttribute(attribs[i]); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | if (resourceFile != null) | ||
112 | { | ||
113 | // unmanaged resources are not supported | ||
114 | throw new ArgumentOutOfRangeException("resourceFile"); | ||
115 | } | ||
116 | } | ||
117 | finally | ||
118 | { | ||
119 | CodeAccessPermission.RevertAssert(); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | static RegexDynamicModule() | ||
124 | { | ||
125 | |||
126 | new ReflectionPermission(PermissionState.Unrestricted).Assert(); | ||
127 | try | ||
128 | { | ||
129 | // note some fields | ||
130 | _textbegF = RegexRunnerField("runtextbeg"); | ||
131 | _textendF = RegexRunnerField("runtextend"); | ||
132 | _textstartF = RegexRunnerField("runtextstart"); | ||
133 | _textposF = RegexRunnerField("runtextpos"); | ||
134 | _textF = RegexRunnerField("runtext"); | ||
135 | _trackposF = RegexRunnerField("runtrackpos"); | ||
136 | _trackF = RegexRunnerField("runtrack"); | ||
137 | _stackposF = RegexRunnerField("runstackpos"); | ||
138 | _stackF = RegexRunnerField("runstack"); | ||
139 | _crawlposF = RegexRunnerField("runcrawlpos"); | ||
140 | _crawlF = RegexRunnerField("runcrawl"); | ||
141 | _matchF = RegexRunnerField("runmatch"); | ||
142 | _trackcountF = RegexRunnerField("runtrackcount"); | ||
143 | |||
144 | // note some methods | ||
145 | _ensurestorageM = RegexRunnerMethod("EnsureStorage"); | ||
146 | _captureM = RegexRunnerMethod("Capture"); | ||
147 | _transferM = RegexRunnerMethod("TransferCapture"); | ||
148 | _uncaptureM = RegexRunnerMethod("Uncapture"); | ||
149 | _ismatchedM = RegexRunnerMethod("IsMatched"); | ||
150 | _matchlengthM = RegexRunnerMethod("MatchLength"); | ||
151 | _matchindexM = RegexRunnerMethod("MatchIndex"); | ||
152 | _isboundaryM = RegexRunnerMethod("IsBoundary"); | ||
153 | _charInSetM = RegexRunnerMethod("CharInSet"); | ||
154 | _isECMABoundaryM = RegexRunnerMethod("IsECMABoundary"); | ||
155 | _crawlposM = RegexRunnerMethod("Crawlpos"); | ||
156 | |||
157 | _chartolowerM = typeof(Char).GetMethod("ToLower", new Type[] { typeof(Char), typeof(CultureInfo) }); | ||
158 | _getcharM = typeof(String).GetMethod("get_Chars", new Type[] { typeof(int) }); | ||
159 | _getCurrentCulture = typeof(CultureInfo).GetMethod("get_CurrentCulture"); | ||
160 | _getInvariantCulture = typeof(CultureInfo).GetMethod("get_InvariantCulture"); | ||
161 | |||
162 | |||
163 | #if DBG | ||
164 | _dumpstateM = RegexRunnerMethod("DumpState"); | ||
165 | #endif | ||
166 | } | ||
167 | finally | ||
168 | { | ||
169 | CodeAccessPermission.RevertAssert(); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | private static FieldInfo RegexRunnerField(String fieldname) | ||
174 | { | ||
175 | return typeof(RegexRunner).GetField(fieldname, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); | ||
176 | } | ||
177 | |||
178 | private static MethodInfo RegexRunnerMethod(String methname) | ||
179 | { | ||
180 | return typeof(RegexRunner).GetMethod(methname, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); | ||
181 | } | ||
182 | } | ||
183 | |||
184 | |||
185 | internal sealed class RegexCompiler : RegexDynamicModule | ||
186 | { | ||
187 | internal static Object _syncObject = new Object(); | ||
188 | internal static int _typeCount = 0; | ||
189 | internal static int _moduleCount = 0; | ||
190 | internal static LocalDataStoreSlot _moduleSlot = Thread.AllocateDataSlot(); | ||
191 | |||
192 | // state of the type builder | ||
193 | internal TypeBuilder _typebuilder; | ||
194 | internal MethodBuilder _methbuilder; | ||
195 | internal ILGenerator _ilg; | ||
196 | |||
197 | // tokens representing local variables | ||
198 | internal LocalBuilder _textstartV; | ||
199 | internal LocalBuilder _textbegV; | ||
200 | internal LocalBuilder _textendV; | ||
201 | internal LocalBuilder _textposV; | ||
202 | internal LocalBuilder _textV; | ||
203 | internal LocalBuilder _trackposV; | ||
204 | internal LocalBuilder _trackV; | ||
205 | internal LocalBuilder _stackposV; | ||
206 | internal LocalBuilder _stackV; | ||
207 | internal LocalBuilder _tempV; | ||
208 | internal LocalBuilder _temp2V; | ||
209 | internal LocalBuilder _temp3V; | ||
210 | |||
211 | |||
212 | internal RegexCode _code; // the RegexCode object (used for debugging only) | ||
213 | internal int[] _codes; // the RegexCodes being translated | ||
214 | internal String[] _strings; // the stringtable associated with the RegexCodes | ||
215 | internal RegexPrefix _fcPrefix; // the possible first chars computed by RegexFCD | ||
216 | internal RegexPrefix _scPrefix; // the set of eaten prefix chars | ||
217 | internal RegexBoyerMoore _bmPrefix; // a prefix as a boyer-moore machine | ||
218 | internal int _anchors; // the set of anchors | ||
219 | |||
220 | internal Label[] _labels; // a label for every operation in _codes | ||
221 | internal BacktrackNote[] _notes; // a list of the backtracking states to be generated | ||
222 | internal int _notecount; // true count of _notes (allocation grows exponentially) | ||
223 | internal int _trackcount; // count of backtracking states (used to reduce allocations) | ||
224 | |||
225 | internal Label _backtrack; // label for backtracking | ||
226 | |||
227 | |||
228 | internal int _regexopcode; // the current opcode being processed | ||
229 | internal int _codepos; // the current code being translated | ||
230 | internal int _backpos; // the current backtrack-note being translated | ||
231 | |||
232 | internal RegexOptions _options; // options | ||
233 | |||
234 | internal const int infinite = RegexNode.infinite; // an infinity | ||
235 | |||
236 | // special code fragments | ||
237 | internal int[] _uniquenote; // _notes indices for code that should be emitted <= once | ||
238 | internal int[] _goto; // indices for forward-jumps-through-switch (for allocations) | ||
239 | |||
240 | // indices for unique code fragments | ||
241 | internal const int stackpop = 0; // pop one | ||
242 | internal const int stackpop2 = 1; // pop two | ||
243 | internal const int stackpop3 = 2; // pop three | ||
244 | internal const int capback = 3; // uncapture | ||
245 | internal const int capback2 = 4; // uncapture 2 | ||
246 | internal const int branchmarkback2 = 5; // back2 part of branchmark | ||
247 | internal const int lazybranchmarkback2 = 6; // back2 part of lazybranchmark | ||
248 | internal const int branchcountback2 = 7; // back2 part of branchcount | ||
249 | internal const int lazybranchcountback2 = 8; // back2 part of lazybranchcount | ||
250 | internal const int forejumpback = 9; // back part of forejump | ||
251 | internal const int uniquecount = 10; | ||
252 | |||
253 | |||
254 | private RegexCompiler(int moduleNum) | ||
255 | : base(moduleNum, null, null, null) | ||
256 | { | ||
257 | } | ||
258 | |||
259 | private RegexCompiler(int moduleNum, AssemblyName an, CustomAttributeBuilder[] attribs, String resourceFile) | ||
260 | : base(moduleNum, an, attribs, resourceFile) | ||
261 | { | ||
262 | } | ||
263 | |||
264 | // Entry point to dynamically compile a regular expression. The expression is compiled to | ||
265 | // an in memory assembly. | ||
266 | internal static RegexRunnerFactory Compile(RegexCode code, RegexOptions options) | ||
267 | { | ||
268 | RegexCompiler c; | ||
269 | |||
270 | c = GetThreadCompiler(); | ||
271 | |||
272 | Type factory; | ||
273 | RegexRunnerFactory rrf; | ||
274 | |||
275 | new ReflectionPermission(PermissionState.Unrestricted).Assert(); | ||
276 | try | ||
277 | { | ||
278 | factory = c.FactoryFromCode(code, options, "Regex"); | ||
279 | rrf = (RegexRunnerFactory)(Activator.CreateInstance(factory, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, null, null)); | ||
280 | } | ||
281 | finally | ||
282 | { | ||
283 | CodeAccessPermission.RevertAssert(); | ||
284 | } | ||
285 | return rrf; | ||
286 | } | ||
287 | |||
288 | // Compile regular expressions into an assembly on disk. | ||
289 | internal static void CompileToAssembly(RegexCompilationInfo[] regexes, AssemblyName an, CustomAttributeBuilder[] attribs, String resourceFile) | ||
290 | { | ||
291 | RegexCompiler c = new RegexCompiler(0, an, attribs, resourceFile); | ||
292 | |||
293 | for (int i = 0; i < regexes.Length; i++) | ||
294 | { | ||
295 | String pattern = regexes[i].Pattern; | ||
296 | RegexOptions options = regexes[i].Options; | ||
297 | String fullname = regexes[i].Namespace + "." + regexes[i].Name; | ||
298 | |||
299 | RegexTree tree = RegexParser.Parse(pattern, options); | ||
300 | RegexCode code = RegexWriter.Write(tree); | ||
301 | |||
302 | Type factory; | ||
303 | |||
304 | new ReflectionPermission(PermissionState.Unrestricted).Assert(); | ||
305 | try | ||
306 | { | ||
307 | factory = c.FactoryFromCode(code, options, fullname); | ||
308 | c.GenerateRegexType(pattern, options, fullname, regexes[i].IsPublic, code, tree, factory); | ||
309 | } | ||
310 | finally | ||
311 | { | ||
312 | CodeAccessPermission.RevertAssert(); | ||
313 | } | ||
314 | } | ||
315 | |||
316 | c.Save(); | ||
317 | } | ||
318 | |||
319 | // The top-level driver. Initializes everything then calls the Generate* methods. | ||
320 | internal Type FactoryFromCode(RegexCode code, RegexOptions options, String typeprefix) | ||
321 | { | ||
322 | String runnertypename; | ||
323 | String runnerfactoryname; | ||
324 | Type runnertype; | ||
325 | Type factory; | ||
326 | |||
327 | _code = code; | ||
328 | _codes = code._codes; | ||
329 | _strings = code._strings; | ||
330 | _fcPrefix = code._fcPrefix; | ||
331 | _scPrefix = code._scPrefix; | ||
332 | _bmPrefix = code._bmPrefix; | ||
333 | _anchors = code._anchors; | ||
334 | _trackcount = code._trackcount; | ||
335 | _options = options; | ||
336 | |||
337 | // pick a name for the class | ||
338 | |||
339 | lock (_syncObject) | ||
340 | { | ||
341 | |||
342 | // Note: Class names must be unique within assemblies, not just | ||
343 | // within modules. We append the modulename to the runner name | ||
344 | // to make our name unique across the assembly | ||
345 | |||
346 | runnertypename = typeprefix + "Runner" + _typeCount.ToString(); | ||
347 | runnerfactoryname = typeprefix + "Factory" + _typeCount.ToString(); | ||
348 | _typeCount++; | ||
349 | } | ||
350 | |||
351 | // Generate a RegexRunner class | ||
352 | // (blocks are simply illustrative) | ||
353 | |||
354 | DefineType(runnertypename, false, typeof(RegexRunner)); | ||
355 | { | ||
356 | DefineMethod("Go", null); | ||
357 | { | ||
358 | GenerateGo(); | ||
359 | BakeMethod(); | ||
360 | } | ||
361 | |||
362 | DefineMethod("FindFirstChar", typeof(bool)); | ||
363 | { | ||
364 | GenerateFindFirstChar(); | ||
365 | BakeMethod(); | ||
366 | } | ||
367 | |||
368 | DefineMethod("InitTrackCount", null); | ||
369 | { | ||
370 | GenerateInitTrackCount(); | ||
371 | BakeMethod(); | ||
372 | } | ||
373 | |||
374 | runnertype = BakeType(); | ||
375 | } | ||
376 | |||
377 | // Generate a RegexRunnerFactory class | ||
378 | |||
379 | DefineType(runnerfactoryname, false, typeof(RegexRunnerFactory)); | ||
380 | { | ||
381 | DefineMethod("CreateInstance", typeof(RegexRunner)); | ||
382 | { | ||
383 | GenerateCreateInstance(runnertype); | ||
384 | BakeMethod(); | ||
385 | } | ||
386 | |||
387 | factory = BakeType(); | ||
388 | } | ||
389 | |||
390 | return factory; | ||
391 | } | ||
392 | |||
393 | |||
394 | internal void GenerateRegexType(String pattern, RegexOptions opts, String name, bool ispublic, RegexCode code, RegexTree tree, Type factory) | ||
395 | { | ||
396 | FieldInfo patternF = RegexField("pattern"); | ||
397 | FieldInfo optionsF = RegexField("roptions"); | ||
398 | FieldInfo factoryF = RegexField("factory"); | ||
399 | FieldInfo capsF = RegexField("caps"); | ||
400 | FieldInfo capnamesF = RegexField("capnames"); | ||
401 | FieldInfo capslistF = RegexField("capslist"); | ||
402 | FieldInfo capsizeF = RegexField("capsize"); | ||
403 | Type[] noTypeArray = new Type[0]; | ||
404 | ConstructorBuilder cbuilder; | ||
405 | |||
406 | DefineType(name, ispublic, typeof(Regex)); | ||
407 | { | ||
408 | // define constructor | ||
409 | _methbuilder = null; | ||
410 | MethodAttributes ma = System.Reflection.MethodAttributes.Public; | ||
411 | cbuilder = _typebuilder.DefineConstructor(ma, CallingConventions.Standard, noTypeArray); | ||
412 | _ilg = cbuilder.GetILGenerator(); | ||
413 | { | ||
414 | // call base constructor | ||
415 | Ldthis(); | ||
416 | _ilg.Emit(OpCodes.Call, typeof(Regex).GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, | ||
417 | null, new Type[0], new ParameterModifier[0])); | ||
418 | // set pattern | ||
419 | Ldthis(); | ||
420 | Ldstr(pattern); | ||
421 | Stfld(patternF); | ||
422 | |||
423 | // set options | ||
424 | Ldthis(); | ||
425 | Ldc((int)opts); | ||
426 | Stfld(optionsF); | ||
427 | |||
428 | // set factory | ||
429 | Ldthis(); | ||
430 | Newobj(factory.GetConstructor(noTypeArray)); | ||
431 | Stfld(factoryF); | ||
432 | |||
433 | // set caps | ||
434 | if (code._caps != null) | ||
435 | GenerateCreateHashtable(capsF, code._caps); | ||
436 | |||
437 | // set capnames | ||
438 | if (tree._capnames != null) | ||
439 | GenerateCreateHashtable(capnamesF, tree._capnames); | ||
440 | |||
441 | // set capslist | ||
442 | if (tree._capslist != null) | ||
443 | { | ||
444 | Ldthis(); | ||
445 | Ldc(tree._capslist.Length); | ||
446 | _ilg.Emit(OpCodes.Newarr, typeof(String)); // create new string array | ||
447 | Stfld(capslistF); | ||
448 | |||
449 | for (int i = 0; i < tree._capslist.Length; i++) | ||
450 | { | ||
451 | Ldthisfld(capslistF); | ||
452 | |||
453 | Ldc(i); | ||
454 | Ldstr(tree._capslist[i]); | ||
455 | _ilg.Emit(OpCodes.Stelem_Ref); | ||
456 | } | ||
457 | } | ||
458 | |||
459 | // set capsize | ||
460 | Ldthis(); | ||
461 | Ldc(code._capsize); | ||
462 | Stfld(capsizeF); | ||
463 | |||
464 | // set runnerref and replref by calling InitializeReferences() | ||
465 | Ldthis(); | ||
466 | Call(typeof(Regex).GetMethod("InitializeReferences", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)); | ||
467 | |||
468 | |||
469 | Ret(); | ||
470 | } | ||
471 | } | ||
472 | |||
473 | // bake the constructor and type, then save the assembly | ||
474 | cbuilder = null; | ||
475 | _typebuilder.CreateType(); | ||
476 | _ilg = null; | ||
477 | _typebuilder = null; | ||
478 | } | ||
479 | |||
480 | internal void GenerateCreateHashtable(FieldInfo field, Hashtable ht) | ||
481 | { | ||
482 | MethodInfo addMethod = typeof(Hashtable).GetMethod("Add", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); | ||
483 | |||
484 | Ldthis(); | ||
485 | Newobj(typeof(Hashtable).GetConstructor(new Type[0])); | ||
486 | Stfld(field); | ||
487 | |||
488 | IDictionaryEnumerator en = ht.GetEnumerator(); | ||
489 | while (en.MoveNext()) | ||
490 | { | ||
491 | Ldthisfld(field); | ||
492 | |||
493 | if (en.Key is int) | ||
494 | { | ||
495 | Ldc((int)en.Key); | ||
496 | _ilg.Emit(OpCodes.Box, typeof(Int32)); | ||
497 | } | ||
498 | else | ||
499 | Ldstr((String)en.Key); | ||
500 | |||
501 | Ldc((int)en.Value); | ||
502 | _ilg.Emit(OpCodes.Box, typeof(Int32)); | ||
503 | Callvirt(addMethod); | ||
504 | } | ||
505 | } | ||
506 | |||
507 | private FieldInfo RegexField(String fieldname) | ||
508 | { | ||
509 | return typeof(Regex).GetField(fieldname, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); | ||
510 | } | ||
511 | |||
512 | internal void Save() | ||
513 | { | ||
514 | _assembly.Save(_assembly.GetName().Name + ".dll"); | ||
515 | } | ||
516 | |||
517 | // Keeps track of an operation that needs to be referenced in the backtrack-jump | ||
518 | // switch table, and that needs backtracking code to be emitted (if flags != 0) | ||
519 | internal sealed class BacktrackNote | ||
520 | { | ||
521 | internal BacktrackNote(int flags, Label label, int codepos) | ||
522 | { | ||
523 | _codepos = codepos; | ||
524 | _flags = flags; | ||
525 | _label = label; | ||
526 | } | ||
527 | |||
528 | internal int _codepos; | ||
529 | internal int _flags; | ||
530 | internal Label _label; | ||
531 | } | ||
532 | |||
533 | // Adds a backtrack note to the list of them, and returns the index of the new | ||
534 | // note (which is also the index for the jump used by the switch table) | ||
535 | internal int AddBacktrackNote(int flags, Label l, int codepos) | ||
536 | { | ||
537 | if (_notes == null || _notecount >= _notes.Length) | ||
538 | { | ||
539 | BacktrackNote[] newnotes = new BacktrackNote[_notes == null ? 16 : _notes.Length * 2]; | ||
540 | if (_notes != null) | ||
541 | System.Array.Copy(_notes, 0, newnotes, 0, _notecount); | ||
542 | _notes = newnotes; | ||
543 | } | ||
544 | |||
545 | _notes[_notecount] = new BacktrackNote(flags, l, codepos); | ||
546 | |||
547 | return _notecount++; | ||
548 | } | ||
549 | |||
550 | // Adds a backtrack note for the current operation; creates a new label for | ||
551 | // where the code will be, and returns the switch index. | ||
552 | internal int AddTrack() | ||
553 | { | ||
554 | return AddTrack(RegexCode.Back); | ||
555 | } | ||
556 | |||
557 | // Adds a backtrack note for the current operation; creates a new label for | ||
558 | // where the code will be, and returns the switch index. | ||
559 | internal int AddTrack(int flags) | ||
560 | { | ||
561 | return AddBacktrackNote(flags, DefineLabel(), _codepos); | ||
562 | } | ||
563 | |||
564 | // Adds a switchtable entry for the specified position (for the forward | ||
565 | // logic; does not cause backtracking logic to be generated) | ||
566 | internal int AddGoto(int destpos) | ||
567 | { | ||
568 | if (_goto[destpos] == -1) | ||
569 | _goto[destpos] = AddBacktrackNote(0, _labels[destpos], destpos); | ||
570 | |||
571 | return _goto[destpos]; | ||
572 | } | ||
573 | |||
574 | // Adds a note for backtracking code that only needs to be generated once; | ||
575 | // if it's already marked to be generated, returns the switch index | ||
576 | // for the unique piece of code. | ||
577 | internal int AddUniqueTrack(int i) | ||
578 | { | ||
579 | return AddUniqueTrack(i, RegexCode.Back); | ||
580 | } | ||
581 | |||
582 | // Adds a note for backtracking code that only needs to be generated once; | ||
583 | // if it's already marked to be generated, returns the switch index | ||
584 | // for the unique piece of code. | ||
585 | internal int AddUniqueTrack(int i, int flags) | ||
586 | { | ||
587 | if (_uniquenote[i] == -1) | ||
588 | _uniquenote[i] = AddTrack(flags); | ||
589 | |||
590 | return _uniquenote[i]; | ||
591 | } | ||
592 | |||
593 | // A macro for _ilg.DefineLabel | ||
594 | internal Label DefineLabel() | ||
595 | { | ||
596 | return _ilg.DefineLabel(); | ||
597 | } | ||
598 | |||
599 | // A macro for _ilg.MarkLabel | ||
600 | internal void MarkLabel(Label l) | ||
601 | { | ||
602 | _ilg.MarkLabel(l); | ||
603 | } | ||
604 | |||
605 | // Returns the ith operand of the current operation | ||
606 | internal int Operand(int i) | ||
607 | { | ||
608 | return _codes[_codepos + i + 1]; | ||
609 | } | ||
610 | |||
611 | // True if the current operation is marked for the leftward direction | ||
612 | internal bool IsRtl() | ||
613 | { | ||
614 | return (_regexopcode & RegexCode.Rtl) != 0; | ||
615 | } | ||
616 | |||
617 | // True if the current operation is marked for the leftward direction | ||
618 | internal bool IsCi() | ||
619 | { | ||
620 | return (_regexopcode & RegexCode.Ci) != 0; | ||
621 | } | ||
622 | |||
623 | #if DBG | ||
624 | // True if we need to do the backtrack logic for the current operation | ||
625 | internal bool IsBack() { | ||
626 | return(_regexopcode & RegexCode.Back) != 0; | ||
627 | } | ||
628 | |||
629 | // True if we need to do the second-backtrack logic for the current operation | ||
630 | internal bool IsBack2() { | ||
631 | return(_regexopcode & RegexCode.Back2) != 0; | ||
632 | } | ||
633 | #endif | ||
634 | |||
635 | // Returns the raw regex opcode (masking out Back and Rtl) | ||
636 | internal int Code() | ||
637 | { | ||
638 | return _regexopcode & RegexCode.Mask; | ||
639 | } | ||
640 | |||
641 | internal void Ldstr(string str) | ||
642 | { | ||
643 | _ilg.Emit(OpCodes.Ldstr, str); | ||
644 | } | ||
645 | |||
646 | // A macro for the various forms of Ldc | ||
647 | internal void Ldc(int i) | ||
648 | { | ||
649 | if (i <= 127 && i >= -128) | ||
650 | _ilg.Emit(OpCodes.Ldc_I4_S, (byte)i); | ||
651 | else | ||
652 | _ilg.Emit(OpCodes.Ldc_I4, i); | ||
653 | } | ||
654 | |||
655 | // A macro for _ilg.Emit(OpCodes.Dup) | ||
656 | internal void Dup() | ||
657 | { | ||
658 | _ilg.Emit(OpCodes.Dup); | ||
659 | } | ||
660 | |||
661 | // A macro for _ilg.Emit(OpCodes.Ret) | ||
662 | internal void Ret() | ||
663 | { | ||
664 | _ilg.Emit(OpCodes.Ret); | ||
665 | } | ||
666 | |||
667 | // A macro for _ilg.Emit(OpCodes.Pop) | ||
668 | internal void Pop() | ||
669 | { | ||
670 | _ilg.Emit(OpCodes.Pop); | ||
671 | } | ||
672 | |||
673 | // A macro for _ilg.Emit(OpCodes.Add) | ||
674 | internal void Add() | ||
675 | { | ||
676 | _ilg.Emit(OpCodes.Add); | ||
677 | } | ||
678 | |||
679 | // A macro for _ilg.Emit(OpCodes.Add); a true flag can turn it into a Sub | ||
680 | internal void Add(bool negate) | ||
681 | { | ||
682 | if (negate) | ||
683 | _ilg.Emit(OpCodes.Sub); | ||
684 | else | ||
685 | _ilg.Emit(OpCodes.Add); | ||
686 | } | ||
687 | |||
688 | // A macro for _ilg.Emit(OpCodes.Sub) | ||
689 | internal void Sub() | ||
690 | { | ||
691 | _ilg.Emit(OpCodes.Sub); | ||
692 | } | ||
693 | |||
694 | // A macro for _ilg.Emit(OpCodes.Sub); a true flag can turn it into a Add | ||
695 | internal void Sub(bool negate) | ||
696 | { | ||
697 | if (negate) | ||
698 | _ilg.Emit(OpCodes.Add); | ||
699 | else | ||
700 | _ilg.Emit(OpCodes.Sub); | ||
701 | } | ||
702 | |||
703 | // A macro for _ilg.Emit(OpCodes.Ldloc); | ||
704 | internal void Ldloc(LocalBuilder lt) | ||
705 | { | ||
706 | _ilg.Emit(OpCodes.Ldloc_S, lt); | ||
707 | } | ||
708 | |||
709 | // A macro for _ilg.Emit(OpCodes.Stloc); | ||
710 | internal void Stloc(LocalBuilder lt) | ||
711 | { | ||
712 | _ilg.Emit(OpCodes.Stloc_S, lt); | ||
713 | } | ||
714 | |||
715 | // A macro for _ilg.Emit(OpCodes.Ldarg_0); | ||
716 | internal void Ldthis() | ||
717 | { | ||
718 | _ilg.Emit(OpCodes.Ldarg_0); | ||
719 | } | ||
720 | |||
721 | // A macro for Ldthis(); Ldfld(); | ||
722 | internal void Ldthisfld(FieldInfo ft) | ||
723 | { | ||
724 | Ldthis(); | ||
725 | _ilg.Emit(OpCodes.Ldfld, ft); | ||
726 | } | ||
727 | |||
728 | // A macro for Ldthis(); Ldfld(); Stloc(); | ||
729 | internal void Mvfldloc(FieldInfo ft, LocalBuilder lt) | ||
730 | { | ||
731 | Ldthisfld(ft); | ||
732 | Stloc(lt); | ||
733 | } | ||
734 | |||
735 | // A macro for Ldthis(); Ldthisfld(); Stloc(); | ||
736 | internal void Mvlocfld(LocalBuilder lt, FieldInfo ft) | ||
737 | { | ||
738 | Ldthis(); | ||
739 | Ldloc(lt); | ||
740 | Stfld(ft); | ||
741 | } | ||
742 | |||
743 | // A macro for _ilg.Emit(OpCodes.Stfld); | ||
744 | internal void Stfld(FieldInfo ft) | ||
745 | { | ||
746 | _ilg.Emit(OpCodes.Stfld, ft); | ||
747 | } | ||
748 | |||
749 | // A macro for _ilg.Emit(OpCodes.Callvirt); | ||
750 | internal void Callvirt(MethodInfo mt) | ||
751 | { | ||
752 | _ilg.Emit(OpCodes.Callvirt, mt); | ||
753 | } | ||
754 | |||
755 | // A macro for _ilg.Emit(OpCodes.Call); | ||
756 | internal void Call(MethodInfo mt) | ||
757 | { | ||
758 | _ilg.Emit(OpCodes.Call, mt); | ||
759 | } | ||
760 | |||
761 | // A macro for _ilg.Emit(OpCodes.Newobj); | ||
762 | internal void Newobj(ConstructorInfo ct) | ||
763 | { | ||
764 | _ilg.Emit(OpCodes.Newobj, ct); | ||
765 | } | ||
766 | |||
767 | // A macro for _ilg.Emit(OpCodes.Brfalse) (long form) | ||
768 | internal void BrfalseFar(Label l) | ||
769 | { | ||
770 | _ilg.Emit(OpCodes.Brfalse, l); | ||
771 | } | ||
772 | |||
773 | // A macro for _ilg.Emit(OpCodes.Brtrue) (long form) | ||
774 | internal void BrtrueFar(Label l) | ||
775 | { | ||
776 | _ilg.Emit(OpCodes.Brtrue, l); | ||
777 | } | ||
778 | |||
779 | // A macro for _ilg.Emit(OpCodes.Br) (long form) | ||
780 | internal void BrFar(Label l) | ||
781 | { | ||
782 | _ilg.Emit(OpCodes.Br, l); | ||
783 | } | ||
784 | |||
785 | // A macro for _ilg.Emit(OpCodes.Ble) (long form) | ||
786 | internal void BleFar(Label l) | ||
787 | { | ||
788 | _ilg.Emit(OpCodes.Ble, l); | ||
789 | } | ||
790 | |||
791 | // A macro for _ilg.Emit(OpCodes.Blt) (long form) | ||
792 | internal void BltFar(Label l) | ||
793 | { | ||
794 | _ilg.Emit(OpCodes.Blt, l); | ||
795 | } | ||
796 | |||
797 | // A macro for _ilg.Emit(OpCodes.Bge) (long form) | ||
798 | internal void BgeFar(Label l) | ||
799 | { | ||
800 | _ilg.Emit(OpCodes.Bge, l); | ||
801 | } | ||
802 | |||
803 | // A macro for _ilg.Emit(OpCodes.Bgt) (long form) | ||
804 | internal void BgtFar(Label l) | ||
805 | { | ||
806 | _ilg.Emit(OpCodes.Bgt, l); | ||
807 | } | ||
808 | |||
809 | // A macro for _ilg.Emit(OpCodes.Bne) (long form) | ||
810 | internal void BneFar(Label l) | ||
811 | { | ||
812 | _ilg.Emit(OpCodes.Bne_Un, l); | ||
813 | } | ||
814 | |||
815 | // A macro for _ilg.Emit(OpCodes.Beq) (long form) | ||
816 | internal void BeqFar(Label l) | ||
817 | { | ||
818 | _ilg.Emit(OpCodes.Beq, l); | ||
819 | } | ||
820 | |||
821 | // A macro for _ilg.Emit(OpCodes.Brfalse_S) (short jump) | ||
822 | internal void Brfalse(Label l) | ||
823 | { | ||
824 | _ilg.Emit(OpCodes.Brfalse_S, l); | ||
825 | } | ||
826 | |||
827 | // A macro for _ilg.Emit(OpCodes.Br_S) (short jump) | ||
828 | internal void Br(Label l) | ||
829 | { | ||
830 | _ilg.Emit(OpCodes.Br_S, l); | ||
831 | } | ||
832 | |||
833 | // A macro for _ilg.Emit(OpCodes.Ble_S) (short jump) | ||
834 | internal void Ble(Label l) | ||
835 | { | ||
836 | _ilg.Emit(OpCodes.Ble_S, l); | ||
837 | } | ||
838 | |||
839 | // A macro for _ilg.Emit(OpCodes.Blt_S) (short jump) | ||
840 | internal void Blt(Label l) | ||
841 | { | ||
842 | _ilg.Emit(OpCodes.Blt_S, l); | ||
843 | } | ||
844 | |||
845 | // A macro for _ilg.Emit(OpCodes.Bge_S) (short jump) | ||
846 | internal void Bge(Label l) | ||
847 | { | ||
848 | _ilg.Emit(OpCodes.Bge_S, l); | ||
849 | } | ||
850 | |||
851 | // A macro for _ilg.Emit(OpCodes.Bgt_S) (short jump) | ||
852 | internal void Bgt(Label l) | ||
853 | { | ||
854 | _ilg.Emit(OpCodes.Bgt_S, l); | ||
855 | } | ||
856 | |||
857 | // A macro for _ilg.Emit(OpCodes.Bleun_S) (short jump) | ||
858 | internal void Bgtun(Label l) | ||
859 | { | ||
860 | _ilg.Emit(OpCodes.Bgt_Un_S, l); | ||
861 | } | ||
862 | |||
863 | // A macro for _ilg.Emit(OpCodes.Bne_S) (short jump) | ||
864 | internal void Bne(Label l) | ||
865 | { | ||
866 | _ilg.Emit(OpCodes.Bne_Un_S, l); | ||
867 | } | ||
868 | |||
869 | // A macro for _ilg.Emit(OpCodes.Beq_S) (short jump) | ||
870 | internal void Beq(Label l) | ||
871 | { | ||
872 | _ilg.Emit(OpCodes.Beq_S, l); | ||
873 | } | ||
874 | |||
875 | // A macro for the Ldlen instruction | ||
876 | internal void Ldlen() | ||
877 | { | ||
878 | _ilg.Emit(OpCodes.Ldlen); | ||
879 | } | ||
880 | |||
881 | // Loads the char to the right of the current position | ||
882 | internal void Rightchar() | ||
883 | { | ||
884 | Ldloc(_textV); | ||
885 | Ldloc(_textposV); | ||
886 | Callvirt(_getcharM); | ||
887 | } | ||
888 | |||
889 | // Loads the char to the right of the current position and advances the current position | ||
890 | internal void Rightcharnext() | ||
891 | { | ||
892 | Ldloc(_textV); | ||
893 | Ldloc(_textposV); | ||
894 | Dup(); | ||
895 | Ldc(1); | ||
896 | Add(); | ||
897 | Stloc(_textposV); | ||
898 | Callvirt(_getcharM); | ||
899 | } | ||
900 | |||
901 | // Loads the char to the left of the current position | ||
902 | internal void Leftchar() | ||
903 | { | ||
904 | Ldloc(_textV); | ||
905 | Ldloc(_textposV); | ||
906 | Ldc(1); | ||
907 | Sub(); | ||
908 | Callvirt(_getcharM); | ||
909 | } | ||
910 | |||
911 | // Loads the char to the left of the current position and advances (leftward) | ||
912 | internal void Leftcharnext() | ||
913 | { | ||
914 | Ldloc(_textV); | ||
915 | Ldloc(_textposV); | ||
916 | Ldc(1); | ||
917 | Sub(); | ||
918 | Dup(); | ||
919 | Stloc(_textposV); | ||
920 | Callvirt(_getcharM); | ||
921 | } | ||
922 | |||
923 | // Creates a backtrack note and pushes the switch index it on the tracking stack | ||
924 | internal void Track() | ||
925 | { | ||
926 | ReadyPushTrack(); | ||
927 | Ldc(AddTrack()); | ||
928 | DoPush(); | ||
929 | } | ||
930 | |||
931 | // Pushes the current switch index on the tracking stack so the backtracking | ||
932 | // logic will be repeated again next time we backtrack here. | ||
933 | // | ||
934 | internal void Trackagain() | ||
935 | { | ||
936 | ReadyPushTrack(); | ||
937 | Ldc(_backpos); | ||
938 | DoPush(); | ||
939 | } | ||
940 | |||
941 | // Saves the value of a local variable on the tracking stack | ||
942 | internal void PushTrack(LocalBuilder lt) | ||
943 | { | ||
944 | ReadyPushTrack(); | ||
945 | Ldloc(lt); | ||
946 | DoPush(); | ||
947 | } | ||
948 | |||
949 | // Creates a backtrack note for a piece of code that should only be generated once, | ||
950 | // and emits code that pushes the switch index on the backtracking stack. | ||
951 | internal void TrackUnique(int i) | ||
952 | { | ||
953 | ReadyPushTrack(); | ||
954 | Ldc(AddUniqueTrack(i)); | ||
955 | DoPush(); | ||
956 | } | ||
957 | |||
958 | // Creates a second-backtrack note for a piece of code that should only be | ||
959 | // generated once, and emits code that pushes the switch index on the | ||
960 | // backtracking stack. | ||
961 | internal void TrackUnique2(int i) | ||
962 | { | ||
963 | ReadyPushTrack(); | ||
964 | Ldc(AddUniqueTrack(i, RegexCode.Back2)); | ||
965 | DoPush(); | ||
966 | } | ||
967 | |||
968 | // Prologue to code that will push an element on the tracking stack | ||
969 | internal void ReadyPushTrack() | ||
970 | { | ||
971 | _ilg.Emit(OpCodes.Ldloc_S, _trackV); | ||
972 | _ilg.Emit(OpCodes.Ldloc_S, _trackposV); | ||
973 | _ilg.Emit(OpCodes.Ldc_I4_1); | ||
974 | _ilg.Emit(OpCodes.Sub); | ||
975 | _ilg.Emit(OpCodes.Dup); | ||
976 | _ilg.Emit(OpCodes.Stloc_S, _trackposV); | ||
977 | } | ||
978 | |||
979 | // Pops an element off the tracking stack (leave it on the operand stack) | ||
980 | internal void PopTrack() | ||
981 | { | ||
982 | _ilg.Emit(OpCodes.Ldloc_S, _trackV); | ||
983 | _ilg.Emit(OpCodes.Ldloc_S, _trackposV); | ||
984 | _ilg.Emit(OpCodes.Dup); | ||
985 | _ilg.Emit(OpCodes.Ldc_I4_1); | ||
986 | _ilg.Emit(OpCodes.Add); | ||
987 | _ilg.Emit(OpCodes.Stloc_S, _trackposV); | ||
988 | _ilg.Emit(OpCodes.Ldelem_I4); | ||
989 | } | ||
990 | |||
991 | // Retrieves the top entry on the tracking stack without popping | ||
992 | internal void TopTrack() | ||
993 | { | ||
994 | _ilg.Emit(OpCodes.Ldloc_S, _trackV); | ||
995 | _ilg.Emit(OpCodes.Ldloc_S, _trackposV); | ||
996 | _ilg.Emit(OpCodes.Ldelem_I4); | ||
997 | } | ||
998 | |||
999 | // Saves the value of a local variable on the grouping stack | ||
1000 | internal void PushStack(LocalBuilder lt) | ||
1001 | { | ||
1002 | ReadyPushStack(); | ||
1003 | _ilg.Emit(OpCodes.Ldloc_S, lt); | ||
1004 | DoPush(); | ||
1005 | } | ||
1006 | |||
1007 | // Prologue to code that will replace the ith element on the grouping stack | ||
1008 | internal void ReadyReplaceStack(int i) | ||
1009 | { | ||
1010 | _ilg.Emit(OpCodes.Ldloc_S, _stackV); | ||
1011 | _ilg.Emit(OpCodes.Ldloc_S, _stackposV); | ||
1012 | if (i != 0) | ||
1013 | { | ||
1014 | Ldc(i); | ||
1015 | _ilg.Emit(OpCodes.Add); | ||
1016 | } | ||
1017 | } | ||
1018 | |||
1019 | // Prologue to code that will push an element on the grouping stack | ||
1020 | internal void ReadyPushStack() | ||
1021 | { | ||
1022 | _ilg.Emit(OpCodes.Ldloc_S, _stackV); | ||
1023 | _ilg.Emit(OpCodes.Ldloc_S, _stackposV); | ||
1024 | _ilg.Emit(OpCodes.Ldc_I4_1); | ||
1025 | _ilg.Emit(OpCodes.Sub); | ||
1026 | _ilg.Emit(OpCodes.Dup); | ||
1027 | _ilg.Emit(OpCodes.Stloc_S, _stackposV); | ||
1028 | } | ||
1029 | |||
1030 | // Retrieves the top entry on the stack without popping | ||
1031 | internal void TopStack() | ||
1032 | { | ||
1033 | _ilg.Emit(OpCodes.Ldloc_S, _stackV); | ||
1034 | _ilg.Emit(OpCodes.Ldloc_S, _stackposV); | ||
1035 | _ilg.Emit(OpCodes.Ldelem_I4); | ||
1036 | } | ||
1037 | |||
1038 | // Pops an element off the grouping stack (leave it on the operand stack) | ||
1039 | internal void PopStack() | ||
1040 | { | ||
1041 | _ilg.Emit(OpCodes.Ldloc_S, _stackV); | ||
1042 | _ilg.Emit(OpCodes.Ldloc_S, _stackposV); | ||
1043 | _ilg.Emit(OpCodes.Dup); | ||
1044 | _ilg.Emit(OpCodes.Ldc_I4_1); | ||
1045 | _ilg.Emit(OpCodes.Add); | ||
1046 | _ilg.Emit(OpCodes.Stloc_S, _stackposV); | ||
1047 | _ilg.Emit(OpCodes.Ldelem_I4); | ||
1048 | } | ||
1049 | |||
1050 | // Pops 1 element off the grouping stack and discards it | ||
1051 | internal void PopDiscardStack() | ||
1052 | { | ||
1053 | PopDiscardStack(1); | ||
1054 | } | ||
1055 | |||
1056 | // Pops i elements off the grouping stack and discards them | ||
1057 | internal void PopDiscardStack(int i) | ||
1058 | { | ||
1059 | _ilg.Emit(OpCodes.Ldloc_S, _stackposV); | ||
1060 | Ldc(i); | ||
1061 | _ilg.Emit(OpCodes.Add); | ||
1062 | _ilg.Emit(OpCodes.Stloc_S, _stackposV); | ||
1063 | } | ||
1064 | |||
1065 | // Epilogue to code that will replace an element on a stack (use Ld* in between) | ||
1066 | internal void DoReplace() | ||
1067 | { | ||
1068 | _ilg.Emit(OpCodes.Stelem_I4); | ||
1069 | } | ||
1070 | |||
1071 | // Epilogue to code that will push an element on a stack (use Ld* in between) | ||
1072 | internal void DoPush() | ||
1073 | { | ||
1074 | _ilg.Emit(OpCodes.Stelem_I4); | ||
1075 | } | ||
1076 | |||
1077 | // Jump to the backtracking switch | ||
1078 | internal void Back() | ||
1079 | { | ||
1080 | _ilg.Emit(OpCodes.Br, _backtrack); | ||
1081 | } | ||
1082 | |||
1083 | // Branch to the MSIL corresponding to the regex code at i | ||
1084 | // | ||
1085 | // A trick: since track and stack space is gobbled up unboundedly | ||
1086 | // only as a result of branching backwards, this is where we check | ||
1087 | // for sufficient space and trigger reallocations. | ||
1088 | // | ||
1089 | // If the "goto" is backwards, we generate code that checks | ||
1090 | // available space against the amount of space that would be needed | ||
1091 | // in the worst case by code that will only go forward; if there's | ||
1092 | // not enough, we push the destination on the tracking stack, then | ||
1093 | // we jump to the place where we invoke the allocator. | ||
1094 | // | ||
1095 | // Since forward gotos pose no threat, they just turn into a Br. | ||
1096 | internal void Goto(int i) | ||
1097 | { | ||
1098 | if (i < _codepos) | ||
1099 | { | ||
1100 | Label l1 = DefineLabel(); | ||
1101 | |||
1102 | // When going backwards, ensure enough space. | ||
1103 | Ldloc(_trackposV); | ||
1104 | Ldc(_trackcount * 4); | ||
1105 | Ble(l1); | ||
1106 | Ldloc(_stackposV); | ||
1107 | Ldc(_trackcount * 3); | ||
1108 | BgtFar(_labels[i]); | ||
1109 | MarkLabel(l1); | ||
1110 | ReadyPushTrack(); | ||
1111 | Ldc(AddGoto(i)); | ||
1112 | DoPush(); | ||
1113 | BrFar(_backtrack); | ||
1114 | } | ||
1115 | else | ||
1116 | { | ||
1117 | BrFar(_labels[i]); | ||
1118 | } | ||
1119 | } | ||
1120 | |||
1121 | // Returns the position of the next operation in the regex code, taking | ||
1122 | // into account the different numbers of arguments taken by operations | ||
1123 | internal int NextCodepos() | ||
1124 | { | ||
1125 | return _codepos + RegexCode.OpcodeSize(_codes[_codepos]); | ||
1126 | } | ||
1127 | |||
1128 | // The label for the next (forward) operation | ||
1129 | internal Label AdvanceLabel() | ||
1130 | { | ||
1131 | return _labels[NextCodepos()]; | ||
1132 | } | ||
1133 | |||
1134 | // Goto the next (forward) operation | ||
1135 | internal void Advance() | ||
1136 | { | ||
1137 | _ilg.Emit(OpCodes.Br, AdvanceLabel()); | ||
1138 | } | ||
1139 | |||
1140 | internal void CallToLower() | ||
1141 | { | ||
1142 | if ((_options & RegexOptions.CultureInvariant) != 0) | ||
1143 | Call(_getInvariantCulture); | ||
1144 | else | ||
1145 | Call(_getCurrentCulture); | ||
1146 | |||
1147 | Call(_chartolowerM); | ||
1148 | } | ||
1149 | |||
1150 | // Generates the first section of the MSIL. This section contains all | ||
1151 | // the forward logic, and corresponds directly to the regex codes. | ||
1152 | // | ||
1153 | // In the absence of backtracking, this is all we would need. | ||
1154 | internal void GenerateForwardSection() | ||
1155 | { | ||
1156 | int codepos; | ||
1157 | |||
1158 | _labels = new Label[_codes.Length]; | ||
1159 | _goto = new int[_codes.Length]; | ||
1160 | |||
1161 | // initialize | ||
1162 | |||
1163 | for (codepos = 0; codepos < _codes.Length; codepos += RegexCode.OpcodeSize(_codes[codepos])) | ||
1164 | { | ||
1165 | _goto[codepos] = -1; | ||
1166 | _labels[codepos] = _ilg.DefineLabel(); | ||
1167 | } | ||
1168 | |||
1169 | _uniquenote = new int[uniquecount]; | ||
1170 | for (int i = 0; i < uniquecount; i++) | ||
1171 | _uniquenote[i] = -1; | ||
1172 | |||
1173 | // emit variable initializers | ||
1174 | |||
1175 | Mvfldloc(_textF, _textV); | ||
1176 | Mvfldloc(_textstartF, _textstartV); | ||
1177 | Mvfldloc(_textbegF, _textbegV); | ||
1178 | Mvfldloc(_textendF, _textendV); | ||
1179 | Mvfldloc(_textposF, _textposV); | ||
1180 | Mvfldloc(_trackF, _trackV); | ||
1181 | Mvfldloc(_trackposF, _trackposV); | ||
1182 | Mvfldloc(_stackF, _stackV); | ||
1183 | Mvfldloc(_stackposF, _stackposV); | ||
1184 | |||
1185 | _backpos = -1; | ||
1186 | |||
1187 | for (codepos = 0; codepos < _codes.Length; codepos += RegexCode.OpcodeSize(_codes[codepos])) | ||
1188 | { | ||
1189 | MarkLabel(_labels[codepos]); | ||
1190 | _codepos = codepos; | ||
1191 | _regexopcode = _codes[codepos]; | ||
1192 | GenerateOneCode(); | ||
1193 | } | ||
1194 | } | ||
1195 | |||
1196 | // Generates the middle section of the MSIL. This section contains the | ||
1197 | // big switch jump that allows us to simulate a stack of addresses, | ||
1198 | // and it also contains the calls that expand the tracking and the | ||
1199 | // grouping stack when they get too full. | ||
1200 | internal void GenerateMiddleSection() | ||
1201 | { | ||
1202 | Label l1 = DefineLabel(); | ||
1203 | Label[] table; | ||
1204 | int i; | ||
1205 | |||
1206 | // Backtrack switch | ||
1207 | MarkLabel(_backtrack); | ||
1208 | |||
1209 | // first call EnsureStorage | ||
1210 | Mvlocfld(_trackposV, _trackposF); | ||
1211 | Mvlocfld(_stackposV, _stackposF); | ||
1212 | Ldthis(); | ||
1213 | Callvirt(_ensurestorageM); | ||
1214 | Mvfldloc(_trackposF, _trackposV); | ||
1215 | Mvfldloc(_stackposF, _stackposV); | ||
1216 | Mvfldloc(_trackF, _trackV); | ||
1217 | Mvfldloc(_stackF, _stackV); | ||
1218 | |||
1219 | |||
1220 | PopTrack(); | ||
1221 | |||
1222 | table = new Label[_notecount]; | ||
1223 | for (i = 0; i < _notecount; i++) | ||
1224 | table[i] = _notes[i]._label; | ||
1225 | |||
1226 | _ilg.Emit(OpCodes.Switch, table); | ||
1227 | |||
1228 | } | ||
1229 | |||
1230 | // Generates the last section of the MSIL. This section contains all of | ||
1231 | // the backtracking logic. | ||
1232 | internal void GenerateBacktrackSection() | ||
1233 | { | ||
1234 | int i; | ||
1235 | |||
1236 | for (i = 0; i < _notecount; i++) | ||
1237 | { | ||
1238 | BacktrackNote n = _notes[i]; | ||
1239 | if (n._flags != 0) | ||
1240 | { | ||
1241 | _ilg.MarkLabel(n._label); | ||
1242 | _codepos = n._codepos; | ||
1243 | _backpos = i; | ||
1244 | _regexopcode = _codes[n._codepos] | n._flags; | ||
1245 | GenerateOneCode(); | ||
1246 | } | ||
1247 | } | ||
1248 | } | ||
1249 | |||
1250 | // Generates FindFirstChar | ||
1251 | internal void GenerateFindFirstChar() | ||
1252 | { | ||
1253 | _textposV = DeclareInt(); | ||
1254 | _textV = DeclareString(); | ||
1255 | _tempV = DeclareInt(); | ||
1256 | _temp2V = DeclareInt(); | ||
1257 | |||
1258 | if (0 != (_anchors & (RegexFCD.Beginning | RegexFCD.Start | RegexFCD.EndZ | RegexFCD.End))) | ||
1259 | { | ||
1260 | if (!_code._rightToLeft) | ||
1261 | { | ||
1262 | if (0 != (_anchors & RegexFCD.Beginning)) | ||
1263 | { | ||
1264 | Label l1 = DefineLabel(); | ||
1265 | Ldthisfld(_textposF); | ||
1266 | Ldthisfld(_textbegF); | ||
1267 | Ble(l1); | ||
1268 | Ldthis(); | ||
1269 | Ldthisfld(_textendF); | ||
1270 | Stfld(_textposF); | ||
1271 | Ldc(0); | ||
1272 | Ret(); | ||
1273 | MarkLabel(l1); | ||
1274 | } | ||
1275 | |||
1276 | if (0 != (_anchors & RegexFCD.Start)) | ||
1277 | { | ||
1278 | Label l1 = DefineLabel(); | ||
1279 | Ldthisfld(_textposF); | ||
1280 | Ldthisfld(_textstartF); | ||
1281 | Ble(l1); | ||
1282 | Ldthis(); | ||
1283 | Ldthisfld(_textendF); | ||
1284 | Stfld(_textposF); | ||
1285 | Ldc(0); | ||
1286 | Ret(); | ||
1287 | MarkLabel(l1); | ||
1288 | } | ||
1289 | |||
1290 | if (0 != (_anchors & RegexFCD.EndZ)) | ||
1291 | { | ||
1292 | Label l1 = DefineLabel(); | ||
1293 | Ldthisfld(_textposF); | ||
1294 | Ldthisfld(_textendF); | ||
1295 | Ldc(1); | ||
1296 | Sub(); | ||
1297 | Bge(l1); | ||
1298 | Ldthis(); | ||
1299 | Ldthisfld(_textendF); | ||
1300 | Ldc(1); | ||
1301 | Sub(); | ||
1302 | Stfld(_textposF); | ||
1303 | MarkLabel(l1); | ||
1304 | } | ||
1305 | |||
1306 | if (0 != (_anchors & RegexFCD.End)) | ||
1307 | { | ||
1308 | Label l1 = DefineLabel(); | ||
1309 | Ldthisfld(_textposF); | ||
1310 | Ldthisfld(_textendF); | ||
1311 | Bge(l1); | ||
1312 | Ldthis(); | ||
1313 | Ldthisfld(_textendF); | ||
1314 | Stfld(_textposF); | ||
1315 | MarkLabel(l1); | ||
1316 | } | ||
1317 | } | ||
1318 | else | ||
1319 | { | ||
1320 | if (0 != (_anchors & RegexFCD.End)) | ||
1321 | { | ||
1322 | Label l1 = DefineLabel(); | ||
1323 | Ldthisfld(_textposF); | ||
1324 | Ldthisfld(_textendF); | ||
1325 | Bge(l1); | ||
1326 | Ldthis(); | ||
1327 | Ldthisfld(_textbegF); | ||
1328 | Stfld(_textposF); | ||
1329 | Ldc(0); | ||
1330 | Ret(); | ||
1331 | MarkLabel(l1); | ||
1332 | } | ||
1333 | |||
1334 | if (0 != (_anchors & RegexFCD.EndZ)) | ||
1335 | { | ||
1336 | Label l1 = DefineLabel(); | ||
1337 | Label l2 = DefineLabel(); | ||
1338 | Ldthisfld(_textposF); | ||
1339 | Ldthisfld(_textendF); | ||
1340 | Ldc(1); | ||
1341 | Sub(); | ||
1342 | Blt(l1); | ||
1343 | Ldthisfld(_textposF); | ||
1344 | Ldthisfld(_textendF); | ||
1345 | Beq(l2); | ||
1346 | Ldthisfld(_textF); | ||
1347 | Ldthisfld(_textposF); | ||
1348 | Callvirt(_getcharM); | ||
1349 | Ldc((int)'\n'); | ||
1350 | Beq(l2); | ||
1351 | MarkLabel(l1); | ||
1352 | Ldthis(); | ||
1353 | Ldthisfld(_textbegF); | ||
1354 | Stfld(_textposF); | ||
1355 | Ldc(0); | ||
1356 | Ret(); | ||
1357 | MarkLabel(l2); | ||
1358 | } | ||
1359 | |||
1360 | if (0 != (_anchors & RegexFCD.Start)) | ||
1361 | { | ||
1362 | Label l1 = DefineLabel(); | ||
1363 | Ldthisfld(_textposF); | ||
1364 | Ldthisfld(_textstartF); | ||
1365 | Bge(l1); | ||
1366 | Ldthis(); | ||
1367 | Ldthisfld(_textbegF); | ||
1368 | Stfld(_textposF); | ||
1369 | Ldc(0); | ||
1370 | Ret(); | ||
1371 | MarkLabel(l1); | ||
1372 | } | ||
1373 | |||
1374 | if (0 != (_anchors & RegexFCD.Beginning)) | ||
1375 | { | ||
1376 | Label l1 = DefineLabel(); | ||
1377 | Ldthisfld(_textposF); | ||
1378 | Ldthisfld(_textbegF); | ||
1379 | Ble(l1); | ||
1380 | Ldthis(); | ||
1381 | Ldthisfld(_textbegF); | ||
1382 | Stfld(_textposF); | ||
1383 | MarkLabel(l1); | ||
1384 | } | ||
1385 | } | ||
1386 | |||
1387 | |||
1388 | Ldc(1); | ||
1389 | Ret(); | ||
1390 | } | ||
1391 | else if (_bmPrefix != null && _bmPrefix._negativeUnicode == null) | ||
1392 | { | ||
1393 | // Compiled Boyer-Moore string matching | ||
1394 | |||
1395 | LocalBuilder chV = _tempV; | ||
1396 | LocalBuilder testV = _tempV; | ||
1397 | LocalBuilder limitV = _temp2V; | ||
1398 | Label lDefaultAdvance = DefineLabel(); | ||
1399 | Label lAdvance = DefineLabel(); | ||
1400 | Label lFail = DefineLabel(); | ||
1401 | Label lStart = DefineLabel(); | ||
1402 | Label lOutOfRange = DefineLabel(); | ||
1403 | Label lPartialMatch = DefineLabel(); | ||
1404 | |||
1405 | |||
1406 | int chLast; | ||
1407 | int i; | ||
1408 | int beforefirst; | ||
1409 | int last; | ||
1410 | Label[] table; | ||
1411 | |||
1412 | if (!_code._rightToLeft) | ||
1413 | { | ||
1414 | beforefirst = -1; | ||
1415 | last = _bmPrefix._pattern.Length - 1; | ||
1416 | } | ||
1417 | else | ||
1418 | { | ||
1419 | beforefirst = _bmPrefix._pattern.Length; | ||
1420 | last = 0; | ||
1421 | } | ||
1422 | |||
1423 | chLast = _bmPrefix._pattern[last]; | ||
1424 | |||
1425 | Mvfldloc(_textF, _textV); | ||
1426 | if (!_code._rightToLeft) | ||
1427 | Ldthisfld(_textendF); | ||
1428 | else | ||
1429 | Ldthisfld(_textbegF); | ||
1430 | Stloc(limitV); | ||
1431 | |||
1432 | Ldthisfld(_textposF); | ||
1433 | if (!_code._rightToLeft) | ||
1434 | { | ||
1435 | Ldc(_bmPrefix._pattern.Length - 1); | ||
1436 | Add(); | ||
1437 | } | ||
1438 | else | ||
1439 | { | ||
1440 | Ldc(_bmPrefix._pattern.Length); | ||
1441 | Sub(); | ||
1442 | } | ||
1443 | Stloc(_textposV); | ||
1444 | Br(lStart); | ||
1445 | |||
1446 | MarkLabel(lDefaultAdvance); | ||
1447 | |||
1448 | if (!_code._rightToLeft) | ||
1449 | Ldc(_bmPrefix._pattern.Length); | ||
1450 | else | ||
1451 | Ldc(-_bmPrefix._pattern.Length); | ||
1452 | |||
1453 | MarkLabel(lAdvance); | ||
1454 | |||
1455 | Ldloc(_textposV); | ||
1456 | Add(); | ||
1457 | Stloc(_textposV); | ||
1458 | |||
1459 | MarkLabel(lStart); | ||
1460 | |||
1461 | Ldloc(_textposV); | ||
1462 | Ldloc(limitV); | ||
1463 | if (!_code._rightToLeft) | ||
1464 | BgeFar(lFail); | ||
1465 | else | ||
1466 | BltFar(lFail); | ||
1467 | |||
1468 | Rightchar(); | ||
1469 | if (_bmPrefix._caseInsensitive) | ||
1470 | CallToLower(); | ||
1471 | |||
1472 | Dup(); | ||
1473 | Stloc(chV); | ||
1474 | Ldc(chLast); | ||
1475 | BeqFar(lPartialMatch); | ||
1476 | |||
1477 | Ldloc(chV); | ||
1478 | Ldc(_bmPrefix._lowASCII); | ||
1479 | Sub(); | ||
1480 | Dup(); | ||
1481 | Stloc(chV); | ||
1482 | Ldc(_bmPrefix._highASCII - _bmPrefix._lowASCII); | ||
1483 | Bgtun(lDefaultAdvance); | ||
1484 | |||
1485 | table = new Label[_bmPrefix._highASCII - _bmPrefix._lowASCII + 1]; | ||
1486 | |||
1487 | for (i = _bmPrefix._lowASCII; i <= _bmPrefix._highASCII; i++) | ||
1488 | { | ||
1489 | if (_bmPrefix._negativeASCII[i] == beforefirst) | ||
1490 | table[i - _bmPrefix._lowASCII] = lDefaultAdvance; | ||
1491 | else | ||
1492 | table[i - _bmPrefix._lowASCII] = DefineLabel(); | ||
1493 | } | ||
1494 | |||
1495 | Ldloc(chV); | ||
1496 | _ilg.Emit(OpCodes.Switch, table); | ||
1497 | |||
1498 | for (i = _bmPrefix._lowASCII; i <= _bmPrefix._highASCII; i++) | ||
1499 | { | ||
1500 | if (_bmPrefix._negativeASCII[i] == beforefirst) | ||
1501 | continue; | ||
1502 | |||
1503 | MarkLabel(table[i - _bmPrefix._lowASCII]); | ||
1504 | |||
1505 | Ldc(_bmPrefix._negativeASCII[i]); | ||
1506 | BrFar(lAdvance); | ||
1507 | } | ||
1508 | |||
1509 | MarkLabel(lPartialMatch); | ||
1510 | |||
1511 | Ldloc(_textposV); | ||
1512 | Stloc(testV); | ||
1513 | |||
1514 | for (i = _bmPrefix._pattern.Length - 2; i >= 0; i--) | ||
1515 | { | ||
1516 | Label lNext = DefineLabel(); | ||
1517 | int charindex; | ||
1518 | |||
1519 | if (!_code._rightToLeft) | ||
1520 | charindex = i; | ||
1521 | else | ||
1522 | charindex = _bmPrefix._pattern.Length - 1 - i; | ||
1523 | |||
1524 | Ldloc(_textV); | ||
1525 | Ldloc(testV); | ||
1526 | Ldc(1); | ||
1527 | Sub(_code._rightToLeft); | ||
1528 | Dup(); | ||
1529 | Stloc(testV); | ||
1530 | Callvirt(_getcharM); | ||
1531 | if (_bmPrefix._caseInsensitive) | ||
1532 | CallToLower(); | ||
1533 | |||
1534 | Ldc(_bmPrefix._pattern[charindex]); | ||
1535 | Beq(lNext); | ||
1536 | Ldc(_bmPrefix._positive[charindex]); | ||
1537 | BrFar(lAdvance); | ||
1538 | |||
1539 | MarkLabel(lNext); | ||
1540 | |||
1541 | } | ||
1542 | |||
1543 | Ldthis(); | ||
1544 | Ldloc(testV); | ||
1545 | if (_code._rightToLeft) | ||
1546 | { | ||
1547 | Ldc(1); | ||
1548 | Add(); | ||
1549 | } | ||
1550 | Stfld(_textposF); | ||
1551 | Ldc(1); | ||
1552 | Ret(); | ||
1553 | |||
1554 | MarkLabel(lFail); | ||
1555 | |||
1556 | Ldthis(); | ||
1557 | if (!_code._rightToLeft) | ||
1558 | Ldthisfld(_textendF); | ||
1559 | else | ||
1560 | Ldthisfld(_textbegF); | ||
1561 | Stfld(_textposF); | ||
1562 | Ldc(0); | ||
1563 | Ret(); | ||
1564 | } | ||
1565 | else if (_fcPrefix == null) | ||
1566 | { | ||
1567 | Ldc(1); | ||
1568 | Ret(); | ||
1569 | } | ||
1570 | else | ||
1571 | { | ||
1572 | LocalBuilder cV = _temp2V; | ||
1573 | LocalBuilder chV = _tempV; | ||
1574 | Label l1 = DefineLabel(); | ||
1575 | Label l2 = DefineLabel(); | ||
1576 | Label l3 = DefineLabel(); | ||
1577 | Label l4 = DefineLabel(); | ||
1578 | Label l5 = DefineLabel(); | ||
1579 | |||
1580 | Mvfldloc(_textposF, _textposV); | ||
1581 | Mvfldloc(_textF, _textV); | ||
1582 | |||
1583 | if (!_code._rightToLeft) | ||
1584 | { | ||
1585 | Ldthisfld(_textendF); | ||
1586 | Ldloc(_textposV); | ||
1587 | } | ||
1588 | else | ||
1589 | { | ||
1590 | Ldloc(_textposV); | ||
1591 | Ldthisfld(_textbegF); | ||
1592 | } | ||
1593 | Sub(); | ||
1594 | Stloc(cV); | ||
1595 | |||
1596 | Ldloc(cV); | ||
1597 | Ldc(0); | ||
1598 | BleFar(l4); | ||
1599 | |||
1600 | MarkLabel(l1); | ||
1601 | |||
1602 | Ldloc(cV); | ||
1603 | Ldc(1); | ||
1604 | Sub(); | ||
1605 | Stloc(cV); | ||
1606 | |||
1607 | if (_code._rightToLeft) | ||
1608 | Leftcharnext(); | ||
1609 | else | ||
1610 | Rightcharnext(); | ||
1611 | |||
1612 | if (_fcPrefix.CaseInsensitive) | ||
1613 | CallToLower(); | ||
1614 | |||
1615 | if (!RegexCharClass.IsSingleton(_fcPrefix.Prefix)) | ||
1616 | { | ||
1617 | Ldstr(_fcPrefix.Prefix); | ||
1618 | Ldstr(String.Empty); | ||
1619 | Call(_charInSetM); | ||
1620 | |||
1621 | BrtrueFar(l2); | ||
1622 | } | ||
1623 | else | ||
1624 | { | ||
1625 | Ldc(RegexCharClass.SingletonChar(_fcPrefix.Prefix)); | ||
1626 | Beq(l2); | ||
1627 | } | ||
1628 | |||
1629 | MarkLabel(l5); | ||
1630 | |||
1631 | Ldloc(cV); | ||
1632 | Ldc(0); | ||
1633 | if (!RegexCharClass.IsSingleton(_fcPrefix.Prefix)) | ||
1634 | BgtFar(l1); | ||
1635 | else | ||
1636 | Bgt(l1); | ||
1637 | |||
1638 | Ldc(0); | ||
1639 | BrFar(l3); | ||
1640 | |||
1641 | MarkLabel(l2); | ||
1642 | |||
1643 | /* // CURRENTLY DISABLED | ||
1644 | // If for some reason we have a prefix we didn't use, use it now. | ||
1645 | |||
1646 | if (_bmPrefix != null) { | ||
1647 | if (!_code._rightToLeft) { | ||
1648 | Ldthisfld(_textendF); | ||
1649 | Ldloc(_textposV); | ||
1650 | } | ||
1651 | else { | ||
1652 | Ldloc(_textposV); | ||
1653 | Ldthisfld(_textbegF); | ||
1654 | } | ||
1655 | Sub(); | ||
1656 | Ldc(_bmPrefix._pattern.Length - 1); | ||
1657 | BltFar(l5); | ||
1658 | |||
1659 | for (int i = 1; i < _bmPrefix._pattern.Length; i++) { | ||
1660 | Ldloc(_textV); | ||
1661 | Ldloc(_textposV); | ||
1662 | if (!_code._rightToLeft) { | ||
1663 | Ldc(i - 1); | ||
1664 | Add(); | ||
1665 | } | ||
1666 | else { | ||
1667 | Ldc(i); | ||
1668 | Sub(); | ||
1669 | } | ||
1670 | Callvirt(_getcharM); | ||
1671 | if (!_code._rightToLeft) | ||
1672 | Ldc(_bmPrefix._pattern[i]); | ||
1673 | else | ||
1674 | Ldc(_bmPrefix._pattern[_bmPrefix._pattern.Length - 1 - i]); | ||
1675 | BneFar(l5); | ||
1676 | } | ||
1677 | } | ||
1678 | */ | ||
1679 | |||
1680 | Ldloc(_textposV); | ||
1681 | Ldc(1); | ||
1682 | Sub(_code._rightToLeft); | ||
1683 | Stloc(_textposV); | ||
1684 | Ldc(1); | ||
1685 | |||
1686 | MarkLabel(l3); | ||
1687 | |||
1688 | Mvlocfld(_textposV, _textposF); | ||
1689 | Ret(); | ||
1690 | |||
1691 | MarkLabel(l4); | ||
1692 | Ldc(0); | ||
1693 | Ret(); | ||
1694 | } | ||
1695 | |||
1696 | } | ||
1697 | |||
1698 | // Generates a very simple method that sets the _trackcount field. | ||
1699 | internal void GenerateInitTrackCount() | ||
1700 | { | ||
1701 | Ldthis(); | ||
1702 | Ldc(_trackcount); | ||
1703 | Stfld(_trackcountF); | ||
1704 | Ret(); | ||
1705 | } | ||
1706 | |||
1707 | // Generates a very simple factory method. | ||
1708 | internal void GenerateCreateInstance(Type newtype) | ||
1709 | { | ||
1710 | Newobj(newtype.GetConstructor(new Type[0])); | ||
1711 | Ret(); | ||
1712 | } | ||
1713 | |||
1714 | // Gets the unique-for-regex dynamic module for this thread | ||
1715 | internal static RegexCompiler GetThreadCompiler() | ||
1716 | { | ||
1717 | RegexCompiler compiler = (RegexCompiler)Thread.GetData(_moduleSlot); | ||
1718 | |||
1719 | if (compiler == null) | ||
1720 | { | ||
1721 | int moduleNum; | ||
1722 | |||
1723 | lock (_syncObject) | ||
1724 | { | ||
1725 | moduleNum = _moduleCount++; | ||
1726 | } | ||
1727 | |||
1728 | compiler = new RegexCompiler(moduleNum); | ||
1729 | Thread.SetData(_moduleSlot, compiler); | ||
1730 | } | ||
1731 | |||
1732 | return compiler; | ||
1733 | } | ||
1734 | |||
1735 | // Begins the definition of a new type with a specified base class | ||
1736 | internal void DefineType(String typename, bool ispublic, Type inheritfromclass) | ||
1737 | { | ||
1738 | if (ispublic) | ||
1739 | _typebuilder = _module.DefineType(typename, TypeAttributes.Class | TypeAttributes.Public, inheritfromclass); | ||
1740 | else | ||
1741 | _typebuilder = _module.DefineType(typename, TypeAttributes.Class | TypeAttributes.NotPublic, inheritfromclass); | ||
1742 | |||
1743 | } | ||
1744 | |||
1745 | // Begins the definition of a new method (no args) with a specified return value | ||
1746 | internal void DefineMethod(String methname, Type returntype) | ||
1747 | { | ||
1748 | MethodAttributes ma = System.Reflection.MethodAttributes.Public | System.Reflection.MethodAttributes.Virtual; | ||
1749 | |||
1750 | _methbuilder = _typebuilder.DefineMethod(methname, ma, returntype, null); | ||
1751 | _ilg = _methbuilder.GetILGenerator(); | ||
1752 | } | ||
1753 | |||
1754 | // Ends the definition of a method | ||
1755 | internal void BakeMethod() | ||
1756 | { | ||
1757 | _methbuilder = null; | ||
1758 | } | ||
1759 | |||
1760 | // Ends the definition of a class and returns the type | ||
1761 | internal Type BakeType() | ||
1762 | { | ||
1763 | Type retval = _typebuilder.CreateType(); | ||
1764 | _typebuilder = null; | ||
1765 | |||
1766 | return retval; | ||
1767 | } | ||
1768 | |||
1769 | // Declares a local int | ||
1770 | internal LocalBuilder DeclareInt() | ||
1771 | { | ||
1772 | return _ilg.DeclareLocal(typeof(int)); | ||
1773 | } | ||
1774 | |||
1775 | // Declares a local int array | ||
1776 | internal LocalBuilder DeclareIntArray() | ||
1777 | { | ||
1778 | return _ilg.DeclareLocal(typeof(int[])); | ||
1779 | } | ||
1780 | |||
1781 | // Declares a local char array | ||
1782 | internal LocalBuilder DeclareCharArray() | ||
1783 | { | ||
1784 | return _ilg.DeclareLocal(typeof(char[])); | ||
1785 | } | ||
1786 | |||
1787 | // Declares a local string | ||
1788 | internal LocalBuilder DeclareString() | ||
1789 | { | ||
1790 | return _ilg.DeclareLocal(typeof(string)); | ||
1791 | } | ||
1792 | |||
1793 | // Generates the code for "RegexRunner.Go" | ||
1794 | internal void GenerateGo() | ||
1795 | { | ||
1796 | // declare some locals | ||
1797 | |||
1798 | _textposV = DeclareInt(); | ||
1799 | _textV = DeclareString(); | ||
1800 | _trackposV = DeclareInt(); | ||
1801 | _trackV = DeclareIntArray(); | ||
1802 | _stackposV = DeclareInt(); | ||
1803 | _stackV = DeclareIntArray(); | ||
1804 | _tempV = DeclareInt(); | ||
1805 | _temp2V = DeclareInt(); | ||
1806 | _temp3V = DeclareInt(); | ||
1807 | _textbegV = DeclareInt(); | ||
1808 | _textendV = DeclareInt(); | ||
1809 | _textstartV = DeclareInt(); | ||
1810 | |||
1811 | // clear some tables | ||
1812 | |||
1813 | _labels = null; | ||
1814 | _notes = null; | ||
1815 | _notecount = 0; | ||
1816 | |||
1817 | // globally used labels | ||
1818 | |||
1819 | _backtrack = DefineLabel(); | ||
1820 | |||
1821 | // emit the code! | ||
1822 | |||
1823 | GenerateForwardSection(); | ||
1824 | GenerateMiddleSection(); | ||
1825 | GenerateBacktrackSection(); | ||
1826 | } | ||
1827 | |||
1828 | #if DBG | ||
1829 | // Some simple debugging stuff | ||
1830 | internal static char[] Hex = new char[] {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; | ||
1831 | internal static MethodInfo _debugWriteLine = typeof(Debug).GetMethod("WriteLine", new Type[] {typeof(string)}); | ||
1832 | |||
1833 | internal static String BaDescription(byte[] ba) { | ||
1834 | StringBuilder sb = new StringBuilder(); | ||
1835 | |||
1836 | sb.Append("Length " + ba.Length.ToString() + "\n"); | ||
1837 | |||
1838 | for (int i = 0; i < ba.Length; i++) { | ||
1839 | sb.Append(Hex[ba[i] >> 4]); | ||
1840 | sb.Append(Hex[ba[i] & 0xF]); | ||
1841 | sb.Append(' '); | ||
1842 | } | ||
1843 | return sb.ToString(); | ||
1844 | } | ||
1845 | |||
1846 | // Debug only: emit code to print out a message | ||
1847 | internal void Message(String str) { | ||
1848 | Ldstr(str); | ||
1849 | Call(_debugWriteLine); | ||
1850 | } | ||
1851 | |||
1852 | #endif | ||
1853 | |||
1854 | // The main translation function. It translates the logic for a single opcode at | ||
1855 | // the current position. The structure of this function exactly mirrors | ||
1856 | // the structure of the inner loop of RegexInterpreter.Go(). | ||
1857 | // | ||
1858 | // The C# code from RegexInterpreter.Go() that corresponds to each case is | ||
1859 | // included as a comment. | ||
1860 | // | ||
1861 | // Note that since we're generating code, we can collapse many cases that are | ||
1862 | // dealt with one-at-a-time in RegexIntepreter. We can also unroll loops that | ||
1863 | // iterate over constant strings or sets. | ||
1864 | internal void GenerateOneCode() | ||
1865 | { | ||
1866 | #if DBG | ||
1867 | if ((_options & RegexOptions.Debug) != 0) { | ||
1868 | Mvlocfld(_textposV, _textposF); | ||
1869 | Mvlocfld(_trackposV, _trackposF); | ||
1870 | Mvlocfld(_stackposV, _stackposF); | ||
1871 | Ldthis(); | ||
1872 | Callvirt(_dumpstateM); | ||
1873 | StringBuilder sb = new StringBuilder(); | ||
1874 | if (_backpos > 0) | ||
1875 | sb.AppendFormat("{0:D6} ", _backpos); | ||
1876 | else | ||
1877 | sb.Append(" "); | ||
1878 | sb.Append(_code.OpcodeDescription(_codepos)); | ||
1879 | if (IsBack()) | ||
1880 | sb.Append(" Back"); | ||
1881 | if (IsBack2()) | ||
1882 | sb.Append(" Back2"); | ||
1883 | Message(sb.ToString()); | ||
1884 | } | ||
1885 | #endif | ||
1886 | |||
1887 | switch (_regexopcode) | ||
1888 | { | ||
1889 | case RegexCode.Stop: | ||
1890 | //: return; | ||
1891 | Mvlocfld(_textposV, _textposF); // update _textpos | ||
1892 | Ret(); | ||
1893 | break; | ||
1894 | |||
1895 | case RegexCode.Nothing: | ||
1896 | //: break Backward; | ||
1897 | Back(); | ||
1898 | break; | ||
1899 | |||
1900 | case RegexCode.Goto: | ||
1901 | //: Goto(Operand(0)); | ||
1902 | Goto(Operand(0)); | ||
1903 | break; | ||
1904 | |||
1905 | case RegexCode.Testref: | ||
1906 | //: if (!_match.IsMatched(Operand(0))) | ||
1907 | //: break Backward; | ||
1908 | Ldthis(); | ||
1909 | Ldc(Operand(0)); | ||
1910 | Callvirt(_ismatchedM); | ||
1911 | BrfalseFar(_backtrack); | ||
1912 | break; | ||
1913 | |||
1914 | case RegexCode.Lazybranch: | ||
1915 | //: Track(Textpos()); | ||
1916 | PushTrack(_textposV); | ||
1917 | Track(); | ||
1918 | break; | ||
1919 | |||
1920 | case RegexCode.Lazybranch | RegexCode.Back: | ||
1921 | //: Trackframe(1); | ||
1922 | //: Textto(Tracked(0)); | ||
1923 | //: Goto(Operand(0)); | ||
1924 | PopTrack(); | ||
1925 | Stloc(_textposV); | ||
1926 | Goto(Operand(0)); | ||
1927 | break; | ||
1928 | |||
1929 | case RegexCode.Nullmark: | ||
1930 | //: Stack(-1); | ||
1931 | //: Track(); | ||
1932 | ReadyPushStack(); | ||
1933 | Ldc(-1); | ||
1934 | DoPush(); | ||
1935 | TrackUnique(stackpop); | ||
1936 | break; | ||
1937 | |||
1938 | case RegexCode.Setmark: | ||
1939 | //: Stack(Textpos()); | ||
1940 | //: Track(); | ||
1941 | PushStack(_textposV); | ||
1942 | TrackUnique(stackpop); | ||
1943 | break; | ||
1944 | |||
1945 | case RegexCode.Nullmark | RegexCode.Back: | ||
1946 | case RegexCode.Setmark | RegexCode.Back: | ||
1947 | //: Stackframe(1); | ||
1948 | //: break Backward; | ||
1949 | PopDiscardStack(); | ||
1950 | Back(); | ||
1951 | break; | ||
1952 | |||
1953 | case RegexCode.Getmark: | ||
1954 | //: Stackframe(1); | ||
1955 | //: Track(Stacked(0)); | ||
1956 | //: Textto(Stacked(0)); | ||
1957 | ReadyPushTrack(); | ||
1958 | PopStack(); | ||
1959 | Dup(); | ||
1960 | Stloc(_textposV); | ||
1961 | DoPush(); | ||
1962 | |||
1963 | Track(); | ||
1964 | break; | ||
1965 | |||
1966 | case RegexCode.Getmark | RegexCode.Back: | ||
1967 | //: Trackframe(1); | ||
1968 | //: Stack(Tracked(0)); | ||
1969 | //: break Backward; | ||
1970 | ReadyPushStack(); | ||
1971 | PopTrack(); | ||
1972 | DoPush(); | ||
1973 | Back(); | ||
1974 | break; | ||
1975 | |||
1976 | case RegexCode.Capturemark: | ||
1977 | //: if (!IsMatched(Operand(1))) | ||
1978 | //: break Backward; | ||
1979 | //: Stackframe(1); | ||
1980 | //: if (Operand(1) != -1) | ||
1981 | //: TransferCapture(Operand(0), Operand(1), Stacked(0), Textpos()); | ||
1982 | //: else | ||
1983 | //: Capture(Operand(0), Stacked(0), Textpos()); | ||
1984 | //: Track(Stacked(0)); | ||
1985 | |||
1986 | //: Stackframe(1); | ||
1987 | //: Capture(Operand(0), Stacked(0), Textpos()); | ||
1988 | //: Track(Stacked(0)); | ||
1989 | |||
1990 | if (Operand(1) != -1) | ||
1991 | { | ||
1992 | Ldthis(); | ||
1993 | Ldc(Operand(1)); | ||
1994 | Callvirt(_ismatchedM); | ||
1995 | BrfalseFar(_backtrack); | ||
1996 | } | ||
1997 | |||
1998 | PopStack(); | ||
1999 | Stloc(_tempV); | ||
2000 | |||
2001 | if (Operand(1) != -1) | ||
2002 | { | ||
2003 | Ldthis(); | ||
2004 | Ldc(Operand(0)); | ||
2005 | Ldc(Operand(1)); | ||
2006 | Ldloc(_tempV); | ||
2007 | Ldloc(_textposV); | ||
2008 | Callvirt(_transferM); | ||
2009 | } | ||
2010 | else | ||
2011 | { | ||
2012 | Ldthis(); | ||
2013 | Ldc(Operand(0)); | ||
2014 | Ldloc(_tempV); | ||
2015 | Ldloc(_textposV); | ||
2016 | Callvirt(_captureM); | ||
2017 | } | ||
2018 | |||
2019 | PushTrack(_tempV); | ||
2020 | |||
2021 | if (Operand(0) != -1 && Operand(1) != -1) | ||
2022 | TrackUnique(capback2); | ||
2023 | else | ||
2024 | TrackUnique(capback); | ||
2025 | |||
2026 | break; | ||
2027 | |||
2028 | |||
2029 | case RegexCode.Capturemark | RegexCode.Back: | ||
2030 | //: Trackframe(1); | ||
2031 | //: Stack(Tracked(0)); | ||
2032 | //: Uncapture(); | ||
2033 | //: if (Operand(0) != -1 && Operand(1) != -1) | ||
2034 | //: Uncapture(); | ||
2035 | //: break Backward; | ||
2036 | ReadyPushStack(); | ||
2037 | PopTrack(); | ||
2038 | DoPush(); | ||
2039 | Ldthis(); | ||
2040 | Callvirt(_uncaptureM); | ||
2041 | if (Operand(0) != -1 && Operand(1) != -1) | ||
2042 | { | ||
2043 | Ldthis(); | ||
2044 | Callvirt(_uncaptureM); | ||
2045 | } | ||
2046 | Back(); | ||
2047 | break; | ||
2048 | |||
2049 | case RegexCode.Branchmark: | ||
2050 | //: Stackframe(1); | ||
2051 | //: | ||
2052 | //: if (Textpos() != Stacked(0)) | ||
2053 | //: { // Nonempty match -> loop now | ||
2054 | //: Track(Stacked(0), Textpos()); // Save old mark, textpos | ||
2055 | //: Stack(Textpos()); // Make new mark | ||
2056 | //: Goto(Operand(0)); // Loop | ||
2057 | //: } | ||
2058 | //: else | ||
2059 | //: { // Empty match -> straight now | ||
2060 | //: Track2(Stacked(0)); // Save old mark | ||
2061 | //: Advance(1); // Straight | ||
2062 | //: } | ||
2063 | //: continue Forward; | ||
2064 | { | ||
2065 | LocalBuilder mark = _tempV; | ||
2066 | Label l1 = DefineLabel(); | ||
2067 | |||
2068 | PopStack(); | ||
2069 | Dup(); | ||
2070 | Stloc(mark); // Stacked(0) -> temp | ||
2071 | PushTrack(mark); | ||
2072 | Ldloc(_textposV); | ||
2073 | Beq(l1); // mark == textpos -> branch | ||
2074 | |||
2075 | // (matched != 0) | ||
2076 | |||
2077 | PushTrack(_textposV); | ||
2078 | PushStack(_textposV); | ||
2079 | Track(); | ||
2080 | Goto(Operand(0)); // Goto(Operand(0)) | ||
2081 | |||
2082 | // else | ||
2083 | |||
2084 | MarkLabel(l1); | ||
2085 | TrackUnique2(branchmarkback2); | ||
2086 | break; | ||
2087 | } | ||
2088 | |||
2089 | case RegexCode.Branchmark | RegexCode.Back: | ||
2090 | //: Trackframe(2); | ||
2091 | //: Stackframe(1); | ||
2092 | //: Textto(Tracked(1)); // Recall position | ||
2093 | //: Track2(Tracked(0)); // Save old mark | ||
2094 | //: Advance(1); | ||
2095 | PopTrack(); | ||
2096 | Stloc(_textposV); | ||
2097 | PopStack(); | ||
2098 | Pop(); | ||
2099 | // track spot 0 is already in place | ||
2100 | TrackUnique2(branchmarkback2); | ||
2101 | Advance(); | ||
2102 | break; | ||
2103 | |||
2104 | case RegexCode.Branchmark | RegexCode.Back2: | ||
2105 | //: Trackframe(1); | ||
2106 | //: Stack(Tracked(0)); // Recall old mark | ||
2107 | //: break Backward; // Backtrack | ||
2108 | ReadyPushStack(); | ||
2109 | PopTrack(); | ||
2110 | DoPush(); | ||
2111 | Back(); | ||
2112 | break; | ||
2113 | |||
2114 | |||
2115 | case RegexCode.Lazybranchmark: | ||
2116 | //: Stackframe(1); | ||
2117 | //: | ||
2118 | //: if (Textpos() != Stacked(0)) | ||
2119 | //: { // Nonempty match -> next loop | ||
2120 | //: Track(Stacked(0), Textpos()); // Save old mark, textpos | ||
2121 | //: } | ||
2122 | //: else | ||
2123 | //: { // Empty match -> no loop | ||
2124 | //: Track2(Stacked(0)); // Save old mark | ||
2125 | //: } | ||
2126 | //: Advance(1); | ||
2127 | //: continue Forward; | ||
2128 | { | ||
2129 | LocalBuilder mark = _tempV; | ||
2130 | Label l1 = DefineLabel(); | ||
2131 | |||
2132 | PopStack(); | ||
2133 | Dup(); | ||
2134 | Stloc(mark); // Stacked(0) -> temp | ||
2135 | PushTrack(mark); | ||
2136 | Ldloc(_textposV); | ||
2137 | Beq(l1); // mark == textpos -> branch | ||
2138 | |||
2139 | // (matched != 0) | ||
2140 | |||
2141 | PushTrack(_textposV); | ||
2142 | Track(); | ||
2143 | Br(AdvanceLabel()); // Advance (near) | ||
2144 | |||
2145 | // else | ||
2146 | |||
2147 | MarkLabel(l1); | ||
2148 | TrackUnique2(lazybranchmarkback2); | ||
2149 | break; | ||
2150 | } | ||
2151 | |||
2152 | case RegexCode.Lazybranchmark | RegexCode.Back: | ||
2153 | //: Trackframe(2); | ||
2154 | //: Track2(Tracked(0)); // Save old mark | ||
2155 | //: Stack(Textpos()); // Make new mark | ||
2156 | //: Textto(Tracked(1)); // Recall position | ||
2157 | //: Goto(Operand(0)); // Loop | ||
2158 | |||
2159 | PopTrack(); | ||
2160 | Stloc(_textposV); | ||
2161 | PushStack(_textposV); | ||
2162 | TrackUnique2(lazybranchmarkback2); | ||
2163 | Goto(Operand(0)); | ||
2164 | break; | ||
2165 | |||
2166 | case RegexCode.Lazybranchmark | RegexCode.Back2: | ||
2167 | //: Stackframe(1); | ||
2168 | //: Trackframe(1); | ||
2169 | //: Stack(Tracked(0)); // Recall old mark | ||
2170 | //: break Backward; | ||
2171 | ReadyReplaceStack(0); | ||
2172 | PopTrack(); | ||
2173 | DoReplace(); | ||
2174 | Back(); | ||
2175 | break; | ||
2176 | |||
2177 | case RegexCode.Nullcount: | ||
2178 | //: Stack(-1, Operand(0)); | ||
2179 | //: Track(); | ||
2180 | ReadyPushStack(); | ||
2181 | Ldc(-1); | ||
2182 | DoPush(); | ||
2183 | ReadyPushStack(); | ||
2184 | Ldc(Operand(0)); | ||
2185 | DoPush(); | ||
2186 | TrackUnique(stackpop2); | ||
2187 | break; | ||
2188 | |||
2189 | case RegexCode.Setcount: | ||
2190 | //: Stack(Textpos(), Operand(0)); | ||
2191 | //: Track(); | ||
2192 | PushStack(_textposV); | ||
2193 | ReadyPushStack(); | ||
2194 | Ldc(Operand(0)); | ||
2195 | DoPush(); | ||
2196 | TrackUnique(stackpop2); | ||
2197 | break; | ||
2198 | |||
2199 | |||
2200 | case RegexCode.Nullcount | RegexCode.Back: | ||
2201 | case RegexCode.Setcount | RegexCode.Back: | ||
2202 | //: Stackframe(2); | ||
2203 | //: break Backward; | ||
2204 | PopDiscardStack(2); | ||
2205 | Back(); | ||
2206 | break; | ||
2207 | |||
2208 | |||
2209 | case RegexCode.Branchcount: | ||
2210 | //: Stackframe(2); | ||
2211 | //: int mark = Stacked(0); | ||
2212 | //: int count = Stacked(1); | ||
2213 | //: | ||
2214 | //: if (count >= Operand(1) || Textpos() == mark && count >= 0) | ||
2215 | //: { // Max loops or empty match -> straight now | ||
2216 | //: Track2(mark, count); // Save old mark, count | ||
2217 | //: Advance(2); // Straight | ||
2218 | //: } | ||
2219 | //: else | ||
2220 | //: { // Nonempty match -> count+loop now | ||
2221 | //: Track(mark); // remember mark | ||
2222 | //: Stack(Textpos(), count + 1); // Make new mark, incr count | ||
2223 | //: Goto(Operand(0)); // Loop | ||
2224 | //: } | ||
2225 | //: continue Forward; | ||
2226 | { | ||
2227 | LocalBuilder count = _tempV; | ||
2228 | LocalBuilder mark = _temp2V; | ||
2229 | Label l1 = DefineLabel(); | ||
2230 | Label l2 = DefineLabel(); | ||
2231 | |||
2232 | PopStack(); | ||
2233 | Stloc(count); // count -> temp | ||
2234 | PopStack(); | ||
2235 | Dup(); | ||
2236 | Stloc(mark); // mark -> temp2 | ||
2237 | PushTrack(mark); | ||
2238 | |||
2239 | Ldloc(_textposV); | ||
2240 | Bne(l1); // mark != textpos -> l1 | ||
2241 | Ldloc(count); | ||
2242 | Ldc(0); | ||
2243 | Bge(l2); // count >= 0 && mark == textpos -> l2 | ||
2244 | |||
2245 | MarkLabel(l1); | ||
2246 | Ldloc(count); | ||
2247 | Ldc(Operand(1)); | ||
2248 | Bge(l2); // count >= Operand(1) -> l2 | ||
2249 | |||
2250 | // else | ||
2251 | PushStack(_textposV); | ||
2252 | ReadyPushStack(); | ||
2253 | Ldloc(count); // mark already on track | ||
2254 | Ldc(1); | ||
2255 | Add(); | ||
2256 | DoPush(); | ||
2257 | Track(); | ||
2258 | Goto(Operand(0)); | ||
2259 | |||
2260 | // if (count >= Operand(1) || Textpos() == mark) | ||
2261 | MarkLabel(l2); | ||
2262 | PushTrack(count); // mark already on track | ||
2263 | TrackUnique2(branchcountback2); | ||
2264 | break; | ||
2265 | } | ||
2266 | |||
2267 | case RegexCode.Branchcount | RegexCode.Back: | ||
2268 | //: Trackframe(1); | ||
2269 | //: Stackframe(2); | ||
2270 | //: if (Stacked(1) > 0) // Positive -> can go straight | ||
2271 | //: { | ||
2272 | //: Textto(Stacked(0)); // Zap to mark | ||
2273 | //: Track2(Tracked(0), Stacked(1) - 1); // Save old mark, old count | ||
2274 | //: Advance(2); // Straight | ||
2275 | //: continue Forward; | ||
2276 | //: } | ||
2277 | //: Stack(Tracked(0), Stacked(1) - 1); // recall old mark, old count | ||
2278 | //: break Backward; | ||
2279 | { | ||
2280 | |||
2281 | LocalBuilder count = _tempV; | ||
2282 | Label l1 = DefineLabel(); | ||
2283 | PopStack(); | ||
2284 | Ldc(1); | ||
2285 | Sub(); | ||
2286 | Dup(); | ||
2287 | Stloc(count); | ||
2288 | Ldc(0); | ||
2289 | Blt(l1); | ||
2290 | |||
2291 | // if (count >= 0) | ||
2292 | PopStack(); | ||
2293 | Stloc(_textposV); | ||
2294 | PushTrack(count); // Tracked(0) is alredy on the track | ||
2295 | TrackUnique2(branchcountback2); | ||
2296 | Advance(); | ||
2297 | |||
2298 | // else | ||
2299 | MarkLabel(l1); | ||
2300 | ReadyReplaceStack(0); | ||
2301 | PopTrack(); | ||
2302 | DoReplace(); | ||
2303 | PushStack(count); | ||
2304 | Back(); | ||
2305 | break; | ||
2306 | } | ||
2307 | |||
2308 | case RegexCode.Branchcount | RegexCode.Back2: | ||
2309 | //: Trackframe(2); | ||
2310 | //: Stack(Tracked(0), Tracked(1)); // Recall old mark, old count | ||
2311 | //: break Backward; // Backtrack | ||
2312 | |||
2313 | PopTrack(); | ||
2314 | Stloc(_tempV); | ||
2315 | ReadyPushStack(); | ||
2316 | PopTrack(); | ||
2317 | DoPush(); | ||
2318 | PushStack(_tempV); | ||
2319 | Back(); | ||
2320 | break; | ||
2321 | |||
2322 | case RegexCode.Lazybranchcount: | ||
2323 | //: Stackframe(2); | ||
2324 | //: int mark = Stacked(0); | ||
2325 | //: int count = Stacked(1); | ||
2326 | //: | ||
2327 | //: if (count < 0) | ||
2328 | //: { // Negative count -> loop now | ||
2329 | //: Track2(mark); // Save old mark | ||
2330 | //: Stack(Textpos(), count + 1); // Make new mark, incr count | ||
2331 | //: Goto(Operand(0)); // Loop | ||
2332 | //: } | ||
2333 | //: else | ||
2334 | //: { // Nonneg count or empty match -> straight now | ||
2335 | //: Track(mark, count, Textpos()); // Save mark, count, position | ||
2336 | //: } | ||
2337 | { | ||
2338 | LocalBuilder count = _tempV; | ||
2339 | LocalBuilder mark = _temp2V; | ||
2340 | Label l1 = DefineLabel(); | ||
2341 | Label l2 = DefineLabel(); | ||
2342 | Label l3 = _labels[NextCodepos()]; | ||
2343 | |||
2344 | PopStack(); | ||
2345 | Stloc(count); // count -> temp | ||
2346 | PopStack(); | ||
2347 | Stloc(mark); // mark -> temp2 | ||
2348 | |||
2349 | Ldloc(count); | ||
2350 | Ldc(0); | ||
2351 | Bge(l1); // count >= 0 -> l1 | ||
2352 | |||
2353 | // if (count < 0) | ||
2354 | PushTrack(mark); | ||
2355 | PushStack(_textposV); | ||
2356 | ReadyPushStack(); | ||
2357 | Ldloc(count); | ||
2358 | Ldc(1); | ||
2359 | Add(); | ||
2360 | DoPush(); | ||
2361 | TrackUnique2(lazybranchcountback2); | ||
2362 | Goto(Operand(0)); | ||
2363 | |||
2364 | // else | ||
2365 | MarkLabel(l1); | ||
2366 | PushTrack(mark); | ||
2367 | PushTrack(count); | ||
2368 | PushTrack(_textposV); | ||
2369 | Track(); | ||
2370 | break; | ||
2371 | } | ||
2372 | |||
2373 | case RegexCode.Lazybranchcount | RegexCode.Back: | ||
2374 | //: Trackframe(3); | ||
2375 | //: int mark = Tracked(0); | ||
2376 | //: int textpos = Tracked(2); | ||
2377 | //: if (Tracked(1) <= Operand(1) && textpos != mark) | ||
2378 | //: { | ||
2379 | //: Textto(Tracked(2)); // Recall position | ||
2380 | //: Stack(Textpos(), Tracked(1) + 1); // Make new mark, incr count | ||
2381 | //: Track2(Tracked(0)); // Save old mark | ||
2382 | //: Goto(Operand(0)); // Loop | ||
2383 | //: continue Forward; | ||
2384 | //: } | ||
2385 | //: else | ||
2386 | //: { | ||
2387 | //: Stack(Tracked(0), Tracked(1)); // Recall old mark, count | ||
2388 | //: break Backward; // backtrack | ||
2389 | //: } | ||
2390 | { | ||
2391 | Label l1 = DefineLabel(); | ||
2392 | LocalBuilder cV = _tempV; | ||
2393 | PopTrack(); | ||
2394 | Stloc(_textposV); | ||
2395 | PopTrack(); | ||
2396 | Dup(); | ||
2397 | Stloc(cV); | ||
2398 | Ldc(Operand(1)); | ||
2399 | Bgt(l1); // Tracked(1) > Operand(1) -> l1 | ||
2400 | |||
2401 | Ldloc(_textposV); | ||
2402 | TopTrack(); | ||
2403 | Beq(l1); // textpos == mark -> l1 | ||
2404 | |||
2405 | PushStack(_textposV); | ||
2406 | ReadyPushStack(); | ||
2407 | Ldloc(cV); | ||
2408 | Ldc(1); | ||
2409 | Add(); | ||
2410 | DoPush(); | ||
2411 | TrackUnique2(lazybranchcountback2); | ||
2412 | Goto(Operand(0)); | ||
2413 | |||
2414 | MarkLabel(l1); | ||
2415 | ReadyPushStack(); | ||
2416 | PopTrack(); | ||
2417 | DoPush(); | ||
2418 | PushStack(cV); | ||
2419 | Back(); | ||
2420 | break; | ||
2421 | } | ||
2422 | |||
2423 | case RegexCode.Lazybranchcount | RegexCode.Back2: | ||
2424 | //: Trackframe(1); | ||
2425 | //: Stackframe(2); | ||
2426 | //: Stack(Tracked(0), Stacked(1) - 1); // Recall old mark, count | ||
2427 | //: break Backward; // Backtrack | ||
2428 | |||
2429 | ReadyReplaceStack(1); | ||
2430 | PopTrack(); | ||
2431 | DoReplace(); | ||
2432 | ReadyReplaceStack(0); | ||
2433 | TopStack(); | ||
2434 | Ldc(1); | ||
2435 | Sub(); | ||
2436 | DoReplace(); | ||
2437 | Back(); | ||
2438 | break; | ||
2439 | |||
2440 | |||
2441 | case RegexCode.Setjump: | ||
2442 | //: Stack(Trackpos(), Crawlpos()); | ||
2443 | //: Track(); | ||
2444 | ReadyPushStack(); | ||
2445 | Ldthisfld(_trackF); | ||
2446 | Ldlen(); | ||
2447 | Ldloc(_trackposV); | ||
2448 | Sub(); | ||
2449 | DoPush(); | ||
2450 | ReadyPushStack(); | ||
2451 | Ldthis(); | ||
2452 | Callvirt(_crawlposM); | ||
2453 | DoPush(); | ||
2454 | TrackUnique(stackpop2); | ||
2455 | break; | ||
2456 | |||
2457 | case RegexCode.Setjump | RegexCode.Back: | ||
2458 | //: Stackframe(2); | ||
2459 | PopDiscardStack(2); | ||
2460 | Back(); | ||
2461 | break; | ||
2462 | |||
2463 | |||
2464 | case RegexCode.Backjump: | ||
2465 | //: Stackframe(2); | ||
2466 | //: Trackto(Stacked(0)); | ||
2467 | //: while (Crawlpos() != Stacked(1)) | ||
2468 | //: Uncapture(); | ||
2469 | //: break Backward; | ||
2470 | { | ||
2471 | Label l1 = DefineLabel(); | ||
2472 | Label l2 = DefineLabel(); | ||
2473 | |||
2474 | PopStack(); | ||
2475 | Ldthisfld(_trackF); | ||
2476 | Ldlen(); | ||
2477 | PopStack(); | ||
2478 | Sub(); | ||
2479 | Stloc(_trackposV); | ||
2480 | Dup(); | ||
2481 | Ldthis(); | ||
2482 | Callvirt(_crawlposM); | ||
2483 | Beq(l2); | ||
2484 | |||
2485 | MarkLabel(l1); | ||
2486 | Ldthis(); | ||
2487 | Callvirt(_uncaptureM); | ||
2488 | Dup(); | ||
2489 | Ldthis(); | ||
2490 | Callvirt(_crawlposM); | ||
2491 | Bne(l1); | ||
2492 | |||
2493 | MarkLabel(l2); | ||
2494 | Pop(); | ||
2495 | Back(); | ||
2496 | break; | ||
2497 | } | ||
2498 | |||
2499 | case RegexCode.Forejump: | ||
2500 | //: Stackframe(2); | ||
2501 | //: Trackto(Stacked(0)); | ||
2502 | //: Track(Stacked(1)); | ||
2503 | PopStack(); | ||
2504 | Stloc(_tempV); | ||
2505 | Ldthisfld(_trackF); | ||
2506 | Ldlen(); | ||
2507 | PopStack(); | ||
2508 | Sub(); | ||
2509 | Stloc(_trackposV); | ||
2510 | PushTrack(_tempV); | ||
2511 | TrackUnique(forejumpback); | ||
2512 | break; | ||
2513 | |||
2514 | case RegexCode.Forejump | RegexCode.Back: | ||
2515 | //: Trackframe(1); | ||
2516 | //: while (Crawlpos() != Tracked(0)) | ||
2517 | //: Uncapture(); | ||
2518 | //: break Backward; | ||
2519 | { | ||
2520 | Label l1 = DefineLabel(); | ||
2521 | Label l2 = DefineLabel(); | ||
2522 | |||
2523 | PopTrack(); | ||
2524 | |||
2525 | Dup(); | ||
2526 | Ldthis(); | ||
2527 | Callvirt(_crawlposM); | ||
2528 | Beq(l2); | ||
2529 | |||
2530 | MarkLabel(l1); | ||
2531 | Ldthis(); | ||
2532 | Callvirt(_uncaptureM); | ||
2533 | Dup(); | ||
2534 | Ldthis(); | ||
2535 | Callvirt(_crawlposM); | ||
2536 | Bne(l1); | ||
2537 | |||
2538 | MarkLabel(l2); | ||
2539 | Pop(); | ||
2540 | Back(); | ||
2541 | break; | ||
2542 | } | ||
2543 | |||
2544 | case RegexCode.Bol: | ||
2545 | //: if (Leftchars() > 0 && CharAt(Textpos() - 1) != '\n') | ||
2546 | //: break Backward; | ||
2547 | { | ||
2548 | Label l1 = _labels[NextCodepos()]; | ||
2549 | Ldloc(_textposV); | ||
2550 | Ldloc(_textbegV); | ||
2551 | Ble(l1); | ||
2552 | Leftchar(); | ||
2553 | Ldc((int)'\n'); | ||
2554 | BneFar(_backtrack); | ||
2555 | break; | ||
2556 | } | ||
2557 | |||
2558 | case RegexCode.Eol: | ||
2559 | //: if (Rightchars() > 0 && CharAt(Textpos()) != '\n') | ||
2560 | //: break Backward; | ||
2561 | { | ||
2562 | Label l1 = _labels[NextCodepos()]; | ||
2563 | Ldloc(_textposV); | ||
2564 | Ldloc(_textendV); | ||
2565 | Bge(l1); | ||
2566 | Rightchar(); | ||
2567 | Ldc((int)'\n'); | ||
2568 | BneFar(_backtrack); | ||
2569 | break; | ||
2570 | } | ||
2571 | |||
2572 | case RegexCode.Boundary: | ||
2573 | case RegexCode.Nonboundary: | ||
2574 | //: if (!IsBoundary(Textpos(), _textbeg, _textend)) | ||
2575 | //: break Backward; | ||
2576 | Ldthis(); | ||
2577 | Ldloc(_textposV); | ||
2578 | Ldloc(_textbegV); | ||
2579 | Ldloc(_textendV); | ||
2580 | Callvirt(_isboundaryM); | ||
2581 | if (Code() == RegexCode.Boundary) | ||
2582 | BrfalseFar(_backtrack); | ||
2583 | else | ||
2584 | BrtrueFar(_backtrack); | ||
2585 | break; | ||
2586 | |||
2587 | case RegexCode.ECMABoundary: | ||
2588 | case RegexCode.NonECMABoundary: | ||
2589 | //: if (!IsECMABoundary(Textpos(), _textbeg, _textend)) | ||
2590 | //: break Backward; | ||
2591 | Ldthis(); | ||
2592 | Ldloc(_textposV); | ||
2593 | Ldloc(_textbegV); | ||
2594 | Ldloc(_textendV); | ||
2595 | Callvirt(_isECMABoundaryM); | ||
2596 | if (Code() == RegexCode.ECMABoundary) | ||
2597 | BrfalseFar(_backtrack); | ||
2598 | else | ||
2599 | BrtrueFar(_backtrack); | ||
2600 | break; | ||
2601 | |||
2602 | case RegexCode.Beginning: | ||
2603 | //: if (Leftchars() > 0) | ||
2604 | //: break Backward; | ||
2605 | Ldloc(_textposV); | ||
2606 | Ldloc(_textbegV); | ||
2607 | BgtFar(_backtrack); | ||
2608 | break; | ||
2609 | |||
2610 | case RegexCode.Start: | ||
2611 | //: if (Textpos() != Textstart()) | ||
2612 | //: break Backward; | ||
2613 | Ldloc(_textposV); | ||
2614 | Ldthisfld(_textstartF); | ||
2615 | BneFar(_backtrack); | ||
2616 | break; | ||
2617 | |||
2618 | case RegexCode.EndZ: | ||
2619 | //: if (Rightchars() > 1 || Rightchars() == 1 && CharAt(Textpos()) != '\n') | ||
2620 | //: break Backward; | ||
2621 | Ldloc(_textposV); | ||
2622 | Ldloc(_textendV); | ||
2623 | Ldc(1); | ||
2624 | Sub(); | ||
2625 | BltFar(_backtrack); | ||
2626 | Ldloc(_textposV); | ||
2627 | Ldloc(_textendV); | ||
2628 | Bge(_labels[NextCodepos()]); | ||
2629 | Rightchar(); | ||
2630 | Ldc((int)'\n'); | ||
2631 | BneFar(_backtrack); | ||
2632 | break; | ||
2633 | |||
2634 | case RegexCode.End: | ||
2635 | //: if (Rightchars() > 0) | ||
2636 | //: break Backward; | ||
2637 | Ldloc(_textposV); | ||
2638 | Ldloc(_textendV); | ||
2639 | BltFar(_backtrack); | ||
2640 | break; | ||
2641 | |||
2642 | case RegexCode.One: | ||
2643 | case RegexCode.Notone: | ||
2644 | case RegexCode.Set: | ||
2645 | case RegexCode.One | RegexCode.Rtl: | ||
2646 | case RegexCode.Notone | RegexCode.Rtl: | ||
2647 | case RegexCode.Set | RegexCode.Rtl: | ||
2648 | case RegexCode.One | RegexCode.Ci: | ||
2649 | case RegexCode.Notone | RegexCode.Ci: | ||
2650 | case RegexCode.Set | RegexCode.Ci: | ||
2651 | case RegexCode.One | RegexCode.Ci | RegexCode.Rtl: | ||
2652 | case RegexCode.Notone | RegexCode.Ci | RegexCode.Rtl: | ||
2653 | case RegexCode.Set | RegexCode.Ci | RegexCode.Rtl: | ||
2654 | |||
2655 | //: if (Rightchars() < 1 || Rightcharnext() != (char)Operand(0)) | ||
2656 | //: break Backward; | ||
2657 | Ldloc(_textposV); | ||
2658 | |||
2659 | if (!IsRtl()) | ||
2660 | { | ||
2661 | Ldloc(_textendV); | ||
2662 | BgeFar(_backtrack); | ||
2663 | Rightcharnext(); | ||
2664 | } | ||
2665 | else | ||
2666 | { | ||
2667 | Ldloc(_textbegV); | ||
2668 | BleFar(_backtrack); | ||
2669 | Leftcharnext(); | ||
2670 | } | ||
2671 | |||
2672 | if (IsCi()) | ||
2673 | CallToLower(); | ||
2674 | |||
2675 | if (Code() == RegexCode.Set) | ||
2676 | { | ||
2677 | |||
2678 | Ldstr(_strings[Operand(0)]); | ||
2679 | Ldstr(_strings[Operand(1)]); | ||
2680 | Call(_charInSetM); | ||
2681 | |||
2682 | BrfalseFar(_backtrack); | ||
2683 | } | ||
2684 | else | ||
2685 | { | ||
2686 | Ldc(Operand(0)); | ||
2687 | if (Code() == RegexCode.One) | ||
2688 | BneFar(_backtrack); | ||
2689 | else | ||
2690 | BeqFar(_backtrack); | ||
2691 | } | ||
2692 | break; | ||
2693 | |||
2694 | case RegexCode.Multi: | ||
2695 | case RegexCode.Multi | RegexCode.Ci: | ||
2696 | // | ||
2697 | // | ||
2698 | |||
2699 | //: String Str = _strings[Operand(0)]; | ||
2700 | //: int i, c; | ||
2701 | //: if (Rightchars() < (c = Str.Length)) | ||
2702 | //: break Backward; | ||
2703 | //: for (i = 0; c > 0; i++, c--) | ||
2704 | //: if (Str[i] != Rightcharnext()) | ||
2705 | //: break Backward; | ||
2706 | { | ||
2707 | int i; | ||
2708 | String str; | ||
2709 | |||
2710 | str = _strings[Operand(0)]; | ||
2711 | |||
2712 | Ldc(str.Length); | ||
2713 | Ldloc(_textendV); | ||
2714 | Ldloc(_textposV); | ||
2715 | Sub(); | ||
2716 | BgtFar(_backtrack); | ||
2717 | |||
2718 | // unroll the string | ||
2719 | for (i = 0; i < str.Length; i++) | ||
2720 | { | ||
2721 | Ldloc(_textV); | ||
2722 | Ldloc(_textposV); | ||
2723 | if (i != 0) | ||
2724 | { | ||
2725 | Ldc(i); | ||
2726 | Add(); | ||
2727 | } | ||
2728 | Callvirt(_getcharM); | ||
2729 | if (IsCi()) | ||
2730 | CallToLower(); | ||
2731 | |||
2732 | Ldc((int)str[i]); | ||
2733 | BneFar(_backtrack); | ||
2734 | } | ||
2735 | |||
2736 | Ldloc(_textposV); | ||
2737 | Ldc(str.Length); | ||
2738 | Add(); | ||
2739 | Stloc(_textposV); | ||
2740 | break; | ||
2741 | } | ||
2742 | |||
2743 | |||
2744 | case RegexCode.Multi | RegexCode.Rtl: | ||
2745 | case RegexCode.Multi | RegexCode.Ci | RegexCode.Rtl: | ||
2746 | //: String Str = _strings[Operand(0)]; | ||
2747 | //: int c; | ||
2748 | //: if (Leftchars() < (c = Str.Length)) | ||
2749 | //: break Backward; | ||
2750 | //: while (c > 0) | ||
2751 | //: if (Str[--c] != Leftcharnext()) | ||
2752 | //: break Backward; | ||
2753 | { | ||
2754 | int i; | ||
2755 | String str; | ||
2756 | |||
2757 | str = _strings[Operand(0)]; | ||
2758 | |||
2759 | Ldc(str.Length); | ||
2760 | Ldloc(_textposV); | ||
2761 | Ldloc(_textbegV); | ||
2762 | Sub(); | ||
2763 | BgtFar(_backtrack); | ||
2764 | |||
2765 | // unroll the string | ||
2766 | for (i = str.Length; i > 0; ) | ||
2767 | { | ||
2768 | i--; | ||
2769 | Ldloc(_textV); | ||
2770 | Ldloc(_textposV); | ||
2771 | Ldc(str.Length - i); | ||
2772 | Sub(); | ||
2773 | Callvirt(_getcharM); | ||
2774 | if (IsCi()) | ||
2775 | { | ||
2776 | CallToLower(); | ||
2777 | } | ||
2778 | Ldc((int)str[i]); | ||
2779 | BneFar(_backtrack); | ||
2780 | } | ||
2781 | |||
2782 | Ldloc(_textposV); | ||
2783 | Ldc(str.Length); | ||
2784 | Sub(); | ||
2785 | Stloc(_textposV); | ||
2786 | |||
2787 | break; | ||
2788 | } | ||
2789 | |||
2790 | case RegexCode.Ref: | ||
2791 | case RegexCode.Ref | RegexCode.Rtl: | ||
2792 | case RegexCode.Ref | RegexCode.Ci: | ||
2793 | case RegexCode.Ref | RegexCode.Ci | RegexCode.Rtl: | ||
2794 | //: int capnum = Operand(0); | ||
2795 | //: int j, c; | ||
2796 | //: if (!_match.IsMatched(capnum)) { | ||
2797 | //: #if ECMA | ||
2798 | //: if (!RegexOptions.ECMAScript) | ||
2799 | //: #endif | ||
2800 | //: break Backward; | ||
2801 | //: } else { | ||
2802 | //: if (Rightchars() < (c = _match.MatchLength(capnum))) | ||
2803 | //: break Backward; | ||
2804 | //: for (j = _match.MatchIndex(capnum); c > 0; j++, c--) | ||
2805 | //: if (CharAt(j) != Rightcharnext()) | ||
2806 | //: break Backward; | ||
2807 | //: } | ||
2808 | { | ||
2809 | LocalBuilder lenV = _tempV; | ||
2810 | LocalBuilder indexV = _temp2V; | ||
2811 | Label l1 = DefineLabel(); | ||
2812 | |||
2813 | Ldthis(); | ||
2814 | Ldc(Operand(0)); | ||
2815 | Callvirt(_ismatchedM); | ||
2816 | if ((_options & RegexOptions.ECMAScript) != 0) | ||
2817 | Brfalse(AdvanceLabel()); | ||
2818 | else | ||
2819 | BrfalseFar(_backtrack); // !IsMatched() -> back | ||
2820 | |||
2821 | Ldthis(); | ||
2822 | Ldc(Operand(0)); | ||
2823 | Callvirt(_matchlengthM); | ||
2824 | Dup(); | ||
2825 | Stloc(lenV); | ||
2826 | if (!IsRtl()) | ||
2827 | { | ||
2828 | Ldloc(_textendV); | ||
2829 | Ldloc(_textposV); | ||
2830 | } | ||
2831 | else | ||
2832 | { | ||
2833 | Ldloc(_textposV); | ||
2834 | Ldloc(_textbegV); | ||
2835 | } | ||
2836 | Sub(); | ||
2837 | BgtFar(_backtrack); // Matchlength() > Rightchars() -> back | ||
2838 | |||
2839 | Ldthis(); | ||
2840 | Ldc(Operand(0)); | ||
2841 | Callvirt(_matchindexM); | ||
2842 | if (!IsRtl()) | ||
2843 | { | ||
2844 | Ldloc(lenV); | ||
2845 | Add(IsRtl()); | ||
2846 | } | ||
2847 | Stloc(indexV); // index += len | ||
2848 | |||
2849 | Ldloc(_textposV); | ||
2850 | Ldloc(lenV); | ||
2851 | Add(IsRtl()); | ||
2852 | Stloc(_textposV); // texpos += len | ||
2853 | |||
2854 | MarkLabel(l1); | ||
2855 | Ldloc(lenV); | ||
2856 | Ldc(0); | ||
2857 | Ble(AdvanceLabel()); | ||
2858 | Ldloc(_textV); | ||
2859 | Ldloc(indexV); | ||
2860 | Ldloc(lenV); | ||
2861 | if (IsRtl()) | ||
2862 | { | ||
2863 | Ldc(1); | ||
2864 | Sub(); | ||
2865 | Dup(); | ||
2866 | Stloc(lenV); | ||
2867 | } | ||
2868 | Sub(IsRtl()); | ||
2869 | Callvirt(_getcharM); | ||
2870 | if (IsCi()) | ||
2871 | CallToLower(); | ||
2872 | |||
2873 | Ldloc(_textV); | ||
2874 | Ldloc(_textposV); | ||
2875 | Ldloc(lenV); | ||
2876 | if (!IsRtl()) | ||
2877 | { | ||
2878 | Dup(); | ||
2879 | Ldc(1); | ||
2880 | Sub(); | ||
2881 | Stloc(lenV); | ||
2882 | } | ||
2883 | Sub(IsRtl()); | ||
2884 | Callvirt(_getcharM); | ||
2885 | if (IsCi()) | ||
2886 | CallToLower(); | ||
2887 | |||
2888 | Beq(l1); | ||
2889 | Back(); | ||
2890 | break; | ||
2891 | } | ||
2892 | |||
2893 | |||
2894 | case RegexCode.Onerep: | ||
2895 | case RegexCode.Notonerep: | ||
2896 | case RegexCode.Setrep: | ||
2897 | case RegexCode.Onerep | RegexCode.Rtl: | ||
2898 | case RegexCode.Notonerep | RegexCode.Rtl: | ||
2899 | case RegexCode.Setrep | RegexCode.Rtl: | ||
2900 | case RegexCode.Onerep | RegexCode.Ci: | ||
2901 | case RegexCode.Notonerep | RegexCode.Ci: | ||
2902 | case RegexCode.Setrep | RegexCode.Ci: | ||
2903 | case RegexCode.Onerep | RegexCode.Ci | RegexCode.Rtl: | ||
2904 | case RegexCode.Notonerep | RegexCode.Ci | RegexCode.Rtl: | ||
2905 | case RegexCode.Setrep | RegexCode.Ci | RegexCode.Rtl: | ||
2906 | //: int c = Operand(1); | ||
2907 | //: if (Rightchars() < c) | ||
2908 | //: break Backward; | ||
2909 | //: char ch = (char)Operand(0); | ||
2910 | //: while (c-- > 0) | ||
2911 | //: if (Rightcharnext() != ch) | ||
2912 | //: break Backward; | ||
2913 | { | ||
2914 | LocalBuilder lenV = _tempV; | ||
2915 | Label l1 = DefineLabel(); | ||
2916 | |||
2917 | int c = (Code() == RegexCode.Setrep) ? Operand(2) : Operand(1); | ||
2918 | |||
2919 | if (c == 0) | ||
2920 | break; | ||
2921 | |||
2922 | Ldc(c); | ||
2923 | if (!IsRtl()) | ||
2924 | { | ||
2925 | Ldloc(_textendV); | ||
2926 | Ldloc(_textposV); | ||
2927 | } | ||
2928 | else | ||
2929 | { | ||
2930 | Ldloc(_textposV); | ||
2931 | Ldloc(_textbegV); | ||
2932 | } | ||
2933 | Sub(); | ||
2934 | BgtFar(_backtrack); // Matchlength() > Rightchars() -> back | ||
2935 | |||
2936 | Ldloc(_textposV); | ||
2937 | Ldc(c); | ||
2938 | Add(IsRtl()); | ||
2939 | Stloc(_textposV); // texpos += len | ||
2940 | |||
2941 | Ldc(c); | ||
2942 | Stloc(lenV); | ||
2943 | |||
2944 | MarkLabel(l1); | ||
2945 | Ldloc(_textV); | ||
2946 | Ldloc(_textposV); | ||
2947 | Ldloc(lenV); | ||
2948 | if (IsRtl()) | ||
2949 | { | ||
2950 | Ldc(1); | ||
2951 | Sub(); | ||
2952 | Dup(); | ||
2953 | Stloc(lenV); | ||
2954 | Add(); | ||
2955 | } | ||
2956 | else | ||
2957 | { | ||
2958 | Dup(); | ||
2959 | Ldc(1); | ||
2960 | Sub(); | ||
2961 | Stloc(lenV); | ||
2962 | Sub(); | ||
2963 | } | ||
2964 | Callvirt(_getcharM); | ||
2965 | if (IsCi()) | ||
2966 | CallToLower(); | ||
2967 | |||
2968 | if (Code() == RegexCode.Setrep) | ||
2969 | { | ||
2970 | Ldstr(_strings[Operand(0)]); | ||
2971 | Ldstr(_strings[Operand(1)]); | ||
2972 | Call(_charInSetM); | ||
2973 | |||
2974 | BrfalseFar(_backtrack); | ||
2975 | } | ||
2976 | else | ||
2977 | { | ||
2978 | Ldc(Operand(0)); | ||
2979 | if (Code() == RegexCode.Onerep) | ||
2980 | BneFar(_backtrack); | ||
2981 | else | ||
2982 | BeqFar(_backtrack); | ||
2983 | } | ||
2984 | Ldloc(lenV); | ||
2985 | Ldc(0); | ||
2986 | if (Code() == RegexCode.Setrep) | ||
2987 | BgtFar(l1); | ||
2988 | else | ||
2989 | Bgt(l1); | ||
2990 | break; | ||
2991 | } | ||
2992 | |||
2993 | |||
2994 | case RegexCode.Oneloop: | ||
2995 | case RegexCode.Notoneloop: | ||
2996 | case RegexCode.Setloop: | ||
2997 | case RegexCode.Oneloop | RegexCode.Rtl: | ||
2998 | case RegexCode.Notoneloop | RegexCode.Rtl: | ||
2999 | case RegexCode.Setloop | RegexCode.Rtl: | ||
3000 | case RegexCode.Oneloop | RegexCode.Ci: | ||
3001 | case RegexCode.Notoneloop | RegexCode.Ci: | ||
3002 | case RegexCode.Setloop | RegexCode.Ci: | ||
3003 | case RegexCode.Oneloop | RegexCode.Ci | RegexCode.Rtl: | ||
3004 | case RegexCode.Notoneloop | RegexCode.Ci | RegexCode.Rtl: | ||
3005 | case RegexCode.Setloop | RegexCode.Ci | RegexCode.Rtl: | ||
3006 | //: int c = Operand(1); | ||
3007 | //: if (c > Rightchars()) | ||
3008 | //: c = Rightchars(); | ||
3009 | //: char ch = (char)Operand(0); | ||
3010 | //: int i; | ||
3011 | //: for (i = c; i > 0; i--) | ||
3012 | //: { | ||
3013 | //: if (Rightcharnext() != ch) | ||
3014 | //: { | ||
3015 | //: Leftnext(); | ||
3016 | //: break; | ||
3017 | //: } | ||
3018 | //: } | ||
3019 | //: if (c > i) | ||
3020 | //: Track(c - i - 1, Textpos() - 1); | ||
3021 | { | ||
3022 | LocalBuilder cV = _tempV; | ||
3023 | LocalBuilder lenV = _temp2V; | ||
3024 | Label l1 = DefineLabel(); | ||
3025 | Label l2 = DefineLabel(); | ||
3026 | |||
3027 | int c = (Code() == RegexCode.Setloop) ? Operand(2) : Operand(1); | ||
3028 | |||
3029 | if (c == 0) | ||
3030 | break; | ||
3031 | if (!IsRtl()) | ||
3032 | { | ||
3033 | Ldloc(_textendV); | ||
3034 | Ldloc(_textposV); | ||
3035 | } | ||
3036 | else | ||
3037 | { | ||
3038 | Ldloc(_textposV); | ||
3039 | Ldloc(_textbegV); | ||
3040 | } | ||
3041 | Sub(); | ||
3042 | if (c != infinite) | ||
3043 | { | ||
3044 | Label l4 = DefineLabel(); | ||
3045 | Dup(); | ||
3046 | Ldc(c); | ||
3047 | Blt(l4); | ||
3048 | Pop(); | ||
3049 | Ldc(c); | ||
3050 | MarkLabel(l4); | ||
3051 | } | ||
3052 | Dup(); | ||
3053 | Stloc(lenV); | ||
3054 | Ldc(1); | ||
3055 | Add(); | ||
3056 | Stloc(cV); | ||
3057 | |||
3058 | MarkLabel(l1); | ||
3059 | Ldloc(cV); | ||
3060 | Ldc(1); | ||
3061 | Sub(); | ||
3062 | Dup(); | ||
3063 | Stloc(cV); | ||
3064 | Ldc(0); | ||
3065 | if (Code() == RegexCode.Setloop) | ||
3066 | BleFar(l2); | ||
3067 | else | ||
3068 | Ble(l2); | ||
3069 | |||
3070 | if (IsRtl()) | ||
3071 | Leftcharnext(); | ||
3072 | else | ||
3073 | Rightcharnext(); | ||
3074 | if (IsCi()) | ||
3075 | CallToLower(); | ||
3076 | |||
3077 | if (Code() == RegexCode.Setloop) | ||
3078 | { | ||
3079 | Ldstr(_strings[Operand(0)]); | ||
3080 | Ldstr(_strings[Operand(1)]); | ||
3081 | Call(_charInSetM); | ||
3082 | |||
3083 | BrtrueFar(l1); | ||
3084 | } | ||
3085 | else | ||
3086 | { | ||
3087 | Ldc(Operand(0)); | ||
3088 | if (Code() == RegexCode.Oneloop) | ||
3089 | Beq(l1); | ||
3090 | else | ||
3091 | Bne(l1); | ||
3092 | } | ||
3093 | |||
3094 | Ldloc(_textposV); | ||
3095 | Ldc(1); | ||
3096 | Sub(IsRtl()); | ||
3097 | Stloc(_textposV); | ||
3098 | |||
3099 | MarkLabel(l2); | ||
3100 | Ldloc(lenV); | ||
3101 | Ldloc(cV); | ||
3102 | Ble(AdvanceLabel()); | ||
3103 | |||
3104 | ReadyPushTrack(); | ||
3105 | Ldloc(lenV); | ||
3106 | Ldloc(cV); | ||
3107 | Sub(); | ||
3108 | Ldc(1); | ||
3109 | Sub(); | ||
3110 | DoPush(); | ||
3111 | |||
3112 | ReadyPushTrack(); | ||
3113 | Ldloc(_textposV); | ||
3114 | Ldc(1); | ||
3115 | Sub(IsRtl()); | ||
3116 | DoPush(); | ||
3117 | |||
3118 | Track(); | ||
3119 | break; | ||
3120 | } | ||
3121 | |||
3122 | case RegexCode.Oneloop | RegexCode.Back: | ||
3123 | case RegexCode.Notoneloop | RegexCode.Back: | ||
3124 | case RegexCode.Setloop | RegexCode.Back: | ||
3125 | case RegexCode.Oneloop | RegexCode.Rtl | RegexCode.Back: | ||
3126 | case RegexCode.Notoneloop | RegexCode.Rtl | RegexCode.Back: | ||
3127 | case RegexCode.Setloop | RegexCode.Rtl | RegexCode.Back: | ||
3128 | case RegexCode.Oneloop | RegexCode.Ci | RegexCode.Back: | ||
3129 | case RegexCode.Notoneloop | RegexCode.Ci | RegexCode.Back: | ||
3130 | case RegexCode.Setloop | RegexCode.Ci | RegexCode.Back: | ||
3131 | case RegexCode.Oneloop | RegexCode.Ci | RegexCode.Rtl | RegexCode.Back: | ||
3132 | case RegexCode.Notoneloop | RegexCode.Ci | RegexCode.Rtl | RegexCode.Back: | ||
3133 | case RegexCode.Setloop | RegexCode.Ci | RegexCode.Rtl | RegexCode.Back: | ||
3134 | //: Trackframe(2); | ||
3135 | //: int i = Tracked(0); | ||
3136 | //: int pos = Tracked(1); | ||
3137 | //: Textto(pos); | ||
3138 | //: if (i > 0) | ||
3139 | //: Track(i - 1, pos - 1); | ||
3140 | //: Advance(2); | ||
3141 | PopTrack(); | ||
3142 | Stloc(_textposV); | ||
3143 | PopTrack(); | ||
3144 | Stloc(_tempV); | ||
3145 | Ldloc(_tempV); | ||
3146 | Ldc(0); | ||
3147 | BleFar(AdvanceLabel()); | ||
3148 | ReadyPushTrack(); | ||
3149 | Ldloc(_tempV); | ||
3150 | Ldc(1); | ||
3151 | Sub(); | ||
3152 | DoPush(); | ||
3153 | ReadyPushTrack(); | ||
3154 | Ldloc(_textposV); | ||
3155 | Ldc(1); | ||
3156 | Sub(IsRtl()); | ||
3157 | DoPush(); | ||
3158 | Trackagain(); | ||
3159 | Advance(); | ||
3160 | break; | ||
3161 | |||
3162 | case RegexCode.Onelazy: | ||
3163 | case RegexCode.Notonelazy: | ||
3164 | case RegexCode.Setlazy: | ||
3165 | case RegexCode.Onelazy | RegexCode.Rtl: | ||
3166 | case RegexCode.Notonelazy | RegexCode.Rtl: | ||
3167 | case RegexCode.Setlazy | RegexCode.Rtl: | ||
3168 | case RegexCode.Onelazy | RegexCode.Ci: | ||
3169 | case RegexCode.Notonelazy | RegexCode.Ci: | ||
3170 | case RegexCode.Setlazy | RegexCode.Ci: | ||
3171 | case RegexCode.Onelazy | RegexCode.Ci | RegexCode.Rtl: | ||
3172 | case RegexCode.Notonelazy | RegexCode.Ci | RegexCode.Rtl: | ||
3173 | case RegexCode.Setlazy | RegexCode.Ci | RegexCode.Rtl: | ||
3174 | //: int c = Operand(1); | ||
3175 | //: if (c > Rightchars()) | ||
3176 | //: c = Rightchars(); | ||
3177 | //: if (c > 0) | ||
3178 | //: Track(c - 1, Textpos()); | ||
3179 | { | ||
3180 | LocalBuilder cV = _tempV; | ||
3181 | |||
3182 | int c = (Code() == RegexCode.Setlazy) ? Operand(2) : Operand(1); | ||
3183 | |||
3184 | if (c == 0) | ||
3185 | break; | ||
3186 | |||
3187 | if (!IsRtl()) | ||
3188 | { | ||
3189 | Ldloc(_textendV); | ||
3190 | Ldloc(_textposV); | ||
3191 | } | ||
3192 | else | ||
3193 | { | ||
3194 | Ldloc(_textposV); | ||
3195 | Ldloc(_textbegV); | ||
3196 | } | ||
3197 | Sub(); | ||
3198 | if (c != infinite) | ||
3199 | { | ||
3200 | Label l4 = DefineLabel(); | ||
3201 | Dup(); | ||
3202 | Ldc(c); | ||
3203 | Blt(l4); | ||
3204 | Pop(); | ||
3205 | Ldc(c); | ||
3206 | MarkLabel(l4); | ||
3207 | } | ||
3208 | Dup(); | ||
3209 | Stloc(cV); | ||
3210 | Ldc(0); | ||
3211 | Ble(AdvanceLabel()); | ||
3212 | ReadyPushTrack(); | ||
3213 | Ldloc(cV); | ||
3214 | Ldc(1); | ||
3215 | Sub(); | ||
3216 | DoPush(); | ||
3217 | PushTrack(_textposV); | ||
3218 | Track(); | ||
3219 | break; | ||
3220 | } | ||
3221 | |||
3222 | case RegexCode.Onelazy | RegexCode.Back: | ||
3223 | case RegexCode.Notonelazy | RegexCode.Back: | ||
3224 | case RegexCode.Setlazy | RegexCode.Back: | ||
3225 | case RegexCode.Onelazy | RegexCode.Rtl | RegexCode.Back: | ||
3226 | case RegexCode.Notonelazy | RegexCode.Rtl | RegexCode.Back: | ||
3227 | case RegexCode.Setlazy | RegexCode.Rtl | RegexCode.Back: | ||
3228 | case RegexCode.Onelazy | RegexCode.Ci | RegexCode.Back: | ||
3229 | case RegexCode.Notonelazy | RegexCode.Ci | RegexCode.Back: | ||
3230 | case RegexCode.Setlazy | RegexCode.Ci | RegexCode.Back: | ||
3231 | case RegexCode.Onelazy | RegexCode.Ci | RegexCode.Rtl | RegexCode.Back: | ||
3232 | case RegexCode.Notonelazy | RegexCode.Ci | RegexCode.Rtl | RegexCode.Back: | ||
3233 | case RegexCode.Setlazy | RegexCode.Ci | RegexCode.Rtl | RegexCode.Back: | ||
3234 | //: Trackframe(2); | ||
3235 | //: int pos = Tracked(1); | ||
3236 | //: Textto(pos); | ||
3237 | //: if (Rightcharnext() != (char)Operand(0)) | ||
3238 | //: break Backward; | ||
3239 | //: int i = Tracked(0); | ||
3240 | //: if (i > 0) | ||
3241 | //: Track(i - 1, pos + 1); | ||
3242 | |||
3243 | PopTrack(); | ||
3244 | Stloc(_textposV); | ||
3245 | PopTrack(); | ||
3246 | Stloc(_temp2V); | ||
3247 | |||
3248 | if (!IsRtl()) | ||
3249 | Rightcharnext(); | ||
3250 | else | ||
3251 | Leftcharnext(); | ||
3252 | |||
3253 | if (IsCi()) | ||
3254 | CallToLower(); | ||
3255 | |||
3256 | if (Code() == RegexCode.Setlazy) | ||
3257 | { | ||
3258 | Ldstr(_strings[Operand(0)]); | ||
3259 | Ldstr(_strings[Operand(1)]); | ||
3260 | Call(_charInSetM); | ||
3261 | |||
3262 | BrfalseFar(_backtrack); | ||
3263 | } | ||
3264 | else | ||
3265 | { | ||
3266 | Ldc(Operand(0)); | ||
3267 | if (Code() == RegexCode.Onelazy) | ||
3268 | BneFar(_backtrack); | ||
3269 | else | ||
3270 | BeqFar(_backtrack); | ||
3271 | } | ||
3272 | |||
3273 | Ldloc(_temp2V); | ||
3274 | Ldc(0); | ||
3275 | BleFar(AdvanceLabel()); | ||
3276 | ReadyPushTrack(); | ||
3277 | Ldloc(_temp2V); | ||
3278 | Ldc(1); | ||
3279 | Sub(); | ||
3280 | DoPush(); | ||
3281 | PushTrack(_textposV); | ||
3282 | Trackagain(); | ||
3283 | Advance(); | ||
3284 | break; | ||
3285 | |||
3286 | default: | ||
3287 | throw new NotImplementedException(SR.GetString(SR.UnimplementedState)); | ||
3288 | } | ||
3289 | } | ||
3290 | } | ||
3291 | |||
3292 | } | ||
3293 | |||