diff options
author | Tedd Hansen | 2007-08-12 17:04:09 +0000 |
---|---|---|
committer | Tedd Hansen | 2007-08-12 17:04:09 +0000 |
commit | 7a5474ec2883357b1874247b838d0e3607552104 (patch) | |
tree | e34090437bc58ac67ada6cd3ec714fbd83b28947 /OpenSim | |
parent | LSL ScriptEngine now only needs to inherit from BaseClass and we will be MUCH... (diff) | |
download | opensim-SC-7a5474ec2883357b1874247b838d0e3607552104.zip opensim-SC-7a5474ec2883357b1874247b838d0e3607552104.tar.gz opensim-SC-7a5474ec2883357b1874247b838d0e3607552104.tar.bz2 opensim-SC-7a5474ec2883357b1874247b838d0e3607552104.tar.xz |
Script now compiles unsuccessfully
(unknown datatypes, no references)
Diffstat (limited to 'OpenSim')
3 files changed, 146 insertions, 30 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs index b5a4a39..33be6ec 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs | |||
@@ -7,7 +7,7 @@ using System.CodeDom.Compiler; | |||
7 | 7 | ||
8 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | 8 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL |
9 | { | 9 | { |
10 | class Compiler | 10 | public class Compiler |
11 | { | 11 | { |
12 | private LSL2CS.Converter.LSL2CSConverter LSL_Converter = new LSL2CS.Converter.LSL2CSConverter(); | 12 | private LSL2CS.Converter.LSL2CSConverter LSL_Converter = new LSL2CS.Converter.LSL2CSConverter(); |
13 | private CSharpCodeProvider codeProvider = new CSharpCodeProvider(); | 13 | private CSharpCodeProvider codeProvider = new CSharpCodeProvider(); |
@@ -15,7 +15,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
15 | public string Compile(string LSOFileName) | 15 | public string Compile(string LSOFileName) |
16 | { | 16 | { |
17 | 17 | ||
18 | 18 | ||
19 | string OutFile = Path.GetFileNameWithoutExtension(LSOFileName); | 19 | string OutFile = Path.GetFileNameWithoutExtension(LSOFileName); |
20 | 20 | ||
21 | // TODO: Add error handling | 21 | // TODO: Add error handling |
@@ -37,7 +37,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
37 | } | 37 | } |
38 | } | 38 | } |
39 | 39 | ||
40 | 40 | ||
41 | return OutFile; | 41 | return OutFile; |
42 | } | 42 | } |
43 | 43 | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs index 1a82f2f..f058566 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs | |||
@@ -10,7 +10,7 @@ namespace LSL2CS.Converter | |||
10 | //private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled); | 10 | //private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled); |
11 | private Dictionary<string, string> DataTypes = new Dictionary<string, string>(); | 11 | private Dictionary<string, string> DataTypes = new Dictionary<string, string>(); |
12 | private Dictionary<string, string> QUOTES = new Dictionary<string, string>(); | 12 | private Dictionary<string, string> QUOTES = new Dictionary<string, string>(); |
13 | 13 | ||
14 | public LSL2CSConverter() | 14 | public LSL2CSConverter() |
15 | { | 15 | { |
16 | DataTypes.Add("void", "void"); | 16 | DataTypes.Add("void", "void"); |
@@ -29,8 +29,6 @@ namespace LSL2CS.Converter | |||
29 | public string Convert(string Script) | 29 | public string Convert(string Script) |
30 | { | 30 | { |
31 | string Return = ""; | 31 | string Return = ""; |
32 | QUOTES.Clear(); | ||
33 | |||
34 | 32 | ||
35 | // | 33 | // |
36 | // Prepare script for processing | 34 | // Prepare script for processing |
@@ -64,10 +62,6 @@ namespace LSL2CS.Converter | |||
64 | // Return += count + ". " + translate(line) + "\r\n"; | 62 | // Return += count + ". " + translate(line) + "\r\n"; |
65 | //} | 63 | //} |
66 | 64 | ||
67 | int level = 0; | ||
68 | bool Level0Set = false; | ||
69 | bool Level1Set = false; | ||
70 | |||
71 | 65 | ||
72 | // QUOTE REPLACEMENT | 66 | // QUOTE REPLACEMENT |
73 | //char[] SA = Script.ToCharArray(); | 67 | //char[] SA = Script.ToCharArray(); |
@@ -77,31 +71,41 @@ namespace LSL2CS.Converter | |||
77 | bool quote_replaced = false; | 71 | bool quote_replaced = false; |
78 | string quote_replacement_string = "Q_U_O_T_E_REPLACEMENT_"; | 72 | string quote_replacement_string = "Q_U_O_T_E_REPLACEMENT_"; |
79 | string quote = ""; | 73 | string quote = ""; |
74 | bool last_was_escape = false; | ||
80 | int quote_replaced_count = 0; | 75 | int quote_replaced_count = 0; |
81 | for (int p = 0; p < Script.Length; p++) | 76 | for (int p = 0; p < Script.Length; p++) |
82 | { | 77 | { |
83 | 78 | ||
84 | while (true) { | 79 | C = Script.Substring(p, 1); |
85 | C = Script.Substring(p,1); | 80 | while (true) |
86 | if (C == "\"") { | 81 | { |
82 | if (C == "\"" && last_was_escape == false) | ||
83 | { | ||
87 | // Toggle inside/outside quote | 84 | // Toggle inside/outside quote |
88 | in_quote = ! in_quote; | 85 | in_quote = !in_quote; |
89 | if(in_quote) { | 86 | if (in_quote) |
87 | { | ||
90 | quote_replaced_count++; | 88 | quote_replaced_count++; |
91 | } else { | 89 | } |
90 | else | ||
91 | { | ||
92 | // We just left a quote | 92 | // We just left a quote |
93 | QUOTES.Add(quote_replacement_string + quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]), quote); | 93 | QUOTES.Add(quote_replacement_string + quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]), quote); |
94 | quote = ""; | 94 | quote = ""; |
95 | } | 95 | } |
96 | break; | 96 | break; |
97 | } | 97 | } |
98 | if (!in_quote) { | 98 | if (!in_quote) |
99 | { | ||
99 | // We are not inside a quote | 100 | // We are not inside a quote |
100 | quote_replaced = false; | 101 | quote_replaced = false; |
101 | 102 | ||
102 | } else { | 103 | } |
104 | else | ||
105 | { | ||
103 | // We are inside a quote | 106 | // We are inside a quote |
104 | if (!quote_replaced) { | 107 | if (!quote_replaced) |
108 | { | ||
105 | // Replace quote | 109 | // Replace quote |
106 | _Script += quote_replacement_string + quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]); | 110 | _Script += quote_replacement_string + quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]); |
107 | quote_replaced = true; | 111 | quote_replaced = true; |
@@ -110,35 +114,135 @@ namespace LSL2CS.Converter | |||
110 | break; | 114 | break; |
111 | } | 115 | } |
112 | _Script += C; | 116 | _Script += C; |
113 | break; | 117 | break; |
118 | } | ||
119 | last_was_escape = false; | ||
120 | if (C == @"\") | ||
121 | { | ||
122 | last_was_escape = true; | ||
114 | } | 123 | } |
115 | } | 124 | } |
125 | Script = _Script; | ||
116 | // | 126 | // |
117 | // END OF QUOTE REPLACEMENT | 127 | // END OF QUOTE REPLACEMENT |
118 | // | 128 | // |
119 | 129 | ||
130 | |||
131 | |||
132 | |||
133 | // PROCESS STATES | ||
134 | int ilevel = 0; | ||
135 | int lastlevel = 0; | ||
136 | string ret = ""; | ||
137 | string cache = ""; | ||
138 | bool in_state = false; | ||
139 | string current_statename = ""; | ||
140 | for (int p = 0; p < Script.Length; p++) | ||
141 | { | ||
142 | C = Script.Substring(p, 1); | ||
143 | while (true) | ||
144 | { | ||
145 | // inc / dec level | ||
146 | if (C == @"{") | ||
147 | ilevel++; | ||
148 | if (C == @"}") | ||
149 | ilevel--; | ||
150 | if (ilevel < 0) | ||
151 | ilevel = 0; | ||
152 | cache += C; | ||
153 | |||
154 | // if level == 0, add to return | ||
155 | if (ilevel == 1 && lastlevel == 0) | ||
156 | { | ||
157 | // 0 => 1: Get last | ||
158 | Match m = Regex.Match(cache, @"(?![a-zA-Z_]+)\s*([a-zA-Z_]+)[^a-zA-Z_\(\)]*{", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
159 | |||
160 | in_state = false; | ||
161 | if (m.Success) | ||
162 | { | ||
163 | // Go back to level 0, this is not a state | ||
164 | in_state = true; | ||
165 | current_statename = m.Groups[1].Captures[0].Value; | ||
166 | Console.WriteLine("Current statename: " + current_statename); | ||
167 | cache = Regex.Replace(cache, @"(?![a-zA-Z_]+)\s*([a-zA-Z_]+)[^a-zA-Z_\(\)]*{", "", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
168 | } | ||
169 | ret += cache; | ||
170 | cache = ""; | ||
171 | } | ||
172 | if (ilevel == 0 && lastlevel == 1) | ||
173 | { | ||
174 | // 1 => 0: Remove last } | ||
175 | if (in_state == true) | ||
176 | { | ||
177 | cache = cache.Remove(cache.Length - 1, 1); | ||
178 | //cache = Regex.Replace(cache, "}$", "", RegexOptions.Multiline | RegexOptions.Singleline); | ||
179 | |||
180 | //Replace function names | ||
181 | // void dataserver(key query_id, string data) { | ||
182 | //cache = Regex.Replace(cache, @"([^a-zA-Z_]\s*)((?!if|switch|for)[a-zA-Z_]+\s*\([^\)]*\)[^{]*{)", "$1" + "<STATE>" + "$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
183 | Console.WriteLine("Replacing using statename: " + current_statename); | ||
184 | cache = Regex.Replace(cache, @"^(\s*)((?!if|switch|for)[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1" + current_statename + "_$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
185 | } | ||
186 | |||
187 | ret += cache; | ||
188 | cache = ""; | ||
189 | in_state = true; | ||
190 | current_statename = ""; | ||
191 | } | ||
192 | |||
193 | // if we moved from level 0 to level 1 don't add last word + { | ||
194 | // if we moved from level 1 to level 0 don't add last } | ||
195 | // if level > 0 cache all data so we can run regex on it when going to level 0 | ||
196 | |||
197 | |||
198 | |||
199 | |||
200 | break; | ||
201 | } | ||
202 | lastlevel = ilevel; | ||
203 | } | ||
204 | ret += cache; | ||
205 | cache = ""; | ||
206 | |||
207 | Script = ret; | ||
208 | ret = ""; | ||
209 | |||
210 | |||
211 | |||
120 | // Replace CAST - (integer) with (int) | 212 | // Replace CAST - (integer) with (int) |
121 | Script = Regex.Replace(_Script, @"\(integer\)", @"(int)", RegexOptions.Compiled | RegexOptions.Multiline); | 213 | Script = Regex.Replace(Script, @"\(integer\)", @"(int)", RegexOptions.Compiled | RegexOptions.Multiline); |
122 | // Replace return types and function variables - integer a() and f(integer a, integer a) | 214 | // Replace return types and function variables - integer a() and f(integer a, integer a) |
123 | _Script = Regex.Replace(Script, @"(^|[\(,])(\s*int)eger(\s*)", @"$1$2$3", RegexOptions.Compiled | RegexOptions.Multiline); | 215 | Script = Regex.Replace(Script, @"(^|;|}|[\(,])(\s*int)eger(\s*)", @"$1$2$3", RegexOptions.Compiled | RegexOptions.Multiline); |
216 | |||
217 | // Add "void" in front of functions that needs it | ||
218 | Script = Regex.Replace(Script, @"^(\s*)((?!if|switch|for)[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1void $2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
219 | |||
220 | // Replace <x,y,z> and <x,y,z,r> | ||
221 | Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*,[^,>]*)>", @"Rotation.Parse($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
222 | Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*)>", @"Vector.Parse($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | ||
124 | 223 | ||
125 | // Add void to functions not having that | 224 | // Replace List []'s |
126 | Script = Regex.Replace(_Script, @"^(\s*)((?!if|switch|for|foreach)[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1void $2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | 225 | Script = Regex.Replace(Script, @"\[([^\]]*)\]", @"List.Parse($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); |
127 | 226 | ||
128 | 227 | ||
129 | // Replace int (TEMPORARY QUICKFIX) | 228 | // Replace (string) to .ToString() // |
130 | //_Script = Regex.Replace(Script, "integer", "int", RegexOptions.Compiled); | 229 | Script = Regex.Replace(Script, @"\(string\)\s*([a-zA-Z0-9_]+(\s*\([^\)]*\))?)", @"$1.ToString()", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); |
131 | 230 | Script = Regex.Replace(Script, @"\((float|int)\)\s*([a-zA-Z0-9_]+(\s*\([^\)]*\))?)", @"$1.Parse($2)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); | |
231 | |||
232 | |||
233 | // REPLACE BACK QUOTES | ||
132 | foreach (string key in QUOTES.Keys) | 234 | foreach (string key in QUOTES.Keys) |
133 | { | 235 | { |
134 | string val; | 236 | string val; |
135 | QUOTES.TryGetValue(key, out val); | 237 | QUOTES.TryGetValue(key, out val); |
136 | _Script = Script.Replace(key, "\"" + val + "\""); | 238 | Script = Script.Replace(key, "\"" + val + "\""); |
137 | Script = _Script; | ||
138 | } | 239 | } |
139 | 240 | ||
140 | 241 | ||
141 | Return = Script; | 242 | Return = "namespace SecondLife {" + Environment.NewLine; |
243 | Return += "public class Script : LSL_BaseClass {" + Environment.NewLine; | ||
244 | Return += Script; | ||
245 | Return += "} }" + Environment.NewLine; | ||
142 | 246 | ||
143 | return Return; | 247 | return Return; |
144 | } | 248 | } |
@@ -154,5 +258,7 @@ namespace LSL2CS.Converter | |||
154 | // return ret; | 258 | // return ret; |
155 | //} | 259 | //} |
156 | 260 | ||
261 | |||
262 | |||
157 | } | 263 | } |
158 | } | 264 | } |
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..03d8ba5 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs | |||
@@ -0,0 +1,10 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
6 | { | ||
7 | class LSL_BaseClass | ||
8 | { | ||
9 | } | ||
10 | } | ||