aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorUbitUmarov2016-08-31 09:15:08 +0100
committerUbitUmarov2016-08-31 09:15:08 +0100
commit5afc5fe343172c315adec97cd8348357a196d5d2 (patch)
tree88d8410c4f32c8505c048dc45e674bb5d9146212 /OpenSim
parentXengine: remove a no thread safe locking, don't allocate a few objects only n... (diff)
downloadopensim-SC_OLD-5afc5fe343172c315adec97cd8348357a196d5d2.zip
opensim-SC_OLD-5afc5fe343172c315adec97cd8348357a196d5d2.tar.gz
opensim-SC_OLD-5afc5fe343172c315adec97cd8348357a196d5d2.tar.bz2
opensim-SC_OLD-5afc5fe343172c315adec97cd8348357a196d5d2.tar.xz
Xengine: try to reduce memory pressure of scripts compile. Still ugly code, possible mistakes, but i need to share it before i loose it :) )
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs546
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs133
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs3
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs2
-rwxr-xr-xOpenSim/Region/ScriptEngine/XEngine/XEngine.cs9
5 files changed, 337 insertions, 356 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
index 4e0c273..287b85b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Text;
29using System.IO; 30using System.IO;
30using System.Collections.Generic; 31using System.Collections.Generic;
31using System.Reflection; 32using System.Reflection;
@@ -39,9 +40,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
39 { 40 {
40// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 41// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
41 42
43 private static yyLSLSyntax yyLSL = new yyLSLSyntax();
42 private SYMBOL m_astRoot = null; 44 private SYMBOL m_astRoot = null;
43 private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> m_positionMap; 45 private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> m_positionMap;
44 private int m_indentWidth = 4; // for indentation
45 private int m_braceCount; // for indentation 46 private int m_braceCount; // for indentation
46 private int m_CSharpLine; // the current line of generated C# code 47 private int m_CSharpLine; // the current line of generated C# code
47 private int m_CSharpCol; // the current column of generated C# code 48 private int m_CSharpCol; // the current column of generated C# code
@@ -94,6 +95,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
94 get { return m_astRoot; } 95 get { return m_astRoot; }
95 } 96 }
96 97
98 public void Clear()
99 {
100 m_astRoot.kids = null;
101 m_astRoot.yylx = null;
102 m_astRoot.yyps = null;
103 m_astRoot = null;
104 m_positionMap = null;
105 m_warnings.Clear();
106 m_comms = null;
107 }
97 /// <summary> 108 /// <summary>
98 /// Resets various counters and metadata. 109 /// Resets various counters and metadata.
99 /// </summary> 110 /// </summary>
@@ -106,18 +117,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
106 m_astRoot = null; 117 m_astRoot = null;
107 } 118 }
108 119
120 public string Convert(string script)
121 {
122 StringBuilder sb = new StringBuilder(4096);
123 Convert(script, sb);
124 return sb.ToString();
125 }
126
109 /// <summary> 127 /// <summary>
110 /// Generate the code from the AST we have. 128 /// Generate the code from the AST we have.
111 /// </summary> 129 /// </summary>
112 /// <param name="script">The LSL source as a string.</param> 130 /// <param name="script">The LSL source as a string.</param>
113 /// <returns>String containing the generated C# code.</returns> 131 /// <returns>String containing the generated C# code.</returns>
114 public string Convert(string script) 132 public void Convert(string script, StringBuilder sb)
115 { 133 {
116// m_log.DebugFormat("[CS CODE GENERATOR]: Converting to C#\n{0}", script); 134// m_log.DebugFormat("[CS CODE GENERATOR]: Converting to C#\n{0}", script);
117 135
118 m_warnings.Clear(); 136 m_warnings.Clear();
119 ResetCounters(); 137 ResetCounters();
120 Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true)); 138 ErrorHandler errorHandler = new ErrorHandler(true);
139 Parser p = new LSLSyntax(yyLSL, errorHandler);
121 140
122 LSL2CSCodeTransformer codeTransformer; 141 LSL2CSCodeTransformer codeTransformer;
123 try 142 try
@@ -148,7 +167,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
148 167
149 m_astRoot = codeTransformer.Transform(); 168 m_astRoot = codeTransformer.Transform();
150 169
151 string retstr = String.Empty;
152 170
153 // standard preamble 171 // standard preamble
154 //retstr = GenerateLine("using OpenSim.Region.ScriptEngine.Common;"); 172 //retstr = GenerateLine("using OpenSim.Region.ScriptEngine.Common;");
@@ -165,21 +183,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
165 m_CSharpLine += 9; 183 m_CSharpLine += 9;
166 184
167 // here's the payload 185 // here's the payload
168 retstr += GenerateLine(); 186 sb.Append("\n");
169 foreach (SYMBOL s in m_astRoot.kids) 187 foreach (SYMBOL s in m_astRoot.kids)
170 retstr += GenerateNode(m_astRoot, s); 188 GenerateNodeToSB(m_astRoot, s, sb);
189
190 codeTransformer = null;
191 p.m_lexer.m_buf=null;
192 p.m_lexer.yytext = null;
193 p.m_lexer = null;
194 p.m_symbols = null;
195 p = null;
196 errorHandler = null;
171 197
172 // close braces! 198 // close braces!
173 m_braceCount--; 199// m_braceCount--;
174 //retstr += GenerateIndentedLine("}"); 200 //retstr += GenerateIndentedLine("}");
175 m_braceCount--; 201// m_braceCount--;
176 //retstr += GenerateLine("}"); 202 //retstr += GenerateLine("}");
177 203
178 // Removes all carriage return characters which may be generated in Windows platform. Is there 204 // Removes all carriage return characters which may be generated in Windows platform. Is there
179 // cleaner way of doing this? 205 // cleaner way of doing this?
180 retstr = retstr.Replace("\r", ""); 206// sb.Replace("\r", "");
181
182 return retstr;
183 } 207 }
184 208
185 /// <summary> 209 /// <summary>
@@ -206,78 +230,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
206 /// <param name="previousSymbol">The parent node.</param> 230 /// <param name="previousSymbol">The parent node.</param>
207 /// <param name="s">The current node to generate code for.</param> 231 /// <param name="s">The current node to generate code for.</param>
208 /// <returns>String containing C# code for SYMBOL s.</returns> 232 /// <returns>String containing C# code for SYMBOL s.</returns>
209 private string GenerateNode(SYMBOL previousSymbol, SYMBOL s) 233 private void GenerateNodeToSB(SYMBOL previousSymbol, SYMBOL s, StringBuilder sb)
210 { 234 {
211 string retstr = String.Empty;
212
213 // make sure to put type lower in the inheritance hierarchy first 235 // make sure to put type lower in the inheritance hierarchy first
214 // ie: since IdentArgument and ExpressionArgument inherit from 236 // ie: since IdentArgument and ExpressionArgument inherit from
215 // Argument, put IdentArgument and ExpressionArgument before Argument 237 // Argument, put IdentArgument and ExpressionArgument before Argument
216 if (s is GlobalFunctionDefinition) 238 if (s is GlobalFunctionDefinition)
217 retstr += GenerateGlobalFunctionDefinition((GlobalFunctionDefinition) s); 239 GenerateGlobalFunctionDefinition((GlobalFunctionDefinition) s, sb);
218 else if (s is GlobalVariableDeclaration) 240 else if (s is GlobalVariableDeclaration)
219 retstr += GenerateGlobalVariableDeclaration((GlobalVariableDeclaration) s); 241 GenerateGlobalVariableDeclaration((GlobalVariableDeclaration) s , sb);
220 else if (s is State) 242 else if (s is State)
221 retstr += GenerateState((State) s); 243 GenerateState((State) s, sb);
222 else if (s is CompoundStatement) 244 else if (s is CompoundStatement)
223 retstr += GenerateCompoundStatement(previousSymbol, (CompoundStatement) s); 245 GenerateCompoundStatement(previousSymbol, (CompoundStatement) s, sb);
224 else if (s is Declaration) 246 else if (s is Declaration)
225 retstr += GenerateDeclaration((Declaration) s); 247 GenerateDeclaration((Declaration) s, sb);
226 else if (s is Statement) 248 else if (s is Statement)
227 retstr += GenerateStatement(previousSymbol, (Statement) s); 249 GenerateStatement(previousSymbol, (Statement) s, sb);
228 else if (s is ReturnStatement) 250 else if (s is ReturnStatement)
229 retstr += GenerateReturnStatement((ReturnStatement) s); 251 GenerateReturnStatement((ReturnStatement) s, sb);
230 else if (s is JumpLabel) 252 else if (s is JumpLabel)
231 retstr += GenerateJumpLabel((JumpLabel) s); 253 GenerateJumpLabel((JumpLabel) s, sb);
232 else if (s is JumpStatement) 254 else if (s is JumpStatement)
233 retstr += GenerateJumpStatement((JumpStatement) s); 255 GenerateJumpStatement((JumpStatement) s, sb);
234 else if (s is StateChange) 256 else if (s is StateChange)
235 retstr += GenerateStateChange((StateChange) s); 257 GenerateStateChange((StateChange) s, sb);
236 else if (s is IfStatement) 258 else if (s is IfStatement)
237 retstr += GenerateIfStatement((IfStatement) s); 259 GenerateIfStatement((IfStatement) s, sb);
238 else if (s is WhileStatement) 260 else if (s is WhileStatement)
239 retstr += GenerateWhileStatement((WhileStatement) s); 261 GenerateWhileStatement((WhileStatement) s, sb);
240 else if (s is DoWhileStatement) 262 else if (s is DoWhileStatement)
241 retstr += GenerateDoWhileStatement((DoWhileStatement) s); 263 GenerateDoWhileStatement((DoWhileStatement) s, sb);
242 else if (s is ForLoop) 264 else if (s is ForLoop)
243 retstr += GenerateForLoop((ForLoop) s); 265 GenerateForLoop((ForLoop) s, sb);
244 else if (s is ArgumentList) 266 else if (s is ArgumentList)
245 retstr += GenerateArgumentList((ArgumentList) s); 267 GenerateArgumentList((ArgumentList) s, sb);
246 else if (s is Assignment) 268 else if (s is Assignment)
247 retstr += GenerateAssignment((Assignment) s); 269 GenerateAssignment((Assignment) s, sb);
248 else if (s is BinaryExpression) 270 else if (s is BinaryExpression)
249 retstr += GenerateBinaryExpression((BinaryExpression) s); 271 GenerateBinaryExpression((BinaryExpression) s, sb);
250 else if (s is ParenthesisExpression) 272 else if (s is ParenthesisExpression)
251 retstr += GenerateParenthesisExpression((ParenthesisExpression) s); 273 GenerateParenthesisExpression((ParenthesisExpression) s, sb);
252 else if (s is UnaryExpression) 274 else if (s is UnaryExpression)
253 retstr += GenerateUnaryExpression((UnaryExpression) s); 275 GenerateUnaryExpression((UnaryExpression) s, sb);
254 else if (s is IncrementDecrementExpression) 276 else if (s is IncrementDecrementExpression)
255 retstr += GenerateIncrementDecrementExpression((IncrementDecrementExpression) s); 277 GenerateIncrementDecrementExpression((IncrementDecrementExpression) s, sb);
256 else if (s is TypecastExpression) 278 else if (s is TypecastExpression)
257 retstr += GenerateTypecastExpression((TypecastExpression) s); 279 GenerateTypecastExpression((TypecastExpression) s, sb);
258 else if (s is FunctionCall) 280 else if (s is FunctionCall)
259 retstr += GenerateFunctionCall((FunctionCall) s); 281 GenerateFunctionCall((FunctionCall) s, sb);
260 else if (s is VectorConstant) 282 else if (s is VectorConstant)
261 retstr += GenerateVectorConstant((VectorConstant) s); 283 GenerateVectorConstant((VectorConstant) s, sb);
262 else if (s is RotationConstant) 284 else if (s is RotationConstant)
263 retstr += GenerateRotationConstant((RotationConstant) s); 285 GenerateRotationConstant((RotationConstant) s, sb);
264 else if (s is ListConstant) 286 else if (s is ListConstant)
265 retstr += GenerateListConstant((ListConstant) s); 287 GenerateListConstant((ListConstant) s, sb);
266 else if (s is Constant) 288 else if (s is Constant)
267 retstr += GenerateConstant((Constant) s); 289 GenerateConstant((Constant) s, sb);
268 else if (s is IdentDotExpression) 290 else if (s is IdentDotExpression)
269 retstr += Generate(CheckName(((IdentDotExpression) s).Name) + "." + ((IdentDotExpression) s).Member, s); 291 Generate(CheckName(((IdentDotExpression) s).Name) + "." + ((IdentDotExpression) s).Member, s, sb);
270 else if (s is IdentExpression) 292 else if (s is IdentExpression)
271 retstr += GenerateIdentifier(((IdentExpression) s).Name, s); 293 GenerateIdentifier(((IdentExpression) s).Name, s, sb);
272 else if (s is IDENT) 294 else if (s is IDENT)
273 retstr += Generate(CheckName(((TOKEN) s).yytext), s); 295 Generate(CheckName(((TOKEN) s).yytext), s, sb);
274 else 296 else
275 { 297 {
276 foreach (SYMBOL kid in s.kids) 298 foreach (SYMBOL kid in s.kids)
277 retstr += GenerateNode(s, kid); 299 GenerateNodeToSB(s, kid,sb);
278 } 300 }
279 301
280 return retstr; 302 return;
281 } 303 }
282 304
283 /// <summary> 305 /// <summary>
@@ -285,10 +307,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
285 /// </summary> 307 /// </summary>
286 /// <param name="gf">The GlobalFunctionDefinition node.</param> 308 /// <param name="gf">The GlobalFunctionDefinition node.</param>
287 /// <returns>String containing C# code for GlobalFunctionDefinition gf.</returns> 309 /// <returns>String containing C# code for GlobalFunctionDefinition gf.</returns>
288 private string GenerateGlobalFunctionDefinition(GlobalFunctionDefinition gf) 310 private void GenerateGlobalFunctionDefinition(GlobalFunctionDefinition gf, StringBuilder sb)
289 { 311 {
290 string retstr = String.Empty;
291
292 // we need to separate the argument declaration list from other kids 312 // we need to separate the argument declaration list from other kids
293 List<SYMBOL> argumentDeclarationListKids = new List<SYMBOL>(); 313 List<SYMBOL> argumentDeclarationListKids = new List<SYMBOL>();
294 List<SYMBOL> remainingKids = new List<SYMBOL>(); 314 List<SYMBOL> remainingKids = new List<SYMBOL>();
@@ -299,18 +319,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
299 else 319 else
300 remainingKids.Add(kid); 320 remainingKids.Add(kid);
301 321
302 retstr += GenerateIndented(String.Format("{0} {1}(", gf.ReturnType, CheckName(gf.Name)), gf); 322 GenerateIndented(String.Format("{0} {1}(", gf.ReturnType, CheckName(gf.Name)), gf, sb);
303 323
304 // print the state arguments, if any 324 // print the state arguments, if any
305 foreach (SYMBOL kid in argumentDeclarationListKids) 325 foreach (SYMBOL kid in argumentDeclarationListKids)
306 retstr += GenerateArgumentDeclarationList((ArgumentDeclarationList) kid); 326 GenerateArgumentDeclarationList((ArgumentDeclarationList) kid, sb);
307 327
308 retstr += GenerateLine(")"); 328 GenerateLine(")", sb);
309 329
310 foreach (SYMBOL kid in remainingKids) 330 foreach (SYMBOL kid in remainingKids)
311 retstr += GenerateNode(gf, kid); 331 GenerateNodeToSB(gf, kid,sb);
312
313 return retstr;
314 } 332 }
315 333
316 /// <summary> 334 /// <summary>
@@ -318,18 +336,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
318 /// </summary> 336 /// </summary>
319 /// <param name="gv">The GlobalVariableDeclaration node.</param> 337 /// <param name="gv">The GlobalVariableDeclaration node.</param>
320 /// <returns>String containing C# code for GlobalVariableDeclaration gv.</returns> 338 /// <returns>String containing C# code for GlobalVariableDeclaration gv.</returns>
321 private string GenerateGlobalVariableDeclaration(GlobalVariableDeclaration gv) 339 private void GenerateGlobalVariableDeclaration(GlobalVariableDeclaration gv, StringBuilder sb)
322 { 340 {
323 string retstr = String.Empty;
324
325 foreach (SYMBOL s in gv.kids) 341 foreach (SYMBOL s in gv.kids)
326 { 342 {
327 retstr += Indent(); 343 Indent(sb);
328 retstr += GenerateNode(gv, s); 344 GenerateNodeToSB(gv, s ,sb);
329 retstr += GenerateLine(";"); 345 GenerateLine(";", sb);
330 } 346 }
331
332 return retstr;
333 } 347 }
334 348
335 /// <summary> 349 /// <summary>
@@ -337,15 +351,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
337 /// </summary> 351 /// </summary>
338 /// <param name="s">The State node.</param> 352 /// <param name="s">The State node.</param>
339 /// <returns>String containing C# code for State s.</returns> 353 /// <returns>String containing C# code for State s.</returns>
340 private string GenerateState(State s) 354 private void GenerateState(State s, StringBuilder sb)
341 { 355 {
342 string retstr = String.Empty;
343
344 foreach (SYMBOL kid in s.kids) 356 foreach (SYMBOL kid in s.kids)
345 if (kid is StateEvent) 357 if (kid is StateEvent)
346 retstr += GenerateStateEvent((StateEvent) kid, s.Name); 358 GenerateStateEvent((StateEvent) kid, s.Name, sb);
347
348 return retstr;
349 } 359 }
350 360
351 /// <summary> 361 /// <summary>
@@ -354,10 +364,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
354 /// <param name="se">The StateEvent node.</param> 364 /// <param name="se">The StateEvent node.</param>
355 /// <param name="parentStateName">The name of the parent state.</param> 365 /// <param name="parentStateName">The name of the parent state.</param>
356 /// <returns>String containing C# code for StateEvent se.</returns> 366 /// <returns>String containing C# code for StateEvent se.</returns>
357 private string GenerateStateEvent(StateEvent se, string parentStateName) 367 private void GenerateStateEvent(StateEvent se, string parentStateName, StringBuilder sb)
358 { 368 {
359 string retstr = String.Empty;
360
361 // we need to separate the argument declaration list from other kids 369 // we need to separate the argument declaration list from other kids
362 List<SYMBOL> argumentDeclarationListKids = new List<SYMBOL>(); 370 List<SYMBOL> argumentDeclarationListKids = new List<SYMBOL>();
363 List<SYMBOL> remainingKids = new List<SYMBOL>(); 371 List<SYMBOL> remainingKids = new List<SYMBOL>();
@@ -369,18 +377,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
369 remainingKids.Add(kid); 377 remainingKids.Add(kid);
370 378
371 // "state" (function) declaration 379 // "state" (function) declaration
372 retstr += GenerateIndented(String.Format("public void {0}_event_{1}(", parentStateName, se.Name), se); 380 GenerateIndented(String.Format("public void {0}_event_{1}(", parentStateName, se.Name), se , sb);
373 381
374 // print the state arguments, if any 382 // print the state arguments, if any
375 foreach (SYMBOL kid in argumentDeclarationListKids) 383 foreach (SYMBOL kid in argumentDeclarationListKids)
376 retstr += GenerateArgumentDeclarationList((ArgumentDeclarationList) kid); 384 GenerateArgumentDeclarationList((ArgumentDeclarationList) kid, sb);
377 385
378 retstr += GenerateLine(")"); 386 GenerateLine(")", sb);
379 387
380 foreach (SYMBOL kid in remainingKids) 388 foreach (SYMBOL kid in remainingKids)
381 retstr += GenerateNode(se, kid); 389 GenerateNodeToSB(se, kid, sb);
382
383 return retstr;
384 } 390 }
385 391
386 /// <summary> 392 /// <summary>
@@ -388,20 +394,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
388 /// </summary> 394 /// </summary>
389 /// <param name="adl">The ArgumentDeclarationList node.</param> 395 /// <param name="adl">The ArgumentDeclarationList node.</param>
390 /// <returns>String containing C# code for ArgumentDeclarationList adl.</returns> 396 /// <returns>String containing C# code for ArgumentDeclarationList adl.</returns>
391 private string GenerateArgumentDeclarationList(ArgumentDeclarationList adl) 397 private void GenerateArgumentDeclarationList(ArgumentDeclarationList adl, StringBuilder sb)
392 { 398 {
393 string retstr = String.Empty;
394
395 int comma = adl.kids.Count - 1; // tells us whether to print a comma 399 int comma = adl.kids.Count - 1; // tells us whether to print a comma
396 400
397 foreach (Declaration d in adl.kids) 401 foreach (Declaration d in adl.kids)
398 { 402 {
399 retstr += Generate(String.Format("{0} {1}", d.Datatype, CheckName(d.Id)), d); 403 Generate(String.Format("{0} {1}", d.Datatype, CheckName(d.Id)), d, sb);
400 if (0 < comma--) 404 if (0 < comma--)
401 retstr += Generate(", "); 405 Generate(", ", sb);
402 } 406 }
403
404 return retstr;
405 } 407 }
406 408
407 /// <summary> 409 /// <summary>
@@ -409,20 +411,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
409 /// </summary> 411 /// </summary>
410 /// <param name="al">The ArgumentList node.</param> 412 /// <param name="al">The ArgumentList node.</param>
411 /// <returns>String containing C# code for ArgumentList al.</returns> 413 /// <returns>String containing C# code for ArgumentList al.</returns>
412 private string GenerateArgumentList(ArgumentList al) 414 private void GenerateArgumentList(ArgumentList al, StringBuilder sb)
413 { 415 {
414 string retstr = String.Empty;
415
416 int comma = al.kids.Count - 1; // tells us whether to print a comma 416 int comma = al.kids.Count - 1; // tells us whether to print a comma
417 417
418 foreach (SYMBOL s in al.kids) 418 foreach (SYMBOL s in al.kids)
419 { 419 {
420 retstr += GenerateNode(al, s); 420 GenerateNodeToSB(al, s, sb);
421 if (0 < comma--) 421 if (0 < comma--)
422 retstr += Generate(", "); 422 Generate(", ", sb);
423 } 423 }
424
425 return retstr;
426 } 424 }
427 425
428 /// <summary> 426 /// <summary>
@@ -430,12 +428,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
430 /// </summary> 428 /// </summary>
431 /// <param name="cs">The CompoundStatement node.</param> 429 /// <param name="cs">The CompoundStatement node.</param>
432 /// <returns>String containing C# code for CompoundStatement cs.</returns> 430 /// <returns>String containing C# code for CompoundStatement cs.</returns>
433 private string GenerateCompoundStatement(SYMBOL previousSymbol, CompoundStatement cs) 431 private void GenerateCompoundStatement(SYMBOL previousSymbol, CompoundStatement cs, StringBuilder sb)
434 { 432 {
435 string retstr = String.Empty;
436
437 // opening brace 433 // opening brace
438 retstr += GenerateIndentedLine("{"); 434 GenerateIndentedLine("{", sb);
439 m_braceCount++; 435 m_braceCount++;
440 436
441 if (m_insertCoopTerminationChecks) 437 if (m_insertCoopTerminationChecks)
@@ -446,17 +442,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
446 || previousSymbol is DoWhileStatement 442 || previousSymbol is DoWhileStatement
447 || previousSymbol is ForLoop 443 || previousSymbol is ForLoop
448 || previousSymbol is StateEvent) 444 || previousSymbol is StateEvent)
449 retstr += GenerateIndentedLine(m_coopTerminationCheck); 445 GenerateIndentedLine(m_coopTerminationCheck, sb);
450 } 446 }
451 447
452 foreach (SYMBOL kid in cs.kids) 448 foreach (SYMBOL kid in cs.kids)
453 retstr += GenerateNode(cs, kid); 449 GenerateNodeToSB(cs, kid, sb);
454 450
455 // closing brace 451 // closing brace
456 m_braceCount--; 452 m_braceCount--;
457 retstr += GenerateIndentedLine("}"); 453 GenerateIndentedLine("}", sb);
458
459 return retstr;
460 } 454 }
461 455
462 /// <summary> 456 /// <summary>
@@ -464,9 +458,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
464 /// </summary> 458 /// </summary>
465 /// <param name="d">The Declaration node.</param> 459 /// <param name="d">The Declaration node.</param>
466 /// <returns>String containing C# code for Declaration d.</returns> 460 /// <returns>String containing C# code for Declaration d.</returns>
467 private string GenerateDeclaration(Declaration d) 461 private void GenerateDeclaration(Declaration d, StringBuilder sb)
468 { 462 {
469 return Generate(String.Format("{0} {1}", d.Datatype, CheckName(d.Id)), d); 463 Generate(String.Format("{0} {1}", d.Datatype, CheckName(d.Id)), d, sb);
470 } 464 }
471 465
472 /// <summary> 466 /// <summary>
@@ -474,7 +468,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
474 /// </summary> 468 /// </summary>
475 /// <param name="s">The Statement node.</param> 469 /// <param name="s">The Statement node.</param>
476 /// <returns>String containing C# code for Statement s.</returns> 470 /// <returns>String containing C# code for Statement s.</returns>
477 private string GenerateStatement(SYMBOL previousSymbol, Statement s) 471 private void GenerateStatement(SYMBOL previousSymbol, Statement s, StringBuilder sb)
478 { 472 {
479 string retstr = String.Empty; 473 string retstr = String.Empty;
480 bool printSemicolon = true; 474 bool printSemicolon = true;
@@ -491,13 +485,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
491 transformToBlock = true; 485 transformToBlock = true;
492 486
493 // FIXME: This will be wrongly indented because the previous for/while/dowhile will have already indented. 487 // FIXME: This will be wrongly indented because the previous for/while/dowhile will have already indented.
494 retstr += GenerateIndentedLine("{"); 488 GenerateIndentedLine("{", sb);
495 489
496 retstr += GenerateIndentedLine(m_coopTerminationCheck); 490 GenerateIndentedLine(m_coopTerminationCheck, sb);
497 } 491 }
498 } 492 }
499 493
500 retstr += Indent(); 494 Indent(sb);
501 495
502 if (0 < s.kids.Count) 496 if (0 < s.kids.Count)
503 { 497 {
@@ -508,19 +502,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
508 // (MONO) error. 502 // (MONO) error.
509 if (!(s.kids.Top is IdentExpression && 1 == s.kids.Count)) 503 if (!(s.kids.Top is IdentExpression && 1 == s.kids.Count))
510 foreach (SYMBOL kid in s.kids) 504 foreach (SYMBOL kid in s.kids)
511 retstr += GenerateNode(s, kid); 505 GenerateNodeToSB(s, kid, sb);
512 } 506 }
513 507
514 if (printSemicolon) 508 if (printSemicolon)
515 retstr += GenerateLine(";"); 509 GenerateLine(";", sb);
516 510
517 if (transformToBlock) 511 if (transformToBlock)
518 { 512 {
519 // FIXME: This will be wrongly indented because the for/while/dowhile is currently handling the unindent 513 // FIXME: This will be wrongly indented because the for/while/dowhile is currently handling the unindent
520 retstr += GenerateIndentedLine("}"); 514 GenerateIndentedLine("}", sb);
521 } 515 }
522
523 return retstr;
524 } 516 }
525 517
526 /// <summary> 518 /// <summary>
@@ -528,19 +520,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
528 /// </summary> 520 /// </summary>
529 /// <param name="a">The Assignment node.</param> 521 /// <param name="a">The Assignment node.</param>
530 /// <returns>String containing C# code for Assignment a.</returns> 522 /// <returns>String containing C# code for Assignment a.</returns>
531 private string GenerateAssignment(Assignment a) 523 private void GenerateAssignment(Assignment a, StringBuilder sb)
532 { 524 {
533 string retstr = String.Empty;
534
535 List<string> identifiers = new List<string>(); 525 List<string> identifiers = new List<string>();
536 checkForMultipleAssignments(identifiers, a); 526 checkForMultipleAssignments(identifiers, a);
537 527
538 retstr += GenerateNode(a, (SYMBOL) a.kids.Pop()); 528 GenerateNodeToSB(a, (SYMBOL) a.kids.Pop(), sb);
539 retstr += Generate(String.Format(" {0} ", a.AssignmentType), a); 529 Generate(String.Format(" {0} ", a.AssignmentType), a, sb);
540 foreach (SYMBOL kid in a.kids) 530 foreach (SYMBOL kid in a.kids)
541 retstr += GenerateNode(a, kid); 531 GenerateNodeToSB(a, kid, sb);
542
543 return retstr;
544 } 532 }
545 533
546 // This code checks for LSL of the following forms, and generates a 534 // This code checks for LSL of the following forms, and generates a
@@ -604,16 +592,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
604 /// </summary> 592 /// </summary>
605 /// <param name="rs">The ReturnStatement node.</param> 593 /// <param name="rs">The ReturnStatement node.</param>
606 /// <returns>String containing C# code for ReturnStatement rs.</returns> 594 /// <returns>String containing C# code for ReturnStatement rs.</returns>
607 private string GenerateReturnStatement(ReturnStatement rs) 595 private void GenerateReturnStatement(ReturnStatement rs, StringBuilder sb)
608 { 596 {
609 string retstr = String.Empty; 597 Generate("return ", rs, sb);
610
611 retstr += Generate("return ", rs);
612 598
613 foreach (SYMBOL kid in rs.kids) 599 foreach (SYMBOL kid in rs.kids)
614 retstr += GenerateNode(rs, kid); 600 GenerateNodeToSB(rs, kid, sb);
615
616 return retstr;
617 } 601 }
618 602
619 /// <summary> 603 /// <summary>
@@ -621,7 +605,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
621 /// </summary> 605 /// </summary>
622 /// <param name="jl">The JumpLabel node.</param> 606 /// <param name="jl">The JumpLabel node.</param>
623 /// <returns>String containing C# code for JumpLabel jl.</returns> 607 /// <returns>String containing C# code for JumpLabel jl.</returns>
624 private string GenerateJumpLabel(JumpLabel jl) 608 private void GenerateJumpLabel(JumpLabel jl, StringBuilder sb)
625 { 609 {
626 string labelStatement; 610 string labelStatement;
627 611
@@ -630,7 +614,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
630 else 614 else
631 labelStatement = "NoOp();"; 615 labelStatement = "NoOp();";
632 616
633 return GenerateLine(String.Format("{0}: {1}", CheckName(jl.LabelName), labelStatement), jl); 617 GenerateLine(String.Format("{0}: {1}", CheckName(jl.LabelName), labelStatement), jl, sb);
634 } 618 }
635 619
636 /// <summary> 620 /// <summary>
@@ -638,9 +622,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
638 /// </summary> 622 /// </summary>
639 /// <param name="js">The JumpStatement node.</param> 623 /// <param name="js">The JumpStatement node.</param>
640 /// <returns>String containing C# code for JumpStatement js.</returns> 624 /// <returns>String containing C# code for JumpStatement js.</returns>
641 private string GenerateJumpStatement(JumpStatement js) 625 private void GenerateJumpStatement(JumpStatement js, StringBuilder sb)
642 { 626 {
643 return Generate(String.Format("goto {0}", CheckName(js.TargetName)), js); 627 Generate(String.Format("goto {0}", CheckName(js.TargetName)), js, sb);
644 } 628 }
645 629
646 /// <summary> 630 /// <summary>
@@ -648,32 +632,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
648 /// </summary> 632 /// </summary>
649 /// <param name="ifs">The IfStatement node.</param> 633 /// <param name="ifs">The IfStatement node.</param>
650 /// <returns>String containing C# code for IfStatement ifs.</returns> 634 /// <returns>String containing C# code for IfStatement ifs.</returns>
651 private string GenerateIfStatement(IfStatement ifs) 635 private void GenerateIfStatement(IfStatement ifs, StringBuilder sb)
652 { 636 {
653 string retstr = String.Empty; 637 GenerateIndented("if (", ifs, sb);
654 638 GenerateNodeToSB(ifs, (SYMBOL) ifs.kids.Pop(), sb);
655 retstr += GenerateIndented("if (", ifs); 639 GenerateLine(")", sb);
656 retstr += GenerateNode(ifs, (SYMBOL) ifs.kids.Pop());
657 retstr += GenerateLine(")");
658 640
659 // CompoundStatement handles indentation itself but we need to do it 641 // CompoundStatement handles indentation itself but we need to do it
660 // otherwise. 642 // otherwise.
661 bool indentHere = ifs.kids.Top is Statement; 643 bool indentHere = ifs.kids.Top is Statement;
662 if (indentHere) m_braceCount++; 644 if (indentHere) m_braceCount++;
663 retstr += GenerateNode(ifs, (SYMBOL) ifs.kids.Pop()); 645 GenerateNodeToSB(ifs, (SYMBOL) ifs.kids.Pop(), sb);
664 if (indentHere) m_braceCount--; 646 if (indentHere) m_braceCount--;
665 647
666 if (0 < ifs.kids.Count) // do it again for an else 648 if (0 < ifs.kids.Count) // do it again for an else
667 { 649 {
668 retstr += GenerateIndentedLine("else", ifs); 650 GenerateIndentedLine("else", ifs, sb);
669 651
670 indentHere = ifs.kids.Top is Statement; 652 indentHere = ifs.kids.Top is Statement;
671 if (indentHere) m_braceCount++; 653 if (indentHere) m_braceCount++;
672 retstr += GenerateNode(ifs, (SYMBOL) ifs.kids.Pop()); 654 GenerateNodeToSB(ifs, (SYMBOL) ifs.kids.Pop(), sb);
673 if (indentHere) m_braceCount--; 655 if (indentHere) m_braceCount--;
674 } 656 }
675
676 return retstr;
677 } 657 }
678 658
679 /// <summary> 659 /// <summary>
@@ -681,9 +661,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
681 /// </summary> 661 /// </summary>
682 /// <param name="sc">The StateChange node.</param> 662 /// <param name="sc">The StateChange node.</param>
683 /// <returns>String containing C# code for StateChange sc.</returns> 663 /// <returns>String containing C# code for StateChange sc.</returns>
684 private string GenerateStateChange(StateChange sc) 664 private void GenerateStateChange(StateChange sc, StringBuilder sb)
685 { 665 {
686 return Generate(String.Format("state(\"{0}\")", sc.NewState), sc); 666 Generate(String.Format("state(\"{0}\")", sc.NewState), sc, sb);
687 } 667 }
688 668
689 /// <summary> 669 /// <summary>
@@ -691,22 +671,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
691 /// </summary> 671 /// </summary>
692 /// <param name="ws">The WhileStatement node.</param> 672 /// <param name="ws">The WhileStatement node.</param>
693 /// <returns>String containing C# code for WhileStatement ws.</returns> 673 /// <returns>String containing C# code for WhileStatement ws.</returns>
694 private string GenerateWhileStatement(WhileStatement ws) 674 private void GenerateWhileStatement(WhileStatement ws, StringBuilder sb)
695 { 675 {
696 string retstr = String.Empty; 676 GenerateIndented("while (", ws, sb);
697 677 GenerateNodeToSB(ws, (SYMBOL) ws.kids.Pop(), sb);
698 retstr += GenerateIndented("while (", ws); 678 GenerateLine(")", sb);
699 retstr += GenerateNode(ws, (SYMBOL) ws.kids.Pop());
700 retstr += GenerateLine(")");
701 679
702 // CompoundStatement handles indentation itself but we need to do it 680 // CompoundStatement handles indentation itself but we need to do it
703 // otherwise. 681 // otherwise.
704 bool indentHere = ws.kids.Top is Statement; 682 bool indentHere = ws.kids.Top is Statement;
705 if (indentHere) m_braceCount++; 683 if (indentHere) m_braceCount++;
706 retstr += GenerateNode(ws, (SYMBOL) ws.kids.Pop()); 684 GenerateNodeToSB(ws, (SYMBOL) ws.kids.Pop(), sb);
707 if (indentHere) m_braceCount--; 685 if (indentHere) m_braceCount--;
708
709 return retstr;
710 } 686 }
711 687
712 /// <summary> 688 /// <summary>
@@ -714,24 +690,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
714 /// </summary> 690 /// </summary>
715 /// <param name="dws">The DoWhileStatement node.</param> 691 /// <param name="dws">The DoWhileStatement node.</param>
716 /// <returns>String containing C# code for DoWhileStatement dws.</returns> 692 /// <returns>String containing C# code for DoWhileStatement dws.</returns>
717 private string GenerateDoWhileStatement(DoWhileStatement dws) 693 private void GenerateDoWhileStatement(DoWhileStatement dws, StringBuilder sb)
718 { 694 {
719 string retstr = String.Empty; 695 GenerateIndentedLine("do", dws, sb);
720
721 retstr += GenerateIndentedLine("do", dws);
722 696
723 // CompoundStatement handles indentation itself but we need to do it 697 // CompoundStatement handles indentation itself but we need to do it
724 // otherwise. 698 // otherwise.
725 bool indentHere = dws.kids.Top is Statement; 699 bool indentHere = dws.kids.Top is Statement;
726 if (indentHere) m_braceCount++; 700 if (indentHere) m_braceCount++;
727 retstr += GenerateNode(dws, (SYMBOL) dws.kids.Pop()); 701 GenerateNodeToSB(dws, (SYMBOL) dws.kids.Pop(), sb);
728 if (indentHere) m_braceCount--; 702 if (indentHere) m_braceCount--;
729 703
730 retstr += GenerateIndented("while (", dws); 704 GenerateIndented("while (", dws ,sb);
731 retstr += GenerateNode(dws, (SYMBOL) dws.kids.Pop()); 705 GenerateNodeToSB(dws, (SYMBOL) dws.kids.Pop(), sb);
732 retstr += GenerateLine(");"); 706 GenerateLine(");", sb);
733
734 return retstr;
735 } 707 }
736 708
737 /// <summary> 709 /// <summary>
@@ -739,11 +711,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
739 /// </summary> 711 /// </summary>
740 /// <param name="fl">The ForLoop node.</param> 712 /// <param name="fl">The ForLoop node.</param>
741 /// <returns>String containing C# code for ForLoop fl.</returns> 713 /// <returns>String containing C# code for ForLoop fl.</returns>
742 private string GenerateForLoop(ForLoop fl) 714 private void GenerateForLoop(ForLoop fl, StringBuilder sb)
743 { 715 {
744 string retstr = String.Empty; 716 GenerateIndented("for (", fl, sb);
745
746 retstr += GenerateIndented("for (", fl);
747 717
748 // It's possible that we don't have an assignment, in which case 718 // It's possible that we don't have an assignment, in which case
749 // the child will be null and we only print the semicolon. 719 // the child will be null and we only print the semicolon.
@@ -752,26 +722,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
752 ForLoopStatement s = (ForLoopStatement) fl.kids.Pop(); 722 ForLoopStatement s = (ForLoopStatement) fl.kids.Pop();
753 if (null != s) 723 if (null != s)
754 { 724 {
755 retstr += GenerateForLoopStatement(s); 725 GenerateForLoopStatement(s, sb);
756 } 726 }
757 retstr += Generate("; "); 727 Generate("; ", sb);
758 // for (x = 0; x < 10; x++) 728 // for (x = 0; x < 10; x++)
759 // ^^^^^^ 729 // ^^^^^^
760 retstr += GenerateNode(fl, (SYMBOL) fl.kids.Pop()); 730 GenerateNodeToSB(fl, (SYMBOL) fl.kids.Pop(), sb);
761 retstr += Generate("; "); 731 Generate("; ", sb);
762 // for (x = 0; x < 10; x++) 732 // for (x = 0; x < 10; x++)
763 // ^^^ 733 // ^^^
764 retstr += GenerateForLoopStatement((ForLoopStatement) fl.kids.Pop()); 734 GenerateForLoopStatement((ForLoopStatement) fl.kids.Pop(), sb);
765 retstr += GenerateLine(")"); 735 GenerateLine(")", sb);
766 736
767 // CompoundStatement handles indentation itself but we need to do it 737 // CompoundStatement handles indentation itself but we need to do it
768 // otherwise. 738 // otherwise.
769 bool indentHere = fl.kids.Top is Statement; 739 bool indentHere = fl.kids.Top is Statement;
770 if (indentHere) m_braceCount++; 740 if (indentHere) m_braceCount++;
771 retstr += GenerateNode(fl, (SYMBOL) fl.kids.Pop()); 741 GenerateNodeToSB(fl, (SYMBOL) fl.kids.Pop(), sb);
772 if (indentHere) m_braceCount--; 742 if (indentHere) m_braceCount--;
773
774 return retstr;
775 } 743 }
776 744
777 /// <summary> 745 /// <summary>
@@ -779,10 +747,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
779 /// </summary> 747 /// </summary>
780 /// <param name="fls">The ForLoopStatement node.</param> 748 /// <param name="fls">The ForLoopStatement node.</param>
781 /// <returns>String containing C# code for ForLoopStatement fls.</returns> 749 /// <returns>String containing C# code for ForLoopStatement fls.</returns>
782 private string GenerateForLoopStatement(ForLoopStatement fls) 750 private void GenerateForLoopStatement(ForLoopStatement fls, StringBuilder sb)
783 { 751 {
784 string retstr = String.Empty;
785
786 int comma = fls.kids.Count - 1; // tells us whether to print a comma 752 int comma = fls.kids.Count - 1; // tells us whether to print a comma
787 753
788 // It's possible that all we have is an empty Ident, for example: 754 // It's possible that all we have is an empty Ident, for example:
@@ -791,7 +757,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
791 // 757 //
792 // Which is illegal in C# (MONO). We'll skip it. 758 // Which is illegal in C# (MONO). We'll skip it.
793 if (fls.kids.Top is IdentExpression && 1 == fls.kids.Count) 759 if (fls.kids.Top is IdentExpression && 1 == fls.kids.Count)
794 return retstr; 760 return;
795 761
796 for (int i = 0; i < fls.kids.Count; i++) 762 for (int i = 0; i < fls.kids.Count; i++)
797 { 763 {
@@ -813,12 +779,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
813 while (s is ParenthesisExpression) 779 while (s is ParenthesisExpression)
814 s = (SYMBOL)s.kids.Pop(); 780 s = (SYMBOL)s.kids.Pop();
815 781
816 retstr += GenerateNode(fls, s); 782 GenerateNodeToSB(fls, s, sb);
817 if (0 < comma--) 783 if (0 < comma--)
818 retstr += Generate(", "); 784 Generate(", ", sb);
819 } 785 }
820
821 return retstr;
822 } 786 }
823 787
824 /// <summary> 788 /// <summary>
@@ -826,31 +790,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
826 /// </summary> 790 /// </summary>
827 /// <param name="be">The BinaryExpression node.</param> 791 /// <param name="be">The BinaryExpression node.</param>
828 /// <returns>String containing C# code for BinaryExpression be.</returns> 792 /// <returns>String containing C# code for BinaryExpression be.</returns>
829 private string GenerateBinaryExpression(BinaryExpression be) 793 private void GenerateBinaryExpression(BinaryExpression be, StringBuilder sb)
830 { 794 {
831 string retstr = String.Empty;
832
833 if (be.ExpressionSymbol.Equals("&&") || be.ExpressionSymbol.Equals("||")) 795 if (be.ExpressionSymbol.Equals("&&") || be.ExpressionSymbol.Equals("||"))
834 { 796 {
835 // special case handling for logical and/or, see Mantis 3174 797 // special case handling for logical and/or, see Mantis 3174
836 retstr += "((bool)("; 798 sb.Append("((bool)(");
837 retstr += GenerateNode(be, (SYMBOL)be.kids.Pop()); 799 GenerateNodeToSB(be, (SYMBOL)be.kids.Pop(), sb);
838 retstr += "))"; 800 sb.Append("))");
839 retstr += Generate(String.Format(" {0} ", be.ExpressionSymbol.Substring(0,1)), be); 801 Generate(String.Format(" {0} ", be.ExpressionSymbol.Substring(0,1)), be, sb);
840 retstr += "((bool)("; 802 sb.Append("((bool)(");
841 foreach (SYMBOL kid in be.kids) 803 foreach (SYMBOL kid in be.kids)
842 retstr += GenerateNode(be, kid); 804 GenerateNodeToSB(be, kid, sb);
843 retstr += "))"; 805 sb.Append("))");
844 } 806 }
845 else 807 else
846 { 808 {
847 retstr += GenerateNode(be, (SYMBOL)be.kids.Pop()); 809 GenerateNodeToSB(be, (SYMBOL)be.kids.Pop(), sb);
848 retstr += Generate(String.Format(" {0} ", be.ExpressionSymbol), be); 810 Generate(String.Format(" {0} ", be.ExpressionSymbol), be, sb);
849 foreach (SYMBOL kid in be.kids) 811 foreach (SYMBOL kid in be.kids)
850 retstr += GenerateNode(be, kid); 812 GenerateNodeToSB(be, kid, sb);
851 } 813 }
852
853 return retstr;
854 } 814 }
855 815
856 /// <summary> 816 /// <summary>
@@ -858,14 +818,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
858 /// </summary> 818 /// </summary>
859 /// <param name="ue">The UnaryExpression node.</param> 819 /// <param name="ue">The UnaryExpression node.</param>
860 /// <returns>String containing C# code for UnaryExpression ue.</returns> 820 /// <returns>String containing C# code for UnaryExpression ue.</returns>
861 private string GenerateUnaryExpression(UnaryExpression ue) 821 private void GenerateUnaryExpression(UnaryExpression ue, StringBuilder sb)
862 { 822 {
863 string retstr = String.Empty; 823 Generate(ue.UnarySymbol, ue, sb);
864 824 GenerateNodeToSB(ue, (SYMBOL) ue.kids.Pop(), sb);
865 retstr += Generate(ue.UnarySymbol, ue);
866 retstr += GenerateNode(ue, (SYMBOL) ue.kids.Pop());
867
868 return retstr;
869 } 825 }
870 826
871 /// <summary> 827 /// <summary>
@@ -873,16 +829,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
873 /// </summary> 829 /// </summary>
874 /// <param name="pe">The ParenthesisExpression node.</param> 830 /// <param name="pe">The ParenthesisExpression node.</param>
875 /// <returns>String containing C# code for ParenthesisExpression pe.</returns> 831 /// <returns>String containing C# code for ParenthesisExpression pe.</returns>
876 private string GenerateParenthesisExpression(ParenthesisExpression pe) 832 private void GenerateParenthesisExpression(ParenthesisExpression pe, StringBuilder sb)
877 { 833 {
878 string retstr = String.Empty; 834 string retstr = String.Empty;
879 835
880 retstr += Generate("("); 836 Generate("(", sb);
881 foreach (SYMBOL kid in pe.kids) 837 foreach (SYMBOL kid in pe.kids)
882 retstr += GenerateNode(pe, kid); 838 GenerateNodeToSB(pe, kid, sb);
883 retstr += Generate(")"); 839 Generate(")", sb);
884
885 return retstr;
886 } 840 }
887 841
888 /// <summary> 842 /// <summary>
@@ -890,19 +844,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
890 /// </summary> 844 /// </summary>
891 /// <param name="ide">The IncrementDecrementExpression node.</param> 845 /// <param name="ide">The IncrementDecrementExpression node.</param>
892 /// <returns>String containing C# code for IncrementDecrementExpression ide.</returns> 846 /// <returns>String containing C# code for IncrementDecrementExpression ide.</returns>
893 private string GenerateIncrementDecrementExpression(IncrementDecrementExpression ide) 847 private void GenerateIncrementDecrementExpression(IncrementDecrementExpression ide, StringBuilder sb)
894 { 848 {
895 string retstr = String.Empty;
896
897 if (0 < ide.kids.Count) 849 if (0 < ide.kids.Count)
898 { 850 {
899 IdentDotExpression dot = (IdentDotExpression) ide.kids.Top; 851 IdentDotExpression dot = (IdentDotExpression) ide.kids.Top;
900 retstr += Generate(String.Format("{0}", ide.PostOperation ? CheckName(dot.Name) + "." + dot.Member + ide.Operation : ide.Operation + CheckName(dot.Name) + "." + dot.Member), ide); 852 Generate(String.Format("{0}", ide.PostOperation ? CheckName(dot.Name) + "." + dot.Member + ide.Operation : ide.Operation + CheckName(dot.Name) + "." + dot.Member), ide, sb);
901 } 853 }
902 else 854 else
903 retstr += Generate(String.Format("{0}", ide.PostOperation ? CheckName(ide.Name) + ide.Operation : ide.Operation + CheckName(ide.Name)), ide); 855 Generate(String.Format("{0}", ide.PostOperation ? CheckName(ide.Name) + ide.Operation : ide.Operation + CheckName(ide.Name)), ide, sb);
904
905 return retstr;
906 } 856 }
907 857
908 /// <summary> 858 /// <summary>
@@ -910,16 +860,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
910 /// </summary> 860 /// </summary>
911 /// <param name="te">The TypecastExpression node.</param> 861 /// <param name="te">The TypecastExpression node.</param>
912 /// <returns>String containing C# code for TypecastExpression te.</returns> 862 /// <returns>String containing C# code for TypecastExpression te.</returns>
913 private string GenerateTypecastExpression(TypecastExpression te) 863 private void GenerateTypecastExpression(TypecastExpression te, StringBuilder sb)
914 { 864 {
915 string retstr = String.Empty;
916
917 // we wrap all typecasted statements in parentheses 865 // we wrap all typecasted statements in parentheses
918 retstr += Generate(String.Format("({0}) (", te.TypecastType), te); 866 Generate(String.Format("({0}) (", te.TypecastType), te, sb);
919 retstr += GenerateNode(te, (SYMBOL) te.kids.Pop()); 867 GenerateNodeToSB(te, (SYMBOL) te.kids.Pop(), sb);
920 retstr += Generate(")"); 868 Generate(")", sb);
921
922 return retstr;
923 } 869 }
924 870
925 /// <summary> 871 /// <summary>
@@ -928,7 +874,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
928 /// <param name="id">The symbol name</param> 874 /// <param name="id">The symbol name</param>
929 /// <param name="s">The Symbol node.</param> 875 /// <param name="s">The Symbol node.</param>
930 /// <returns>String containing C# code for identifier reference.</returns> 876 /// <returns>String containing C# code for identifier reference.</returns>
931 private string GenerateIdentifier(string id, SYMBOL s) 877 private void GenerateIdentifier(string id, SYMBOL s, StringBuilder sb)
932 { 878 {
933 if (m_comms != null) 879 if (m_comms != null)
934 { 880 {
@@ -950,11 +896,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
950 retval = String.Format("new LSL_Types.Quaternion(\"{0}\")",((OpenMetaverse.Quaternion)value).ToString()); 896 retval = String.Format("new LSL_Types.Quaternion(\"{0}\")",((OpenMetaverse.Quaternion)value).ToString());
951 else retval = id; 897 else retval = id;
952 898
953 return Generate(retval, s); 899 Generate(retval, s, sb);
900 return;
954 } 901 }
955 } 902 }
956 903
957 return Generate(CheckName(id), s); 904 Generate(CheckName(id), s, sb);
905 return;
958 } 906 }
959 907
960 /// <summary> 908 /// <summary>
@@ -962,10 +910,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
962 /// </summary> 910 /// </summary>
963 /// <param name="fc">The FunctionCall node.</param> 911 /// <param name="fc">The FunctionCall node.</param>
964 /// <returns>String containing C# code for FunctionCall fc.</returns> 912 /// <returns>String containing C# code for FunctionCall fc.</returns>
965 private string GenerateFunctionCall(FunctionCall fc) 913 private void GenerateFunctionCall(FunctionCall fc, StringBuilder sb)
966 { 914 {
967 string retstr = String.Empty;
968
969 string modinvoke = null; 915 string modinvoke = null;
970 if (m_comms != null) 916 if (m_comms != null)
971 modinvoke = m_comms.LookupModInvocation(fc.Id); 917 modinvoke = m_comms.LookupModInvocation(fc.Id);
@@ -975,22 +921,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
975 if (fc.kids[0] is ArgumentList) 921 if (fc.kids[0] is ArgumentList)
976 { 922 {
977 if ((fc.kids[0] as ArgumentList).kids.Count == 0) 923 if ((fc.kids[0] as ArgumentList).kids.Count == 0)
978 retstr += Generate(String.Format("{0}(\"{1}\"",modinvoke,fc.Id), fc); 924 Generate(String.Format("{0}(\"{1}\"",modinvoke,fc.Id), fc, sb);
979 else 925 else
980 retstr += Generate(String.Format("{0}(\"{1}\",",modinvoke,fc.Id), fc); 926 Generate(String.Format("{0}(\"{1}\",",modinvoke,fc.Id), fc, sb);
981 } 927 }
982 } 928 }
983 else 929 else
984 { 930 {
985 retstr += Generate(String.Format("{0}(", CheckName(fc.Id)), fc); 931 Generate(String.Format("{0}(", CheckName(fc.Id)), fc, sb);
986 } 932 }
987 933
988 foreach (SYMBOL kid in fc.kids) 934 foreach (SYMBOL kid in fc.kids)
989 retstr += GenerateNode(fc, kid); 935 GenerateNodeToSB(fc, kid, sb);
990 936
991 retstr += Generate(")"); 937 Generate(")", sb);
992
993 return retstr;
994 } 938 }
995 939
996 /// <summary> 940 /// <summary>
@@ -998,10 +942,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
998 /// </summary> 942 /// </summary>
999 /// <param name="c">The Constant node.</param> 943 /// <param name="c">The Constant node.</param>
1000 /// <returns>String containing C# code for Constant c.</returns> 944 /// <returns>String containing C# code for Constant c.</returns>
1001 private string GenerateConstant(Constant c) 945 private void GenerateConstant(Constant c, StringBuilder sb)
1002 { 946 {
1003 string retstr = String.Empty;
1004
1005 // Supprt LSL's weird acceptance of floats with no trailing digits 947 // Supprt LSL's weird acceptance of floats with no trailing digits
1006 // after the period. Turn float x = 10.; into float x = 10.0; 948 // after the period. Turn float x = 10.; into float x = 10.0;
1007 if ("LSL_Types.LSLFloat" == c.Type) 949 if ("LSL_Types.LSLFloat" == c.Type)
@@ -1020,9 +962,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1020 c.Value = "new LSL_Types.LSLString(\""+c.Value+"\")"; 962 c.Value = "new LSL_Types.LSLString(\""+c.Value+"\")";
1021 } 963 }
1022 964
1023 retstr += Generate(c.Value, c); 965 Generate(c.Value, c, sb);
1024
1025 return retstr;
1026 } 966 }
1027 967
1028 /// <summary> 968 /// <summary>
@@ -1030,19 +970,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1030 /// </summary> 970 /// </summary>
1031 /// <param name="vc">The VectorConstant node.</param> 971 /// <param name="vc">The VectorConstant node.</param>
1032 /// <returns>String containing C# code for VectorConstant vc.</returns> 972 /// <returns>String containing C# code for VectorConstant vc.</returns>
1033 private string GenerateVectorConstant(VectorConstant vc) 973 private void GenerateVectorConstant(VectorConstant vc, StringBuilder sb)
1034 { 974 {
1035 string retstr = String.Empty; 975 Generate(String.Format("new {0}(", vc.Type), vc, sb);
1036 976 GenerateNodeToSB(vc, (SYMBOL) vc.kids.Pop(), sb);
1037 retstr += Generate(String.Format("new {0}(", vc.Type), vc); 977 Generate(", ", sb);
1038 retstr += GenerateNode(vc, (SYMBOL) vc.kids.Pop()); 978 GenerateNodeToSB(vc, (SYMBOL) vc.kids.Pop(), sb);
1039 retstr += Generate(", "); 979 Generate(", ", sb);
1040 retstr += GenerateNode(vc, (SYMBOL) vc.kids.Pop()); 980 GenerateNodeToSB(vc, (SYMBOL) vc.kids.Pop(), sb);
1041 retstr += Generate(", "); 981 Generate(")", sb);
1042 retstr += GenerateNode(vc, (SYMBOL) vc.kids.Pop());
1043 retstr += Generate(")");
1044
1045 return retstr;
1046 } 982 }
1047 983
1048 /// <summary> 984 /// <summary>
@@ -1050,21 +986,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1050 /// </summary> 986 /// </summary>
1051 /// <param name="rc">The RotationConstant node.</param> 987 /// <param name="rc">The RotationConstant node.</param>
1052 /// <returns>String containing C# code for RotationConstant rc.</returns> 988 /// <returns>String containing C# code for RotationConstant rc.</returns>
1053 private string GenerateRotationConstant(RotationConstant rc) 989 private void GenerateRotationConstant(RotationConstant rc, StringBuilder sb)
1054 { 990 {
1055 string retstr = String.Empty; 991 Generate(String.Format("new {0}(", rc.Type), rc, sb);
1056 992 GenerateNodeToSB(rc, (SYMBOL) rc.kids.Pop(), sb);
1057 retstr += Generate(String.Format("new {0}(", rc.Type), rc); 993 Generate(", ", sb);
1058 retstr += GenerateNode(rc, (SYMBOL) rc.kids.Pop()); 994 GenerateNodeToSB(rc, (SYMBOL) rc.kids.Pop(), sb);
1059 retstr += Generate(", "); 995 Generate(", ", sb);
1060 retstr += GenerateNode(rc, (SYMBOL) rc.kids.Pop()); 996 GenerateNodeToSB(rc, (SYMBOL) rc.kids.Pop(), sb);
1061 retstr += Generate(", "); 997 Generate(", ", sb);
1062 retstr += GenerateNode(rc, (SYMBOL) rc.kids.Pop()); 998 GenerateNodeToSB(rc, (SYMBOL) rc.kids.Pop(), sb);
1063 retstr += Generate(", "); 999 Generate(")", sb);
1064 retstr += GenerateNode(rc, (SYMBOL) rc.kids.Pop());
1065 retstr += Generate(")");
1066
1067 return retstr;
1068 } 1000 }
1069 1001
1070 /// <summary> 1002 /// <summary>
@@ -1072,27 +1004,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1072 /// </summary> 1004 /// </summary>
1073 /// <param name="lc">The ListConstant node.</param> 1005 /// <param name="lc">The ListConstant node.</param>
1074 /// <returns>String containing C# code for ListConstant lc.</returns> 1006 /// <returns>String containing C# code for ListConstant lc.</returns>
1075 private string GenerateListConstant(ListConstant lc) 1007 private void GenerateListConstant(ListConstant lc, StringBuilder sb)
1076 { 1008 {
1077 string retstr = String.Empty; 1009 Generate(String.Format("new {0}(", lc.Type), lc, sb);
1078
1079 retstr += Generate(String.Format("new {0}(", lc.Type), lc);
1080 1010
1081 foreach (SYMBOL kid in lc.kids) 1011 foreach (SYMBOL kid in lc.kids)
1082 retstr += GenerateNode(lc, kid); 1012 GenerateNodeToSB(lc, kid, sb);
1083
1084 retstr += Generate(")");
1085 1013
1086 return retstr; 1014 Generate(")", sb);
1087 } 1015 }
1088 1016
1089 /// <summary> 1017 /// <summary>
1090 /// Prints a newline. 1018 /// Prints a newline.
1091 /// </summary> 1019 /// </summary>
1092 /// <returns>A newline.</returns> 1020 /// <returns>A newline.</returns>
1093 private string GenerateLine() 1021 private void GenerateLine(StringBuilder sb)
1094 { 1022 {
1095 return GenerateLine(""); 1023 sb.Append("\n");
1096 } 1024 }
1097 1025
1098 /// <summary> 1026 /// <summary>
@@ -1100,9 +1028,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1100 /// </summary> 1028 /// </summary>
1101 /// <param name="s">String of text to print.</param> 1029 /// <param name="s">String of text to print.</param>
1102 /// <returns>String s followed by newline.</returns> 1030 /// <returns>String s followed by newline.</returns>
1103 private string GenerateLine(string s) 1031 private void GenerateLine(string s, StringBuilder sb)
1104 { 1032 {
1105 return GenerateLine(s, null); 1033 sb.Append(s);
1034 sb.Append("\n");
1106 } 1035 }
1107 1036
1108 /// <summary> 1037 /// <summary>
@@ -1112,14 +1041,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1112 /// <param name="sym">Symbol being generated to extract original line 1041 /// <param name="sym">Symbol being generated to extract original line
1113 /// number and column from.</param> 1042 /// number and column from.</param>
1114 /// <returns>String s followed by newline.</returns> 1043 /// <returns>String s followed by newline.</returns>
1115 private string GenerateLine(string s, SYMBOL sym) 1044 private void GenerateLine(string s, SYMBOL sym, StringBuilder sb)
1116 { 1045 {
1117 string retstr = Generate(s, sym) + "\n"; 1046 Generate(s, sym, sb);
1047 sb.Append("\n");
1118 1048
1119 m_CSharpLine++; 1049 m_CSharpLine++;
1120 m_CSharpCol = 1; 1050 m_CSharpCol = 1;
1121
1122 return retstr;
1123 } 1051 }
1124 1052
1125 /// <summary> 1053 /// <summary>
@@ -1127,9 +1055,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1127 /// </summary> 1055 /// </summary>
1128 /// <param name="s">String of text to print.</param> 1056 /// <param name="s">String of text to print.</param>
1129 /// <returns>String s.</returns> 1057 /// <returns>String s.</returns>
1130 private string Generate(string s) 1058 private void Generate(string s, StringBuilder sb)
1131 { 1059 {
1132 return Generate(s, null); 1060 sb.Append(s);
1061 m_CSharpCol += s.Length;
1133 } 1062 }
1134 1063
1135 /// <summary> 1064 /// <summary>
@@ -1139,14 +1068,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1139 /// <param name="sym">Symbol being generated to extract original line 1068 /// <param name="sym">Symbol being generated to extract original line
1140 /// number and column from.</param> 1069 /// number and column from.</param>
1141 /// <returns>String s.</returns> 1070 /// <returns>String s.</returns>
1142 private string Generate(string s, SYMBOL sym) 1071 private void Generate(string s, SYMBOL sym, StringBuilder sb)
1143 { 1072 {
1073 sb.Append(s);
1144 if (null != sym) 1074 if (null != sym)
1145 m_positionMap.Add(new KeyValuePair<int, int>(m_CSharpLine, m_CSharpCol), new KeyValuePair<int, int>(sym.Line, sym.Position)); 1075 m_positionMap.Add(new KeyValuePair<int, int>(m_CSharpLine, m_CSharpCol), new KeyValuePair<int, int>(sym.Line, sym.Position));
1146 1076
1147 m_CSharpCol += s.Length; 1077 m_CSharpCol += s.Length;
1148
1149 return s;
1150 } 1078 }
1151 1079
1152 /// <summary> 1080 /// <summary>
@@ -1154,9 +1082,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1154 /// </summary> 1082 /// </summary>
1155 /// <param name="s">String of text to print.</param> 1083 /// <param name="s">String of text to print.</param>
1156 /// <returns>Properly indented string s followed by newline.</returns> 1084 /// <returns>Properly indented string s followed by newline.</returns>
1157 private string GenerateIndentedLine(string s) 1085 private void GenerateIndentedLine(string s, StringBuilder sb)
1158 { 1086 {
1159 return GenerateIndentedLine(s, null); 1087 GenerateIndentedLine(s, null, sb);
1160 } 1088 }
1161 1089
1162 /// <summary> 1090 /// <summary>
@@ -1166,14 +1094,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1166 /// <param name="sym">Symbol being generated to extract original line 1094 /// <param name="sym">Symbol being generated to extract original line
1167 /// number and column from.</param> 1095 /// number and column from.</param>
1168 /// <returns>Properly indented string s followed by newline.</returns> 1096 /// <returns>Properly indented string s followed by newline.</returns>
1169 private string GenerateIndentedLine(string s, SYMBOL sym) 1097 private void GenerateIndentedLine(string s, SYMBOL sym, StringBuilder sb)
1170 { 1098 {
1171 string retstr = GenerateIndented(s, sym) + "\n"; 1099 GenerateIndented(s, sym , sb );
1172 1100 sb.Append("\n");
1173 m_CSharpLine++; 1101 m_CSharpLine++;
1174 m_CSharpCol = 1; 1102 m_CSharpCol = 1;
1175
1176 return retstr;
1177 } 1103 }
1178 1104
1179 /// <summary> 1105 /// <summary>
@@ -1194,34 +1120,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
1194 /// <param name="sym">Symbol being generated to extract original line 1120 /// <param name="sym">Symbol being generated to extract original line
1195 /// number and column from.</param> 1121 /// number and column from.</param>
1196 /// <returns>Properly indented string s.</returns> 1122 /// <returns>Properly indented string s.</returns>
1197 private string GenerateIndented(string s, SYMBOL sym) 1123 private void GenerateIndented(string s, SYMBOL sym, StringBuilder sb)
1198 { 1124 {
1199 string retstr = Indent() + s; 1125 Indent(sb);
1200 1126 sb.Append(s);
1127
1201 if (null != sym) 1128 if (null != sym)
1202 m_positionMap.Add(new KeyValuePair<int, int>(m_CSharpLine, m_CSharpCol), new KeyValuePair<int, int>(sym.Line, sym.Position)); 1129 m_positionMap.Add(new KeyValuePair<int, int>(m_CSharpLine, m_CSharpCol), new KeyValuePair<int, int>(sym.Line, sym.Position));
1203 1130
1204 m_CSharpCol += s.Length; 1131 m_CSharpCol += s.Length;
1205
1206 return retstr;
1207 } 1132 }
1208 1133
1209 /// <summary> 1134 /// <summary>
1210 /// Prints correct indentation. 1135 /// Prints correct indentation.
1211 /// </summary> 1136 /// </summary>
1212 /// <returns>Indentation based on brace count.</returns> 1137 /// <returns>Indentation based on brace count.</returns>
1213 private string Indent() 1138 private void Indent(StringBuilder sb)
1214 { 1139 {
1215 string retstr = String.Empty; 1140 sb.Append(" ");
1216
1217 for (int i = 0; i < m_braceCount; i++)
1218 for (int j = 0; j < m_indentWidth; j++)
1219 {
1220 retstr += " ";
1221 m_CSharpCol++;
1222 }
1223
1224 return retstr;
1225 } 1141 }
1226 1142
1227 /// <summary> 1143 /// <summary>
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
index af324bf..67762a3 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
@@ -81,8 +81,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
81 81
82 // private object m_syncy = new object(); 82 // private object m_syncy = new object();
83 83
84 private static CSharpCodeProvider CScodeProvider = new CSharpCodeProvider(); 84// private static CSharpCodeProvider CScodeProvider = new CSharpCodeProvider();
85 private static VBCodeProvider VBcodeProvider = new VBCodeProvider(); 85// private static VBCodeProvider VBcodeProvider = new VBCodeProvider();
86 86
87 // private static int instanceID = new Random().Next(0, int.MaxValue); // Unique number to use on our compiled files 87 // private static int instanceID = new Random().Next(0, int.MaxValue); // Unique number to use on our compiled files
88 private static UInt64 scriptCompileCounter = 0; // And a counter 88 private static UInt64 scriptCompileCounter = 0; // And a counter
@@ -356,14 +356,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
356 throw new Exception(errtext); 356 throw new Exception(errtext);
357 } 357 }
358 358
359 string compileScript = source; 359 string compileScript = string.Empty;
360 360
361 if (language == enumCompileType.lsl) 361 if (language == enumCompileType.lsl)
362 { 362 {
363 // Its LSL, convert it to C# 363 // Its LSL, convert it to C#
364
365 StringBuilder sb = new StringBuilder(16394);
366
364 LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms, m_insertCoopTerminationCalls); 367 LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms, m_insertCoopTerminationCalls);
365 compileScript = LSL_Converter.Convert(source); 368 AddCSScriptHeader(
369 m_scriptEngine.ScriptClassName,
370 m_scriptEngine.ScriptBaseClassName,
371 m_scriptEngine.ScriptBaseClassParameters,
372 sb);
366 373
374 LSL_Converter.Convert(source,sb);
375 AddCSScriptTail(sb);
376 compileScript = sb.ToString();
367 // copy converter warnings into our warnings. 377 // copy converter warnings into our warnings.
368 foreach (string warning in LSL_Converter.GetWarnings()) 378 foreach (string warning in LSL_Converter.GetWarnings())
369 { 379 {
@@ -374,22 +384,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
374 // Write the linemap to a file and save it in our dictionary for next time. 384 // Write the linemap to a file and save it in our dictionary for next time.
375 m_lineMaps[assembly] = linemap; 385 m_lineMaps[assembly] = linemap;
376 WriteMapFile(assembly + ".map", linemap); 386 WriteMapFile(assembly + ".map", linemap);
387 LSL_Converter.Clear();
377 } 388 }
378 389 else
379 switch (language) 390 {
380 { 391 switch (language)
381 case enumCompileType.cs: 392 {
382 case enumCompileType.lsl: 393 case enumCompileType.cs:
383 compileScript = CreateCSCompilerScript( 394 compileScript = CreateCSCompilerScript(
384 compileScript, 395 compileScript,
385 m_scriptEngine.ScriptClassName, 396 m_scriptEngine.ScriptClassName,
386 m_scriptEngine.ScriptBaseClassName, 397 m_scriptEngine.ScriptBaseClassName,
387 m_scriptEngine.ScriptBaseClassParameters); 398 m_scriptEngine.ScriptBaseClassParameters);
388 break; 399 break;
389 case enumCompileType.vb: 400 case enumCompileType.vb:
390 compileScript = CreateVBCompilerScript( 401 compileScript = CreateVBCompilerScript(
391 compileScript, m_scriptEngine.ScriptClassName, m_scriptEngine.ScriptBaseClassName); 402 compileScript, m_scriptEngine.ScriptClassName, m_scriptEngine.ScriptBaseClassName);
392 break; 403 break;
404 }
393 } 405 }
394 406
395 assembly = CompileFromDotNetText(compileScript, language, asset, assembly); 407 assembly = CompileFromDotNetText(compileScript, language, asset, assembly);
@@ -419,6 +431,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
419// return compileScript; 431// return compileScript;
420// } 432// }
421 433
434 public static void AddCSScriptHeader(string className, string baseClassName, ParameterInfo[] constructorParameters, StringBuilder sb)
435 {
436 sb.Append(string.Format(
437@"using OpenSim.Region.ScriptEngine.Shared;
438using System.Collections.Generic;
439
440namespace SecondLife
441{{
442 public class {0} : {1}
443 {{
444 public {0}({2}) : base({3}) {{}}
445",
446 className,
447 baseClassName,
448 constructorParameters != null
449 ? string.Join(", ", Array.ConvertAll<ParameterInfo, string>(constructorParameters, pi => pi.ToString()))
450 : "",
451 constructorParameters != null
452 ? string.Join(", ", Array.ConvertAll<ParameterInfo, string>(constructorParameters, pi => pi.Name))
453 : ""
454 ));
455 }
456
457 public static void AddCSScriptTail(StringBuilder sb)
458 {
459 sb.Append(string.Format("\n }}\n}}\n"));
460 }
461
422 public static string CreateCSCompilerScript( 462 public static string CreateCSCompilerScript(
423 string compileScript, string className, string baseClassName, ParameterInfo[] constructorParameters) 463 string compileScript, string className, string baseClassName, ParameterInfo[] constructorParameters)
424 { 464 {
@@ -511,8 +551,6 @@ namespace SecondLife
511 // Do actual compile 551 // Do actual compile
512 CompilerParameters parameters = new CompilerParameters(); 552 CompilerParameters parameters = new CompilerParameters();
513 553
514 parameters.IncludeDebugInformation = true;
515
516 string rootPath = AppDomain.CurrentDomain.BaseDirectory; 554 string rootPath = AppDomain.CurrentDomain.BaseDirectory;
517 555
518 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, 556 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
@@ -532,26 +570,44 @@ namespace SecondLife
532 parameters.IncludeDebugInformation = CompileWithDebugInformation; 570 parameters.IncludeDebugInformation = CompileWithDebugInformation;
533 //parameters.WarningLevel = 1; // Should be 4? 571 //parameters.WarningLevel = 1; // Should be 4?
534 parameters.TreatWarningsAsErrors = false; 572 parameters.TreatWarningsAsErrors = false;
535 573 parameters.GenerateInMemory = false;
574
536 CompilerResults results; 575 CompilerResults results;
576
577 CodeDomProvider provider;
537 switch (lang) 578 switch (lang)
538 { 579 {
539 case enumCompileType.vb: 580 case enumCompileType.vb:
540 results = VBcodeProvider.CompileAssemblyFromSource( 581// results = VBcodeProvider.CompileAssemblyFromSource(
541 parameters, Script); 582// parameters, Script);
583 provider = CodeDomProvider.CreateProvider("VisualBasic");
542 break; 584 break;
543 case enumCompileType.cs: 585 case enumCompileType.cs:
544 case enumCompileType.lsl: 586 case enumCompileType.lsl:
587 provider = CodeDomProvider.CreateProvider("CSharp");
588 break;
589 default:
590 throw new Exception("Compiler is not able to recongnize " +
591 "language type \"" + lang.ToString() + "\"");
592 }
593
594 if(provider == null)
595 throw new Exception("Compiler failed to load ");
596
597
545 bool complete = false; 598 bool complete = false;
546 bool retried = false; 599 bool retried = false;
600
547 do 601 do
548 { 602 {
549 lock (CScodeProvider) 603// lock (CScodeProvider)
550 { 604// {
551 results = CScodeProvider.CompileAssemblyFromSource( 605// results = CScodeProvider.CompileAssemblyFromSource(
606// parameters, Script);
607// }
608
609 results = provider.CompileAssemblyFromSource(
552 parameters, Script); 610 parameters, Script);
553 }
554
555 // Deal with an occasional segv in the compiler. 611 // Deal with an occasional segv in the compiler.
556 // Rarely, if ever, occurs twice in succession. 612 // Rarely, if ever, occurs twice in succession.
557 // Line # == 0 and no file name are indications that 613 // Line # == 0 and no file name are indications that
@@ -575,11 +631,11 @@ namespace SecondLife
575 complete = true; 631 complete = true;
576 } 632 }
577 } while (!complete); 633 } while (!complete);
578 break; 634// break;
579 default: 635// default:
580 throw new Exception("Compiler is not able to recongnize " + 636// throw new Exception("Compiler is not able to recongnize " +
581 "language type \"" + lang.ToString() + "\""); 637// "language type \"" + lang.ToString() + "\"");
582 } 638// }
583 639
584// foreach (Type type in results.CompiledAssembly.GetTypes()) 640// foreach (Type type in results.CompiledAssembly.GetTypes())
585// { 641// {
@@ -628,6 +684,8 @@ namespace SecondLife
628 } 684 }
629 } 685 }
630 686
687 provider.Dispose();
688
631 if (hadErrors) 689 if (hadErrors)
632 { 690 {
633 throw new Exception(errtext); 691 throw new Exception(errtext);
@@ -785,15 +843,16 @@ namespace SecondLife
785 843
786 private static void WriteMapFile(string filename, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap) 844 private static void WriteMapFile(string filename, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap)
787 { 845 {
788 string mapstring = String.Empty; 846 StringBuilder mapbuilder = new StringBuilder(1024);
847
789 foreach (KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>> kvp in linemap) 848 foreach (KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>> kvp in linemap)
790 { 849 {
791 KeyValuePair<int, int> k = kvp.Key; 850 KeyValuePair<int, int> k = kvp.Key;
792 KeyValuePair<int, int> v = kvp.Value; 851 KeyValuePair<int, int> v = kvp.Value;
793 mapstring += String.Format("{0},{1},{2},{3}\n", k.Key, k.Value, v.Key, v.Value); 852 mapbuilder.Append(String.Format("{0},{1},{2},{3}\n", k.Key, k.Value, v.Key, v.Value));
794 } 853 }
795 854
796 Byte[] mapbytes = Encoding.ASCII.GetBytes(mapstring); 855 Byte[] mapbytes = Encoding.ASCII.GetBytes(mapbuilder.ToString());
797 856
798 using (FileStream mfs = File.Create(filename)) 857 using (FileStream mfs = File.Create(filename))
799 mfs.Write(mapbytes, 0, mapbytes.Length); 858 mfs.Write(mapbytes, 0, mapbytes.Length);
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs
index 84e8ab2..076caad 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/ICodeConverter.cs
@@ -27,12 +27,15 @@
27*/ 27*/
28 28
29using System; 29using System;
30using System.Text;
30 31
31namespace OpenSim.Region.ScriptEngine.Shared.CodeTools 32namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
32{ 33{
33 public interface ICodeConverter 34 public interface ICodeConverter
34 { 35 {
35 string Convert(string script); 36 string Convert(string script);
37 void Convert(string script, StringBuilder sb);
36 string[] GetWarnings(); 38 string[] GetWarnings();
39 void Clear();
37 } 40 }
38} 41}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 6d78f0e..611df58 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -416,7 +416,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
416 PostEvent(new EventParams("on_rez", 416 PostEvent(new EventParams("on_rez",
417 new Object[] {new LSL_Types.LSLInteger(StartParam)}, new DetectParams[0])); 417 new Object[] {new LSL_Types.LSLInteger(StartParam)}, new DetectParams[0]));
418 } 418 }
419
420 if (m_stateSource == StateSource.AttachedRez) 419 if (m_stateSource == StateSource.AttachedRez)
421 { 420 {
422 PostEvent(new EventParams("attach", 421 PostEvent(new EventParams("attach",
@@ -457,7 +456,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
457 PostEvent(new EventParams("attach", 456 PostEvent(new EventParams("attach",
458 new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0])); 457 new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0]));
459 } 458 }
460
461 } 459 }
462 } 460 }
463 461
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index ecd0b69..f42b5ad 100755
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -1278,6 +1278,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1278 } 1278 }
1279 } 1279 }
1280 1280
1281 // do not load a assembly on top of a lot of to release memory
1282 // also yield a bit
1283 GC.Collect(2);
1284
1281 ScriptInstance instance = null; 1285 ScriptInstance instance = null;
1282 lock (m_Scripts) 1286 lock (m_Scripts)
1283 { 1287 {
@@ -1501,11 +1505,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1501 m_PrimObjects[localID].Add(itemID); 1505 m_PrimObjects[localID].Add(itemID);
1502 } 1506 }
1503 1507
1504 if (!m_Assemblies.ContainsKey(assetID))
1505 m_Assemblies[assetID] = assemblyPath;
1506 1508
1507 lock (m_AddingAssemblies) 1509 lock (m_AddingAssemblies)
1508 { 1510 {
1511 if (!m_Assemblies.ContainsKey(assetID))
1512 m_Assemblies[assetID] = assemblyPath;
1513
1509 m_AddingAssemblies[assemblyPath]--; 1514 m_AddingAssemblies[assemblyPath]--;
1510 } 1515 }
1511 1516