aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCompile.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/MMRScriptCompile.cs (renamed from OpenSim/Region/ScriptEngine/XMREngine/MMRScriptCompile.cs)175
1 files changed, 77 insertions, 98 deletions
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/MMRScriptCompile.cs b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCompile.cs
index 017d2c5..bd7ccc1 100644
--- a/OpenSim/Region/ScriptEngine/XMREngine/MMRScriptCompile.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCompile.cs
@@ -31,12 +31,8 @@
31 31
32using System; 32using System;
33using System.IO; 33using System.IO;
34using System.IO.Compression;
35using System.Reflection;
36using System.Security.Cryptography;
37using System.Text;
38 34
39namespace OpenSim.Region.ScriptEngine.XMREngine 35namespace OpenSim.Region.ScriptEngine.Yengine
40{ 36{
41 public partial class XMRInstance 37 public partial class XMRInstance
42 { 38 {
@@ -45,155 +41,136 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
45 * @returns object code pointer or null if compile error 41 * @returns object code pointer or null if compile error
46 * also can throw compile error exception 42 * also can throw compile error exception
47 */ 43 */
48 public ScriptObjCode Compile () 44 public ScriptObjCode Compile()
49 { 45 {
50 bool oldObjFile = false;
51 Stream objFileStream = null; 46 Stream objFileStream = null;
52 StreamWriter asmFileWriter = null; 47 StreamWriter asmFileWriter = null;
53 string envar = null;
54 string sourceHash = null; 48 string sourceHash = null;
55 TextWriter saveSource = null; 49 TextWriter saveSource = null;
56 50
57 string asmFileName = GetScriptFileName (m_ScriptObjCodeKey + ".xmrasm");
58 string lslFileName = GetScriptFileName (m_ScriptObjCodeKey + ".lsl");
59 string objFileName = GetScriptFileName (m_ScriptObjCodeKey + ".xmrobj"); 51 string objFileName = GetScriptFileName (m_ScriptObjCodeKey + ".xmrobj");
60 string tmpFileName = GetScriptFileName (m_ScriptObjCodeKey + ".xmrtmp"); 52 string tmpFileName = GetScriptFileName (m_ScriptObjCodeKey + ".xmrtmp");
61 53
62 /* 54 // If we already have an object file, don't bother compiling.
63 * If we already have an object file, don't bother compiling. 55 if (!m_ForceRecomp && File.Exists(objFileName))
64 */ 56 {
65 if (!m_ForceRecomp && File.Exists (objFileName)) {
66 objFileStream = File.OpenRead (objFileName); 57 objFileStream = File.OpenRead (objFileName);
67 oldObjFile = true; 58 }
68 } else { 59 else
69 60 {
70 /* 61 // If source file empty, try to read from asset server.
71 * If source file empty, try to read from asset server. 62 if (EmptySource (m_SourceCode))
72 */
73 if (EmptySource (m_SourceCode)) {
74 m_SourceCode = FetchSource (m_CameFrom); 63 m_SourceCode = FetchSource (m_CameFrom);
75 }
76 64
77 /* 65 // Maybe write script source to a file for debugging.
78 * Maybe write script source to a file for debugging. 66 if (m_Engine.m_ScriptDebugSaveSource)
79 */ 67 {
80 envar = Environment.GetEnvironmentVariable ("MMRScriptCompileSaveSource"); 68 string lslFileName = GetScriptFileName (m_ScriptObjCodeKey + ".lsl");
81 if ((envar != null) && ((envar[0] & 1) != 0)) { 69// m_log.Debug ("[YEngine]: MMRScriptCompileSaveSource: saving to " + lslFileName);
82 m_log.Debug ("[XMREngine]: MMRScriptCompileSaveSource: saving to " + lslFileName);
83 saveSource = File.CreateText (lslFileName); 70 saveSource = File.CreateText (lslFileName);
84 } 71 }
85 72
86 /* 73 // Parse source string into tokens.
87 * Parse source string into tokens.
88 */
89 TokenBegin tokenBegin; 74 TokenBegin tokenBegin;
90 try { 75 try
76 {
91 tokenBegin = TokenBegin.Construct(m_CameFrom, saveSource, ErrorHandler, m_SourceCode, out sourceHash); 77 tokenBegin = TokenBegin.Construct(m_CameFrom, saveSource, ErrorHandler, m_SourceCode, out sourceHash);
92 } finally {
93 if (saveSource != null) saveSource.Close ();
94 } 78 }
95 if (tokenBegin == null) { 79 finally
96 m_log.Debug ("[XMREngine]: parsing errors on " + m_ScriptObjCodeKey); 80 {
81 if (saveSource != null)
82 saveSource.Close ();
83 }
84 if (tokenBegin == null)
85 {
86 m_log.Debug ("[YEngine]: parsing errors on " + m_ScriptObjCodeKey);
97 return null; 87 return null;
98 } 88 }
99 89
100 /* 90 // Create object file one way or another.
101 * Create object file one way or another. 91 try
102 */ 92 {
103 try {
104 objFileStream = File.Create (tmpFileName); 93 objFileStream = File.Create (tmpFileName);
105 94
106 /* 95 // Create abstract syntax tree from raw tokens.
107 * Create abstract syntax tree from raw tokens.
108 */
109 TokenScript tokenScript = ScriptReduce.Reduce(tokenBegin); 96 TokenScript tokenScript = ScriptReduce.Reduce(tokenBegin);
110 if (tokenScript == null) { 97 if (tokenScript == null)
111 m_log.Warn ("[XMREngine]: reduction errors on " + m_ScriptObjCodeKey + " (" + m_CameFrom + ")"); 98 {
112 PrintCompilerErrors (); 99 m_log.Warn ("[YEngine]: reduction errors on " + m_ScriptObjCodeKey + " (" + m_CameFrom + ")");
100 PrintCompilerErrors();
101 objFileStream.Close();
113 return null; 102 return null;
114 } 103 }
115 104
116 /* 105 // Compile abstract syntax tree to write object file.
117 * Compile abstract syntax tree to write object file.
118 */
119 BinaryWriter objFileWriter = new BinaryWriter (objFileStream); 106 BinaryWriter objFileWriter = new BinaryWriter (objFileStream);
120 bool ok = ScriptCodeGen.CodeGen(tokenScript, objFileWriter, sourceHash); 107 bool ok = ScriptCodeGen.CodeGen(tokenScript, objFileWriter, sourceHash);
121 if (!ok) { 108 if (!ok)
122 m_log.Warn ("[XMREngine]: compile error on " + m_ScriptObjCodeKey + " (" + m_CameFrom + ")"); 109 {
110 m_log.Warn ("[YEngine]: compile error on " + m_ScriptObjCodeKey + " (" + m_CameFrom + ")");
123 PrintCompilerErrors (); 111 PrintCompilerErrors ();
124 objFileStream.Close (); 112 objFileWriter.Close ();
125 return null; 113 return null;
126 } 114 }
127 objFileStream.Close (); 115 objFileWriter.Close ();
128 116
129 /* 117 // File has been completely written.
130 * File has been completely written. 118 // If there is an old one laying around, delete it now.
131 * If there is an old one laying around, delete it now. 119 // Then re-open the new file for reading from the beginning.
132 * Then re-open the new file for reading from the beginning. 120 if (File.Exists (objFileName))
133 */
134 if (File.Exists (objFileName)) {
135 File.Replace (tmpFileName, objFileName, null); 121 File.Replace (tmpFileName, objFileName, null);
136 } else { 122 else
137 File.Move (tmpFileName, objFileName); 123 File.Move (tmpFileName, objFileName);
138 }
139 objFileStream = File.OpenRead (objFileName);
140 } finally {
141 124
142 /* 125 objFileStream = File.OpenRead (objFileName);
143 * In case something went wrong writing temp file, delete it. 126 }
144 */ 127 finally
145 try { 128 {
129 // In case something went wrong writing temp file, delete it.
130 try
131 {
146 File.Delete (tmpFileName); 132 File.Delete (tmpFileName);
147 } catch { 133 }
134 catch
135 {
148 } 136 }
149 } 137 }
150 138
151 /* 139 // Since we just wrote the .xmrobj file, maybe save disassembly.
152 * Since we just wrote the .xmrobj file, maybe save disassembly. 140 if (m_Engine.m_ScriptDebugSaveIL)
153 */ 141 {
154 envar = Environment.GetEnvironmentVariable ("MMRScriptCompileSaveILGen"); 142 string asmFileName = GetScriptFileName (m_ScriptObjCodeKey + ".xmrasm");
155 if ((envar != null) && ((envar[0] & 1) != 0)) { 143// m_log.Debug ("[YEngine]: MMRScriptCompileSaveILGen: saving to " + asmFileName);
156 m_log.Debug ("[XMREngine]: MMRScriptCompileSaveILGen: saving to " + asmFileName);
157 asmFileWriter = File.CreateText (asmFileName); 144 asmFileWriter = File.CreateText (asmFileName);
158 } 145 }
159 } 146 }
160 147
161 /* 148 // Read object file to create ScriptObjCode object.
162 * Read object file to create ScriptObjCode object. 149 // Maybe also write disassembly to a file for debugging.
163 * Maybe also write disassembly to a file for debugging.
164 */
165 BinaryReader objFileReader = new BinaryReader (objFileStream); 150 BinaryReader objFileReader = new BinaryReader (objFileStream);
166 ScriptObjCode scriptObjCode = null; 151 ScriptObjCode scriptObjCode = null;
167 try { 152 try
153 {
168 scriptObjCode = new ScriptObjCode (objFileReader, asmFileWriter, null); 154 scriptObjCode = new ScriptObjCode (objFileReader, asmFileWriter, null);
169 if (scriptObjCode != null) { 155 }
170 scriptObjCode.fileDateUtc = File.GetLastWriteTimeUtc (objFileName); 156 finally
171 } 157 {
172 } finally {
173 objFileReader.Close (); 158 objFileReader.Close ();
174 if (asmFileWriter != null) { 159 if (asmFileWriter != null)
160 {
175 asmFileWriter.Flush (); 161 asmFileWriter.Flush ();
176 asmFileWriter.Close (); 162 asmFileWriter.Close ();
177 } 163 }
178 } 164 }
179 165
180 /*
181 * Maybe an old object file has reached its expiration date.
182 */
183 if (oldObjFile && (scriptObjCode != null) && scriptObjCode.IsExpired ()) {
184 m_log.Debug ("[XMREngine]: expiration reached on " + m_ScriptObjCodeKey + ", reloading");
185 m_ForceRecomp = true;
186 scriptObjCode = Compile ();
187 }
188
189 return scriptObjCode; 166 return scriptObjCode;
190 } 167 }
191 168
192 private void PrintCompilerErrors () 169 private void PrintCompilerErrors ()
193 { 170 {
194 m_log.Info ("[XMREngine]: - " + m_Part.GetWorldPosition () + " " + m_DescName); 171 m_log.Info ("[YEngine]: - " + m_Part.GetWorldPosition () + " " + m_DescName);
195 foreach (string error in m_CompilerErrors) { 172 foreach (string error in m_CompilerErrors) {
196 m_log.Info ("[XMREngine]: - " + error); 173 m_log.Info ("[YEngine]: - " + error);
197 } 174 }
198 } 175 }
199 176
@@ -204,11 +181,13 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
204 { 181 {
205 int len = source.Length; 182 int len = source.Length;
206 bool skipeol = false; 183 bool skipeol = false;
207 for (int i = 0; i < len; i ++) { 184 for (int i = 0; i < len; i ++)
185 {
208 char c = source[i]; 186 char c = source[i];
209 skipeol &= c != '\n'; 187 skipeol &= c != '\n';
210 skipeol |= (c == '/') && (i + 1 < len) && (source[i+1] == '/'); 188 skipeol |= (c == '/') && (i + 1 < len) && (source[i+1] == '/');
211 if ((c > ' ') && !skipeol) return false; 189 if ((c > ' ') && !skipeol)
190 return false;
212 } 191 }
213 return true; 192 return true;
214 } 193 }