diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api')
30 files changed, 5956 insertions, 17287 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs index 47a9cdc..036cb5d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs | |||
@@ -28,7 +28,9 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Reflection; | ||
31 | using System.Threading; | 32 | using System.Threading; |
33 | using log4net; | ||
32 | using OpenMetaverse; | 34 | using OpenMetaverse; |
33 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
34 | using OpenSim.Framework.Monitoring; | 36 | using OpenSim.Framework.Monitoring; |
@@ -45,15 +47,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
45 | /// </summary> | 47 | /// </summary> |
46 | public class AsyncCommandManager | 48 | public class AsyncCommandManager |
47 | { | 49 | { |
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
48 | private static Thread cmdHandlerThread; | 52 | private static Thread cmdHandlerThread; |
49 | private static int cmdHandlerThreadCycleSleepms; | 53 | private static int cmdHandlerThreadCycleSleepms; |
50 | 54 | ||
51 | private static List<IScene> m_Scenes = new List<IScene>(); | 55 | /// <summary> |
56 | /// Lock for reading/writing static components of AsyncCommandManager. | ||
57 | /// </summary> | ||
58 | /// <remarks> | ||
59 | /// This lock exists so that multiple threads from different engines and/or different copies of the same engine | ||
60 | /// are prevented from running non-thread safe code (e.g. read/write of lists) concurrently. | ||
61 | /// </remarks> | ||
62 | private static object staticLock = new object(); | ||
63 | |||
52 | private static List<IScriptEngine> m_ScriptEngines = | 64 | private static List<IScriptEngine> m_ScriptEngines = |
53 | new List<IScriptEngine>(); | 65 | new List<IScriptEngine>(); |
54 | 66 | ||
55 | public IScriptEngine m_ScriptEngine; | 67 | public IScriptEngine m_ScriptEngine; |
56 | private IScene m_Scene; | ||
57 | 68 | ||
58 | private static Dictionary<IScriptEngine, Dataserver> m_Dataserver = | 69 | private static Dictionary<IScriptEngine, Dataserver> m_Dataserver = |
59 | new Dictionary<IScriptEngine, Dataserver>(); | 70 | new Dictionary<IScriptEngine, Dataserver>(); |
@@ -70,67 +81,99 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
70 | 81 | ||
71 | public Dataserver DataserverPlugin | 82 | public Dataserver DataserverPlugin |
72 | { | 83 | { |
73 | get { return m_Dataserver[m_ScriptEngine]; } | 84 | get |
85 | { | ||
86 | lock (staticLock) | ||
87 | return m_Dataserver[m_ScriptEngine]; | ||
88 | } | ||
74 | } | 89 | } |
75 | 90 | ||
76 | public Timer TimerPlugin | 91 | public Timer TimerPlugin |
77 | { | 92 | { |
78 | get { return m_Timer[m_ScriptEngine]; } | 93 | get |
94 | { | ||
95 | lock (staticLock) | ||
96 | return m_Timer[m_ScriptEngine]; | ||
97 | } | ||
79 | } | 98 | } |
80 | 99 | ||
81 | public HttpRequest HttpRequestPlugin | 100 | public HttpRequest HttpRequestPlugin |
82 | { | 101 | { |
83 | get { return m_HttpRequest[m_ScriptEngine]; } | 102 | get |
103 | { | ||
104 | lock (staticLock) | ||
105 | return m_HttpRequest[m_ScriptEngine]; | ||
106 | } | ||
84 | } | 107 | } |
85 | 108 | ||
86 | public Listener ListenerPlugin | 109 | public Listener ListenerPlugin |
87 | { | 110 | { |
88 | get { return m_Listener[m_ScriptEngine]; } | 111 | get |
112 | { | ||
113 | lock (staticLock) | ||
114 | return m_Listener[m_ScriptEngine]; | ||
115 | } | ||
89 | } | 116 | } |
90 | 117 | ||
91 | public SensorRepeat SensorRepeatPlugin | 118 | public SensorRepeat SensorRepeatPlugin |
92 | { | 119 | { |
93 | get { return m_SensorRepeat[m_ScriptEngine]; } | 120 | get |
121 | { | ||
122 | lock (staticLock) | ||
123 | return m_SensorRepeat[m_ScriptEngine]; | ||
124 | } | ||
94 | } | 125 | } |
95 | 126 | ||
96 | public XmlRequest XmlRequestPlugin | 127 | public XmlRequest XmlRequestPlugin |
97 | { | 128 | { |
98 | get { return m_XmlRequest[m_ScriptEngine]; } | 129 | get |
130 | { | ||
131 | lock (staticLock) | ||
132 | return m_XmlRequest[m_ScriptEngine]; | ||
133 | } | ||
99 | } | 134 | } |
100 | 135 | ||
101 | public IScriptEngine[] ScriptEngines | 136 | public IScriptEngine[] ScriptEngines |
102 | { | 137 | { |
103 | get { return m_ScriptEngines.ToArray(); } | 138 | get |
139 | { | ||
140 | lock (staticLock) | ||
141 | return m_ScriptEngines.ToArray(); | ||
142 | } | ||
104 | } | 143 | } |
105 | 144 | ||
106 | public AsyncCommandManager(IScriptEngine _ScriptEngine) | 145 | public AsyncCommandManager(IScriptEngine _ScriptEngine) |
107 | { | 146 | { |
108 | m_ScriptEngine = _ScriptEngine; | 147 | m_ScriptEngine = _ScriptEngine; |
109 | m_Scene = m_ScriptEngine.World; | 148 | |
110 | 149 | // If there is more than one scene in the simulator or multiple script engines are used on the same region | |
111 | if (m_Scenes.Count == 0) | 150 | // then more than one thread could arrive at this block of code simultaneously. However, it cannot be |
112 | ReadConfig(); | 151 | // executed concurrently both because concurrent list operations are not thread-safe and because of other |
113 | 152 | // race conditions such as the later check of cmdHandlerThread == null. | |
114 | if (!m_Scenes.Contains(m_Scene)) | 153 | lock (staticLock) |
115 | m_Scenes.Add(m_Scene); | 154 | { |
116 | if (!m_ScriptEngines.Contains(m_ScriptEngine)) | 155 | if (m_ScriptEngines.Count == 0) |
117 | m_ScriptEngines.Add(m_ScriptEngine); | 156 | ReadConfig(); |
118 | 157 | ||
119 | // Create instances of all plugins | 158 | if (!m_ScriptEngines.Contains(m_ScriptEngine)) |
120 | if (!m_Dataserver.ContainsKey(m_ScriptEngine)) | 159 | m_ScriptEngines.Add(m_ScriptEngine); |
121 | m_Dataserver[m_ScriptEngine] = new Dataserver(this); | 160 | |
122 | if (!m_Timer.ContainsKey(m_ScriptEngine)) | 161 | // Create instances of all plugins |
123 | m_Timer[m_ScriptEngine] = new Timer(this); | 162 | if (!m_Dataserver.ContainsKey(m_ScriptEngine)) |
124 | if (!m_HttpRequest.ContainsKey(m_ScriptEngine)) | 163 | m_Dataserver[m_ScriptEngine] = new Dataserver(this); |
125 | m_HttpRequest[m_ScriptEngine] = new HttpRequest(this); | 164 | if (!m_Timer.ContainsKey(m_ScriptEngine)) |
126 | if (!m_Listener.ContainsKey(m_ScriptEngine)) | 165 | m_Timer[m_ScriptEngine] = new Timer(this); |
127 | m_Listener[m_ScriptEngine] = new Listener(this); | 166 | if (!m_HttpRequest.ContainsKey(m_ScriptEngine)) |
128 | if (!m_SensorRepeat.ContainsKey(m_ScriptEngine)) | 167 | m_HttpRequest[m_ScriptEngine] = new HttpRequest(this); |
129 | m_SensorRepeat[m_ScriptEngine] = new SensorRepeat(this); | 168 | if (!m_Listener.ContainsKey(m_ScriptEngine)) |
130 | if (!m_XmlRequest.ContainsKey(m_ScriptEngine)) | 169 | m_Listener[m_ScriptEngine] = new Listener(this); |
131 | m_XmlRequest[m_ScriptEngine] = new XmlRequest(this); | 170 | if (!m_SensorRepeat.ContainsKey(m_ScriptEngine)) |
132 | 171 | m_SensorRepeat[m_ScriptEngine] = new SensorRepeat(this); | |
133 | StartThread(); | 172 | if (!m_XmlRequest.ContainsKey(m_ScriptEngine)) |
173 | m_XmlRequest[m_ScriptEngine] = new XmlRequest(this); | ||
174 | |||
175 | StartThread(); | ||
176 | } | ||
134 | } | 177 | } |
135 | 178 | ||
136 | private static void StartThread() | 179 | private static void StartThread() |
@@ -139,7 +182,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
139 | { | 182 | { |
140 | // Start the thread that will be doing the work | 183 | // Start the thread that will be doing the work |
141 | cmdHandlerThread | 184 | cmdHandlerThread |
142 | = Watchdog.StartThread( | 185 | = WorkManager.StartThread( |
143 | CmdHandlerThreadLoop, "AsyncLSLCmdHandlerThread", ThreadPriority.Normal, true, true); | 186 | CmdHandlerThreadLoop, "AsyncLSLCmdHandlerThread", ThreadPriority.Normal, true, true); |
144 | } | 187 | } |
145 | } | 188 | } |
@@ -179,42 +222,43 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
179 | { | 222 | { |
180 | try | 223 | try |
181 | { | 224 | { |
182 | while (true) | 225 | Thread.Sleep(cmdHandlerThreadCycleSleepms); |
183 | { | ||
184 | Thread.Sleep(cmdHandlerThreadCycleSleepms); | ||
185 | 226 | ||
186 | DoOneCmdHandlerPass(); | 227 | DoOneCmdHandlerPass(); |
187 | 228 | ||
188 | Watchdog.UpdateThread(); | 229 | Watchdog.UpdateThread(); |
189 | } | ||
190 | } | 230 | } |
191 | catch | 231 | catch (Exception e) |
192 | { | 232 | { |
233 | m_log.Error("[ASYNC COMMAND MANAGER]: Exception in command handler pass: ", e); | ||
193 | } | 234 | } |
194 | } | 235 | } |
195 | } | 236 | } |
196 | 237 | ||
197 | private static void DoOneCmdHandlerPass() | 238 | private static void DoOneCmdHandlerPass() |
198 | { | 239 | { |
199 | // Check HttpRequests | 240 | lock (staticLock) |
200 | m_HttpRequest[m_ScriptEngines[0]].CheckHttpRequests(); | 241 | { |
242 | // Check HttpRequests | ||
243 | m_HttpRequest[m_ScriptEngines[0]].CheckHttpRequests(); | ||
201 | 244 | ||
202 | // Check XMLRPCRequests | 245 | // Check XMLRPCRequests |
203 | m_XmlRequest[m_ScriptEngines[0]].CheckXMLRPCRequests(); | 246 | m_XmlRequest[m_ScriptEngines[0]].CheckXMLRPCRequests(); |
204 | 247 | ||
205 | foreach (IScriptEngine s in m_ScriptEngines) | 248 | foreach (IScriptEngine s in m_ScriptEngines) |
206 | { | 249 | { |
207 | // Check Listeners | 250 | // Check Listeners |
208 | m_Listener[s].CheckListeners(); | 251 | m_Listener[s].CheckListeners(); |
209 | 252 | ||
210 | // Check timers | 253 | // Check timers |
211 | m_Timer[s].CheckTimerEvents(); | 254 | m_Timer[s].CheckTimerEvents(); |
212 | 255 | ||
213 | // Check Sensors | 256 | // Check Sensors |
214 | m_SensorRepeat[s].CheckSenseRepeaterEvents(); | 257 | m_SensorRepeat[s].CheckSenseRepeaterEvents(); |
215 | 258 | ||
216 | // Check dataserver | 259 | // Check dataserver |
217 | m_Dataserver[s].ExpireRequests(); | 260 | m_Dataserver[s].ExpireRequests(); |
261 | } | ||
218 | } | 262 | } |
219 | } | 263 | } |
220 | 264 | ||
@@ -225,19 +269,44 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
225 | /// <param name="itemID"></param> | 269 | /// <param name="itemID"></param> |
226 | public static void RemoveScript(IScriptEngine engine, uint localID, UUID itemID) | 270 | public static void RemoveScript(IScriptEngine engine, uint localID, UUID itemID) |
227 | { | 271 | { |
272 | // m_log.DebugFormat("[ASYNC COMMAND MANAGER]: Removing facilities for script {0}", itemID); | ||
273 | |||
274 | lock (staticLock) | ||
275 | { | ||
276 | // Remove dataserver events | ||
277 | m_Dataserver[engine].RemoveEvents(localID, itemID); | ||
278 | |||
279 | // Remove from: Timers | ||
280 | m_Timer[engine].UnSetTimerEvents(localID, itemID); | ||
281 | |||
282 | // Remove from: HttpRequest | ||
283 | IHttpRequestModule iHttpReq = engine.World.RequestModuleInterface<IHttpRequestModule>(); | ||
284 | if (iHttpReq != null) | ||
285 | iHttpReq.StopHttpRequestsForScript(itemID); | ||
286 | |||
287 | IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>(); | ||
288 | if (comms != null) | ||
289 | comms.DeleteListener(itemID); | ||
290 | |||
291 | IXMLRPC xmlrpc = engine.World.RequestModuleInterface<IXMLRPC>(); | ||
292 | if (xmlrpc != null) | ||
293 | { | ||
294 | xmlrpc.DeleteChannels(itemID); | ||
295 | xmlrpc.CancelSRDRequests(itemID); | ||
296 | } | ||
297 | |||
298 | // Remove Sensors | ||
299 | m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID); | ||
300 | } | ||
301 | } | ||
302 | |||
303 | public static void StateChange(IScriptEngine engine, uint localID, UUID itemID) | ||
304 | { | ||
228 | // Remove a specific script | 305 | // Remove a specific script |
229 | 306 | ||
230 | // Remove dataserver events | 307 | // Remove dataserver events |
231 | m_Dataserver[engine].RemoveEvents(localID, itemID); | 308 | m_Dataserver[engine].RemoveEvents(localID, itemID); |
232 | 309 | ||
233 | // Remove from: Timers | ||
234 | m_Timer[engine].UnSetTimerEvents(localID, itemID); | ||
235 | |||
236 | // Remove from: HttpRequest | ||
237 | IHttpRequestModule iHttpReq = engine.World.RequestModuleInterface<IHttpRequestModule>(); | ||
238 | if (iHttpReq != null) | ||
239 | iHttpReq.StopHttpRequest(localID, itemID); | ||
240 | |||
241 | IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>(); | 310 | IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>(); |
242 | if (comms != null) | 311 | if (comms != null) |
243 | comms.DeleteListener(itemID); | 312 | comms.DeleteListener(itemID); |
@@ -248,9 +317,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
248 | xmlrpc.DeleteChannels(itemID); | 317 | xmlrpc.DeleteChannels(itemID); |
249 | xmlrpc.CancelSRDRequests(itemID); | 318 | xmlrpc.CancelSRDRequests(itemID); |
250 | } | 319 | } |
251 | |||
252 | // Remove Sensors | 320 | // Remove Sensors |
253 | m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID); | 321 | m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID); |
322 | |||
254 | } | 323 | } |
255 | 324 | ||
256 | /// <summary> | 325 | /// <summary> |
@@ -260,10 +329,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
260 | /// <returns></returns> | 329 | /// <returns></returns> |
261 | public static SensorRepeat GetSensorRepeatPlugin(IScriptEngine engine) | 330 | public static SensorRepeat GetSensorRepeatPlugin(IScriptEngine engine) |
262 | { | 331 | { |
263 | if (m_SensorRepeat.ContainsKey(engine)) | 332 | lock (staticLock) |
264 | return m_SensorRepeat[engine]; | 333 | { |
265 | else | 334 | if (m_SensorRepeat.ContainsKey(engine)) |
266 | return null; | 335 | return m_SensorRepeat[engine]; |
336 | else | ||
337 | return null; | ||
338 | } | ||
267 | } | 339 | } |
268 | 340 | ||
269 | /// <summary> | 341 | /// <summary> |
@@ -273,10 +345,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
273 | /// <returns></returns> | 345 | /// <returns></returns> |
274 | public static Dataserver GetDataserverPlugin(IScriptEngine engine) | 346 | public static Dataserver GetDataserverPlugin(IScriptEngine engine) |
275 | { | 347 | { |
276 | if (m_Dataserver.ContainsKey(engine)) | 348 | lock (staticLock) |
277 | return m_Dataserver[engine]; | 349 | { |
278 | else | 350 | if (m_Dataserver.ContainsKey(engine)) |
279 | return null; | 351 | return m_Dataserver[engine]; |
352 | else | ||
353 | return null; | ||
354 | } | ||
280 | } | 355 | } |
281 | 356 | ||
282 | /// <summary> | 357 | /// <summary> |
@@ -286,10 +361,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
286 | /// <returns></returns> | 361 | /// <returns></returns> |
287 | public static Timer GetTimerPlugin(IScriptEngine engine) | 362 | public static Timer GetTimerPlugin(IScriptEngine engine) |
288 | { | 363 | { |
289 | if (m_Timer.ContainsKey(engine)) | 364 | lock (staticLock) |
290 | return m_Timer[engine]; | 365 | { |
291 | else | 366 | if (m_Timer.ContainsKey(engine)) |
292 | return null; | 367 | return m_Timer[engine]; |
368 | else | ||
369 | return null; | ||
370 | } | ||
293 | } | 371 | } |
294 | 372 | ||
295 | /// <summary> | 373 | /// <summary> |
@@ -299,38 +377,44 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
299 | /// <returns></returns> | 377 | /// <returns></returns> |
300 | public static Listener GetListenerPlugin(IScriptEngine engine) | 378 | public static Listener GetListenerPlugin(IScriptEngine engine) |
301 | { | 379 | { |
302 | if (m_Listener.ContainsKey(engine)) | 380 | lock (staticLock) |
303 | return m_Listener[engine]; | 381 | { |
304 | else | 382 | if (m_Listener.ContainsKey(engine)) |
305 | return null; | 383 | return m_Listener[engine]; |
384 | else | ||
385 | return null; | ||
386 | } | ||
306 | } | 387 | } |
307 | 388 | ||
308 | public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID) | 389 | public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID) |
309 | { | 390 | { |
310 | List<Object> data = new List<Object>(); | 391 | List<Object> data = new List<Object>(); |
311 | 392 | ||
312 | Object[] listeners = m_Listener[engine].GetSerializationData(itemID); | 393 | lock (staticLock) |
313 | if (listeners.Length > 0) | ||
314 | { | 394 | { |
315 | data.Add("listener"); | 395 | Object[] listeners = m_Listener[engine].GetSerializationData(itemID); |
316 | data.Add(listeners.Length); | 396 | if (listeners.Length > 0) |
317 | data.AddRange(listeners); | 397 | { |
318 | } | 398 | data.Add("listener"); |
399 | data.Add(listeners.Length); | ||
400 | data.AddRange(listeners); | ||
401 | } | ||
319 | 402 | ||
320 | Object[] timers=m_Timer[engine].GetSerializationData(itemID); | 403 | Object[] timers=m_Timer[engine].GetSerializationData(itemID); |
321 | if (timers.Length > 0) | 404 | if (timers.Length > 0) |
322 | { | 405 | { |
323 | data.Add("timer"); | 406 | data.Add("timer"); |
324 | data.Add(timers.Length); | 407 | data.Add(timers.Length); |
325 | data.AddRange(timers); | 408 | data.AddRange(timers); |
326 | } | 409 | } |
327 | 410 | ||
328 | Object[] sensors = m_SensorRepeat[engine].GetSerializationData(itemID); | 411 | Object[] sensors = m_SensorRepeat[engine].GetSerializationData(itemID); |
329 | if (sensors.Length > 0) | 412 | if (sensors.Length > 0) |
330 | { | 413 | { |
331 | data.Add("sensor"); | 414 | data.Add("sensor"); |
332 | data.Add(sensors.Length); | 415 | data.Add(sensors.Length); |
333 | data.AddRange(sensors); | 416 | data.AddRange(sensors); |
417 | } | ||
334 | } | 418 | } |
335 | 419 | ||
336 | return data.ToArray(); | 420 | return data.ToArray(); |
@@ -355,41 +439,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
355 | 439 | ||
356 | idx+=len; | 440 | idx+=len; |
357 | 441 | ||
442 | lock (staticLock) | ||
443 | { | ||
358 | switch (type) | 444 | switch (type) |
359 | { | 445 | { |
360 | case "listener": | 446 | case "listener": |
361 | m_Listener[engine].CreateFromData(localID, itemID, | 447 | m_Listener[engine].CreateFromData(localID, itemID, |
362 | hostID, item); | 448 | hostID, item); |
363 | break; | 449 | break; |
364 | case "timer": | 450 | case "timer": |
365 | m_Timer[engine].CreateFromData(localID, itemID, | 451 | m_Timer[engine].CreateFromData(localID, itemID, |
366 | hostID, item); | 452 | hostID, item); |
367 | break; | 453 | break; |
368 | case "sensor": | 454 | case "sensor": |
369 | m_SensorRepeat[engine].CreateFromData(localID, | 455 | m_SensorRepeat[engine].CreateFromData(localID, |
370 | itemID, hostID, item); | 456 | itemID, hostID, item); |
371 | break; | 457 | break; |
458 | } | ||
372 | } | 459 | } |
373 | } | 460 | } |
374 | } | 461 | } |
375 | } | 462 | } |
376 | |||
377 | #region Check llRemoteData channels | ||
378 | |||
379 | #endregion | ||
380 | |||
381 | #region Check llListeners | ||
382 | |||
383 | #endregion | ||
384 | |||
385 | /// <summary> | ||
386 | /// If set to true then threads and stuff should try to make a graceful exit | ||
387 | /// </summary> | ||
388 | public bool PleaseShutdown | ||
389 | { | ||
390 | get { return _PleaseShutdown; } | ||
391 | set { _PleaseShutdown = value; } | ||
392 | } | ||
393 | private bool _PleaseShutdown = false; | ||
394 | } | 463 | } |
395 | } | 464 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 1ab107a..4eda443 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -28,6 +28,9 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Diagnostics; | ||
32 | using System.Drawing; | ||
33 | using System.Drawing.Imaging; | ||
31 | using System.Runtime.Remoting.Lifetime; | 34 | using System.Runtime.Remoting.Lifetime; |
32 | using System.Text; | 35 | using System.Text; |
33 | using System.Threading; | 36 | using System.Threading; |
@@ -35,7 +38,9 @@ using System.Text.RegularExpressions; | |||
35 | using Nini.Config; | 38 | using Nini.Config; |
36 | using log4net; | 39 | using log4net; |
37 | using OpenMetaverse; | 40 | using OpenMetaverse; |
41 | using OpenMetaverse.Assets; | ||
38 | using OpenMetaverse.Packets; | 42 | using OpenMetaverse.Packets; |
43 | using OpenMetaverse.Rendering; | ||
39 | using OpenSim; | 44 | using OpenSim; |
40 | using OpenSim.Framework; | 45 | using OpenSim.Framework; |
41 | 46 | ||
@@ -45,7 +50,8 @@ using OpenSim.Region.CoreModules.World.Terrain; | |||
45 | using OpenSim.Region.Framework.Interfaces; | 50 | using OpenSim.Region.Framework.Interfaces; |
46 | using OpenSim.Region.Framework.Scenes; | 51 | using OpenSim.Region.Framework.Scenes; |
47 | using OpenSim.Region.Framework.Scenes.Animation; | 52 | using OpenSim.Region.Framework.Scenes.Animation; |
48 | using OpenSim.Region.Physics.Manager; | 53 | using OpenSim.Region.Framework.Scenes.Scripting; |
54 | using OpenSim.Region.PhysicsModules.SharedBase; | ||
49 | using OpenSim.Region.ScriptEngine.Shared; | 55 | using OpenSim.Region.ScriptEngine.Shared; |
50 | using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; | 56 | using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; |
51 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | 57 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; |
@@ -66,6 +72,8 @@ using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; | |||
66 | using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; | 72 | using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; |
67 | using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; | 73 | using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; |
68 | using System.Reflection; | 74 | using System.Reflection; |
75 | using System.Linq; | ||
76 | using PermissionMask = OpenSim.Framework.PermissionMask; | ||
69 | 77 | ||
70 | namespace OpenSim.Region.ScriptEngine.Shared.Api | 78 | namespace OpenSim.Region.ScriptEngine.Shared.Api |
71 | { | 79 | { |
@@ -83,15 +91,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
83 | public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi | 91 | public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi |
84 | { | 92 | { |
85 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 93 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
94 | |||
95 | public int LlRequestAgentDataCacheTimeoutMs { get; set; } | ||
96 | |||
86 | protected IScriptEngine m_ScriptEngine; | 97 | protected IScriptEngine m_ScriptEngine; |
87 | protected SceneObjectPart m_host; | 98 | protected SceneObjectPart m_host; |
88 | 99 | ||
89 | /// <summary> | 100 | /// <summary> |
101 | /// Used for script sleeps when we are using co-operative script termination. | ||
102 | /// </summary> | ||
103 | /// <remarks>null if co-operative script termination is not active</remarks> | ||
104 | /// <summary> | ||
90 | /// The item that hosts this script | 105 | /// The item that hosts this script |
91 | /// </summary> | 106 | /// </summary> |
92 | protected TaskInventoryItem m_item; | 107 | protected TaskInventoryItem m_item; |
93 | 108 | ||
94 | protected bool throwErrorOnNotImplemented = true; | 109 | protected bool throwErrorOnNotImplemented = false; |
95 | protected AsyncCommandManager AsyncCommands = null; | 110 | protected AsyncCommandManager AsyncCommands = null; |
96 | protected float m_ScriptDelayFactor = 1.0f; | 111 | protected float m_ScriptDelayFactor = 1.0f; |
97 | protected float m_ScriptDistanceFactor = 1.0f; | 112 | protected float m_ScriptDistanceFactor = 1.0f; |
@@ -108,49 +123,260 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
108 | protected IUrlModule m_UrlModule = null; | 123 | protected IUrlModule m_UrlModule = null; |
109 | protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = new Dictionary<UUID, UserInfoCacheEntry>(); | 124 | protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = new Dictionary<UUID, UserInfoCacheEntry>(); |
110 | protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp. | 125 | protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp. |
126 | protected int m_sleepMsOnSetTexture = 200; | ||
127 | protected int m_sleepMsOnSetLinkTexture = 200; | ||
128 | protected int m_sleepMsOnScaleTexture = 200; | ||
129 | protected int m_sleepMsOnOffsetTexture = 200; | ||
130 | protected int m_sleepMsOnRotateTexture = 200; | ||
131 | protected int m_sleepMsOnSetPos = 200; | ||
132 | protected int m_sleepMsOnSetRot = 200; | ||
133 | protected int m_sleepMsOnSetLocalRot = 200; | ||
134 | protected int m_sleepMsOnPreloadSound = 1000; | ||
135 | protected int m_sleepMsOnMakeExplosion = 100; | ||
136 | protected int m_sleepMsOnMakeFountain = 100; | ||
137 | protected int m_sleepMsOnMakeSmoke = 100; | ||
138 | protected int m_sleepMsOnMakeFire = 100; | ||
139 | protected int m_sleepMsOnRezAtRoot = 100; | ||
140 | protected int m_sleepMsOnInstantMessage = 2000; | ||
141 | protected int m_sleepMsOnEmail = 20000; | ||
142 | protected int m_sleepMsOnCreateLink = 1000; | ||
143 | protected int m_sleepMsOnGiveInventory = 3000; | ||
144 | protected int m_sleepMsOnRequestAgentData = 100; | ||
145 | protected int m_sleepMsOnRequestInventoryData = 1000; | ||
146 | protected int m_sleepMsOnSetDamage = 5000; | ||
147 | protected int m_sleepMsOnTextBox = 1000; | ||
148 | protected int m_sleepMsOnAdjustSoundVolume = 100; | ||
149 | protected int m_sleepMsOnEjectFromLand = 5000; | ||
150 | protected int m_sleepMsOnAddToLandPassList = 100; | ||
151 | protected int m_sleepMsOnDialog = 1000; | ||
152 | protected int m_sleepMsOnRemoteLoadScript = 3000; | ||
153 | protected int m_sleepMsOnRemoteLoadScriptPin = 3000; | ||
154 | protected int m_sleepMsOnOpenRemoteDataChannel = 1000; | ||
155 | protected int m_sleepMsOnSendRemoteData = 3000; | ||
156 | protected int m_sleepMsOnRemoteDataReply = 3000; | ||
157 | protected int m_sleepMsOnCloseRemoteDataChannel = 1000; | ||
158 | protected int m_sleepMsOnSetPrimitiveParams = 200; | ||
159 | protected int m_sleepMsOnSetLinkPrimitiveParams = 200; | ||
160 | protected int m_sleepMsOnXorBase64Strings = 300; | ||
161 | protected int m_sleepMsOnSetParcelMusicURL = 2000; | ||
162 | protected int m_sleepMsOnGetPrimMediaParams = 1000; | ||
163 | protected int m_sleepMsOnGetLinkMedia = 1000; | ||
164 | protected int m_sleepMsOnSetPrimMediaParams = 1000; | ||
165 | protected int m_sleepMsOnSetLinkMedia = 1000; | ||
166 | protected int m_sleepMsOnClearPrimMedia = 1000; | ||
167 | protected int m_sleepMsOnClearLinkMedia = 1000; | ||
168 | protected int m_sleepMsOnRequestSimulatorData = 1000; | ||
169 | protected int m_sleepMsOnLoadURL = 10000; | ||
170 | protected int m_sleepMsOnParcelMediaCommandList = 2000; | ||
171 | protected int m_sleepMsOnParcelMediaQuery = 2000; | ||
172 | protected int m_sleepMsOnModPow = 1000; | ||
173 | protected int m_sleepMsOnSetPrimURL = 2000; | ||
174 | protected int m_sleepMsOnRefreshPrimURL = 20000; | ||
175 | protected int m_sleepMsOnMapDestination = 1000; | ||
176 | protected int m_sleepMsOnAddToLandBanList = 100; | ||
177 | protected int m_sleepMsOnRemoveFromLandPassList = 100; | ||
178 | protected int m_sleepMsOnRemoveFromLandBanList = 100; | ||
179 | protected int m_sleepMsOnResetLandBanList = 100; | ||
180 | protected int m_sleepMsOnResetLandPassList = 100; | ||
181 | protected int m_sleepMsOnGetParcelPrimOwners = 2000; | ||
182 | protected int m_sleepMsOnGetNumberOfNotecardLines = 100; | ||
183 | protected int m_sleepMsOnGetNotecardLine = 100; | ||
184 | protected string m_internalObjectHost = "lsl.opensim.local"; | ||
185 | protected bool m_restrictEmail = false; | ||
111 | protected ISoundModule m_SoundModule = null; | 186 | protected ISoundModule m_SoundModule = null; |
112 | 187 | ||
113 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) | 188 | protected float m_avatarHeightCorrection = 0.2f; |
189 | protected bool m_useSimpleBoxesInGetBoundingBox = false; | ||
190 | protected bool m_addStatsInGetBoundingBox = false; | ||
191 | |||
192 | //LSL Avatar Bounding Box (lABB), lower (1) and upper (2), | ||
193 | //standing (Std), Groundsitting (Grs), Sitting (Sit), | ||
194 | //along X, Y and Z axes, constants (0) and coefficients (1) | ||
195 | protected float m_lABB1StdX0 = -0.275f; | ||
196 | protected float m_lABB2StdX0 = 0.275f; | ||
197 | protected float m_lABB1StdY0 = -0.35f; | ||
198 | protected float m_lABB2StdY0 = 0.35f; | ||
199 | protected float m_lABB1StdZ0 = -0.1f; | ||
200 | protected float m_lABB1StdZ1 = -0.5f; | ||
201 | protected float m_lABB2StdZ0 = 0.1f; | ||
202 | protected float m_lABB2StdZ1 = 0.5f; | ||
203 | protected float m_lABB1GrsX0 = -0.3875f; | ||
204 | protected float m_lABB2GrsX0 = 0.3875f; | ||
205 | protected float m_lABB1GrsY0 = -0.5f; | ||
206 | protected float m_lABB2GrsY0 = 0.5f; | ||
207 | protected float m_lABB1GrsZ0 = -0.05f; | ||
208 | protected float m_lABB1GrsZ1 = -0.375f; | ||
209 | protected float m_lABB2GrsZ0 = 0.5f; | ||
210 | protected float m_lABB2GrsZ1 = 0.0f; | ||
211 | protected float m_lABB1SitX0 = -0.5875f; | ||
212 | protected float m_lABB2SitX0 = 0.1875f; | ||
213 | protected float m_lABB1SitY0 = -0.35f; | ||
214 | protected float m_lABB2SitY0 = 0.35f; | ||
215 | protected float m_lABB1SitZ0 = -0.35f; | ||
216 | protected float m_lABB1SitZ1 = -0.375f; | ||
217 | protected float m_lABB2SitZ0 = -0.25f; | ||
218 | protected float m_lABB2SitZ1 = 0.25f; | ||
219 | |||
220 | protected float m_primSafetyCoeffX = 2.414214f; | ||
221 | protected float m_primSafetyCoeffY = 2.414214f; | ||
222 | protected float m_primSafetyCoeffZ = 1.618034f; | ||
223 | protected bool m_useCastRayV3 = false; | ||
224 | protected float m_floatToleranceInCastRay = 0.00001f; | ||
225 | protected float m_floatTolerance2InCastRay = 0.001f; | ||
226 | protected DetailLevel m_primLodInCastRay = DetailLevel.Medium; | ||
227 | protected DetailLevel m_sculptLodInCastRay = DetailLevel.Medium; | ||
228 | protected DetailLevel m_meshLodInCastRay = DetailLevel.Highest; | ||
229 | protected DetailLevel m_avatarLodInCastRay = DetailLevel.Medium; | ||
230 | protected int m_maxHitsInCastRay = 16; | ||
231 | protected int m_maxHitsPerPrimInCastRay = 16; | ||
232 | protected int m_maxHitsPerObjectInCastRay = 16; | ||
233 | protected bool m_detectExitsInCastRay = false; | ||
234 | protected bool m_filterPartsInCastRay = false; | ||
235 | protected bool m_doAttachmentsInCastRay = false; | ||
236 | protected int m_msThrottleInCastRay = 200; | ||
237 | protected int m_msPerRegionInCastRay = 40; | ||
238 | protected int m_msPerAvatarInCastRay = 10; | ||
239 | protected int m_msMinInCastRay = 2; | ||
240 | protected int m_msMaxInCastRay = 40; | ||
241 | protected static List<CastRayCall> m_castRayCalls = new List<CastRayCall>(); | ||
242 | protected bool m_useMeshCacheInCastRay = true; | ||
243 | protected static Dictionary<ulong, FacetedMesh> m_cachedMeshes = new Dictionary<ulong, FacetedMesh>(); | ||
244 | |||
245 | //An array of HTTP/1.1 headers that are not allowed to be used | ||
246 | //as custom headers by llHTTPRequest. | ||
247 | private string[] HttpStandardHeaders = | ||
248 | { | ||
249 | "Accept", "Accept-Charset", "Accept-Encoding", "Accept-Language", | ||
250 | "Accept-Ranges", "Age", "Allow", "Authorization", "Cache-Control", | ||
251 | "Connection", "Content-Encoding", "Content-Language", | ||
252 | "Content-Length", "Content-Location", "Content-MD5", | ||
253 | "Content-Range", "Content-Type", "Date", "ETag", "Expect", | ||
254 | "Expires", "From", "Host", "If-Match", "If-Modified-Since", | ||
255 | "If-None-Match", "If-Range", "If-Unmodified-Since", "Last-Modified", | ||
256 | "Location", "Max-Forwards", "Pragma", "Proxy-Authenticate", | ||
257 | "Proxy-Authorization", "Range", "Referer", "Retry-After", "Server", | ||
258 | "TE", "Trailer", "Transfer-Encoding", "Upgrade", "User-Agent", | ||
259 | "Vary", "Via", "Warning", "WWW-Authenticate" | ||
260 | }; | ||
261 | |||
262 | public void Initialize( | ||
263 | IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item) | ||
114 | { | 264 | { |
115 | m_ScriptEngine = ScriptEngine; | 265 | m_ScriptEngine = scriptEngine; |
116 | m_host = host; | 266 | m_host = host; |
117 | m_item = item; | 267 | m_item = item; |
118 | 268 | ||
119 | LoadLimits(); // read script limits from config. | 269 | LoadConfig(); |
120 | 270 | ||
121 | m_TransferModule = | 271 | m_TransferModule = |
122 | m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>(); | 272 | m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>(); |
123 | m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); | 273 | m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); |
124 | m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>(); | 274 | m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>(); |
125 | 275 | ||
126 | AsyncCommands = new AsyncCommandManager(ScriptEngine); | 276 | AsyncCommands = new AsyncCommandManager(m_ScriptEngine); |
127 | } | 277 | } |
128 | 278 | ||
129 | /* load configuration items that affect script, object and run-time behavior. */ | 279 | /// <summary> |
130 | private void LoadLimits() | 280 | /// Load configuration items that affect script, object and run-time behavior. */ |
281 | /// </summary> | ||
282 | private void LoadConfig() | ||
131 | { | 283 | { |
132 | m_ScriptDelayFactor = | 284 | LlRequestAgentDataCacheTimeoutMs = 20000; |
133 | m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); | 285 | |
134 | m_ScriptDistanceFactor = | 286 | IConfig seConfig = m_ScriptEngine.Config; |
135 | m_ScriptEngine.Config.GetFloat("ScriptDistanceLimitFactor", 1.0f); | 287 | |
136 | m_MinTimerInterval = | 288 | if (seConfig != null) |
137 | m_ScriptEngine.Config.GetFloat("MinTimerInterval", 0.5f); | 289 | { |
138 | m_automaticLinkPermission = | 290 | m_ScriptDelayFactor = |
139 | m_ScriptEngine.Config.GetBoolean("AutomaticLinkPermission", false); | 291 | seConfig.GetFloat("ScriptDelayFactor", m_ScriptDelayFactor); |
140 | m_notecardLineReadCharsMax = | 292 | m_ScriptDistanceFactor = |
141 | m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255); | 293 | seConfig.GetFloat("ScriptDistanceLimitFactor", m_ScriptDistanceFactor); |
294 | m_MinTimerInterval = | ||
295 | seConfig.GetFloat("MinTimerInterval", m_MinTimerInterval); | ||
296 | m_automaticLinkPermission = | ||
297 | seConfig.GetBoolean("AutomaticLinkPermission", m_automaticLinkPermission); | ||
298 | m_notecardLineReadCharsMax = | ||
299 | seConfig.GetInt("NotecardLineReadCharsMax", m_notecardLineReadCharsMax); | ||
300 | |||
301 | // Rezzing an object with a velocity can create recoil. This feature seems to have been | ||
302 | // removed from recent versions of SL. The code computes recoil (vel*mass) and scales | ||
303 | // it by this factor. May be zero to turn off recoil all together. | ||
304 | m_recoilScaleFactor = m_ScriptEngine.Config.GetFloat("RecoilScaleFactor", m_recoilScaleFactor); | ||
305 | } | ||
306 | |||
142 | if (m_notecardLineReadCharsMax > 65535) | 307 | if (m_notecardLineReadCharsMax > 65535) |
143 | m_notecardLineReadCharsMax = 65535; | 308 | m_notecardLineReadCharsMax = 65535; |
309 | |||
144 | // load limits for particular subsystems. | 310 | // load limits for particular subsystems. |
145 | IConfig SMTPConfig; | 311 | IConfigSource seConfigSource = m_ScriptEngine.ConfigSource; |
146 | if ((SMTPConfig = m_ScriptEngine.ConfigSource.Configs["SMTP"]) != null) { | 312 | |
147 | // there's an smtp config, so load in the snooze time. | 313 | if (seConfigSource != null) |
148 | EMAIL_PAUSE_TIME = SMTPConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME); | 314 | { |
149 | } | 315 | IConfig lslConfig = seConfigSource.Configs["LL-Functions"]; |
150 | // Rezzing an object with a velocity can create recoil. This feature seems to have been | 316 | if (lslConfig != null) |
151 | // removed from recent versions of SL. The code computes recoil (vel*mass) and scales | 317 | { |
152 | // it by this factor. May be zero to turn off recoil all together. | 318 | m_restrictEmail = lslConfig.GetBoolean("RestrictEmail", m_restrictEmail); |
153 | m_recoilScaleFactor = m_ScriptEngine.Config.GetFloat("RecoilScaleFactor", m_recoilScaleFactor); | 319 | m_avatarHeightCorrection = lslConfig.GetFloat("AvatarHeightCorrection", m_avatarHeightCorrection); |
320 | m_useSimpleBoxesInGetBoundingBox = lslConfig.GetBoolean("UseSimpleBoxesInGetBoundingBox", m_useSimpleBoxesInGetBoundingBox); | ||
321 | m_addStatsInGetBoundingBox = lslConfig.GetBoolean("AddStatsInGetBoundingBox", m_addStatsInGetBoundingBox); | ||
322 | m_lABB1StdX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingXconst", m_lABB1StdX0); | ||
323 | m_lABB2StdX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingXconst", m_lABB2StdX0); | ||
324 | m_lABB1StdY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingYconst", m_lABB1StdY0); | ||
325 | m_lABB2StdY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingYconst", m_lABB2StdY0); | ||
326 | m_lABB1StdZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZconst", m_lABB1StdZ0); | ||
327 | m_lABB1StdZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZcoeff", m_lABB1StdZ1); | ||
328 | m_lABB2StdZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZconst", m_lABB2StdZ0); | ||
329 | m_lABB2StdZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZcoeff", m_lABB2StdZ1); | ||
330 | m_lABB1GrsX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingXconst", m_lABB1GrsX0); | ||
331 | m_lABB2GrsX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingXconst", m_lABB2GrsX0); | ||
332 | m_lABB1GrsY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingYconst", m_lABB1GrsY0); | ||
333 | m_lABB2GrsY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingYconst", m_lABB2GrsY0); | ||
334 | m_lABB1GrsZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZconst", m_lABB1GrsZ0); | ||
335 | m_lABB1GrsZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZcoeff", m_lABB1GrsZ1); | ||
336 | m_lABB2GrsZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZconst", m_lABB2GrsZ0); | ||
337 | m_lABB2GrsZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZcoeff", m_lABB2GrsZ1); | ||
338 | m_lABB1SitX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingXconst", m_lABB1SitX0); | ||
339 | m_lABB2SitX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingXconst", m_lABB2SitX0); | ||
340 | m_lABB1SitY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingYconst", m_lABB1SitY0); | ||
341 | m_lABB2SitY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingYconst", m_lABB2SitY0); | ||
342 | m_lABB1SitZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZconst", m_lABB1SitZ0); | ||
343 | m_lABB1SitZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZcoeff", m_lABB1SitZ1); | ||
344 | m_lABB2SitZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZconst", m_lABB2SitZ0); | ||
345 | m_lABB2SitZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZcoeff", m_lABB2SitZ1); | ||
346 | m_primSafetyCoeffX = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientX", m_primSafetyCoeffX); | ||
347 | m_primSafetyCoeffY = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientY", m_primSafetyCoeffY); | ||
348 | m_primSafetyCoeffZ = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientZ", m_primSafetyCoeffZ); | ||
349 | m_useCastRayV3 = lslConfig.GetBoolean("UseLlCastRayV3", m_useCastRayV3); | ||
350 | m_floatToleranceInCastRay = lslConfig.GetFloat("FloatToleranceInLlCastRay", m_floatToleranceInCastRay); | ||
351 | m_floatTolerance2InCastRay = lslConfig.GetFloat("FloatTolerance2InLlCastRay", m_floatTolerance2InCastRay); | ||
352 | m_primLodInCastRay = (DetailLevel)lslConfig.GetInt("PrimDetailLevelInLlCastRay", (int)m_primLodInCastRay); | ||
353 | m_sculptLodInCastRay = (DetailLevel)lslConfig.GetInt("SculptDetailLevelInLlCastRay", (int)m_sculptLodInCastRay); | ||
354 | m_meshLodInCastRay = (DetailLevel)lslConfig.GetInt("MeshDetailLevelInLlCastRay", (int)m_meshLodInCastRay); | ||
355 | m_avatarLodInCastRay = (DetailLevel)lslConfig.GetInt("AvatarDetailLevelInLlCastRay", (int)m_avatarLodInCastRay); | ||
356 | m_maxHitsInCastRay = lslConfig.GetInt("MaxHitsInLlCastRay", m_maxHitsInCastRay); | ||
357 | m_maxHitsPerPrimInCastRay = lslConfig.GetInt("MaxHitsPerPrimInLlCastRay", m_maxHitsPerPrimInCastRay); | ||
358 | m_maxHitsPerObjectInCastRay = lslConfig.GetInt("MaxHitsPerObjectInLlCastRay", m_maxHitsPerObjectInCastRay); | ||
359 | m_detectExitsInCastRay = lslConfig.GetBoolean("DetectExitHitsInLlCastRay", m_detectExitsInCastRay); | ||
360 | m_filterPartsInCastRay = lslConfig.GetBoolean("FilterPartsInLlCastRay", m_filterPartsInCastRay); | ||
361 | m_doAttachmentsInCastRay = lslConfig.GetBoolean("DoAttachmentsInLlCastRay", m_doAttachmentsInCastRay); | ||
362 | m_msThrottleInCastRay = lslConfig.GetInt("ThrottleTimeInMsInLlCastRay", m_msThrottleInCastRay); | ||
363 | m_msPerRegionInCastRay = lslConfig.GetInt("AvailableTimeInMsPerRegionInLlCastRay", m_msPerRegionInCastRay); | ||
364 | m_msPerAvatarInCastRay = lslConfig.GetInt("AvailableTimeInMsPerAvatarInLlCastRay", m_msPerAvatarInCastRay); | ||
365 | m_msMinInCastRay = lslConfig.GetInt("RequiredAvailableTimeInMsInLlCastRay", m_msMinInCastRay); | ||
366 | m_msMaxInCastRay = lslConfig.GetInt("MaximumAvailableTimeInMsInLlCastRay", m_msMaxInCastRay); | ||
367 | m_useMeshCacheInCastRay = lslConfig.GetBoolean("UseMeshCacheInLlCastRay", m_useMeshCacheInCastRay); | ||
368 | } | ||
369 | |||
370 | IConfig smtpConfig = seConfigSource.Configs["SMTP"]; | ||
371 | if (smtpConfig != null) | ||
372 | { | ||
373 | // there's an smtp config, so load in the snooze time. | ||
374 | EMAIL_PAUSE_TIME = smtpConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME); | ||
375 | |||
376 | m_internalObjectHost = smtpConfig.GetString("internal_object_host", m_internalObjectHost); | ||
377 | } | ||
378 | } | ||
379 | m_sleepMsOnEmail = EMAIL_PAUSE_TIME * 1000; | ||
154 | } | 380 | } |
155 | 381 | ||
156 | public override Object InitializeLifetimeService() | 382 | public override Object InitializeLifetimeService() |
@@ -171,9 +397,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
171 | delay = (int)((float)delay * m_ScriptDelayFactor); | 397 | delay = (int)((float)delay * m_ScriptDelayFactor); |
172 | if (delay == 0) | 398 | if (delay == 0) |
173 | return; | 399 | return; |
174 | System.Threading.Thread.Sleep(delay); | 400 | |
401 | Sleep(delay); | ||
175 | } | 402 | } |
176 | 403 | ||
404 | protected virtual void Sleep(int delay) | ||
405 | { | ||
406 | if (m_item == null) // Some unit tests don't set this | ||
407 | { | ||
408 | Thread.Sleep(delay); | ||
409 | return; | ||
410 | } | ||
411 | |||
412 | m_ScriptEngine.SleepScript(m_item.ItemID, delay); | ||
413 | } | ||
414 | |||
415 | /// <summary> | ||
416 | /// Check for co-operative termination. | ||
417 | /// </summary> | ||
418 | /// <param name='delay'>If called with 0, then just the check is performed with no wait.</param> | ||
419 | |||
177 | public Scene World | 420 | public Scene World |
178 | { | 421 | { |
179 | get { return m_ScriptEngine.World; } | 422 | get { return m_ScriptEngine.World; } |
@@ -209,7 +452,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
209 | if ((item = GetScriptByName(name)) != UUID.Zero) | 452 | if ((item = GetScriptByName(name)) != UUID.Zero) |
210 | m_ScriptEngine.ResetScript(item); | 453 | m_ScriptEngine.ResetScript(item); |
211 | else | 454 | else |
212 | ShoutError("llResetOtherScript: script "+name+" not found"); | 455 | Error("llResetOtherScript", "Can't find script '" + name + "'"); |
213 | } | 456 | } |
214 | 457 | ||
215 | public LSL_Integer llGetScriptState(string name) | 458 | public LSL_Integer llGetScriptState(string name) |
@@ -223,7 +466,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
223 | return m_ScriptEngine.GetScriptState(item) ?1:0; | 466 | return m_ScriptEngine.GetScriptState(item) ?1:0; |
224 | } | 467 | } |
225 | 468 | ||
226 | ShoutError("llGetScriptState: script "+name+" not found"); | 469 | Error("llGetScriptState", "Can't find script '" + name + "'"); |
227 | 470 | ||
228 | // If we didn't find it, then it's safe to | 471 | // If we didn't find it, then it's safe to |
229 | // assume it is not running. | 472 | // assume it is not running. |
@@ -246,7 +489,78 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
246 | } | 489 | } |
247 | else | 490 | else |
248 | { | 491 | { |
249 | ShoutError("llSetScriptState: script "+name+" not found"); | 492 | Error("llSetScriptState", "Can't find script '" + name + "'"); |
493 | } | ||
494 | } | ||
495 | |||
496 | /// <summary> | ||
497 | /// Get a given link entity from a linkset (linked objects and any sitting avatars). | ||
498 | /// </summary> | ||
499 | /// <remarks> | ||
500 | /// If there are any ScenePresence's in the linkset (i.e. because they are sat upon one of the prims), then | ||
501 | /// these are counted as extra entities that correspond to linknums beyond the number of prims in the linkset. | ||
502 | /// The ScenePresences receive linknums in the order in which they sat. | ||
503 | /// </remarks> | ||
504 | /// <returns> | ||
505 | /// The link entity. null if not found. | ||
506 | /// </returns> | ||
507 | /// <param name='part'></param> | ||
508 | /// <param name='linknum'> | ||
509 | /// Can be either a non-negative integer or ScriptBaseClass.LINK_THIS (-4). | ||
510 | /// If ScriptBaseClass.LINK_THIS then the entity containing the script is returned. | ||
511 | /// If the linkset has one entity and a linknum of zero is given, then the single entity is returned. If any | ||
512 | /// positive integer is given in this case then null is returned. | ||
513 | /// If the linkset has more than one entity and a linknum greater than zero but equal to or less than the number | ||
514 | /// of entities, then the entity which corresponds to that linknum is returned. | ||
515 | /// Otherwise, if a positive linknum is given which is greater than the number of entities in the linkset, then | ||
516 | /// null is returned. | ||
517 | /// </param> | ||
518 | public ISceneEntity GetLinkEntity(SceneObjectPart part, int linknum) | ||
519 | { | ||
520 | if (linknum < 0) | ||
521 | { | ||
522 | if (linknum == ScriptBaseClass.LINK_THIS) | ||
523 | return part; | ||
524 | else | ||
525 | return null; | ||
526 | } | ||
527 | |||
528 | int actualPrimCount = part.ParentGroup.PrimCount; | ||
529 | List<ScenePresence> sittingAvatars = part.ParentGroup.GetSittingAvatars(); | ||
530 | int adjustedPrimCount = actualPrimCount + sittingAvatars.Count; | ||
531 | |||
532 | // Special case for a single prim. In this case the linknum is zero. However, this will not match a single | ||
533 | // prim that has any avatars sat upon it (in which case the root prim is link 1). | ||
534 | if (linknum == 0) | ||
535 | { | ||
536 | if (actualPrimCount == 1 && sittingAvatars.Count == 0) | ||
537 | return part; | ||
538 | |||
539 | return null; | ||
540 | } | ||
541 | // Special case to handle a single prim with sitting avatars. GetLinkPart() would only match zero but | ||
542 | // here we must match 1 (ScriptBaseClass.LINK_ROOT). | ||
543 | else if (linknum == ScriptBaseClass.LINK_ROOT && actualPrimCount == 1) | ||
544 | { | ||
545 | if (sittingAvatars.Count > 0) | ||
546 | return part.ParentGroup.RootPart; | ||
547 | else | ||
548 | return null; | ||
549 | } | ||
550 | else if (linknum <= adjustedPrimCount) | ||
551 | { | ||
552 | if (linknum <= actualPrimCount) | ||
553 | { | ||
554 | return part.ParentGroup.GetLinkNumPart(linknum); | ||
555 | } | ||
556 | else | ||
557 | { | ||
558 | return sittingAvatars[linknum - actualPrimCount - 1]; | ||
559 | } | ||
560 | } | ||
561 | else | ||
562 | { | ||
563 | return null; | ||
250 | } | 564 | } |
251 | } | 565 | } |
252 | 566 | ||
@@ -301,77 +615,52 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
301 | } | 615 | } |
302 | } | 616 | } |
303 | 617 | ||
304 | protected UUID InventoryKey(string name, int type) | 618 | public List<ISceneEntity> GetLinkEntities(int linkType) |
305 | { | 619 | { |
306 | TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name); | 620 | return GetLinkEntities(m_host, linkType); |
307 | |||
308 | if (item != null && item.Type == type) | ||
309 | return item.AssetID; | ||
310 | else | ||
311 | return UUID.Zero; | ||
312 | } | 621 | } |
313 | 622 | ||
314 | /// <summary> | 623 | public List<ISceneEntity> GetLinkEntities(SceneObjectPart part, int linkType) |
315 | /// accepts a valid UUID, -or- a name of an inventory item. | ||
316 | /// Returns a valid UUID or UUID.Zero if key invalid and item not found | ||
317 | /// in prim inventory. | ||
318 | /// </summary> | ||
319 | /// <param name="k"></param> | ||
320 | /// <returns></returns> | ||
321 | protected UUID KeyOrName(string k) | ||
322 | { | 624 | { |
323 | UUID key; | 625 | List<ISceneEntity> ret; |
324 | 626 | ||
325 | // if we can parse the string as a key, use it. | 627 | switch (linkType) |
326 | // else try to locate the name in inventory of object. found returns key, | ||
327 | // not found returns UUID.Zero | ||
328 | if (!UUID.TryParse(k, out key)) | ||
329 | { | 628 | { |
330 | TaskInventoryItem item = m_host.Inventory.GetInventoryItem(k); | 629 | case ScriptBaseClass.LINK_SET: |
630 | return new List<ISceneEntity>(part.ParentGroup.Parts); | ||
331 | 631 | ||
332 | if (item != null) | 632 | case ScriptBaseClass.LINK_ROOT: |
333 | key = item.AssetID; | 633 | return new List<ISceneEntity>() { part.ParentGroup.RootPart }; |
334 | else | ||
335 | key = UUID.Zero; | ||
336 | } | ||
337 | 634 | ||
338 | return key; | 635 | case ScriptBaseClass.LINK_ALL_OTHERS: |
339 | } | 636 | ret = new List<ISceneEntity>(part.ParentGroup.Parts); |
340 | 637 | ||
341 | /// <summary> | 638 | if (ret.Contains(part)) |
342 | /// Return the UUID of the asset matching the specified key or name | 639 | ret.Remove(part); |
343 | /// and asset type. | ||
344 | /// </summary> | ||
345 | /// <param name="k"></param> | ||
346 | /// <param name="type"></param> | ||
347 | /// <returns></returns> | ||
348 | protected UUID KeyOrName(string k, AssetType type) | ||
349 | { | ||
350 | UUID key; | ||
351 | 640 | ||
352 | if (!UUID.TryParse(k, out key)) | 641 | return ret; |
353 | { | 642 | |
354 | TaskInventoryItem item = m_host.Inventory.GetInventoryItem(k); | 643 | case ScriptBaseClass.LINK_ALL_CHILDREN: |
355 | if (item != null && item.Type == (int)type) | 644 | ret = new List<ISceneEntity>(part.ParentGroup.Parts); |
356 | key = item.AssetID; | ||
357 | } | ||
358 | else | ||
359 | { | ||
360 | lock (m_host.TaskInventory) | ||
361 | { | ||
362 | foreach (KeyValuePair<UUID, TaskInventoryItem> item in m_host.TaskInventory) | ||
363 | { | ||
364 | if (item.Value.Type == (int)type && item.Value.Name == k) | ||
365 | { | ||
366 | key = item.Value.ItemID; | ||
367 | break; | ||
368 | } | ||
369 | } | ||
370 | } | ||
371 | } | ||
372 | 645 | ||
646 | if (ret.Contains(part.ParentGroup.RootPart)) | ||
647 | ret.Remove(part.ParentGroup.RootPart); | ||
373 | 648 | ||
374 | return key; | 649 | return ret; |
650 | |||
651 | case ScriptBaseClass.LINK_THIS: | ||
652 | return new List<ISceneEntity>() { part }; | ||
653 | |||
654 | default: | ||
655 | if (linkType < 0) | ||
656 | return new List<ISceneEntity>(); | ||
657 | |||
658 | ISceneEntity target = GetLinkEntity(part, linkType); | ||
659 | if (target == null) | ||
660 | return new List<ISceneEntity>(); | ||
661 | |||
662 | return new List<ISceneEntity>() { target }; | ||
663 | } | ||
375 | } | 664 | } |
376 | 665 | ||
377 | //These are the implementations of the various ll-functions used by the LSL scripts. | 666 | //These are the implementations of the various ll-functions used by the LSL scripts. |
@@ -430,10 +719,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
430 | public LSL_Float llFrand(double mag) | 719 | public LSL_Float llFrand(double mag) |
431 | { | 720 | { |
432 | m_host.AddScriptLPS(1); | 721 | m_host.AddScriptLPS(1); |
433 | lock (Util.RandomClass) | 722 | |
434 | { | 723 | return Util.RandomClass.NextDouble() * mag; |
435 | return Util.RandomClass.NextDouble() * mag; | ||
436 | } | ||
437 | } | 724 | } |
438 | 725 | ||
439 | public LSL_Integer llFloor(double f) | 726 | public LSL_Integer llFloor(double f) |
@@ -837,7 +1124,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
837 | { | 1124 | { |
838 | if (channelID == 0) | 1125 | if (channelID == 0) |
839 | { | 1126 | { |
840 | LSLError("Cannot use llRegionSay() on channel 0"); | 1127 | Error("llRegionSay", "Cannot use on channel 0"); |
841 | return; | 1128 | return; |
842 | } | 1129 | } |
843 | 1130 | ||
@@ -846,6 +1133,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
846 | 1133 | ||
847 | m_host.AddScriptLPS(1); | 1134 | m_host.AddScriptLPS(1); |
848 | 1135 | ||
1136 | World.SimChat(Utils.StringToBytes(text), | ||
1137 | ChatTypeEnum.Region, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false); | ||
1138 | |||
849 | IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); | 1139 | IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); |
850 | if (wComm != null) | 1140 | if (wComm != null) |
851 | wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, text); | 1141 | wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, text); |
@@ -866,6 +1156,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
866 | UUID TargetID; | 1156 | UUID TargetID; |
867 | UUID.TryParse(target, out TargetID); | 1157 | UUID.TryParse(target, out TargetID); |
868 | 1158 | ||
1159 | World.SimChatToAgent(TargetID, Utils.StringToBytes(msg), | ||
1160 | channel, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true); | ||
1161 | |||
869 | IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); | 1162 | IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); |
870 | if (wComm != null) | 1163 | if (wComm != null) |
871 | wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg); | 1164 | wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg); |
@@ -1255,12 +1548,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1255 | } | 1548 | } |
1256 | 1549 | ||
1257 | if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB) == ScriptBaseClass.STATUS_BLOCK_GRAB) | 1550 | if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB) == ScriptBaseClass.STATUS_BLOCK_GRAB) |
1258 | { | 1551 | m_host.BlockGrab = value != 0; |
1259 | if (value != 0) | 1552 | |
1260 | m_host.SetBlockGrab(true); | 1553 | if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT) == ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT) |
1261 | else | 1554 | m_host.ParentGroup.BlockGrabOverride = value != 0; |
1262 | m_host.SetBlockGrab(false); | ||
1263 | } | ||
1264 | 1555 | ||
1265 | if ((status & ScriptBaseClass.STATUS_DIE_AT_EDGE) == ScriptBaseClass.STATUS_DIE_AT_EDGE) | 1556 | if ((status & ScriptBaseClass.STATUS_DIE_AT_EDGE) == ScriptBaseClass.STATUS_DIE_AT_EDGE) |
1266 | { | 1557 | { |
@@ -1321,10 +1612,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1321 | return 0; | 1612 | return 0; |
1322 | 1613 | ||
1323 | case ScriptBaseClass.STATUS_BLOCK_GRAB: | 1614 | case ScriptBaseClass.STATUS_BLOCK_GRAB: |
1324 | if (m_host.GetBlockGrab()) | 1615 | return m_host.BlockGrab ? 1 : 0; |
1325 | return 1; | 1616 | |
1326 | else | 1617 | case ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT: |
1327 | return 0; | 1618 | return m_host.ParentGroup.BlockGrabOverride ? 1 : 0; |
1328 | 1619 | ||
1329 | case ScriptBaseClass.STATUS_DIE_AT_EDGE: | 1620 | case ScriptBaseClass.STATUS_DIE_AT_EDGE: |
1330 | if (m_host.GetDieAtEdge()) | 1621 | if (m_host.GetDieAtEdge()) |
@@ -1427,6 +1718,73 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1427 | m_host.SetFaceColorAlpha(face, color, null); | 1718 | m_host.SetFaceColorAlpha(face, color, null); |
1428 | } | 1719 | } |
1429 | 1720 | ||
1721 | public void llSetContentType(LSL_Key id, LSL_Integer type) | ||
1722 | { | ||
1723 | m_host.AddScriptLPS(1); | ||
1724 | |||
1725 | if (m_UrlModule == null) | ||
1726 | return; | ||
1727 | |||
1728 | // Make sure the content type is text/plain to start with | ||
1729 | m_UrlModule.HttpContentType(new UUID(id), "text/plain"); | ||
1730 | |||
1731 | // Is the object owner online and in the region | ||
1732 | ScenePresence agent = World.GetScenePresence(m_host.ParentGroup.OwnerID); | ||
1733 | if (agent == null || agent.IsChildAgent) | ||
1734 | return; // Fail if the owner is not in the same region | ||
1735 | |||
1736 | // Is it the embeded browser? | ||
1737 | string userAgent = m_UrlModule.GetHttpHeader(new UUID(id), "user-agent"); | ||
1738 | if (userAgent.IndexOf("SecondLife") < 0) | ||
1739 | return; // Not the embedded browser. Is this check good enough? | ||
1740 | |||
1741 | // Use the IP address of the client and check against the request | ||
1742 | // seperate logins from the same IP will allow all of them to get non-text/plain as long | ||
1743 | // as the owner is in the region. Same as SL! | ||
1744 | string logonFromIPAddress = agent.ControllingClient.RemoteEndPoint.Address.ToString(); | ||
1745 | string requestFromIPAddress = m_UrlModule.GetHttpHeader(new UUID(id), "remote_addr"); | ||
1746 | //m_log.Debug("IP from header='" + requestFromIPAddress + "' IP from endpoint='" + logonFromIPAddress + "'"); | ||
1747 | if (requestFromIPAddress == null || requestFromIPAddress.Trim() == "") | ||
1748 | return; | ||
1749 | if (logonFromIPAddress == null || logonFromIPAddress.Trim() == "") | ||
1750 | return; | ||
1751 | |||
1752 | // If the request isnt from the same IP address then the request cannot be from the owner | ||
1753 | if (!requestFromIPAddress.Trim().Equals(logonFromIPAddress.Trim())) | ||
1754 | return; | ||
1755 | |||
1756 | switch (type) | ||
1757 | { | ||
1758 | case ScriptBaseClass.CONTENT_TYPE_HTML: | ||
1759 | m_UrlModule.HttpContentType(new UUID(id), "text/html"); | ||
1760 | break; | ||
1761 | case ScriptBaseClass.CONTENT_TYPE_XML: | ||
1762 | m_UrlModule.HttpContentType(new UUID(id), "application/xml"); | ||
1763 | break; | ||
1764 | case ScriptBaseClass.CONTENT_TYPE_XHTML: | ||
1765 | m_UrlModule.HttpContentType(new UUID(id), "application/xhtml+xml"); | ||
1766 | break; | ||
1767 | case ScriptBaseClass.CONTENT_TYPE_ATOM: | ||
1768 | m_UrlModule.HttpContentType(new UUID(id), "application/atom+xml"); | ||
1769 | break; | ||
1770 | case ScriptBaseClass.CONTENT_TYPE_JSON: | ||
1771 | m_UrlModule.HttpContentType(new UUID(id), "application/json"); | ||
1772 | break; | ||
1773 | case ScriptBaseClass.CONTENT_TYPE_LLSD: | ||
1774 | m_UrlModule.HttpContentType(new UUID(id), "application/llsd+xml"); | ||
1775 | break; | ||
1776 | case ScriptBaseClass.CONTENT_TYPE_FORM: | ||
1777 | m_UrlModule.HttpContentType(new UUID(id), "application/x-www-form-urlencoded"); | ||
1778 | break; | ||
1779 | case ScriptBaseClass.CONTENT_TYPE_RSS: | ||
1780 | m_UrlModule.HttpContentType(new UUID(id), "application/rss+xml"); | ||
1781 | break; | ||
1782 | default: | ||
1783 | m_UrlModule.HttpContentType(new UUID(id), "text/plain"); | ||
1784 | break; | ||
1785 | } | ||
1786 | } | ||
1787 | |||
1430 | public void SetTexGen(SceneObjectPart part, int face,int style) | 1788 | public void SetTexGen(SceneObjectPart part, int face,int style) |
1431 | { | 1789 | { |
1432 | Primitive.TextureEntry tex = part.Shape.Textures; | 1790 | Primitive.TextureEntry tex = part.Shape.Textures; |
@@ -1522,7 +1880,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1522 | if (tex.FaceTextures[i] != null) | 1880 | if (tex.FaceTextures[i] != null) |
1523 | { | 1881 | { |
1524 | tex.FaceTextures[i].Shiny = sval; | 1882 | tex.FaceTextures[i].Shiny = sval; |
1525 | tex.FaceTextures[i].Bump = bump;; | 1883 | tex.FaceTextures[i].Bump = bump; |
1526 | } | 1884 | } |
1527 | tex.DefaultTexture.Shiny = sval; | 1885 | tex.DefaultTexture.Shiny = sval; |
1528 | tex.DefaultTexture.Bump = bump; | 1886 | tex.DefaultTexture.Bump = bump; |
@@ -1631,7 +1989,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1631 | texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f); | 1989 | texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f); |
1632 | tex.DefaultTexture.RGBA = texcolor; | 1990 | tex.DefaultTexture.RGBA = texcolor; |
1633 | } | 1991 | } |
1634 | 1992 | ||
1635 | part.UpdateTextureEntry(tex.GetBytes()); | 1993 | part.UpdateTextureEntry(tex.GetBytes()); |
1636 | return; | 1994 | return; |
1637 | } | 1995 | } |
@@ -1703,9 +2061,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1703 | part.Shape.LightColorR = Util.Clip((float)color.x, 0.0f, 1.0f); | 2061 | part.Shape.LightColorR = Util.Clip((float)color.x, 0.0f, 1.0f); |
1704 | part.Shape.LightColorG = Util.Clip((float)color.y, 0.0f, 1.0f); | 2062 | part.Shape.LightColorG = Util.Clip((float)color.y, 0.0f, 1.0f); |
1705 | part.Shape.LightColorB = Util.Clip((float)color.z, 0.0f, 1.0f); | 2063 | part.Shape.LightColorB = Util.Clip((float)color.z, 0.0f, 1.0f); |
1706 | part.Shape.LightIntensity = intensity; | 2064 | part.Shape.LightIntensity = Util.Clip((float)intensity, 0.0f, 1.0f); |
1707 | part.Shape.LightRadius = radius; | 2065 | part.Shape.LightRadius = Util.Clip((float)radius, 0.1f, 20.0f); |
1708 | part.Shape.LightFalloff = falloff; | 2066 | part.Shape.LightFalloff = Util.Clip((float)falloff, 0.01f, 2.0f); |
1709 | } | 2067 | } |
1710 | else | 2068 | else |
1711 | { | 2069 | { |
@@ -1752,7 +2110,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1752 | rgb.x = texcolor.R; | 2110 | rgb.x = texcolor.R; |
1753 | rgb.y = texcolor.G; | 2111 | rgb.y = texcolor.G; |
1754 | rgb.z = texcolor.B; | 2112 | rgb.z = texcolor.B; |
1755 | 2113 | ||
1756 | return rgb; | 2114 | return rgb; |
1757 | } | 2115 | } |
1758 | else | 2116 | else |
@@ -1765,7 +2123,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1765 | { | 2123 | { |
1766 | m_host.AddScriptLPS(1); | 2124 | m_host.AddScriptLPS(1); |
1767 | SetTexture(m_host, texture, face); | 2125 | SetTexture(m_host, texture, face); |
1768 | ScriptSleep(200); | 2126 | ScriptSleep(m_sleepMsOnSetTexture); |
1769 | } | 2127 | } |
1770 | 2128 | ||
1771 | public void llSetLinkTexture(int linknumber, string texture, int face) | 2129 | public void llSetLinkTexture(int linknumber, string texture, int face) |
@@ -1777,19 +2135,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1777 | foreach (SceneObjectPart part in parts) | 2135 | foreach (SceneObjectPart part in parts) |
1778 | SetTexture(part, texture, face); | 2136 | SetTexture(part, texture, face); |
1779 | 2137 | ||
1780 | ScriptSleep(200); | 2138 | ScriptSleep(m_sleepMsOnSetLinkTexture); |
1781 | } | 2139 | } |
1782 | 2140 | ||
1783 | protected void SetTexture(SceneObjectPart part, string texture, int face) | 2141 | protected void SetTexture(SceneObjectPart part, string texture, int face) |
1784 | { | 2142 | { |
1785 | UUID textureID = new UUID(); | 2143 | UUID textureID = new UUID(); |
1786 | 2144 | ||
1787 | textureID = InventoryKey(texture, (int)AssetType.Texture); | 2145 | textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture); |
1788 | if (textureID == UUID.Zero) | 2146 | if (textureID == UUID.Zero) |
1789 | { | 2147 | { |
1790 | if (!UUID.TryParse(texture, out textureID)) | 2148 | if (!UUID.TryParse(texture, out textureID)) |
1791 | return; | 2149 | return; |
1792 | } | 2150 | } |
1793 | 2151 | ||
1794 | Primitive.TextureEntry tex = part.Shape.Textures; | 2152 | Primitive.TextureEntry tex = part.Shape.Textures; |
1795 | 2153 | ||
@@ -1821,7 +2179,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1821 | m_host.AddScriptLPS(1); | 2179 | m_host.AddScriptLPS(1); |
1822 | 2180 | ||
1823 | ScaleTexture(m_host, u, v, face); | 2181 | ScaleTexture(m_host, u, v, face); |
1824 | ScriptSleep(200); | 2182 | ScriptSleep(m_sleepMsOnScaleTexture); |
1825 | } | 2183 | } |
1826 | 2184 | ||
1827 | protected void ScaleTexture(SceneObjectPart part, double u, double v, int face) | 2185 | protected void ScaleTexture(SceneObjectPart part, double u, double v, int face) |
@@ -1857,7 +2215,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1857 | { | 2215 | { |
1858 | m_host.AddScriptLPS(1); | 2216 | m_host.AddScriptLPS(1); |
1859 | OffsetTexture(m_host, u, v, face); | 2217 | OffsetTexture(m_host, u, v, face); |
1860 | ScriptSleep(200); | 2218 | ScriptSleep(m_sleepMsOnOffsetTexture); |
1861 | } | 2219 | } |
1862 | 2220 | ||
1863 | protected void OffsetTexture(SceneObjectPart part, double u, double v, int face) | 2221 | protected void OffsetTexture(SceneObjectPart part, double u, double v, int face) |
@@ -1893,7 +2251,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1893 | { | 2251 | { |
1894 | m_host.AddScriptLPS(1); | 2252 | m_host.AddScriptLPS(1); |
1895 | RotateTexture(m_host, rotation, face); | 2253 | RotateTexture(m_host, rotation, face); |
1896 | ScriptSleep(200); | 2254 | ScriptSleep(m_sleepMsOnRotateTexture); |
1897 | } | 2255 | } |
1898 | 2256 | ||
1899 | protected void RotateTexture(SceneObjectPart part, double rotation, int face) | 2257 | protected void RotateTexture(SceneObjectPart part, double rotation, int face) |
@@ -1968,7 +2326,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1968 | 2326 | ||
1969 | SetPos(m_host, pos, true); | 2327 | SetPos(m_host, pos, true); |
1970 | 2328 | ||
1971 | ScriptSleep(200); | 2329 | ScriptSleep(m_sleepMsOnSetPos); |
1972 | } | 2330 | } |
1973 | 2331 | ||
1974 | /// <summary> | 2332 | /// <summary> |
@@ -1986,8 +2344,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1986 | // IF YOU GET REGION CROSSINGS WORKING WITH THIS FUNCTION, REPLACE THE WORKAROUND. | 2344 | // IF YOU GET REGION CROSSINGS WORKING WITH THIS FUNCTION, REPLACE THE WORKAROUND. |
1987 | // | 2345 | // |
1988 | // This workaround is to prevent silent failure of this function. | 2346 | // This workaround is to prevent silent failure of this function. |
1989 | // According to the specification on the SL Wiki, providing a position outside of the | 2347 | // According to the specification on the SL Wiki, providing a position outside of the |
1990 | if (pos.x < 0 || pos.x > Constants.RegionSize || pos.y < 0 || pos.y > Constants.RegionSize) | 2348 | if (pos.x < 0 || pos.x > World.RegionInfo.RegionSizeX || pos.y < 0 || pos.y > World.RegionInfo.RegionSizeY) |
1991 | { | 2349 | { |
1992 | return 0; | 2350 | return 0; |
1993 | } | 2351 | } |
@@ -1997,9 +2355,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1997 | m_host.ParentGroup.IsAttachment || // return FALSE if attachment | 2355 | m_host.ParentGroup.IsAttachment || // return FALSE if attachment |
1998 | ( | 2356 | ( |
1999 | pos.x < -10.0 || // return FALSE if more than 10 meters into a west-adjacent region. | 2357 | pos.x < -10.0 || // return FALSE if more than 10 meters into a west-adjacent region. |
2000 | pos.x > (Constants.RegionSize + 10) || // return FALSE if more than 10 meters into a east-adjacent region. | 2358 | pos.x > (World.RegionInfo.RegionSizeX + 10) || // return FALSE if more than 10 meters into a east-adjacent region. |
2001 | pos.y < -10.0 || // return FALSE if more than 10 meters into a south-adjacent region. | 2359 | pos.y < -10.0 || // return FALSE if more than 10 meters into a south-adjacent region. |
2002 | pos.y > (Constants.RegionSize + 10) || // return FALSE if more than 10 meters into a north-adjacent region. | 2360 | pos.y > (World.RegionInfo.RegionSizeY + 10) || // return FALSE if more than 10 meters into a north-adjacent region. |
2003 | pos.z > Constants.RegionHeight // return FALSE if altitude than 4096m | 2361 | pos.z > Constants.RegionHeight // return FALSE if altitude than 4096m |
2004 | ) | 2362 | ) |
2005 | ) | 2363 | ) |
@@ -2151,14 +2509,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2151 | } | 2509 | } |
2152 | } | 2510 | } |
2153 | 2511 | ||
2154 | ScriptSleep(200); | 2512 | ScriptSleep(m_sleepMsOnSetRot); |
2155 | } | 2513 | } |
2156 | 2514 | ||
2157 | public void llSetLocalRot(LSL_Rotation rot) | 2515 | public void llSetLocalRot(LSL_Rotation rot) |
2158 | { | 2516 | { |
2159 | m_host.AddScriptLPS(1); | 2517 | m_host.AddScriptLPS(1); |
2160 | SetRot(m_host, rot); | 2518 | SetRot(m_host, rot); |
2161 | ScriptSleep(200); | 2519 | ScriptSleep(m_sleepMsOnSetLocalRot); |
2162 | } | 2520 | } |
2163 | 2521 | ||
2164 | protected void SetRot(SceneObjectPart part, Quaternion rot) | 2522 | protected void SetRot(SceneObjectPart part, Quaternion rot) |
@@ -2195,7 +2553,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2195 | { | 2553 | { |
2196 | return llGetRootRotation(); | 2554 | return llGetRootRotation(); |
2197 | } | 2555 | } |
2198 | 2556 | ||
2199 | m_host.AddScriptLPS(1); | 2557 | m_host.AddScriptLPS(1); |
2200 | Quaternion q = m_host.GetWorldRotation(); | 2558 | Quaternion q = m_host.GetWorldRotation(); |
2201 | return new LSL_Rotation(q.X, q.Y, q.Z, q.W); | 2559 | return new LSL_Rotation(q.X, q.Y, q.Z, q.W); |
@@ -2214,23 +2572,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2214 | if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0) | 2572 | if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0) |
2215 | q = avatar.CameraRotation; // Mouselook | 2573 | q = avatar.CameraRotation; // Mouselook |
2216 | else | 2574 | else |
2217 | q = avatar.Rotation; // Currently infrequently updated so may be inaccurate | 2575 | q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate |
2218 | } | 2576 | } |
2219 | else | 2577 | else |
2220 | q = part.ParentGroup.GroupRotation; // Likely never get here but just in case | 2578 | q = part.ParentGroup.GroupRotation; // Likely never get here but just in case |
2221 | } | 2579 | } |
2222 | else | 2580 | else |
2223 | q = part.ParentGroup.GroupRotation; // just the group rotation | 2581 | q = part.ParentGroup.GroupRotation; // just the group rotation |
2224 | return new LSL_Rotation(q.X, q.Y, q.Z, q.W); | 2582 | |
2583 | return new LSL_Rotation(q); | ||
2225 | } | 2584 | } |
2226 | q = part.GetWorldRotation(); | 2585 | |
2227 | return new LSL_Rotation(q.X, q.Y, q.Z, q.W); | 2586 | return new LSL_Rotation(part.GetWorldRotation()); |
2228 | } | 2587 | } |
2229 | 2588 | ||
2230 | public LSL_Rotation llGetLocalRot() | 2589 | public LSL_Rotation llGetLocalRot() |
2231 | { | 2590 | { |
2232 | m_host.AddScriptLPS(1); | 2591 | m_host.AddScriptLPS(1); |
2233 | return new LSL_Rotation(m_host.RotationOffset.X, m_host.RotationOffset.Y, m_host.RotationOffset.Z, m_host.RotationOffset.W); | 2592 | |
2593 | return new LSL_Rotation(m_host.RotationOffset); | ||
2234 | } | 2594 | } |
2235 | 2595 | ||
2236 | public void llSetForce(LSL_Vector force, int local) | 2596 | public void llSetForce(LSL_Vector force, int local) |
@@ -2260,6 +2620,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2260 | return force; | 2620 | return force; |
2261 | } | 2621 | } |
2262 | 2622 | ||
2623 | public void llSetVelocity(LSL_Vector velocity, int local) | ||
2624 | { | ||
2625 | m_host.AddScriptLPS(1); | ||
2626 | |||
2627 | if (!m_host.ParentGroup.IsDeleted) | ||
2628 | { | ||
2629 | if (local != 0) | ||
2630 | velocity *= llGetRot(); | ||
2631 | |||
2632 | m_host.ParentGroup.RootPart.Velocity = velocity; | ||
2633 | } | ||
2634 | } | ||
2635 | |||
2636 | public void llSetAngularVelocity(LSL_Vector angularVelocity, int local) | ||
2637 | { | ||
2638 | m_host.AddScriptLPS(1); | ||
2639 | |||
2640 | if (!m_host.ParentGroup.IsDeleted) | ||
2641 | { | ||
2642 | if (local != 0) | ||
2643 | angularVelocity *= llGetRot(); | ||
2644 | |||
2645 | m_host.ParentGroup.RootPart.AngularVelocity = angularVelocity; | ||
2646 | } | ||
2647 | } | ||
2648 | |||
2263 | public LSL_Integer llTarget(LSL_Vector position, double range) | 2649 | public LSL_Integer llTarget(LSL_Vector position, double range) |
2264 | { | 2650 | { |
2265 | m_host.AddScriptLPS(1); | 2651 | m_host.AddScriptLPS(1); |
@@ -2325,8 +2711,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2325 | public LSL_Vector llGetTorque() | 2711 | public LSL_Vector llGetTorque() |
2326 | { | 2712 | { |
2327 | m_host.AddScriptLPS(1); | 2713 | m_host.AddScriptLPS(1); |
2328 | Vector3 torque = m_host.ParentGroup.GetTorque(); | 2714 | |
2329 | return new LSL_Vector(torque.X,torque.Y,torque.Z); | 2715 | return new LSL_Vector(m_host.ParentGroup.GetTorque()); |
2330 | } | 2716 | } |
2331 | 2717 | ||
2332 | public void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local) | 2718 | public void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local) |
@@ -2345,26 +2731,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2345 | if (m_host.ParentGroup.IsAttachment) | 2731 | if (m_host.ParentGroup.IsAttachment) |
2346 | { | 2732 | { |
2347 | ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar); | 2733 | ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar); |
2348 | vel = avatar.Velocity; | 2734 | vel = avatar.GetWorldVelocity(); |
2349 | } | 2735 | } |
2350 | else | 2736 | else |
2351 | { | 2737 | { |
2352 | vel = m_host.Velocity; | 2738 | vel = m_host.Velocity; |
2353 | } | 2739 | } |
2354 | 2740 | ||
2355 | return new LSL_Vector(vel.X, vel.Y, vel.Z); | 2741 | return new LSL_Vector(vel); |
2356 | } | 2742 | } |
2357 | 2743 | ||
2358 | public LSL_Vector llGetAccel() | 2744 | public LSL_Vector llGetAccel() |
2359 | { | 2745 | { |
2360 | m_host.AddScriptLPS(1); | 2746 | m_host.AddScriptLPS(1); |
2361 | return new LSL_Vector(m_host.Acceleration.X, m_host.Acceleration.Y, m_host.Acceleration.Z); | 2747 | |
2748 | return new LSL_Vector(m_host.Acceleration); | ||
2362 | } | 2749 | } |
2363 | 2750 | ||
2364 | public LSL_Vector llGetOmega() | 2751 | public LSL_Vector llGetOmega() |
2365 | { | 2752 | { |
2366 | m_host.AddScriptLPS(1); | 2753 | m_host.AddScriptLPS(1); |
2367 | return new LSL_Vector(m_host.AngularVelocity.X, m_host.AngularVelocity.Y, m_host.AngularVelocity.Z); | 2754 | |
2755 | return new LSL_Vector(m_host.AngularVelocity); | ||
2368 | } | 2756 | } |
2369 | 2757 | ||
2370 | public LSL_Float llGetTimeOfDay() | 2758 | public LSL_Float llGetTimeOfDay() |
@@ -2403,9 +2791,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2403 | public void llSound(string sound, double volume, int queue, int loop) | 2791 | public void llSound(string sound, double volume, int queue, int loop) |
2404 | { | 2792 | { |
2405 | m_host.AddScriptLPS(1); | 2793 | m_host.AddScriptLPS(1); |
2406 | // This function has been deprecated | 2794 | Deprecated("llSound", "Use llPlaySound instead"); |
2407 | // see http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSound | ||
2408 | Deprecated("llSound"); | ||
2409 | } | 2795 | } |
2410 | 2796 | ||
2411 | // Xantor 20080528 PlaySound updated so it accepts an objectinventory name -or- a key to a sound | 2797 | // Xantor 20080528 PlaySound updated so it accepts an objectinventory name -or- a key to a sound |
@@ -2417,9 +2803,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2417 | // send the sound, once, to all clients in range | 2803 | // send the sound, once, to all clients in range |
2418 | if (m_SoundModule != null) | 2804 | if (m_SoundModule != null) |
2419 | { | 2805 | { |
2420 | m_SoundModule.SendSound(m_host.UUID, | 2806 | m_SoundModule.SendSound( |
2421 | KeyOrName(sound, AssetType.Sound), volume, false, 0, | 2807 | m_host.UUID, |
2422 | 0, false, false); | 2808 | ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), |
2809 | volume, false, m_host.SoundQueueing ? (byte)SoundFlags.Queue : (byte)SoundFlags.None, | ||
2810 | 0, false, false); | ||
2423 | } | 2811 | } |
2424 | } | 2812 | } |
2425 | 2813 | ||
@@ -2428,7 +2816,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2428 | m_host.AddScriptLPS(1); | 2816 | m_host.AddScriptLPS(1); |
2429 | if (m_SoundModule != null) | 2817 | if (m_SoundModule != null) |
2430 | { | 2818 | { |
2431 | m_SoundModule.LoopSound(m_host.UUID, KeyOrName(sound), | 2819 | m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), |
2432 | volume, 20, false); | 2820 | volume, 20, false); |
2433 | } | 2821 | } |
2434 | } | 2822 | } |
@@ -2438,7 +2826,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2438 | m_host.AddScriptLPS(1); | 2826 | m_host.AddScriptLPS(1); |
2439 | if (m_SoundModule != null) | 2827 | if (m_SoundModule != null) |
2440 | { | 2828 | { |
2441 | m_SoundModule.LoopSound(m_host.UUID, KeyOrName(sound), | 2829 | m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), |
2442 | volume, 20, true); | 2830 | volume, 20, true); |
2443 | } | 2831 | } |
2444 | } | 2832 | } |
@@ -2460,7 +2848,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2460 | if (m_SoundModule != null) | 2848 | if (m_SoundModule != null) |
2461 | { | 2849 | { |
2462 | m_SoundModule.SendSound(m_host.UUID, | 2850 | m_SoundModule.SendSound(m_host.UUID, |
2463 | KeyOrName(sound, AssetType.Sound), volume, false, 0, | 2851 | ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, false, 0, |
2464 | 0, true, false); | 2852 | 0, true, false); |
2465 | } | 2853 | } |
2466 | } | 2854 | } |
@@ -2472,7 +2860,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2472 | if (m_SoundModule != null) | 2860 | if (m_SoundModule != null) |
2473 | { | 2861 | { |
2474 | m_SoundModule.SendSound(m_host.UUID, | 2862 | m_SoundModule.SendSound(m_host.UUID, |
2475 | KeyOrName(sound, AssetType.Sound), volume, true, 0, 0, | 2863 | ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, true, 0, 0, |
2476 | false, false); | 2864 | false, false); |
2477 | } | 2865 | } |
2478 | } | 2866 | } |
@@ -2489,8 +2877,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2489 | { | 2877 | { |
2490 | m_host.AddScriptLPS(1); | 2878 | m_host.AddScriptLPS(1); |
2491 | if (m_SoundModule != null) | 2879 | if (m_SoundModule != null) |
2492 | m_SoundModule.PreloadSound(m_host.UUID, KeyOrName(sound), 0); | 2880 | m_SoundModule.PreloadSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), 0); |
2493 | ScriptSleep(1000); | 2881 | ScriptSleep(m_sleepMsOnPreloadSound); |
2494 | } | 2882 | } |
2495 | 2883 | ||
2496 | /// <summary> | 2884 | /// <summary> |
@@ -2723,70 +3111,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2723 | return src.ToLower(); | 3111 | return src.ToLower(); |
2724 | } | 3112 | } |
2725 | 3113 | ||
2726 | public LSL_Integer llGiveMoney(string destination, int amount) | 3114 | public void llGiveMoney(string destination, int amount) |
2727 | { | 3115 | { |
2728 | m_host.AddScriptLPS(1); | 3116 | Util.FireAndForget(x => |
2729 | |||
2730 | if (m_item.PermsGranter == UUID.Zero) | ||
2731 | return 0; | ||
2732 | |||
2733 | if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0) | ||
2734 | { | 3117 | { |
2735 | LSLError("No permissions to give money"); | 3118 | m_host.AddScriptLPS(1); |
2736 | return 0; | ||
2737 | } | ||
2738 | 3119 | ||
2739 | UUID toID = new UUID(); | 3120 | if (m_item.PermsGranter == UUID.Zero) |
3121 | return; | ||
2740 | 3122 | ||
2741 | if (!UUID.TryParse(destination, out toID)) | 3123 | if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0) |
2742 | { | 3124 | { |
2743 | LSLError("Bad key in llGiveMoney"); | 3125 | Error("llGiveMoney", "No permissions to give money"); |
2744 | return 0; | 3126 | return; |
2745 | } | 3127 | } |
2746 | 3128 | ||
2747 | IMoneyModule money = World.RequestModuleInterface<IMoneyModule>(); | 3129 | UUID toID = new UUID(); |
2748 | 3130 | ||
2749 | if (money == null) | 3131 | if (!UUID.TryParse(destination, out toID)) |
2750 | { | 3132 | { |
2751 | NotImplemented("llGiveMoney"); | 3133 | Error("llGiveMoney", "Bad key in llGiveMoney"); |
2752 | return 0; | 3134 | return; |
2753 | } | 3135 | } |
2754 | 3136 | ||
2755 | bool result = money.ObjectGiveMoney( | 3137 | IMoneyModule money = World.RequestModuleInterface<IMoneyModule>(); |
2756 | m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount); | ||
2757 | 3138 | ||
2758 | if (result) | 3139 | if (money == null) |
2759 | return 1; | 3140 | { |
3141 | NotImplemented("llGiveMoney"); | ||
3142 | return; | ||
3143 | } | ||
2760 | 3144 | ||
2761 | return 0; | 3145 | money.ObjectGiveMoney( |
3146 | m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount); | ||
3147 | }, null, "LSL_Api.llGiveMoney"); | ||
2762 | } | 3148 | } |
2763 | 3149 | ||
2764 | public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset) | 3150 | public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset) |
2765 | { | 3151 | { |
2766 | m_host.AddScriptLPS(1); | 3152 | m_host.AddScriptLPS(1); |
2767 | Deprecated("llMakeExplosion"); | 3153 | Deprecated("llMakeExplosion", "Use llParticleSystem instead"); |
2768 | ScriptSleep(100); | 3154 | ScriptSleep(m_sleepMsOnMakeExplosion); |
2769 | } | 3155 | } |
2770 | 3156 | ||
2771 | public void llMakeFountain(int particles, double scale, double vel, double lifetime, double arc, int bounce, string texture, LSL_Vector offset, double bounce_offset) | 3157 | public void llMakeFountain(int particles, double scale, double vel, double lifetime, double arc, int bounce, string texture, LSL_Vector offset, double bounce_offset) |
2772 | { | 3158 | { |
2773 | m_host.AddScriptLPS(1); | 3159 | m_host.AddScriptLPS(1); |
2774 | Deprecated("llMakeFountain"); | 3160 | Deprecated("llMakeFountain", "Use llParticleSystem instead"); |
2775 | ScriptSleep(100); | 3161 | ScriptSleep(m_sleepMsOnMakeFountain); |
2776 | } | 3162 | } |
2777 | 3163 | ||
2778 | public void llMakeSmoke(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset) | 3164 | public void llMakeSmoke(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset) |
2779 | { | 3165 | { |
2780 | m_host.AddScriptLPS(1); | 3166 | m_host.AddScriptLPS(1); |
2781 | Deprecated("llMakeSmoke"); | 3167 | Deprecated("llMakeSmoke", "Use llParticleSystem instead"); |
2782 | ScriptSleep(100); | 3168 | ScriptSleep(m_sleepMsOnMakeSmoke); |
2783 | } | 3169 | } |
2784 | 3170 | ||
2785 | public void llMakeFire(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset) | 3171 | public void llMakeFire(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset) |
2786 | { | 3172 | { |
2787 | m_host.AddScriptLPS(1); | 3173 | m_host.AddScriptLPS(1); |
2788 | Deprecated("llMakeFire"); | 3174 | Deprecated("llMakeFire", "Use llParticleSystem instead"); |
2789 | ScriptSleep(100); | 3175 | ScriptSleep(m_sleepMsOnMakeFire); |
2790 | } | 3176 | } |
2791 | 3177 | ||
2792 | public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param) | 3178 | public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param) |
@@ -2807,54 +3193,57 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2807 | 3193 | ||
2808 | if (item == null) | 3194 | if (item == null) |
2809 | { | 3195 | { |
2810 | llSay(0, "Could not find object " + inventory); | 3196 | Error("llRezAtRoot", "Can't find object '" + inventory + "'"); |
2811 | return; | 3197 | return; |
2812 | } | 3198 | } |
2813 | 3199 | ||
2814 | if (item.InvType != (int)InventoryType.Object) | 3200 | if (item.InvType != (int)InventoryType.Object) |
2815 | { | 3201 | { |
2816 | llSay(0, "Unable to create requested object. Object is missing from database."); | 3202 | Error("llRezAtRoot", "Can't create requested object; object is missing from database"); |
2817 | return; | 3203 | return; |
2818 | } | 3204 | } |
2819 | 3205 | ||
2820 | // need the magnitude later | 3206 | // need the magnitude later |
2821 | // float velmag = (float)Util.GetMagnitude(llvel); | 3207 | // float velmag = (float)Util.GetMagnitude(llvel); |
2822 | 3208 | ||
2823 | SceneObjectGroup new_group = World.RezObject(m_host, item, pos, rot, vel, param); | 3209 | List<SceneObjectGroup> new_groups = World.RezObject(m_host, item, pos, rot, vel, param); |
2824 | 3210 | ||
2825 | // If either of these are null, then there was an unknown error. | 3211 | // If either of these are null, then there was an unknown error. |
2826 | if (new_group == null) | 3212 | if (new_groups == null) |
2827 | return; | 3213 | return; |
2828 | 3214 | ||
2829 | // objects rezzed with this method are die_at_edge by default. | 3215 | foreach (SceneObjectGroup group in new_groups) |
2830 | new_group.RootPart.SetDieAtEdge(true); | 3216 | { |
3217 | // objects rezzed with this method are die_at_edge by default. | ||
3218 | group.RootPart.SetDieAtEdge(true); | ||
2831 | 3219 | ||
2832 | new_group.ResumeScripts(); | 3220 | group.ResumeScripts(); |
2833 | 3221 | ||
2834 | m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams( | 3222 | m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams( |
2835 | "object_rez", new Object[] { | 3223 | "object_rez", new Object[] { |
2836 | new LSL_String( | 3224 | new LSL_String( |
2837 | new_group.RootPart.UUID.ToString()) }, | 3225 | group.RootPart.UUID.ToString()) }, |
2838 | new DetectParams[0])); | 3226 | new DetectParams[0])); |
2839 | 3227 | ||
2840 | float groupmass = new_group.GetMass(); | 3228 | float groupmass = group.GetMass(); |
2841 | 3229 | ||
2842 | PhysicsActor pa = new_group.RootPart.PhysActor; | 3230 | PhysicsActor pa = group.RootPart.PhysActor; |
2843 | 3231 | ||
2844 | //Recoil. | 3232 | //Recoil. |
2845 | if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero) | 3233 | if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero) |
2846 | { | ||
2847 | Vector3 recoil = -vel * groupmass * m_recoilScaleFactor; | ||
2848 | if (recoil != Vector3.Zero) | ||
2849 | { | 3234 | { |
2850 | llApplyImpulse(recoil, 0); | 3235 | Vector3 recoil = -vel * groupmass * m_recoilScaleFactor; |
3236 | if (recoil != Vector3.Zero) | ||
3237 | { | ||
3238 | llApplyImpulse(recoil, 0); | ||
3239 | } | ||
2851 | } | 3240 | } |
3241 | // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) | ||
2852 | } | 3242 | } |
2853 | // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) | 3243 | }, null, "LSL_Api.llRezAtRoot"); |
2854 | }); | ||
2855 | 3244 | ||
2856 | //ScriptSleep((int)((groupmass * velmag) / 10)); | 3245 | //ScriptSleep((int)((groupmass * velmag) / 10)); |
2857 | ScriptSleep(100); | 3246 | ScriptSleep(m_sleepMsOnRezAtRoot); |
2858 | } | 3247 | } |
2859 | 3248 | ||
2860 | public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param) | 3249 | public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param) |
@@ -2868,26 +3257,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2868 | // Determine where we are looking from | 3257 | // Determine where we are looking from |
2869 | LSL_Vector from = llGetPos(); | 3258 | LSL_Vector from = llGetPos(); |
2870 | 3259 | ||
2871 | // Work out the normalised vector from the source to the target | 3260 | // normalized direction to target |
2872 | LSL_Vector delta = llVecNorm(target - from); | 3261 | LSL_Vector dir = llVecNorm(target - from); |
2873 | LSL_Vector angle = new LSL_Vector(0,0,0); | 3262 | // use vertical to help compute left axis |
3263 | LSL_Vector up = new LSL_Vector(0.0, 0.0, 1.0); | ||
3264 | // find normalized left axis parallel to horizon | ||
3265 | LSL_Vector left = llVecNorm(LSL_Vector.Cross(up, dir)); | ||
3266 | // make up orthogonal to left and dir | ||
3267 | up = LSL_Vector.Cross(dir, left); | ||
2874 | 3268 | ||
2875 | // Calculate the yaw | 3269 | // compute rotation based on orthogonal axes |
2876 | // subtracting PI_BY_TWO is required to compensate for the odd SL co-ordinate system | 3270 | LSL_Rotation rot = new LSL_Rotation(0.0, 0.707107, 0.0, 0.707107) * llAxes2Rot(dir, left, up); |
2877 | angle.x = llAtan2(delta.z, delta.y) - ScriptBaseClass.PI_BY_TWO; | ||
2878 | 3271 | ||
2879 | // Calculate pitch | ||
2880 | angle.y = llAtan2(delta.x, llSqrt((delta.y * delta.y) + (delta.z * delta.z))); | ||
2881 | |||
2882 | // we need to convert from a vector describing | ||
2883 | // the angles of rotation in radians into rotation value | ||
2884 | LSL_Rotation rot = llEuler2Rot(angle); | ||
2885 | |||
2886 | // Per discussion with Melanie, for non-physical objects llLookAt appears to simply | 3272 | // Per discussion with Melanie, for non-physical objects llLookAt appears to simply |
2887 | // set the rotation of the object, copy that behavior | 3273 | // set the rotation of the object, copy that behavior |
2888 | PhysicsActor pa = m_host.PhysActor; | 3274 | PhysicsActor pa = m_host.PhysActor; |
2889 | 3275 | ||
2890 | if (strength == 0 || pa == null || !pa.IsPhysical) | 3276 | if (m_host.ParentGroup.IsAttachment || strength == 0 || pa == null || !pa.IsPhysical) |
2891 | { | 3277 | { |
2892 | llSetRot(rot); | 3278 | llSetRot(rot); |
2893 | } | 3279 | } |
@@ -2900,7 +3286,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2900 | public void llStopLookAt() | 3286 | public void llStopLookAt() |
2901 | { | 3287 | { |
2902 | m_host.AddScriptLPS(1); | 3288 | m_host.AddScriptLPS(1); |
2903 | // NotImplemented("llStopLookAt"); | ||
2904 | m_host.StopLookAt(); | 3289 | m_host.StopLookAt(); |
2905 | } | 3290 | } |
2906 | 3291 | ||
@@ -2917,7 +3302,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2917 | { | 3302 | { |
2918 | // m_log.Info("llSleep snoozing " + sec + "s."); | 3303 | // m_log.Info("llSleep snoozing " + sec + "s."); |
2919 | m_host.AddScriptLPS(1); | 3304 | m_host.AddScriptLPS(1); |
2920 | Thread.Sleep((int)(sec * 1000)); | 3305 | |
3306 | Sleep((int)(sec * 1000)); | ||
2921 | } | 3307 | } |
2922 | 3308 | ||
2923 | public LSL_Float llGetMass() | 3309 | public LSL_Float llGetMass() |
@@ -2950,6 +3336,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2950 | } | 3336 | } |
2951 | } | 3337 | } |
2952 | 3338 | ||
3339 | public LSL_Float llGetMassMKS() | ||
3340 | { | ||
3341 | // this is what the wiki says it does! | ||
3342 | // http://wiki.secondlife.com/wiki/LlGetMassMKS | ||
3343 | return llGetMass() * 100.0; | ||
3344 | } | ||
3345 | |||
2953 | public void llCollisionFilter(string name, string id, int accept) | 3346 | public void llCollisionFilter(string name, string id, int accept) |
2954 | { | 3347 | { |
2955 | m_host.AddScriptLPS(1); | 3348 | m_host.AddScriptLPS(1); |
@@ -2958,7 +3351,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2958 | 3351 | ||
2959 | if (!UUID.TryParse(id, out objectID)) | 3352 | if (!UUID.TryParse(id, out objectID)) |
2960 | objectID = UUID.Zero; | 3353 | objectID = UUID.Zero; |
2961 | 3354 | ||
2962 | if (objectID == UUID.Zero && name == "") | 3355 | if (objectID == UUID.Zero && name == "") |
2963 | return; | 3356 | return; |
2964 | 3357 | ||
@@ -3026,7 +3419,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3026 | IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; | 3419 | IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; |
3027 | 3420 | ||
3028 | if (attachmentsModule != null) | 3421 | if (attachmentsModule != null) |
3029 | return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, false); | 3422 | return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, true); |
3030 | else | 3423 | else |
3031 | return false; | 3424 | return false; |
3032 | } | 3425 | } |
@@ -3039,7 +3432,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3039 | /// </remarks> | 3432 | /// </remarks> |
3040 | public void DetachFromAvatar() | 3433 | public void DetachFromAvatar() |
3041 | { | 3434 | { |
3042 | Util.FireAndForget(DetachWrapper, m_host); | 3435 | Util.FireAndForget(DetachWrapper, m_host, "LSL_Api.DetachFromAvatar"); |
3043 | } | 3436 | } |
3044 | 3437 | ||
3045 | private void DetachWrapper(object o) | 3438 | private void DetachWrapper(object o) |
@@ -3083,13 +3476,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3083 | public void llTakeCamera(string avatar) | 3476 | public void llTakeCamera(string avatar) |
3084 | { | 3477 | { |
3085 | m_host.AddScriptLPS(1); | 3478 | m_host.AddScriptLPS(1); |
3086 | Deprecated("llTakeCamera"); | 3479 | Deprecated("llTakeCamera", "Use llSetCameraParams instead"); |
3087 | } | 3480 | } |
3088 | 3481 | ||
3089 | public void llReleaseCamera(string avatar) | 3482 | public void llReleaseCamera(string avatar) |
3090 | { | 3483 | { |
3091 | m_host.AddScriptLPS(1); | 3484 | m_host.AddScriptLPS(1); |
3092 | Deprecated("llReleaseCamera"); | 3485 | Deprecated("llReleaseCamera", "Use llClearCameraParams instead"); |
3093 | } | 3486 | } |
3094 | 3487 | ||
3095 | public LSL_String llGetOwner() | 3488 | public LSL_String llGetOwner() |
@@ -3112,14 +3505,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3112 | 3505 | ||
3113 | // TODO: figure out values for client, fromSession, and imSessionID | 3506 | // TODO: figure out values for client, fromSession, and imSessionID |
3114 | // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch()); | 3507 | // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch()); |
3115 | UUID friendTransactionID = UUID.Random(); | ||
3116 | |||
3117 | //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); | ||
3118 | 3508 | ||
3119 | GridInstantMessage msg = new GridInstantMessage(); | 3509 | GridInstantMessage msg = new GridInstantMessage(); |
3120 | msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid; | 3510 | msg.fromAgentID = new Guid(m_host.OwnerID.ToString()); // fromAgentID.Guid; |
3121 | msg.toAgentID = new Guid(user); // toAgentID.Guid; | 3511 | msg.toAgentID = new Guid(user); // toAgentID.Guid; |
3122 | msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here | 3512 | msg.imSessionID = new Guid(m_host.UUID.ToString()); // This is the item we're mucking with here |
3123 | // m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message); | 3513 | // m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message); |
3124 | // m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString()); | 3514 | // m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString()); |
3125 | msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp; | 3515 | msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp; |
@@ -3142,20 +3532,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3142 | msg.ParentEstateID = 0; //ParentEstateID; | 3532 | msg.ParentEstateID = 0; //ParentEstateID; |
3143 | msg.Position = new Vector3(m_host.AbsolutePosition); | 3533 | msg.Position = new Vector3(m_host.AbsolutePosition); |
3144 | msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid; | 3534 | msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid; |
3145 | msg.binaryBucket | 3535 | |
3536 | Vector3 pos = m_host.AbsolutePosition; | ||
3537 | msg.binaryBucket | ||
3146 | = Util.StringToBytes256( | 3538 | = Util.StringToBytes256( |
3147 | "{0}/{1}/{2}/{3}", | 3539 | "{0}/{1}/{2}/{3}", |
3148 | World.RegionInfo.RegionName, | 3540 | World.RegionInfo.RegionName, |
3149 | (int)Math.Floor(m_host.AbsolutePosition.X), | 3541 | (int)Math.Floor(pos.X), |
3150 | (int)Math.Floor(m_host.AbsolutePosition.Y), | 3542 | (int)Math.Floor(pos.Y), |
3151 | (int)Math.Floor(m_host.AbsolutePosition.Z)); | 3543 | (int)Math.Floor(pos.Z)); |
3152 | 3544 | ||
3153 | if (m_TransferModule != null) | 3545 | if (m_TransferModule != null) |
3154 | { | 3546 | { |
3155 | m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); | 3547 | m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); |
3156 | } | 3548 | } |
3157 | 3549 | ||
3158 | ScriptSleep(2000); | 3550 | ScriptSleep(m_sleepMsOnInstantMessage); |
3159 | } | 3551 | } |
3160 | 3552 | ||
3161 | public void llEmail(string address, string subject, string message) | 3553 | public void llEmail(string address, string subject, string message) |
@@ -3164,12 +3556,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3164 | IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>(); | 3556 | IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>(); |
3165 | if (emailModule == null) | 3557 | if (emailModule == null) |
3166 | { | 3558 | { |
3167 | ShoutError("llEmail: email module not configured"); | 3559 | Error("llEmail", "Email module not configured"); |
3168 | return; | 3560 | return; |
3169 | } | 3561 | } |
3170 | 3562 | ||
3563 | //Restrict email destination to the avatars registered email address? | ||
3564 | //The restriction only applies if the destination address is not local. | ||
3565 | if (m_restrictEmail == true && address.Contains(m_internalObjectHost) == false) | ||
3566 | { | ||
3567 | UserAccount account = | ||
3568 | World.UserAccountService.GetUserAccount( | ||
3569 | World.RegionInfo.ScopeID, | ||
3570 | m_host.OwnerID); | ||
3571 | |||
3572 | if (account == null) | ||
3573 | { | ||
3574 | Error("llEmail", "Can't find user account for '" + m_host.OwnerID.ToString() + "'"); | ||
3575 | return; | ||
3576 | } | ||
3577 | |||
3578 | if (String.IsNullOrEmpty(account.Email)) | ||
3579 | { | ||
3580 | Error("llEmail", "User account has not registered an email address."); | ||
3581 | return; | ||
3582 | } | ||
3583 | |||
3584 | address = account.Email; | ||
3585 | } | ||
3586 | |||
3171 | emailModule.SendEmail(m_host.UUID, address, subject, message); | 3587 | emailModule.SendEmail(m_host.UUID, address, subject, message); |
3172 | llSleep(EMAIL_PAUSE_TIME); | 3588 | ScriptSleep(m_sleepMsOnEmail); |
3173 | } | 3589 | } |
3174 | 3590 | ||
3175 | public void llGetNextEmail(string address, string subject) | 3591 | public void llGetNextEmail(string address, string subject) |
@@ -3178,7 +3594,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3178 | IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>(); | 3594 | IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>(); |
3179 | if (emailModule == null) | 3595 | if (emailModule == null) |
3180 | { | 3596 | { |
3181 | ShoutError("llGetNextEmail: email module not configured"); | 3597 | Error("llGetNextEmail", "Email module not configured"); |
3182 | return; | 3598 | return; |
3183 | } | 3599 | } |
3184 | Email email; | 3600 | Email email; |
@@ -3263,23 +3679,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3263 | catch (NotImplementedException) | 3679 | catch (NotImplementedException) |
3264 | { | 3680 | { |
3265 | // Currently not implemented in DotNetEngine only XEngine | 3681 | // Currently not implemented in DotNetEngine only XEngine |
3266 | NotImplemented("llMinEventDelay in DotNetEngine"); | 3682 | NotImplemented("llMinEventDelay", "In DotNetEngine"); |
3267 | } | 3683 | } |
3268 | } | 3684 | } |
3269 | 3685 | ||
3270 | /// <summary> | ||
3271 | /// llSoundPreload is deprecated. In SL this appears to do absolutely nothing | ||
3272 | /// and is documented to have no delay. | ||
3273 | /// </summary> | ||
3274 | public void llSoundPreload(string sound) | 3686 | public void llSoundPreload(string sound) |
3275 | { | 3687 | { |
3276 | m_host.AddScriptLPS(1); | 3688 | m_host.AddScriptLPS(1); |
3689 | Deprecated("llSoundPreload", "Use llPreloadSound instead"); | ||
3277 | } | 3690 | } |
3278 | 3691 | ||
3279 | public void llRotLookAt(LSL_Rotation target, double strength, double damping) | 3692 | public void llRotLookAt(LSL_Rotation target, double strength, double damping) |
3280 | { | 3693 | { |
3281 | m_host.AddScriptLPS(1); | 3694 | m_host.AddScriptLPS(1); |
3282 | 3695 | ||
3283 | // Per discussion with Melanie, for non-physical objects llLookAt appears to simply | 3696 | // Per discussion with Melanie, for non-physical objects llLookAt appears to simply |
3284 | // set the rotation of the object, copy that behavior | 3697 | // set the rotation of the object, copy that behavior |
3285 | PhysicsActor pa = m_host.PhysActor; | 3698 | PhysicsActor pa = m_host.PhysActor; |
@@ -3321,7 +3734,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3321 | if (presence != null) | 3734 | if (presence != null) |
3322 | { | 3735 | { |
3323 | // Do NOT try to parse UUID, animations cannot be triggered by ID | 3736 | // Do NOT try to parse UUID, animations cannot be triggered by ID |
3324 | UUID animID = InventoryKey(anim, (int)AssetType.Animation); | 3737 | UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation); |
3325 | if (animID == UUID.Zero) | 3738 | if (animID == UUID.Zero) |
3326 | presence.Animator.AddAnimation(anim, m_host.UUID); | 3739 | presence.Animator.AddAnimation(anim, m_host.UUID); |
3327 | else | 3740 | else |
@@ -3343,7 +3756,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3343 | 3756 | ||
3344 | if (presence != null) | 3757 | if (presence != null) |
3345 | { | 3758 | { |
3346 | UUID animID = KeyOrName(anim); | 3759 | UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim); |
3347 | 3760 | ||
3348 | if (animID == UUID.Zero) | 3761 | if (animID == UUID.Zero) |
3349 | presence.Animator.RemoveAnimation(anim); | 3762 | presence.Animator.RemoveAnimation(anim); |
@@ -3371,6 +3784,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3371 | 3784 | ||
3372 | protected void TargetOmega(SceneObjectPart part, LSL_Vector axis, double spinrate, double gain) | 3785 | protected void TargetOmega(SceneObjectPart part, LSL_Vector axis, double spinrate, double gain) |
3373 | { | 3786 | { |
3787 | PhysicsActor pa = part.PhysActor; | ||
3788 | if ( ( pa == null || !pa.IsPhysical ) && gain == 0.0d ) | ||
3789 | spinrate = 0.0d; | ||
3374 | part.UpdateAngularVelocity(axis * spinrate); | 3790 | part.UpdateAngularVelocity(axis * spinrate); |
3375 | } | 3791 | } |
3376 | 3792 | ||
@@ -3415,11 +3831,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3415 | implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS | | 3831 | implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS | |
3416 | ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | | 3832 | ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | |
3417 | ScriptBaseClass.PERMISSION_CONTROL_CAMERA | | 3833 | ScriptBaseClass.PERMISSION_CONTROL_CAMERA | |
3834 | ScriptBaseClass.PERMISSION_TRACK_CAMERA | | ||
3418 | ScriptBaseClass.PERMISSION_ATTACH; | 3835 | ScriptBaseClass.PERMISSION_ATTACH; |
3419 | } | 3836 | } |
3420 | else | 3837 | else |
3421 | { | 3838 | { |
3422 | if (m_host.ParentGroup.GetSittingAvatars().Contains(agentID)) | 3839 | if (m_host.ParentGroup.GetSittingAvatars().SingleOrDefault(sp => sp.UUID == agentID) != null) |
3423 | { | 3840 | { |
3424 | // When agent is sitting, certain permissions are implicit if requested from sitting agent | 3841 | // When agent is sitting, certain permissions are implicit if requested from sitting agent |
3425 | implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | | 3842 | implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | |
@@ -3451,10 +3868,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3451 | } | 3868 | } |
3452 | 3869 | ||
3453 | ScenePresence presence = World.GetScenePresence(agentID); | 3870 | ScenePresence presence = World.GetScenePresence(agentID); |
3871 | |||
3454 | if (presence != null) | 3872 | if (presence != null) |
3455 | { | 3873 | { |
3456 | // If permissions are being requested from an NPC and were not implicitly granted above then | 3874 | // If permissions are being requested from an NPC and were not implicitly granted above then |
3457 | // auto grant all reuqested permissions if the script is owned by the NPC or the NPCs owner | 3875 | // auto grant all requested permissions if the script is owned by the NPC or the NPCs owner |
3458 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); | 3876 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); |
3459 | if (npcModule != null && npcModule.IsNPC(agentID, World)) | 3877 | if (npcModule != null && npcModule.IsNPC(agentID, World)) |
3460 | { | 3878 | { |
@@ -3570,22 +3988,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3570 | public void llCreateLink(string target, int parent) | 3988 | public void llCreateLink(string target, int parent) |
3571 | { | 3989 | { |
3572 | m_host.AddScriptLPS(1); | 3990 | m_host.AddScriptLPS(1); |
3573 | UUID targetID; | ||
3574 | |||
3575 | if (!UUID.TryParse(target, out targetID)) | ||
3576 | return; | ||
3577 | 3991 | ||
3578 | if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 | 3992 | if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 |
3579 | && !m_automaticLinkPermission) | 3993 | && !m_automaticLinkPermission) |
3580 | { | 3994 | { |
3581 | ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); | 3995 | Error("llCreateLink", "PERMISSION_CHANGE_LINKS permission not set"); |
3582 | return; | 3996 | return; |
3583 | } | 3997 | } |
3584 | 3998 | ||
3585 | IClientAPI client = null; | 3999 | CreateLink(target, parent); |
3586 | ScenePresence sp = World.GetScenePresence(m_item.PermsGranter); | 4000 | } |
3587 | if (sp != null) | 4001 | |
3588 | client = sp.ControllingClient; | 4002 | public void CreateLink(string target, int parent) |
4003 | { | ||
4004 | UUID targetID; | ||
4005 | |||
4006 | if (!UUID.TryParse(target, out targetID)) | ||
4007 | return; | ||
3589 | 4008 | ||
3590 | SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)targetID); | 4009 | SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)targetID); |
3591 | 4010 | ||
@@ -3620,10 +4039,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3620 | parentPrim.HasGroupChanged = true; | 4039 | parentPrim.HasGroupChanged = true; |
3621 | parentPrim.ScheduleGroupForFullUpdate(); | 4040 | parentPrim.ScheduleGroupForFullUpdate(); |
3622 | 4041 | ||
4042 | IClientAPI client = null; | ||
4043 | ScenePresence sp = World.GetScenePresence(m_host.OwnerID); | ||
4044 | if (sp != null) | ||
4045 | client = sp.ControllingClient; | ||
4046 | |||
3623 | if (client != null) | 4047 | if (client != null) |
3624 | parentPrim.SendPropertiesToClient(client); | 4048 | parentPrim.SendPropertiesToClient(client); |
3625 | 4049 | ||
3626 | ScriptSleep(1000); | 4050 | ScriptSleep(m_sleepMsOnCreateLink); |
3627 | } | 4051 | } |
3628 | 4052 | ||
3629 | public void llBreakLink(int linknum) | 4053 | public void llBreakLink(int linknum) |
@@ -3633,10 +4057,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3633 | if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 | 4057 | if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 |
3634 | && !m_automaticLinkPermission) | 4058 | && !m_automaticLinkPermission) |
3635 | { | 4059 | { |
3636 | ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); | 4060 | Error("llBreakLink", "PERMISSION_CHANGE_LINKS permission not set"); |
3637 | return; | 4061 | return; |
3638 | } | 4062 | } |
3639 | 4063 | ||
4064 | BreakLink(linknum); | ||
4065 | } | ||
4066 | |||
4067 | public void BreakLink(int linknum) | ||
4068 | { | ||
3640 | if (linknum < ScriptBaseClass.LINK_THIS) | 4069 | if (linknum < ScriptBaseClass.LINK_THIS) |
3641 | return; | 4070 | return; |
3642 | 4071 | ||
@@ -3712,6 +4141,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3712 | public void llBreakAllLinks() | 4141 | public void llBreakAllLinks() |
3713 | { | 4142 | { |
3714 | m_host.AddScriptLPS(1); | 4143 | m_host.AddScriptLPS(1); |
4144 | |||
4145 | if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 | ||
4146 | && !m_automaticLinkPermission) | ||
4147 | { | ||
4148 | Error("llBreakAllLinks", "PERMISSION_CHANGE_LINKS permission not set"); | ||
4149 | return; | ||
4150 | } | ||
4151 | |||
4152 | BreakAllLinks(); | ||
4153 | } | ||
4154 | |||
4155 | public void BreakAllLinks() | ||
4156 | { | ||
3715 | SceneObjectGroup parentPrim = m_host.ParentGroup; | 4157 | SceneObjectGroup parentPrim = m_host.ParentGroup; |
3716 | if (parentPrim.AttachmentPoint != 0) | 4158 | if (parentPrim.AttachmentPoint != 0) |
3717 | return; // Fail silently if attached | 4159 | return; // Fail silently if attached |
@@ -3732,47 +4174,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3732 | { | 4174 | { |
3733 | m_host.AddScriptLPS(1); | 4175 | m_host.AddScriptLPS(1); |
3734 | 4176 | ||
3735 | if (linknum < 0) | 4177 | ISceneEntity entity = GetLinkEntity(m_host, linknum); |
3736 | { | ||
3737 | if (linknum == ScriptBaseClass.LINK_THIS) | ||
3738 | return m_host.UUID.ToString(); | ||
3739 | else | ||
3740 | return ScriptBaseClass.NULL_KEY; | ||
3741 | } | ||
3742 | |||
3743 | int actualPrimCount = m_host.ParentGroup.PrimCount; | ||
3744 | List<UUID> sittingAvatarIds = m_host.ParentGroup.GetSittingAvatars(); | ||
3745 | int adjustedPrimCount = actualPrimCount + sittingAvatarIds.Count; | ||
3746 | |||
3747 | // Special case for a single prim. In this case the linknum is zero. However, this will not match a single | ||
3748 | // prim that has any avatars sat upon it (in which case the root prim is link 1). | ||
3749 | if (linknum == 0) | ||
3750 | { | ||
3751 | if (actualPrimCount == 1 && sittingAvatarIds.Count == 0) | ||
3752 | return m_host.UUID.ToString(); | ||
3753 | 4178 | ||
3754 | return ScriptBaseClass.NULL_KEY; | 4179 | if (entity != null) |
3755 | } | 4180 | return entity.UUID.ToString(); |
3756 | // Special case to handle a single prim with sitting avatars. GetLinkPart() would only match zero but | ||
3757 | // here we must match 1 (ScriptBaseClass.LINK_ROOT). | ||
3758 | else if (linknum == 1 && actualPrimCount == 1) | ||
3759 | { | ||
3760 | if (sittingAvatarIds.Count > 0) | ||
3761 | return m_host.ParentGroup.RootPart.UUID.ToString(); | ||
3762 | else | ||
3763 | return ScriptBaseClass.NULL_KEY; | ||
3764 | } | ||
3765 | else if (linknum <= adjustedPrimCount) | ||
3766 | { | ||
3767 | if (linknum <= actualPrimCount) | ||
3768 | return m_host.ParentGroup.GetLinkNumPart(linknum).UUID.ToString(); | ||
3769 | else | ||
3770 | return sittingAvatarIds[linknum - actualPrimCount - 1].ToString(); | ||
3771 | } | ||
3772 | else | 4181 | else |
3773 | { | ||
3774 | return ScriptBaseClass.NULL_KEY; | 4182 | return ScriptBaseClass.NULL_KEY; |
3775 | } | ||
3776 | } | 4183 | } |
3777 | 4184 | ||
3778 | /// <summary> | 4185 | /// <summary> |
@@ -3818,55 +4225,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3818 | { | 4225 | { |
3819 | m_host.AddScriptLPS(1); | 4226 | m_host.AddScriptLPS(1); |
3820 | 4227 | ||
3821 | if (linknum < 0) | 4228 | ISceneEntity entity = GetLinkEntity(m_host, linknum); |
3822 | { | ||
3823 | if (linknum == ScriptBaseClass.LINK_THIS) | ||
3824 | return m_host.Name; | ||
3825 | else | ||
3826 | return ScriptBaseClass.NULL_KEY; | ||
3827 | } | ||
3828 | 4229 | ||
3829 | int actualPrimCount = m_host.ParentGroup.PrimCount; | 4230 | if (entity != null) |
3830 | List<UUID> sittingAvatarIds = m_host.ParentGroup.GetSittingAvatars(); | 4231 | return entity.Name; |
3831 | int adjustedPrimCount = actualPrimCount + sittingAvatarIds.Count; | ||
3832 | |||
3833 | // Special case for a single prim. In this case the linknum is zero. However, this will not match a single | ||
3834 | // prim that has any avatars sat upon it (in which case the root prim is link 1). | ||
3835 | if (linknum == 0) | ||
3836 | { | ||
3837 | if (actualPrimCount == 1 && sittingAvatarIds.Count == 0) | ||
3838 | return m_host.Name; | ||
3839 | |||
3840 | return ScriptBaseClass.NULL_KEY; | ||
3841 | } | ||
3842 | // Special case to handle a single prim with sitting avatars. GetLinkPart() would only match zero but | ||
3843 | // here we must match 1 (ScriptBaseClass.LINK_ROOT). | ||
3844 | else if (linknum == 1 && actualPrimCount == 1) | ||
3845 | { | ||
3846 | if (sittingAvatarIds.Count > 0) | ||
3847 | return m_host.ParentGroup.RootPart.Name; | ||
3848 | else | ||
3849 | return ScriptBaseClass.NULL_KEY; | ||
3850 | } | ||
3851 | else if (linknum <= adjustedPrimCount) | ||
3852 | { | ||
3853 | if (linknum <= actualPrimCount) | ||
3854 | { | ||
3855 | return m_host.ParentGroup.GetLinkNumPart(linknum).Name; | ||
3856 | } | ||
3857 | else | ||
3858 | { | ||
3859 | ScenePresence sp = World.GetScenePresence(sittingAvatarIds[linknum - actualPrimCount - 1]); | ||
3860 | if (sp != null) | ||
3861 | return sp.Name; | ||
3862 | else | ||
3863 | return ScriptBaseClass.NULL_KEY; | ||
3864 | } | ||
3865 | } | ||
3866 | else | 4232 | else |
3867 | { | ||
3868 | return ScriptBaseClass.NULL_KEY; | 4233 | return ScriptBaseClass.NULL_KEY; |
3869 | } | ||
3870 | } | 4234 | } |
3871 | 4235 | ||
3872 | public LSL_Integer llGetInventoryNumber(int type) | 4236 | public LSL_Integer llGetInventoryNumber(int type) |
@@ -3931,7 +4295,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3931 | 4295 | ||
3932 | if (!UUID.TryParse(destination, out destId)) | 4296 | if (!UUID.TryParse(destination, out destId)) |
3933 | { | 4297 | { |
3934 | llSay(0, "Could not parse key " + destination); | 4298 | Error("llGiveInventory", "Can't parse destination key '" + destination + "'"); |
3935 | return; | 4299 | return; |
3936 | } | 4300 | } |
3937 | 4301 | ||
@@ -3939,8 +4303,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3939 | 4303 | ||
3940 | if (item == null) | 4304 | if (item == null) |
3941 | { | 4305 | { |
3942 | llSay(0, String.Format("Could not find object '{0}'", inventory)); | 4306 | Error("llGiveInventory", "Can't find inventory object '" + inventory + "'"); |
3943 | throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory)); | 4307 | return; |
3944 | } | 4308 | } |
3945 | 4309 | ||
3946 | UUID objId = item.ItemID; | 4310 | UUID objId = item.ItemID; |
@@ -3964,15 +4328,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3964 | 4328 | ||
3965 | if (account == null) | 4329 | if (account == null) |
3966 | { | 4330 | { |
3967 | llSay(0, "Can't find destination "+destId.ToString()); | 4331 | GridUserInfo info = World.GridUserService.GetGridUserInfo(destId.ToString()); |
3968 | return; | 4332 | if(info == null || info.Online == false) |
4333 | { | ||
4334 | Error("llGiveInventory", "Can't find destination '" + destId.ToString() + "'"); | ||
4335 | return; | ||
4336 | } | ||
3969 | } | 4337 | } |
3970 | } | 4338 | } |
3971 | // destination is an avatar | 4339 | // destination is an avatar |
3972 | InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId); | 4340 | string message; |
4341 | InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId, out message); | ||
3973 | 4342 | ||
3974 | if (agentItem == null) | 4343 | if (agentItem == null) |
4344 | { | ||
4345 | llSay(0, message); | ||
3975 | return; | 4346 | return; |
4347 | } | ||
3976 | 4348 | ||
3977 | if (m_TransferModule != null) | 4349 | if (m_TransferModule != null) |
3978 | { | 4350 | { |
@@ -3991,7 +4363,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3991 | m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); | 4363 | m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); |
3992 | } | 4364 | } |
3993 | 4365 | ||
3994 | ScriptSleep(3000); | 4366 | ScriptSleep(m_sleepMsOnGiveInventory); |
3995 | } | 4367 | } |
3996 | } | 4368 | } |
3997 | 4369 | ||
@@ -4054,87 +4426,98 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4054 | UserAccount account; | 4426 | UserAccount account; |
4055 | 4427 | ||
4056 | UserInfoCacheEntry ce; | 4428 | UserInfoCacheEntry ce; |
4057 | if (!m_userInfoCache.TryGetValue(uuid, out ce)) | 4429 | |
4430 | lock (m_userInfoCache) | ||
4058 | { | 4431 | { |
4059 | account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); | 4432 | if (!m_userInfoCache.TryGetValue(uuid, out ce)) |
4060 | if (account == null) | ||
4061 | { | 4433 | { |
4062 | m_userInfoCache[uuid] = null; // Cache negative | 4434 | account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); |
4063 | return UUID.Zero.ToString(); | 4435 | if (account == null) |
4064 | } | 4436 | { |
4065 | 4437 | m_userInfoCache[uuid] = null; // Cache negative | |
4438 | return UUID.Zero.ToString(); | ||
4439 | } | ||
4066 | 4440 | ||
4067 | PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); | 4441 | PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); |
4068 | if (pinfos != null && pinfos.Length > 0) | 4442 | if (pinfos != null && pinfos.Length > 0) |
4069 | { | ||
4070 | foreach (PresenceInfo p in pinfos) | ||
4071 | { | 4443 | { |
4072 | if (p.RegionID != UUID.Zero) | 4444 | foreach (PresenceInfo p in pinfos) |
4073 | { | 4445 | { |
4074 | pinfo = p; | 4446 | if (p.RegionID != UUID.Zero) |
4447 | { | ||
4448 | pinfo = p; | ||
4449 | } | ||
4075 | } | 4450 | } |
4076 | } | 4451 | } |
4077 | } | ||
4078 | 4452 | ||
4079 | ce = new UserInfoCacheEntry(); | 4453 | ce = new UserInfoCacheEntry(); |
4080 | ce.time = Util.EnvironmentTickCount(); | 4454 | ce.time = Util.EnvironmentTickCount(); |
4081 | ce.account = account; | 4455 | ce.account = account; |
4082 | ce.pinfo = pinfo; | 4456 | ce.pinfo = pinfo; |
4083 | } | ||
4084 | else | ||
4085 | { | ||
4086 | if (ce == null) | ||
4087 | return UUID.Zero.ToString(); | ||
4088 | |||
4089 | account = ce.account; | ||
4090 | pinfo = ce.pinfo; | ||
4091 | } | ||
4092 | 4457 | ||
4093 | if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000) | 4458 | m_userInfoCache[uuid] = ce; |
4094 | { | 4459 | } |
4095 | PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); | 4460 | else |
4096 | if (pinfos != null && pinfos.Length > 0) | ||
4097 | { | 4461 | { |
4098 | foreach (PresenceInfo p in pinfos) | 4462 | if (ce == null) |
4463 | return UUID.Zero.ToString(); | ||
4464 | |||
4465 | account = ce.account; | ||
4466 | |||
4467 | if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) | ||
4468 | >= LlRequestAgentDataCacheTimeoutMs) | ||
4099 | { | 4469 | { |
4100 | if (p.RegionID != UUID.Zero) | 4470 | PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); |
4471 | if (pinfos != null && pinfos.Length > 0) | ||
4101 | { | 4472 | { |
4102 | pinfo = p; | 4473 | foreach (PresenceInfo p in pinfos) |
4474 | { | ||
4475 | if (p.RegionID != UUID.Zero) | ||
4476 | { | ||
4477 | pinfo = p; | ||
4478 | } | ||
4479 | } | ||
4103 | } | 4480 | } |
4481 | else | ||
4482 | { | ||
4483 | pinfo = null; | ||
4484 | } | ||
4485 | |||
4486 | ce.time = Util.EnvironmentTickCount(); | ||
4487 | ce.pinfo = pinfo; | ||
4488 | } | ||
4489 | else | ||
4490 | { | ||
4491 | pinfo = ce.pinfo; | ||
4104 | } | 4492 | } |
4105 | } | 4493 | } |
4106 | else | ||
4107 | pinfo = null; | ||
4108 | |||
4109 | ce.time = Util.EnvironmentTickCount(); | ||
4110 | ce.pinfo = pinfo; | ||
4111 | } | 4494 | } |
4112 | 4495 | ||
4113 | string reply = String.Empty; | 4496 | string reply = String.Empty; |
4114 | 4497 | ||
4115 | switch (data) | 4498 | switch (data) |
4116 | { | 4499 | { |
4117 | case 1: // DATA_ONLINE (0|1) | 4500 | case ScriptBaseClass.DATA_ONLINE: |
4118 | if (pinfo != null && pinfo.RegionID != UUID.Zero) | 4501 | if (pinfo != null && pinfo.RegionID != UUID.Zero) |
4119 | reply = "1"; | 4502 | reply = "1"; |
4120 | else | 4503 | else |
4121 | reply = "0"; | 4504 | reply = "0"; |
4122 | break; | 4505 | break; |
4123 | case 2: // DATA_NAME (First Last) | 4506 | case ScriptBaseClass.DATA_NAME: // (First Last) |
4124 | reply = account.FirstName + " " + account.LastName; | 4507 | reply = account.FirstName + " " + account.LastName; |
4125 | break; | 4508 | break; |
4126 | case 3: // DATA_BORN (YYYY-MM-DD) | 4509 | case ScriptBaseClass.DATA_BORN: // (YYYY-MM-DD) |
4127 | DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0); | 4510 | DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0); |
4128 | born = born.AddSeconds(account.Created); | 4511 | born = born.AddSeconds(account.Created); |
4129 | reply = born.ToString("yyyy-MM-dd"); | 4512 | reply = born.ToString("yyyy-MM-dd"); |
4130 | break; | 4513 | break; |
4131 | case 4: // DATA_RATING (0,0,0,0,0,0) | 4514 | case ScriptBaseClass.DATA_RATING: // (0,0,0,0,0,0) |
4132 | reply = "0,0,0,0,0,0"; | 4515 | reply = "0,0,0,0,0,0"; |
4133 | break; | 4516 | break; |
4134 | case 7: // DATA_USERLEVEL (integer) | 4517 | case 7: // DATA_USERLEVEL (integer). This is not available in LL and so has no constant. |
4135 | reply = account.UserLevel.ToString(); | 4518 | reply = account.UserLevel.ToString(); |
4136 | break; | 4519 | break; |
4137 | case 8: // DATA_PAYINFO (0|1|2|3) | 4520 | case ScriptBaseClass.DATA_PAYINFO: // (0|1|2|3) |
4138 | reply = "0"; | 4521 | reply = "0"; |
4139 | break; | 4522 | break; |
4140 | default: | 4523 | default: |
@@ -4150,7 +4533,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4150 | AsyncCommands. | 4533 | AsyncCommands. |
4151 | DataserverPlugin.DataserverReply(rq.ToString(), reply); | 4534 | DataserverPlugin.DataserverReply(rq.ToString(), reply); |
4152 | 4535 | ||
4153 | ScriptSleep(100); | 4536 | ScriptSleep(m_sleepMsOnRequestAgentData); |
4154 | return tid.ToString(); | 4537 | return tid.ToString(); |
4155 | } | 4538 | } |
4156 | 4539 | ||
@@ -4166,10 +4549,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4166 | DataserverPlugin.RegisterRequest(m_host.LocalId, | 4549 | DataserverPlugin.RegisterRequest(m_host.LocalId, |
4167 | m_item.ItemID, item.AssetID.ToString()); | 4550 | m_item.ItemID, item.AssetID.ToString()); |
4168 | 4551 | ||
4169 | Vector3 region = new Vector3( | 4552 | Vector3 region = new Vector3(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0); |
4170 | World.RegionInfo.RegionLocX * Constants.RegionSize, | ||
4171 | World.RegionInfo.RegionLocY * Constants.RegionSize, | ||
4172 | 0); | ||
4173 | 4553 | ||
4174 | World.AssetService.Get(item.AssetID.ToString(), this, | 4554 | World.AssetService.Get(item.AssetID.ToString(), this, |
4175 | delegate(string i, object sender, AssetBase a) | 4555 | delegate(string i, object sender, AssetBase a) |
@@ -4186,12 +4566,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4186 | reply); | 4566 | reply); |
4187 | }); | 4567 | }); |
4188 | 4568 | ||
4189 | ScriptSleep(1000); | 4569 | ScriptSleep(m_sleepMsOnRequestInventoryData); |
4190 | return tid.ToString(); | 4570 | return tid.ToString(); |
4191 | } | 4571 | } |
4192 | } | 4572 | } |
4193 | 4573 | ||
4194 | ScriptSleep(1000); | 4574 | ScriptSleep(m_sleepMsOnRequestInventoryData); |
4195 | return String.Empty; | 4575 | return String.Empty; |
4196 | } | 4576 | } |
4197 | 4577 | ||
@@ -4211,14 +4591,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4211 | if (presence != null) | 4591 | if (presence != null) |
4212 | { | 4592 | { |
4213 | // agent must be over the owners land | 4593 | // agent must be over the owners land |
4214 | if (m_host.OwnerID == World.LandChannel.GetLandObject( | 4594 | if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID) |
4215 | presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID) | ||
4216 | { | 4595 | { |
4217 | World.TeleportClientHome(agentId, presence.ControllingClient); | 4596 | World.TeleportClientHome(agentId, presence.ControllingClient); |
4218 | } | 4597 | } |
4219 | } | 4598 | } |
4220 | } | 4599 | } |
4221 | ScriptSleep(5000); | 4600 | |
4601 | ScriptSleep(m_sleepMsOnSetDamage); | ||
4222 | } | 4602 | } |
4223 | 4603 | ||
4224 | public void llTeleportAgent(string agent, string destination, LSL_Vector targetPos, LSL_Vector targetLookAt) | 4604 | public void llTeleportAgent(string agent, string destination, LSL_Vector targetPos, LSL_Vector targetLookAt) |
@@ -4238,8 +4618,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4238 | destination = World.RegionInfo.RegionName; | 4618 | destination = World.RegionInfo.RegionName; |
4239 | 4619 | ||
4240 | // agent must be over the owners land | 4620 | // agent must be over the owners land |
4241 | if (m_host.OwnerID == World.LandChannel.GetLandObject( | 4621 | if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID) |
4242 | presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID) | ||
4243 | { | 4622 | { |
4244 | DoLLTeleport(presence, destination, targetPos, targetLookAt); | 4623 | DoLLTeleport(presence, destination, targetPos, targetLookAt); |
4245 | } | 4624 | } |
@@ -4259,7 +4638,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4259 | m_host.AddScriptLPS(1); | 4638 | m_host.AddScriptLPS(1); |
4260 | UUID agentId = new UUID(); | 4639 | UUID agentId = new UUID(); |
4261 | 4640 | ||
4262 | ulong regionHandle = Utils.UIntsToLong((uint)global_coords.x, (uint)global_coords.y); | 4641 | ulong regionHandle = Util.RegionWorldLocToHandle((uint)global_coords.x, (uint)global_coords.y); |
4263 | 4642 | ||
4264 | if (UUID.TryParse(agent, out agentId)) | 4643 | if (UUID.TryParse(agent, out agentId)) |
4265 | { | 4644 | { |
@@ -4270,8 +4649,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4270 | if (presence.GodLevel >= 200) return; | 4649 | if (presence.GodLevel >= 200) return; |
4271 | 4650 | ||
4272 | // agent must be over the owners land | 4651 | // agent must be over the owners land |
4273 | if (m_host.OwnerID == World.LandChannel.GetLandObject( | 4652 | if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID) |
4274 | presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID) | ||
4275 | { | 4653 | { |
4276 | World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation); | 4654 | World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation); |
4277 | } | 4655 | } |
@@ -4288,7 +4666,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4288 | 4666 | ||
4289 | private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt) | 4667 | private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt) |
4290 | { | 4668 | { |
4291 | UUID assetID = KeyOrName(destination); | 4669 | UUID assetID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, destination); |
4292 | 4670 | ||
4293 | // The destinaion is not an asset ID and also doesn't name a landmark. | 4671 | // The destinaion is not an asset ID and also doesn't name a landmark. |
4294 | // Use it as a sim name | 4672 | // Use it as a sim name |
@@ -4321,22 +4699,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4321 | UUID av = new UUID(); | 4699 | UUID av = new UUID(); |
4322 | if (!UUID.TryParse(agent,out av)) | 4700 | if (!UUID.TryParse(agent,out av)) |
4323 | { | 4701 | { |
4324 | LSLError("First parameter to llDialog needs to be a key"); | 4702 | Error("llTextBox", "First parameter must be a key"); |
4325 | return; | 4703 | return; |
4326 | } | 4704 | } |
4327 | 4705 | ||
4328 | if (message == string.Empty) | 4706 | if (message == string.Empty) |
4329 | { | 4707 | { |
4330 | ShoutError("Trying to use llTextBox with empty message."); | 4708 | Error("llTextBox", "Empty message"); |
4331 | } | 4709 | } |
4332 | else if (message.Length > 512) | 4710 | else if (message.Length > 512) |
4333 | { | 4711 | { |
4334 | ShoutError("Trying to use llTextBox with message over 512 characters."); | 4712 | Error("llTextBox", "Message more than 512 characters"); |
4335 | } | 4713 | } |
4336 | else | 4714 | else |
4337 | { | 4715 | { |
4338 | dm.SendTextBoxToUser(av, message, chatChannel, m_host.Name, m_host.UUID, m_host.OwnerID); | 4716 | dm.SendTextBoxToUser(av, message, chatChannel, m_host.Name, m_host.UUID, m_host.OwnerID); |
4339 | ScriptSleep(1000); | 4717 | ScriptSleep(m_sleepMsOnTextBox); |
4340 | } | 4718 | } |
4341 | } | 4719 | } |
4342 | 4720 | ||
@@ -4353,9 +4731,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4353 | public void llCollisionSound(string impact_sound, double impact_volume) | 4731 | public void llCollisionSound(string impact_sound, double impact_volume) |
4354 | { | 4732 | { |
4355 | m_host.AddScriptLPS(1); | 4733 | m_host.AddScriptLPS(1); |
4356 | 4734 | ||
4357 | // TODO: Parameter check logic required. | 4735 | // TODO: Parameter check logic required. |
4358 | m_host.CollisionSound = KeyOrName(impact_sound, AssetType.Sound); | 4736 | m_host.CollisionSound = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound); |
4359 | m_host.CollisionSoundVolume = (float)impact_volume; | 4737 | m_host.CollisionSoundVolume = (float)impact_volume; |
4360 | } | 4738 | } |
4361 | 4739 | ||
@@ -4475,7 +4853,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4475 | { | 4853 | { |
4476 | if (pushrestricted) | 4854 | if (pushrestricted) |
4477 | { | 4855 | { |
4478 | ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos.X, PusheePos.Y); | 4856 | ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos); |
4479 | 4857 | ||
4480 | // We didn't find the parcel but region is push restricted so assume it is NOT ok | 4858 | // We didn't find the parcel but region is push restricted so assume it is NOT ok |
4481 | if (targetlandObj == null) | 4859 | if (targetlandObj == null) |
@@ -4490,7 +4868,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4490 | } | 4868 | } |
4491 | else | 4869 | else |
4492 | { | 4870 | { |
4493 | ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos.X, PusheePos.Y); | 4871 | ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos); |
4494 | if (targetlandObj == null) | 4872 | if (targetlandObj == null) |
4495 | { | 4873 | { |
4496 | // We didn't find the parcel but region isn't push restricted so assume it's ok | 4874 | // We didn't find the parcel but region isn't push restricted so assume it's ok |
@@ -4520,6 +4898,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4520 | } | 4898 | } |
4521 | } | 4899 | } |
4522 | } | 4900 | } |
4901 | |||
4523 | if (pushAllowed) | 4902 | if (pushAllowed) |
4524 | { | 4903 | { |
4525 | float distance = (PusheePos - m_host.AbsolutePosition).Length(); | 4904 | float distance = (PusheePos - m_host.AbsolutePosition).Length(); |
@@ -4548,17 +4927,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4548 | applied_linear_impulse *= scaling_factor; | 4927 | applied_linear_impulse *= scaling_factor; |
4549 | 4928 | ||
4550 | } | 4929 | } |
4930 | |||
4551 | if (pusheeIsAvatar) | 4931 | if (pusheeIsAvatar) |
4552 | { | 4932 | { |
4553 | if (pusheeav != null) | 4933 | if (pusheeav != null) |
4554 | { | 4934 | { |
4555 | if (pusheeav.PhysicsActor != null) | 4935 | PhysicsActor pa = pusheeav.PhysicsActor; |
4936 | |||
4937 | if (pa != null) | ||
4556 | { | 4938 | { |
4557 | if (local != 0) | 4939 | if (local != 0) |
4558 | { | 4940 | { |
4559 | applied_linear_impulse *= m_host.GetWorldRotation(); | 4941 | applied_linear_impulse *= m_host.GetWorldRotation(); |
4560 | } | 4942 | } |
4561 | pusheeav.PhysicsActor.AddForce(applied_linear_impulse, true); | 4943 | |
4944 | pa.AddForce(applied_linear_impulse, true); | ||
4562 | } | 4945 | } |
4563 | } | 4946 | } |
4564 | } | 4947 | } |
@@ -4666,6 +5049,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4666 | 5049 | ||
4667 | s = Math.Cos(angle * 0.5); | 5050 | s = Math.Cos(angle * 0.5); |
4668 | t = Math.Sin(angle * 0.5); // temp value to avoid 2 more sin() calcs | 5051 | t = Math.Sin(angle * 0.5); // temp value to avoid 2 more sin() calcs |
5052 | axis = LSL_Vector.Norm(axis); | ||
4669 | x = axis.x * t; | 5053 | x = axis.x * t; |
4670 | y = axis.y * t; | 5054 | y = axis.y * t; |
4671 | z = axis.z * t; | 5055 | z = axis.z * t; |
@@ -4673,41 +5057,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4673 | return new LSL_Rotation(x,y,z,s); | 5057 | return new LSL_Rotation(x,y,z,s); |
4674 | } | 5058 | } |
4675 | 5059 | ||
4676 | 5060 | /// <summary> | |
4677 | // Xantor 29/apr/2008 | 5061 | /// Returns the axis of rotation for a quaternion |
4678 | // converts a Quaternion to X,Y,Z axis rotations | 5062 | /// </summary> |
5063 | /// <returns></returns> | ||
5064 | /// <param name='rot'></param> | ||
4679 | public LSL_Vector llRot2Axis(LSL_Rotation rot) | 5065 | public LSL_Vector llRot2Axis(LSL_Rotation rot) |
4680 | { | 5066 | { |
4681 | m_host.AddScriptLPS(1); | 5067 | m_host.AddScriptLPS(1); |
4682 | double x,y,z; | ||
4683 | |||
4684 | if (rot.s > 1) // normalization needed | ||
4685 | { | ||
4686 | double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y + | ||
4687 | rot.z * rot.z + rot.s * rot.s); | ||
4688 | 5068 | ||
4689 | rot.x /= length; | 5069 | if (Math.Abs(rot.s) > 1) // normalization needed |
4690 | rot.y /= length; | 5070 | rot.Normalize(); |
4691 | rot.z /= length; | ||
4692 | rot.s /= length; | ||
4693 | 5071 | ||
4694 | } | ||
4695 | |||
4696 | // double angle = 2 * Math.Acos(rot.s); | ||
4697 | double s = Math.Sqrt(1 - rot.s * rot.s); | 5072 | double s = Math.Sqrt(1 - rot.s * rot.s); |
4698 | if (s < 0.001) | 5073 | if (s < 0.001) |
4699 | { | 5074 | { |
4700 | x = 1; | 5075 | return new LSL_Vector(1, 0, 0); |
4701 | y = z = 0; | ||
4702 | } | 5076 | } |
4703 | else | 5077 | else |
4704 | { | 5078 | { |
4705 | x = rot.x / s; // normalise axis | 5079 | double invS = 1.0 / s; |
4706 | y = rot.y / s; | 5080 | if (rot.s < 0) invS = -invS; |
4707 | z = rot.z / s; | 5081 | return new LSL_Vector(rot.x * invS, rot.y * invS, rot.z * invS); |
4708 | } | 5082 | } |
4709 | |||
4710 | return new LSL_Vector(x,y,z); | ||
4711 | } | 5083 | } |
4712 | 5084 | ||
4713 | 5085 | ||
@@ -4716,18 +5088,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4716 | { | 5088 | { |
4717 | m_host.AddScriptLPS(1); | 5089 | m_host.AddScriptLPS(1); |
4718 | 5090 | ||
4719 | if (rot.s > 1) // normalization needed | 5091 | if (Math.Abs(rot.s) > 1) // normalization needed |
4720 | { | 5092 | rot.Normalize(); |
4721 | double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y + | ||
4722 | rot.z * rot.z + rot.s * rot.s); | ||
4723 | |||
4724 | rot.x /= length; | ||
4725 | rot.y /= length; | ||
4726 | rot.z /= length; | ||
4727 | rot.s /= length; | ||
4728 | } | ||
4729 | 5093 | ||
4730 | double angle = 2 * Math.Acos(rot.s); | 5094 | double angle = 2 * Math.Acos(rot.s); |
5095 | if (angle > Math.PI) | ||
5096 | angle = 2 * Math.PI - angle; | ||
4731 | 5097 | ||
4732 | return angle; | 5098 | return angle; |
4733 | } | 5099 | } |
@@ -4907,8 +5273,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4907 | public LSL_Vector llGetCenterOfMass() | 5273 | public LSL_Vector llGetCenterOfMass() |
4908 | { | 5274 | { |
4909 | m_host.AddScriptLPS(1); | 5275 | m_host.AddScriptLPS(1); |
4910 | Vector3 center = m_host.GetGeometricCenter(); | 5276 | |
4911 | return new LSL_Vector(center.X,center.Y,center.Z); | 5277 | return new LSL_Vector(m_host.GetCenterOfMass()); |
4912 | } | 5278 | } |
4913 | 5279 | ||
4914 | public LSL_List llListSort(LSL_List src, int stride, int ascending) | 5280 | public LSL_List llListSort(LSL_List src, int stride, int ascending) |
@@ -5043,10 +5409,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5043 | // SL spits out an empty string for types other than key & string | 5409 | // SL spits out an empty string for types other than key & string |
5044 | // At the time of patching, LSL_Key is currently LSL_String, | 5410 | // At the time of patching, LSL_Key is currently LSL_String, |
5045 | // so the OR check may be a little redundant, but it's being done | 5411 | // so the OR check may be a little redundant, but it's being done |
5046 | // for completion and should LSL_Key ever be implemented | 5412 | // for completion and should LSL_Key ever be implemented |
5047 | // as it's own struct | 5413 | // as it's own struct |
5414 | // NOTE: 3rd case is needed because a NULL_KEY comes through as | ||
5415 | // type 'obj' and wrongly returns "" | ||
5048 | else if (!(src.Data[index] is LSL_String || | 5416 | else if (!(src.Data[index] is LSL_String || |
5049 | src.Data[index] is LSL_Key)) | 5417 | src.Data[index] is LSL_Key || |
5418 | src.Data[index].ToString() == "00000000-0000-0000-0000-000000000000")) | ||
5050 | { | 5419 | { |
5051 | return ""; | 5420 | return ""; |
5052 | } | 5421 | } |
@@ -5179,8 +5548,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5179 | { | 5548 | { |
5180 | m_host.AddScriptLPS(1); | 5549 | m_host.AddScriptLPS(1); |
5181 | 5550 | ||
5182 | return string.Join(", ", | 5551 | return string.Join(", ", |
5183 | (new List<object>(src.Data)).ConvertAll<string>(o => | 5552 | (new List<object>(src.Data)).ConvertAll<string>(o => |
5184 | { | 5553 | { |
5185 | return o.ToString(); | 5554 | return o.ToString(); |
5186 | }).ToArray()); | 5555 | }).ToArray()); |
@@ -5254,7 +5623,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5254 | public LSL_List llListRandomize(LSL_List src, int stride) | 5623 | public LSL_List llListRandomize(LSL_List src, int stride) |
5255 | { | 5624 | { |
5256 | LSL_List result; | 5625 | LSL_List result; |
5257 | Random rand = new Random(); | 5626 | BetterRandom rand = new BetterRandom(); |
5258 | 5627 | ||
5259 | int chunkk; | 5628 | int chunkk; |
5260 | int[] chunks; | 5629 | int[] chunks; |
@@ -5270,24 +5639,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5270 | // If not, then return the src list. This also | 5639 | // If not, then return the src list. This also |
5271 | // traps those cases where stride > length. | 5640 | // traps those cases where stride > length. |
5272 | 5641 | ||
5273 | if (src.Length != stride && src.Length%stride == 0) | 5642 | if (src.Length != stride && src.Length % stride == 0) |
5274 | { | 5643 | { |
5275 | chunkk = src.Length/stride; | 5644 | chunkk = src.Length/stride; |
5276 | 5645 | ||
5277 | chunks = new int[chunkk]; | 5646 | chunks = new int[chunkk]; |
5278 | 5647 | ||
5279 | for (int i = 0; i < chunkk; i++) | 5648 | for (int i = 0; i < chunkk; i++) |
5649 | { | ||
5280 | chunks[i] = i; | 5650 | chunks[i] = i; |
5651 | } | ||
5281 | 5652 | ||
5282 | // Knuth shuffle the chunkk index | 5653 | // Knuth shuffle the chunkk index |
5283 | for (int i = chunkk - 1; i >= 1; i--) | 5654 | for (int i = chunkk - 1; i > 0; i--) |
5284 | { | 5655 | { |
5285 | // Elect an unrandomized chunk to swap | 5656 | // Elect an unrandomized chunk to swap |
5286 | int index = rand.Next(i + 1); | 5657 | int index = rand.Next(i + 1); |
5287 | int tmp; | ||
5288 | 5658 | ||
5289 | // and swap position with first unrandomized chunk | 5659 | // and swap position with first unrandomized chunk |
5290 | tmp = chunks[i]; | 5660 | int tmp = chunks[i]; |
5291 | chunks[i] = chunks[index]; | 5661 | chunks[i] = chunks[index]; |
5292 | chunks[index] = tmp; | 5662 | chunks[index] = tmp; |
5293 | } | 5663 | } |
@@ -5300,7 +5670,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5300 | { | 5670 | { |
5301 | for (int j = 0; j < stride; j++) | 5671 | for (int j = 0; j < stride; j++) |
5302 | { | 5672 | { |
5303 | result.Add(src.Data[chunks[i]*stride+j]); | 5673 | result.Add(src.Data[chunks[i] * stride + j]); |
5304 | } | 5674 | } |
5305 | } | 5675 | } |
5306 | } | 5676 | } |
@@ -5417,7 +5787,72 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5417 | public LSL_Vector llGetRegionCorner() | 5787 | public LSL_Vector llGetRegionCorner() |
5418 | { | 5788 | { |
5419 | m_host.AddScriptLPS(1); | 5789 | m_host.AddScriptLPS(1); |
5420 | return new LSL_Vector(World.RegionInfo.RegionLocX * Constants.RegionSize, World.RegionInfo.RegionLocY * Constants.RegionSize, 0); | 5790 | return new LSL_Vector(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0); |
5791 | } | ||
5792 | |||
5793 | public LSL_String llGetEnv(LSL_String name) | ||
5794 | { | ||
5795 | m_host.AddScriptLPS(1); | ||
5796 | if (name == "agent_limit") | ||
5797 | { | ||
5798 | return World.RegionInfo.RegionSettings.AgentLimit.ToString(); | ||
5799 | } | ||
5800 | else if (name == "dynamic_pathfinding") | ||
5801 | { | ||
5802 | return "0"; | ||
5803 | } | ||
5804 | else if (name == "estate_id") | ||
5805 | { | ||
5806 | return World.RegionInfo.EstateSettings.EstateID.ToString(); | ||
5807 | } | ||
5808 | else if (name == "estate_name") | ||
5809 | { | ||
5810 | return World.RegionInfo.EstateSettings.EstateName; | ||
5811 | } | ||
5812 | else if (name == "frame_number") | ||
5813 | { | ||
5814 | return World.Frame.ToString(); | ||
5815 | } | ||
5816 | else if (name == "region_cpu_ratio") | ||
5817 | { | ||
5818 | return "1"; | ||
5819 | } | ||
5820 | else if (name == "region_idle") | ||
5821 | { | ||
5822 | return "0"; | ||
5823 | } | ||
5824 | else if (name == "region_product_name") | ||
5825 | { | ||
5826 | if (World.RegionInfo.RegionType != String.Empty) | ||
5827 | return World.RegionInfo.RegionType; | ||
5828 | else | ||
5829 | return ""; | ||
5830 | } | ||
5831 | else if (name == "region_product_sku") | ||
5832 | { | ||
5833 | return "OpenSim"; | ||
5834 | } | ||
5835 | else if (name == "region_start_time") | ||
5836 | { | ||
5837 | return World.UnixStartTime.ToString(); | ||
5838 | } | ||
5839 | else if (name == "sim_channel") | ||
5840 | { | ||
5841 | return "OpenSim"; | ||
5842 | } | ||
5843 | else if (name == "sim_version") | ||
5844 | { | ||
5845 | return World.GetSimulatorVersion(); | ||
5846 | } | ||
5847 | else if (name == "simulator_hostname") | ||
5848 | { | ||
5849 | IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>(); | ||
5850 | return UrlModule.ExternalHostNameForLSL; | ||
5851 | } | ||
5852 | else | ||
5853 | { | ||
5854 | return ""; | ||
5855 | } | ||
5421 | } | 5856 | } |
5422 | 5857 | ||
5423 | /// <summary> | 5858 | /// <summary> |
@@ -5429,8 +5864,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5429 | public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index) | 5864 | public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index) |
5430 | { | 5865 | { |
5431 | 5866 | ||
5432 | LSL_List pref = null; | 5867 | LSL_List pref; |
5433 | LSL_List suff = null; | 5868 | LSL_List suff; |
5434 | 5869 | ||
5435 | m_host.AddScriptLPS(1); | 5870 | m_host.AddScriptLPS(1); |
5436 | 5871 | ||
@@ -5564,7 +5999,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5564 | LSL_Float mag; | 5999 | LSL_Float mag; |
5565 | if (dir.x > 0) | 6000 | if (dir.x > 0) |
5566 | { | 6001 | { |
5567 | mag = (Constants.RegionSize - pos.x) / dir.x; | 6002 | mag = (World.RegionInfo.RegionSizeX - pos.x) / dir.x; |
5568 | } | 6003 | } |
5569 | else | 6004 | else |
5570 | { | 6005 | { |
@@ -5575,7 +6010,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5575 | 6010 | ||
5576 | edge.y = pos.y + (dir.y * mag); | 6011 | edge.y = pos.y + (dir.y * mag); |
5577 | 6012 | ||
5578 | if (edge.y > Constants.RegionSize || edge.y < 0) | 6013 | if (edge.y > World.RegionInfo.RegionSizeY || edge.y < 0) |
5579 | { | 6014 | { |
5580 | // Y goes out of bounds first | 6015 | // Y goes out of bounds first |
5581 | edge.y = dir.y / Math.Abs(dir.y); | 6016 | edge.y = dir.y / Math.Abs(dir.y); |
@@ -5704,12 +6139,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5704 | 6139 | ||
5705 | public LSL_String llGetAgentLanguage(string id) | 6140 | public LSL_String llGetAgentLanguage(string id) |
5706 | { | 6141 | { |
5707 | // This should only return a value if the avatar is in the same region | 6142 | // This should only return a value if the avatar is in the same region, but eh. idc. |
5708 | //ckrinke 1-30-09 : This needs to parse the XMLRPC language field supplied | ||
5709 | //by the client at login. Currently returning only en-us until our I18N | ||
5710 | //effort gains momentum | ||
5711 | m_host.AddScriptLPS(1); | 6143 | m_host.AddScriptLPS(1); |
5712 | return "en-us"; | 6144 | if (World.AgentPreferencesService == null) |
6145 | { | ||
6146 | Error("llGetAgentLanguage", "No AgentPreferencesService present"); | ||
6147 | } | ||
6148 | else | ||
6149 | { | ||
6150 | UUID key = new UUID(); | ||
6151 | if (UUID.TryParse(id, out key)) | ||
6152 | { | ||
6153 | return new LSL_String(World.AgentPreferencesService.GetLang(key)); | ||
6154 | } | ||
6155 | } | ||
6156 | return new LSL_String("en-us"); | ||
5713 | } | 6157 | } |
5714 | /// <summary> | 6158 | /// <summary> |
5715 | /// http://wiki.secondlife.com/wiki/LlGetAgentList | 6159 | /// http://wiki.secondlife.com/wiki/LlGetAgentList |
@@ -5739,12 +6183,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5739 | } | 6183 | } |
5740 | 6184 | ||
5741 | ILandObject land; | 6185 | ILandObject land; |
5742 | Vector3 pos; | ||
5743 | UUID id = UUID.Zero; | 6186 | UUID id = UUID.Zero; |
6187 | |||
5744 | if (parcel || parcelOwned) | 6188 | if (parcel || parcelOwned) |
5745 | { | 6189 | { |
5746 | pos = m_host.ParentGroup.RootPart.GetWorldPosition(); | 6190 | land = World.LandChannel.GetLandObject(m_host.ParentGroup.RootPart.GetWorldPosition()); |
5747 | land = World.LandChannel.GetLandObject(pos.X, pos.Y); | ||
5748 | if (land == null) | 6191 | if (land == null) |
5749 | { | 6192 | { |
5750 | id = UUID.Zero; | 6193 | id = UUID.Zero; |
@@ -5770,8 +6213,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5770 | { | 6213 | { |
5771 | if (!regionWide) | 6214 | if (!regionWide) |
5772 | { | 6215 | { |
5773 | pos = ssp.AbsolutePosition; | 6216 | land = World.LandChannel.GetLandObject(ssp.AbsolutePosition); |
5774 | land = World.LandChannel.GetLandObject(pos.X, pos.Y); | ||
5775 | if (land != null) | 6217 | if (land != null) |
5776 | { | 6218 | { |
5777 | if (parcelOwned && land.LandData.OwnerID == id || | 6219 | if (parcelOwned && land.LandData.OwnerID == id || |
@@ -5800,7 +6242,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5800 | { | 6242 | { |
5801 | m_host.AddScriptLPS(1); | 6243 | m_host.AddScriptLPS(1); |
5802 | m_host.AdjustSoundGain(volume); | 6244 | m_host.AdjustSoundGain(volume); |
5803 | ScriptSleep(100); | 6245 | ScriptSleep(m_sleepMsOnAdjustSoundVolume); |
5804 | } | 6246 | } |
5805 | 6247 | ||
5806 | public void llSetSoundRadius(double radius) | 6248 | public void llSetSoundRadius(double radius) |
@@ -5881,7 +6323,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5881 | if (m_SoundModule != null) | 6323 | if (m_SoundModule != null) |
5882 | { | 6324 | { |
5883 | m_SoundModule.TriggerSoundLimited(m_host.UUID, | 6325 | m_SoundModule.TriggerSoundLimited(m_host.UUID, |
5884 | KeyOrName(sound, AssetType.Sound), volume, | 6326 | ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, |
5885 | bottom_south_west, top_north_east); | 6327 | bottom_south_west, top_north_east); |
5886 | } | 6328 | } |
5887 | } | 6329 | } |
@@ -5896,7 +6338,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5896 | if (presence != null) | 6338 | if (presence != null) |
5897 | { | 6339 | { |
5898 | // agent must be over the owners land | 6340 | // agent must be over the owners land |
5899 | ILandObject land = World.LandChannel.GetLandObject(presence.AbsolutePosition.X, presence.AbsolutePosition.Y); | 6341 | ILandObject land = World.LandChannel.GetLandObject(presence.AbsolutePosition); |
5900 | if (land == null) | 6342 | if (land == null) |
5901 | return; | 6343 | return; |
5902 | 6344 | ||
@@ -5906,7 +6348,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5906 | } | 6348 | } |
5907 | } | 6349 | } |
5908 | } | 6350 | } |
5909 | ScriptSleep(5000); | 6351 | ScriptSleep(m_sleepMsOnEjectFromLand); |
5910 | } | 6352 | } |
5911 | 6353 | ||
5912 | public LSL_Integer llOverMyLand(string id) | 6354 | public LSL_Integer llOverMyLand(string id) |
@@ -5918,19 +6360,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5918 | ScenePresence presence = World.GetScenePresence(key); | 6360 | ScenePresence presence = World.GetScenePresence(key); |
5919 | if (presence != null) // object is an avatar | 6361 | if (presence != null) // object is an avatar |
5920 | { | 6362 | { |
5921 | if (m_host.OwnerID | 6363 | if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID) |
5922 | == World.LandChannel.GetLandObject( | ||
5923 | presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID) | ||
5924 | return 1; | 6364 | return 1; |
5925 | } | 6365 | } |
5926 | else // object is not an avatar | 6366 | else // object is not an avatar |
5927 | { | 6367 | { |
5928 | SceneObjectPart obj = World.GetSceneObjectPart(key); | 6368 | SceneObjectPart obj = World.GetSceneObjectPart(key); |
6369 | |||
5929 | if (obj != null) | 6370 | if (obj != null) |
5930 | if (m_host.OwnerID | 6371 | { |
5931 | == World.LandChannel.GetLandObject( | 6372 | if (m_host.OwnerID == World.LandChannel.GetLandObject(obj.AbsolutePosition).LandData.OwnerID) |
5932 | obj.AbsolutePosition.X, obj.AbsolutePosition.Y).LandData.OwnerID) | ||
5933 | return 1; | 6373 | return 1; |
6374 | } | ||
5934 | } | 6375 | } |
5935 | } | 6376 | } |
5936 | 6377 | ||
@@ -5962,8 +6403,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5962 | } | 6403 | } |
5963 | else | 6404 | else |
5964 | { | 6405 | { |
5965 | agentSize = new LSL_Vector(0.45, 0.6, avatar.Appearance.AvatarHeight); | 6406 | agentSize = GetAgentSize(avatar); |
5966 | } | 6407 | } |
6408 | |||
5967 | return agentSize; | 6409 | return agentSize; |
5968 | } | 6410 | } |
5969 | 6411 | ||
@@ -5991,10 +6433,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5991 | if (UUID.TryParse(id, out key)) | 6433 | if (UUID.TryParse(id, out key)) |
5992 | { | 6434 | { |
5993 | ScenePresence av = World.GetScenePresence(key); | 6435 | ScenePresence av = World.GetScenePresence(key); |
6436 | List<ScenePresence> sittingAvatars = m_host.ParentGroup.GetSittingAvatars(); | ||
5994 | 6437 | ||
5995 | if (av != null) | 6438 | if (av != null) |
5996 | { | 6439 | { |
5997 | if (llAvatarOnSitTarget() == id) | 6440 | if (sittingAvatars.Contains(av)) |
5998 | { | 6441 | { |
5999 | // if the avatar is sitting on this object, then | 6442 | // if the avatar is sitting on this object, then |
6000 | // we can unsit them. We don't want random scripts unsitting random people | 6443 | // we can unsit them. We don't want random scripts unsitting random people |
@@ -6008,8 +6451,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6008 | // if the land is group owned and the object is group owned by the same group | 6451 | // if the land is group owned and the object is group owned by the same group |
6009 | // or | 6452 | // or |
6010 | // if the object is owned by a person with estate access. | 6453 | // if the object is owned by a person with estate access. |
6011 | 6454 | ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition); | |
6012 | ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition.X, av.AbsolutePosition.Y); | ||
6013 | if (parcel != null) | 6455 | if (parcel != null) |
6014 | { | 6456 | { |
6015 | if (m_host.OwnerID == parcel.LandData.OwnerID || | 6457 | if (m_host.OwnerID == parcel.LandData.OwnerID || |
@@ -6021,14 +6463,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6021 | } | 6463 | } |
6022 | } | 6464 | } |
6023 | } | 6465 | } |
6024 | |||
6025 | } | 6466 | } |
6026 | |||
6027 | } | 6467 | } |
6028 | 6468 | ||
6029 | public LSL_Vector llGroundSlope(LSL_Vector offset) | 6469 | public LSL_Vector llGroundSlope(LSL_Vector offset) |
6030 | { | 6470 | { |
6031 | m_host.AddScriptLPS(1); | 6471 | m_host.AddScriptLPS(1); |
6472 | |||
6032 | //Get the slope normal. This gives us the equation of the plane tangent to the slope. | 6473 | //Get the slope normal. This gives us the equation of the plane tangent to the slope. |
6033 | LSL_Vector vsn = llGroundNormal(offset); | 6474 | LSL_Vector vsn = llGroundNormal(offset); |
6034 | 6475 | ||
@@ -6039,7 +6480,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6039 | vsl.Normalize(); | 6480 | vsl.Normalize(); |
6040 | //Normalization might be overkill here | 6481 | //Normalization might be overkill here |
6041 | 6482 | ||
6042 | return new LSL_Vector(vsl.X, vsl.Y, vsl.Z); | 6483 | vsn.x = vsl.X; |
6484 | vsn.y = vsl.Y; | ||
6485 | vsn.z = vsl.Z; | ||
6486 | |||
6487 | return vsn; | ||
6043 | } | 6488 | } |
6044 | 6489 | ||
6045 | public LSL_Vector llGroundNormal(LSL_Vector offset) | 6490 | public LSL_Vector llGroundNormal(LSL_Vector offset) |
@@ -6089,7 +6534,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6089 | //I believe the crossproduct of two normalized vectors is a normalized vector so | 6534 | //I believe the crossproduct of two normalized vectors is a normalized vector so |
6090 | //this normalization may be overkill | 6535 | //this normalization may be overkill |
6091 | 6536 | ||
6092 | return new LSL_Vector(vsn.X, vsn.Y, vsn.Z); | 6537 | return new LSL_Vector(vsn); |
6093 | } | 6538 | } |
6094 | 6539 | ||
6095 | public LSL_Vector llGroundContour(LSL_Vector offset) | 6540 | public LSL_Vector llGroundContour(LSL_Vector offset) |
@@ -6105,11 +6550,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6105 | return m_host.ParentGroup.AttachmentPoint; | 6550 | return m_host.ParentGroup.AttachmentPoint; |
6106 | } | 6551 | } |
6107 | 6552 | ||
6108 | public LSL_Integer llGetFreeMemory() | 6553 | public virtual LSL_Integer llGetFreeMemory() |
6109 | { | 6554 | { |
6110 | m_host.AddScriptLPS(1); | 6555 | m_host.AddScriptLPS(1); |
6111 | // Make scripts designed for LSO happy | 6556 | // Make scripts designed for Mono happy |
6112 | return 16384; | 6557 | return 65536; |
6113 | } | 6558 | } |
6114 | 6559 | ||
6115 | public LSL_Integer llGetFreeURLs() | 6560 | public LSL_Integer llGetFreeURLs() |
@@ -6176,7 +6621,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6176 | PSYS_SRC_TARGET_KEY = 20, | 6621 | PSYS_SRC_TARGET_KEY = 20, |
6177 | PSYS_SRC_OMEGA = 21, | 6622 | PSYS_SRC_OMEGA = 21, |
6178 | PSYS_SRC_ANGLE_BEGIN = 22, | 6623 | PSYS_SRC_ANGLE_BEGIN = 22, |
6179 | PSYS_SRC_ANGLE_END = 23 | 6624 | PSYS_SRC_ANGLE_END = 23, |
6625 | PSYS_PART_BLEND_FUNC_SOURCE = 24, | ||
6626 | PSYS_PART_BLEND_FUNC_DEST = 25, | ||
6627 | PSYS_PART_START_GLOW = 26, | ||
6628 | PSYS_PART_END_GLOW = 27 | ||
6180 | } | 6629 | } |
6181 | 6630 | ||
6182 | internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags) | 6631 | internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags) |
@@ -6202,6 +6651,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6202 | ps.BurstRate = 0.1f; | 6651 | ps.BurstRate = 0.1f; |
6203 | ps.PartMaxAge = 10.0f; | 6652 | ps.PartMaxAge = 10.0f; |
6204 | ps.BurstPartCount = 1; | 6653 | ps.BurstPartCount = 1; |
6654 | ps.BlendFuncSource = ScriptBaseClass.PSYS_PART_BF_SOURCE_ALPHA; | ||
6655 | ps.BlendFuncDest = ScriptBaseClass.PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA; | ||
6656 | ps.PartStartGlow = 0.0f; | ||
6657 | ps.PartEndGlow = 0.0f; | ||
6658 | |||
6205 | return ps; | 6659 | return ps; |
6206 | } | 6660 | } |
6207 | 6661 | ||
@@ -6213,17 +6667,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6213 | 6667 | ||
6214 | foreach (SceneObjectPart part in parts) | 6668 | foreach (SceneObjectPart part in parts) |
6215 | { | 6669 | { |
6216 | SetParticleSystem(part, rules); | 6670 | SetParticleSystem(part, rules, "llLinkParticleSystem"); |
6217 | } | 6671 | } |
6218 | } | 6672 | } |
6219 | 6673 | ||
6220 | public void llParticleSystem(LSL_List rules) | 6674 | public void llParticleSystem(LSL_List rules) |
6221 | { | 6675 | { |
6222 | m_host.AddScriptLPS(1); | 6676 | m_host.AddScriptLPS(1); |
6223 | SetParticleSystem(m_host, rules); | 6677 | SetParticleSystem(m_host, rules, "llParticleSystem"); |
6224 | } | 6678 | } |
6225 | 6679 | ||
6226 | private void SetParticleSystem(SceneObjectPart part, LSL_List rules) | 6680 | private void SetParticleSystem(SceneObjectPart part, LSL_List rules, string originFunc) |
6227 | { | 6681 | { |
6228 | if (rules.Length == 0) | 6682 | if (rules.Length == 0) |
6229 | { | 6683 | { |
@@ -6236,65 +6690,156 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6236 | LSL_Vector tempv = new LSL_Vector(); | 6690 | LSL_Vector tempv = new LSL_Vector(); |
6237 | 6691 | ||
6238 | float tempf = 0; | 6692 | float tempf = 0; |
6693 | int tmpi = 0; | ||
6239 | 6694 | ||
6240 | for (int i = 0; i < rules.Length; i += 2) | 6695 | for (int i = 0; i < rules.Length; i += 2) |
6241 | { | 6696 | { |
6242 | switch (rules.GetLSLIntegerItem(i)) | 6697 | int psystype; |
6698 | try | ||
6699 | { | ||
6700 | psystype = rules.GetLSLIntegerItem(i); | ||
6701 | } | ||
6702 | catch (InvalidCastException) | ||
6703 | { | ||
6704 | Error(originFunc, string.Format("Error running particle system params index #{0}: particle system parameter type must be integer", i)); | ||
6705 | return; | ||
6706 | } | ||
6707 | switch (psystype) | ||
6243 | { | 6708 | { |
6244 | case (int)ScriptBaseClass.PSYS_PART_FLAGS: | 6709 | case (int)ScriptBaseClass.PSYS_PART_FLAGS: |
6245 | prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1); | 6710 | try |
6711 | { | ||
6712 | prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1); | ||
6713 | } | ||
6714 | catch(InvalidCastException) | ||
6715 | { | ||
6716 | Error(originFunc, string.Format("Error running rule PSYS_PART_FLAGS: arg #{0} - parameter 1 must be integer", i + 1)); | ||
6717 | return; | ||
6718 | } | ||
6246 | break; | 6719 | break; |
6247 | 6720 | ||
6248 | case (int)ScriptBaseClass.PSYS_PART_START_COLOR: | 6721 | case (int)ScriptBaseClass.PSYS_PART_START_COLOR: |
6249 | tempv = rules.GetVector3Item(i + 1); | 6722 | try |
6723 | { | ||
6724 | tempv = rules.GetVector3Item(i + 1); | ||
6725 | } | ||
6726 | catch(InvalidCastException) | ||
6727 | { | ||
6728 | Error(originFunc, string.Format("Error running rule PSYS_PART_START_COLOR: arg #{0} - parameter 1 must be vector", i + 1)); | ||
6729 | return; | ||
6730 | } | ||
6250 | prules.PartStartColor.R = (float)tempv.x; | 6731 | prules.PartStartColor.R = (float)tempv.x; |
6251 | prules.PartStartColor.G = (float)tempv.y; | 6732 | prules.PartStartColor.G = (float)tempv.y; |
6252 | prules.PartStartColor.B = (float)tempv.z; | 6733 | prules.PartStartColor.B = (float)tempv.z; |
6253 | break; | 6734 | break; |
6254 | 6735 | ||
6255 | case (int)ScriptBaseClass.PSYS_PART_START_ALPHA: | 6736 | case (int)ScriptBaseClass.PSYS_PART_START_ALPHA: |
6256 | tempf = (float)rules.GetLSLFloatItem(i + 1); | 6737 | try |
6738 | { | ||
6739 | tempf = (float)rules.GetLSLFloatItem(i + 1); | ||
6740 | } | ||
6741 | catch(InvalidCastException) | ||
6742 | { | ||
6743 | Error(originFunc, string.Format("Error running rule PSYS_PART_START_ALPHA: arg #{0} - parameter 1 must be float", i + 1)); | ||
6744 | return; | ||
6745 | } | ||
6257 | prules.PartStartColor.A = tempf; | 6746 | prules.PartStartColor.A = tempf; |
6258 | break; | 6747 | break; |
6259 | 6748 | ||
6260 | case (int)ScriptBaseClass.PSYS_PART_END_COLOR: | 6749 | case (int)ScriptBaseClass.PSYS_PART_END_COLOR: |
6261 | tempv = rules.GetVector3Item(i + 1); | 6750 | try |
6751 | { | ||
6752 | tempv = rules.GetVector3Item(i + 1); | ||
6753 | } | ||
6754 | catch(InvalidCastException) | ||
6755 | { | ||
6756 | Error(originFunc, string.Format("Error running rule PSYS_PART_END_COLOR: arg #{0} - parameter 1 must be vector", i + 1)); | ||
6757 | return; | ||
6758 | } | ||
6262 | prules.PartEndColor.R = (float)tempv.x; | 6759 | prules.PartEndColor.R = (float)tempv.x; |
6263 | prules.PartEndColor.G = (float)tempv.y; | 6760 | prules.PartEndColor.G = (float)tempv.y; |
6264 | prules.PartEndColor.B = (float)tempv.z; | 6761 | prules.PartEndColor.B = (float)tempv.z; |
6265 | break; | 6762 | break; |
6266 | 6763 | ||
6267 | case (int)ScriptBaseClass.PSYS_PART_END_ALPHA: | 6764 | case (int)ScriptBaseClass.PSYS_PART_END_ALPHA: |
6268 | tempf = (float)rules.GetLSLFloatItem(i + 1); | 6765 | try |
6766 | { | ||
6767 | tempf = (float)rules.GetLSLFloatItem(i + 1); | ||
6768 | } | ||
6769 | catch(InvalidCastException) | ||
6770 | { | ||
6771 | Error(originFunc, string.Format("Error running rule PSYS_PART_END_ALPHA: arg #{0} - parameter 1 must be float", i + 1)); | ||
6772 | return; | ||
6773 | } | ||
6269 | prules.PartEndColor.A = tempf; | 6774 | prules.PartEndColor.A = tempf; |
6270 | break; | 6775 | break; |
6271 | 6776 | ||
6272 | case (int)ScriptBaseClass.PSYS_PART_START_SCALE: | 6777 | case (int)ScriptBaseClass.PSYS_PART_START_SCALE: |
6273 | tempv = rules.GetVector3Item(i + 1); | 6778 | try |
6274 | prules.PartStartScaleX = (float)tempv.x; | 6779 | { |
6275 | prules.PartStartScaleY = (float)tempv.y; | 6780 | tempv = rules.GetVector3Item(i + 1); |
6781 | } | ||
6782 | catch(InvalidCastException) | ||
6783 | { | ||
6784 | Error(originFunc, string.Format("Error running rule PSYS_PART_START_SCALE: arg #{0} - parameter 1 must be vector", i + 1)); | ||
6785 | return; | ||
6786 | } | ||
6787 | prules.PartStartScaleX = validParticleScale((float)tempv.x); | ||
6788 | prules.PartStartScaleY = validParticleScale((float)tempv.y); | ||
6276 | break; | 6789 | break; |
6277 | 6790 | ||
6278 | case (int)ScriptBaseClass.PSYS_PART_END_SCALE: | 6791 | case (int)ScriptBaseClass.PSYS_PART_END_SCALE: |
6279 | tempv = rules.GetVector3Item(i + 1); | 6792 | try |
6280 | prules.PartEndScaleX = (float)tempv.x; | 6793 | { |
6281 | prules.PartEndScaleY = (float)tempv.y; | 6794 | tempv = rules.GetVector3Item(i + 1); |
6795 | } | ||
6796 | catch(InvalidCastException) | ||
6797 | { | ||
6798 | Error(originFunc, string.Format("Error running rule PSYS_PART_END_SCALE: arg #{0} - parameter 1 must be vector", i + 1)); | ||
6799 | return; | ||
6800 | } | ||
6801 | prules.PartEndScaleX = validParticleScale((float)tempv.x); | ||
6802 | prules.PartEndScaleY = validParticleScale((float)tempv.y); | ||
6282 | break; | 6803 | break; |
6283 | 6804 | ||
6284 | case (int)ScriptBaseClass.PSYS_PART_MAX_AGE: | 6805 | case (int)ScriptBaseClass.PSYS_PART_MAX_AGE: |
6285 | tempf = (float)rules.GetLSLFloatItem(i + 1); | 6806 | try |
6807 | { | ||
6808 | tempf = (float)rules.GetLSLFloatItem(i + 1); | ||
6809 | } | ||
6810 | catch(InvalidCastException) | ||
6811 | { | ||
6812 | Error(originFunc, string.Format("Error running rule PSYS_PART_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1)); | ||
6813 | return; | ||
6814 | } | ||
6286 | prules.PartMaxAge = tempf; | 6815 | prules.PartMaxAge = tempf; |
6287 | break; | 6816 | break; |
6288 | 6817 | ||
6289 | case (int)ScriptBaseClass.PSYS_SRC_ACCEL: | 6818 | case (int)ScriptBaseClass.PSYS_SRC_ACCEL: |
6290 | tempv = rules.GetVector3Item(i + 1); | 6819 | try |
6820 | { | ||
6821 | tempv = rules.GetVector3Item(i + 1); | ||
6822 | } | ||
6823 | catch(InvalidCastException) | ||
6824 | { | ||
6825 | Error(originFunc, string.Format("Error running rule PSYS_SRC_ACCEL: arg #{0} - parameter 1 must be vector", i + 1)); | ||
6826 | return; | ||
6827 | } | ||
6291 | prules.PartAcceleration.X = (float)tempv.x; | 6828 | prules.PartAcceleration.X = (float)tempv.x; |
6292 | prules.PartAcceleration.Y = (float)tempv.y; | 6829 | prules.PartAcceleration.Y = (float)tempv.y; |
6293 | prules.PartAcceleration.Z = (float)tempv.z; | 6830 | prules.PartAcceleration.Z = (float)tempv.z; |
6294 | break; | 6831 | break; |
6295 | 6832 | ||
6296 | case (int)ScriptBaseClass.PSYS_SRC_PATTERN: | 6833 | case (int)ScriptBaseClass.PSYS_SRC_PATTERN: |
6297 | int tmpi = (int)rules.GetLSLIntegerItem(i + 1); | 6834 | try |
6835 | { | ||
6836 | tmpi = (int)rules.GetLSLIntegerItem(i + 1); | ||
6837 | } | ||
6838 | catch(InvalidCastException) | ||
6839 | { | ||
6840 | Error(originFunc, string.Format("Error running rule PSYS_SRC_PATTERN: arg #{0} - parameter 1 must be integer", i + 1)); | ||
6841 | return; | ||
6842 | } | ||
6298 | prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi; | 6843 | prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi; |
6299 | break; | 6844 | break; |
6300 | 6845 | ||
@@ -6303,47 +6848,171 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6303 | // client tells the difference between the two by looking at the 0x02 bit in | 6848 | // client tells the difference between the two by looking at the 0x02 bit in |
6304 | // the PartFlags variable. | 6849 | // the PartFlags variable. |
6305 | case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE: | 6850 | case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE: |
6306 | tempf = (float)rules.GetLSLFloatItem(i + 1); | 6851 | try |
6852 | { | ||
6853 | tempf = (float)rules.GetLSLFloatItem(i + 1); | ||
6854 | } | ||
6855 | catch(InvalidCastException) | ||
6856 | { | ||
6857 | Error(originFunc, string.Format("Error running rule PSYS_SRC_INNERANGLE: arg #{0} - parameter 1 must be float", i + 1)); | ||
6858 | return; | ||
6859 | } | ||
6307 | prules.InnerAngle = (float)tempf; | 6860 | prules.InnerAngle = (float)tempf; |
6308 | prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off. | 6861 | prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off. |
6309 | break; | 6862 | break; |
6310 | 6863 | ||
6311 | case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE: | 6864 | case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE: |
6312 | tempf = (float)rules.GetLSLFloatItem(i + 1); | 6865 | try |
6866 | { | ||
6867 | tempf = (float)rules.GetLSLFloatItem(i + 1); | ||
6868 | } | ||
6869 | catch(InvalidCastException) | ||
6870 | { | ||
6871 | Error(originFunc, string.Format("Error running rule PSYS_SRC_OUTERANGLE: arg #{0} - parameter 1 must be float", i + 1)); | ||
6872 | return; | ||
6873 | } | ||
6313 | prules.OuterAngle = (float)tempf; | 6874 | prules.OuterAngle = (float)tempf; |
6314 | prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off. | 6875 | prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off. |
6315 | break; | 6876 | break; |
6316 | 6877 | ||
6878 | case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_SOURCE: | ||
6879 | try | ||
6880 | { | ||
6881 | tmpi = (int)rules.GetLSLIntegerItem(i + 1); | ||
6882 | } | ||
6883 | catch(InvalidCastException) | ||
6884 | { | ||
6885 | Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_SOURCE: arg #{0} - parameter 1 must be integer", i + 1)); | ||
6886 | return; | ||
6887 | } | ||
6888 | prules.BlendFuncSource = (byte)tmpi; | ||
6889 | break; | ||
6890 | |||
6891 | case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_DEST: | ||
6892 | try | ||
6893 | { | ||
6894 | tmpi = (int)rules.GetLSLIntegerItem(i + 1); | ||
6895 | } | ||
6896 | catch(InvalidCastException) | ||
6897 | { | ||
6898 | Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_DEST: arg #{0} - parameter 1 must be integer", i + 1)); | ||
6899 | return; | ||
6900 | } | ||
6901 | prules.BlendFuncDest = (byte)tmpi; | ||
6902 | break; | ||
6903 | |||
6904 | case (int)ScriptBaseClass.PSYS_PART_START_GLOW: | ||
6905 | try | ||
6906 | { | ||
6907 | tempf = (float)rules.GetLSLFloatItem(i + 1); | ||
6908 | } | ||
6909 | catch(InvalidCastException) | ||
6910 | { | ||
6911 | Error(originFunc, string.Format("Error running rule PSYS_PART_START_GLOW: arg #{0} - parameter 1 must be float", i + 1)); | ||
6912 | return; | ||
6913 | } | ||
6914 | prules.PartStartGlow = (float)tempf; | ||
6915 | break; | ||
6916 | |||
6917 | case (int)ScriptBaseClass.PSYS_PART_END_GLOW: | ||
6918 | try | ||
6919 | { | ||
6920 | tempf = (float)rules.GetLSLFloatItem(i + 1); | ||
6921 | } | ||
6922 | catch(InvalidCastException) | ||
6923 | { | ||
6924 | Error(originFunc, string.Format("Error running rule PSYS_PART_END_GLOW: arg #{0} - parameter 1 must be float", i + 1)); | ||
6925 | return; | ||
6926 | } | ||
6927 | prules.PartEndGlow = (float)tempf; | ||
6928 | break; | ||
6929 | |||
6317 | case (int)ScriptBaseClass.PSYS_SRC_TEXTURE: | 6930 | case (int)ScriptBaseClass.PSYS_SRC_TEXTURE: |
6318 | prules.Texture = KeyOrName(rules.GetLSLStringItem(i + 1)); | 6931 | try |
6932 | { | ||
6933 | prules.Texture = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, rules.GetLSLStringItem(i + 1)); | ||
6934 | } | ||
6935 | catch(InvalidCastException) | ||
6936 | { | ||
6937 | Error(originFunc, string.Format("Error running rule PSYS_SRC_TEXTURE: arg #{0} - parameter 1 must be string or key", i + 1)); | ||
6938 | return; | ||
6939 | } | ||
6319 | break; | 6940 | break; |
6320 | 6941 | ||
6321 | case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE: | 6942 | case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE: |
6322 | tempf = (float)rules.GetLSLFloatItem(i + 1); | 6943 | try |
6944 | { | ||
6945 | tempf = (float)rules.GetLSLFloatItem(i + 1); | ||
6946 | } | ||
6947 | catch(InvalidCastException) | ||
6948 | { | ||
6949 | Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RATE: arg #{0} - parameter 1 must be float", i + 1)); | ||
6950 | return; | ||
6951 | } | ||
6323 | prules.BurstRate = (float)tempf; | 6952 | prules.BurstRate = (float)tempf; |
6324 | break; | 6953 | break; |
6325 | 6954 | ||
6326 | case (int)ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT: | 6955 | case (int)ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT: |
6327 | prules.BurstPartCount = (byte)(int)rules.GetLSLIntegerItem(i + 1); | 6956 | try |
6957 | { | ||
6958 | prules.BurstPartCount = (byte)(int)rules.GetLSLIntegerItem(i + 1); | ||
6959 | } | ||
6960 | catch(InvalidCastException) | ||
6961 | { | ||
6962 | Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_PART_COUNT: arg #{0} - parameter 1 must be integer", i + 1)); | ||
6963 | return; | ||
6964 | } | ||
6328 | break; | 6965 | break; |
6329 | 6966 | ||
6330 | case (int)ScriptBaseClass.PSYS_SRC_BURST_RADIUS: | 6967 | case (int)ScriptBaseClass.PSYS_SRC_BURST_RADIUS: |
6331 | tempf = (float)rules.GetLSLFloatItem(i + 1); | 6968 | try |
6969 | { | ||
6970 | tempf = (float)rules.GetLSLFloatItem(i + 1); | ||
6971 | } | ||
6972 | catch(InvalidCastException) | ||
6973 | { | ||
6974 | Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RADIUS: arg #{0} - parameter 1 must be float", i + 1)); | ||
6975 | return; | ||
6976 | } | ||
6332 | prules.BurstRadius = (float)tempf; | 6977 | prules.BurstRadius = (float)tempf; |
6333 | break; | 6978 | break; |
6334 | 6979 | ||
6335 | case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN: | 6980 | case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN: |
6336 | tempf = (float)rules.GetLSLFloatItem(i + 1); | 6981 | try |
6982 | { | ||
6983 | tempf = (float)rules.GetLSLFloatItem(i + 1); | ||
6984 | } | ||
6985 | catch(InvalidCastException) | ||
6986 | { | ||
6987 | Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MIN: arg #{0} - parameter 1 must be float", i + 1)); | ||
6988 | return; | ||
6989 | } | ||
6337 | prules.BurstSpeedMin = (float)tempf; | 6990 | prules.BurstSpeedMin = (float)tempf; |
6338 | break; | 6991 | break; |
6339 | 6992 | ||
6340 | case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX: | 6993 | case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX: |
6341 | tempf = (float)rules.GetLSLFloatItem(i + 1); | 6994 | try |
6995 | { | ||
6996 | tempf = (float)rules.GetLSLFloatItem(i + 1); | ||
6997 | } | ||
6998 | catch(InvalidCastException) | ||
6999 | { | ||
7000 | Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MAX: arg #{0} - parameter 1 must be float", i + 1)); | ||
7001 | return; | ||
7002 | } | ||
6342 | prules.BurstSpeedMax = (float)tempf; | 7003 | prules.BurstSpeedMax = (float)tempf; |
6343 | break; | 7004 | break; |
6344 | 7005 | ||
6345 | case (int)ScriptBaseClass.PSYS_SRC_MAX_AGE: | 7006 | case (int)ScriptBaseClass.PSYS_SRC_MAX_AGE: |
6346 | tempf = (float)rules.GetLSLFloatItem(i + 1); | 7007 | try |
7008 | { | ||
7009 | tempf = (float)rules.GetLSLFloatItem(i + 1); | ||
7010 | } | ||
7011 | catch(InvalidCastException) | ||
7012 | { | ||
7013 | Error(originFunc, string.Format("Error running rule PSYS_SRC_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1)); | ||
7014 | return; | ||
7015 | } | ||
6347 | prules.MaxAge = (float)tempf; | 7016 | prules.MaxAge = (float)tempf; |
6348 | break; | 7017 | break; |
6349 | 7018 | ||
@@ -6361,20 +7030,44 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6361 | 7030 | ||
6362 | case (int)ScriptBaseClass.PSYS_SRC_OMEGA: | 7031 | case (int)ScriptBaseClass.PSYS_SRC_OMEGA: |
6363 | // AL: This is an assumption, since it is the only thing that would match. | 7032 | // AL: This is an assumption, since it is the only thing that would match. |
6364 | tempv = rules.GetVector3Item(i + 1); | 7033 | try |
7034 | { | ||
7035 | tempv = rules.GetVector3Item(i + 1); | ||
7036 | } | ||
7037 | catch(InvalidCastException) | ||
7038 | { | ||
7039 | Error(originFunc, string.Format("Error running rule PSYS_SRC_OMEGA: arg #{0} - parameter 1 must be vector", i + 1)); | ||
7040 | return; | ||
7041 | } | ||
6365 | prules.AngularVelocity.X = (float)tempv.x; | 7042 | prules.AngularVelocity.X = (float)tempv.x; |
6366 | prules.AngularVelocity.Y = (float)tempv.y; | 7043 | prules.AngularVelocity.Y = (float)tempv.y; |
6367 | prules.AngularVelocity.Z = (float)tempv.z; | 7044 | prules.AngularVelocity.Z = (float)tempv.z; |
6368 | break; | 7045 | break; |
6369 | 7046 | ||
6370 | case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN: | 7047 | case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN: |
6371 | tempf = (float)rules.GetLSLFloatItem(i + 1); | 7048 | try |
7049 | { | ||
7050 | tempf = (float)rules.GetLSLFloatItem(i + 1); | ||
7051 | } | ||
7052 | catch(InvalidCastException) | ||
7053 | { | ||
7054 | Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_BEGIN: arg #{0} - parameter 1 must be float", i + 1)); | ||
7055 | return; | ||
7056 | } | ||
6372 | prules.InnerAngle = (float)tempf; | 7057 | prules.InnerAngle = (float)tempf; |
6373 | prules.PartFlags |= 0x02; // Set new angle format. | 7058 | prules.PartFlags |= 0x02; // Set new angle format. |
6374 | break; | 7059 | break; |
6375 | 7060 | ||
6376 | case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END: | 7061 | case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END: |
6377 | tempf = (float)rules.GetLSLFloatItem(i + 1); | 7062 | try |
7063 | { | ||
7064 | tempf = (float)rules.GetLSLFloatItem(i + 1); | ||
7065 | } | ||
7066 | catch (InvalidCastException) | ||
7067 | { | ||
7068 | Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_END: arg #{0} - parameter 1 must be float", i + 1)); | ||
7069 | return; | ||
7070 | } | ||
6378 | prules.OuterAngle = (float)tempf; | 7071 | prules.OuterAngle = (float)tempf; |
6379 | prules.PartFlags |= 0x02; // Set new angle format. | 7072 | prules.PartFlags |= 0x02; // Set new angle format. |
6380 | break; | 7073 | break; |
@@ -6389,6 +7082,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6389 | part.SendFullUpdateToAllClients(); | 7082 | part.SendFullUpdateToAllClients(); |
6390 | } | 7083 | } |
6391 | 7084 | ||
7085 | private float validParticleScale(float value) | ||
7086 | { | ||
7087 | if (value > 4.0f) return 4.0f; | ||
7088 | return value; | ||
7089 | } | ||
7090 | |||
6392 | public void llGroundRepel(double height, int water, double tau) | 7091 | public void llGroundRepel(double height, int water, double tau) |
6393 | { | 7092 | { |
6394 | m_host.AddScriptLPS(1); | 7093 | m_host.AddScriptLPS(1); |
@@ -6460,7 +7159,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6460 | m_host.OwnerID, m_host.Name, destID, | 7159 | m_host.OwnerID, m_host.Name, destID, |
6461 | (byte)InstantMessageDialog.TaskInventoryOffered, | 7160 | (byte)InstantMessageDialog.TaskInventoryOffered, |
6462 | false, string.Format("'{0}'", category), | 7161 | false, string.Format("'{0}'", category), |
6463 | // We won't go so far as to add a SLURL, but this is the format used by LL as of 2012-10-06 | 7162 | // We won't go so far as to add a SLURL, but this is the format used by LL as of 2012-10-06 |
6464 | // false, string.Format("'{0}' ( http://slurl.com/secondlife/{1}/{2}/{3}/{4} )", category, World.Name, (int)pos.X, (int)pos.Y, (int)pos.Z), | 7163 | // false, string.Format("'{0}' ( http://slurl.com/secondlife/{1}/{2}/{3}/{4} )", category, World.Name, (int)pos.X, (int)pos.Y, (int)pos.Z), |
6465 | folderID, false, pos, | 7164 | folderID, false, pos, |
6466 | bucket, false); | 7165 | bucket, false); |
@@ -6575,12 +7274,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6575 | public LSL_String llAvatarOnLinkSitTarget(int linknum) | 7274 | public LSL_String llAvatarOnLinkSitTarget(int linknum) |
6576 | { | 7275 | { |
6577 | m_host.AddScriptLPS(1); | 7276 | m_host.AddScriptLPS(1); |
6578 | if(linknum == ScriptBaseClass.LINK_SET || | 7277 | if(linknum == ScriptBaseClass.LINK_SET || |
6579 | linknum == ScriptBaseClass.LINK_ALL_CHILDREN || | 7278 | linknum == ScriptBaseClass.LINK_ALL_CHILDREN || |
6580 | linknum == ScriptBaseClass.LINK_ALL_OTHERS) return UUID.Zero.ToString(); | 7279 | linknum == ScriptBaseClass.LINK_ALL_OTHERS) return UUID.Zero.ToString(); |
6581 | 7280 | ||
6582 | List<SceneObjectPart> parts = GetLinkParts(linknum); | 7281 | List<SceneObjectPart> parts = GetLinkParts(linknum); |
6583 | if (parts.Count == 0) return UUID.Zero.ToString(); | 7282 | if (parts.Count == 0) return UUID.Zero.ToString(); |
6584 | return parts[0].SitTargetAvatar.ToString(); | 7283 | return parts[0].SitTargetAvatar.ToString(); |
6585 | } | 7284 | } |
6586 | 7285 | ||
@@ -6589,7 +7288,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6589 | { | 7288 | { |
6590 | m_host.AddScriptLPS(1); | 7289 | m_host.AddScriptLPS(1); |
6591 | UUID key; | 7290 | UUID key; |
6592 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); | 7291 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); |
7292 | |||
6593 | if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned)) | 7293 | if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned)) |
6594 | { | 7294 | { |
6595 | int expires = 0; | 7295 | int expires = 0; |
@@ -6623,7 +7323,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6623 | World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land); | 7323 | World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land); |
6624 | } | 7324 | } |
6625 | } | 7325 | } |
6626 | ScriptSleep(100); | 7326 | ScriptSleep(m_sleepMsOnAddToLandPassList); |
6627 | } | 7327 | } |
6628 | 7328 | ||
6629 | public void llSetTouchText(string text) | 7329 | public void llSetTouchText(string text) |
@@ -6642,12 +7342,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6642 | { | 7342 | { |
6643 | m_host.AddScriptLPS(1); | 7343 | m_host.AddScriptLPS(1); |
6644 | m_host.SetCameraEyeOffset(offset); | 7344 | m_host.SetCameraEyeOffset(offset); |
7345 | |||
7346 | if (m_host.ParentGroup.RootPart.GetCameraEyeOffset() == Vector3.Zero) | ||
7347 | m_host.ParentGroup.RootPart.SetCameraEyeOffset(offset); | ||
6645 | } | 7348 | } |
6646 | 7349 | ||
6647 | public void llSetCameraAtOffset(LSL_Vector offset) | 7350 | public void llSetCameraAtOffset(LSL_Vector offset) |
6648 | { | 7351 | { |
6649 | m_host.AddScriptLPS(1); | 7352 | m_host.AddScriptLPS(1); |
6650 | m_host.SetCameraAtOffset(offset); | 7353 | m_host.SetCameraAtOffset(offset); |
7354 | |||
7355 | if (m_host.ParentGroup.RootPart.GetCameraAtOffset() == Vector3.Zero) | ||
7356 | m_host.ParentGroup.RootPart.SetCameraAtOffset(offset); | ||
6651 | } | 7357 | } |
6652 | 7358 | ||
6653 | public void llSetLinkCamera(LSL_Integer link, LSL_Vector eye, LSL_Vector at) | 7359 | public void llSetLinkCamera(LSL_Integer link, LSL_Vector eye, LSL_Vector at) |
@@ -6722,17 +7428,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6722 | UUID av = new UUID(); | 7428 | UUID av = new UUID(); |
6723 | if (!UUID.TryParse(avatar,out av)) | 7429 | if (!UUID.TryParse(avatar,out av)) |
6724 | { | 7430 | { |
6725 | LSLError("First parameter to llDialog needs to be a key"); | 7431 | Error("llDialog", "First parameter must be a key"); |
6726 | return; | 7432 | return; |
6727 | } | 7433 | } |
6728 | if (buttons.Length < 1) | 7434 | if (buttons.Length < 1) |
6729 | { | 7435 | { |
6730 | LSLError("No less than 1 button can be shown"); | 7436 | Error("llDialog", "At least 1 button must be shown"); |
6731 | return; | 7437 | return; |
6732 | } | 7438 | } |
6733 | if (buttons.Length > 12) | 7439 | if (buttons.Length > 12) |
6734 | { | 7440 | { |
6735 | LSLError("No more than 12 buttons can be shown"); | 7441 | Error("llDialog", "No more than 12 buttons can be shown"); |
6736 | return; | 7442 | return; |
6737 | } | 7443 | } |
6738 | string[] buts = new string[buttons.Length]; | 7444 | string[] buts = new string[buttons.Length]; |
@@ -6740,12 +7446,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6740 | { | 7446 | { |
6741 | if (buttons.Data[i].ToString() == String.Empty) | 7447 | if (buttons.Data[i].ToString() == String.Empty) |
6742 | { | 7448 | { |
6743 | LSLError("button label cannot be blank"); | 7449 | Error("llDialog", "Button label cannot be blank"); |
6744 | return; | 7450 | return; |
6745 | } | 7451 | } |
6746 | if (buttons.Data[i].ToString().Length > 24) | 7452 | if (buttons.Data[i].ToString().Length > 24) |
6747 | { | 7453 | { |
6748 | LSLError("button label cannot be longer than 24 characters"); | 7454 | Error("llDialog", "Button label cannot be longer than 24 characters"); |
6749 | return; | 7455 | return; |
6750 | } | 7456 | } |
6751 | buts[i] = buttons.Data[i].ToString(); | 7457 | buts[i] = buttons.Data[i].ToString(); |
@@ -6755,7 +7461,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6755 | av, m_host.Name, m_host.UUID, m_host.OwnerID, | 7461 | av, m_host.Name, m_host.UUID, m_host.OwnerID, |
6756 | message, new UUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts); | 7462 | message, new UUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts); |
6757 | 7463 | ||
6758 | ScriptSleep(1000); | 7464 | ScriptSleep(m_sleepMsOnDialog); |
6759 | } | 7465 | } |
6760 | 7466 | ||
6761 | public void llVolumeDetect(int detect) | 7467 | public void llVolumeDetect(int detect) |
@@ -6766,16 +7472,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6766 | m_host.ParentGroup.ScriptSetVolumeDetect(detect != 0); | 7472 | m_host.ParentGroup.ScriptSetVolumeDetect(detect != 0); |
6767 | } | 7473 | } |
6768 | 7474 | ||
6769 | /// <summary> | ||
6770 | /// This is a depecated function so this just replicates the result of | ||
6771 | /// invoking it in SL | ||
6772 | /// </summary> | ||
6773 | public void llRemoteLoadScript(string target, string name, int running, int start_param) | 7475 | public void llRemoteLoadScript(string target, string name, int running, int start_param) |
6774 | { | 7476 | { |
6775 | m_host.AddScriptLPS(1); | 7477 | m_host.AddScriptLPS(1); |
6776 | // Report an error as it does in SL | 7478 | Deprecated("llRemoteLoadScript", "Use llRemoteLoadScriptPin instead"); |
6777 | ShoutError("Deprecated. Please use llRemoteLoadScriptPin instead."); | 7479 | ScriptSleep(m_sleepMsOnRemoteLoadScript); |
6778 | ScriptSleep(3000); | ||
6779 | } | 7480 | } |
6780 | 7481 | ||
6781 | public void llSetRemoteScriptAccessPin(int pin) | 7482 | public void llSetRemoteScriptAccessPin(int pin) |
@@ -6792,7 +7493,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6792 | 7493 | ||
6793 | if (!UUID.TryParse(target, out destId)) | 7494 | if (!UUID.TryParse(target, out destId)) |
6794 | { | 7495 | { |
6795 | llSay(0, "Could not parse key " + target); | 7496 | Error("llRemoteLoadScriptPin", "Can't parse key '" + target + "'"); |
6796 | return; | 7497 | return; |
6797 | } | 7498 | } |
6798 | 7499 | ||
@@ -6808,7 +7509,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6808 | // make sure the object is a script | 7509 | // make sure the object is a script |
6809 | if (item == null || item.Type != 10) | 7510 | if (item == null || item.Type != 10) |
6810 | { | 7511 | { |
6811 | llSay(0, "Could not find script " + name); | 7512 | Error("llRemoteLoadScriptPin", "Can't find script '" + name + "'"); |
6812 | return; | 7513 | return; |
6813 | } | 7514 | } |
6814 | 7515 | ||
@@ -6816,14 +7517,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6816 | World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param); | 7517 | World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param); |
6817 | 7518 | ||
6818 | // this will cause the delay even if the script pin or permissions were wrong - seems ok | 7519 | // this will cause the delay even if the script pin or permissions were wrong - seems ok |
6819 | ScriptSleep(3000); | 7520 | ScriptSleep(m_sleepMsOnRemoteLoadScriptPin); |
6820 | } | 7521 | } |
6821 | 7522 | ||
6822 | public void llOpenRemoteDataChannel() | 7523 | public void llOpenRemoteDataChannel() |
6823 | { | 7524 | { |
6824 | m_host.AddScriptLPS(1); | 7525 | m_host.AddScriptLPS(1); |
6825 | IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); | 7526 | IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); |
6826 | if (xmlrpcMod.IsEnabled()) | 7527 | if (xmlrpcMod != null && xmlrpcMod.IsEnabled()) |
6827 | { | 7528 | { |
6828 | UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero); | 7529 | UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero); |
6829 | IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>(); | 7530 | IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>(); |
@@ -6847,14 +7548,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6847 | m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj, | 7548 | m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj, |
6848 | new DetectParams[0])); | 7549 | new DetectParams[0])); |
6849 | } | 7550 | } |
6850 | ScriptSleep(1000); | 7551 | ScriptSleep(m_sleepMsOnOpenRemoteDataChannel); |
6851 | } | 7552 | } |
6852 | 7553 | ||
6853 | public LSL_String llSendRemoteData(string channel, string dest, int idata, string sdata) | 7554 | public LSL_String llSendRemoteData(string channel, string dest, int idata, string sdata) |
6854 | { | 7555 | { |
6855 | m_host.AddScriptLPS(1); | 7556 | m_host.AddScriptLPS(1); |
6856 | IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); | 7557 | IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); |
6857 | ScriptSleep(3000); | 7558 | ScriptSleep(m_sleepMsOnSendRemoteData); |
7559 | if (xmlrpcMod == null) | ||
7560 | return ""; | ||
6858 | return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString(); | 7561 | return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString(); |
6859 | } | 7562 | } |
6860 | 7563 | ||
@@ -6862,8 +7565,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6862 | { | 7565 | { |
6863 | m_host.AddScriptLPS(1); | 7566 | m_host.AddScriptLPS(1); |
6864 | IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); | 7567 | IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); |
6865 | xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata); | 7568 | if (xmlrpcMod != null) |
6866 | ScriptSleep(3000); | 7569 | xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata); |
7570 | ScriptSleep(m_sleepMsOnRemoteDataReply); | ||
6867 | } | 7571 | } |
6868 | 7572 | ||
6869 | public void llCloseRemoteDataChannel(string channel) | 7573 | public void llCloseRemoteDataChannel(string channel) |
@@ -6877,8 +7581,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6877 | } | 7581 | } |
6878 | 7582 | ||
6879 | IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); | 7583 | IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); |
6880 | xmlrpcMod.CloseXMLRPCChannel((UUID)channel); | 7584 | if (xmlrpcMod != null) |
6881 | ScriptSleep(1000); | 7585 | xmlrpcMod.CloseXMLRPCChannel((UUID)channel); |
7586 | ScriptSleep(m_sleepMsOnCloseRemoteDataChannel); | ||
6882 | } | 7587 | } |
6883 | 7588 | ||
6884 | public LSL_String llMD5String(string src, int nonce) | 7589 | public LSL_String llMD5String(string src, int nonce) |
@@ -6924,13 +7629,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6924 | { | 7629 | { |
6925 | cut.y = 1f; | 7630 | cut.y = 1f; |
6926 | } | 7631 | } |
6927 | if (cut.y - cut.x < 0.05f) | 7632 | if (cut.y - cut.x < 0.02f) |
6928 | { | 7633 | { |
6929 | cut.x = cut.y - 0.05f; | 7634 | cut.x = cut.y - 0.02f; |
6930 | if (cut.x < 0.0f) | 7635 | if (cut.x < 0.0f) |
6931 | { | 7636 | { |
6932 | cut.x = 0.0f; | 7637 | cut.x = 0.0f; |
6933 | cut.y = 0.05f; | 7638 | cut.y = 0.02f; |
6934 | } | 7639 | } |
6935 | } | 7640 | } |
6936 | shapeBlock.ProfileBegin = (ushort)(50000 * cut.x); | 7641 | shapeBlock.ProfileBegin = (ushort)(50000 * cut.x); |
@@ -6952,12 +7657,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6952 | hollow = 0.70f; | 7657 | hollow = 0.70f; |
6953 | } | 7658 | } |
6954 | } | 7659 | } |
6955 | // Otherwise, hollow is limited to 95%. | 7660 | // Otherwise, hollow is limited to 99%. |
6956 | else | 7661 | else |
6957 | { | 7662 | { |
6958 | if (hollow > 0.95f) | 7663 | if (hollow > 0.99f) |
6959 | { | 7664 | { |
6960 | hollow = 0.95f; | 7665 | hollow = 0.99f; |
6961 | } | 7666 | } |
6962 | } | 7667 | } |
6963 | shapeBlock.ProfileHollow = (ushort)(50000 * hollow); | 7668 | shapeBlock.ProfileHollow = (ushort)(50000 * hollow); |
@@ -7081,9 +7786,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7081 | { | 7786 | { |
7082 | dimple.y = 1f; | 7787 | dimple.y = 1f; |
7083 | } | 7788 | } |
7084 | if (dimple.y - cut.x < 0.05f) | 7789 | if (dimple.y - dimple.x < 0.02f) |
7085 | { | 7790 | { |
7086 | dimple.x = cut.y - 0.05f; | 7791 | dimple.x = dimple.y - 0.02f; |
7792 | if (dimple.x < 0.0f) | ||
7793 | { | ||
7794 | dimple.x = 0.0f; | ||
7795 | dimple.y = 0.02f; | ||
7796 | } | ||
7087 | } | 7797 | } |
7088 | shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x); | 7798 | shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x); |
7089 | shapeBlock.ProfileEnd = (ushort)(50000 * (1 - dimple.y)); | 7799 | shapeBlock.ProfileEnd = (ushort)(50000 * (1 - dimple.y)); |
@@ -7104,17 +7814,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7104 | shapeBlock.PathBegin = shapeBlock.ProfileBegin; | 7814 | shapeBlock.PathBegin = shapeBlock.ProfileBegin; |
7105 | shapeBlock.PathEnd = shapeBlock.ProfileEnd; | 7815 | shapeBlock.PathEnd = shapeBlock.ProfileEnd; |
7106 | 7816 | ||
7107 | if (holesize.x < 0.05f) | 7817 | if (holesize.x < 0.01f) |
7108 | { | 7818 | { |
7109 | holesize.x = 0.05f; | 7819 | holesize.x = 0.01f; |
7110 | } | 7820 | } |
7111 | if (holesize.x > 1f) | 7821 | if (holesize.x > 1f) |
7112 | { | 7822 | { |
7113 | holesize.x = 1f; | 7823 | holesize.x = 1f; |
7114 | } | 7824 | } |
7115 | if (holesize.y < 0.05f) | 7825 | if (holesize.y < 0.01f) |
7116 | { | 7826 | { |
7117 | holesize.y = 0.05f; | 7827 | holesize.y = 0.01f; |
7118 | } | 7828 | } |
7119 | if (holesize.y > 0.5f) | 7829 | if (holesize.y > 0.5f) |
7120 | { | 7830 | { |
@@ -7160,13 +7870,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7160 | { | 7870 | { |
7161 | profilecut.y = 1f; | 7871 | profilecut.y = 1f; |
7162 | } | 7872 | } |
7163 | if (profilecut.y - profilecut.x < 0.05f) | 7873 | if (profilecut.y - profilecut.x < 0.02f) |
7164 | { | 7874 | { |
7165 | profilecut.x = profilecut.y - 0.05f; | 7875 | profilecut.x = profilecut.y - 0.02f; |
7166 | if (profilecut.x < 0.0f) | 7876 | if (profilecut.x < 0.0f) |
7167 | { | 7877 | { |
7168 | profilecut.x = 0.0f; | 7878 | profilecut.x = 0.0f; |
7169 | profilecut.y = 0.05f; | 7879 | profilecut.y = 0.02f; |
7170 | } | 7880 | } |
7171 | } | 7881 | } |
7172 | shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x); | 7882 | shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x); |
@@ -7234,9 +7944,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7234 | UUID sculptId; | 7944 | UUID sculptId; |
7235 | 7945 | ||
7236 | if (!UUID.TryParse(map, out sculptId)) | 7946 | if (!UUID.TryParse(map, out sculptId)) |
7237 | { | 7947 | sculptId = ScriptUtils.GetAssetIdFromItemName(m_host, map, (int)AssetType.Texture); |
7238 | sculptId = InventoryKey(map, (int)AssetType.Texture); | ||
7239 | } | ||
7240 | 7948 | ||
7241 | if (sculptId == UUID.Zero) | 7949 | if (sculptId == UUID.Zero) |
7242 | return; | 7950 | return; |
@@ -7266,45 +7974,205 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7266 | { | 7974 | { |
7267 | m_host.AddScriptLPS(1); | 7975 | m_host.AddScriptLPS(1); |
7268 | 7976 | ||
7269 | setLinkPrimParams(ScriptBaseClass.LINK_THIS, rules, "llSetPrimitiveParams"); | 7977 | SetLinkPrimParams(ScriptBaseClass.LINK_THIS, rules, "llSetPrimitiveParams"); |
7270 | 7978 | ||
7271 | ScriptSleep(200); | 7979 | ScriptSleep(m_sleepMsOnSetPrimitiveParams); |
7272 | } | 7980 | } |
7273 | 7981 | ||
7274 | public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules) | 7982 | public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules) |
7275 | { | 7983 | { |
7276 | m_host.AddScriptLPS(1); | 7984 | m_host.AddScriptLPS(1); |
7277 | 7985 | ||
7278 | setLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams"); | 7986 | SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams"); |
7279 | 7987 | ||
7280 | ScriptSleep(200); | 7988 | ScriptSleep(m_sleepMsOnSetLinkPrimitiveParams); |
7281 | } | 7989 | } |
7282 | 7990 | ||
7283 | public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules) | 7991 | public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules) |
7284 | { | 7992 | { |
7285 | m_host.AddScriptLPS(1); | 7993 | m_host.AddScriptLPS(1); |
7286 | 7994 | ||
7287 | setLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast"); | 7995 | SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast"); |
7288 | } | 7996 | } |
7289 | 7997 | ||
7290 | protected void setLinkPrimParams(int linknumber, LSL_List rules, string originFunc) | 7998 | protected void SetLinkPrimParams(int linknumber, LSL_List rules, string originFunc) |
7291 | { | 7999 | { |
7292 | List<SceneObjectPart> parts = GetLinkParts(linknumber); | 8000 | SetEntityParams(GetLinkEntities(linknumber), rules, originFunc); |
8001 | } | ||
7293 | 8002 | ||
7294 | LSL_List remaining = null; | 8003 | protected void SetEntityParams(List<ISceneEntity> entities, LSL_List rules, string originFunc) |
8004 | { | ||
8005 | LSL_List remaining = new LSL_List(); | ||
7295 | uint rulesParsed = 0; | 8006 | uint rulesParsed = 0; |
7296 | 8007 | ||
7297 | foreach (SceneObjectPart part in parts) | 8008 | foreach (ISceneEntity entity in entities) |
7298 | remaining = SetPrimParams(part, rules, originFunc, ref rulesParsed); | 8009 | { |
8010 | if (entity is SceneObjectPart) | ||
8011 | remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed); | ||
8012 | else | ||
8013 | remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed); | ||
8014 | } | ||
7299 | 8015 | ||
7300 | while (remaining != null && remaining.Length > 2) | 8016 | while (remaining.Length > 2) |
7301 | { | 8017 | { |
7302 | linknumber = remaining.GetLSLIntegerItem(0); | 8018 | int linknumber; |
8019 | try | ||
8020 | { | ||
8021 | linknumber = remaining.GetLSLIntegerItem(0); | ||
8022 | } | ||
8023 | catch(InvalidCastException) | ||
8024 | { | ||
8025 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_LINK_TARGET: parameter 2 must be integer", rulesParsed)); | ||
8026 | return; | ||
8027 | } | ||
8028 | |||
7303 | rules = remaining.GetSublist(1, -1); | 8029 | rules = remaining.GetSublist(1, -1); |
7304 | parts = GetLinkParts(linknumber); | 8030 | entities = GetLinkEntities(linknumber); |
7305 | 8031 | ||
7306 | foreach (SceneObjectPart part in parts) | 8032 | foreach (ISceneEntity entity in entities) |
7307 | remaining = SetPrimParams(part, rules, originFunc, ref rulesParsed); | 8033 | { |
8034 | if (entity is SceneObjectPart) | ||
8035 | remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed); | ||
8036 | else | ||
8037 | remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed); | ||
8038 | } | ||
8039 | } | ||
8040 | } | ||
8041 | |||
8042 | public void llSetKeyframedMotion(LSL_List frames, LSL_List options) | ||
8043 | { | ||
8044 | SceneObjectGroup group = m_host.ParentGroup; | ||
8045 | |||
8046 | if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical) | ||
8047 | return; | ||
8048 | if (group.IsAttachment) | ||
8049 | return; | ||
8050 | |||
8051 | if (frames.Data.Length > 0) // We are getting a new motion | ||
8052 | { | ||
8053 | if (group.RootPart.KeyframeMotion != null) | ||
8054 | group.RootPart.KeyframeMotion.Delete(); | ||
8055 | group.RootPart.KeyframeMotion = null; | ||
8056 | |||
8057 | int idx = 0; | ||
8058 | |||
8059 | KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward; | ||
8060 | KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation; | ||
8061 | |||
8062 | while (idx < options.Data.Length) | ||
8063 | { | ||
8064 | int option = (int)options.GetLSLIntegerItem(idx++); | ||
8065 | int remain = options.Data.Length - idx; | ||
8066 | |||
8067 | switch (option) | ||
8068 | { | ||
8069 | case ScriptBaseClass.KFM_MODE: | ||
8070 | if (remain < 1) | ||
8071 | break; | ||
8072 | int modeval = (int)options.GetLSLIntegerItem(idx++); | ||
8073 | switch(modeval) | ||
8074 | { | ||
8075 | case ScriptBaseClass.KFM_FORWARD: | ||
8076 | mode = KeyframeMotion.PlayMode.Forward; | ||
8077 | break; | ||
8078 | case ScriptBaseClass.KFM_REVERSE: | ||
8079 | mode = KeyframeMotion.PlayMode.Reverse; | ||
8080 | break; | ||
8081 | case ScriptBaseClass.KFM_LOOP: | ||
8082 | mode = KeyframeMotion.PlayMode.Loop; | ||
8083 | break; | ||
8084 | case ScriptBaseClass.KFM_PING_PONG: | ||
8085 | mode = KeyframeMotion.PlayMode.PingPong; | ||
8086 | break; | ||
8087 | } | ||
8088 | break; | ||
8089 | case ScriptBaseClass.KFM_DATA: | ||
8090 | if (remain < 1) | ||
8091 | break; | ||
8092 | int dataval = (int)options.GetLSLIntegerItem(idx++); | ||
8093 | data = (KeyframeMotion.DataFormat)dataval; | ||
8094 | break; | ||
8095 | } | ||
8096 | } | ||
8097 | |||
8098 | group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data); | ||
8099 | |||
8100 | idx = 0; | ||
8101 | |||
8102 | int elemLength = 2; | ||
8103 | if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation)) | ||
8104 | elemLength = 3; | ||
8105 | |||
8106 | List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>(); | ||
8107 | while (idx < frames.Data.Length) | ||
8108 | { | ||
8109 | int remain = frames.Data.Length - idx; | ||
8110 | |||
8111 | if (remain < elemLength) | ||
8112 | break; | ||
8113 | |||
8114 | KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe(); | ||
8115 | frame.Position = null; | ||
8116 | frame.Rotation = null; | ||
8117 | |||
8118 | if ((data & KeyframeMotion.DataFormat.Translation) != 0) | ||
8119 | { | ||
8120 | LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++); | ||
8121 | frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z); | ||
8122 | } | ||
8123 | if ((data & KeyframeMotion.DataFormat.Rotation) != 0) | ||
8124 | { | ||
8125 | LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++); | ||
8126 | Quaternion q = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s); | ||
8127 | q.Normalize(); | ||
8128 | frame.Rotation = q; | ||
8129 | } | ||
8130 | |||
8131 | float tempf = (float)frames.GetLSLFloatItem(idx++); | ||
8132 | frame.TimeMS = (int)(tempf * 1000.0f); | ||
8133 | |||
8134 | keyframes.Add(frame); | ||
8135 | } | ||
8136 | |||
8137 | group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray()); | ||
8138 | group.RootPart.KeyframeMotion.Start(); | ||
8139 | } | ||
8140 | else | ||
8141 | { | ||
8142 | if (group.RootPart.KeyframeMotion == null) | ||
8143 | return; | ||
8144 | |||
8145 | if (options.Data.Length == 0) | ||
8146 | { | ||
8147 | group.RootPart.KeyframeMotion.Stop(); | ||
8148 | return; | ||
8149 | } | ||
8150 | |||
8151 | int idx = 0; | ||
8152 | |||
8153 | while (idx < options.Data.Length) | ||
8154 | { | ||
8155 | int option = (int)options.GetLSLIntegerItem(idx++); | ||
8156 | |||
8157 | switch (option) | ||
8158 | { | ||
8159 | case ScriptBaseClass.KFM_COMMAND: | ||
8160 | int cmd = (int)options.GetLSLIntegerItem(idx++); | ||
8161 | switch (cmd) | ||
8162 | { | ||
8163 | case ScriptBaseClass.KFM_CMD_PLAY: | ||
8164 | group.RootPart.KeyframeMotion.Start(); | ||
8165 | break; | ||
8166 | case ScriptBaseClass.KFM_CMD_STOP: | ||
8167 | group.RootPart.KeyframeMotion.Stop(); | ||
8168 | break; | ||
8169 | case ScriptBaseClass.KFM_CMD_PAUSE: | ||
8170 | group.RootPart.KeyframeMotion.Pause(); | ||
8171 | break; | ||
8172 | } | ||
8173 | break; | ||
8174 | } | ||
8175 | } | ||
7308 | } | 8176 | } |
7309 | } | 8177 | } |
7310 | 8178 | ||
@@ -7331,29 +8199,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7331 | 8199 | ||
7332 | switch (code) | 8200 | switch (code) |
7333 | { | 8201 | { |
7334 | case (int)ScriptBaseClass.PRIM_POSITION: | 8202 | case ScriptBaseClass.PRIM_POSITION: |
7335 | case (int)ScriptBaseClass.PRIM_POS_LOCAL: | 8203 | case ScriptBaseClass.PRIM_POS_LOCAL: |
7336 | if (remain < 1) | 8204 | if (remain < 1) |
7337 | return null; | 8205 | return new LSL_List(); |
7338 | 8206 | ||
7339 | v=rules.GetVector3Item(idx++); | 8207 | try |
8208 | { | ||
8209 | v = rules.GetVector3Item(idx++); | ||
8210 | } | ||
8211 | catch(InvalidCastException) | ||
8212 | { | ||
8213 | if(code == ScriptBaseClass.PRIM_POSITION) | ||
8214 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8215 | else | ||
8216 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8217 | return new LSL_List(); | ||
8218 | } | ||
7340 | positionChanged = true; | 8219 | positionChanged = true; |
7341 | currentPosition = GetSetPosTarget(part, v, currentPosition); | 8220 | currentPosition = GetSetPosTarget(part, v, currentPosition); |
7342 | 8221 | ||
7343 | break; | 8222 | break; |
7344 | case (int)ScriptBaseClass.PRIM_SIZE: | 8223 | case ScriptBaseClass.PRIM_SIZE: |
7345 | if (remain < 1) | 8224 | if (remain < 1) |
7346 | return null; | 8225 | return new LSL_List(); |
7347 | 8226 | ||
7348 | v=rules.GetVector3Item(idx++); | 8227 | v=rules.GetVector3Item(idx++); |
7349 | SetScale(part, v); | 8228 | SetScale(part, v); |
7350 | 8229 | ||
7351 | break; | 8230 | break; |
7352 | case (int)ScriptBaseClass.PRIM_ROTATION: | 8231 | case ScriptBaseClass.PRIM_ROTATION: |
7353 | if (remain < 1) | 8232 | if (remain < 1) |
7354 | return null; | 8233 | return new LSL_List(); |
7355 | 8234 | LSL_Rotation q; | |
7356 | LSL_Rotation q = rules.GetQuaternionItem(idx++); | 8235 | try |
8236 | { | ||
8237 | q = rules.GetQuaternionItem(idx++); | ||
8238 | } | ||
8239 | catch(InvalidCastException) | ||
8240 | { | ||
8241 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 1 must be rotation", rulesParsed, idx - idxStart - 1)); | ||
8242 | return new LSL_List(); | ||
8243 | } | ||
7357 | // try to let this work as in SL... | 8244 | // try to let this work as in SL... |
7358 | if (part.ParentID == 0) | 8245 | if (part.ParentID == 0) |
7359 | { | 8246 | { |
@@ -7369,11 +8256,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7369 | 8256 | ||
7370 | break; | 8257 | break; |
7371 | 8258 | ||
7372 | case (int)ScriptBaseClass.PRIM_TYPE: | 8259 | case ScriptBaseClass.PRIM_TYPE: |
7373 | if (remain < 3) | 8260 | if (remain < 3) |
7374 | return null; | 8261 | return new LSL_List(); |
7375 | 8262 | ||
7376 | code = (int)rules.GetLSLIntegerItem(idx++); | 8263 | try |
8264 | { | ||
8265 | code = (int)rules.GetLSLIntegerItem(idx++); | ||
8266 | } | ||
8267 | catch(InvalidCastException) | ||
8268 | { | ||
8269 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1)); | ||
8270 | return new LSL_List(); | ||
8271 | } | ||
7377 | 8272 | ||
7378 | remain = rules.Length - idx; | 8273 | remain = rules.Length - idx; |
7379 | float hollow; | 8274 | float hollow; |
@@ -7388,140 +8283,625 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7388 | 8283 | ||
7389 | switch (code) | 8284 | switch (code) |
7390 | { | 8285 | { |
7391 | case (int)ScriptBaseClass.PRIM_TYPE_BOX: | 8286 | case ScriptBaseClass.PRIM_TYPE_BOX: |
7392 | if (remain < 6) | 8287 | if (remain < 6) |
7393 | return null; | 8288 | return new LSL_List(); |
7394 | 8289 | ||
7395 | face = (int)rules.GetLSLIntegerItem(idx++); | 8290 | try |
7396 | v = rules.GetVector3Item(idx++); // cut | 8291 | { |
7397 | hollow = (float)rules.GetLSLFloatItem(idx++); | 8292 | face = (int)rules.GetLSLIntegerItem(idx++); |
7398 | twist = rules.GetVector3Item(idx++); | 8293 | } |
7399 | taper_b = rules.GetVector3Item(idx++); | 8294 | catch(InvalidCastException) |
7400 | topshear = rules.GetVector3Item(idx++); | 8295 | { |
8296 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1)); | ||
8297 | return new LSL_List(); | ||
8298 | } | ||
8299 | try | ||
8300 | { | ||
8301 | v = rules.GetVector3Item(idx++); // cut | ||
8302 | } | ||
8303 | catch(InvalidCastException) | ||
8304 | { | ||
8305 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8306 | return new LSL_List(); | ||
8307 | } | ||
8308 | try | ||
8309 | { | ||
8310 | hollow = (float)rules.GetLSLFloatItem(idx++); | ||
8311 | } | ||
8312 | catch(InvalidCastException) | ||
8313 | { | ||
8314 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1)); | ||
8315 | return new LSL_List(); | ||
8316 | } | ||
8317 | try | ||
8318 | { | ||
8319 | twist = rules.GetVector3Item(idx++); | ||
8320 | } | ||
8321 | catch(InvalidCastException) | ||
8322 | { | ||
8323 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 5 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8324 | return new LSL_List(); | ||
8325 | } | ||
8326 | try | ||
8327 | { | ||
8328 | taper_b = rules.GetVector3Item(idx++); | ||
8329 | } | ||
8330 | catch(InvalidCastException) | ||
8331 | { | ||
8332 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8333 | return new LSL_List(); | ||
8334 | } | ||
8335 | try | ||
8336 | { | ||
8337 | topshear = rules.GetVector3Item(idx++); | ||
8338 | } | ||
8339 | catch(InvalidCastException) | ||
8340 | { | ||
8341 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8342 | return new LSL_List(); | ||
8343 | } | ||
7401 | 8344 | ||
7402 | SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, | 8345 | SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, |
7403 | (byte)ProfileShape.Square, (byte)Extrusion.Straight); | 8346 | (byte)ProfileShape.Square, (byte)Extrusion.Straight); |
7404 | break; | 8347 | break; |
7405 | 8348 | ||
7406 | case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER: | 8349 | case ScriptBaseClass.PRIM_TYPE_CYLINDER: |
7407 | if (remain < 6) | 8350 | if (remain < 6) |
7408 | return null; | 8351 | return new LSL_List(); |
7409 | 8352 | ||
7410 | face = (int)rules.GetLSLIntegerItem(idx++); // holeshape | 8353 | try |
7411 | v = rules.GetVector3Item(idx++); // cut | 8354 | { |
7412 | hollow = (float)rules.GetLSLFloatItem(idx++); | 8355 | face = (int)rules.GetLSLIntegerItem(idx++); // holeshape |
7413 | twist = rules.GetVector3Item(idx++); | 8356 | } |
7414 | taper_b = rules.GetVector3Item(idx++); | 8357 | catch(InvalidCastException) |
7415 | topshear = rules.GetVector3Item(idx++); | 8358 | { |
8359 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1)); | ||
8360 | return new LSL_List(); | ||
8361 | } | ||
8362 | try | ||
8363 | { | ||
8364 | v = rules.GetVector3Item(idx++); // cut | ||
8365 | } | ||
8366 | catch(InvalidCastException) | ||
8367 | { | ||
8368 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8369 | return new LSL_List(); | ||
8370 | } | ||
8371 | try | ||
8372 | { | ||
8373 | hollow = (float)rules.GetLSLFloatItem(idx++); | ||
8374 | } | ||
8375 | catch(InvalidCastException) | ||
8376 | { | ||
8377 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1)); | ||
8378 | return new LSL_List(); | ||
8379 | } | ||
8380 | try | ||
8381 | { | ||
8382 | twist = rules.GetVector3Item(idx++); | ||
8383 | } | ||
8384 | catch(InvalidCastException) | ||
8385 | { | ||
8386 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8387 | return new LSL_List(); | ||
8388 | } | ||
8389 | try | ||
8390 | { | ||
8391 | taper_b = rules.GetVector3Item(idx++); | ||
8392 | } | ||
8393 | catch(InvalidCastException) | ||
8394 | { | ||
8395 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8396 | return new LSL_List(); | ||
8397 | } | ||
8398 | try | ||
8399 | { | ||
8400 | topshear = rules.GetVector3Item(idx++); | ||
8401 | } | ||
8402 | catch(InvalidCastException) | ||
8403 | { | ||
8404 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8405 | return new LSL_List(); | ||
8406 | } | ||
7416 | SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, | 8407 | SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, |
7417 | (byte)ProfileShape.Circle, (byte)Extrusion.Straight); | 8408 | (byte)ProfileShape.Circle, (byte)Extrusion.Straight); |
7418 | break; | 8409 | break; |
7419 | 8410 | ||
7420 | case (int)ScriptBaseClass.PRIM_TYPE_PRISM: | 8411 | case ScriptBaseClass.PRIM_TYPE_PRISM: |
7421 | if (remain < 6) | 8412 | if (remain < 6) |
7422 | return null; | 8413 | return new LSL_List(); |
7423 | 8414 | ||
7424 | face = (int)rules.GetLSLIntegerItem(idx++); // holeshape | 8415 | try |
7425 | v = rules.GetVector3Item(idx++); //cut | 8416 | { |
7426 | hollow = (float)rules.GetLSLFloatItem(idx++); | 8417 | face = (int)rules.GetLSLIntegerItem(idx++); // holeshape |
7427 | twist = rules.GetVector3Item(idx++); | 8418 | } |
7428 | taper_b = rules.GetVector3Item(idx++); | 8419 | catch(InvalidCastException) |
7429 | topshear = rules.GetVector3Item(idx++); | 8420 | { |
8421 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1)); | ||
8422 | return new LSL_List(); | ||
8423 | } | ||
8424 | try | ||
8425 | { | ||
8426 | v = rules.GetVector3Item(idx++); //cut | ||
8427 | } | ||
8428 | catch(InvalidCastException) | ||
8429 | { | ||
8430 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8431 | return new LSL_List(); | ||
8432 | } | ||
8433 | try | ||
8434 | { | ||
8435 | hollow = (float)rules.GetLSLFloatItem(idx++); | ||
8436 | } | ||
8437 | catch(InvalidCastException) | ||
8438 | { | ||
8439 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1)); | ||
8440 | return new LSL_List(); | ||
8441 | } | ||
8442 | try | ||
8443 | { | ||
8444 | twist = rules.GetVector3Item(idx++); | ||
8445 | } | ||
8446 | catch(InvalidCastException) | ||
8447 | { | ||
8448 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8449 | return new LSL_List(); | ||
8450 | } | ||
8451 | try | ||
8452 | { | ||
8453 | taper_b = rules.GetVector3Item(idx++); | ||
8454 | } | ||
8455 | catch(InvalidCastException) | ||
8456 | { | ||
8457 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8458 | return new LSL_List(); | ||
8459 | } | ||
8460 | try | ||
8461 | { | ||
8462 | topshear = rules.GetVector3Item(idx++); | ||
8463 | } | ||
8464 | catch(InvalidCastException) | ||
8465 | { | ||
8466 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8467 | return new LSL_List(); | ||
8468 | } | ||
7430 | SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, | 8469 | SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, |
7431 | (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Straight); | 8470 | (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Straight); |
7432 | break; | 8471 | break; |
7433 | 8472 | ||
7434 | case (int)ScriptBaseClass.PRIM_TYPE_SPHERE: | 8473 | case ScriptBaseClass.PRIM_TYPE_SPHERE: |
7435 | if (remain < 5) | 8474 | if (remain < 5) |
7436 | return null; | 8475 | return new LSL_List(); |
7437 | 8476 | ||
7438 | face = (int)rules.GetLSLIntegerItem(idx++); // holeshape | 8477 | try |
7439 | v = rules.GetVector3Item(idx++); // cut | 8478 | { |
7440 | hollow = (float)rules.GetLSLFloatItem(idx++); | 8479 | face = (int)rules.GetLSLIntegerItem(idx++); // holeshape |
7441 | twist = rules.GetVector3Item(idx++); | 8480 | } |
7442 | taper_b = rules.GetVector3Item(idx++); // dimple | 8481 | catch(InvalidCastException) |
8482 | { | ||
8483 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1)); | ||
8484 | return new LSL_List(); | ||
8485 | } | ||
8486 | try | ||
8487 | { | ||
8488 | v = rules.GetVector3Item(idx++); // cut | ||
8489 | } | ||
8490 | catch(InvalidCastException) | ||
8491 | { | ||
8492 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8493 | return new LSL_List(); | ||
8494 | } | ||
8495 | try | ||
8496 | { | ||
8497 | hollow = (float)rules.GetLSLFloatItem(idx++); | ||
8498 | } | ||
8499 | catch(InvalidCastException) | ||
8500 | { | ||
8501 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1)); | ||
8502 | return new LSL_List(); | ||
8503 | } | ||
8504 | try | ||
8505 | { | ||
8506 | twist = rules.GetVector3Item(idx++); | ||
8507 | } | ||
8508 | catch(InvalidCastException) | ||
8509 | { | ||
8510 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8511 | return new LSL_List(); | ||
8512 | } | ||
8513 | try | ||
8514 | { | ||
8515 | taper_b = rules.GetVector3Item(idx++); // dimple | ||
8516 | } | ||
8517 | catch(InvalidCastException) | ||
8518 | { | ||
8519 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8520 | return new LSL_List(); | ||
8521 | } | ||
7443 | SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, | 8522 | SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, |
7444 | (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1); | 8523 | (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1); |
7445 | break; | 8524 | break; |
7446 | 8525 | ||
7447 | case (int)ScriptBaseClass.PRIM_TYPE_TORUS: | 8526 | case ScriptBaseClass.PRIM_TYPE_TORUS: |
7448 | if (remain < 11) | 8527 | if (remain < 11) |
7449 | return null; | 8528 | return new LSL_List(); |
7450 | 8529 | ||
7451 | face = (int)rules.GetLSLIntegerItem(idx++); // holeshape | 8530 | try |
7452 | v = rules.GetVector3Item(idx++); //cut | 8531 | { |
7453 | hollow = (float)rules.GetLSLFloatItem(idx++); | 8532 | face = (int)rules.GetLSLIntegerItem(idx++); // holeshape |
7454 | twist = rules.GetVector3Item(idx++); | 8533 | } |
7455 | holesize = rules.GetVector3Item(idx++); | 8534 | catch(InvalidCastException) |
7456 | topshear = rules.GetVector3Item(idx++); | 8535 | { |
7457 | profilecut = rules.GetVector3Item(idx++); | 8536 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1)); |
7458 | taper_b = rules.GetVector3Item(idx++); // taper_a | 8537 | return new LSL_List(); |
7459 | revolutions = (float)rules.GetLSLFloatItem(idx++); | 8538 | } |
7460 | radiusoffset = (float)rules.GetLSLFloatItem(idx++); | 8539 | try |
7461 | skew = (float)rules.GetLSLFloatItem(idx++); | 8540 | { |
8541 | v = rules.GetVector3Item(idx++); //cut | ||
8542 | } | ||
8543 | catch(InvalidCastException) | ||
8544 | { | ||
8545 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8546 | return new LSL_List(); | ||
8547 | } | ||
8548 | try | ||
8549 | { | ||
8550 | hollow = (float)rules.GetLSLFloatItem(idx++); | ||
8551 | } | ||
8552 | catch(InvalidCastException) | ||
8553 | { | ||
8554 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1)); | ||
8555 | return new LSL_List(); | ||
8556 | } | ||
8557 | try | ||
8558 | { | ||
8559 | twist = rules.GetVector3Item(idx++); | ||
8560 | } | ||
8561 | catch(InvalidCastException) | ||
8562 | { | ||
8563 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8564 | return new LSL_List(); | ||
8565 | } | ||
8566 | try | ||
8567 | { | ||
8568 | holesize = rules.GetVector3Item(idx++); | ||
8569 | } | ||
8570 | catch(InvalidCastException) | ||
8571 | { | ||
8572 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8573 | return new LSL_List(); | ||
8574 | } | ||
8575 | try | ||
8576 | { | ||
8577 | topshear = rules.GetVector3Item(idx++); | ||
8578 | } | ||
8579 | catch(InvalidCastException) | ||
8580 | { | ||
8581 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8582 | return new LSL_List(); | ||
8583 | } | ||
8584 | try | ||
8585 | { | ||
8586 | profilecut = rules.GetVector3Item(idx++); | ||
8587 | } | ||
8588 | catch(InvalidCastException) | ||
8589 | { | ||
8590 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8591 | return new LSL_List(); | ||
8592 | } | ||
8593 | try | ||
8594 | { | ||
8595 | taper_b = rules.GetVector3Item(idx++); // taper_a | ||
8596 | } | ||
8597 | catch(InvalidCastException) | ||
8598 | { | ||
8599 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8600 | return new LSL_List(); | ||
8601 | } | ||
8602 | try | ||
8603 | { | ||
8604 | revolutions = (float)rules.GetLSLFloatItem(idx++); | ||
8605 | } | ||
8606 | catch(InvalidCastException) | ||
8607 | { | ||
8608 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1)); | ||
8609 | return new LSL_List(); | ||
8610 | } | ||
8611 | try | ||
8612 | { | ||
8613 | radiusoffset = (float)rules.GetLSLFloatItem(idx++); | ||
8614 | } | ||
8615 | catch(InvalidCastException) | ||
8616 | { | ||
8617 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1)); | ||
8618 | return new LSL_List(); | ||
8619 | } | ||
8620 | try | ||
8621 | { | ||
8622 | skew = (float)rules.GetLSLFloatItem(idx++); | ||
8623 | } | ||
8624 | catch(InvalidCastException) | ||
8625 | { | ||
8626 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 13 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8627 | return new LSL_List(); | ||
8628 | } | ||
7462 | SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b, | 8629 | SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b, |
7463 | revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1); | 8630 | revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1); |
7464 | break; | 8631 | break; |
7465 | 8632 | ||
7466 | case (int)ScriptBaseClass.PRIM_TYPE_TUBE: | 8633 | case ScriptBaseClass.PRIM_TYPE_TUBE: |
7467 | if (remain < 11) | 8634 | if (remain < 11) |
7468 | return null; | 8635 | return new LSL_List(); |
7469 | 8636 | ||
7470 | face = (int)rules.GetLSLIntegerItem(idx++); // holeshape | 8637 | try |
7471 | v = rules.GetVector3Item(idx++); //cut | 8638 | { |
7472 | hollow = (float)rules.GetLSLFloatItem(idx++); | 8639 | face = (int)rules.GetLSLIntegerItem(idx++); // holeshape |
7473 | twist = rules.GetVector3Item(idx++); | 8640 | } |
7474 | holesize = rules.GetVector3Item(idx++); | 8641 | catch(InvalidCastException) |
7475 | topshear = rules.GetVector3Item(idx++); | 8642 | { |
7476 | profilecut = rules.GetVector3Item(idx++); | 8643 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1)); |
7477 | taper_b = rules.GetVector3Item(idx++); // taper_a | 8644 | return new LSL_List(); |
7478 | revolutions = (float)rules.GetLSLFloatItem(idx++); | 8645 | } |
7479 | radiusoffset = (float)rules.GetLSLFloatItem(idx++); | 8646 | try |
7480 | skew = (float)rules.GetLSLFloatItem(idx++); | 8647 | { |
8648 | v = rules.GetVector3Item(idx++); //cut | ||
8649 | } | ||
8650 | catch(InvalidCastException) | ||
8651 | { | ||
8652 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8653 | return new LSL_List(); | ||
8654 | } | ||
8655 | try | ||
8656 | { | ||
8657 | hollow = (float)rules.GetLSLFloatItem(idx++); | ||
8658 | } | ||
8659 | catch(InvalidCastException) | ||
8660 | { | ||
8661 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1)); | ||
8662 | return new LSL_List(); | ||
8663 | } | ||
8664 | try | ||
8665 | { | ||
8666 | twist = rules.GetVector3Item(idx++); | ||
8667 | } | ||
8668 | catch(InvalidCastException) | ||
8669 | { | ||
8670 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8671 | return new LSL_List(); | ||
8672 | } | ||
8673 | try | ||
8674 | { | ||
8675 | holesize = rules.GetVector3Item(idx++); | ||
8676 | } | ||
8677 | catch(InvalidCastException) | ||
8678 | { | ||
8679 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8680 | return new LSL_List(); | ||
8681 | } | ||
8682 | try | ||
8683 | { | ||
8684 | topshear = rules.GetVector3Item(idx++); | ||
8685 | } | ||
8686 | catch(InvalidCastException) | ||
8687 | { | ||
8688 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8689 | return new LSL_List(); | ||
8690 | } | ||
8691 | try | ||
8692 | { | ||
8693 | profilecut = rules.GetVector3Item(idx++); | ||
8694 | } | ||
8695 | catch(InvalidCastException) | ||
8696 | { | ||
8697 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8698 | return new LSL_List(); | ||
8699 | } | ||
8700 | try | ||
8701 | { | ||
8702 | taper_b = rules.GetVector3Item(idx++); // taper_a | ||
8703 | } | ||
8704 | catch(InvalidCastException) | ||
8705 | { | ||
8706 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8707 | return new LSL_List(); | ||
8708 | } | ||
8709 | try | ||
8710 | { | ||
8711 | revolutions = (float)rules.GetLSLFloatItem(idx++); | ||
8712 | } | ||
8713 | catch(InvalidCastException) | ||
8714 | { | ||
8715 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1)); | ||
8716 | return new LSL_List(); | ||
8717 | } | ||
8718 | try | ||
8719 | { | ||
8720 | radiusoffset = (float)rules.GetLSLFloatItem(idx++); | ||
8721 | } | ||
8722 | catch(InvalidCastException) | ||
8723 | { | ||
8724 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1)); | ||
8725 | return new LSL_List(); | ||
8726 | } | ||
8727 | try | ||
8728 | { | ||
8729 | skew = (float)rules.GetLSLFloatItem(idx++); | ||
8730 | } | ||
8731 | catch(InvalidCastException) | ||
8732 | { | ||
8733 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1)); | ||
8734 | return new LSL_List(); | ||
8735 | } | ||
7481 | SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b, | 8736 | SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b, |
7482 | revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1); | 8737 | revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1); |
7483 | break; | 8738 | break; |
7484 | 8739 | ||
7485 | case (int)ScriptBaseClass.PRIM_TYPE_RING: | 8740 | case ScriptBaseClass.PRIM_TYPE_RING: |
7486 | if (remain < 11) | 8741 | if (remain < 11) |
7487 | return null; | 8742 | return new LSL_List(); |
7488 | 8743 | ||
7489 | face = (int)rules.GetLSLIntegerItem(idx++); // holeshape | 8744 | try |
7490 | v = rules.GetVector3Item(idx++); //cut | 8745 | { |
7491 | hollow = (float)rules.GetLSLFloatItem(idx++); | 8746 | face = (int)rules.GetLSLIntegerItem(idx++); // holeshape |
7492 | twist = rules.GetVector3Item(idx++); | 8747 | } |
7493 | holesize = rules.GetVector3Item(idx++); | 8748 | catch(InvalidCastException) |
7494 | topshear = rules.GetVector3Item(idx++); | 8749 | { |
7495 | profilecut = rules.GetVector3Item(idx++); | 8750 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1)); |
7496 | taper_b = rules.GetVector3Item(idx++); // taper_a | 8751 | return new LSL_List(); |
7497 | revolutions = (float)rules.GetLSLFloatItem(idx++); | 8752 | } |
7498 | radiusoffset = (float)rules.GetLSLFloatItem(idx++); | 8753 | try |
7499 | skew = (float)rules.GetLSLFloatItem(idx++); | 8754 | { |
8755 | v = rules.GetVector3Item(idx++); //cut | ||
8756 | } | ||
8757 | catch(InvalidCastException) | ||
8758 | { | ||
8759 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8760 | return new LSL_List(); | ||
8761 | } | ||
8762 | try | ||
8763 | { | ||
8764 | hollow = (float)rules.GetLSLFloatItem(idx++); | ||
8765 | } | ||
8766 | catch(InvalidCastException) | ||
8767 | { | ||
8768 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1)); | ||
8769 | return new LSL_List(); | ||
8770 | } | ||
8771 | try | ||
8772 | { | ||
8773 | twist = rules.GetVector3Item(idx++); | ||
8774 | } | ||
8775 | catch(InvalidCastException) | ||
8776 | { | ||
8777 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8778 | return new LSL_List(); | ||
8779 | } | ||
8780 | try | ||
8781 | { | ||
8782 | holesize = rules.GetVector3Item(idx++); | ||
8783 | } | ||
8784 | catch(InvalidCastException) | ||
8785 | { | ||
8786 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8787 | return new LSL_List(); | ||
8788 | } | ||
8789 | try | ||
8790 | { | ||
8791 | topshear = rules.GetVector3Item(idx++); | ||
8792 | } | ||
8793 | catch(InvalidCastException) | ||
8794 | { | ||
8795 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8796 | return new LSL_List(); | ||
8797 | } | ||
8798 | try | ||
8799 | { | ||
8800 | profilecut = rules.GetVector3Item(idx++); | ||
8801 | } | ||
8802 | catch(InvalidCastException) | ||
8803 | { | ||
8804 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8805 | return new LSL_List(); | ||
8806 | } | ||
8807 | try | ||
8808 | { | ||
8809 | taper_b = rules.GetVector3Item(idx++); // taper_a | ||
8810 | } | ||
8811 | catch(InvalidCastException) | ||
8812 | { | ||
8813 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8814 | return new LSL_List(); | ||
8815 | } | ||
8816 | try | ||
8817 | { | ||
8818 | revolutions = (float)rules.GetLSLFloatItem(idx++); | ||
8819 | } | ||
8820 | catch(InvalidCastException) | ||
8821 | { | ||
8822 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1)); | ||
8823 | return new LSL_List(); | ||
8824 | } | ||
8825 | try | ||
8826 | { | ||
8827 | radiusoffset = (float)rules.GetLSLFloatItem(idx++); | ||
8828 | } | ||
8829 | catch(InvalidCastException) | ||
8830 | { | ||
8831 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1)); | ||
8832 | return new LSL_List(); | ||
8833 | } | ||
8834 | try | ||
8835 | { | ||
8836 | skew = (float)rules.GetLSLFloatItem(idx++); | ||
8837 | } | ||
8838 | catch(InvalidCastException) | ||
8839 | { | ||
8840 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1)); | ||
8841 | return new LSL_List(); | ||
8842 | } | ||
7500 | SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b, | 8843 | SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b, |
7501 | revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1); | 8844 | revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1); |
7502 | break; | 8845 | break; |
7503 | 8846 | ||
7504 | case (int)ScriptBaseClass.PRIM_TYPE_SCULPT: | 8847 | case ScriptBaseClass.PRIM_TYPE_SCULPT: |
7505 | if (remain < 2) | 8848 | if (remain < 2) |
7506 | return null; | 8849 | return new LSL_List(); |
7507 | 8850 | ||
7508 | string map = rules.Data[idx++].ToString(); | 8851 | string map = rules.Data[idx++].ToString(); |
7509 | face = (int)rules.GetLSLIntegerItem(idx++); // type | 8852 | try |
8853 | { | ||
8854 | face = (int)rules.GetLSLIntegerItem(idx++); // type | ||
8855 | } | ||
8856 | catch(InvalidCastException) | ||
8857 | { | ||
8858 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SCULPT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1)); | ||
8859 | return new LSL_List(); | ||
8860 | } | ||
7510 | SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1); | 8861 | SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1); |
7511 | break; | 8862 | break; |
7512 | } | 8863 | } |
7513 | 8864 | ||
7514 | break; | 8865 | break; |
7515 | 8866 | ||
7516 | case (int)ScriptBaseClass.PRIM_TEXTURE: | 8867 | case ScriptBaseClass.PRIM_TEXTURE: |
7517 | if (remain < 5) | 8868 | if (remain < 5) |
7518 | return null; | 8869 | return new LSL_List(); |
7519 | 8870 | ||
7520 | face=(int)rules.GetLSLIntegerItem(idx++); | 8871 | face=(int)rules.GetLSLIntegerItem(idx++); |
7521 | string tex=rules.Data[idx++].ToString(); | 8872 | string tex; |
7522 | LSL_Vector repeats=rules.GetVector3Item(idx++); | 8873 | LSL_Vector repeats; |
7523 | LSL_Vector offsets=rules.GetVector3Item(idx++); | 8874 | LSL_Vector offsets; |
7524 | double rotation=(double)rules.GetLSLFloatItem(idx++); | 8875 | double rotation; |
8876 | |||
8877 | tex = rules.Data[idx++].ToString(); | ||
8878 | try | ||
8879 | { | ||
8880 | repeats = rules.GetVector3Item(idx++); | ||
8881 | } | ||
8882 | catch(InvalidCastException) | ||
8883 | { | ||
8884 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8885 | return new LSL_List(); | ||
8886 | } | ||
8887 | try | ||
8888 | { | ||
8889 | offsets = rules.GetVector3Item(idx++); | ||
8890 | } | ||
8891 | catch(InvalidCastException) | ||
8892 | { | ||
8893 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8894 | return new LSL_List(); | ||
8895 | } | ||
8896 | try | ||
8897 | { | ||
8898 | rotation = (double)rules.GetLSLFloatItem(idx++); | ||
8899 | } | ||
8900 | catch(InvalidCastException) | ||
8901 | { | ||
8902 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1)); | ||
8903 | return new LSL_List(); | ||
8904 | } | ||
7525 | 8905 | ||
7526 | SetTexture(part, tex, face); | 8906 | SetTexture(part, tex, face); |
7527 | ScaleTexture(part, repeats.x, repeats.y, face); | 8907 | ScaleTexture(part, repeats.x, repeats.y, face); |
@@ -7530,180 +8910,525 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7530 | 8910 | ||
7531 | break; | 8911 | break; |
7532 | 8912 | ||
7533 | case (int)ScriptBaseClass.PRIM_COLOR: | 8913 | case ScriptBaseClass.PRIM_COLOR: |
7534 | if (remain < 3) | 8914 | if (remain < 3) |
7535 | return null; | 8915 | return new LSL_List(); |
7536 | 8916 | ||
7537 | face=(int)rules.GetLSLIntegerItem(idx++); | 8917 | LSL_Vector color; |
7538 | LSL_Vector color=rules.GetVector3Item(idx++); | 8918 | double alpha; |
7539 | double alpha=(double)rules.GetLSLFloatItem(idx++); | 8919 | |
8920 | try | ||
8921 | { | ||
8922 | face = (int)rules.GetLSLIntegerItem(idx++); | ||
8923 | } | ||
8924 | catch(InvalidCastException) | ||
8925 | { | ||
8926 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1)); | ||
8927 | return new LSL_List(); | ||
8928 | } | ||
8929 | try | ||
8930 | { | ||
8931 | color = rules.GetVector3Item(idx++); | ||
8932 | } | ||
8933 | catch(InvalidCastException) | ||
8934 | { | ||
8935 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1)); | ||
8936 | return new LSL_List(); | ||
8937 | } | ||
8938 | try | ||
8939 | { | ||
8940 | alpha = (double)rules.GetLSLFloatItem(idx++); | ||
8941 | } | ||
8942 | catch(InvalidCastException) | ||
8943 | { | ||
8944 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1)); | ||
8945 | return new LSL_List(); | ||
8946 | } | ||
7540 | 8947 | ||
7541 | part.SetFaceColorAlpha(face, color, alpha); | 8948 | part.SetFaceColorAlpha(face, color, alpha); |
7542 | 8949 | ||
7543 | break; | 8950 | break; |
7544 | 8951 | ||
7545 | case (int)ScriptBaseClass.PRIM_FLEXIBLE: | 8952 | case ScriptBaseClass.PRIM_FLEXIBLE: |
7546 | if (remain < 7) | 8953 | if (remain < 7) |
7547 | return null; | 8954 | return new LSL_List(); |
7548 | 8955 | bool flexi; | |
7549 | bool flexi = rules.GetLSLIntegerItem(idx++); | 8956 | int softness; |
7550 | int softness = rules.GetLSLIntegerItem(idx++); | 8957 | float gravity; |
7551 | float gravity = (float)rules.GetLSLFloatItem(idx++); | 8958 | float friction; |
7552 | float friction = (float)rules.GetLSLFloatItem(idx++); | 8959 | float wind; |
7553 | float wind = (float)rules.GetLSLFloatItem(idx++); | 8960 | float tension; |
7554 | float tension = (float)rules.GetLSLFloatItem(idx++); | 8961 | LSL_Vector force; |
7555 | LSL_Vector force = rules.GetVector3Item(idx++); | 8962 | |
8963 | try | ||
8964 | { | ||
8965 | flexi = rules.GetLSLIntegerItem(idx++); | ||
8966 | } | ||
8967 | catch(InvalidCastException) | ||
8968 | { | ||
8969 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1)); | ||
8970 | return new LSL_List(); | ||
8971 | } | ||
8972 | try | ||
8973 | { | ||
8974 | softness = rules.GetLSLIntegerItem(idx++); | ||
8975 | } | ||
8976 | catch(InvalidCastException) | ||
8977 | { | ||
8978 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1)); | ||
8979 | return new LSL_List(); | ||
8980 | } | ||
8981 | try | ||
8982 | { | ||
8983 | gravity = (float)rules.GetLSLFloatItem(idx++); | ||
8984 | } | ||
8985 | catch(InvalidCastException) | ||
8986 | { | ||
8987 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1)); | ||
8988 | return new LSL_List(); | ||
8989 | } | ||
8990 | try | ||
8991 | { | ||
8992 | friction = (float)rules.GetLSLFloatItem(idx++); | ||
8993 | } | ||
8994 | catch(InvalidCastException) | ||
8995 | { | ||
8996 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1)); | ||
8997 | return new LSL_List(); | ||
8998 | } | ||
8999 | try | ||
9000 | { | ||
9001 | wind = (float)rules.GetLSLFloatItem(idx++); | ||
9002 | } | ||
9003 | catch(InvalidCastException) | ||
9004 | { | ||
9005 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1)); | ||
9006 | return new LSL_List(); | ||
9007 | } | ||
9008 | try | ||
9009 | { | ||
9010 | tension = (float)rules.GetLSLFloatItem(idx++); | ||
9011 | } | ||
9012 | catch(InvalidCastException) | ||
9013 | { | ||
9014 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 7 must be float", rulesParsed, idx - idxStart - 1)); | ||
9015 | return new LSL_List(); | ||
9016 | } | ||
9017 | try | ||
9018 | { | ||
9019 | force = rules.GetVector3Item(idx++); | ||
9020 | } | ||
9021 | catch(InvalidCastException) | ||
9022 | { | ||
9023 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1)); | ||
9024 | return new LSL_List(); | ||
9025 | } | ||
7556 | 9026 | ||
7557 | SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force); | 9027 | SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force); |
7558 | 9028 | ||
7559 | break; | 9029 | break; |
7560 | 9030 | ||
7561 | case (int)ScriptBaseClass.PRIM_POINT_LIGHT: | 9031 | case ScriptBaseClass.PRIM_POINT_LIGHT: |
7562 | if (remain < 5) | 9032 | if (remain < 5) |
7563 | return null; | 9033 | return new LSL_List(); |
7564 | bool light = rules.GetLSLIntegerItem(idx++); | 9034 | bool light; |
7565 | LSL_Vector lightcolor = rules.GetVector3Item(idx++); | 9035 | LSL_Vector lightcolor; |
7566 | float intensity = (float)rules.GetLSLFloatItem(idx++); | 9036 | float intensity; |
7567 | float radius = (float)rules.GetLSLFloatItem(idx++); | 9037 | float radius; |
7568 | float falloff = (float)rules.GetLSLFloatItem(idx++); | 9038 | float falloff; |
9039 | |||
9040 | try | ||
9041 | { | ||
9042 | light = rules.GetLSLIntegerItem(idx++); | ||
9043 | } | ||
9044 | catch(InvalidCastException) | ||
9045 | { | ||
9046 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1)); | ||
9047 | return new LSL_List(); | ||
9048 | } | ||
9049 | try | ||
9050 | { | ||
9051 | lightcolor = rules.GetVector3Item(idx++); | ||
9052 | } | ||
9053 | catch(InvalidCastException) | ||
9054 | { | ||
9055 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1)); | ||
9056 | return new LSL_List(); | ||
9057 | } | ||
9058 | try | ||
9059 | { | ||
9060 | intensity = (float)rules.GetLSLFloatItem(idx++); | ||
9061 | } | ||
9062 | catch(InvalidCastException) | ||
9063 | { | ||
9064 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1)); | ||
9065 | return new LSL_List(); | ||
9066 | } | ||
9067 | try | ||
9068 | { | ||
9069 | radius = (float)rules.GetLSLFloatItem(idx++); | ||
9070 | } | ||
9071 | catch(InvalidCastException) | ||
9072 | { | ||
9073 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1)); | ||
9074 | return new LSL_List(); | ||
9075 | } | ||
9076 | try | ||
9077 | { | ||
9078 | falloff = (float)rules.GetLSLFloatItem(idx++); | ||
9079 | } | ||
9080 | catch(InvalidCastException) | ||
9081 | { | ||
9082 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1)); | ||
9083 | return new LSL_List(); | ||
9084 | } | ||
7569 | 9085 | ||
7570 | SetPointLight(part, light, lightcolor, intensity, radius, falloff); | 9086 | SetPointLight(part, light, lightcolor, intensity, radius, falloff); |
7571 | 9087 | ||
7572 | break; | 9088 | break; |
7573 | 9089 | ||
7574 | case (int)ScriptBaseClass.PRIM_GLOW: | 9090 | case ScriptBaseClass.PRIM_GLOW: |
7575 | if (remain < 2) | 9091 | if (remain < 2) |
7576 | return null; | 9092 | return new LSL_List(); |
7577 | face = rules.GetLSLIntegerItem(idx++); | 9093 | |
7578 | float glow = (float)rules.GetLSLFloatItem(idx++); | 9094 | float glow; |
9095 | |||
9096 | try | ||
9097 | { | ||
9098 | face = rules.GetLSLIntegerItem(idx++); | ||
9099 | } | ||
9100 | catch(InvalidCastException) | ||
9101 | { | ||
9102 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1)); | ||
9103 | return new LSL_List(); | ||
9104 | } | ||
9105 | try | ||
9106 | { | ||
9107 | glow = (float)rules.GetLSLFloatItem(idx++); | ||
9108 | } | ||
9109 | catch(InvalidCastException) | ||
9110 | { | ||
9111 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1)); | ||
9112 | return new LSL_List(); | ||
9113 | } | ||
7579 | 9114 | ||
7580 | SetGlow(part, face, glow); | 9115 | SetGlow(part, face, glow); |
7581 | 9116 | ||
7582 | break; | 9117 | break; |
7583 | 9118 | ||
7584 | case (int)ScriptBaseClass.PRIM_BUMP_SHINY: | 9119 | case ScriptBaseClass.PRIM_BUMP_SHINY: |
7585 | if (remain < 3) | 9120 | if (remain < 3) |
7586 | return null; | 9121 | return new LSL_List(); |
7587 | face = (int)rules.GetLSLIntegerItem(idx++); | 9122 | |
7588 | int shiny = (int)rules.GetLSLIntegerItem(idx++); | 9123 | int shiny; |
7589 | Bumpiness bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++); | 9124 | Bumpiness bump; |
9125 | |||
9126 | try | ||
9127 | { | ||
9128 | face = (int)rules.GetLSLIntegerItem(idx++); | ||
9129 | } | ||
9130 | catch(InvalidCastException) | ||
9131 | { | ||
9132 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1)); | ||
9133 | return new LSL_List(); | ||
9134 | } | ||
9135 | try | ||
9136 | { | ||
9137 | shiny = (int)rules.GetLSLIntegerItem(idx++); | ||
9138 | } | ||
9139 | catch(InvalidCastException) | ||
9140 | { | ||
9141 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1)); | ||
9142 | return new LSL_List(); | ||
9143 | } | ||
9144 | try | ||
9145 | { | ||
9146 | bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++); | ||
9147 | } | ||
9148 | catch(InvalidCastException) | ||
9149 | { | ||
9150 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1)); | ||
9151 | return new LSL_List(); | ||
9152 | } | ||
7590 | 9153 | ||
7591 | SetShiny(part, face, shiny, bump); | 9154 | SetShiny(part, face, shiny, bump); |
7592 | 9155 | ||
7593 | break; | 9156 | break; |
7594 | 9157 | ||
7595 | case (int)ScriptBaseClass.PRIM_FULLBRIGHT: | 9158 | case ScriptBaseClass.PRIM_FULLBRIGHT: |
7596 | if (remain < 2) | 9159 | if (remain < 2) |
7597 | return null; | 9160 | return new LSL_List(); |
7598 | face = rules.GetLSLIntegerItem(idx++); | 9161 | bool st; |
7599 | bool st = rules.GetLSLIntegerItem(idx++); | 9162 | |
7600 | SetFullBright(part, face , st); | 9163 | try |
7601 | break; | 9164 | { |
9165 | face = rules.GetLSLIntegerItem(idx++); | ||
9166 | } | ||
9167 | catch(InvalidCastException) | ||
9168 | { | ||
9169 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1)); | ||
9170 | return new LSL_List(); | ||
9171 | } | ||
9172 | try | ||
9173 | { | ||
9174 | st = rules.GetLSLIntegerItem(idx++); | ||
9175 | } | ||
9176 | catch(InvalidCastException) | ||
9177 | { | ||
9178 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1)); | ||
9179 | return new LSL_List(); | ||
9180 | } | ||
9181 | SetFullBright(part, face , st); | ||
9182 | break; | ||
9183 | |||
9184 | case ScriptBaseClass.PRIM_MATERIAL: | ||
9185 | if (remain < 1) | ||
9186 | return new LSL_List(); | ||
9187 | int mat; | ||
9188 | |||
9189 | try | ||
9190 | { | ||
9191 | mat = rules.GetLSLIntegerItem(idx++); | ||
9192 | } | ||
9193 | catch(InvalidCastException) | ||
9194 | { | ||
9195 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_MATERIAL: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1)); | ||
9196 | return new LSL_List(); | ||
9197 | } | ||
9198 | if (mat < 0 || mat > 7) | ||
9199 | return new LSL_List(); | ||
7602 | 9200 | ||
7603 | case (int)ScriptBaseClass.PRIM_MATERIAL: | 9201 | part.Material = Convert.ToByte(mat); |
7604 | if (remain < 1) | 9202 | break; |
7605 | return null; | ||
7606 | int mat = rules.GetLSLIntegerItem(idx++); | ||
7607 | if (mat < 0 || mat > 7) | ||
7608 | return null; | ||
7609 | 9203 | ||
7610 | part.Material = Convert.ToByte(mat); | 9204 | case ScriptBaseClass.PRIM_PHANTOM: |
7611 | break; | 9205 | if (remain < 1) |
9206 | return new LSL_List(); | ||
7612 | 9207 | ||
7613 | case (int)ScriptBaseClass.PRIM_PHANTOM: | 9208 | string ph = rules.Data[idx++].ToString(); |
7614 | if (remain < 1) | 9209 | part.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1")); |
7615 | return null; | ||
7616 | 9210 | ||
7617 | string ph = rules.Data[idx++].ToString(); | 9211 | break; |
7618 | m_host.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1")); | ||
7619 | 9212 | ||
7620 | break; | 9213 | case ScriptBaseClass.PRIM_PHYSICS: |
9214 | if (remain < 1) | ||
9215 | return new LSL_List(); | ||
9216 | string phy = rules.Data[idx++].ToString(); | ||
9217 | part.ScriptSetPhysicsStatus(phy.Equals("1")); | ||
9218 | break; | ||
7621 | 9219 | ||
7622 | case (int)ScriptBaseClass.PRIM_PHYSICS: | 9220 | case ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE: |
7623 | if (remain < 1) | 9221 | if (remain < 1) |
7624 | return null; | 9222 | return new LSL_List(); |
7625 | string phy = rules.Data[idx++].ToString(); | ||
7626 | bool physics; | ||
7627 | 9223 | ||
7628 | if (phy.Equals("1")) | 9224 | int shape_type; |
7629 | physics = true; | ||
7630 | else | ||
7631 | physics = false; | ||
7632 | 9225 | ||
7633 | part.ScriptSetPhysicsStatus(physics); | 9226 | try |
7634 | break; | 9227 | { |
9228 | shape_type = rules.GetLSLIntegerItem(idx++); | ||
9229 | } | ||
9230 | catch(InvalidCastException) | ||
9231 | { | ||
9232 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_PHYSICS_SHAPE_TYPE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1)); | ||
9233 | return new LSL_List(); | ||
9234 | } | ||
9235 | |||
9236 | ExtraPhysicsData physdata = new ExtraPhysicsData(); | ||
9237 | physdata.Density = part.Density; | ||
9238 | physdata.Bounce = part.Restitution; | ||
9239 | physdata.GravitationModifier = part.GravityModifier; | ||
9240 | physdata.PhysShapeType = (PhysShapeType)shape_type; | ||
9241 | |||
9242 | part.UpdateExtraPhysics(physdata); | ||
7635 | 9243 | ||
7636 | case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ: | 9244 | break; |
9245 | |||
9246 | case ScriptBaseClass.PRIM_TEMP_ON_REZ: | ||
7637 | if (remain < 1) | 9247 | if (remain < 1) |
7638 | return null; | 9248 | return new LSL_List(); |
7639 | string temp = rules.Data[idx++].ToString(); | 9249 | string temp = rules.Data[idx++].ToString(); |
7640 | 9250 | ||
7641 | m_host.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1")); | 9251 | part.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1")); |
7642 | 9252 | ||
7643 | break; | 9253 | break; |
7644 | 9254 | ||
7645 | case (int)ScriptBaseClass.PRIM_TEXGEN: | 9255 | case ScriptBaseClass.PRIM_TEXGEN: |
7646 | if (remain < 2) | 9256 | if (remain < 2) |
7647 | return null; | 9257 | return new LSL_List(); |
7648 | //face,type | 9258 | //face,type |
7649 | face = rules.GetLSLIntegerItem(idx++); | 9259 | int style; |
7650 | int style = rules.GetLSLIntegerItem(idx++); | 9260 | |
9261 | try | ||
9262 | { | ||
9263 | face = rules.GetLSLIntegerItem(idx++); | ||
9264 | } | ||
9265 | catch(InvalidCastException) | ||
9266 | { | ||
9267 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1)); | ||
9268 | return new LSL_List(); | ||
9269 | } | ||
9270 | try | ||
9271 | { | ||
9272 | style = rules.GetLSLIntegerItem(idx++); | ||
9273 | } | ||
9274 | catch(InvalidCastException) | ||
9275 | { | ||
9276 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1)); | ||
9277 | return new LSL_List(); | ||
9278 | } | ||
7651 | SetTexGen(part, face, style); | 9279 | SetTexGen(part, face, style); |
7652 | break; | 9280 | break; |
7653 | case (int)ScriptBaseClass.PRIM_TEXT: | 9281 | case ScriptBaseClass.PRIM_TEXT: |
7654 | if (remain < 3) | 9282 | if (remain < 3) |
7655 | return null; | 9283 | return new LSL_List(); |
7656 | string primText = rules.GetLSLStringItem(idx++); | 9284 | string primText; |
7657 | LSL_Vector primTextColor = rules.GetVector3Item(idx++); | 9285 | LSL_Vector primTextColor; |
7658 | LSL_Float primTextAlpha = rules.GetLSLFloatItem(idx++); | 9286 | LSL_Float primTextAlpha; |
9287 | |||
9288 | try | ||
9289 | { | ||
9290 | primText = rules.GetLSLStringItem(idx++); | ||
9291 | } | ||
9292 | catch(InvalidCastException) | ||
9293 | { | ||
9294 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1)); | ||
9295 | return new LSL_List(); | ||
9296 | } | ||
9297 | try | ||
9298 | { | ||
9299 | primTextColor = rules.GetVector3Item(idx++); | ||
9300 | } | ||
9301 | catch(InvalidCastException) | ||
9302 | { | ||
9303 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1)); | ||
9304 | return new LSL_List(); | ||
9305 | } | ||
9306 | try | ||
9307 | { | ||
9308 | primTextAlpha = rules.GetLSLFloatItem(idx++); | ||
9309 | } | ||
9310 | catch(InvalidCastException) | ||
9311 | { | ||
9312 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1)); | ||
9313 | return new LSL_List(); | ||
9314 | } | ||
7659 | Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f); | 9315 | Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f); |
7660 | part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f)); | 9316 | part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f)); |
7661 | 9317 | ||
7662 | break; | 9318 | break; |
7663 | case (int)ScriptBaseClass.PRIM_NAME: | 9319 | |
9320 | case ScriptBaseClass.PRIM_NAME: | ||
7664 | if (remain < 1) | 9321 | if (remain < 1) |
7665 | return null; | 9322 | return new LSL_List(); |
7666 | string primName = rules.GetLSLStringItem(idx++); | 9323 | try |
7667 | part.Name = primName; | 9324 | { |
9325 | string primName = rules.GetLSLStringItem(idx++); | ||
9326 | part.Name = primName; | ||
9327 | } | ||
9328 | catch(InvalidCastException) | ||
9329 | { | ||
9330 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NAME: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1)); | ||
9331 | return new LSL_List(); | ||
9332 | } | ||
7668 | break; | 9333 | break; |
7669 | case (int)ScriptBaseClass.PRIM_DESC: | 9334 | case ScriptBaseClass.PRIM_DESC: |
7670 | if (remain < 1) | 9335 | if (remain < 1) |
7671 | return null; | 9336 | return new LSL_List(); |
7672 | string primDesc = rules.GetLSLStringItem(idx++); | 9337 | try |
7673 | part.Description = primDesc; | 9338 | { |
9339 | string primDesc = rules.GetLSLStringItem(idx++); | ||
9340 | part.Description = primDesc; | ||
9341 | } | ||
9342 | catch(InvalidCastException) | ||
9343 | { | ||
9344 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_DESC: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1)); | ||
9345 | return new LSL_List(); | ||
9346 | } | ||
7674 | break; | 9347 | break; |
7675 | case (int)ScriptBaseClass.PRIM_ROT_LOCAL: | 9348 | case ScriptBaseClass.PRIM_ROT_LOCAL: |
7676 | if (remain < 1) | 9349 | if (remain < 1) |
7677 | return null; | 9350 | return new LSL_List(); |
7678 | SetRot(part, rules.GetQuaternionItem(idx++)); | 9351 | LSL_Rotation rot; |
9352 | try | ||
9353 | { | ||
9354 | rot = rules.GetQuaternionItem(idx++); | ||
9355 | } | ||
9356 | catch(InvalidCastException) | ||
9357 | { | ||
9358 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1)); | ||
9359 | return new LSL_List(); | ||
9360 | } | ||
9361 | SetRot(part, rot); | ||
7679 | break; | 9362 | break; |
7680 | case (int)ScriptBaseClass.PRIM_OMEGA: | 9363 | |
9364 | case ScriptBaseClass.PRIM_OMEGA: | ||
7681 | if (remain < 3) | 9365 | if (remain < 3) |
7682 | return null; | 9366 | return new LSL_List(); |
7683 | LSL_Vector axis = rules.GetVector3Item(idx++); | 9367 | LSL_Vector axis; |
7684 | LSL_Float spinrate = rules.GetLSLFloatItem(idx++); | 9368 | LSL_Float spinrate; |
7685 | LSL_Float gain = rules.GetLSLFloatItem(idx++); | 9369 | LSL_Float gain; |
9370 | |||
9371 | try | ||
9372 | { | ||
9373 | axis = rules.GetVector3Item(idx++); | ||
9374 | } | ||
9375 | catch(InvalidCastException) | ||
9376 | { | ||
9377 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1)); | ||
9378 | return new LSL_List(); | ||
9379 | } | ||
9380 | try | ||
9381 | { | ||
9382 | spinrate = rules.GetLSLFloatItem(idx++); | ||
9383 | } | ||
9384 | catch(InvalidCastException) | ||
9385 | { | ||
9386 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1)); | ||
9387 | return new LSL_List(); | ||
9388 | } | ||
9389 | try | ||
9390 | { | ||
9391 | gain = rules.GetLSLFloatItem(idx++); | ||
9392 | } | ||
9393 | catch(InvalidCastException) | ||
9394 | { | ||
9395 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1)); | ||
9396 | return new LSL_List(); | ||
9397 | } | ||
7686 | TargetOmega(part, axis, (double)spinrate, (double)gain); | 9398 | TargetOmega(part, axis, (double)spinrate, (double)gain); |
7687 | break; | 9399 | break; |
7688 | case (int)ScriptBaseClass.PRIM_SLICE: | 9400 | |
9401 | case ScriptBaseClass.PRIM_SLICE: | ||
7689 | if (remain < 1) | 9402 | if (remain < 1) |
7690 | return null; | 9403 | return new LSL_List(); |
7691 | LSL_Vector slice = rules.GetVector3Item(idx++); | 9404 | LSL_Vector slice; |
9405 | try | ||
9406 | { | ||
9407 | slice = rules.GetVector3Item(idx++); | ||
9408 | } | ||
9409 | catch(InvalidCastException) | ||
9410 | { | ||
9411 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SLICE: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1)); | ||
9412 | return new LSL_List(); | ||
9413 | } | ||
7692 | part.UpdateSlice((float)slice.x, (float)slice.y); | 9414 | part.UpdateSlice((float)slice.x, (float)slice.y); |
7693 | break; | 9415 | break; |
7694 | case (int)ScriptBaseClass.PRIM_LINK_TARGET: | 9416 | |
9417 | case ScriptBaseClass.PRIM_LINK_TARGET: | ||
7695 | if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless. | 9418 | if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless. |
7696 | return null; | 9419 | return new LSL_List(); |
7697 | 9420 | ||
7698 | return rules.GetSublist(idx, -1); | 9421 | return rules.GetSublist(idx, -1); |
9422 | |||
9423 | default: | ||
9424 | Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - unsupported parameter", rulesParsed, idx - idxStart)); | ||
9425 | return new LSL_List(); | ||
7699 | } | 9426 | } |
7700 | } | 9427 | } |
7701 | } | 9428 | } |
7702 | catch (InvalidCastException e) | 9429 | catch (InvalidCastException e) |
7703 | { | 9430 | { |
7704 | ShoutError(string.Format( | 9431 | Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message); |
7705 | "{0} error running rule #{1}: arg #{2} ", | ||
7706 | originFunc, rulesParsed, idx - idxStart) + e.Message); | ||
7707 | } | 9432 | } |
7708 | finally | 9433 | finally |
7709 | { | 9434 | { |
@@ -7723,7 +9448,118 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7723 | } | 9448 | } |
7724 | } | 9449 | } |
7725 | } | 9450 | } |
7726 | return null; | 9451 | |
9452 | return new LSL_List(); | ||
9453 | } | ||
9454 | |||
9455 | protected LSL_List SetAgentParams(ScenePresence sp, LSL_List rules, string originFunc, ref uint rulesParsed) | ||
9456 | { | ||
9457 | int idx = 0; | ||
9458 | int idxStart = 0; | ||
9459 | |||
9460 | try | ||
9461 | { | ||
9462 | while (idx < rules.Length) | ||
9463 | { | ||
9464 | ++rulesParsed; | ||
9465 | int code = rules.GetLSLIntegerItem(idx++); | ||
9466 | |||
9467 | int remain = rules.Length - idx; | ||
9468 | idxStart = idx; | ||
9469 | |||
9470 | switch (code) | ||
9471 | { | ||
9472 | case ScriptBaseClass.PRIM_POSITION: | ||
9473 | case ScriptBaseClass.PRIM_POS_LOCAL: | ||
9474 | if (remain < 1) | ||
9475 | return new LSL_List(); | ||
9476 | |||
9477 | try | ||
9478 | { | ||
9479 | sp.OffsetPosition = rules.GetVector3Item(idx++); | ||
9480 | } | ||
9481 | catch(InvalidCastException) | ||
9482 | { | ||
9483 | if (code == ScriptBaseClass.PRIM_POSITION) | ||
9484 | { | ||
9485 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1)); | ||
9486 | } | ||
9487 | else | ||
9488 | { | ||
9489 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1)); | ||
9490 | } | ||
9491 | return new LSL_List(); | ||
9492 | } | ||
9493 | break; | ||
9494 | |||
9495 | case ScriptBaseClass.PRIM_ROTATION: | ||
9496 | if (remain < 1) | ||
9497 | return new LSL_List(); | ||
9498 | |||
9499 | Quaternion inRot; | ||
9500 | |||
9501 | try | ||
9502 | { | ||
9503 | inRot = rules.GetQuaternionItem(idx++); | ||
9504 | } | ||
9505 | catch(InvalidCastException) | ||
9506 | { | ||
9507 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1)); | ||
9508 | return new LSL_List(); | ||
9509 | } | ||
9510 | |||
9511 | SceneObjectPart parentPart = sp.ParentPart; | ||
9512 | |||
9513 | if (parentPart != null) | ||
9514 | sp.Rotation = m_host.GetWorldRotation() * inRot; | ||
9515 | |||
9516 | break; | ||
9517 | |||
9518 | case ScriptBaseClass.PRIM_ROT_LOCAL: | ||
9519 | if (remain < 1) | ||
9520 | return new LSL_List(); | ||
9521 | |||
9522 | try | ||
9523 | { | ||
9524 | sp.Rotation = rules.GetQuaternionItem(idx++); | ||
9525 | } | ||
9526 | catch(InvalidCastException) | ||
9527 | { | ||
9528 | Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1)); | ||
9529 | return new LSL_List(); | ||
9530 | } | ||
9531 | |||
9532 | break; | ||
9533 | |||
9534 | case ScriptBaseClass.PRIM_TYPE: | ||
9535 | Error(originFunc, "PRIM_TYPE disallowed on agent"); | ||
9536 | return new LSL_List(); | ||
9537 | |||
9538 | case ScriptBaseClass.PRIM_OMEGA: | ||
9539 | Error(originFunc, "PRIM_OMEGA disallowed on agent"); | ||
9540 | return new LSL_List(); | ||
9541 | |||
9542 | case ScriptBaseClass.PRIM_LINK_TARGET: | ||
9543 | if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless. | ||
9544 | return new LSL_List(); | ||
9545 | |||
9546 | return rules.GetSublist(idx, -1); | ||
9547 | |||
9548 | default: | ||
9549 | Error(originFunc, | ||
9550 | string.Format("Error running rule #{0} on agent: arg #{1} - disallowed on agent", rulesParsed, idx - idxStart)); | ||
9551 | return new LSL_List(); | ||
9552 | } | ||
9553 | } | ||
9554 | } | ||
9555 | catch (InvalidCastException e) | ||
9556 | { | ||
9557 | Error( | ||
9558 | originFunc, | ||
9559 | string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message); | ||
9560 | } | ||
9561 | |||
9562 | return new LSL_List(); | ||
7727 | } | 9563 | } |
7728 | 9564 | ||
7729 | public LSL_String llStringToBase64(string str) | 9565 | public LSL_String llStringToBase64(string str) |
@@ -7731,14 +9567,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7731 | m_host.AddScriptLPS(1); | 9567 | m_host.AddScriptLPS(1); |
7732 | try | 9568 | try |
7733 | { | 9569 | { |
7734 | byte[] encData_byte = new byte[str.Length]; | 9570 | byte[] encData_byte; |
7735 | encData_byte = Util.UTF8.GetBytes(str); | 9571 | encData_byte = Util.UTF8.GetBytes(str); |
7736 | string encodedData = Convert.ToBase64String(encData_byte); | 9572 | string encodedData = Convert.ToBase64String(encData_byte); |
7737 | return encodedData; | 9573 | return encodedData; |
7738 | } | 9574 | } |
7739 | catch (Exception e) | 9575 | catch |
7740 | { | 9576 | { |
7741 | throw new Exception("Error in base64Encode" + e.Message); | 9577 | Error("llBase64ToString", "Error encoding string"); |
9578 | return String.Empty; | ||
7742 | } | 9579 | } |
7743 | } | 9580 | } |
7744 | 9581 | ||
@@ -7747,26 +9584,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7747 | m_host.AddScriptLPS(1); | 9584 | m_host.AddScriptLPS(1); |
7748 | try | 9585 | try |
7749 | { | 9586 | { |
7750 | return Util.Base64ToString(str); | 9587 | byte[] b = Convert.FromBase64String(str); |
9588 | return Encoding.UTF8.GetString(b); | ||
7751 | } | 9589 | } |
7752 | catch (Exception e) | 9590 | catch |
7753 | { | 9591 | { |
7754 | throw new Exception("Error in base64Decode" + e.Message); | 9592 | Error("llBase64ToString", "Error decoding string"); |
9593 | return String.Empty; | ||
7755 | } | 9594 | } |
7756 | } | 9595 | } |
7757 | 9596 | ||
7758 | public LSL_String llXorBase64Strings(string str1, string str2) | 9597 | public LSL_String llXorBase64Strings(string str1, string str2) |
7759 | { | 9598 | { |
7760 | m_host.AddScriptLPS(1); | 9599 | m_host.AddScriptLPS(1); |
7761 | Deprecated("llXorBase64Strings"); | 9600 | Deprecated("llXorBase64Strings", "Use llXorBase64 instead"); |
7762 | ScriptSleep(300); | 9601 | ScriptSleep(m_sleepMsOnXorBase64Strings); |
7763 | return String.Empty; | 9602 | return String.Empty; |
7764 | } | 9603 | } |
7765 | 9604 | ||
7766 | public void llRemoteDataSetRegion() | 9605 | public void llRemoteDataSetRegion() |
7767 | { | 9606 | { |
7768 | m_host.AddScriptLPS(1); | 9607 | m_host.AddScriptLPS(1); |
7769 | Deprecated("llRemoteDataSetRegion"); | 9608 | Deprecated("llRemoteDataSetRegion", "Use llOpenRemoteDataChannel instead"); |
7770 | } | 9609 | } |
7771 | 9610 | ||
7772 | public LSL_Float llLog10(double val) | 9611 | public LSL_Float llLog10(double val) |
@@ -7800,21 +9639,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7800 | { | 9639 | { |
7801 | m_host.AddScriptLPS(1); | 9640 | m_host.AddScriptLPS(1); |
7802 | 9641 | ||
7803 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); | 9642 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); |
7804 | 9643 | ||
7805 | if (land.LandData.OwnerID != m_host.OwnerID) | 9644 | if (land.LandData.OwnerID != m_host.OwnerID) |
7806 | return; | 9645 | return; |
7807 | 9646 | ||
7808 | land.SetMusicUrl(url); | 9647 | land.SetMusicUrl(url); |
7809 | 9648 | ||
7810 | ScriptSleep(2000); | 9649 | ScriptSleep(m_sleepMsOnSetParcelMusicURL); |
7811 | } | 9650 | } |
7812 | 9651 | ||
7813 | public LSL_String llGetParcelMusicURL() | 9652 | public LSL_String llGetParcelMusicURL() |
7814 | { | 9653 | { |
7815 | m_host.AddScriptLPS(1); | 9654 | m_host.AddScriptLPS(1); |
7816 | 9655 | ||
7817 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); | 9656 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); |
7818 | 9657 | ||
7819 | if (land.LandData.OwnerID != m_host.OwnerID) | 9658 | if (land.LandData.OwnerID != m_host.OwnerID) |
7820 | return String.Empty; | 9659 | return String.Empty; |
@@ -7825,8 +9664,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7825 | public LSL_Vector llGetRootPosition() | 9664 | public LSL_Vector llGetRootPosition() |
7826 | { | 9665 | { |
7827 | m_host.AddScriptLPS(1); | 9666 | m_host.AddScriptLPS(1); |
7828 | return new LSL_Vector(m_host.ParentGroup.AbsolutePosition.X, m_host.ParentGroup.AbsolutePosition.Y, | 9667 | |
7829 | m_host.ParentGroup.AbsolutePosition.Z); | 9668 | return new LSL_Vector(m_host.ParentGroup.AbsolutePosition); |
7830 | } | 9669 | } |
7831 | 9670 | ||
7832 | /// <summary> | 9671 | /// <summary> |
@@ -7849,13 +9688,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7849 | if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0) | 9688 | if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0) |
7850 | q = avatar.CameraRotation; // Mouselook | 9689 | q = avatar.CameraRotation; // Mouselook |
7851 | else | 9690 | else |
7852 | q = avatar.Rotation; // Currently infrequently updated so may be inaccurate | 9691 | q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate |
7853 | else | 9692 | else |
7854 | q = m_host.ParentGroup.GroupRotation; // Likely never get here but just in case | 9693 | q = m_host.ParentGroup.GroupRotation; // Likely never get here but just in case |
7855 | } | 9694 | } |
7856 | else | 9695 | else |
7857 | q = m_host.ParentGroup.GroupRotation; // just the group rotation | 9696 | q = m_host.ParentGroup.GroupRotation; // just the group rotation |
7858 | return new LSL_Rotation(q.X, q.Y, q.Z, q.W); | 9697 | |
9698 | return new LSL_Rotation(q); | ||
7859 | } | 9699 | } |
7860 | 9700 | ||
7861 | public LSL_String llGetObjectDesc() | 9701 | public LSL_String llGetObjectDesc() |
@@ -7889,137 +9729,668 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7889 | } | 9729 | } |
7890 | 9730 | ||
7891 | /// <summary> | 9731 | /// <summary> |
7892 | /// A partial implementation. | 9732 | /// Full implementation of llGetBoundingBox according to SL 2015-04-15. |
9733 | /// http://wiki.secondlife.com/wiki/LlGetBoundingBox | ||
7893 | /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox | 9734 | /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox |
7894 | /// So far only valid for standing/flying/ground sitting avatars and single prim objects. | 9735 | /// Returns local bounding box of avatar without attachments |
7895 | /// If the object has multiple prims and/or a sitting avatar then the bounding | 9736 | /// if target is non-seated avatar or prim/mesh in avatar attachment. |
7896 | /// box is for the root prim only. | 9737 | /// Returns local bounding box of object including seated avatars |
9738 | /// if target is seated avatar or prim/mesh in object. | ||
9739 | /// Uses meshing of prims for high accuracy | ||
9740 | /// or less accurate box models for speed. | ||
7897 | /// </summary> | 9741 | /// </summary> |
7898 | public LSL_List llGetBoundingBox(string obj) | 9742 | public LSL_List llGetBoundingBox(string obj) |
7899 | { | 9743 | { |
7900 | m_host.AddScriptLPS(1); | 9744 | m_host.AddScriptLPS(1); |
9745 | |||
9746 | // Get target avatar if non-seated avatar or attachment, or prim and object | ||
7901 | UUID objID = UUID.Zero; | 9747 | UUID objID = UUID.Zero; |
9748 | UUID.TryParse(obj, out objID); | ||
9749 | ScenePresence agent = World.GetScenePresence(objID); | ||
9750 | if (agent != null) | ||
9751 | { | ||
9752 | if (agent.ParentPart != null) | ||
9753 | { | ||
9754 | objID = agent.ParentPart.UUID; | ||
9755 | agent = null; | ||
9756 | } | ||
9757 | } | ||
9758 | SceneObjectGroup group = null; | ||
9759 | SceneObjectPart target = World.GetSceneObjectPart(objID); | ||
9760 | if (target != null) | ||
9761 | { | ||
9762 | group = target.ParentGroup; | ||
9763 | if (group.IsAttachment) { | ||
9764 | objID = group.AttachedAvatar; | ||
9765 | agent = World.GetScenePresence(objID); | ||
9766 | group = null; | ||
9767 | target = null; | ||
9768 | } | ||
9769 | } | ||
9770 | |||
9771 | // Initialize but break if no target | ||
7902 | LSL_List result = new LSL_List(); | 9772 | LSL_List result = new LSL_List(); |
7903 | if (!UUID.TryParse(obj, out objID)) | 9773 | int groupCount = 0; |
9774 | int partCount = 0; | ||
9775 | int vertexCount = 0; | ||
9776 | if (target == null && agent == null) | ||
7904 | { | 9777 | { |
7905 | result.Add(new LSL_Vector()); | 9778 | result.Add(new LSL_Vector()); |
7906 | result.Add(new LSL_Vector()); | 9779 | result.Add(new LSL_Vector()); |
9780 | if (m_addStatsInGetBoundingBox) | ||
9781 | result.Add(new LSL_Vector((float)groupCount, (float)partCount, (float)vertexCount)); | ||
7907 | return result; | 9782 | return result; |
7908 | } | 9783 | } |
7909 | ScenePresence presence = World.GetScenePresence(objID); | 9784 | Vector3 minPosition = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue); |
7910 | if (presence != null) | 9785 | Vector3 maxPosition = new Vector3(float.MinValue, float.MinValue, float.MinValue); |
9786 | |||
9787 | // Try to get a mesher | ||
9788 | IRendering primMesher = null; | ||
9789 | List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory()); | ||
9790 | if (renderers.Count > 0) | ||
9791 | primMesher = RenderingLoader.LoadRenderer(renderers[0]); | ||
9792 | |||
9793 | // Get bounding box of just avatar, seated or not | ||
9794 | if (agent != null) | ||
9795 | { | ||
9796 | bool hasParent = false; | ||
9797 | Vector3 lower; | ||
9798 | Vector3 upper; | ||
9799 | BoundingBoxOfScenePresence(agent, out lower, out upper); | ||
9800 | Vector3 offset = Vector3.Zero; | ||
9801 | |||
9802 | // Since local bounding box unrotated and untilted, keep it simple | ||
9803 | AddBoundingBoxOfSimpleBox(lower, upper, offset, agent.Rotation, hasParent, ref minPosition, ref maxPosition, ref vertexCount); | ||
9804 | partCount++; | ||
9805 | groupCount++; | ||
9806 | |||
9807 | // Return lower and upper bounding box corners | ||
9808 | result.Add(new LSL_Vector(minPosition)); | ||
9809 | result.Add(new LSL_Vector(maxPosition)); | ||
9810 | if (m_addStatsInGetBoundingBox) | ||
9811 | result.Add(new LSL_Vector((float)groupCount, (float)partCount, (float)vertexCount)); | ||
9812 | return result; | ||
9813 | } | ||
9814 | // Get bounding box of object including seated avatars | ||
9815 | else if (group != null) | ||
7911 | { | 9816 | { |
7912 | if (presence.ParentID == 0) // not sat on an object | 9817 | // Merge bounding boxes of all parts (prims and mesh) |
9818 | foreach (SceneObjectPart part in group.Parts) | ||
7913 | { | 9819 | { |
7914 | LSL_Vector lower; | 9820 | bool hasParent = (!part.IsRoot); |
7915 | LSL_Vector upper; | 9821 | // When requested or if no mesher, keep it simple |
7916 | if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID | 9822 | if (m_useSimpleBoxesInGetBoundingBox || primMesher == null) |
7917 | == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) | ||
7918 | { | 9823 | { |
7919 | // This is for ground sitting avatars | 9824 | AddBoundingBoxOfSimpleBox(part.Scale * -0.5f, part.Scale * 0.5f, part.OffsetPosition, part.RotationOffset, hasParent, ref minPosition, ref maxPosition, ref vertexCount); |
7920 | float height = presence.Appearance.AvatarHeight / 2.66666667f; | ||
7921 | lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f); | ||
7922 | upper = new LSL_Vector(0.3375f, 0.45f, 0.0f); | ||
7923 | } | 9825 | } |
9826 | // Do the full mounty | ||
7924 | else | 9827 | else |
7925 | { | 9828 | { |
7926 | // This is for standing/flying avatars | 9829 | Primitive omvPrim = part.Shape.ToOmvPrimitive(part.OffsetPosition, part.RotationOffset); |
7927 | float height = presence.Appearance.AvatarHeight / 2.0f; | 9830 | byte[] sculptAsset = null; |
7928 | lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f); | 9831 | if (omvPrim.Sculpt != null) |
7929 | upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f); | 9832 | sculptAsset = World.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString()); |
9833 | |||
9834 | // When part is mesh | ||
9835 | // Quirk: Only imports as incompletely populated faceted mesh object, so needs an own handler. | ||
9836 | if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type == SculptType.Mesh && sculptAsset != null) | ||
9837 | { | ||
9838 | AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset); | ||
9839 | FacetedMesh mesh = null; | ||
9840 | FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, DetailLevel.Highest, out mesh); | ||
9841 | meshAsset = null; | ||
9842 | if (mesh != null) | ||
9843 | { | ||
9844 | AddBoundingBoxOfFacetedMesh(mesh, omvPrim, hasParent, ref minPosition, ref maxPosition, ref vertexCount); | ||
9845 | mesh = null; | ||
9846 | } | ||
9847 | } | ||
9848 | |||
9849 | // When part is sculpt | ||
9850 | // Quirk: Generated sculpt mesh is about 2.8% smaller in X and Y than visual sculpt. | ||
9851 | else if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type != SculptType.Mesh && sculptAsset != null) | ||
9852 | { | ||
9853 | IJ2KDecoder imgDecoder = World.RequestModuleInterface<IJ2KDecoder>(); | ||
9854 | if (imgDecoder != null) | ||
9855 | { | ||
9856 | Image sculpt = imgDecoder.DecodeToImage(sculptAsset); | ||
9857 | if (sculpt != null) | ||
9858 | { | ||
9859 | SimpleMesh mesh = primMesher.GenerateSimpleSculptMesh(omvPrim, (Bitmap)sculpt, DetailLevel.Medium); | ||
9860 | sculpt.Dispose(); | ||
9861 | if (mesh != null) | ||
9862 | { | ||
9863 | AddBoundingBoxOfSimpleMesh(mesh, omvPrim, hasParent, ref minPosition, ref maxPosition, ref vertexCount); | ||
9864 | mesh = null; | ||
9865 | } | ||
9866 | } | ||
9867 | } | ||
9868 | } | ||
9869 | |||
9870 | // When part is prim | ||
9871 | else if (omvPrim.Sculpt == null) | ||
9872 | { | ||
9873 | SimpleMesh mesh = primMesher.GenerateSimpleMesh(omvPrim, DetailLevel.Medium); | ||
9874 | if (mesh != null) | ||
9875 | { | ||
9876 | AddBoundingBoxOfSimpleMesh(mesh, omvPrim, hasParent, ref minPosition, ref maxPosition, ref vertexCount); | ||
9877 | mesh = null; | ||
9878 | } | ||
9879 | } | ||
9880 | |||
9881 | // When all else fails, try fallback to simple box | ||
9882 | else | ||
9883 | { | ||
9884 | AddBoundingBoxOfSimpleBox(part.Scale * -0.5f, part.Scale * 0.5f, part.OffsetPosition, part.RotationOffset, hasParent, ref minPosition, ref maxPosition, ref vertexCount); | ||
9885 | } | ||
7930 | } | 9886 | } |
7931 | result.Add(lower); | 9887 | partCount++; |
7932 | result.Add(upper); | ||
7933 | return result; | ||
7934 | } | 9888 | } |
9889 | } | ||
9890 | |||
9891 | // Merge bounding boxes of seated avatars | ||
9892 | foreach (ScenePresence sp in group.GetSittingAvatars()) | ||
9893 | { | ||
9894 | Vector3 lower; | ||
9895 | Vector3 upper; | ||
9896 | BoundingBoxOfScenePresence(sp, out lower, out upper); | ||
9897 | Vector3 offset = sp.OffsetPosition; | ||
9898 | |||
9899 | bool hasParent = true; | ||
9900 | // When requested or if no mesher, keep it simple | ||
9901 | if (m_useSimpleBoxesInGetBoundingBox || primMesher == null) | ||
9902 | { | ||
9903 | AddBoundingBoxOfSimpleBox(lower, upper, offset, sp.Rotation, hasParent, ref minPosition, ref maxPosition, ref vertexCount); | ||
9904 | } | ||
9905 | // Do the full mounty | ||
7935 | else | 9906 | else |
7936 | { | 9907 | { |
7937 | // sitting on an object so we need the bounding box of that | 9908 | // Prim shapes don't do center offsets, so add it here. |
7938 | // which should include the avatar so set the UUID to the | 9909 | offset = offset + (lower + upper) * 0.5f * sp.Rotation; |
7939 | // UUID of the object the avatar is sat on and allow it to fall through | 9910 | Primitive omvPrim = MakeOpenMetaversePrim(upper - lower, offset, sp.Rotation, ScriptBaseClass.PRIM_TYPE_SPHERE); |
7940 | // to processing an object | 9911 | SimpleMesh mesh = primMesher.GenerateSimpleMesh(omvPrim, DetailLevel.Medium); |
7941 | SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID); | 9912 | AddBoundingBoxOfSimpleMesh(mesh, omvPrim, hasParent, ref minPosition, ref maxPosition, ref vertexCount); |
7942 | objID = p.UUID; | 9913 | mesh = null; |
7943 | } | 9914 | } |
9915 | partCount++; | ||
7944 | } | 9916 | } |
7945 | SceneObjectPart part = World.GetSceneObjectPart(objID); | 9917 | |
7946 | // Currently only works for single prims without a sitting avatar | 9918 | groupCount++; |
7947 | if (part != null) | 9919 | |
9920 | // Return lower and upper bounding box corners | ||
9921 | result.Add(new LSL_Vector(minPosition)); | ||
9922 | result.Add(new LSL_Vector(maxPosition)); | ||
9923 | if (m_addStatsInGetBoundingBox) | ||
9924 | result.Add(new LSL_Vector((float)groupCount, (float)partCount, (float)vertexCount)); | ||
9925 | |||
9926 | primMesher = null; | ||
9927 | return result; | ||
9928 | } | ||
9929 | |||
9930 | /// <summary> | ||
9931 | /// Helper to calculate bounding box of an avatar. | ||
9932 | /// </summary> | ||
9933 | private void BoundingBoxOfScenePresence(ScenePresence sp, out Vector3 lower, out Vector3 upper) | ||
9934 | { | ||
9935 | // Adjust from OS model | ||
9936 | // avatar height = visual height - 0.2, bounding box height = visual height | ||
9937 | // to SL model | ||
9938 | // avatar height = visual height, bounding box height = visual height + 0.2 | ||
9939 | float height = sp.Appearance.AvatarHeight + m_avatarHeightCorrection; | ||
9940 | |||
9941 | // According to avatar bounding box in SL 2015-04-18: | ||
9942 | // standing = <-0.275,-0.35,-0.1-0.5*h> : <0.275,0.35,0.1+0.5*h> | ||
9943 | // groundsitting = <-0.3875,-0.5,-0.05-0.375*h> : <0.3875,0.5,0.5> | ||
9944 | // sitting = <-0.5875,-0.35,-0.35-0.375*h> : <0.1875,0.35,-0.25+0.25*h> | ||
9945 | |||
9946 | // When avatar is sitting | ||
9947 | if (sp.ParentPart != null) | ||
7948 | { | 9948 | { |
7949 | Vector3 halfSize = part.Scale / 2.0f; | 9949 | lower = new Vector3(m_lABB1SitX0, m_lABB1SitY0, m_lABB1SitZ0 + m_lABB1SitZ1 * height); |
7950 | LSL_Vector lower = (new LSL_Vector(halfSize)) * -1.0f; | 9950 | upper = new Vector3(m_lABB2SitX0, m_lABB2SitY0, m_lABB2SitZ0 + m_lABB2SitZ1 * height); |
7951 | LSL_Vector upper = new LSL_Vector(halfSize); | 9951 | } |
7952 | result.Add(lower); | 9952 | // When avatar is groundsitting |
7953 | result.Add(upper); | 9953 | else if (sp.Animator.Animations.ImplicitDefaultAnimation.AnimID == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) |
7954 | return result; | 9954 | { |
9955 | lower = new Vector3(m_lABB1GrsX0, m_lABB1GrsY0, m_lABB1GrsZ0 + m_lABB1GrsZ1 * height); | ||
9956 | upper = new Vector3(m_lABB2GrsX0, m_lABB2GrsY0, m_lABB2GrsZ0 + m_lABB2GrsZ1 * height); | ||
9957 | } | ||
9958 | // When avatar is standing or flying | ||
9959 | else | ||
9960 | { | ||
9961 | lower = new Vector3(m_lABB1StdX0, m_lABB1StdY0, m_lABB1StdZ0 + m_lABB1StdZ1 * height); | ||
9962 | upper = new Vector3(m_lABB2StdX0, m_lABB2StdY0, m_lABB2StdZ0 + m_lABB2StdZ1 * height); | ||
7955 | } | 9963 | } |
9964 | } | ||
7956 | 9965 | ||
7957 | // Not found so return empty values | 9966 | /// <summary> |
7958 | result.Add(new LSL_Vector()); | 9967 | /// Helper to approximate a part with a simple box. |
7959 | result.Add(new LSL_Vector()); | 9968 | /// </summary> |
7960 | return result; | 9969 | private void AddBoundingBoxOfSimpleBox(Vector3 corner1, Vector3 corner2, Vector3 offset, Quaternion rotation, bool hasParent, ref Vector3 lower, ref Vector3 upper, ref int count) |
9970 | { | ||
9971 | // Parse the 8 box corners | ||
9972 | for (int i = 0; i < 8; i++) | ||
9973 | { | ||
9974 | // Calculate each box corner | ||
9975 | Vector3 position = corner1; | ||
9976 | if ((i & 1) != 0) | ||
9977 | position.X = corner2.X; | ||
9978 | if ((i & 2) != 0) | ||
9979 | position.Y = corner2.Y; | ||
9980 | if ((i & 4) != 0) | ||
9981 | position.Z = corner2.Z; | ||
9982 | // Rotate part unless part is root | ||
9983 | if (hasParent) | ||
9984 | position = position * rotation; | ||
9985 | position = position + offset; | ||
9986 | // Adjust lower and upper bounding box corners if needed | ||
9987 | lower = Vector3.Min(lower, position); | ||
9988 | upper = Vector3.Max(upper, position); | ||
9989 | count++; | ||
9990 | } | ||
7961 | } | 9991 | } |
7962 | 9992 | ||
7963 | public LSL_Vector llGetGeometricCenter() | 9993 | /// <summary> |
9994 | /// Helper to parse a meshed prim and needed especially | ||
9995 | /// for accuracy with tortured prims and sculpts. | ||
9996 | /// </summary> | ||
9997 | private void AddBoundingBoxOfSimpleMesh(SimpleMesh mesh, Primitive prim, bool hasParent, ref Vector3 lower, ref Vector3 upper, ref int count) | ||
7964 | { | 9998 | { |
7965 | return new LSL_Vector(m_host.GetGeometricCenter().X, m_host.GetGeometricCenter().Y, m_host.GetGeometricCenter().Z); | 9999 | // Quirk: A meshed box contains 10 instead of the 8 necessary vertices. |
10000 | if (mesh != null) | ||
10001 | { | ||
10002 | // Parse each vertex in mesh | ||
10003 | foreach (Vertex vertex in mesh.Vertices) | ||
10004 | { | ||
10005 | Vector3 position = vertex.Position; | ||
10006 | position = position * prim.Scale; | ||
10007 | // Rotate part unless part is root | ||
10008 | if (hasParent) | ||
10009 | position = position * prim.Rotation; | ||
10010 | position = position + prim.Position; | ||
10011 | // Adjust lower and upper bounding box corners if needed | ||
10012 | lower = Vector3.Min(lower, position); | ||
10013 | upper = Vector3.Max(upper, position); | ||
10014 | count++; | ||
10015 | } | ||
10016 | } | ||
7966 | } | 10017 | } |
7967 | 10018 | ||
7968 | public LSL_List llGetPrimitiveParams(LSL_List rules) | 10019 | /// <summary> |
10020 | /// Helper to parse mesh because no method exists | ||
10021 | /// to parse mesh assets to SimpleMesh. | ||
10022 | /// </summary> | ||
10023 | private void AddBoundingBoxOfFacetedMesh(FacetedMesh mesh, Primitive prim, bool hasParent, ref Vector3 lower, ref Vector3 upper, ref int count) | ||
7969 | { | 10024 | { |
7970 | m_host.AddScriptLPS(1); | 10025 | if (mesh != null) |
10026 | { | ||
10027 | // Parse each face in mesh | ||
10028 | // since vertex array isn't populated. | ||
10029 | // This parses each unique vertex 3-6 times. | ||
10030 | foreach (Face face in mesh.Faces) | ||
10031 | { | ||
10032 | // Parse each vertex in face | ||
10033 | foreach (Vertex vertex in face.Vertices) | ||
10034 | { | ||
10035 | Vector3 position = vertex.Position; | ||
10036 | position = position * prim.Scale; | ||
10037 | // Rotate part unless part is root | ||
10038 | if (hasParent) | ||
10039 | position = position * prim.Rotation; | ||
10040 | position = position + prim.Position; | ||
10041 | // Adjust lower and upper bounding box corners if needed | ||
10042 | lower = Vector3.Min(lower, position); | ||
10043 | upper = Vector3.Max(upper, position); | ||
10044 | count++; | ||
10045 | } | ||
10046 | } | ||
10047 | } | ||
10048 | } | ||
7971 | 10049 | ||
7972 | LSL_List result = new LSL_List(); | 10050 | /// <summary> |
10051 | /// Helper to make up an OpenMetaverse prim | ||
10052 | /// needed to create mesh from parts. | ||
10053 | /// </summary> | ||
10054 | private Primitive MakeOpenMetaversePrim(Vector3 scale, Vector3 position, Quaternion rotation, int primType) | ||
10055 | { | ||
10056 | // Initialize and set common parameters | ||
10057 | Primitive prim = new OpenMetaverse.Primitive(); | ||
10058 | prim.Scale = scale; | ||
10059 | prim.Position = position; | ||
10060 | prim.Rotation = rotation; | ||
10061 | prim.PrimData.PathShearX = 0.0f; | ||
10062 | prim.PrimData.PathShearY = 0.0f; | ||
10063 | prim.PrimData.PathBegin = 0.0f; | ||
10064 | prim.PrimData.PathEnd = 1.0f; | ||
10065 | prim.PrimData.PathScaleX = 1.0f; | ||
10066 | prim.PrimData.PathScaleY = 1.0f; | ||
10067 | prim.PrimData.PathTaperX = 0.0f; | ||
10068 | prim.PrimData.PathTaperY = 0.0f; | ||
10069 | prim.PrimData.PathTwistBegin = 0.0f; | ||
10070 | prim.PrimData.PathTwist = 0.0f; | ||
10071 | prim.PrimData.ProfileBegin = 0.0f; | ||
10072 | prim.PrimData.ProfileEnd = 1.0f; | ||
10073 | prim.PrimData.ProfileHollow = 0.0f; | ||
10074 | prim.PrimData.ProfileCurve = (ProfileCurve)1; | ||
10075 | prim.PrimData.ProfileHole = (HoleType)0; | ||
10076 | prim.PrimData.PathCurve = (PathCurve)16; | ||
10077 | prim.PrimData.PathRadiusOffset = 0.0f; | ||
10078 | prim.PrimData.PathRevolutions = 1.0f; | ||
10079 | prim.PrimData.PathSkew = 0.0f; | ||
10080 | prim.PrimData.PCode = OpenMetaverse.PCode.Prim; | ||
10081 | prim.PrimData.State = (byte)0; | ||
10082 | |||
10083 | // Set type specific parameters | ||
10084 | switch (primType) | ||
10085 | { | ||
10086 | // Set specific parameters for box | ||
10087 | case ScriptBaseClass.PRIM_TYPE_BOX: | ||
10088 | prim.PrimData.PathScaleY = 1.0f; | ||
10089 | prim.PrimData.ProfileCurve = (ProfileCurve)1; | ||
10090 | prim.PrimData.PathCurve = (PathCurve)16; | ||
10091 | break; | ||
10092 | // Set specific parameters for cylinder | ||
10093 | case ScriptBaseClass.PRIM_TYPE_CYLINDER: | ||
10094 | prim.PrimData.PathScaleY = 1.0f; | ||
10095 | prim.PrimData.ProfileCurve = (ProfileCurve)0; | ||
10096 | prim.PrimData.PathCurve = (PathCurve)16; | ||
10097 | break; | ||
10098 | // Set specific parameters for prism | ||
10099 | case ScriptBaseClass.PRIM_TYPE_PRISM: | ||
10100 | prim.PrimData.PathScaleY = 1.0f; | ||
10101 | prim.PrimData.ProfileCurve = (ProfileCurve)3; | ||
10102 | prim.PrimData.PathCurve = (PathCurve)16; | ||
10103 | break; | ||
10104 | // Set specific parameters for sphere | ||
10105 | case ScriptBaseClass.PRIM_TYPE_SPHERE: | ||
10106 | prim.PrimData.PathScaleY = 1.0f; | ||
10107 | prim.PrimData.ProfileCurve = (ProfileCurve)5; | ||
10108 | prim.PrimData.PathCurve = (PathCurve)32; | ||
10109 | break; | ||
10110 | // Set specific parameters for torus | ||
10111 | case ScriptBaseClass.PRIM_TYPE_TORUS: | ||
10112 | prim.PrimData.PathScaleY = 0.5f; | ||
10113 | prim.PrimData.ProfileCurve = (ProfileCurve)0; | ||
10114 | prim.PrimData.PathCurve = (PathCurve)32; | ||
10115 | break; | ||
10116 | // Set specific parameters for tube | ||
10117 | case ScriptBaseClass.PRIM_TYPE_TUBE: | ||
10118 | prim.PrimData.PathScaleY = 0.5f; | ||
10119 | prim.PrimData.ProfileCurve = (ProfileCurve)1; | ||
10120 | prim.PrimData.PathCurve = (PathCurve)32; | ||
10121 | break; | ||
10122 | // Set specific parameters for ring | ||
10123 | case ScriptBaseClass.PRIM_TYPE_RING: | ||
10124 | prim.PrimData.PathScaleY = 0.5f; | ||
10125 | prim.PrimData.ProfileCurve = (ProfileCurve)3; | ||
10126 | prim.PrimData.PathCurve = (PathCurve)32; | ||
10127 | break; | ||
10128 | // Set specific parameters for sculpt | ||
10129 | case ScriptBaseClass.PRIM_TYPE_SCULPT: | ||
10130 | prim.PrimData.PathScaleY = 1.0f; | ||
10131 | prim.PrimData.ProfileCurve = (ProfileCurve)5; | ||
10132 | prim.PrimData.PathCurve = (PathCurve)32; | ||
10133 | break; | ||
10134 | // Default to specific parameters for box | ||
10135 | default: | ||
10136 | prim.PrimData.PathScaleY = 1.0f; | ||
10137 | prim.PrimData.ProfileCurve = (ProfileCurve)1; | ||
10138 | prim.PrimData.PathCurve = (PathCurve)16; | ||
10139 | break; | ||
10140 | } | ||
7973 | 10141 | ||
7974 | LSL_List remaining = GetPrimParams(m_host, rules, ref result); | 10142 | return prim; |
10143 | } | ||
10144 | |||
10145 | /// <summary> | ||
10146 | /// Implementation of llGetGeometricCenter according to SL 2015-04-30. | ||
10147 | /// http://wiki.secondlife.com/wiki/LlGetGeometricCenter | ||
10148 | /// Returns the average position offset of all linked parts, | ||
10149 | /// including the root prim and seated avatars, | ||
10150 | /// relative to the root prim in local coordinates. | ||
10151 | /// </summary> | ||
10152 | public LSL_Vector llGetGeometricCenter() | ||
10153 | { | ||
10154 | // Subtract whatever position the root prim has to make it zero | ||
10155 | Vector3 offset = m_host.ParentGroup.RootPart.OffsetPosition * -1.0f; | ||
10156 | |||
10157 | // Add all prim/part position offsets | ||
10158 | foreach (SceneObjectPart part in m_host.ParentGroup.Parts) | ||
10159 | offset = offset + part.OffsetPosition; | ||
10160 | // Add all avatar/scene presence position offsets | ||
10161 | foreach (ScenePresence sp in m_host.ParentGroup.GetSittingAvatars()) | ||
10162 | offset = offset + sp.OffsetPosition; | ||
7975 | 10163 | ||
7976 | while (remaining != null && remaining.Length > 2) | 10164 | // Calculate and return the average offset |
10165 | offset = offset / (float)(m_host.ParentGroup.PrimCount + m_host.ParentGroup.GetSittingAvatarsCount()); | ||
10166 | return new LSL_Vector(offset); | ||
10167 | } | ||
10168 | |||
10169 | public LSL_List GetEntityParams(ISceneEntity entity, LSL_List rules) | ||
10170 | { | ||
10171 | LSL_List result = new LSL_List(); | ||
10172 | LSL_List remaining; | ||
10173 | |||
10174 | while (true) | ||
7977 | { | 10175 | { |
10176 | // m_log.DebugFormat( | ||
10177 | // "[LSL API]: GetEntityParams has {0} rules with scene entity named {1}", | ||
10178 | // rules.Length, entity != null ? entity.Name : "NULL"); | ||
10179 | |||
10180 | if (entity == null) | ||
10181 | return result; | ||
10182 | |||
10183 | if (entity is SceneObjectPart) | ||
10184 | remaining = GetPrimParams((SceneObjectPart)entity, rules, ref result); | ||
10185 | else | ||
10186 | remaining = GetAgentParams((ScenePresence)entity, rules, ref result); | ||
10187 | |||
10188 | if (remaining == null || remaining.Length < 2) | ||
10189 | return result; | ||
10190 | |||
7978 | int linknumber = remaining.GetLSLIntegerItem(0); | 10191 | int linknumber = remaining.GetLSLIntegerItem(0); |
7979 | rules = remaining.GetSublist(1, -1); | 10192 | rules = remaining.GetSublist(1, -1); |
7980 | List<SceneObjectPart> parts = GetLinkParts(linknumber); | 10193 | entity = GetLinkEntity(m_host, linknumber); |
7981 | |||
7982 | foreach (SceneObjectPart part in parts) | ||
7983 | remaining = GetPrimParams(part, rules, ref result); | ||
7984 | } | 10194 | } |
10195 | } | ||
7985 | 10196 | ||
7986 | return result; | 10197 | public LSL_List llGetPrimitiveParams(LSL_List rules) |
10198 | { | ||
10199 | m_host.AddScriptLPS(1); | ||
10200 | |||
10201 | return GetEntityParams(m_host, rules); | ||
7987 | } | 10202 | } |
7988 | 10203 | ||
7989 | public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules) | 10204 | public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules) |
7990 | { | 10205 | { |
7991 | m_host.AddScriptLPS(1); | 10206 | m_host.AddScriptLPS(1); |
7992 | 10207 | ||
7993 | List<SceneObjectPart> parts = GetLinkParts(linknumber); | 10208 | return GetEntityParams(GetLinkEntity(m_host, linknumber), rules); |
10209 | } | ||
7994 | 10210 | ||
7995 | LSL_List res = new LSL_List(); | 10211 | public LSL_Vector GetAgentSize(ScenePresence sp) |
7996 | LSL_List remaining = null; | 10212 | { |
10213 | return new LSL_Vector(0.45, 0.6, sp.Appearance.AvatarHeight); | ||
10214 | } | ||
7997 | 10215 | ||
7998 | foreach (SceneObjectPart part in parts) | 10216 | /// <summary> |
10217 | /// Gets params for a seated avatar in a linkset. | ||
10218 | /// </summary> | ||
10219 | /// <returns></returns> | ||
10220 | /// <param name='sp'></param> | ||
10221 | /// <param name='rules'></param> | ||
10222 | /// <param name='res'></param> | ||
10223 | public LSL_List GetAgentParams(ScenePresence sp, LSL_List rules, ref LSL_List res) | ||
10224 | { | ||
10225 | int idx = 0; | ||
10226 | while (idx < rules.Length) | ||
7999 | { | 10227 | { |
8000 | remaining = GetPrimParams(part, rules, ref res); | 10228 | int code = (int)rules.GetLSLIntegerItem(idx++); |
8001 | } | 10229 | int remain = rules.Length-idx; |
8002 | 10230 | ||
8003 | while (remaining != null && remaining.Length > 2) | 10231 | switch (code) |
8004 | { | 10232 | { |
8005 | linknumber = remaining.GetLSLIntegerItem(0); | 10233 | case (int)ScriptBaseClass.PRIM_MATERIAL: |
8006 | rules = remaining.GetSublist(1, -1); | 10234 | res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MATERIAL_FLESH)); |
8007 | parts = GetLinkParts(linknumber); | 10235 | break; |
8008 | 10236 | ||
8009 | foreach (SceneObjectPart part in parts) | 10237 | case (int)ScriptBaseClass.PRIM_PHYSICS: |
8010 | remaining = GetPrimParams(part, rules, ref res); | 10238 | res.Add(ScriptBaseClass.FALSE); |
10239 | break; | ||
10240 | |||
10241 | case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ: | ||
10242 | res.Add(ScriptBaseClass.FALSE); | ||
10243 | break; | ||
10244 | |||
10245 | case (int)ScriptBaseClass.PRIM_PHANTOM: | ||
10246 | res.Add(ScriptBaseClass.FALSE); | ||
10247 | break; | ||
10248 | |||
10249 | case (int)ScriptBaseClass.PRIM_POSITION: | ||
10250 | res.Add(new LSL_Vector(sp.AbsolutePosition)); | ||
10251 | break; | ||
10252 | |||
10253 | case (int)ScriptBaseClass.PRIM_SIZE: | ||
10254 | res.Add(GetAgentSize(sp)); | ||
10255 | break; | ||
10256 | |||
10257 | case (int)ScriptBaseClass.PRIM_ROTATION: | ||
10258 | res.Add(sp.GetWorldRotation()); | ||
10259 | break; | ||
10260 | |||
10261 | case (int)ScriptBaseClass.PRIM_TYPE: | ||
10262 | res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX)); | ||
10263 | res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT)); | ||
10264 | res.Add(new LSL_Vector(0, 1, 0)); | ||
10265 | res.Add(new LSL_Float(0)); | ||
10266 | res.Add(new LSL_Vector(0, 0, 0)); | ||
10267 | res.Add(new LSL_Vector(1, 1, 0)); | ||
10268 | res.Add(new LSL_Vector(0, 0, 0)); | ||
10269 | break; | ||
10270 | |||
10271 | case (int)ScriptBaseClass.PRIM_TEXTURE: | ||
10272 | if (remain < 1) | ||
10273 | return new LSL_List(); | ||
10274 | |||
10275 | int face = (int)rules.GetLSLIntegerItem(idx++); | ||
10276 | if (face > 21) | ||
10277 | break; | ||
10278 | |||
10279 | res.Add(new LSL_String("")); | ||
10280 | res.Add(ScriptBaseClass.ZERO_VECTOR); | ||
10281 | res.Add(ScriptBaseClass.ZERO_VECTOR); | ||
10282 | res.Add(new LSL_Float(0)); | ||
10283 | break; | ||
10284 | |||
10285 | case (int)ScriptBaseClass.PRIM_COLOR: | ||
10286 | if (remain < 1) | ||
10287 | return new LSL_List(); | ||
10288 | |||
10289 | face = (int)rules.GetLSLIntegerItem(idx++); | ||
10290 | if (face > 21) | ||
10291 | break; | ||
10292 | |||
10293 | res.Add(ScriptBaseClass.ZERO_VECTOR); | ||
10294 | res.Add(new LSL_Float(0)); | ||
10295 | break; | ||
10296 | |||
10297 | case (int)ScriptBaseClass.PRIM_BUMP_SHINY: | ||
10298 | if (remain < 1) | ||
10299 | return new LSL_List(); | ||
10300 | |||
10301 | face = (int)rules.GetLSLIntegerItem(idx++); | ||
10302 | if (face > 21) | ||
10303 | break; | ||
10304 | |||
10305 | res.Add(ScriptBaseClass.PRIM_SHINY_NONE); | ||
10306 | res.Add(ScriptBaseClass.PRIM_BUMP_NONE); | ||
10307 | break; | ||
10308 | |||
10309 | case (int)ScriptBaseClass.PRIM_FULLBRIGHT: | ||
10310 | if (remain < 1) | ||
10311 | return new LSL_List(); | ||
10312 | |||
10313 | face = (int)rules.GetLSLIntegerItem(idx++); | ||
10314 | if (face > 21) | ||
10315 | break; | ||
10316 | |||
10317 | res.Add(ScriptBaseClass.FALSE); | ||
10318 | break; | ||
10319 | |||
10320 | case (int)ScriptBaseClass.PRIM_FLEXIBLE: | ||
10321 | res.Add(ScriptBaseClass.FALSE); | ||
10322 | res.Add(new LSL_Integer(0)); | ||
10323 | res.Add(new LSL_Float(0)); | ||
10324 | res.Add(new LSL_Float(0)); | ||
10325 | res.Add(new LSL_Float(0)); | ||
10326 | res.Add(new LSL_Float(0)); | ||
10327 | res.Add(ScriptBaseClass.ZERO_VECTOR); | ||
10328 | break; | ||
10329 | |||
10330 | case (int)ScriptBaseClass.PRIM_TEXGEN: | ||
10331 | if (remain < 1) | ||
10332 | return new LSL_List(); | ||
10333 | |||
10334 | face = (int)rules.GetLSLIntegerItem(idx++); | ||
10335 | if (face > 21) | ||
10336 | break; | ||
10337 | |||
10338 | res.Add(ScriptBaseClass.PRIM_TEXGEN_DEFAULT); | ||
10339 | break; | ||
10340 | |||
10341 | case (int)ScriptBaseClass.PRIM_POINT_LIGHT: | ||
10342 | res.Add(ScriptBaseClass.FALSE); | ||
10343 | res.Add(ScriptBaseClass.ZERO_VECTOR); | ||
10344 | res.Add(ScriptBaseClass.ZERO_VECTOR); | ||
10345 | break; | ||
10346 | |||
10347 | case (int)ScriptBaseClass.PRIM_GLOW: | ||
10348 | if (remain < 1) | ||
10349 | return new LSL_List(); | ||
10350 | |||
10351 | face = (int)rules.GetLSLIntegerItem(idx++); | ||
10352 | if (face > 21) | ||
10353 | break; | ||
10354 | |||
10355 | res.Add(new LSL_Float(0)); | ||
10356 | break; | ||
10357 | |||
10358 | case (int)ScriptBaseClass.PRIM_TEXT: | ||
10359 | res.Add(new LSL_String("")); | ||
10360 | res.Add(ScriptBaseClass.ZERO_VECTOR); | ||
10361 | res.Add(new LSL_Float(1)); | ||
10362 | break; | ||
10363 | |||
10364 | case (int)ScriptBaseClass.PRIM_ROT_LOCAL: | ||
10365 | res.Add(new LSL_Rotation(sp.Rotation)); | ||
10366 | break; | ||
10367 | |||
10368 | case (int)ScriptBaseClass.PRIM_POS_LOCAL: | ||
10369 | res.Add(new LSL_Vector(sp.OffsetPosition)); | ||
10370 | break; | ||
10371 | |||
10372 | case (int)ScriptBaseClass.PRIM_SLICE: | ||
10373 | res.Add(new LSL_Vector(0, 1, 0)); | ||
10374 | break; | ||
10375 | |||
10376 | case (int)ScriptBaseClass.PRIM_LINK_TARGET: | ||
10377 | if(remain < 3) | ||
10378 | return new LSL_List(); | ||
10379 | |||
10380 | return rules.GetSublist(idx, -1); | ||
10381 | } | ||
8011 | } | 10382 | } |
8012 | 10383 | ||
8013 | return res; | 10384 | return new LSL_List(); |
8014 | } | 10385 | } |
8015 | 10386 | ||
8016 | public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res) | 10387 | public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res) |
8017 | { | 10388 | { |
8018 | int idx=0; | 10389 | int idx = 0; |
8019 | while (idx < rules.Length) | 10390 | while (idx < rules.Length) |
8020 | { | 10391 | { |
8021 | int code=(int)rules.GetLSLIntegerItem(idx++); | 10392 | int code = (int)rules.GetLSLIntegerItem(idx++); |
8022 | int remain=rules.Length-idx; | 10393 | int remain = rules.Length - idx; |
8023 | 10394 | ||
8024 | switch (code) | 10395 | switch (code) |
8025 | { | 10396 | { |
@@ -8049,29 +10420,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8049 | break; | 10420 | break; |
8050 | 10421 | ||
8051 | case (int)ScriptBaseClass.PRIM_POSITION: | 10422 | case (int)ScriptBaseClass.PRIM_POSITION: |
8052 | LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X, | 10423 | LSL_Vector v = new LSL_Vector(part.AbsolutePosition); |
8053 | part.AbsolutePosition.Y, | 10424 | |
8054 | part.AbsolutePosition.Z); | ||
8055 | // For some reason, the part.AbsolutePosition.* values do not change if the | 10425 | // For some reason, the part.AbsolutePosition.* values do not change if the |
8056 | // linkset is rotated; they always reflect the child prim's world position | 10426 | // linkset is rotated; they always reflect the child prim's world position |
8057 | // as though the linkset is unrotated. This is incompatible behavior with SL's | 10427 | // as though the linkset is unrotated. This is incompatible behavior with SL's |
8058 | // implementation, so will break scripts imported from there (not to mention it | 10428 | // implementation, so will break scripts imported from there (not to mention it |
8059 | // makes it more difficult to determine a child prim's actual inworld position). | 10429 | // makes it more difficult to determine a child prim's actual inworld position). |
8060 | if (part.ParentID != 0) | 10430 | if (!part.IsRoot) |
8061 | v = ((v - llGetRootPosition()) * llGetRootRotation()) + llGetRootPosition(); | 10431 | { |
10432 | LSL_Vector rootPos = new LSL_Vector(m_host.ParentGroup.AbsolutePosition); | ||
10433 | v = ((v - rootPos) * llGetRootRotation()) + rootPos; | ||
10434 | } | ||
10435 | |||
8062 | res.Add(v); | 10436 | res.Add(v); |
8063 | break; | 10437 | break; |
8064 | 10438 | ||
8065 | case (int)ScriptBaseClass.PRIM_SIZE: | 10439 | case (int)ScriptBaseClass.PRIM_SIZE: |
8066 | res.Add(new LSL_Vector(part.Scale.X, | 10440 | res.Add(new LSL_Vector(part.Scale)); |
8067 | part.Scale.Y, | ||
8068 | part.Scale.Z)); | ||
8069 | break; | 10441 | break; |
8070 | 10442 | ||
8071 | case (int)ScriptBaseClass.PRIM_ROTATION: | 10443 | case (int)ScriptBaseClass.PRIM_ROTATION: |
8072 | res.Add(GetPartRot(part)); | 10444 | res.Add(GetPartRot(part)); |
8073 | break; | 10445 | break; |
8074 | 10446 | ||
10447 | case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE: | ||
10448 | res.Add(new LSL_Integer((int)part.PhysicsShapeType)); | ||
10449 | break; | ||
10450 | |||
8075 | case (int)ScriptBaseClass.PRIM_TYPE: | 10451 | case (int)ScriptBaseClass.PRIM_TYPE: |
8076 | // implementing box | 10452 | // implementing box |
8077 | PrimitiveBaseShape Shape = part.Shape; | 10453 | PrimitiveBaseShape Shape = part.Shape; |
@@ -8101,7 +10477,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8101 | break; | 10477 | break; |
8102 | 10478 | ||
8103 | case ScriptBaseClass.PRIM_TYPE_SCULPT: | 10479 | case ScriptBaseClass.PRIM_TYPE_SCULPT: |
8104 | res.Add(Shape.SculptTexture.ToString()); | 10480 | res.Add(new LSL_String(Shape.SculptTexture.ToString())); |
8105 | res.Add(new LSL_Integer(Shape.SculptType)); | 10481 | res.Add(new LSL_Integer(Shape.SculptType)); |
8106 | break; | 10482 | break; |
8107 | 10483 | ||
@@ -8133,16 +10509,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8133 | res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0)); | 10509 | res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0)); |
8134 | 10510 | ||
8135 | // float revolutions | 10511 | // float revolutions |
8136 | res.Add(new LSL_Float(Math.Round(Shape.PathRevolutions * 0.015d, 2, MidpointRounding.AwayFromZero)) + 1.0d); | 10512 | res.Add(new LSL_Float(Math.Round(Shape.PathRevolutions * 0.015d, 2, MidpointRounding.AwayFromZero)) + 1.0d); |
8137 | // Slightly inaccurate, because an unsigned byte is being used to represent | 10513 | // Slightly inaccurate, because an unsigned byte is being used to represent |
8138 | // the entire range of floating-point values from 1.0 through 4.0 (which is how | 10514 | // the entire range of floating-point values from 1.0 through 4.0 (which is how |
8139 | // SL does it). | 10515 | // SL does it). |
8140 | // | 10516 | // |
8141 | // Using these formulas to store and retrieve PathRevolutions, it is not | 10517 | // Using these formulas to store and retrieve PathRevolutions, it is not |
8142 | // possible to use all values between 1.00 and 4.00. For instance, you can't | 10518 | // possible to use all values between 1.00 and 4.00. For instance, you can't |
8143 | // represent 1.10. You can represent 1.09 and 1.11, but not 1.10. So, if you | 10519 | // represent 1.10. You can represent 1.09 and 1.11, but not 1.10. So, if you |
8144 | // use llSetPrimitiveParams to set revolutions to 1.10 and then retreive them | 10520 | // use llSetPrimitiveParams to set revolutions to 1.10 and then retreive them |
8145 | // with llGetPrimitiveParams, you'll retrieve 1.09. You can also see a similar | 10521 | // with llGetPrimitiveParams, you'll retrieve 1.09. You can also see a similar |
8146 | // behavior in the viewer as you cannot set 1.10. The viewer jumps to 1.11. | 10522 | // behavior in the viewer as you cannot set 1.10. The viewer jumps to 1.11. |
8147 | // In SL, llSetPrimitveParams and llGetPrimitiveParams can set and get a value | 10523 | // In SL, llSetPrimitveParams and llGetPrimitiveParams can set and get a value |
8148 | // such as 1.10. So, SL must store and retreive the actual user input rather | 10524 | // such as 1.10. So, SL must store and retreive the actual user input rather |
@@ -8159,7 +10535,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8159 | 10535 | ||
8160 | case (int)ScriptBaseClass.PRIM_TEXTURE: | 10536 | case (int)ScriptBaseClass.PRIM_TEXTURE: |
8161 | if (remain < 1) | 10537 | if (remain < 1) |
8162 | return null; | 10538 | return new LSL_List(); |
8163 | 10539 | ||
8164 | int face = (int)rules.GetLSLIntegerItem(idx++); | 10540 | int face = (int)rules.GetLSLIntegerItem(idx++); |
8165 | Primitive.TextureEntry tex = part.Shape.Textures; | 10541 | Primitive.TextureEntry tex = part.Shape.Textures; |
@@ -8199,7 +10575,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8199 | 10575 | ||
8200 | case (int)ScriptBaseClass.PRIM_COLOR: | 10576 | case (int)ScriptBaseClass.PRIM_COLOR: |
8201 | if (remain < 1) | 10577 | if (remain < 1) |
8202 | return null; | 10578 | return new LSL_List(); |
8203 | 10579 | ||
8204 | face=(int)rules.GetLSLIntegerItem(idx++); | 10580 | face=(int)rules.GetLSLIntegerItem(idx++); |
8205 | 10581 | ||
@@ -8228,7 +10604,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8228 | 10604 | ||
8229 | case (int)ScriptBaseClass.PRIM_BUMP_SHINY: | 10605 | case (int)ScriptBaseClass.PRIM_BUMP_SHINY: |
8230 | if (remain < 1) | 10606 | if (remain < 1) |
8231 | return null; | 10607 | return new LSL_List(); |
8232 | 10608 | ||
8233 | face=(int)rules.GetLSLIntegerItem(idx++); | 10609 | face=(int)rules.GetLSLIntegerItem(idx++); |
8234 | 10610 | ||
@@ -8259,9 +10635,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8259 | 10635 | ||
8260 | case (int)ScriptBaseClass.PRIM_FULLBRIGHT: | 10636 | case (int)ScriptBaseClass.PRIM_FULLBRIGHT: |
8261 | if (remain < 1) | 10637 | if (remain < 1) |
8262 | return null; | 10638 | return new LSL_List(); |
8263 | 10639 | ||
8264 | face=(int)rules.GetLSLIntegerItem(idx++); | 10640 | face = (int)rules.GetLSLIntegerItem(idx++); |
8265 | 10641 | ||
8266 | tex = part.Shape.Textures; | 10642 | tex = part.Shape.Textures; |
8267 | if (face == ScriptBaseClass.ALL_SIDES) | 10643 | if (face == ScriptBaseClass.ALL_SIDES) |
@@ -8301,7 +10677,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8301 | 10677 | ||
8302 | case (int)ScriptBaseClass.PRIM_TEXGEN: | 10678 | case (int)ScriptBaseClass.PRIM_TEXGEN: |
8303 | if (remain < 1) | 10679 | if (remain < 1) |
8304 | return null; | 10680 | return new LSL_List(); |
8305 | 10681 | ||
8306 | face=(int)rules.GetLSLIntegerItem(idx++); | 10682 | face=(int)rules.GetLSLIntegerItem(idx++); |
8307 | 10683 | ||
@@ -8342,7 +10718,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8342 | 10718 | ||
8343 | case (int)ScriptBaseClass.PRIM_GLOW: | 10719 | case (int)ScriptBaseClass.PRIM_GLOW: |
8344 | if (remain < 1) | 10720 | if (remain < 1) |
8345 | return null; | 10721 | return new LSL_List(); |
8346 | 10722 | ||
8347 | face=(int)rules.GetLSLIntegerItem(idx++); | 10723 | face=(int)rules.GetLSLIntegerItem(idx++); |
8348 | 10724 | ||
@@ -8371,7 +10747,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8371 | res.Add(new LSL_Vector(textColor.R, | 10747 | res.Add(new LSL_Vector(textColor.R, |
8372 | textColor.G, | 10748 | textColor.G, |
8373 | textColor.B)); | 10749 | textColor.B)); |
8374 | res.Add(new LSL_Float(textColor.A)); | 10750 | res.Add(new LSL_Float(1.0 - textColor.A)); |
8375 | break; | 10751 | break; |
8376 | case (int)ScriptBaseClass.PRIM_NAME: | 10752 | case (int)ScriptBaseClass.PRIM_NAME: |
8377 | res.Add(new LSL_String(part.Name)); | 10753 | res.Add(new LSL_String(part.Name)); |
@@ -8380,7 +10756,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8380 | res.Add(new LSL_String(part.Description)); | 10756 | res.Add(new LSL_String(part.Description)); |
8381 | break; | 10757 | break; |
8382 | case (int)ScriptBaseClass.PRIM_ROT_LOCAL: | 10758 | case (int)ScriptBaseClass.PRIM_ROT_LOCAL: |
8383 | res.Add(new LSL_Rotation(part.RotationOffset.X, part.RotationOffset.Y, part.RotationOffset.Z, part.RotationOffset.W)); | 10759 | res.Add(new LSL_Rotation(part.RotationOffset)); |
8384 | break; | 10760 | break; |
8385 | case (int)ScriptBaseClass.PRIM_POS_LOCAL: | 10761 | case (int)ScriptBaseClass.PRIM_POS_LOCAL: |
8386 | res.Add(new LSL_Vector(GetPartLocalPos(part))); | 10762 | res.Add(new LSL_Vector(GetPartLocalPos(part))); |
@@ -8395,27 +10771,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8395 | )); | 10771 | )); |
8396 | break; | 10772 | break; |
8397 | case (int)ScriptBaseClass.PRIM_LINK_TARGET: | 10773 | case (int)ScriptBaseClass.PRIM_LINK_TARGET: |
8398 | if(remain < 3) | 10774 | |
8399 | return null; | 10775 | // TODO: Should be issuing a runtime script warning in this case. |
10776 | if (remain < 2) | ||
10777 | return new LSL_List(); | ||
8400 | 10778 | ||
8401 | return rules.GetSublist(idx, -1); | 10779 | return rules.GetSublist(idx, -1); |
8402 | } | 10780 | } |
8403 | } | 10781 | } |
8404 | 10782 | ||
8405 | return null; | 10783 | return new LSL_List(); |
8406 | } | 10784 | } |
8407 | 10785 | ||
8408 | public LSL_List llGetPrimMediaParams(int face, LSL_List rules) | 10786 | public LSL_List llGetPrimMediaParams(int face, LSL_List rules) |
8409 | { | 10787 | { |
8410 | m_host.AddScriptLPS(1); | 10788 | m_host.AddScriptLPS(1); |
8411 | ScriptSleep(1000); | 10789 | ScriptSleep(m_sleepMsOnGetPrimMediaParams); |
8412 | return GetPrimMediaParams(m_host, face, rules); | 10790 | return GetPrimMediaParams(m_host, face, rules); |
8413 | } | 10791 | } |
8414 | 10792 | ||
8415 | public LSL_List llGetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules) | 10793 | public LSL_List llGetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules) |
8416 | { | 10794 | { |
8417 | m_host.AddScriptLPS(1); | 10795 | m_host.AddScriptLPS(1); |
8418 | ScriptSleep(1000); | 10796 | ScriptSleep(m_sleepMsOnGetLinkMedia); |
8419 | if (link == ScriptBaseClass.LINK_ROOT) | 10797 | if (link == ScriptBaseClass.LINK_ROOT) |
8420 | return GetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules); | 10798 | return GetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules); |
8421 | else if (link == ScriptBaseClass.LINK_THIS) | 10799 | else if (link == ScriptBaseClass.LINK_THIS) |
@@ -8535,14 +10913,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8535 | public LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules) | 10913 | public LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules) |
8536 | { | 10914 | { |
8537 | m_host.AddScriptLPS(1); | 10915 | m_host.AddScriptLPS(1); |
8538 | ScriptSleep(1000); | 10916 | ScriptSleep(m_sleepMsOnSetPrimMediaParams); |
8539 | return SetPrimMediaParams(m_host, face, rules); | 10917 | return SetPrimMediaParams(m_host, face, rules); |
8540 | } | 10918 | } |
8541 | 10919 | ||
8542 | public LSL_Integer llSetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules) | 10920 | public LSL_Integer llSetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules) |
8543 | { | 10921 | { |
8544 | m_host.AddScriptLPS(1); | 10922 | m_host.AddScriptLPS(1); |
8545 | ScriptSleep(1000); | 10923 | ScriptSleep(m_sleepMsOnSetLinkMedia); |
8546 | if (link == ScriptBaseClass.LINK_ROOT) | 10924 | if (link == ScriptBaseClass.LINK_ROOT) |
8547 | return SetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules); | 10925 | return SetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules); |
8548 | else if (link == ScriptBaseClass.LINK_THIS) | 10926 | else if (link == ScriptBaseClass.LINK_THIS) |
@@ -8661,14 +11039,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8661 | public LSL_Integer llClearPrimMedia(LSL_Integer face) | 11039 | public LSL_Integer llClearPrimMedia(LSL_Integer face) |
8662 | { | 11040 | { |
8663 | m_host.AddScriptLPS(1); | 11041 | m_host.AddScriptLPS(1); |
8664 | ScriptSleep(1000); | 11042 | ScriptSleep(m_sleepMsOnClearPrimMedia); |
8665 | return ClearPrimMedia(m_host, face); | 11043 | return ClearPrimMedia(m_host, face); |
8666 | } | 11044 | } |
8667 | 11045 | ||
8668 | public LSL_Integer llClearLinkMedia(LSL_Integer link, LSL_Integer face) | 11046 | public LSL_Integer llClearLinkMedia(LSL_Integer link, LSL_Integer face) |
8669 | { | 11047 | { |
8670 | m_host.AddScriptLPS(1); | 11048 | m_host.AddScriptLPS(1); |
8671 | ScriptSleep(1000); | 11049 | ScriptSleep(m_sleepMsOnClearLinkMedia); |
8672 | if (link == ScriptBaseClass.LINK_ROOT) | 11050 | if (link == ScriptBaseClass.LINK_ROOT) |
8673 | return ClearPrimMedia(m_host.ParentGroup.RootPart, face); | 11051 | return ClearPrimMedia(m_host.ParentGroup.RootPart, face); |
8674 | else if (link == ScriptBaseClass.LINK_THIS) | 11052 | else if (link == ScriptBaseClass.LINK_THIS) |
@@ -9307,7 +11685,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9307 | 11685 | ||
9308 | if (item == null) | 11686 | if (item == null) |
9309 | { | 11687 | { |
9310 | llSay(0, "No item name '" + item + "'"); | 11688 | Error("llGetInventoryCreator", "Can't find item '" + item + "'"); |
9311 | 11689 | ||
9312 | return String.Empty; | 11690 | return String.Empty; |
9313 | } | 11691 | } |
@@ -9355,7 +11733,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9355 | case ScriptBaseClass.DATA_SIM_POS: | 11733 | case ScriptBaseClass.DATA_SIM_POS: |
9356 | if (info == null) | 11734 | if (info == null) |
9357 | { | 11735 | { |
9358 | ScriptSleep(1000); | 11736 | ScriptSleep(m_sleepMsOnRequestSimulatorData); |
9359 | return UUID.Zero.ToString(); | 11737 | return UUID.Zero.ToString(); |
9360 | } | 11738 | } |
9361 | 11739 | ||
@@ -9402,7 +11780,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9402 | case ScriptBaseClass.DATA_SIM_RATING: | 11780 | case ScriptBaseClass.DATA_SIM_RATING: |
9403 | if (info == null) | 11781 | if (info == null) |
9404 | { | 11782 | { |
9405 | ScriptSleep(1000); | 11783 | ScriptSleep(m_sleepMsOnRequestSimulatorData); |
9406 | return UUID.Zero.ToString(); | 11784 | return UUID.Zero.ToString(); |
9407 | } | 11785 | } |
9408 | int access = info.Maturity; | 11786 | int access = info.Maturity; |
@@ -9421,7 +11799,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9421 | reply = "OpenSim"; | 11799 | reply = "OpenSim"; |
9422 | break; | 11800 | break; |
9423 | default: | 11801 | default: |
9424 | ScriptSleep(1000); | 11802 | ScriptSleep(m_sleepMsOnRequestSimulatorData); |
9425 | return UUID.Zero.ToString(); // Raise no event | 11803 | return UUID.Zero.ToString(); // Raise no event |
9426 | } | 11804 | } |
9427 | UUID rq = UUID.Random(); | 11805 | UUID rq = UUID.Random(); |
@@ -9432,7 +11810,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9432 | AsyncCommands. | 11810 | AsyncCommands. |
9433 | DataserverPlugin.DataserverReply(rq.ToString(), reply); | 11811 | DataserverPlugin.DataserverReply(rq.ToString(), reply); |
9434 | 11812 | ||
9435 | ScriptSleep(1000); | 11813 | ScriptSleep(m_sleepMsOnRequestSimulatorData); |
9436 | return tid.ToString(); | 11814 | return tid.ToString(); |
9437 | } | 11815 | } |
9438 | catch(Exception) | 11816 | catch(Exception) |
@@ -9441,6 +11819,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9441 | return UUID.Zero.ToString(); | 11819 | return UUID.Zero.ToString(); |
9442 | } | 11820 | } |
9443 | } | 11821 | } |
11822 | |||
9444 | public LSL_String llRequestURL() | 11823 | public LSL_String llRequestURL() |
9445 | { | 11824 | { |
9446 | m_host.AddScriptLPS(1); | 11825 | m_host.AddScriptLPS(1); |
@@ -9499,7 +11878,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9499 | 11878 | ||
9500 | public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end) | 11879 | public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end) |
9501 | { | 11880 | { |
9502 | LSL_List pref = null; | 11881 | LSL_List pref; |
9503 | 11882 | ||
9504 | m_host.AddScriptLPS(1); | 11883 | m_host.AddScriptLPS(1); |
9505 | 11884 | ||
@@ -9576,7 +11955,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9576 | dm.SendUrlToUser( | 11955 | dm.SendUrlToUser( |
9577 | new UUID(avatar_id), m_host.Name, m_host.UUID, m_host.OwnerID, false, message, url); | 11956 | new UUID(avatar_id), m_host.Name, m_host.UUID, m_host.OwnerID, false, message, url); |
9578 | 11957 | ||
9579 | ScriptSleep(10000); | 11958 | ScriptSleep(m_sleepMsOnLoadURL); |
9580 | } | 11959 | } |
9581 | 11960 | ||
9582 | public void llParcelMediaCommandList(LSL_List commandList) | 11961 | public void llParcelMediaCommandList(LSL_List commandList) |
@@ -9588,7 +11967,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9588 | 11967 | ||
9589 | // according to the docs, this command only works if script owner and land owner are the same | 11968 | // according to the docs, this command only works if script owner and land owner are the same |
9590 | // lets add estate owners and gods, too, and use the generic permission check. | 11969 | // lets add estate owners and gods, too, and use the generic permission check. |
9591 | ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); | 11970 | ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition); |
9592 | if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia)) return; | 11971 | if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia)) return; |
9593 | 11972 | ||
9594 | bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)? | 11973 | bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)? |
@@ -9625,7 +12004,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9625 | presence = World.GetScenePresence(agentID); | 12004 | presence = World.GetScenePresence(agentID); |
9626 | } | 12005 | } |
9627 | } | 12006 | } |
9628 | else ShoutError("The argument of PARCEL_MEDIA_COMMAND_AGENT must be a key"); | 12007 | else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AGENT must be a key"); |
9629 | ++i; | 12008 | ++i; |
9630 | } | 12009 | } |
9631 | break; | 12010 | break; |
@@ -9656,7 +12035,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9656 | url = (LSL_String)commandList.Data[i + 1]; | 12035 | url = (LSL_String)commandList.Data[i + 1]; |
9657 | update = true; | 12036 | update = true; |
9658 | } | 12037 | } |
9659 | else ShoutError("The argument of PARCEL_MEDIA_COMMAND_URL must be a string."); | 12038 | else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_URL must be a string"); |
9660 | ++i; | 12039 | ++i; |
9661 | } | 12040 | } |
9662 | break; | 12041 | break; |
@@ -9669,7 +12048,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9669 | texture = (LSL_String)commandList.Data[i + 1]; | 12048 | texture = (LSL_String)commandList.Data[i + 1]; |
9670 | update = true; | 12049 | update = true; |
9671 | } | 12050 | } |
9672 | else ShoutError("The argument of PARCEL_MEDIA_COMMAND_TEXTURE must be a string or key."); | 12051 | else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TEXTURE must be a string or a key"); |
9673 | ++i; | 12052 | ++i; |
9674 | } | 12053 | } |
9675 | break; | 12054 | break; |
@@ -9681,7 +12060,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9681 | { | 12060 | { |
9682 | time = (float)(LSL_Float)commandList.Data[i + 1]; | 12061 | time = (float)(LSL_Float)commandList.Data[i + 1]; |
9683 | } | 12062 | } |
9684 | else ShoutError("The argument of PARCEL_MEDIA_COMMAND_TIME must be a float."); | 12063 | else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TIME must be a float"); |
9685 | ++i; | 12064 | ++i; |
9686 | } | 12065 | } |
9687 | break; | 12066 | break; |
@@ -9695,7 +12074,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9695 | update = true; | 12074 | update = true; |
9696 | } | 12075 | } |
9697 | 12076 | ||
9698 | else ShoutError("The argument of PARCEL_MEDIA_COMMAND_AUTO_ALIGN must be an integer."); | 12077 | else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AUTO_ALIGN must be an integer"); |
9699 | ++i; | 12078 | ++i; |
9700 | } | 12079 | } |
9701 | break; | 12080 | break; |
@@ -9708,7 +12087,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9708 | mediaType = (LSL_String)commandList.Data[i + 1]; | 12087 | mediaType = (LSL_String)commandList.Data[i + 1]; |
9709 | update = true; | 12088 | update = true; |
9710 | } | 12089 | } |
9711 | else ShoutError("The argument of PARCEL_MEDIA_COMMAND_TYPE must be a string."); | 12090 | else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TYPE must be a string"); |
9712 | ++i; | 12091 | ++i; |
9713 | } | 12092 | } |
9714 | break; | 12093 | break; |
@@ -9721,7 +12100,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9721 | description = (LSL_String)commandList.Data[i + 1]; | 12100 | description = (LSL_String)commandList.Data[i + 1]; |
9722 | update = true; | 12101 | update = true; |
9723 | } | 12102 | } |
9724 | else ShoutError("The argument of PARCEL_MEDIA_COMMAND_DESC must be a string."); | 12103 | else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_DESC must be a string"); |
9725 | ++i; | 12104 | ++i; |
9726 | } | 12105 | } |
9727 | break; | 12106 | break; |
@@ -9737,15 +12116,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9737 | height = (LSL_Integer)commandList.Data[i + 2]; | 12116 | height = (LSL_Integer)commandList.Data[i + 2]; |
9738 | update = true; | 12117 | update = true; |
9739 | } | 12118 | } |
9740 | else ShoutError("The second argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer."); | 12119 | else Error("llParcelMediaCommandList", "The second argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer"); |
9741 | } | 12120 | } |
9742 | else ShoutError("The first argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer."); | 12121 | else Error("llParcelMediaCommandList", "The first argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer"); |
9743 | i += 2; | 12122 | i += 2; |
9744 | } | 12123 | } |
9745 | break; | 12124 | break; |
9746 | 12125 | ||
9747 | default: | 12126 | default: |
9748 | NotImplemented("llParcelMediaCommandList parameter not supported yet: " + Enum.Parse(typeof(ParcelMediaCommandEnum), commandList.Data[i].ToString()).ToString()); | 12127 | NotImplemented("llParcelMediaCommandList", "Parameter not supported yet: " + Enum.Parse(typeof(ParcelMediaCommandEnum), commandList.Data[i].ToString()).ToString()); |
9749 | break; | 12128 | break; |
9750 | }//end switch | 12129 | }//end switch |
9751 | }//end for | 12130 | }//end for |
@@ -9819,7 +12198,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9819 | time); | 12198 | time); |
9820 | } | 12199 | } |
9821 | } | 12200 | } |
9822 | ScriptSleep(2000); | 12201 | ScriptSleep(m_sleepMsOnParcelMediaCommandList); |
9823 | } | 12202 | } |
9824 | 12203 | ||
9825 | public LSL_List llParcelMediaQuery(LSL_List aList) | 12204 | public LSL_List llParcelMediaQuery(LSL_List aList) |
@@ -9853,13 +12232,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9853 | break; | 12232 | break; |
9854 | default: | 12233 | default: |
9855 | ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url; | 12234 | ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url; |
9856 | NotImplemented("llParcelMediaQuery parameter do not supported yet: " + Enum.Parse(mediaCommandEnum.GetType() , aList.Data[i].ToString()).ToString()); | 12235 | NotImplemented("llParcelMediaQuery", "Parameter not supported yet: " + Enum.Parse(mediaCommandEnum.GetType() , aList.Data[i].ToString()).ToString()); |
9857 | break; | 12236 | break; |
9858 | } | 12237 | } |
9859 | 12238 | ||
9860 | } | 12239 | } |
9861 | } | 12240 | } |
9862 | ScriptSleep(2000); | 12241 | ScriptSleep(m_sleepMsOnParcelMediaQuery); |
9863 | return list; | 12242 | return list; |
9864 | } | 12243 | } |
9865 | 12244 | ||
@@ -9868,7 +12247,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9868 | m_host.AddScriptLPS(1); | 12247 | m_host.AddScriptLPS(1); |
9869 | Int64 tmp = 0; | 12248 | Int64 tmp = 0; |
9870 | Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp); | 12249 | Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp); |
9871 | ScriptSleep(1000); | 12250 | ScriptSleep(m_sleepMsOnModPow); |
9872 | return Convert.ToInt32(tmp); | 12251 | return Convert.ToInt32(tmp); |
9873 | } | 12252 | } |
9874 | 12253 | ||
@@ -9890,7 +12269,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9890 | 12269 | ||
9891 | if (quick_pay_buttons.Data.Length < 4) | 12270 | if (quick_pay_buttons.Data.Length < 4) |
9892 | { | 12271 | { |
9893 | LSLError("List must have at least 4 elements"); | 12272 | Error("llSetPayPrice", "List must have at least 4 elements"); |
9894 | return; | 12273 | return; |
9895 | } | 12274 | } |
9896 | m_host.ParentGroup.RootPart.PayPrice[0]=price; | 12275 | m_host.ParentGroup.RootPart.PayPrice[0]=price; |
@@ -9907,21 +12286,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9907 | m_host.AddScriptLPS(1); | 12286 | m_host.AddScriptLPS(1); |
9908 | 12287 | ||
9909 | if (m_item.PermsGranter == UUID.Zero) | 12288 | if (m_item.PermsGranter == UUID.Zero) |
9910 | return new LSL_Vector(); | 12289 | return Vector3.Zero; |
9911 | 12290 | ||
9912 | if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) | 12291 | if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) |
9913 | { | 12292 | { |
9914 | ShoutError("No permissions to track the camera"); | 12293 | Error("llGetCameraPos", "No permissions to track the camera"); |
9915 | return new LSL_Vector(); | 12294 | return Vector3.Zero; |
9916 | } | 12295 | } |
9917 | 12296 | ||
9918 | ScenePresence presence = World.GetScenePresence(m_host.OwnerID); | 12297 | ScenePresence presence = World.GetScenePresence(m_host.OwnerID); |
9919 | if (presence != null) | 12298 | if (presence != null) |
9920 | { | 12299 | { |
9921 | LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z); | 12300 | LSL_Vector pos = new LSL_Vector(presence.CameraPosition); |
9922 | return pos; | 12301 | return pos; |
9923 | } | 12302 | } |
9924 | return new LSL_Vector(); | 12303 | |
12304 | return Vector3.Zero; | ||
9925 | } | 12305 | } |
9926 | 12306 | ||
9927 | public LSL_Rotation llGetCameraRot() | 12307 | public LSL_Rotation llGetCameraRot() |
@@ -9929,42 +12309,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9929 | m_host.AddScriptLPS(1); | 12309 | m_host.AddScriptLPS(1); |
9930 | 12310 | ||
9931 | if (m_item.PermsGranter == UUID.Zero) | 12311 | if (m_item.PermsGranter == UUID.Zero) |
9932 | return new LSL_Rotation(); | 12312 | return Quaternion.Identity; |
9933 | 12313 | ||
9934 | if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) | 12314 | if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) |
9935 | { | 12315 | { |
9936 | ShoutError("No permissions to track the camera"); | 12316 | Error("llGetCameraRot", "No permissions to track the camera"); |
9937 | return new LSL_Rotation(); | 12317 | return Quaternion.Identity; |
9938 | } | 12318 | } |
9939 | 12319 | ||
9940 | ScenePresence presence = World.GetScenePresence(m_host.OwnerID); | 12320 | ScenePresence presence = World.GetScenePresence(m_host.OwnerID); |
9941 | if (presence != null) | 12321 | if (presence != null) |
9942 | { | 12322 | { |
9943 | return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W); | 12323 | return new LSL_Rotation(presence.CameraRotation); |
9944 | } | 12324 | } |
9945 | 12325 | ||
9946 | return new LSL_Rotation(); | 12326 | return Quaternion.Identity; |
9947 | } | 12327 | } |
9948 | 12328 | ||
9949 | /// <summary> | ||
9950 | /// The SL implementation does nothing, it is deprecated | ||
9951 | /// This duplicates SL | ||
9952 | /// </summary> | ||
9953 | public void llSetPrimURL(string url) | 12329 | public void llSetPrimURL(string url) |
9954 | { | 12330 | { |
9955 | m_host.AddScriptLPS(1); | 12331 | m_host.AddScriptLPS(1); |
9956 | ScriptSleep(2000); | 12332 | Deprecated("llSetPrimURL", "Use llSetPrimMediaParams instead"); |
12333 | ScriptSleep(m_sleepMsOnSetPrimURL); | ||
9957 | } | 12334 | } |
9958 | 12335 | ||
9959 | /// <summary> | ||
9960 | /// The SL implementation shouts an error, it is deprecated | ||
9961 | /// This duplicates SL | ||
9962 | /// </summary> | ||
9963 | public void llRefreshPrimURL() | 12336 | public void llRefreshPrimURL() |
9964 | { | 12337 | { |
9965 | m_host.AddScriptLPS(1); | 12338 | m_host.AddScriptLPS(1); |
9966 | ShoutError("llRefreshPrimURL - not yet supported"); | 12339 | Deprecated("llRefreshPrimURL"); |
9967 | ScriptSleep(20000); | 12340 | ScriptSleep(m_sleepMsOnRefreshPrimURL); |
9968 | } | 12341 | } |
9969 | 12342 | ||
9970 | public LSL_String llEscapeURL(string url) | 12343 | public LSL_String llEscapeURL(string url) |
@@ -10005,14 +12378,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10005 | avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name, | 12378 | avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name, |
10006 | simname, pos, lookAt); | 12379 | simname, pos, lookAt); |
10007 | } | 12380 | } |
10008 | ScriptSleep(1000); | 12381 | ScriptSleep(m_sleepMsOnMapDestination); |
10009 | } | 12382 | } |
10010 | 12383 | ||
10011 | public void llAddToLandBanList(string avatar, double hours) | 12384 | public void llAddToLandBanList(string avatar, double hours) |
10012 | { | 12385 | { |
10013 | m_host.AddScriptLPS(1); | 12386 | m_host.AddScriptLPS(1); |
10014 | UUID key; | 12387 | UUID key; |
10015 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); | 12388 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); |
10016 | if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned)) | 12389 | if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned)) |
10017 | { | 12390 | { |
10018 | int expires = 0; | 12391 | int expires = 0; |
@@ -10046,14 +12419,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10046 | World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land); | 12419 | World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land); |
10047 | } | 12420 | } |
10048 | } | 12421 | } |
10049 | ScriptSleep(100); | 12422 | ScriptSleep(m_sleepMsOnAddToLandBanList); |
10050 | } | 12423 | } |
10051 | 12424 | ||
10052 | public void llRemoveFromLandPassList(string avatar) | 12425 | public void llRemoveFromLandPassList(string avatar) |
10053 | { | 12426 | { |
10054 | m_host.AddScriptLPS(1); | 12427 | m_host.AddScriptLPS(1); |
10055 | UUID key; | 12428 | UUID key; |
10056 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); | 12429 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); |
10057 | if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageAllowed)) | 12430 | if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageAllowed)) |
10058 | { | 12431 | { |
10059 | if (UUID.TryParse(avatar, out key)) | 12432 | if (UUID.TryParse(avatar, out key)) |
@@ -10073,14 +12446,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10073 | } | 12446 | } |
10074 | } | 12447 | } |
10075 | } | 12448 | } |
10076 | ScriptSleep(100); | 12449 | ScriptSleep(m_sleepMsOnRemoveFromLandPassList); |
10077 | } | 12450 | } |
10078 | 12451 | ||
10079 | public void llRemoveFromLandBanList(string avatar) | 12452 | public void llRemoveFromLandBanList(string avatar) |
10080 | { | 12453 | { |
10081 | m_host.AddScriptLPS(1); | 12454 | m_host.AddScriptLPS(1); |
10082 | UUID key; | 12455 | UUID key; |
10083 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); | 12456 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); |
10084 | if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned)) | 12457 | if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned)) |
10085 | { | 12458 | { |
10086 | if (UUID.TryParse(avatar, out key)) | 12459 | if (UUID.TryParse(avatar, out key)) |
@@ -10100,7 +12473,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10100 | } | 12473 | } |
10101 | } | 12474 | } |
10102 | } | 12475 | } |
10103 | ScriptSleep(100); | 12476 | ScriptSleep(m_sleepMsOnRemoveFromLandBanList); |
10104 | } | 12477 | } |
10105 | 12478 | ||
10106 | public void llSetCameraParams(LSL_List rules) | 12479 | public void llSetCameraParams(LSL_List rules) |
@@ -10128,19 +12501,84 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10128 | 12501 | ||
10129 | SortedDictionary<int, float> parameters = new SortedDictionary<int, float>(); | 12502 | SortedDictionary<int, float> parameters = new SortedDictionary<int, float>(); |
10130 | object[] data = rules.Data; | 12503 | object[] data = rules.Data; |
10131 | for (int i = 0; i < data.Length; ++i) { | 12504 | for (int i = 0; i < data.Length; ++i) |
10132 | int type = Convert.ToInt32(data[i++].ToString()); | 12505 | { |
12506 | int type; | ||
12507 | try | ||
12508 | { | ||
12509 | type = Convert.ToInt32(data[i++].ToString()); | ||
12510 | } | ||
12511 | catch | ||
12512 | { | ||
12513 | Error("llSetCameraParams", string.Format("Invalid camera param type {0}", data[i - 1])); | ||
12514 | return; | ||
12515 | } | ||
10133 | if (i >= data.Length) break; // odd number of entries => ignore the last | 12516 | if (i >= data.Length) break; // odd number of entries => ignore the last |
10134 | 12517 | ||
10135 | // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3) | 12518 | // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3) |
10136 | switch (type) { | 12519 | switch (type) |
12520 | { | ||
10137 | case ScriptBaseClass.CAMERA_FOCUS: | 12521 | case ScriptBaseClass.CAMERA_FOCUS: |
10138 | case ScriptBaseClass.CAMERA_FOCUS_OFFSET: | 12522 | case ScriptBaseClass.CAMERA_FOCUS_OFFSET: |
10139 | case ScriptBaseClass.CAMERA_POSITION: | 12523 | case ScriptBaseClass.CAMERA_POSITION: |
10140 | LSL_Vector v = (LSL_Vector)data[i]; | 12524 | LSL_Vector v = (LSL_Vector)data[i]; |
10141 | parameters.Add(type + 1, (float)v.x); | 12525 | try |
10142 | parameters.Add(type + 2, (float)v.y); | 12526 | { |
10143 | parameters.Add(type + 3, (float)v.z); | 12527 | parameters.Add(type + 1, (float)v.x); |
12528 | } | ||
12529 | catch | ||
12530 | { | ||
12531 | switch(type) | ||
12532 | { | ||
12533 | case ScriptBaseClass.CAMERA_FOCUS: | ||
12534 | Error("llSetCameraParams", "CAMERA_FOCUS: Parameter x is invalid"); | ||
12535 | return; | ||
12536 | case ScriptBaseClass.CAMERA_FOCUS_OFFSET: | ||
12537 | Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter x is invalid"); | ||
12538 | return; | ||
12539 | case ScriptBaseClass.CAMERA_POSITION: | ||
12540 | Error("llSetCameraParams", "CAMERA_POSITION: Parameter x is invalid"); | ||
12541 | return; | ||
12542 | } | ||
12543 | } | ||
12544 | try | ||
12545 | { | ||
12546 | parameters.Add(type + 2, (float)v.y); | ||
12547 | } | ||
12548 | catch | ||
12549 | { | ||
12550 | switch(type) | ||
12551 | { | ||
12552 | case ScriptBaseClass.CAMERA_FOCUS: | ||
12553 | Error("llSetCameraParams", "CAMERA_FOCUS: Parameter y is invalid"); | ||
12554 | return; | ||
12555 | case ScriptBaseClass.CAMERA_FOCUS_OFFSET: | ||
12556 | Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter y is invalid"); | ||
12557 | return; | ||
12558 | case ScriptBaseClass.CAMERA_POSITION: | ||
12559 | Error("llSetCameraParams", "CAMERA_POSITION: Parameter y is invalid"); | ||
12560 | return; | ||
12561 | } | ||
12562 | } | ||
12563 | try | ||
12564 | { | ||
12565 | parameters.Add(type + 3, (float)v.z); | ||
12566 | } | ||
12567 | catch | ||
12568 | { | ||
12569 | switch(type) | ||
12570 | { | ||
12571 | case ScriptBaseClass.CAMERA_FOCUS: | ||
12572 | Error("llSetCameraParams", "CAMERA_FOCUS: Parameter z is invalid"); | ||
12573 | return; | ||
12574 | case ScriptBaseClass.CAMERA_FOCUS_OFFSET: | ||
12575 | Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter z is invalid"); | ||
12576 | return; | ||
12577 | case ScriptBaseClass.CAMERA_POSITION: | ||
12578 | Error("llSetCameraParams", "CAMERA_POSITION: Parameter z is invalid"); | ||
12579 | return; | ||
12580 | } | ||
12581 | } | ||
10144 | break; | 12582 | break; |
10145 | default: | 12583 | default: |
10146 | // TODO: clean that up as soon as the implicit casts are in | 12584 | // TODO: clean that up as soon as the implicit casts are in |
@@ -10148,7 +12586,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10148 | parameters.Add(type, (float)((LSL_Float)data[i]).value); | 12586 | parameters.Add(type, (float)((LSL_Float)data[i]).value); |
10149 | else if (data[i] is LSL_Integer) | 12587 | else if (data[i] is LSL_Integer) |
10150 | parameters.Add(type, (float)((LSL_Integer)data[i]).value); | 12588 | parameters.Add(type, (float)((LSL_Integer)data[i]).value); |
10151 | else parameters.Add(type, Convert.ToSingle(data[i])); | 12589 | else |
12590 | { | ||
12591 | try | ||
12592 | { | ||
12593 | parameters.Add(type, Convert.ToSingle(data[i])); | ||
12594 | } | ||
12595 | catch | ||
12596 | { | ||
12597 | Error("llSetCameraParams", string.Format("{0}: Parameter is invalid", type)); | ||
12598 | } | ||
12599 | } | ||
10152 | break; | 12600 | break; |
10153 | } | 12601 | } |
10154 | } | 12602 | } |
@@ -10264,9 +12712,60 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10264 | IHttpRequestModule httpScriptMod = | 12712 | IHttpRequestModule httpScriptMod = |
10265 | m_ScriptEngine.World.RequestModuleInterface<IHttpRequestModule>(); | 12713 | m_ScriptEngine.World.RequestModuleInterface<IHttpRequestModule>(); |
10266 | List<string> param = new List<string>(); | 12714 | List<string> param = new List<string>(); |
10267 | foreach (object o in parameters.Data) | 12715 | bool ok; |
12716 | Int32 flag; | ||
12717 | |||
12718 | for (int i = 0; i < parameters.Data.Length; i += 2) | ||
10268 | { | 12719 | { |
10269 | param.Add(o.ToString()); | 12720 | ok = Int32.TryParse(parameters.Data[i].ToString(), out flag); |
12721 | if (!ok || flag < 0 || | ||
12722 | flag > (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE) | ||
12723 | { | ||
12724 | Error("llHTTPRequest", "Parameter " + i.ToString() + " is an invalid flag"); | ||
12725 | } | ||
12726 | |||
12727 | param.Add(parameters.Data[i].ToString()); //Add parameter flag | ||
12728 | |||
12729 | if (flag != (int)HttpRequestConstants.HTTP_CUSTOM_HEADER) | ||
12730 | { | ||
12731 | param.Add(parameters.Data[i+1].ToString()); //Add parameter value | ||
12732 | } | ||
12733 | else | ||
12734 | { | ||
12735 | //Parameters are in pairs and custom header takes | ||
12736 | //arguments in pairs so adjust for header marker. | ||
12737 | ++i; | ||
12738 | |||
12739 | //Maximum of 8 headers are allowed based on the | ||
12740 | //Second Life documentation for llHTTPRequest. | ||
12741 | for (int count = 1; count <= 8; ++count) | ||
12742 | { | ||
12743 | //Enough parameters remaining for (another) header? | ||
12744 | if (parameters.Data.Length - i < 2) | ||
12745 | { | ||
12746 | //There must be at least one name/value pair for custom header | ||
12747 | if (count == 1) | ||
12748 | Error("llHTTPRequest", "Missing name/value for custom header at parameter " + i.ToString()); | ||
12749 | break; | ||
12750 | } | ||
12751 | |||
12752 | if (HttpStandardHeaders.Contains(parameters.Data[i].ToString(), StringComparer.OrdinalIgnoreCase)) | ||
12753 | Error("llHTTPRequest", "Name is invalid as a custom header at parameter " + i.ToString()); | ||
12754 | |||
12755 | param.Add(parameters.Data[i].ToString()); | ||
12756 | param.Add(parameters.Data[i+1].ToString()); | ||
12757 | |||
12758 | //Have we reached the end of the list of headers? | ||
12759 | //End is marked by a string with a single digit. | ||
12760 | if (i+2 >= parameters.Data.Length || | ||
12761 | Char.IsDigit(parameters.Data[i].ToString()[0])) | ||
12762 | { | ||
12763 | break; | ||
12764 | } | ||
12765 | |||
12766 | i += 2; | ||
12767 | } | ||
12768 | } | ||
10270 | } | 12769 | } |
10271 | 12770 | ||
10272 | Vector3 position = m_host.AbsolutePosition; | 12771 | Vector3 position = m_host.AbsolutePosition; |
@@ -10318,8 +12817,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10318 | } | 12817 | } |
10319 | } | 12818 | } |
10320 | 12819 | ||
12820 | HttpInitialRequestStatus status; | ||
10321 | UUID reqID | 12821 | UUID reqID |
10322 | = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body); | 12822 | = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body, out status); |
12823 | |||
12824 | if (status == HttpInitialRequestStatus.DISALLOWED_BY_FILTER) | ||
12825 | Error("llHttpRequest", string.Format("Request to {0} disallowed by filter", url)); | ||
10323 | 12826 | ||
10324 | if (reqID != UUID.Zero) | 12827 | if (reqID != UUID.Zero) |
10325 | return reqID.ToString(); | 12828 | return reqID.ToString(); |
@@ -10342,7 +12845,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10342 | public void llResetLandBanList() | 12845 | public void llResetLandBanList() |
10343 | { | 12846 | { |
10344 | m_host.AddScriptLPS(1); | 12847 | m_host.AddScriptLPS(1); |
10345 | LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData; | 12848 | LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData; |
10346 | if (land.OwnerID == m_host.OwnerID) | 12849 | if (land.OwnerID == m_host.OwnerID) |
10347 | { | 12850 | { |
10348 | foreach (LandAccessEntry entry in land.ParcelAccessList) | 12851 | foreach (LandAccessEntry entry in land.ParcelAccessList) |
@@ -10353,13 +12856,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10353 | } | 12856 | } |
10354 | } | 12857 | } |
10355 | } | 12858 | } |
10356 | ScriptSleep(100); | 12859 | ScriptSleep(m_sleepMsOnResetLandBanList); |
10357 | } | 12860 | } |
10358 | 12861 | ||
10359 | public void llResetLandPassList() | 12862 | public void llResetLandPassList() |
10360 | { | 12863 | { |
10361 | m_host.AddScriptLPS(1); | 12864 | m_host.AddScriptLPS(1); |
10362 | LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData; | 12865 | LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData; |
10363 | if (land.OwnerID == m_host.OwnerID) | 12866 | if (land.OwnerID == m_host.OwnerID) |
10364 | { | 12867 | { |
10365 | foreach (LandAccessEntry entry in land.ParcelAccessList) | 12868 | foreach (LandAccessEntry entry in land.ParcelAccessList) |
@@ -10370,18 +12873,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10370 | } | 12873 | } |
10371 | } | 12874 | } |
10372 | } | 12875 | } |
10373 | ScriptSleep(100); | 12876 | ScriptSleep(m_sleepMsOnResetLandPassList); |
10374 | } | 12877 | } |
10375 | 12878 | ||
10376 | public LSL_Integer llGetParcelPrimCount(LSL_Vector pos, int category, int sim_wide) | 12879 | public LSL_Integer llGetParcelPrimCount(LSL_Vector pos, int category, int sim_wide) |
10377 | { | 12880 | { |
10378 | m_host.AddScriptLPS(1); | 12881 | m_host.AddScriptLPS(1); |
10379 | 12882 | ||
10380 | ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y); | 12883 | ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y); |
10381 | 12884 | ||
10382 | if (lo == null) | 12885 | if (lo == null) |
10383 | return 0; | 12886 | return 0; |
10384 | 12887 | ||
10385 | IPrimCounts pc = lo.PrimCounts; | 12888 | IPrimCounts pc = lo.PrimCounts; |
10386 | 12889 | ||
10387 | if (sim_wide != ScriptBaseClass.FALSE) | 12890 | if (sim_wide != ScriptBaseClass.FALSE) |
@@ -10411,7 +12914,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10411 | else if (category == ScriptBaseClass.PARCEL_COUNT_TEMP) | 12914 | else if (category == ScriptBaseClass.PARCEL_COUNT_TEMP) |
10412 | return 0; // counts not implemented yet | 12915 | return 0; // counts not implemented yet |
10413 | } | 12916 | } |
10414 | 12917 | ||
10415 | return 0; | 12918 | return 0; |
10416 | } | 12919 | } |
10417 | 12920 | ||
@@ -10428,7 +12931,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10428 | ret.Add(new LSL_Integer(detectedParams.Value)); | 12931 | ret.Add(new LSL_Integer(detectedParams.Value)); |
10429 | } | 12932 | } |
10430 | } | 12933 | } |
10431 | ScriptSleep(2000); | 12934 | ScriptSleep(m_sleepMsOnGetParcelPrimOwners); |
10432 | return ret; | 12935 | return ret; |
10433 | } | 12936 | } |
10434 | 12937 | ||
@@ -10535,10 +13038,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10535 | ret.Add(new LSL_Vector((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z)); | 13038 | ret.Add(new LSL_Vector((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z)); |
10536 | break; | 13039 | break; |
10537 | case ScriptBaseClass.OBJECT_ROT: | 13040 | case ScriptBaseClass.OBJECT_ROT: |
10538 | ret.Add(new LSL_Rotation((double)av.Rotation.X, (double)av.Rotation.Y, (double)av.Rotation.Z, (double)av.Rotation.W)); | 13041 | ret.Add(new LSL_Rotation(av.GetWorldRotation())); |
10539 | break; | 13042 | break; |
10540 | case ScriptBaseClass.OBJECT_VELOCITY: | 13043 | case ScriptBaseClass.OBJECT_VELOCITY: |
10541 | ret.Add(new LSL_Vector(av.Velocity.X, av.Velocity.Y, av.Velocity.Z)); | 13044 | ret.Add(new LSL_Vector(av.GetWorldVelocity())); |
10542 | break; | 13045 | break; |
10543 | case ScriptBaseClass.OBJECT_OWNER: | 13046 | case ScriptBaseClass.OBJECT_OWNER: |
10544 | ret.Add(new LSL_String(id)); | 13047 | ret.Add(new LSL_String(id)); |
@@ -10603,6 +13106,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10603 | case ScriptBaseClass.OBJECT_TEMP_ON_REZ: | 13106 | case ScriptBaseClass.OBJECT_TEMP_ON_REZ: |
10604 | ret.Add(new LSL_Integer(0)); | 13107 | ret.Add(new LSL_Integer(0)); |
10605 | break; | 13108 | break; |
13109 | case ScriptBaseClass.OBJECT_RENDER_WEIGHT: | ||
13110 | ret.Add(new LSL_Integer(-1)); | ||
13111 | break; | ||
13112 | case ScriptBaseClass.OBJECT_HOVER_HEIGHT: | ||
13113 | ret.Add(new LSL_Float(0)); | ||
13114 | break; | ||
13115 | case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE: | ||
13116 | LSL_Float shapeType; | ||
13117 | if (av.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] != 0) | ||
13118 | shapeType = new LSL_Float(1); | ||
13119 | else | ||
13120 | shapeType = new LSL_Float(0); | ||
13121 | ret.Add(shapeType); | ||
13122 | break; | ||
13123 | case ScriptBaseClass.OBJECT_LAST_OWNER_ID: | ||
13124 | ret.Add(new LSL_Key(ScriptBaseClass.NULL_KEY)); | ||
13125 | break; | ||
10606 | default: | 13126 | default: |
10607 | // Invalid or unhandled constant. | 13127 | // Invalid or unhandled constant. |
10608 | ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL)); | 13128 | ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL)); |
@@ -10630,20 +13150,43 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10630 | ret.Add(new LSL_Vector(obj.AbsolutePosition.X, obj.AbsolutePosition.Y, obj.AbsolutePosition.Z)); | 13150 | ret.Add(new LSL_Vector(obj.AbsolutePosition.X, obj.AbsolutePosition.Y, obj.AbsolutePosition.Z)); |
10631 | break; | 13151 | break; |
10632 | case ScriptBaseClass.OBJECT_ROT: | 13152 | case ScriptBaseClass.OBJECT_ROT: |
13153 | Quaternion rot = Quaternion.Identity; | ||
13154 | |||
13155 | if (obj.ParentGroup.IsAttachment) | ||
10633 | { | 13156 | { |
10634 | Quaternion rot = Quaternion.Identity; | 13157 | ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar); |
10635 | 13158 | ||
13159 | if (sp != null) | ||
13160 | rot = sp.GetWorldRotation(); | ||
13161 | } | ||
13162 | else | ||
13163 | { | ||
10636 | if (obj.ParentGroup.RootPart == obj) | 13164 | if (obj.ParentGroup.RootPart == obj) |
10637 | rot = obj.ParentGroup.GroupRotation; | 13165 | rot = obj.ParentGroup.GroupRotation; |
10638 | else | 13166 | else |
10639 | rot = obj.GetWorldRotation(); | 13167 | rot = obj.GetWorldRotation(); |
10640 | |||
10641 | LSL_Rotation objrot = new LSL_Rotation(rot); | ||
10642 | ret.Add(objrot); | ||
10643 | } | 13168 | } |
13169 | |||
13170 | LSL_Rotation objrot = new LSL_Rotation(rot); | ||
13171 | ret.Add(objrot); | ||
13172 | |||
10644 | break; | 13173 | break; |
10645 | case ScriptBaseClass.OBJECT_VELOCITY: | 13174 | case ScriptBaseClass.OBJECT_VELOCITY: |
10646 | ret.Add(new LSL_Vector(obj.Velocity)); | 13175 | Vector3 vel = Vector3.Zero; |
13176 | |||
13177 | if (obj.ParentGroup.IsAttachment) | ||
13178 | { | ||
13179 | ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar); | ||
13180 | |||
13181 | if (sp != null) | ||
13182 | vel = sp.GetWorldVelocity(); | ||
13183 | } | ||
13184 | else | ||
13185 | { | ||
13186 | vel = obj.Velocity; | ||
13187 | } | ||
13188 | |||
13189 | ret.Add(vel); | ||
10647 | break; | 13190 | break; |
10648 | case ScriptBaseClass.OBJECT_OWNER: | 13191 | case ScriptBaseClass.OBJECT_OWNER: |
10649 | ret.Add(new LSL_String(obj.OwnerID.ToString())); | 13192 | ret.Add(new LSL_String(obj.OwnerID.ToString())); |
@@ -10744,6 +13287,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10744 | case ScriptBaseClass.OBJECT_TEMP_ON_REZ: | 13287 | case ScriptBaseClass.OBJECT_TEMP_ON_REZ: |
10745 | ret.Add(new LSL_Integer(obj.ParentGroup.IsTemporary ? 1 : 0)); | 13288 | ret.Add(new LSL_Integer(obj.ParentGroup.IsTemporary ? 1 : 0)); |
10746 | break; | 13289 | break; |
13290 | case ScriptBaseClass.OBJECT_RENDER_WEIGHT: | ||
13291 | ret.Add(new LSL_Integer(0)); | ||
13292 | break; | ||
13293 | case ScriptBaseClass.OBJECT_HOVER_HEIGHT: | ||
13294 | ret.Add(new LSL_Float(0)); | ||
13295 | break; | ||
13296 | case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE: | ||
13297 | ret.Add(new LSL_Float(-1)); | ||
13298 | break; | ||
13299 | case ScriptBaseClass.OBJECT_LAST_OWNER_ID: | ||
13300 | ret.Add(new LSL_Key(obj.ParentGroup.LastOwnerID.ToString())); | ||
13301 | break; | ||
10747 | default: | 13302 | default: |
10748 | // Invalid or unhandled constant. | 13303 | // Invalid or unhandled constant. |
10749 | ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL)); | 13304 | ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL)); |
@@ -10754,7 +13309,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10754 | return ret; | 13309 | return ret; |
10755 | } | 13310 | } |
10756 | } | 13311 | } |
10757 | 13312 | ||
10758 | return new LSL_List(); | 13313 | return new LSL_List(); |
10759 | } | 13314 | } |
10760 | 13315 | ||
@@ -10768,25 +13323,71 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10768 | return item.ItemID; | 13323 | return item.ItemID; |
10769 | } | 13324 | } |
10770 | 13325 | ||
10771 | internal void ShoutError(string msg) | 13326 | /// <summary> |
13327 | /// Reports the script error in the viewer's Script Warning/Error dialog and shouts it on the debug channel. | ||
13328 | /// </summary> | ||
13329 | /// <param name="command">The name of the command that generated the error.</param> | ||
13330 | /// <param name="message">The error message to report to the user.</param> | ||
13331 | internal void Error(string command, string message) | ||
10772 | { | 13332 | { |
10773 | llShout(ScriptBaseClass.DEBUG_CHANNEL, msg); | 13333 | string text = command + ": " + message; |
13334 | if (text.Length > 1023) | ||
13335 | { | ||
13336 | text = text.Substring(0, 1023); | ||
13337 | } | ||
13338 | |||
13339 | World.SimChat(Utils.StringToBytes(text), ChatTypeEnum.DebugChannel, ScriptBaseClass.DEBUG_CHANNEL, | ||
13340 | m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false); | ||
13341 | |||
13342 | IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); | ||
13343 | if (wComm != null) | ||
13344 | { | ||
13345 | wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, text); | ||
13346 | } | ||
10774 | } | 13347 | } |
10775 | 13348 | ||
10776 | internal void NotImplemented(string command) | 13349 | /// <summary> |
13350 | /// Reports that the command is not implemented as a script error. | ||
13351 | /// </summary> | ||
13352 | /// <param name="command">The name of the command that is not implemented.</param> | ||
13353 | /// <param name="message">Additional information to report to the user. (Optional)</param> | ||
13354 | internal void NotImplemented(string command, string message = "") | ||
10777 | { | 13355 | { |
10778 | if (throwErrorOnNotImplemented) | 13356 | if (throwErrorOnNotImplemented) |
10779 | throw new NotImplementedException("Command not implemented: " + command); | 13357 | { |
10780 | } | 13358 | if (message != "") |
13359 | { | ||
13360 | message = " - " + message; | ||
13361 | } | ||
10781 | 13362 | ||
10782 | internal void Deprecated(string command) | 13363 | throw new NotImplementedException("Command not implemented: " + command + message); |
10783 | { | 13364 | } |
10784 | throw new ScriptException("Command deprecated: " + command); | 13365 | else |
13366 | { | ||
13367 | string text = "Command not implemented"; | ||
13368 | if (message != "") | ||
13369 | { | ||
13370 | text = text + " - " + message; | ||
13371 | } | ||
13372 | |||
13373 | Error(command, text); | ||
13374 | } | ||
10785 | } | 13375 | } |
10786 | 13376 | ||
10787 | internal void LSLError(string msg) | 13377 | /// <summary> |
13378 | /// Reports that the command is deprecated as a script error. | ||
13379 | /// </summary> | ||
13380 | /// <param name="command">The name of the command that is deprecated.</param> | ||
13381 | /// <param name="message">Additional information to report to the user. (Optional)</param> | ||
13382 | internal void Deprecated(string command, string message = "") | ||
10788 | { | 13383 | { |
10789 | throw new ScriptException("LSL Runtime Error: " + msg); | 13384 | string text = "Command deprecated"; |
13385 | if (message != "") | ||
13386 | { | ||
13387 | text = text + " - " + message; | ||
13388 | } | ||
13389 | |||
13390 | Error(command, text); | ||
10790 | } | 13391 | } |
10791 | 13392 | ||
10792 | public delegate void AssetRequestCallback(UUID assetID, AssetBase asset); | 13393 | public delegate void AssetRequestCallback(UUID assetID, AssetBase asset); |
@@ -10818,20 +13419,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10818 | if (assetID == UUID.Zero) | 13419 | if (assetID == UUID.Zero) |
10819 | { | 13420 | { |
10820 | // => complain loudly, as specified by the LSL docs | 13421 | // => complain loudly, as specified by the LSL docs |
10821 | ShoutError("Notecard '" + name + "' could not be found."); | 13422 | Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'"); |
10822 | 13423 | ||
10823 | return UUID.Zero.ToString(); | 13424 | return UUID.Zero.ToString(); |
10824 | } | 13425 | } |
10825 | 13426 | ||
13427 | string reqIdentifier = UUID.Random().ToString(); | ||
13428 | |||
10826 | // was: UUID tid = tid = AsyncCommands. | 13429 | // was: UUID tid = tid = AsyncCommands. |
10827 | UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString()); | 13430 | UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier); |
10828 | 13431 | ||
10829 | if (NotecardCache.IsCached(assetID)) | 13432 | if (NotecardCache.IsCached(assetID)) |
10830 | { | 13433 | { |
10831 | AsyncCommands. | 13434 | AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(assetID).ToString()); |
10832 | DataserverPlugin.DataserverReply(assetID.ToString(), | 13435 | |
10833 | NotecardCache.GetLines(assetID).ToString()); | 13436 | ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines); |
10834 | ScriptSleep(100); | ||
10835 | return tid.ToString(); | 13437 | return tid.ToString(); |
10836 | } | 13438 | } |
10837 | 13439 | ||
@@ -10839,19 +13441,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10839 | { | 13441 | { |
10840 | if (a == null || a.Type != 7) | 13442 | if (a == null || a.Type != 7) |
10841 | { | 13443 | { |
10842 | ShoutError("Notecard '" + name + "' could not be found."); | 13444 | Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'"); |
10843 | return; | 13445 | return; |
10844 | } | 13446 | } |
10845 | 13447 | ||
10846 | string data = Encoding.UTF8.GetString(a.Data); | 13448 | NotecardCache.Cache(id, a.Data); |
10847 | //m_log.Debug(data); | 13449 | AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(id).ToString()); |
10848 | NotecardCache.Cache(id, data); | ||
10849 | AsyncCommands. | ||
10850 | DataserverPlugin.DataserverReply(id.ToString(), | ||
10851 | NotecardCache.GetLines(id).ToString()); | ||
10852 | }); | 13450 | }); |
10853 | 13451 | ||
10854 | ScriptSleep(100); | 13452 | ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines); |
10855 | return tid.ToString(); | 13453 | return tid.ToString(); |
10856 | } | 13454 | } |
10857 | 13455 | ||
@@ -10872,19 +13470,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10872 | if (assetID == UUID.Zero) | 13470 | if (assetID == UUID.Zero) |
10873 | { | 13471 | { |
10874 | // => complain loudly, as specified by the LSL docs | 13472 | // => complain loudly, as specified by the LSL docs |
10875 | ShoutError("Notecard '" + name + "' could not be found."); | 13473 | Error("llGetNotecardLine", "Can't find notecard '" + name + "'"); |
10876 | 13474 | ||
10877 | return UUID.Zero.ToString(); | 13475 | return UUID.Zero.ToString(); |
10878 | } | 13476 | } |
10879 | 13477 | ||
13478 | string reqIdentifier = UUID.Random().ToString(); | ||
13479 | |||
10880 | // was: UUID tid = tid = AsyncCommands. | 13480 | // was: UUID tid = tid = AsyncCommands. |
10881 | UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString()); | 13481 | UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier); |
10882 | 13482 | ||
10883 | if (NotecardCache.IsCached(assetID)) | 13483 | if (NotecardCache.IsCached(assetID)) |
10884 | { | 13484 | { |
10885 | AsyncCommands.DataserverPlugin.DataserverReply(assetID.ToString(), | 13485 | AsyncCommands.DataserverPlugin.DataserverReply( |
10886 | NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax)); | 13486 | reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax)); |
10887 | ScriptSleep(100); | 13487 | |
13488 | ScriptSleep(m_sleepMsOnGetNotecardLine); | ||
10888 | return tid.ToString(); | 13489 | return tid.ToString(); |
10889 | } | 13490 | } |
10890 | 13491 | ||
@@ -10892,18 +13493,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10892 | { | 13493 | { |
10893 | if (a == null || a.Type != 7) | 13494 | if (a == null || a.Type != 7) |
10894 | { | 13495 | { |
10895 | ShoutError("Notecard '" + name + "' could not be found."); | 13496 | Error("llGetNotecardLine", "Can't find notecard '" + name + "'"); |
10896 | return; | 13497 | return; |
10897 | } | 13498 | } |
10898 | 13499 | ||
10899 | string data = Encoding.UTF8.GetString(a.Data); | 13500 | string data = Encoding.UTF8.GetString(a.Data); |
10900 | //m_log.Debug(data); | 13501 | //m_log.Debug(data); |
10901 | NotecardCache.Cache(id, data); | 13502 | NotecardCache.Cache(id, a.Data); |
10902 | AsyncCommands.DataserverPlugin.DataserverReply(id.ToString(), | 13503 | AsyncCommands.DataserverPlugin.DataserverReply( |
10903 | NotecardCache.GetLine(id, line, m_notecardLineReadCharsMax)); | 13504 | reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax)); |
10904 | }); | 13505 | }); |
10905 | 13506 | ||
10906 | ScriptSleep(100); | 13507 | ScriptSleep(m_sleepMsOnGetNotecardLine); |
10907 | return tid.ToString(); | 13508 | return tid.ToString(); |
10908 | } | 13509 | } |
10909 | 13510 | ||
@@ -10916,41 +13517,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10916 | if (obj.OwnerID != m_host.OwnerID) | 13517 | if (obj.OwnerID != m_host.OwnerID) |
10917 | return; | 13518 | return; |
10918 | 13519 | ||
10919 | uint rulesParsed = 0; | 13520 | SetEntityParams(new List<ISceneEntity>() { obj }, rules, originFunc); |
10920 | LSL_List remaining = SetPrimParams(obj, rules, originFunc, ref rulesParsed); | ||
10921 | |||
10922 | while ((object)remaining != null && remaining.Length > 2) | ||
10923 | { | ||
10924 | LSL_Integer newLink = remaining.GetLSLIntegerItem(0); | ||
10925 | LSL_List newrules = remaining.GetSublist(1, -1); | ||
10926 | foreach(SceneObjectPart part in GetLinkParts(obj, newLink)){ | ||
10927 | remaining = SetPrimParams(part, newrules, originFunc, ref rulesParsed); | ||
10928 | } | ||
10929 | } | ||
10930 | } | 13521 | } |
10931 | 13522 | ||
10932 | public LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules) | 13523 | public LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules) |
10933 | { | 13524 | { |
10934 | SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim)); | 13525 | SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim)); |
10935 | 13526 | ||
10936 | LSL_List result = new LSL_List(); | 13527 | if (obj != null && obj.OwnerID == m_host.OwnerID) |
10937 | 13528 | return GetEntityParams(obj, rules); | |
10938 | if (obj != null && obj.OwnerID != m_host.OwnerID) | ||
10939 | { | ||
10940 | LSL_List remaining = GetPrimParams(obj, rules, ref result); | ||
10941 | |||
10942 | while (remaining != null && remaining.Length > 2) | ||
10943 | { | ||
10944 | int linknumber = remaining.GetLSLIntegerItem(0); | ||
10945 | rules = remaining.GetSublist(1, -1); | ||
10946 | List<SceneObjectPart> parts = GetLinkParts(linknumber); | ||
10947 | 13529 | ||
10948 | foreach (SceneObjectPart part in parts) | 13530 | return new LSL_List(); |
10949 | remaining = GetPrimParams(part, rules, ref result); | ||
10950 | } | ||
10951 | } | ||
10952 | |||
10953 | return result; | ||
10954 | } | 13531 | } |
10955 | 13532 | ||
10956 | public void print(string str) | 13533 | public void print(string str) |
@@ -11036,7 +13613,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11036 | World.ForEachScenePresence(delegate(ScenePresence sp) | 13613 | World.ForEachScenePresence(delegate(ScenePresence sp) |
11037 | { | 13614 | { |
11038 | Vector3 ac = sp.AbsolutePosition - rayStart; | 13615 | Vector3 ac = sp.AbsolutePosition - rayStart; |
11039 | Vector3 bc = sp.AbsolutePosition - rayEnd; | 13616 | // Vector3 bc = sp.AbsolutePosition - rayEnd; |
11040 | 13617 | ||
11041 | double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd)); | 13618 | double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd)); |
11042 | 13619 | ||
@@ -11124,9 +13701,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11124 | radius = Math.Abs(maxY); | 13701 | radius = Math.Abs(maxY); |
11125 | if (Math.Abs(maxZ) > radius) | 13702 | if (Math.Abs(maxZ) > radius) |
11126 | radius = Math.Abs(maxZ); | 13703 | radius = Math.Abs(maxZ); |
11127 | 13704 | radius = radius*1.413f; | |
11128 | Vector3 ac = group.AbsolutePosition - rayStart; | 13705 | Vector3 ac = group.AbsolutePosition - rayStart; |
11129 | Vector3 bc = group.AbsolutePosition - rayEnd; | 13706 | // Vector3 bc = group.AbsolutePosition - rayEnd; |
11130 | 13707 | ||
11131 | double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd)); | 13708 | double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd)); |
11132 | 13709 | ||
@@ -11139,11 +13716,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11139 | if (d2 > 0) | 13716 | if (d2 > 0) |
11140 | return; | 13717 | return; |
11141 | 13718 | ||
13719 | ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart)); | ||
11142 | EntityIntersection intersection = group.TestIntersection(ray, true, false); | 13720 | EntityIntersection intersection = group.TestIntersection(ray, true, false); |
11143 | // Miss. | 13721 | // Miss. |
11144 | if (!intersection.HitTF) | 13722 | if (!intersection.HitTF) |
11145 | return; | 13723 | return; |
11146 | 13724 | ||
13725 | Vector3 b1 = group.AbsolutePosition + new Vector3(minX, minY, minZ); | ||
13726 | Vector3 b2 = group.AbsolutePosition + new Vector3(maxX, maxY, maxZ); | ||
13727 | //m_log.DebugFormat("[LLCASTRAY]: min<{0},{1},{2}>, max<{3},{4},{5}> = hitp<{6},{7},{8}>", b1.X,b1.Y,b1.Z,b2.X,b2.Y,b2.Z,intersection.ipoint.X,intersection.ipoint.Y,intersection.ipoint.Z); | ||
13728 | if (!(intersection.ipoint.X >= b1.X && intersection.ipoint.X <= b2.X && | ||
13729 | intersection.ipoint.Y >= b1.Y && intersection.ipoint.Y <= b2.Y && | ||
13730 | intersection.ipoint.Z >= b1.Z && intersection.ipoint.Z <= b2.Z)) | ||
13731 | return; | ||
13732 | |||
11147 | ContactResult result = new ContactResult (); | 13733 | ContactResult result = new ContactResult (); |
11148 | result.ConsumerID = group.LocalId; | 13734 | result.ConsumerID = group.LocalId; |
11149 | result.Depth = intersection.distance; | 13735 | result.Depth = intersection.distance; |
@@ -11284,6 +13870,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11284 | 13870 | ||
11285 | public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options) | 13871 | public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options) |
11286 | { | 13872 | { |
13873 | // Use llCastRay V3 if configured | ||
13874 | if (m_useCastRayV3) | ||
13875 | return llCastRayV3(start, end, options); | ||
13876 | |||
11287 | LSL_List list = new LSL_List(); | 13877 | LSL_List list = new LSL_List(); |
11288 | 13878 | ||
11289 | m_host.AddScriptLPS(1); | 13879 | m_host.AddScriptLPS(1); |
@@ -11322,25 +13912,93 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11322 | bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL); | 13912 | bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL); |
11323 | 13913 | ||
11324 | 13914 | ||
11325 | if (checkTerrain) | 13915 | if (World.SupportsRayCastFiltered()) |
11326 | { | 13916 | { |
11327 | ContactResult? groundContact = GroundIntersection(rayStart, rayEnd); | 13917 | if (dist == 0) |
11328 | if (groundContact != null) | 13918 | return list; |
11329 | results.Add((ContactResult)groundContact); | 13919 | |
11330 | } | 13920 | RayFilterFlags rayfilter = RayFilterFlags.ClosestAndBackCull; |
13921 | if (checkTerrain) | ||
13922 | rayfilter |= RayFilterFlags.land; | ||
13923 | // if (checkAgents) | ||
13924 | // rayfilter |= RayFilterFlags.agent; | ||
13925 | if (checkPhysical) | ||
13926 | rayfilter |= RayFilterFlags.physical; | ||
13927 | if (checkNonPhysical) | ||
13928 | rayfilter |= RayFilterFlags.nonphysical; | ||
13929 | if (detectPhantom) | ||
13930 | rayfilter |= RayFilterFlags.LSLPhantom; | ||
11331 | 13931 | ||
11332 | if (checkAgents) | 13932 | Vector3 direction = dir * ( 1/dist); |
13933 | |||
13934 | if(rayfilter == 0) | ||
13935 | { | ||
13936 | list.Add(new LSL_Integer(0)); | ||
13937 | return list; | ||
13938 | } | ||
13939 | |||
13940 | // get some more contacts to sort ??? | ||
13941 | int physcount = 4 * count; | ||
13942 | if (physcount > 20) | ||
13943 | physcount = 20; | ||
13944 | |||
13945 | object physresults; | ||
13946 | physresults = World.RayCastFiltered(rayStart, direction, dist, physcount, rayfilter); | ||
13947 | |||
13948 | if (physresults == null) | ||
13949 | { | ||
13950 | list.Add(new LSL_Integer(-3)); // timeout error | ||
13951 | return list; | ||
13952 | } | ||
13953 | |||
13954 | results = (List<ContactResult>)physresults; | ||
13955 | |||
13956 | // for now physics doesn't detect sitted avatars so do it outside physics | ||
13957 | if (checkAgents) | ||
13958 | { | ||
13959 | ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd); | ||
13960 | foreach (ContactResult r in agentHits) | ||
13961 | results.Add(r); | ||
13962 | } | ||
13963 | |||
13964 | // TODO: Replace this with a better solution. ObjectIntersection can only | ||
13965 | // detect nonphysical phantoms. They are detected by virtue of being | ||
13966 | // nonphysical (e.g. no PhysActor) so will not conflict with detecting | ||
13967 | // physicsl phantoms as done by the physics scene | ||
13968 | // We don't want anything else but phantoms here. | ||
13969 | if (detectPhantom) | ||
13970 | { | ||
13971 | ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, false, false, true); | ||
13972 | foreach (ContactResult r in objectHits) | ||
13973 | results.Add(r); | ||
13974 | } | ||
13975 | } | ||
13976 | else | ||
11333 | { | 13977 | { |
11334 | ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd); | 13978 | if (checkAgents) |
11335 | foreach (ContactResult r in agentHits) | 13979 | { |
11336 | results.Add(r); | 13980 | ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd); |
13981 | foreach (ContactResult r in agentHits) | ||
13982 | results.Add(r); | ||
13983 | } | ||
13984 | |||
13985 | if (checkPhysical || checkNonPhysical || detectPhantom) | ||
13986 | { | ||
13987 | ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom); | ||
13988 | for (int iter = 0; iter < objectHits.Length; iter++) | ||
13989 | { | ||
13990 | // Redistance the Depth because the Scene RayCaster returns distance from center to make the rezzing code simpler. | ||
13991 | objectHits[iter].Depth = Vector3.Distance(objectHits[iter].Pos, rayStart); | ||
13992 | results.Add(objectHits[iter]); | ||
13993 | } | ||
13994 | } | ||
11337 | } | 13995 | } |
11338 | 13996 | ||
11339 | if (checkPhysical || checkNonPhysical || detectPhantom) | 13997 | if (checkTerrain) |
11340 | { | 13998 | { |
11341 | ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom); | 13999 | ContactResult? groundContact = GroundIntersection(rayStart, rayEnd); |
11342 | foreach (ContactResult r in objectHits) | 14000 | if (groundContact != null) |
11343 | results.Add(r); | 14001 | results.Add((ContactResult)groundContact); |
11344 | } | 14002 | } |
11345 | 14003 | ||
11346 | results.Sort(delegate(ContactResult a, ContactResult b) | 14004 | results.Sort(delegate(ContactResult a, ContactResult b) |
@@ -11381,7 +14039,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11381 | else | 14039 | else |
11382 | { | 14040 | { |
11383 | ScenePresence sp = World.GetScenePresence(result.ConsumerID); | 14041 | ScenePresence sp = World.GetScenePresence(result.ConsumerID); |
11384 | /// It it a boy? a girl? | 14042 | /// It it a boy? a girl? |
11385 | if (sp != null) | 14043 | if (sp != null) |
11386 | itemID = sp.UUID; | 14044 | itemID = sp.UUID; |
11387 | } | 14045 | } |
@@ -11393,7 +14051,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11393 | list.Add(new LSL_Integer(linkNum)); | 14051 | list.Add(new LSL_Integer(linkNum)); |
11394 | 14052 | ||
11395 | if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL) | 14053 | if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL) |
11396 | list.Add(new LSL_Vector(result.Normal.X, result.Normal.Y, result.Normal.Z)); | 14054 | list.Add(new LSL_Vector(result.Normal)); |
11397 | 14055 | ||
11398 | values++; | 14056 | values++; |
11399 | if (values >= count) | 14057 | if (values >= count) |
@@ -11405,6 +14063,872 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11405 | return list; | 14063 | return list; |
11406 | } | 14064 | } |
11407 | 14065 | ||
14066 | /// <summary> | ||
14067 | /// Implementation of llCastRay similar to SL 2015-04-21. | ||
14068 | /// http://wiki.secondlife.com/wiki/LlCastRay | ||
14069 | /// Uses pure geometry, bounding shapes, meshing and no physics | ||
14070 | /// for prims, sculpts, meshes, avatars and terrain. | ||
14071 | /// Implements all flags, reject types and data flags. | ||
14072 | /// Can handle both objects/groups and prims/parts, by config. | ||
14073 | /// May sometimes be inaccurate owing to calculation precision, | ||
14074 | /// meshing detail level and a bug in libopenmetaverse PrimMesher. | ||
14075 | /// </summary> | ||
14076 | public LSL_List llCastRayV3(LSL_Vector start, LSL_Vector end, LSL_List options) | ||
14077 | { | ||
14078 | m_host.AddScriptLPS(1); | ||
14079 | LSL_List result = new LSL_List(); | ||
14080 | |||
14081 | // Prepare throttle data | ||
14082 | int calledMs = Environment.TickCount; | ||
14083 | Stopwatch stopWatch = new Stopwatch(); | ||
14084 | stopWatch.Start(); | ||
14085 | UUID regionId = World.RegionInfo.RegionID; | ||
14086 | UUID userId = UUID.Zero; | ||
14087 | int msAvailable = 0; | ||
14088 | // Throttle per owner when attachment or "vehicle" (sat upon) | ||
14089 | if (m_host.ParentGroup.IsAttachment || m_host.ParentGroup.GetSittingAvatars().Count > 0) | ||
14090 | { | ||
14091 | userId = m_host.OwnerID; | ||
14092 | msAvailable = m_msPerAvatarInCastRay; | ||
14093 | } | ||
14094 | // Throttle per parcel when not attachment or vehicle | ||
14095 | else | ||
14096 | { | ||
14097 | LandData land = World.GetLandData(m_host.GetWorldPosition()); | ||
14098 | if (land != null) | ||
14099 | msAvailable = m_msPerRegionInCastRay * land.Area / 65536; | ||
14100 | } | ||
14101 | // Clamp for "oversized" parcels on varregions | ||
14102 | if (msAvailable > m_msMaxInCastRay) | ||
14103 | msAvailable = m_msMaxInCastRay; | ||
14104 | |||
14105 | // Check throttle data | ||
14106 | int fromCalledMs = calledMs - m_msThrottleInCastRay; | ||
14107 | lock (m_castRayCalls) | ||
14108 | { | ||
14109 | for (int i = m_castRayCalls.Count - 1; i >= 0; i--) | ||
14110 | { | ||
14111 | // Delete old calls from throttle data | ||
14112 | if (m_castRayCalls[i].CalledMs < fromCalledMs) | ||
14113 | m_castRayCalls.RemoveAt(i); | ||
14114 | // Use current region (in multi-region sims) | ||
14115 | else if (m_castRayCalls[i].RegionId == regionId) | ||
14116 | { | ||
14117 | // Reduce available time with recent calls | ||
14118 | if (m_castRayCalls[i].UserId == userId) | ||
14119 | msAvailable -= m_castRayCalls[i].UsedMs; | ||
14120 | } | ||
14121 | } | ||
14122 | } | ||
14123 | |||
14124 | // Return failure if not enough available time | ||
14125 | if (msAvailable < m_msMinInCastRay) | ||
14126 | { | ||
14127 | result.Add(new LSL_Integer(ScriptBaseClass.RCERR_CAST_TIME_EXCEEDED)); | ||
14128 | return result; | ||
14129 | } | ||
14130 | |||
14131 | // Initialize | ||
14132 | List<RayHit> rayHits = new List<RayHit>(); | ||
14133 | float tol = m_floatToleranceInCastRay; | ||
14134 | Vector3 pos1Ray = start; | ||
14135 | Vector3 pos2Ray = end; | ||
14136 | |||
14137 | // Get input options | ||
14138 | int rejectTypes = 0; | ||
14139 | int dataFlags = 0; | ||
14140 | int maxHits = 1; | ||
14141 | bool detectPhantom = false; | ||
14142 | for (int i = 0; i < options.Length; i += 2) | ||
14143 | { | ||
14144 | if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES) | ||
14145 | rejectTypes = options.GetLSLIntegerItem(i + 1); | ||
14146 | else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS) | ||
14147 | dataFlags = options.GetLSLIntegerItem(i + 1); | ||
14148 | else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS) | ||
14149 | maxHits = options.GetLSLIntegerItem(i + 1); | ||
14150 | else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM) | ||
14151 | detectPhantom = (options.GetLSLIntegerItem(i + 1) != 0); | ||
14152 | } | ||
14153 | if (maxHits > m_maxHitsInCastRay) | ||
14154 | maxHits = m_maxHitsInCastRay; | ||
14155 | bool rejectAgents = ((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) != 0); | ||
14156 | bool rejectPhysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) != 0); | ||
14157 | bool rejectNonphysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) != 0); | ||
14158 | bool rejectLand = ((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) != 0); | ||
14159 | bool getNormal = ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) != 0); | ||
14160 | bool getRootKey = ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) != 0); | ||
14161 | bool getLinkNum = ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) != 0); | ||
14162 | |||
14163 | // Calculate some basic parameters | ||
14164 | Vector3 vecRay = pos2Ray - pos1Ray; | ||
14165 | float rayLength = vecRay.Length(); | ||
14166 | |||
14167 | // Try to get a mesher and return failure if none, degenerate ray, or max 0 hits | ||
14168 | IRendering primMesher = null; | ||
14169 | List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory()); | ||
14170 | if (renderers.Count < 1 || rayLength < tol || m_maxHitsInCastRay < 1) | ||
14171 | { | ||
14172 | result.Add(new LSL_Integer(ScriptBaseClass.RCERR_UNKNOWN)); | ||
14173 | return result; | ||
14174 | } | ||
14175 | primMesher = RenderingLoader.LoadRenderer(renderers[0]); | ||
14176 | |||
14177 | // Iterate over all objects/groups and prims/parts in region | ||
14178 | World.ForEachSOG( | ||
14179 | delegate(SceneObjectGroup group) | ||
14180 | { | ||
14181 | // Check group filters unless part filters are configured | ||
14182 | bool isPhysical = (group.RootPart != null && group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical); | ||
14183 | bool isNonphysical = !isPhysical; | ||
14184 | bool isPhantom = group.IsPhantom || group.IsVolumeDetect; | ||
14185 | bool isAttachment = group.IsAttachment; | ||
14186 | bool doGroup = true; | ||
14187 | if (isPhysical && rejectPhysical) | ||
14188 | doGroup = false; | ||
14189 | if (isNonphysical && rejectNonphysical) | ||
14190 | doGroup = false; | ||
14191 | if (isPhantom && detectPhantom) | ||
14192 | doGroup = true; | ||
14193 | if (m_filterPartsInCastRay) | ||
14194 | doGroup = true; | ||
14195 | if (isAttachment && !m_doAttachmentsInCastRay) | ||
14196 | doGroup = false; | ||
14197 | // Parse object/group if passed filters | ||
14198 | if (doGroup) | ||
14199 | { | ||
14200 | // Iterate over all prims/parts in object/group | ||
14201 | foreach(SceneObjectPart part in group.Parts) | ||
14202 | { | ||
14203 | // Check part filters if configured | ||
14204 | if (m_filterPartsInCastRay) | ||
14205 | { | ||
14206 | isPhysical = (part.PhysActor != null && part.PhysActor.IsPhysical); | ||
14207 | isNonphysical = !isPhysical; | ||
14208 | isPhantom = ((part.Flags & PrimFlags.Phantom) != 0) || (part.VolumeDetectActive); | ||
14209 | bool doPart = true; | ||
14210 | if (isPhysical && rejectPhysical) | ||
14211 | doPart = false; | ||
14212 | if (isNonphysical && rejectNonphysical) | ||
14213 | doPart = false; | ||
14214 | if (isPhantom && detectPhantom) | ||
14215 | doPart = true; | ||
14216 | if (!doPart) | ||
14217 | continue; | ||
14218 | } | ||
14219 | |||
14220 | // Parse prim/part and project ray if passed filters | ||
14221 | Vector3 scalePart = part.Scale; | ||
14222 | Vector3 posPart = part.GetWorldPosition(); | ||
14223 | Quaternion rotPart = part.GetWorldRotation(); | ||
14224 | Quaternion rotPartInv = Quaternion.Inverse(rotPart); | ||
14225 | Vector3 pos1RayProj = ((pos1Ray - posPart) * rotPartInv) / scalePart; | ||
14226 | Vector3 pos2RayProj = ((pos2Ray - posPart) * rotPartInv) / scalePart; | ||
14227 | |||
14228 | // Filter parts by shape bounding boxes | ||
14229 | Vector3 shapeBoxMax = new Vector3(0.5f, 0.5f, 0.5f); | ||
14230 | if (!part.Shape.SculptEntry) | ||
14231 | shapeBoxMax = shapeBoxMax * (new Vector3(m_primSafetyCoeffX, m_primSafetyCoeffY, m_primSafetyCoeffZ)); | ||
14232 | shapeBoxMax = shapeBoxMax + (new Vector3(tol, tol, tol)); | ||
14233 | if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax)) | ||
14234 | { | ||
14235 | // Prepare data needed to check for ray hits | ||
14236 | RayTrans rayTrans = new RayTrans(); | ||
14237 | rayTrans.PartId = part.UUID; | ||
14238 | rayTrans.GroupId = part.ParentGroup.UUID; | ||
14239 | rayTrans.Link = group.PrimCount > 1 ? part.LinkNum : 0; | ||
14240 | rayTrans.ScalePart = scalePart; | ||
14241 | rayTrans.PositionPart = posPart; | ||
14242 | rayTrans.RotationPart = rotPart; | ||
14243 | rayTrans.ShapeNeedsEnds = true; | ||
14244 | rayTrans.Position1Ray = pos1Ray; | ||
14245 | rayTrans.Position1RayProj = pos1RayProj; | ||
14246 | rayTrans.VectorRayProj = pos2RayProj - pos1RayProj; | ||
14247 | |||
14248 | // Get detail level depending on type | ||
14249 | int lod = 0; | ||
14250 | // Mesh detail level | ||
14251 | if (part.Shape.SculptEntry && part.Shape.SculptType == (byte)SculptType.Mesh) | ||
14252 | lod = (int)m_meshLodInCastRay; | ||
14253 | // Sculpt detail level | ||
14254 | else if (part.Shape.SculptEntry && part.Shape.SculptType == (byte)SculptType.Mesh) | ||
14255 | lod = (int)m_sculptLodInCastRay; | ||
14256 | // Shape detail level | ||
14257 | else if (!part.Shape.SculptEntry) | ||
14258 | lod = (int)m_primLodInCastRay; | ||
14259 | |||
14260 | // Try to get cached mesh if configured | ||
14261 | ulong meshKey = 0; | ||
14262 | FacetedMesh mesh = null; | ||
14263 | if (m_useMeshCacheInCastRay) | ||
14264 | { | ||
14265 | meshKey = part.Shape.GetMeshKey(Vector3.One, (float)(4 << lod)); | ||
14266 | lock (m_cachedMeshes) | ||
14267 | { | ||
14268 | m_cachedMeshes.TryGetValue(meshKey, out mesh); | ||
14269 | } | ||
14270 | } | ||
14271 | |||
14272 | // Create mesh if no cached mesh | ||
14273 | if (mesh == null) | ||
14274 | { | ||
14275 | // Make an OMV prim to be able to mesh part | ||
14276 | Primitive omvPrim = part.Shape.ToOmvPrimitive(posPart, rotPart); | ||
14277 | byte[] sculptAsset = null; | ||
14278 | if (omvPrim.Sculpt != null) | ||
14279 | sculptAsset = World.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString()); | ||
14280 | |||
14281 | // When part is mesh, get mesh | ||
14282 | if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type == SculptType.Mesh && sculptAsset != null) | ||
14283 | { | ||
14284 | AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset); | ||
14285 | FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, m_meshLodInCastRay, out mesh); | ||
14286 | meshAsset = null; | ||
14287 | } | ||
14288 | |||
14289 | // When part is sculpt, create mesh | ||
14290 | // Quirk: Generated sculpt mesh is about 2.8% smaller in X and Y than visual sculpt. | ||
14291 | else if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type != SculptType.Mesh && sculptAsset != null) | ||
14292 | { | ||
14293 | IJ2KDecoder imgDecoder = World.RequestModuleInterface<IJ2KDecoder>(); | ||
14294 | if (imgDecoder != null) | ||
14295 | { | ||
14296 | Image sculpt = imgDecoder.DecodeToImage(sculptAsset); | ||
14297 | if (sculpt != null) | ||
14298 | { | ||
14299 | mesh = primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, m_sculptLodInCastRay); | ||
14300 | sculpt.Dispose(); | ||
14301 | } | ||
14302 | } | ||
14303 | } | ||
14304 | |||
14305 | // When part is shape, create mesh | ||
14306 | else if (omvPrim.Sculpt == null) | ||
14307 | { | ||
14308 | if ( | ||
14309 | omvPrim.PrimData.PathBegin == 0.0 && omvPrim.PrimData.PathEnd == 1.0 && | ||
14310 | omvPrim.PrimData.PathTaperX == 0.0 && omvPrim.PrimData.PathTaperY == 0.0 && | ||
14311 | omvPrim.PrimData.PathSkew == 0.0 && | ||
14312 | omvPrim.PrimData.PathTwist - omvPrim.PrimData.PathTwistBegin == 0.0 | ||
14313 | ) | ||
14314 | rayTrans.ShapeNeedsEnds = false; | ||
14315 | mesh = primMesher.GenerateFacetedMesh(omvPrim, m_primLodInCastRay); | ||
14316 | } | ||
14317 | |||
14318 | // Cache mesh if configured | ||
14319 | if (m_useMeshCacheInCastRay && mesh != null) | ||
14320 | { | ||
14321 | lock(m_cachedMeshes) | ||
14322 | { | ||
14323 | if (!m_cachedMeshes.ContainsKey(meshKey)) | ||
14324 | m_cachedMeshes.Add(meshKey, mesh); | ||
14325 | } | ||
14326 | } | ||
14327 | } | ||
14328 | // Check mesh for ray hits | ||
14329 | AddRayInFacetedMesh(mesh, rayTrans, ref rayHits); | ||
14330 | mesh = null; | ||
14331 | } | ||
14332 | } | ||
14333 | } | ||
14334 | } | ||
14335 | ); | ||
14336 | |||
14337 | // Check avatar filter | ||
14338 | if (!rejectAgents) | ||
14339 | { | ||
14340 | // Iterate over all avatars in region | ||
14341 | World.ForEachRootScenePresence( | ||
14342 | delegate (ScenePresence sp) | ||
14343 | { | ||
14344 | // Get bounding box | ||
14345 | Vector3 lower; | ||
14346 | Vector3 upper; | ||
14347 | BoundingBoxOfScenePresence(sp, out lower, out upper); | ||
14348 | // Parse avatar | ||
14349 | Vector3 scalePart = upper - lower; | ||
14350 | Vector3 posPart = sp.AbsolutePosition; | ||
14351 | Quaternion rotPart = sp.GetWorldRotation(); | ||
14352 | Quaternion rotPartInv = Quaternion.Inverse(rotPart); | ||
14353 | posPart = posPart + (lower + upper) * 0.5f * rotPart; | ||
14354 | // Project ray | ||
14355 | Vector3 pos1RayProj = ((pos1Ray - posPart) * rotPartInv) / scalePart; | ||
14356 | Vector3 pos2RayProj = ((pos2Ray - posPart) * rotPartInv) / scalePart; | ||
14357 | |||
14358 | // Filter avatars by shape bounding boxes | ||
14359 | Vector3 shapeBoxMax = new Vector3(0.5f + tol, 0.5f + tol, 0.5f + tol); | ||
14360 | if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax)) | ||
14361 | { | ||
14362 | // Prepare data needed to check for ray hits | ||
14363 | RayTrans rayTrans = new RayTrans(); | ||
14364 | rayTrans.PartId = sp.UUID; | ||
14365 | rayTrans.GroupId = sp.ParentPart != null ? sp.ParentPart.ParentGroup.UUID : sp.UUID; | ||
14366 | rayTrans.Link = sp.ParentPart != null ? UUID2LinkNumber(sp.ParentPart, sp.UUID) : 0; | ||
14367 | rayTrans.ScalePart = scalePart; | ||
14368 | rayTrans.PositionPart = posPart; | ||
14369 | rayTrans.RotationPart = rotPart; | ||
14370 | rayTrans.ShapeNeedsEnds = false; | ||
14371 | rayTrans.Position1Ray = pos1Ray; | ||
14372 | rayTrans.Position1RayProj = pos1RayProj; | ||
14373 | rayTrans.VectorRayProj = pos2RayProj - pos1RayProj; | ||
14374 | |||
14375 | // Try to get cached mesh if configured | ||
14376 | PrimitiveBaseShape prim = PrimitiveBaseShape.CreateSphere(); | ||
14377 | int lod = (int)m_avatarLodInCastRay; | ||
14378 | ulong meshKey = prim.GetMeshKey(Vector3.One, (float)(4 << lod)); | ||
14379 | FacetedMesh mesh = null; | ||
14380 | if (m_useMeshCacheInCastRay) | ||
14381 | { | ||
14382 | lock (m_cachedMeshes) | ||
14383 | { | ||
14384 | m_cachedMeshes.TryGetValue(meshKey, out mesh); | ||
14385 | } | ||
14386 | } | ||
14387 | |||
14388 | // Create mesh if no cached mesh | ||
14389 | if (mesh == null) | ||
14390 | { | ||
14391 | // Make OMV prim and create mesh | ||
14392 | prim.Scale = scalePart; | ||
14393 | Primitive omvPrim = prim.ToOmvPrimitive(posPart, rotPart); | ||
14394 | mesh = primMesher.GenerateFacetedMesh(omvPrim, m_avatarLodInCastRay); | ||
14395 | |||
14396 | // Cache mesh if configured | ||
14397 | if (m_useMeshCacheInCastRay && mesh != null) | ||
14398 | { | ||
14399 | lock(m_cachedMeshes) | ||
14400 | { | ||
14401 | if (!m_cachedMeshes.ContainsKey(meshKey)) | ||
14402 | m_cachedMeshes.Add(meshKey, mesh); | ||
14403 | } | ||
14404 | } | ||
14405 | } | ||
14406 | |||
14407 | // Check mesh for ray hits | ||
14408 | AddRayInFacetedMesh(mesh, rayTrans, ref rayHits); | ||
14409 | mesh = null; | ||
14410 | } | ||
14411 | } | ||
14412 | ); | ||
14413 | } | ||
14414 | |||
14415 | // Check terrain filter | ||
14416 | if (!rejectLand) | ||
14417 | { | ||
14418 | // Parse terrain | ||
14419 | |||
14420 | // Mesh terrain and check bounding box | ||
14421 | Vector3 lower; | ||
14422 | Vector3 upper; | ||
14423 | List<Tri> triangles = TrisFromHeightmapUnderRay(pos1Ray, pos2Ray, out lower, out upper); | ||
14424 | lower.Z -= tol; | ||
14425 | upper.Z += tol; | ||
14426 | if ((pos1Ray.Z >= lower.Z || pos2Ray.Z >= lower.Z) && (pos1Ray.Z <= upper.Z || pos2Ray.Z <= upper.Z)) | ||
14427 | { | ||
14428 | // Prepare data needed to check for ray hits | ||
14429 | RayTrans rayTrans = new RayTrans(); | ||
14430 | rayTrans.PartId = UUID.Zero; | ||
14431 | rayTrans.GroupId = UUID.Zero; | ||
14432 | rayTrans.Link = 0; | ||
14433 | rayTrans.ScalePart = new Vector3 (1.0f, 1.0f, 1.0f); | ||
14434 | rayTrans.PositionPart = Vector3.Zero; | ||
14435 | rayTrans.RotationPart = Quaternion.Identity; | ||
14436 | rayTrans.ShapeNeedsEnds = true; | ||
14437 | rayTrans.Position1Ray = pos1Ray; | ||
14438 | rayTrans.Position1RayProj = pos1Ray; | ||
14439 | rayTrans.VectorRayProj = vecRay; | ||
14440 | |||
14441 | // Check mesh | ||
14442 | AddRayInTris(triangles, rayTrans, ref rayHits); | ||
14443 | triangles = null; | ||
14444 | } | ||
14445 | } | ||
14446 | |||
14447 | // Sort hits by ascending distance | ||
14448 | rayHits.Sort((s1, s2) => s1.Distance.CompareTo(s2.Distance)); | ||
14449 | |||
14450 | // Check excess hits per part and group | ||
14451 | for (int t = 0; t < 2; t++) | ||
14452 | { | ||
14453 | int maxHitsPerType = 0; | ||
14454 | UUID id = UUID.Zero; | ||
14455 | if (t == 0) | ||
14456 | maxHitsPerType = m_maxHitsPerPrimInCastRay; | ||
14457 | else | ||
14458 | maxHitsPerType = m_maxHitsPerObjectInCastRay; | ||
14459 | |||
14460 | // Handle excess hits only when needed | ||
14461 | if (maxHitsPerType < m_maxHitsInCastRay) | ||
14462 | { | ||
14463 | // Find excess hits | ||
14464 | Hashtable hits = new Hashtable(); | ||
14465 | for (int i = rayHits.Count - 1; i >= 0; i--) | ||
14466 | { | ||
14467 | if (t == 0) | ||
14468 | id = rayHits[i].PartId; | ||
14469 | else | ||
14470 | id = rayHits[i].GroupId; | ||
14471 | if (hits.ContainsKey(id)) | ||
14472 | hits[id] = (int)hits[id] + 1; | ||
14473 | else | ||
14474 | hits[id] = 1; | ||
14475 | } | ||
14476 | |||
14477 | // Remove excess hits | ||
14478 | for (int i = rayHits.Count - 1; i >= 0; i--) | ||
14479 | { | ||
14480 | if (t == 0) | ||
14481 | id = rayHits[i].PartId; | ||
14482 | else | ||
14483 | id = rayHits[i].GroupId; | ||
14484 | int hit = (int)hits[id]; | ||
14485 | if (hit > m_maxHitsPerPrimInCastRay) | ||
14486 | { | ||
14487 | rayHits.RemoveAt(i); | ||
14488 | hit--; | ||
14489 | hits[id] = hit; | ||
14490 | } | ||
14491 | } | ||
14492 | } | ||
14493 | } | ||
14494 | |||
14495 | // Parse hits into result list according to data flags | ||
14496 | int hitCount = rayHits.Count; | ||
14497 | if (hitCount > maxHits) | ||
14498 | hitCount = maxHits; | ||
14499 | for (int i = 0; i < hitCount; i++) | ||
14500 | { | ||
14501 | RayHit rayHit = rayHits[i]; | ||
14502 | if (getRootKey) | ||
14503 | result.Add(new LSL_Key(rayHit.GroupId.ToString())); | ||
14504 | else | ||
14505 | result.Add(new LSL_Key(rayHit.PartId.ToString())); | ||
14506 | result.Add(new LSL_Vector(rayHit.Position)); | ||
14507 | if (getLinkNum) | ||
14508 | result.Add(new LSL_Integer(rayHit.Link)); | ||
14509 | if (getNormal) | ||
14510 | result.Add(new LSL_Vector(rayHit.Normal)); | ||
14511 | } | ||
14512 | result.Add(new LSL_Integer(hitCount)); | ||
14513 | |||
14514 | // Add to throttle data | ||
14515 | stopWatch.Stop(); | ||
14516 | CastRayCall castRayCall = new CastRayCall(); | ||
14517 | castRayCall.RegionId = regionId; | ||
14518 | castRayCall.UserId = userId; | ||
14519 | castRayCall.CalledMs = calledMs; | ||
14520 | castRayCall.UsedMs = (int)stopWatch.ElapsedMilliseconds; | ||
14521 | lock (m_castRayCalls) | ||
14522 | { | ||
14523 | m_castRayCalls.Add(castRayCall); | ||
14524 | } | ||
14525 | |||
14526 | // Return hits | ||
14527 | return result; | ||
14528 | } | ||
14529 | |||
14530 | /// <summary> | ||
14531 | /// Struct for transmitting parameters required for finding llCastRay ray hits. | ||
14532 | /// </summary> | ||
14533 | public struct RayTrans | ||
14534 | { | ||
14535 | public UUID PartId; | ||
14536 | public UUID GroupId; | ||
14537 | public int Link; | ||
14538 | public Vector3 ScalePart; | ||
14539 | public Vector3 PositionPart; | ||
14540 | public Quaternion RotationPart; | ||
14541 | public bool ShapeNeedsEnds; | ||
14542 | public Vector3 Position1Ray; | ||
14543 | public Vector3 Position1RayProj; | ||
14544 | public Vector3 VectorRayProj; | ||
14545 | } | ||
14546 | |||
14547 | /// <summary> | ||
14548 | /// Struct for llCastRay ray hits. | ||
14549 | /// </summary> | ||
14550 | public struct RayHit | ||
14551 | { | ||
14552 | public UUID PartId; | ||
14553 | public UUID GroupId; | ||
14554 | public int Link; | ||
14555 | public Vector3 Position; | ||
14556 | public Vector3 Normal; | ||
14557 | public float Distance; | ||
14558 | } | ||
14559 | |||
14560 | /// <summary> | ||
14561 | /// Struct for llCastRay throttle data. | ||
14562 | /// </summary> | ||
14563 | public struct CastRayCall | ||
14564 | { | ||
14565 | public UUID RegionId; | ||
14566 | public UUID UserId; | ||
14567 | public int CalledMs; | ||
14568 | public int UsedMs; | ||
14569 | } | ||
14570 | |||
14571 | /// <summary> | ||
14572 | /// Helper to check if a ray intersects a shape bounding box. | ||
14573 | /// </summary> | ||
14574 | private bool RayIntersectsShapeBox(Vector3 pos1RayProj, Vector3 pos2RayProj, Vector3 shapeBoxMax) | ||
14575 | { | ||
14576 | // Skip if ray can't intersect bounding box; | ||
14577 | Vector3 rayBoxProjMin = Vector3.Min(pos1RayProj, pos2RayProj); | ||
14578 | Vector3 rayBoxProjMax = Vector3.Max(pos1RayProj, pos2RayProj); | ||
14579 | if ( | ||
14580 | rayBoxProjMin.X > shapeBoxMax.X || rayBoxProjMin.Y > shapeBoxMax.Y || rayBoxProjMin.Z > shapeBoxMax.Z || | ||
14581 | rayBoxProjMax.X < -shapeBoxMax.X || rayBoxProjMax.Y < -shapeBoxMax.Y || rayBoxProjMax.Z < -shapeBoxMax.Z | ||
14582 | ) | ||
14583 | return false; | ||
14584 | |||
14585 | // Check if ray intersect any bounding box side | ||
14586 | int sign = 0; | ||
14587 | float dist = 0.0f; | ||
14588 | Vector3 posProj = Vector3.Zero; | ||
14589 | Vector3 vecRayProj = pos2RayProj - pos1RayProj; | ||
14590 | |||
14591 | // Check both X sides unless ray is parallell to them | ||
14592 | if (Math.Abs(vecRayProj.X) > m_floatToleranceInCastRay) | ||
14593 | { | ||
14594 | for (sign = -1; sign <= 1; sign += 2) | ||
14595 | { | ||
14596 | dist = ((float)sign * shapeBoxMax.X - pos1RayProj.X) / vecRayProj.X; | ||
14597 | posProj = pos1RayProj + vecRayProj * dist; | ||
14598 | if (Math.Abs(posProj.Y) <= shapeBoxMax.Y && Math.Abs(posProj.Z) <= shapeBoxMax.Z) | ||
14599 | return true; | ||
14600 | } | ||
14601 | } | ||
14602 | |||
14603 | // Check both Y sides unless ray is parallell to them | ||
14604 | if (Math.Abs(vecRayProj.Y) > m_floatToleranceInCastRay) | ||
14605 | { | ||
14606 | for (sign = -1; sign <= 1; sign += 2) | ||
14607 | { | ||
14608 | dist = ((float)sign * shapeBoxMax.Y - pos1RayProj.Y) / vecRayProj.Y; | ||
14609 | posProj = pos1RayProj + vecRayProj * dist; | ||
14610 | if (Math.Abs(posProj.X) <= shapeBoxMax.X && Math.Abs(posProj.Z) <= shapeBoxMax.Z) | ||
14611 | return true; | ||
14612 | } | ||
14613 | } | ||
14614 | |||
14615 | // Check both Z sides unless ray is parallell to them | ||
14616 | if (Math.Abs(vecRayProj.Z) > m_floatToleranceInCastRay) | ||
14617 | { | ||
14618 | for (sign = -1; sign <= 1; sign += 2) | ||
14619 | { | ||
14620 | dist = ((float)sign * shapeBoxMax.Z - pos1RayProj.Z) / vecRayProj.Z; | ||
14621 | posProj = pos1RayProj + vecRayProj * dist; | ||
14622 | if (Math.Abs(posProj.X) <= shapeBoxMax.X && Math.Abs(posProj.Y) <= shapeBoxMax.Y) | ||
14623 | return true; | ||
14624 | } | ||
14625 | } | ||
14626 | |||
14627 | // No hits on bounding box so return false | ||
14628 | return false; | ||
14629 | } | ||
14630 | |||
14631 | /// <summary> | ||
14632 | /// Helper to parse FacetedMesh for ray hits. | ||
14633 | /// </summary> | ||
14634 | private void AddRayInFacetedMesh(FacetedMesh mesh, RayTrans rayTrans, ref List<RayHit> rayHits) | ||
14635 | { | ||
14636 | if (mesh != null) | ||
14637 | { | ||
14638 | foreach (Face face in mesh.Faces) | ||
14639 | { | ||
14640 | for (int i = 0; i < face.Indices.Count; i += 3) | ||
14641 | { | ||
14642 | Tri triangle = new Tri(); | ||
14643 | triangle.p1 = face.Vertices[face.Indices[i]].Position; | ||
14644 | triangle.p2 = face.Vertices[face.Indices[i + 1]].Position; | ||
14645 | triangle.p3 = face.Vertices[face.Indices[i + 2]].Position; | ||
14646 | AddRayInTri(triangle, rayTrans, ref rayHits); | ||
14647 | } | ||
14648 | } | ||
14649 | } | ||
14650 | } | ||
14651 | |||
14652 | /// <summary> | ||
14653 | /// Helper to parse Tri (triangle) List for ray hits. | ||
14654 | /// </summary> | ||
14655 | private void AddRayInTris(List<Tri> triangles, RayTrans rayTrans, ref List<RayHit> rayHits) | ||
14656 | { | ||
14657 | foreach (Tri triangle in triangles) | ||
14658 | { | ||
14659 | AddRayInTri(triangle, rayTrans, ref rayHits); | ||
14660 | } | ||
14661 | } | ||
14662 | |||
14663 | /// <summary> | ||
14664 | /// Helper to add ray hit in a Tri (triangle). | ||
14665 | /// </summary> | ||
14666 | private void AddRayInTri(Tri triProj, RayTrans rayTrans, ref List<RayHit> rayHits) | ||
14667 | { | ||
14668 | // Check for hit in triangle | ||
14669 | Vector3 posHitProj; | ||
14670 | Vector3 normalProj; | ||
14671 | if (HitRayInTri(triProj, rayTrans.Position1RayProj, rayTrans.VectorRayProj, out posHitProj, out normalProj)) | ||
14672 | { | ||
14673 | // Hack to circumvent ghost face bug in PrimMesher by removing hits in (ghost) face plane through shape center | ||
14674 | if (Math.Abs(Vector3.Dot(posHitProj, normalProj)) < m_floatToleranceInCastRay && !rayTrans.ShapeNeedsEnds) | ||
14675 | return; | ||
14676 | |||
14677 | // Transform hit and normal to region coordinate system | ||
14678 | Vector3 posHit = rayTrans.PositionPart + (posHitProj * rayTrans.ScalePart) * rayTrans.RotationPart; | ||
14679 | Vector3 normal = Vector3.Normalize((normalProj * rayTrans.ScalePart) * rayTrans.RotationPart); | ||
14680 | |||
14681 | // Remove duplicate hits at triangle intersections | ||
14682 | float distance = Vector3.Distance(rayTrans.Position1Ray, posHit); | ||
14683 | for (int i = rayHits.Count - 1; i >= 0; i--) | ||
14684 | { | ||
14685 | if (rayHits[i].PartId != rayTrans.PartId) | ||
14686 | break; | ||
14687 | if (Math.Abs(rayHits[i].Distance - distance) < m_floatTolerance2InCastRay) | ||
14688 | return; | ||
14689 | } | ||
14690 | |||
14691 | // Build result data set | ||
14692 | RayHit rayHit = new RayHit(); | ||
14693 | rayHit.PartId = rayTrans.PartId; | ||
14694 | rayHit.GroupId = rayTrans.GroupId; | ||
14695 | rayHit.Link = rayTrans.Link; | ||
14696 | rayHit.Position = posHit; | ||
14697 | rayHit.Normal = normal; | ||
14698 | rayHit.Distance = distance; | ||
14699 | rayHits.Add(rayHit); | ||
14700 | } | ||
14701 | } | ||
14702 | |||
14703 | /// <summary> | ||
14704 | /// Helper to find ray hit in triangle | ||
14705 | /// </summary> | ||
14706 | bool HitRayInTri(Tri triProj, Vector3 pos1RayProj, Vector3 vecRayProj, out Vector3 posHitProj, out Vector3 normalProj) | ||
14707 | { | ||
14708 | float tol = m_floatToleranceInCastRay; | ||
14709 | posHitProj = Vector3.Zero; | ||
14710 | |||
14711 | // Calculate triangle edge vectors | ||
14712 | Vector3 vec1Proj = triProj.p2 - triProj.p1; | ||
14713 | Vector3 vec2Proj = triProj.p3 - triProj.p2; | ||
14714 | Vector3 vec3Proj = triProj.p1 - triProj.p3; | ||
14715 | |||
14716 | // Calculate triangle normal | ||
14717 | normalProj = Vector3.Cross(vec1Proj, vec2Proj); | ||
14718 | |||
14719 | // Skip if degenerate triangle or ray parallell with triangle plane | ||
14720 | float divisor = Vector3.Dot(vecRayProj, normalProj); | ||
14721 | if (Math.Abs(divisor) < tol) | ||
14722 | return false; | ||
14723 | |||
14724 | // Skip if exit and not configured to detect | ||
14725 | if (divisor > tol && !m_detectExitsInCastRay) | ||
14726 | return false; | ||
14727 | |||
14728 | // Skip if outside ray ends | ||
14729 | float distanceProj = Vector3.Dot(triProj.p1 - pos1RayProj, normalProj) / divisor; | ||
14730 | if (distanceProj < -tol || distanceProj > 1 + tol) | ||
14731 | return false; | ||
14732 | |||
14733 | // Calculate hit position in triangle | ||
14734 | posHitProj = pos1RayProj + vecRayProj * distanceProj; | ||
14735 | |||
14736 | // Skip if outside triangle bounding box | ||
14737 | Vector3 triProjMin = Vector3.Min(Vector3.Min(triProj.p1, triProj.p2), triProj.p3); | ||
14738 | Vector3 triProjMax = Vector3.Max(Vector3.Max(triProj.p1, triProj.p2), triProj.p3); | ||
14739 | if ( | ||
14740 | posHitProj.X < triProjMin.X - tol || posHitProj.Y < triProjMin.Y - tol || posHitProj.Z < triProjMin.Z - tol || | ||
14741 | posHitProj.X > triProjMax.X + tol || posHitProj.Y > triProjMax.Y + tol || posHitProj.Z > triProjMax.Z + tol | ||
14742 | ) | ||
14743 | return false; | ||
14744 | |||
14745 | // Skip if outside triangle | ||
14746 | if ( | ||
14747 | Vector3.Dot(Vector3.Cross(vec1Proj, normalProj), posHitProj - triProj.p1) > tol || | ||
14748 | Vector3.Dot(Vector3.Cross(vec2Proj, normalProj), posHitProj - triProj.p2) > tol || | ||
14749 | Vector3.Dot(Vector3.Cross(vec3Proj, normalProj), posHitProj - triProj.p3) > tol | ||
14750 | ) | ||
14751 | return false; | ||
14752 | |||
14753 | // Return hit | ||
14754 | return true; | ||
14755 | } | ||
14756 | |||
14757 | /// <summary> | ||
14758 | /// Helper to parse selected parts of HeightMap into a Tri (triangle) List and calculate bounding box. | ||
14759 | /// </summary> | ||
14760 | private List<Tri> TrisFromHeightmapUnderRay(Vector3 posStart, Vector3 posEnd, out Vector3 lower, out Vector3 upper) | ||
14761 | { | ||
14762 | // Get bounding X-Y rectangle of terrain under ray | ||
14763 | lower = Vector3.Min(posStart, posEnd); | ||
14764 | upper = Vector3.Max(posStart, posEnd); | ||
14765 | lower.X = (float)Math.Floor(lower.X); | ||
14766 | lower.Y = (float)Math.Floor(lower.Y); | ||
14767 | float zLower = float.MaxValue; | ||
14768 | upper.X = (float)Math.Ceiling(upper.X); | ||
14769 | upper.Y = (float)Math.Ceiling(upper.Y); | ||
14770 | float zUpper = float.MinValue; | ||
14771 | |||
14772 | // Initialize Tri (triangle) List | ||
14773 | List<Tri> triangles = new List<Tri>(); | ||
14774 | |||
14775 | // Set parsing lane direction to major ray X-Y axis | ||
14776 | Vector3 vec = posEnd - posStart; | ||
14777 | float xAbs = Math.Abs(vec.X); | ||
14778 | float yAbs = Math.Abs(vec.Y); | ||
14779 | bool bigX = true; | ||
14780 | if (yAbs > xAbs) | ||
14781 | { | ||
14782 | bigX = false; | ||
14783 | vec = vec / yAbs; | ||
14784 | } | ||
14785 | else if (xAbs > yAbs || xAbs > 0.0f) | ||
14786 | vec = vec / xAbs; | ||
14787 | else | ||
14788 | vec = new Vector3(1.0f, 1.0f, 0.0f); | ||
14789 | |||
14790 | // Simplify by start parsing in lower end of lane | ||
14791 | if ((bigX && vec.X < 0.0f) || (!bigX && vec.Y < 0.0f)) | ||
14792 | { | ||
14793 | Vector3 posTemp = posStart; | ||
14794 | posStart = posEnd; | ||
14795 | posEnd = posTemp; | ||
14796 | vec = vec * -1.0f; | ||
14797 | } | ||
14798 | |||
14799 | // First 1x1 rectangle under ray | ||
14800 | float xFloorOld = 0.0f; | ||
14801 | float yFloorOld = 0.0f; | ||
14802 | Vector3 pos = posStart; | ||
14803 | float xFloor = (float)Math.Floor(pos.X); | ||
14804 | float yFloor = (float)Math.Floor(pos.Y); | ||
14805 | AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper); | ||
14806 | |||
14807 | // Parse every remaining 1x1 rectangle under ray | ||
14808 | while (pos != posEnd) | ||
14809 | { | ||
14810 | // Next 1x1 rectangle under ray | ||
14811 | xFloorOld = xFloor; | ||
14812 | yFloorOld = yFloor; | ||
14813 | pos = pos + vec; | ||
14814 | |||
14815 | // Clip position to 1x1 rectangle border | ||
14816 | xFloor = (float)Math.Floor(pos.X); | ||
14817 | yFloor = (float)Math.Floor(pos.Y); | ||
14818 | if (bigX && pos.X > xFloor) | ||
14819 | { | ||
14820 | pos.Y -= vec.Y * (pos.X - xFloor); | ||
14821 | pos.X = xFloor; | ||
14822 | } | ||
14823 | else if (!bigX && pos.Y > yFloor) | ||
14824 | { | ||
14825 | pos.X -= vec.X * (pos.Y - yFloor); | ||
14826 | pos.Y = yFloor; | ||
14827 | } | ||
14828 | |||
14829 | // Last 1x1 rectangle under ray | ||
14830 | if ((bigX && pos.X >= posEnd.X) || (!bigX && pos.Y >= posEnd.Y)) | ||
14831 | { | ||
14832 | pos = posEnd; | ||
14833 | xFloor = (float)Math.Floor(pos.X); | ||
14834 | yFloor = (float)Math.Floor(pos.Y); | ||
14835 | } | ||
14836 | |||
14837 | // Add new 1x1 rectangle in lane | ||
14838 | if ((bigX && xFloor != xFloorOld) || (!bigX && yFloor != yFloorOld)) | ||
14839 | AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper); | ||
14840 | // Add last 1x1 rectangle in old lane at lane shift | ||
14841 | if (bigX && yFloor != yFloorOld) | ||
14842 | AddTrisFromHeightmap(xFloor, yFloorOld, ref triangles, ref zLower, ref zUpper); | ||
14843 | if (!bigX && xFloor != xFloorOld) | ||
14844 | AddTrisFromHeightmap(xFloorOld, yFloor, ref triangles, ref zLower, ref zUpper); | ||
14845 | } | ||
14846 | |||
14847 | // Finalize bounding box Z | ||
14848 | lower.Z = zLower; | ||
14849 | upper.Z = zUpper; | ||
14850 | |||
14851 | // Done and returning Tri (triangle)List | ||
14852 | return triangles; | ||
14853 | } | ||
14854 | |||
14855 | /// <summary> | ||
14856 | /// Helper to add HeightMap squares into Tri (triangle) List and adjust bounding box. | ||
14857 | /// </summary> | ||
14858 | private void AddTrisFromHeightmap(float xPos, float yPos, ref List<Tri> triangles, ref float zLower, ref float zUpper) | ||
14859 | { | ||
14860 | int xInt = (int)xPos; | ||
14861 | int yInt = (int)yPos; | ||
14862 | |||
14863 | // Corner 1 of 1x1 rectangle | ||
14864 | int x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1); | ||
14865 | int y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1); | ||
14866 | Vector3 pos1 = new Vector3(x, y, (float)World.Heightmap[x, y]); | ||
14867 | // Adjust bounding box | ||
14868 | zLower = Math.Min(zLower, pos1.Z); | ||
14869 | zUpper = Math.Max(zUpper, pos1.Z); | ||
14870 | |||
14871 | // Corner 2 of 1x1 rectangle | ||
14872 | x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1); | ||
14873 | y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1); | ||
14874 | Vector3 pos2 = new Vector3(x, y, (float)World.Heightmap[x, y]); | ||
14875 | // Adjust bounding box | ||
14876 | zLower = Math.Min(zLower, pos2.Z); | ||
14877 | zUpper = Math.Max(zUpper, pos2.Z); | ||
14878 | |||
14879 | // Corner 3 of 1x1 rectangle | ||
14880 | x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1); | ||
14881 | y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1); | ||
14882 | Vector3 pos3 = new Vector3(x, y, (float)World.Heightmap[x, y]); | ||
14883 | // Adjust bounding box | ||
14884 | zLower = Math.Min(zLower, pos3.Z); | ||
14885 | zUpper = Math.Max(zUpper, pos3.Z); | ||
14886 | |||
14887 | // Corner 4 of 1x1 rectangle | ||
14888 | x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1); | ||
14889 | y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1); | ||
14890 | Vector3 pos4 = new Vector3(x, y, (float)World.Heightmap[x, y]); | ||
14891 | // Adjust bounding box | ||
14892 | zLower = Math.Min(zLower, pos4.Z); | ||
14893 | zUpper = Math.Max(zUpper, pos4.Z); | ||
14894 | |||
14895 | // Add triangle 1 | ||
14896 | Tri triangle1 = new Tri(); | ||
14897 | triangle1.p1 = pos1; | ||
14898 | triangle1.p2 = pos2; | ||
14899 | triangle1.p3 = pos3; | ||
14900 | triangles.Add(triangle1); | ||
14901 | |||
14902 | // Add triangle 2 | ||
14903 | Tri triangle2 = new Tri(); | ||
14904 | triangle2.p1 = pos3; | ||
14905 | triangle2.p2 = pos4; | ||
14906 | triangle2.p3 = pos1; | ||
14907 | triangles.Add(triangle2); | ||
14908 | } | ||
14909 | |||
14910 | /// <summary> | ||
14911 | /// Helper to get link number for a UUID. | ||
14912 | /// </summary> | ||
14913 | private int UUID2LinkNumber(SceneObjectPart part, UUID id) | ||
14914 | { | ||
14915 | SceneObjectGroup group = part.ParentGroup; | ||
14916 | if (group != null) | ||
14917 | { | ||
14918 | // Parse every link for UUID | ||
14919 | int linkCount = group.PrimCount + group.GetSittingAvatarsCount(); | ||
14920 | for (int link = linkCount; link > 0; link--) | ||
14921 | { | ||
14922 | ISceneEntity entity = GetLinkEntity(part, link); | ||
14923 | // Return link number if UUID match | ||
14924 | if (entity != null && entity.UUID == id) | ||
14925 | return link; | ||
14926 | } | ||
14927 | } | ||
14928 | // Return link number 0 if no links or UUID matches | ||
14929 | return 0; | ||
14930 | } | ||
14931 | |||
11408 | public LSL_Integer llManageEstateAccess(int action, string avatar) | 14932 | public LSL_Integer llManageEstateAccess(int action, string avatar) |
11409 | { | 14933 | { |
11410 | m_host.AddScriptLPS(1); | 14934 | m_host.AddScriptLPS(1); |
@@ -11477,8 +15001,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11477 | public LSL_Integer llGetMemoryLimit() | 15001 | public LSL_Integer llGetMemoryLimit() |
11478 | { | 15002 | { |
11479 | m_host.AddScriptLPS(1); | 15003 | m_host.AddScriptLPS(1); |
11480 | // The value returned for LSO scripts in SL | 15004 | // The value returned for Mono scripts in SL |
11481 | return 16384; | 15005 | return 65536; |
11482 | } | 15006 | } |
11483 | 15007 | ||
11484 | public LSL_Integer llSetMemoryLimit(LSL_Integer limit) | 15008 | public LSL_Integer llSetMemoryLimit(LSL_Integer limit) |
@@ -11491,15 +15015,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11491 | public LSL_Integer llGetSPMaxMemory() | 15015 | public LSL_Integer llGetSPMaxMemory() |
11492 | { | 15016 | { |
11493 | m_host.AddScriptLPS(1); | 15017 | m_host.AddScriptLPS(1); |
11494 | // The value returned for LSO scripts in SL | 15018 | // The value returned for Mono scripts in SL |
11495 | return 16384; | 15019 | return 65536; |
11496 | } | 15020 | } |
11497 | 15021 | ||
11498 | public LSL_Integer llGetUsedMemory() | 15022 | public virtual LSL_Integer llGetUsedMemory() |
11499 | { | 15023 | { |
11500 | m_host.AddScriptLPS(1); | 15024 | m_host.AddScriptLPS(1); |
11501 | // The value returned for LSO scripts in SL | 15025 | // The value returned for Mono scripts in SL |
11502 | return 16384; | 15026 | return 65536; |
11503 | } | 15027 | } |
11504 | 15028 | ||
11505 | public void llScriptProfiler(LSL_Integer flags) | 15029 | public void llScriptProfiler(LSL_Integer flags) |
@@ -11514,16 +15038,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11514 | // them from this region as they are completed | 15038 | // them from this region as they are completed |
11515 | // | 15039 | // |
11516 | 15040 | ||
11517 | public void llGetEnv(LSL_String name) | ||
11518 | { | ||
11519 | m_host.AddScriptLPS(1); | ||
11520 | NotImplemented("llGetEnv"); | ||
11521 | } | ||
11522 | |||
11523 | public void llSetSoundQueueing(int queue) | 15041 | public void llSetSoundQueueing(int queue) |
11524 | { | 15042 | { |
11525 | m_host.AddScriptLPS(1); | 15043 | m_host.AddScriptLPS(1); |
11526 | NotImplemented("llSetSoundQueueing"); | 15044 | |
15045 | if (m_SoundModule != null) | ||
15046 | m_SoundModule.SetSoundQueueing(m_host.UUID, queue == ScriptBaseClass.TRUE.value); | ||
11527 | } | 15047 | } |
11528 | 15048 | ||
11529 | public void llCollisionSprite(string impact_sprite) | 15049 | public void llCollisionSprite(string impact_sprite) |
@@ -11538,6 +15058,79 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11538 | NotImplemented("llGodLikeRezObject"); | 15058 | NotImplemented("llGodLikeRezObject"); |
11539 | } | 15059 | } |
11540 | 15060 | ||
15061 | public LSL_String llTransferLindenDollars(string destination, int amount) | ||
15062 | { | ||
15063 | UUID txn = UUID.Random(); | ||
15064 | |||
15065 | Util.FireAndForget(delegate(object x) | ||
15066 | { | ||
15067 | int replycode = 0; | ||
15068 | string replydata = destination + "," + amount.ToString(); | ||
15069 | |||
15070 | try | ||
15071 | { | ||
15072 | TaskInventoryItem item = m_item; | ||
15073 | if (item == null) | ||
15074 | { | ||
15075 | replydata = "SERVICE_ERROR"; | ||
15076 | return; | ||
15077 | } | ||
15078 | |||
15079 | m_host.AddScriptLPS(1); | ||
15080 | |||
15081 | if (item.PermsGranter == UUID.Zero) | ||
15082 | { | ||
15083 | replydata = "MISSING_PERMISSION_DEBIT"; | ||
15084 | return; | ||
15085 | } | ||
15086 | |||
15087 | if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0) | ||
15088 | { | ||
15089 | replydata = "MISSING_PERMISSION_DEBIT"; | ||
15090 | return; | ||
15091 | } | ||
15092 | |||
15093 | UUID toID = new UUID(); | ||
15094 | |||
15095 | if (!UUID.TryParse(destination, out toID)) | ||
15096 | { | ||
15097 | replydata = "INVALID_AGENT"; | ||
15098 | return; | ||
15099 | } | ||
15100 | |||
15101 | IMoneyModule money = World.RequestModuleInterface<IMoneyModule>(); | ||
15102 | |||
15103 | if (money == null) | ||
15104 | { | ||
15105 | replydata = "TRANSFERS_DISABLED"; | ||
15106 | return; | ||
15107 | } | ||
15108 | |||
15109 | bool result = money.ObjectGiveMoney( | ||
15110 | m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount); | ||
15111 | |||
15112 | if (result) | ||
15113 | { | ||
15114 | replycode = 1; | ||
15115 | return; | ||
15116 | } | ||
15117 | |||
15118 | replydata = "LINDENDOLLAR_INSUFFICIENTFUNDS"; | ||
15119 | } | ||
15120 | finally | ||
15121 | { | ||
15122 | m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams( | ||
15123 | "transaction_result", new Object[] { | ||
15124 | new LSL_String(txn.ToString()), | ||
15125 | new LSL_Integer(replycode), | ||
15126 | new LSL_String(replydata) }, | ||
15127 | new DetectParams[0])); | ||
15128 | } | ||
15129 | }, null, "LSL_Api.llTransferLindenDollars"); | ||
15130 | |||
15131 | return txn.ToString(); | ||
15132 | } | ||
15133 | |||
11541 | #endregion | 15134 | #endregion |
11542 | } | 15135 | } |
11543 | 15136 | ||
@@ -11549,12 +15142,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11549 | public DateTime lastRef; | 15142 | public DateTime lastRef; |
11550 | } | 15143 | } |
11551 | 15144 | ||
11552 | protected static Dictionary<UUID, Notecard> m_Notecards = | 15145 | private static Dictionary<UUID, Notecard> m_Notecards = |
11553 | new Dictionary<UUID, Notecard>(); | 15146 | new Dictionary<UUID, Notecard>(); |
11554 | 15147 | ||
11555 | public static void Cache(UUID assetID, string text) | 15148 | public static void Cache(UUID assetID, byte[] text) |
11556 | { | 15149 | { |
11557 | CacheCheck(); | 15150 | CheckCache(); |
11558 | 15151 | ||
11559 | lock (m_Notecards) | 15152 | lock (m_Notecards) |
11560 | { | 15153 | { |
@@ -11563,7 +15156,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11563 | 15156 | ||
11564 | Notecard nc = new Notecard(); | 15157 | Notecard nc = new Notecard(); |
11565 | nc.lastRef = DateTime.Now; | 15158 | nc.lastRef = DateTime.Now; |
11566 | nc.text = SLUtil.ParseNotecardToList(text).ToArray(); | 15159 | try |
15160 | { | ||
15161 | nc.text = SLUtil.ParseNotecardToArray(text); | ||
15162 | } | ||
15163 | catch(SLUtil.NotANotecardFormatException) | ||
15164 | { | ||
15165 | nc.text = new string[0]; | ||
15166 | } | ||
11567 | m_Notecards[assetID] = nc; | 15167 | m_Notecards[assetID] = nc; |
11568 | } | 15168 | } |
11569 | } | 15169 | } |
@@ -11639,13 +15239,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
11639 | return line; | 15239 | return line; |
11640 | } | 15240 | } |
11641 | 15241 | ||
11642 | public static void CacheCheck() | 15242 | public static void CheckCache() |
11643 | { | 15243 | { |
11644 | foreach (UUID key in new List<UUID>(m_Notecards.Keys)) | 15244 | lock (m_Notecards) |
11645 | { | 15245 | { |
11646 | Notecard nc = m_Notecards[key]; | 15246 | foreach (UUID key in new List<UUID>(m_Notecards.Keys)) |
11647 | if (nc.lastRef.AddSeconds(30) < DateTime.Now) | 15247 | { |
11648 | m_Notecards.Remove(key); | 15248 | Notecard nc = m_Notecards[key]; |
15249 | if (nc.lastRef.AddSeconds(30) < DateTime.Now) | ||
15250 | m_Notecards.Remove(key); | ||
15251 | } | ||
11649 | } | 15252 | } |
11650 | } | 15253 | } |
11651 | } | 15254 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs index ceb4660..e5e43f8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs | |||
@@ -30,6 +30,7 @@ using System.Reflection; | |||
30 | using System.Collections; | 30 | using System.Collections; |
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using System.Runtime.Remoting.Lifetime; | 32 | using System.Runtime.Remoting.Lifetime; |
33 | using System.Threading; | ||
33 | using OpenMetaverse; | 34 | using OpenMetaverse; |
34 | using Nini.Config; | 35 | using Nini.Config; |
35 | using OpenSim; | 36 | using OpenSim; |
@@ -61,9 +62,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
61 | internal bool m_LSFunctionsEnabled = false; | 62 | internal bool m_LSFunctionsEnabled = false; |
62 | internal IScriptModuleComms m_comms = null; | 63 | internal IScriptModuleComms m_comms = null; |
63 | 64 | ||
64 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) | 65 | public void Initialize( |
66 | IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item) | ||
65 | { | 67 | { |
66 | m_ScriptEngine = ScriptEngine; | 68 | m_ScriptEngine = scriptEngine; |
67 | m_host = host; | 69 | m_host = host; |
68 | 70 | ||
69 | if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false)) | 71 | if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false)) |
@@ -92,10 +94,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
92 | get { return m_ScriptEngine.World; } | 94 | get { return m_ScriptEngine.World; } |
93 | } | 95 | } |
94 | 96 | ||
95 | // | 97 | /// <summary> |
96 | //Dumps an error message on the debug console. | 98 | /// Dumps an error message on the debug console. |
97 | // | 99 | /// </summary> |
98 | |||
99 | internal void LSShoutError(string message) | 100 | internal void LSShoutError(string message) |
100 | { | 101 | { |
101 | if (message.Length > 1023) | 102 | if (message.Length > 1023) |
@@ -264,175 +265,445 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
264 | int idx = 0; | 265 | int idx = 0; |
265 | while (idx < rules.Length) | 266 | while (idx < rules.Length) |
266 | { | 267 | { |
267 | uint rule = (uint)rules.GetLSLIntegerItem(idx); | 268 | uint rule; |
269 | |||
270 | try | ||
271 | { | ||
272 | rule = (uint)rules.GetLSLIntegerItem(idx); | ||
273 | } | ||
274 | catch (InvalidCastException) | ||
275 | { | ||
276 | throw new InvalidCastException(string.Format("Error running rule type: arg #{0} - parameter type must be integer", idx)); | ||
277 | } | ||
278 | |||
268 | LSL_Types.Quaternion iQ; | 279 | LSL_Types.Quaternion iQ; |
269 | LSL_Types.Vector3 iV; | 280 | LSL_Types.Vector3 iV; |
270 | switch (rule) | 281 | switch (rule) |
271 | { | 282 | { |
272 | case (int)ScriptBaseClass.WL_SUN_MOON_POSITION: | 283 | case (int)ScriptBaseClass.WL_SUN_MOON_POSITION: |
273 | idx++; | 284 | idx++; |
274 | wl.sunMoonPosition = (float)rules.GetLSLFloatItem(idx); | 285 | try |
286 | { | ||
287 | wl.sunMoonPosition = (float)rules.GetLSLFloatItem(idx); | ||
288 | } | ||
289 | catch (InvalidCastException) | ||
290 | { | ||
291 | throw new InvalidCastException(string.Format("Error running rule WL_SUN_MOON_POSITION: arg #{0} - parameter 1 must be float", idx)); | ||
292 | } | ||
275 | break; | 293 | break; |
276 | case (int)ScriptBaseClass.WL_AMBIENT: | 294 | case (int)ScriptBaseClass.WL_AMBIENT: |
277 | idx++; | 295 | idx++; |
278 | iQ = rules.GetQuaternionItem(idx); | 296 | try |
297 | { | ||
298 | iQ = rules.GetQuaternionItem(idx); | ||
299 | } | ||
300 | catch (InvalidCastException) | ||
301 | { | ||
302 | throw new InvalidCastException(string.Format("Error running rule WL_AMBIENT: arg #{0} - parameter 1 must be rotation", idx)); | ||
303 | } | ||
279 | wl.ambient = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); | 304 | wl.ambient = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); |
280 | break; | 305 | break; |
281 | case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION: | 306 | case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION: |
282 | idx++; | 307 | idx++; |
283 | iV = rules.GetVector3Item(idx); | 308 | try |
309 | { | ||
310 | iV = rules.GetVector3Item(idx); | ||
311 | } | ||
312 | catch (InvalidCastException) | ||
313 | { | ||
314 | throw new InvalidCastException(string.Format("Error running rule WL_BIG_WAVE_DIRECTION: arg #{0} - parameter 1 must be vector", idx)); | ||
315 | } | ||
284 | wl.bigWaveDirection = new Vector2((float)iV.x, (float)iV.y); | 316 | wl.bigWaveDirection = new Vector2((float)iV.x, (float)iV.y); |
285 | break; | 317 | break; |
286 | case (int)ScriptBaseClass.WL_BLUE_DENSITY: | 318 | case (int)ScriptBaseClass.WL_BLUE_DENSITY: |
287 | idx++; | 319 | idx++; |
288 | iQ = rules.GetQuaternionItem(idx); | 320 | try |
321 | { | ||
322 | iQ = rules.GetQuaternionItem(idx); | ||
323 | } | ||
324 | catch (InvalidCastException) | ||
325 | { | ||
326 | throw new InvalidCastException(string.Format("Error running rule WL_BLUE_DENSITY: arg #{0} - parameter 1 must be rotation", idx)); | ||
327 | } | ||
289 | wl.blueDensity = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); | 328 | wl.blueDensity = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); |
290 | break; | 329 | break; |
291 | case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER: | 330 | case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER: |
292 | idx++; | 331 | idx++; |
293 | wl.blurMultiplier = (float)rules.GetLSLFloatItem(idx); | 332 | try |
333 | { | ||
334 | wl.blurMultiplier = (float)rules.GetLSLFloatItem(idx); | ||
335 | } | ||
336 | catch (InvalidCastException) | ||
337 | { | ||
338 | throw new InvalidCastException(string.Format("Error running rule WL_BLUR_MULTIPLIER: arg #{0} - parameter 1 must be float", idx)); | ||
339 | } | ||
294 | break; | 340 | break; |
295 | case (int)ScriptBaseClass.WL_CLOUD_COLOR: | 341 | case (int)ScriptBaseClass.WL_CLOUD_COLOR: |
296 | idx++; | 342 | idx++; |
297 | iQ = rules.GetQuaternionItem(idx); | 343 | try |
344 | { | ||
345 | iQ = rules.GetQuaternionItem(idx); | ||
346 | } | ||
347 | catch (InvalidCastException) | ||
348 | { | ||
349 | throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_COLOR: arg #{0} - parameter 1 must be rotation", idx)); | ||
350 | } | ||
298 | wl.cloudColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); | 351 | wl.cloudColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); |
299 | break; | 352 | break; |
300 | case (int)ScriptBaseClass.WL_CLOUD_COVERAGE: | 353 | case (int)ScriptBaseClass.WL_CLOUD_COVERAGE: |
301 | idx++; | 354 | idx++; |
302 | wl.cloudCoverage = (float)rules.GetLSLFloatItem(idx); | 355 | try |
356 | { | ||
357 | wl.cloudCoverage = (float)rules.GetLSLFloatItem(idx); | ||
358 | } | ||
359 | catch (InvalidCastException) | ||
360 | { | ||
361 | throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_COVERAGE: arg #{0} - parameter 1 must be float", idx)); | ||
362 | } | ||
303 | break; | 363 | break; |
304 | case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY: | 364 | case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY: |
305 | idx++; | 365 | idx++; |
306 | iV = rules.GetVector3Item(idx); | 366 | try |
367 | { | ||
368 | iV = rules.GetVector3Item(idx); | ||
369 | } | ||
370 | catch (InvalidCastException) | ||
371 | { | ||
372 | throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_DETAIL_XY_DENSITY: arg #{0} - parameter 1 must be vector", idx)); | ||
373 | } | ||
307 | wl.cloudDetailXYDensity = iV; | 374 | wl.cloudDetailXYDensity = iV; |
308 | break; | 375 | break; |
309 | case (int)ScriptBaseClass.WL_CLOUD_SCALE: | 376 | case (int)ScriptBaseClass.WL_CLOUD_SCALE: |
310 | idx++; | 377 | idx++; |
311 | wl.cloudScale = (float)rules.GetLSLFloatItem(idx); | 378 | try |
379 | { | ||
380 | wl.cloudScale = (float)rules.GetLSLFloatItem(idx); | ||
381 | } | ||
382 | catch (InvalidCastException) | ||
383 | { | ||
384 | throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCALE: arg #{0} - parameter 1 must be float", idx)); | ||
385 | } | ||
312 | break; | 386 | break; |
313 | case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X: | 387 | case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X: |
314 | idx++; | 388 | idx++; |
315 | wl.cloudScrollX = (float)rules.GetLSLFloatItem(idx); | 389 | try |
390 | { | ||
391 | wl.cloudScrollX = (float)rules.GetLSLFloatItem(idx); | ||
392 | } | ||
393 | catch (InvalidCastException) | ||
394 | { | ||
395 | throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_X: arg #{0} - parameter 1 must be float", idx)); | ||
396 | } | ||
316 | break; | 397 | break; |
317 | case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK: | 398 | case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK: |
318 | idx++; | 399 | idx++; |
319 | wl.cloudScrollXLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false; | 400 | try |
401 | { | ||
402 | wl.cloudScrollXLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false; | ||
403 | } | ||
404 | catch (InvalidCastException) | ||
405 | { | ||
406 | throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_Y_LOCK: arg #{0} - parameter 1 must be integer", idx)); | ||
407 | } | ||
320 | break; | 408 | break; |
321 | case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y: | 409 | case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y: |
322 | idx++; | 410 | idx++; |
323 | wl.cloudScrollY = (float)rules.GetLSLFloatItem(idx); | 411 | try |
412 | { | ||
413 | wl.cloudScrollY = (float)rules.GetLSLFloatItem(idx); | ||
414 | } | ||
415 | catch (InvalidCastException) | ||
416 | { | ||
417 | throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_Y: arg #{0} - parameter 1 must be float", idx)); | ||
418 | } | ||
324 | break; | 419 | break; |
325 | case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK: | 420 | case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK: |
326 | idx++; | 421 | idx++; |
327 | wl.cloudScrollYLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false; | 422 | try |
423 | { | ||
424 | wl.cloudScrollYLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false; | ||
425 | } | ||
426 | catch (InvalidCastException) | ||
427 | { | ||
428 | throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_Y_LOCK: arg #{0} - parameter 1 must be integer", idx)); | ||
429 | } | ||
328 | break; | 430 | break; |
329 | case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY: | 431 | case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY: |
330 | idx++; | 432 | idx++; |
331 | iV = rules.GetVector3Item(idx); | 433 | try |
434 | { | ||
435 | iV = rules.GetVector3Item(idx); | ||
436 | } | ||
437 | catch (InvalidCastException) | ||
438 | { | ||
439 | throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_XY_DENSITY: arg #{0} - parameter 1 must be vector", idx)); | ||
440 | } | ||
332 | wl.cloudXYDensity = iV; | 441 | wl.cloudXYDensity = iV; |
333 | break; | 442 | break; |
334 | case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER: | 443 | case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER: |
335 | idx++; | 444 | idx++; |
336 | wl.densityMultiplier = (float)rules.GetLSLFloatItem(idx); | 445 | try |
446 | { | ||
447 | wl.densityMultiplier = (float)rules.GetLSLFloatItem(idx); | ||
448 | } | ||
449 | catch (InvalidCastException) | ||
450 | { | ||
451 | throw new InvalidCastException(string.Format("Error running rule WL_DENSITY_MULTIPLIER: arg #{0} - parameter 1 must be float", idx)); | ||
452 | } | ||
337 | break; | 453 | break; |
338 | case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER: | 454 | case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER: |
339 | idx++; | 455 | idx++; |
340 | wl.distanceMultiplier = (float)rules.GetLSLFloatItem(idx); | 456 | try |
457 | { | ||
458 | wl.distanceMultiplier = (float)rules.GetLSLFloatItem(idx); | ||
459 | } | ||
460 | catch (InvalidCastException) | ||
461 | { | ||
462 | throw new InvalidCastException(string.Format("Error running rule WL_DISTANCE_MULTIPLIER: arg #{0} - parameter 1 must be float", idx)); | ||
463 | } | ||
341 | break; | 464 | break; |
342 | case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS: | 465 | case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS: |
343 | idx++; | 466 | idx++; |
344 | wl.drawClassicClouds = rules.GetLSLIntegerItem(idx).value == 1 ? true : false; | 467 | try |
468 | { | ||
469 | wl.drawClassicClouds = rules.GetLSLIntegerItem(idx).value == 1 ? true : false; | ||
470 | } | ||
471 | catch (InvalidCastException) | ||
472 | { | ||
473 | throw new InvalidCastException(string.Format("Error running rule WL_DRAW_CLASSIC_CLOUDS: arg #{0} - parameter 1 must be integer", idx)); | ||
474 | } | ||
345 | break; | 475 | break; |
346 | case (int)ScriptBaseClass.WL_EAST_ANGLE: | 476 | case (int)ScriptBaseClass.WL_EAST_ANGLE: |
347 | idx++; | 477 | idx++; |
348 | wl.eastAngle = (float)rules.GetLSLFloatItem(idx); | 478 | try |
479 | { | ||
480 | wl.eastAngle = (float)rules.GetLSLFloatItem(idx); | ||
481 | } | ||
482 | catch (InvalidCastException) | ||
483 | { | ||
484 | throw new InvalidCastException(string.Format("Error running rule WL_EAST_ANGLE: arg #{0} - parameter 1 must be float", idx)); | ||
485 | } | ||
349 | break; | 486 | break; |
350 | case (int)ScriptBaseClass.WL_FRESNEL_OFFSET: | 487 | case (int)ScriptBaseClass.WL_FRESNEL_OFFSET: |
351 | idx++; | 488 | idx++; |
352 | wl.fresnelOffset = (float)rules.GetLSLFloatItem(idx); | 489 | try |
490 | { | ||
491 | wl.fresnelOffset = (float)rules.GetLSLFloatItem(idx); | ||
492 | } | ||
493 | catch (InvalidCastException) | ||
494 | { | ||
495 | throw new InvalidCastException(string.Format("Error running rule WL_FRESNEL_OFFSET: arg #{0} - parameter 1 must be float", idx)); | ||
496 | } | ||
353 | break; | 497 | break; |
354 | case (int)ScriptBaseClass.WL_FRESNEL_SCALE: | 498 | case (int)ScriptBaseClass.WL_FRESNEL_SCALE: |
355 | idx++; | 499 | idx++; |
356 | wl.fresnelScale = (float)rules.GetLSLFloatItem(idx); | 500 | try |
501 | { | ||
502 | wl.fresnelScale = (float)rules.GetLSLFloatItem(idx); | ||
503 | } | ||
504 | catch (InvalidCastException) | ||
505 | { | ||
506 | throw new InvalidCastException(string.Format("Error running rule WL_FRESNEL_SCALE: arg #{0} - parameter 1 must be float", idx)); | ||
507 | } | ||
357 | break; | 508 | break; |
358 | case (int)ScriptBaseClass.WL_HAZE_DENSITY: | 509 | case (int)ScriptBaseClass.WL_HAZE_DENSITY: |
359 | idx++; | 510 | idx++; |
360 | wl.hazeDensity = (float)rules.GetLSLFloatItem(idx); | 511 | try |
512 | { | ||
513 | wl.hazeDensity = (float)rules.GetLSLFloatItem(idx); | ||
514 | } | ||
515 | catch (InvalidCastException) | ||
516 | { | ||
517 | throw new InvalidCastException(string.Format("Error running rule WL_HAZE_DENSITY: arg #{0} - parameter 1 must be float", idx)); | ||
518 | } | ||
361 | break; | 519 | break; |
362 | case (int)ScriptBaseClass.WL_HAZE_HORIZON: | 520 | case (int)ScriptBaseClass.WL_HAZE_HORIZON: |
363 | idx++; | 521 | idx++; |
364 | wl.hazeHorizon = (float)rules.GetLSLFloatItem(idx); | 522 | try |
523 | { | ||
524 | wl.hazeHorizon = (float)rules.GetLSLFloatItem(idx); | ||
525 | } | ||
526 | catch (InvalidCastException) | ||
527 | { | ||
528 | throw new InvalidCastException(string.Format("Error running rule WL_HAZE_HORIZON: arg #{0} - parameter 1 must be float", idx)); | ||
529 | } | ||
365 | break; | 530 | break; |
366 | case (int)ScriptBaseClass.WL_HORIZON: | 531 | case (int)ScriptBaseClass.WL_HORIZON: |
367 | idx++; | 532 | idx++; |
368 | iQ = rules.GetQuaternionItem(idx); | 533 | try |
534 | { | ||
535 | iQ = rules.GetQuaternionItem(idx); | ||
536 | } | ||
537 | catch (InvalidCastException) | ||
538 | { | ||
539 | throw new InvalidCastException(string.Format("Error running rule WL_HORIZON: arg #{0} - parameter 1 must be rotation", idx)); | ||
540 | } | ||
369 | wl.horizon = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); | 541 | wl.horizon = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); |
370 | break; | 542 | break; |
371 | case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION: | 543 | case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION: |
372 | idx++; | 544 | idx++; |
373 | iV = rules.GetVector3Item(idx); | 545 | try |
546 | { | ||
547 | iV = rules.GetVector3Item(idx); | ||
548 | } | ||
549 | catch (InvalidCastException) | ||
550 | { | ||
551 | throw new InvalidCastException(string.Format("Error running rule WL_LITTLE_WAVE_DIRECTION: arg #{0} - parameter 1 must be vector", idx)); | ||
552 | } | ||
374 | wl.littleWaveDirection = new Vector2((float)iV.x, (float)iV.y); | 553 | wl.littleWaveDirection = new Vector2((float)iV.x, (float)iV.y); |
375 | break; | 554 | break; |
376 | case (int)ScriptBaseClass.WL_MAX_ALTITUDE: | 555 | case (int)ScriptBaseClass.WL_MAX_ALTITUDE: |
377 | idx++; | 556 | idx++; |
378 | wl.maxAltitude = (ushort)rules.GetLSLIntegerItem(idx).value; | 557 | try |
558 | { | ||
559 | wl.maxAltitude = (ushort)rules.GetLSLIntegerItem(idx).value; | ||
560 | } | ||
561 | catch (InvalidCastException) | ||
562 | { | ||
563 | throw new InvalidCastException(string.Format("Error running rule WL_MAX_ALTITUDE: arg #{0} - parameter 1 must be integer", idx)); | ||
564 | } | ||
379 | break; | 565 | break; |
380 | case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE: | 566 | case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE: |
381 | idx++; | 567 | idx++; |
382 | wl.normalMapTexture = new UUID(rules.GetLSLStringItem(idx).m_string); | 568 | try |
569 | { | ||
570 | wl.normalMapTexture = new UUID(rules.GetLSLStringItem(idx).m_string); | ||
571 | } | ||
572 | catch (ArgumentException) | ||
573 | { | ||
574 | throw new InvalidCastException(string.Format("Error running rule WL_NORMAL_MAP_TEXTURE: arg #{0} - parameter 1 must be key", idx)); | ||
575 | } | ||
383 | break; | 576 | break; |
384 | case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE: | 577 | case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE: |
385 | idx++; | 578 | idx++; |
386 | iV = rules.GetVector3Item(idx); | 579 | try |
580 | { | ||
581 | iV = rules.GetVector3Item(idx); | ||
582 | } | ||
583 | catch (InvalidCastException) | ||
584 | { | ||
585 | throw new InvalidCastException(string.Format("Error running rule WL_REFLECTION_WAVELET_SCALE: arg #{0} - parameter 1 must be vector", idx)); | ||
586 | } | ||
387 | wl.reflectionWaveletScale = iV; | 587 | wl.reflectionWaveletScale = iV; |
388 | break; | 588 | break; |
389 | case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE: | 589 | case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE: |
390 | idx++; | 590 | idx++; |
391 | wl.refractScaleAbove = (float)rules.GetLSLFloatItem(idx); | 591 | try |
592 | { | ||
593 | wl.refractScaleAbove = (float)rules.GetLSLFloatItem(idx); | ||
594 | } | ||
595 | catch (InvalidCastException) | ||
596 | { | ||
597 | throw new InvalidCastException(string.Format("Error running rule WL_REFRACT_SCALE_ABOVE: arg #{0} - parameter 1 must be float", idx)); | ||
598 | } | ||
392 | break; | 599 | break; |
393 | case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW: | 600 | case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW: |
394 | idx++; | 601 | idx++; |
395 | wl.refractScaleBelow = (float)rules.GetLSLFloatItem(idx); | 602 | try |
603 | { | ||
604 | wl.refractScaleBelow = (float)rules.GetLSLFloatItem(idx); | ||
605 | } | ||
606 | catch (InvalidCastException) | ||
607 | { | ||
608 | throw new InvalidCastException(string.Format("Error running rule WL_REFRACT_SCALE_BELOW: arg #{0} - parameter 1 must be float", idx)); | ||
609 | } | ||
396 | break; | 610 | break; |
397 | case (int)ScriptBaseClass.WL_SCENE_GAMMA: | 611 | case (int)ScriptBaseClass.WL_SCENE_GAMMA: |
398 | idx++; | 612 | idx++; |
399 | wl.sceneGamma = (float)rules.GetLSLFloatItem(idx); | 613 | try |
614 | { | ||
615 | wl.sceneGamma = (float)rules.GetLSLFloatItem(idx); | ||
616 | } | ||
617 | catch (InvalidCastException) | ||
618 | { | ||
619 | throw new InvalidCastException(string.Format("Error running rule WL_SCENE_GAMMA: arg #{0} - parameter 1 must be float", idx)); | ||
620 | } | ||
400 | break; | 621 | break; |
401 | case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS: | 622 | case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS: |
402 | idx++; | 623 | idx++; |
403 | wl.starBrightness = (float)rules.GetLSLFloatItem(idx); | 624 | try |
625 | { | ||
626 | wl.starBrightness = (float)rules.GetLSLFloatItem(idx); | ||
627 | } | ||
628 | catch (InvalidCastException) | ||
629 | { | ||
630 | throw new InvalidCastException(string.Format("Error running rule WL_STAR_BRIGHTNESS: arg #{0} - parameter 1 must be float", idx)); | ||
631 | } | ||
404 | break; | 632 | break; |
405 | case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS: | 633 | case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS: |
406 | idx++; | 634 | idx++; |
407 | wl.sunGlowFocus = (float)rules.GetLSLFloatItem(idx); | 635 | try |
636 | { | ||
637 | wl.sunGlowFocus = (float)rules.GetLSLFloatItem(idx); | ||
638 | } | ||
639 | catch (InvalidCastException) | ||
640 | { | ||
641 | throw new InvalidCastException(string.Format("Error running rule WL_SUN_GLOW_FOCUS: arg #{0} - parameter 1 must be float", idx)); | ||
642 | } | ||
408 | break; | 643 | break; |
409 | case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE: | 644 | case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE: |
410 | idx++; | 645 | idx++; |
411 | wl.sunGlowSize = (float)rules.GetLSLFloatItem(idx); | 646 | try |
647 | { | ||
648 | wl.sunGlowSize = (float)rules.GetLSLFloatItem(idx); | ||
649 | } | ||
650 | catch (InvalidCastException) | ||
651 | { | ||
652 | throw new InvalidCastException(string.Format("Error running rule WL_SUN_GLOW_SIZE: arg #{0} - parameter 1 must be float", idx)); | ||
653 | } | ||
412 | break; | 654 | break; |
413 | case (int)ScriptBaseClass.WL_SUN_MOON_COLOR: | 655 | case (int)ScriptBaseClass.WL_SUN_MOON_COLOR: |
414 | idx++; | 656 | idx++; |
415 | iQ = rules.GetQuaternionItem(idx); | 657 | iQ = rules.GetQuaternionItem(idx); |
416 | wl.sunMoonColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); | 658 | try |
659 | { | ||
660 | wl.sunMoonColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); | ||
661 | } | ||
662 | catch (InvalidCastException) | ||
663 | { | ||
664 | throw new InvalidCastException(string.Format("Error running rule WL_SUN_MOON_COLOR: arg #{0} - parameter 1 must be rotation", idx)); | ||
665 | } | ||
417 | break; | 666 | break; |
418 | case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER: | 667 | case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER: |
419 | idx++; | 668 | idx++; |
420 | wl.underwaterFogModifier = (float)rules.GetLSLFloatItem(idx); | 669 | try |
670 | { | ||
671 | wl.underwaterFogModifier = (float)rules.GetLSLFloatItem(idx); | ||
672 | } | ||
673 | catch (InvalidCastException) | ||
674 | { | ||
675 | throw new InvalidCastException(string.Format("Error running rule WL_UNDERWATER_FOG_MODIFIER: arg #{0} - parameter 1 must be float", idx)); | ||
676 | } | ||
421 | break; | 677 | break; |
422 | case (int)ScriptBaseClass.WL_WATER_COLOR: | 678 | case (int)ScriptBaseClass.WL_WATER_COLOR: |
423 | idx++; | 679 | idx++; |
424 | iV = rules.GetVector3Item(idx); | 680 | try |
681 | { | ||
682 | iV = rules.GetVector3Item(idx); | ||
683 | } | ||
684 | catch (InvalidCastException) | ||
685 | { | ||
686 | throw new InvalidCastException(string.Format("Error running rule WL_WATER_COLOR: arg #{0} - parameter 1 must be vector", idx)); | ||
687 | } | ||
425 | wl.waterColor = iV; | 688 | wl.waterColor = iV; |
426 | break; | 689 | break; |
427 | case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT: | 690 | case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT: |
428 | idx++; | 691 | idx++; |
429 | wl.waterFogDensityExponent = (float)rules.GetLSLFloatItem(idx); | 692 | try |
693 | { | ||
694 | wl.waterFogDensityExponent = (float)rules.GetLSLFloatItem(idx); | ||
695 | } | ||
696 | catch (InvalidCastException) | ||
697 | { | ||
698 | throw new InvalidCastException(string.Format("Error running rule WL_WATER_FOG_DENSITY_EXPONENT: arg #{0} - parameter 1 must be float", idx)); | ||
699 | } | ||
430 | break; | 700 | break; |
431 | } | 701 | } |
432 | idx++; | 702 | idx++; |
433 | } | 703 | } |
434 | return wl; | 704 | return wl; |
435 | } | 705 | } |
706 | |||
436 | /// <summary> | 707 | /// <summary> |
437 | /// Set the current Windlight scene | 708 | /// Set the current Windlight scene |
438 | /// </summary> | 709 | /// </summary> |
@@ -445,16 +716,33 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
445 | LSShoutError("LightShare functions are not enabled."); | 716 | LSShoutError("LightShare functions are not enabled."); |
446 | return 0; | 717 | return 0; |
447 | } | 718 | } |
448 | if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) | 719 | |
720 | if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID)) | ||
449 | { | 721 | { |
450 | LSShoutError("lsSetWindlightScene can only be used by estate managers or owners."); | 722 | ScenePresence sp = World.GetScenePresence(m_host.OwnerID); |
451 | return 0; | 723 | |
724 | if (sp == null || sp.GodLevel < 200) | ||
725 | { | ||
726 | LSShoutError("lsSetWindlightScene can only be used by estate managers or owners."); | ||
727 | return 0; | ||
728 | } | ||
452 | } | 729 | } |
730 | |||
453 | int success = 0; | 731 | int success = 0; |
454 | m_host.AddScriptLPS(1); | 732 | m_host.AddScriptLPS(1); |
733 | |||
455 | if (LightShareModule.EnableWindlight) | 734 | if (LightShareModule.EnableWindlight) |
456 | { | 735 | { |
457 | RegionLightShareData wl = getWindlightProfileFromRules(rules); | 736 | RegionLightShareData wl; |
737 | try | ||
738 | { | ||
739 | wl = getWindlightProfileFromRules(rules); | ||
740 | } | ||
741 | catch(InvalidCastException e) | ||
742 | { | ||
743 | LSShoutError(e.Message); | ||
744 | return 0; | ||
745 | } | ||
458 | wl.valid = true; | 746 | wl.valid = true; |
459 | m_host.ParentGroup.Scene.StoreWindlightProfile(wl); | 747 | m_host.ParentGroup.Scene.StoreWindlightProfile(wl); |
460 | success = 1; | 748 | success = 1; |
@@ -464,8 +752,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
464 | LSShoutError("Windlight module is disabled"); | 752 | LSShoutError("Windlight module is disabled"); |
465 | return 0; | 753 | return 0; |
466 | } | 754 | } |
755 | |||
467 | return success; | 756 | return success; |
468 | } | 757 | } |
758 | |||
469 | public void lsClearWindlightScene() | 759 | public void lsClearWindlightScene() |
470 | { | 760 | { |
471 | if (!m_LSFunctionsEnabled) | 761 | if (!m_LSFunctionsEnabled) |
@@ -473,17 +763,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
473 | LSShoutError("LightShare functions are not enabled."); | 763 | LSShoutError("LightShare functions are not enabled."); |
474 | return; | 764 | return; |
475 | } | 765 | } |
476 | if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) | 766 | |
767 | if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID)) | ||
477 | { | 768 | { |
478 | LSShoutError("lsSetWindlightScene can only be used by estate managers or owners."); | 769 | ScenePresence sp = World.GetScenePresence(m_host.OwnerID); |
479 | return; | 770 | |
771 | if (sp == null || sp.GodLevel < 200) | ||
772 | { | ||
773 | LSShoutError("lsSetWindlightScene can only be used by estate managers or owners."); | ||
774 | return; | ||
775 | } | ||
480 | } | 776 | } |
481 | 777 | ||
482 | m_host.ParentGroup.Scene.RegionInfo.WindlightSettings.valid = false; | 778 | m_host.ParentGroup.Scene.RegionInfo.WindlightSettings.valid = false; |
483 | if (m_host.ParentGroup.Scene.SimulationDataService != null) | 779 | if (m_host.ParentGroup.Scene.SimulationDataService != null) |
484 | m_host.ParentGroup.Scene.SimulationDataService.RemoveRegionWindlightSettings(m_host.ParentGroup.Scene.RegionInfo.RegionID); | 780 | m_host.ParentGroup.Scene.SimulationDataService.RemoveRegionWindlightSettings(m_host.ParentGroup.Scene.RegionInfo.RegionID); |
781 | |||
485 | m_host.ParentGroup.Scene.EventManager.TriggerOnSaveNewWindlightProfile(); | 782 | m_host.ParentGroup.Scene.EventManager.TriggerOnSaveNewWindlightProfile(); |
486 | } | 783 | } |
784 | |||
487 | /// <summary> | 785 | /// <summary> |
488 | /// Set the current Windlight scene to a target avatar | 786 | /// Set the current Windlight scene to a target avatar |
489 | /// </summary> | 787 | /// </summary> |
@@ -496,16 +794,33 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
496 | LSShoutError("LightShare functions are not enabled."); | 794 | LSShoutError("LightShare functions are not enabled."); |
497 | return 0; | 795 | return 0; |
498 | } | 796 | } |
499 | if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) | 797 | |
798 | if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID)) | ||
500 | { | 799 | { |
501 | LSShoutError("lsSetWindlightSceneTargeted can only be used by estate managers or owners."); | 800 | ScenePresence sp = World.GetScenePresence(m_host.OwnerID); |
502 | return 0; | 801 | |
802 | if (sp == null || sp.GodLevel < 200) | ||
803 | { | ||
804 | LSShoutError("lsSetWindlightSceneTargeted can only be used by estate managers or owners."); | ||
805 | return 0; | ||
806 | } | ||
503 | } | 807 | } |
808 | |||
504 | int success = 0; | 809 | int success = 0; |
505 | m_host.AddScriptLPS(1); | 810 | m_host.AddScriptLPS(1); |
811 | |||
506 | if (LightShareModule.EnableWindlight) | 812 | if (LightShareModule.EnableWindlight) |
507 | { | 813 | { |
508 | RegionLightShareData wl = getWindlightProfileFromRules(rules); | 814 | RegionLightShareData wl; |
815 | try | ||
816 | { | ||
817 | wl = getWindlightProfileFromRules(rules); | ||
818 | } | ||
819 | catch(InvalidCastException e) | ||
820 | { | ||
821 | LSShoutError(e.Message); | ||
822 | return 0; | ||
823 | } | ||
509 | World.EventManager.TriggerOnSendNewWindlightProfileTargeted(wl, new UUID(target.m_string)); | 824 | World.EventManager.TriggerOnSendNewWindlightProfileTargeted(wl, new UUID(target.m_string)); |
510 | success = 1; | 825 | success = 1; |
511 | } | 826 | } |
@@ -514,8 +829,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
514 | LSShoutError("Windlight module is disabled"); | 829 | LSShoutError("Windlight module is disabled"); |
515 | return 0; | 830 | return 0; |
516 | } | 831 | } |
832 | |||
517 | return success; | 833 | return success; |
518 | } | 834 | } |
519 | |||
520 | } | 835 | } |
521 | } | 836 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index 8f34833..1458c95 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs | |||
@@ -30,6 +30,8 @@ using System.Reflection; | |||
30 | using System.Collections; | 30 | using System.Collections; |
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using System.Runtime.Remoting.Lifetime; | 32 | using System.Runtime.Remoting.Lifetime; |
33 | using System.Threading; | ||
34 | using log4net; | ||
33 | using OpenMetaverse; | 35 | using OpenMetaverse; |
34 | using Nini.Config; | 36 | using Nini.Config; |
35 | using OpenSim; | 37 | using OpenSim; |
@@ -55,15 +57,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
55 | [Serializable] | 57 | [Serializable] |
56 | public class MOD_Api : MarshalByRefObject, IMOD_Api, IScriptApi | 58 | public class MOD_Api : MarshalByRefObject, IMOD_Api, IScriptApi |
57 | { | 59 | { |
60 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
61 | |||
58 | internal IScriptEngine m_ScriptEngine; | 62 | internal IScriptEngine m_ScriptEngine; |
59 | internal SceneObjectPart m_host; | 63 | internal SceneObjectPart m_host; |
60 | internal TaskInventoryItem m_item; | 64 | internal TaskInventoryItem m_item; |
61 | internal bool m_MODFunctionsEnabled = false; | 65 | internal bool m_MODFunctionsEnabled = false; |
62 | internal IScriptModuleComms m_comms = null; | 66 | internal IScriptModuleComms m_comms = null; |
63 | 67 | ||
64 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) | 68 | public void Initialize( |
69 | IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item) | ||
65 | { | 70 | { |
66 | m_ScriptEngine = ScriptEngine; | 71 | m_ScriptEngine = scriptEngine; |
67 | m_host = host; | 72 | m_host = host; |
68 | m_item = item; | 73 | m_item = item; |
69 | 74 | ||
@@ -107,8 +112,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
107 | if (message.Length > 1023) | 112 | if (message.Length > 1023) |
108 | message = message.Substring(0, 1023); | 113 | message = message.Substring(0, 1023); |
109 | 114 | ||
110 | World.SimChat(Utils.StringToBytes(message), | 115 | World.SimChat( |
111 | ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true); | 116 | Utils.StringToBytes(message), |
117 | ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, | ||
118 | m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false); | ||
112 | 119 | ||
113 | IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); | 120 | IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); |
114 | wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); | 121 | wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); |
@@ -122,6 +129,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
122 | /// <returns>string result of the invocation</returns> | 129 | /// <returns>string result of the invocation</returns> |
123 | public void modInvokeN(string fname, params object[] parms) | 130 | public void modInvokeN(string fname, params object[] parms) |
124 | { | 131 | { |
132 | // m_log.DebugFormat( | ||
133 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | ||
134 | // fname, | ||
135 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | ||
136 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | ||
137 | |||
125 | Type returntype = m_comms.LookupReturnType(fname); | 138 | Type returntype = m_comms.LookupReturnType(fname); |
126 | if (returntype != typeof(string)) | 139 | if (returntype != typeof(string)) |
127 | MODError(String.Format("return type mismatch for {0}",fname)); | 140 | MODError(String.Format("return type mismatch for {0}",fname)); |
@@ -131,6 +144,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
131 | 144 | ||
132 | public LSL_String modInvokeS(string fname, params object[] parms) | 145 | public LSL_String modInvokeS(string fname, params object[] parms) |
133 | { | 146 | { |
147 | // m_log.DebugFormat( | ||
148 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | ||
149 | // fname, | ||
150 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | ||
151 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | ||
152 | |||
134 | Type returntype = m_comms.LookupReturnType(fname); | 153 | Type returntype = m_comms.LookupReturnType(fname); |
135 | if (returntype != typeof(string)) | 154 | if (returntype != typeof(string)) |
136 | MODError(String.Format("return type mismatch for {0}",fname)); | 155 | MODError(String.Format("return type mismatch for {0}",fname)); |
@@ -141,6 +160,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
141 | 160 | ||
142 | public LSL_Integer modInvokeI(string fname, params object[] parms) | 161 | public LSL_Integer modInvokeI(string fname, params object[] parms) |
143 | { | 162 | { |
163 | // m_log.DebugFormat( | ||
164 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | ||
165 | // fname, | ||
166 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | ||
167 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | ||
168 | |||
144 | Type returntype = m_comms.LookupReturnType(fname); | 169 | Type returntype = m_comms.LookupReturnType(fname); |
145 | if (returntype != typeof(int)) | 170 | if (returntype != typeof(int)) |
146 | MODError(String.Format("return type mismatch for {0}",fname)); | 171 | MODError(String.Format("return type mismatch for {0}",fname)); |
@@ -151,6 +176,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
151 | 176 | ||
152 | public LSL_Float modInvokeF(string fname, params object[] parms) | 177 | public LSL_Float modInvokeF(string fname, params object[] parms) |
153 | { | 178 | { |
179 | // m_log.DebugFormat( | ||
180 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | ||
181 | // fname, | ||
182 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | ||
183 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | ||
184 | |||
154 | Type returntype = m_comms.LookupReturnType(fname); | 185 | Type returntype = m_comms.LookupReturnType(fname); |
155 | if (returntype != typeof(float)) | 186 | if (returntype != typeof(float)) |
156 | MODError(String.Format("return type mismatch for {0}",fname)); | 187 | MODError(String.Format("return type mismatch for {0}",fname)); |
@@ -161,6 +192,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
161 | 192 | ||
162 | public LSL_Key modInvokeK(string fname, params object[] parms) | 193 | public LSL_Key modInvokeK(string fname, params object[] parms) |
163 | { | 194 | { |
195 | // m_log.DebugFormat( | ||
196 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | ||
197 | // fname, | ||
198 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | ||
199 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | ||
200 | |||
164 | Type returntype = m_comms.LookupReturnType(fname); | 201 | Type returntype = m_comms.LookupReturnType(fname); |
165 | if (returntype != typeof(UUID)) | 202 | if (returntype != typeof(UUID)) |
166 | MODError(String.Format("return type mismatch for {0}",fname)); | 203 | MODError(String.Format("return type mismatch for {0}",fname)); |
@@ -171,6 +208,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
171 | 208 | ||
172 | public LSL_Vector modInvokeV(string fname, params object[] parms) | 209 | public LSL_Vector modInvokeV(string fname, params object[] parms) |
173 | { | 210 | { |
211 | // m_log.DebugFormat( | ||
212 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | ||
213 | // fname, | ||
214 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | ||
215 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | ||
216 | |||
174 | Type returntype = m_comms.LookupReturnType(fname); | 217 | Type returntype = m_comms.LookupReturnType(fname); |
175 | if (returntype != typeof(OpenMetaverse.Vector3)) | 218 | if (returntype != typeof(OpenMetaverse.Vector3)) |
176 | MODError(String.Format("return type mismatch for {0}",fname)); | 219 | MODError(String.Format("return type mismatch for {0}",fname)); |
@@ -181,6 +224,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
181 | 224 | ||
182 | public LSL_Rotation modInvokeR(string fname, params object[] parms) | 225 | public LSL_Rotation modInvokeR(string fname, params object[] parms) |
183 | { | 226 | { |
227 | // m_log.DebugFormat( | ||
228 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | ||
229 | // fname, | ||
230 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | ||
231 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | ||
232 | |||
184 | Type returntype = m_comms.LookupReturnType(fname); | 233 | Type returntype = m_comms.LookupReturnType(fname); |
185 | if (returntype != typeof(OpenMetaverse.Quaternion)) | 234 | if (returntype != typeof(OpenMetaverse.Quaternion)) |
186 | MODError(String.Format("return type mismatch for {0}",fname)); | 235 | MODError(String.Format("return type mismatch for {0}",fname)); |
@@ -191,6 +240,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
191 | 240 | ||
192 | public LSL_List modInvokeL(string fname, params object[] parms) | 241 | public LSL_List modInvokeL(string fname, params object[] parms) |
193 | { | 242 | { |
243 | // m_log.DebugFormat( | ||
244 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | ||
245 | // fname, | ||
246 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | ||
247 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | ||
248 | |||
194 | Type returntype = m_comms.LookupReturnType(fname); | 249 | Type returntype = m_comms.LookupReturnType(fname); |
195 | if (returntype != typeof(object[])) | 250 | if (returntype != typeof(object[])) |
196 | MODError(String.Format("return type mismatch for {0}",fname)); | 251 | MODError(String.Format("return type mismatch for {0}",fname)); |
@@ -211,6 +266,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
211 | { | 266 | { |
212 | llist[i] = new LSL_Float((float)result[i]); | 267 | llist[i] = new LSL_Float((float)result[i]); |
213 | } | 268 | } |
269 | else if (result[i] is double) | ||
270 | { | ||
271 | llist[i] = new LSL_Float((double)result[i]); | ||
272 | } | ||
214 | else if (result[i] is UUID) | 273 | else if (result[i] is UUID) |
215 | { | 274 | { |
216 | llist[i] = new LSL_Key(result[i].ToString()); | 275 | llist[i] = new LSL_Key(result[i].ToString()); |
@@ -248,13 +307,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
248 | return ""; | 307 | return ""; |
249 | } | 308 | } |
250 | 309 | ||
310 | // m_log.DebugFormat( | ||
311 | // "[MOD API]: Invoking dynamic function {0}, args '{1}' with {2} return type", | ||
312 | // fname, | ||
313 | // string.Join(",", Array.ConvertAll<object, string>(parms, o => o.ToString())), | ||
314 | // ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); | ||
315 | |||
251 | Type[] signature = m_comms.LookupTypeSignature(fname); | 316 | Type[] signature = m_comms.LookupTypeSignature(fname); |
252 | if (signature.Length != parms.Length) | 317 | if (signature.Length != parms.Length) |
253 | MODError(String.Format("wrong number of parameters to function {0}",fname)); | 318 | MODError(String.Format("wrong number of parameters to function {0}",fname)); |
254 | 319 | ||
255 | object[] convertedParms = new object[parms.Length]; | 320 | object[] convertedParms = new object[parms.Length]; |
256 | for (int i = 0; i < parms.Length; i++) | 321 | for (int i = 0; i < parms.Length; i++) |
257 | convertedParms[i] = ConvertFromLSL(parms[i],signature[i], fname); | 322 | convertedParms[i] = ConvertFromLSL(parms[i], signature[i], fname); |
258 | 323 | ||
259 | // now call the function, the contract with the function is that it will always return | 324 | // now call the function, the contract with the function is that it will always return |
260 | // non-null but don't trust it completely | 325 | // non-null but don't trust it completely |
@@ -351,7 +416,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
351 | { | 416 | { |
352 | if (type == typeof(object[])) | 417 | if (type == typeof(object[])) |
353 | { | 418 | { |
354 | object[] plist = (lslparm as LSL_List).Data; | 419 | object[] plist = ((LSL_List)lslparm).Data; |
355 | object[] result = new object[plist.Length]; | 420 | object[] result = new object[plist.Length]; |
356 | for (int i = 0; i < plist.Length; i++) | 421 | for (int i = 0; i < plist.Length; i++) |
357 | { | 422 | { |
@@ -379,7 +444,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
379 | } | 444 | } |
380 | } | 445 | } |
381 | 446 | ||
382 | MODError(String.Format("{1}: parameter type mismatch; expecting {0}",type.Name, fname)); | 447 | MODError(String.Format("{0}: parameter type mismatch; expecting {1}, type(parm)={2}", fname, type.Name, lslparm.GetType())); |
383 | return null; | 448 | return null; |
384 | } | 449 | } |
385 | 450 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index dcc85c4..e799714 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |||
@@ -62,6 +62,8 @@ using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; | |||
62 | using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; | 62 | using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; |
63 | using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; | 63 | using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; |
64 | using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; | 64 | using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; |
65 | using PermissionMask = OpenSim.Framework.PermissionMask; | ||
66 | using OpenSim.Services.Connectors.Hypergrid; | ||
65 | 67 | ||
66 | namespace OpenSim.Region.ScriptEngine.Shared.Api | 68 | namespace OpenSim.Region.ScriptEngine.Shared.Api |
67 | { | 69 | { |
@@ -142,16 +144,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
142 | 144 | ||
143 | protected IUrlModule m_UrlModule = null; | 145 | protected IUrlModule m_UrlModule = null; |
144 | 146 | ||
145 | public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) | 147 | public void Initialize( |
148 | IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item) | ||
146 | { | 149 | { |
147 | m_ScriptEngine = ScriptEngine; | 150 | m_ScriptEngine = scriptEngine; |
148 | m_host = host; | 151 | m_host = host; |
149 | m_item = item; | 152 | m_item = item; |
150 | 153 | ||
151 | m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); | 154 | m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); |
152 | 155 | ||
153 | if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false)) | 156 | if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false)) |
157 | { | ||
154 | m_OSFunctionsEnabled = true; | 158 | m_OSFunctionsEnabled = true; |
159 | // m_log.Warn("[OSSL] OSSL FUNCTIONS ENABLED"); | ||
160 | } | ||
155 | 161 | ||
156 | m_ScriptDelayFactor = | 162 | m_ScriptDelayFactor = |
157 | m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); | 163 | m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); |
@@ -245,11 +251,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
245 | wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); | 251 | wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); |
246 | } | 252 | } |
247 | 253 | ||
254 | // Returns of the function is allowed. Throws a script exception if not allowed. | ||
248 | public void CheckThreatLevel(ThreatLevel level, string function) | 255 | public void CheckThreatLevel(ThreatLevel level, string function) |
249 | { | 256 | { |
250 | if (!m_OSFunctionsEnabled) | 257 | if (!m_OSFunctionsEnabled) |
251 | OSSLError(String.Format("{0} permission denied. All OS functions are disabled.", function)); // throws | 258 | OSSLError(String.Format("{0} permission denied. All OS functions are disabled.", function)); // throws |
252 | 259 | ||
260 | string reasonWhyNot = CheckThreatLevelTest(level, function); | ||
261 | if (!String.IsNullOrEmpty(reasonWhyNot)) | ||
262 | { | ||
263 | OSSLError(reasonWhyNot); | ||
264 | } | ||
265 | } | ||
266 | |||
267 | // Check to see if function is allowed. Returns an empty string if function permitted | ||
268 | // or a string explaining why this function can't be used. | ||
269 | private string CheckThreatLevelTest(ThreatLevel level, string function) | ||
270 | { | ||
253 | if (!m_FunctionPerms.ContainsKey(function)) | 271 | if (!m_FunctionPerms.ContainsKey(function)) |
254 | { | 272 | { |
255 | FunctionPerms perms = new FunctionPerms(); | 273 | FunctionPerms perms = new FunctionPerms(); |
@@ -329,10 +347,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
329 | { | 347 | { |
330 | // Allow / disallow by threat level | 348 | // Allow / disallow by threat level |
331 | if (level > m_MaxThreatLevel) | 349 | if (level > m_MaxThreatLevel) |
332 | OSSLError( | 350 | return |
333 | String.Format( | 351 | String.Format( |
334 | "{0} permission denied. Allowed threat level is {1} but function threat level is {2}.", | 352 | "{0} permission denied. Allowed threat level is {1} but function threat level is {2}.", |
335 | function, m_MaxThreatLevel, level)); | 353 | function, m_MaxThreatLevel, level); |
336 | } | 354 | } |
337 | else | 355 | else |
338 | { | 356 | { |
@@ -342,7 +360,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
342 | if (m_FunctionPerms[function].AllowedOwners.Contains(m_host.OwnerID)) | 360 | if (m_FunctionPerms[function].AllowedOwners.Contains(m_host.OwnerID)) |
343 | { | 361 | { |
344 | // prim owner is in the list of allowed owners | 362 | // prim owner is in the list of allowed owners |
345 | return; | 363 | return String.Empty; |
346 | } | 364 | } |
347 | 365 | ||
348 | UUID ownerID = m_item.OwnerID; | 366 | UUID ownerID = m_item.OwnerID; |
@@ -350,22 +368,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
350 | //OSSL only may be used if object is in the same group as the parcel | 368 | //OSSL only may be used if object is in the same group as the parcel |
351 | if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_GROUP_MEMBER")) | 369 | if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_GROUP_MEMBER")) |
352 | { | 370 | { |
353 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); | 371 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); |
354 | 372 | ||
355 | if (land.LandData.GroupID == m_item.GroupID && land.LandData.GroupID != UUID.Zero) | 373 | if (land.LandData.GroupID == m_item.GroupID && land.LandData.GroupID != UUID.Zero) |
356 | { | 374 | { |
357 | return; | 375 | return String.Empty; |
358 | } | 376 | } |
359 | } | 377 | } |
360 | 378 | ||
361 | //Only Parcelowners may use the function | 379 | //Only Parcelowners may use the function |
362 | if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_OWNER")) | 380 | if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_OWNER")) |
363 | { | 381 | { |
364 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); | 382 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); |
365 | 383 | ||
366 | if (land.LandData.OwnerID == ownerID) | 384 | if (land.LandData.OwnerID == ownerID) |
367 | { | 385 | { |
368 | return; | 386 | return String.Empty; |
369 | } | 387 | } |
370 | } | 388 | } |
371 | 389 | ||
@@ -375,7 +393,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
375 | //Only Estate Managers may use the function | 393 | //Only Estate Managers may use the function |
376 | if (World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID) | 394 | if (World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID) |
377 | { | 395 | { |
378 | return; | 396 | return String.Empty; |
379 | } | 397 | } |
380 | } | 398 | } |
381 | 399 | ||
@@ -384,25 +402,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
384 | { | 402 | { |
385 | if (World.RegionInfo.EstateSettings.EstateOwner == ownerID) | 403 | if (World.RegionInfo.EstateSettings.EstateOwner == ownerID) |
386 | { | 404 | { |
387 | return; | 405 | return String.Empty; |
388 | } | 406 | } |
389 | } | 407 | } |
390 | 408 | ||
391 | if (!m_FunctionPerms[function].AllowedCreators.Contains(m_item.CreatorID)) | 409 | if (!m_FunctionPerms[function].AllowedCreators.Contains(m_item.CreatorID)) |
392 | OSSLError( | 410 | return( |
393 | String.Format("{0} permission denied. Script creator is not in the list of users allowed to execute this function and prim owner also has no permission.", | 411 | String.Format("{0} permission denied. Script creator is not in the list of users allowed to execute this function and prim owner also has no permission.", |
394 | function)); | 412 | function)); |
395 | 413 | ||
396 | if (m_item.CreatorID != ownerID) | 414 | if (m_item.CreatorID != ownerID) |
397 | { | 415 | { |
398 | if ((m_item.CurrentPermissions & (uint)PermissionMask.Modify) != 0) | 416 | if ((m_item.CurrentPermissions & (uint)PermissionMask.Modify) != 0) |
399 | OSSLError( | 417 | return String.Format("{0} permission denied. Script permissions error.", function); |
400 | String.Format("{0} permission denied. Script permissions error.", | ||
401 | function)); | ||
402 | 418 | ||
403 | } | 419 | } |
404 | } | 420 | } |
405 | } | 421 | } |
422 | return String.Empty; | ||
406 | } | 423 | } |
407 | 424 | ||
408 | internal void OSSLDeprecated(string function, string replacement) | 425 | internal void OSSLDeprecated(string function, string replacement) |
@@ -437,7 +454,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
437 | { | 454 | { |
438 | m_host.AddScriptLPS(1); | 455 | m_host.AddScriptLPS(1); |
439 | 456 | ||
440 | if (x > ((int)Constants.RegionSize - 1) || x < 0 || y > ((int)Constants.RegionSize - 1) || y < 0) | 457 | if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0) |
441 | OSSLError("osSetTerrainHeight: Coordinate out of bounds"); | 458 | OSSLError("osSetTerrainHeight: Coordinate out of bounds"); |
442 | 459 | ||
443 | if (World.Permissions.CanTerraformLand(m_host.OwnerID, new Vector3(x, y, 0))) | 460 | if (World.Permissions.CanTerraformLand(m_host.OwnerID, new Vector3(x, y, 0))) |
@@ -467,7 +484,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
467 | private LSL_Float GetTerrainHeight(int x, int y) | 484 | private LSL_Float GetTerrainHeight(int x, int y) |
468 | { | 485 | { |
469 | m_host.AddScriptLPS(1); | 486 | m_host.AddScriptLPS(1); |
470 | if (x > ((int)Constants.RegionSize - 1) || x < 0 || y > ((int)Constants.RegionSize - 1) || y < 0) | 487 | if (x > (World.RegionInfo.RegionSizeX - 1) || x < 0 || y > (World.RegionInfo.RegionSizeY - 1) || y < 0) |
471 | OSSLError("osGetTerrainHeight: Coordinate out of bounds"); | 488 | OSSLError("osGetTerrainHeight: Coordinate out of bounds"); |
472 | 489 | ||
473 | return World.Heightmap[x, y]; | 490 | return World.Heightmap[x, y]; |
@@ -777,9 +794,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
777 | 794 | ||
778 | // We will launch the teleport on a new thread so that when the script threads are terminated | 795 | // We will launch the teleport on a new thread so that when the script threads are terminated |
779 | // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting. | 796 | // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting. |
780 | Util.FireAndForget(o => World.RequestTeleportLocation( | 797 | Util.FireAndForget( |
781 | presence.ControllingClient, regionName, position, | 798 | o => World.RequestTeleportLocation( |
782 | lookat, (uint)TPFlags.ViaLocation)); | 799 | presence.ControllingClient, regionName, position, |
800 | lookat, (uint)TPFlags.ViaLocation), | ||
801 | null, "OSSL_Api.TeleportAgentByRegionCoords"); | ||
783 | 802 | ||
784 | ScriptSleep(5000); | 803 | ScriptSleep(5000); |
785 | 804 | ||
@@ -801,7 +820,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
801 | private void TeleportAgent(string agent, int regionX, int regionY, | 820 | private void TeleportAgent(string agent, int regionX, int regionY, |
802 | LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions) | 821 | LSL_Types.Vector3 position, LSL_Types.Vector3 lookat, bool relaxRestrictions) |
803 | { | 822 | { |
804 | ulong regionHandle = Util.UIntsToLong(((uint)regionX * (uint)Constants.RegionSize), ((uint)regionY * (uint)Constants.RegionSize)); | 823 | // ulong regionHandle = Util.UIntsToLong(((uint)regionX * (uint)Constants.RegionSize), ((uint)regionY * (uint)Constants.RegionSize)); |
824 | ulong regionHandle = Util.RegionLocToHandle((uint)regionX, (uint)regionY); | ||
805 | 825 | ||
806 | m_host.AddScriptLPS(1); | 826 | m_host.AddScriptLPS(1); |
807 | UUID agentId = new UUID(); | 827 | UUID agentId = new UUID(); |
@@ -822,9 +842,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
822 | 842 | ||
823 | // We will launch the teleport on a new thread so that when the script threads are terminated | 843 | // We will launch the teleport on a new thread so that when the script threads are terminated |
824 | // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting. | 844 | // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting. |
825 | Util.FireAndForget(o => World.RequestTeleportLocation( | 845 | Util.FireAndForget( |
826 | presence.ControllingClient, regionHandle, | 846 | o => World.RequestTeleportLocation( |
827 | position, lookat, (uint)TPFlags.ViaLocation)); | 847 | presence.ControllingClient, regionHandle, |
848 | position, lookat, (uint)TPFlags.ViaLocation), | ||
849 | null, "OSSL_Api.TeleportAgentByRegionName"); | ||
828 | 850 | ||
829 | ScriptSleep(5000); | 851 | ScriptSleep(5000); |
830 | 852 | ||
@@ -859,6 +881,59 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
859 | TeleportAgent(m_host.OwnerID.ToString(), regionX, regionY, position, lookat, true); | 881 | TeleportAgent(m_host.OwnerID.ToString(), regionX, regionY, position, lookat, true); |
860 | } | 882 | } |
861 | 883 | ||
884 | ///<summary> | ||
885 | /// Allows a script IN the target prim to force an avatar to sit on it using normal methods | ||
886 | /// as if called by the client. | ||
887 | /// Silent fail if agent (or target if overloaded) not found. | ||
888 | /// Does work if passed key (or keys if overloaded). | ||
889 | /// </summary> | ||
890 | /// <param name="avatar"></param> | ||
891 | public void osForceOtherSit(string avatar) | ||
892 | { | ||
893 | CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit"); | ||
894 | |||
895 | m_host.AddScriptLPS(1); | ||
896 | |||
897 | ForceSit(avatar, m_host.UUID); | ||
898 | } | ||
899 | |||
900 | /// <summary> | ||
901 | /// Overload method of osForceOtherSit(string avatar) to allow a script NOT in the target prim to force | ||
902 | /// an avatar to sit on the target prim using normal methods as if called by the client. | ||
903 | /// </summary> | ||
904 | /// <param name="avatar"></param> | ||
905 | /// <param name="target"></param> | ||
906 | public void osForceOtherSit(string avatar, string target) | ||
907 | { | ||
908 | CheckThreatLevel(ThreatLevel.VeryHigh, "osForceOtherSit"); | ||
909 | |||
910 | m_host.AddScriptLPS(1); | ||
911 | |||
912 | UUID targetID = new UUID(target); | ||
913 | |||
914 | ForceSit(avatar, targetID); | ||
915 | } | ||
916 | |||
917 | public void ForceSit(string avatar, UUID targetID) | ||
918 | { | ||
919 | UUID agentID; | ||
920 | |||
921 | if (!UUID.TryParse(avatar, out agentID)) | ||
922 | return; | ||
923 | |||
924 | ScenePresence presence = World.GetScenePresence(agentID); | ||
925 | |||
926 | SceneObjectPart part = World.GetSceneObjectPart(targetID); | ||
927 | |||
928 | if (presence != null && | ||
929 | part != null && | ||
930 | part.SitTargetAvatar == UUID.Zero) | ||
931 | presence.HandleAgentRequestSit(presence.ControllingClient, | ||
932 | agentID, | ||
933 | targetID, | ||
934 | part.SitTargetPosition); | ||
935 | } | ||
936 | |||
862 | // Functions that get information from the agent itself. | 937 | // Functions that get information from the agent itself. |
863 | // | 938 | // |
864 | // osGetAgentIP - this is used to determine the IP address of | 939 | // osGetAgentIP - this is used to determine the IP address of |
@@ -1205,12 +1280,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1205 | sunHour += 24.0; | 1280 | sunHour += 24.0; |
1206 | 1281 | ||
1207 | World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun; | 1282 | World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun; |
1208 | World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30 | 1283 | World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30 |
1209 | World.RegionInfo.RegionSettings.FixedSun = sunFixed; | 1284 | World.RegionInfo.RegionSettings.FixedSun = sunFixed; |
1210 | World.RegionInfo.RegionSettings.Save(); | 1285 | World.RegionInfo.RegionSettings.Save(); |
1211 | 1286 | ||
1212 | World.EventManager.TriggerEstateToolsSunUpdate( | 1287 | World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle); |
1213 | World.RegionInfo.RegionHandle, sunFixed, useEstateSun, (float)sunHour); | ||
1214 | } | 1288 | } |
1215 | 1289 | ||
1216 | /// <summary> | 1290 | /// <summary> |
@@ -1233,10 +1307,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1233 | World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed; | 1307 | World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed; |
1234 | World.RegionInfo.EstateSettings.SunPosition = sunHour; | 1308 | World.RegionInfo.EstateSettings.SunPosition = sunHour; |
1235 | World.RegionInfo.EstateSettings.FixedSun = sunFixed; | 1309 | World.RegionInfo.EstateSettings.FixedSun = sunFixed; |
1236 | World.RegionInfo.EstateSettings.Save(); | 1310 | World.EstateDataService.StoreEstateSettings(World.RegionInfo.EstateSettings); |
1237 | 1311 | ||
1238 | World.EventManager.TriggerEstateToolsSunUpdate( | 1312 | World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle); |
1239 | World.RegionInfo.RegionHandle, sunFixed, World.RegionInfo.RegionSettings.UseEstateSun, (float)sunHour); | ||
1240 | } | 1313 | } |
1241 | 1314 | ||
1242 | /// <summary> | 1315 | /// <summary> |
@@ -1492,8 +1565,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1492 | 1565 | ||
1493 | m_host.AddScriptLPS(1); | 1566 | m_host.AddScriptLPS(1); |
1494 | 1567 | ||
1495 | ILandObject land | 1568 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); |
1496 | = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); | ||
1497 | 1569 | ||
1498 | if (land.LandData.OwnerID != m_host.OwnerID) | 1570 | if (land.LandData.OwnerID != m_host.OwnerID) |
1499 | return; | 1571 | return; |
@@ -1509,8 +1581,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1509 | 1581 | ||
1510 | m_host.AddScriptLPS(1); | 1582 | m_host.AddScriptLPS(1); |
1511 | 1583 | ||
1512 | ILandObject land | 1584 | ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); |
1513 | = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); | ||
1514 | 1585 | ||
1515 | if (land.LandData.OwnerID != m_host.OwnerID) | 1586 | if (land.LandData.OwnerID != m_host.OwnerID) |
1516 | { | 1587 | { |
@@ -1560,6 +1631,47 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1560 | } | 1631 | } |
1561 | } | 1632 | } |
1562 | 1633 | ||
1634 | public LSL_Integer osCheckODE() | ||
1635 | { | ||
1636 | m_host.AddScriptLPS(1); | ||
1637 | LSL_Integer ret = 0; // false | ||
1638 | if (m_ScriptEngine.World.PhysicsScene != null) | ||
1639 | { | ||
1640 | string physEngine = m_ScriptEngine.World.PhysicsScene.EngineType; | ||
1641 | if (physEngine == "OpenDynamicsEngine") | ||
1642 | { | ||
1643 | ret = 1; // true | ||
1644 | } | ||
1645 | } | ||
1646 | return ret; | ||
1647 | } | ||
1648 | |||
1649 | public string osGetPhysicsEngineType() | ||
1650 | { | ||
1651 | // High because it can be used to target attacks to known weaknesses | ||
1652 | // This would allow a new class of griefer scripts that don't even | ||
1653 | // require their user to know what they are doing (see script | ||
1654 | // kiddie) | ||
1655 | // Because it would be nice if scripts didn't blow up if the information | ||
1656 | // about the physics engine, this function returns an empty string if | ||
1657 | // the user does not have permission to see it. This as opposed to | ||
1658 | // throwing an exception. | ||
1659 | m_host.AddScriptLPS(1); | ||
1660 | string ret = String.Empty; | ||
1661 | if (String.IsNullOrEmpty(CheckThreatLevelTest(ThreatLevel.High, "osGetPhysicsEngineType"))) | ||
1662 | { | ||
1663 | if (m_ScriptEngine.World.PhysicsScene != null) | ||
1664 | { | ||
1665 | ret = m_ScriptEngine.World.PhysicsScene.EngineType; | ||
1666 | // An old physics engine might have an uninitialized engine type | ||
1667 | if (ret == null) | ||
1668 | ret = "unknown"; | ||
1669 | } | ||
1670 | } | ||
1671 | |||
1672 | return ret; | ||
1673 | } | ||
1674 | |||
1563 | public string osGetSimulatorVersion() | 1675 | public string osGetSimulatorVersion() |
1564 | { | 1676 | { |
1565 | // High because it can be used to target attacks to known weaknesses | 1677 | // High because it can be used to target attacks to known weaknesses |
@@ -1732,13 +1844,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1732 | // Create new asset | 1844 | // Create new asset |
1733 | AssetBase asset = new AssetBase(UUID.Random(), name, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString()); | 1845 | AssetBase asset = new AssetBase(UUID.Random(), name, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString()); |
1734 | asset.Description = description; | 1846 | asset.Description = description; |
1847 | byte[] a; | ||
1848 | byte[] b; | ||
1849 | byte[] c; | ||
1850 | |||
1851 | b = Util.UTF8.GetBytes(data); | ||
1735 | 1852 | ||
1736 | int textLength = data.Length; | 1853 | a = Util.UTF8.GetBytes( |
1737 | data | 1854 | "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " + b.Length.ToString() + "\n"); |
1738 | = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " | ||
1739 | + textLength.ToString() + "\n" + data + "}\n"; | ||
1740 | 1855 | ||
1741 | asset.Data = Util.UTF8.GetBytes(data); | 1856 | c = Util.UTF8.GetBytes("}"); |
1857 | |||
1858 | byte[] d = new byte[a.Length + b.Length + c.Length]; | ||
1859 | Buffer.BlockCopy(a, 0, d, 0, a.Length); | ||
1860 | Buffer.BlockCopy(b, 0, d, a.Length, b.Length); | ||
1861 | Buffer.BlockCopy(c, 0, d, a.Length + b.Length, c.Length); | ||
1862 | |||
1863 | asset.Data = d; | ||
1742 | World.AssetService.Store(asset); | 1864 | World.AssetService.Store(asset); |
1743 | 1865 | ||
1744 | // Create Task Entry | 1866 | // Create Task Entry |
@@ -1753,8 +1875,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1753 | taskItem.InvType = (int)InventoryType.Notecard; | 1875 | taskItem.InvType = (int)InventoryType.Notecard; |
1754 | taskItem.OwnerID = m_host.OwnerID; | 1876 | taskItem.OwnerID = m_host.OwnerID; |
1755 | taskItem.CreatorID = m_host.OwnerID; | 1877 | taskItem.CreatorID = m_host.OwnerID; |
1756 | taskItem.BasePermissions = (uint)PermissionMask.All; | 1878 | taskItem.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; |
1757 | taskItem.CurrentPermissions = (uint)PermissionMask.All; | 1879 | taskItem.CurrentPermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export; |
1758 | taskItem.EveryonePermissions = 0; | 1880 | taskItem.EveryonePermissions = 0; |
1759 | taskItem.NextPermissions = (uint)PermissionMask.All; | 1881 | taskItem.NextPermissions = (uint)PermissionMask.All; |
1760 | taskItem.GroupID = m_host.GroupID; | 1882 | taskItem.GroupID = m_host.GroupID; |
@@ -1833,8 +1955,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1833 | if (a == null) | 1955 | if (a == null) |
1834 | return UUID.Zero; | 1956 | return UUID.Zero; |
1835 | 1957 | ||
1836 | string data = Encoding.UTF8.GetString(a.Data); | 1958 | NotecardCache.Cache(assetID, a.Data); |
1837 | NotecardCache.Cache(assetID, data); | ||
1838 | }; | 1959 | }; |
1839 | 1960 | ||
1840 | return assetID; | 1961 | return assetID; |
@@ -1932,15 +2053,51 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1932 | CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key"); | 2053 | CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key"); |
1933 | m_host.AddScriptLPS(1); | 2054 | m_host.AddScriptLPS(1); |
1934 | 2055 | ||
1935 | UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, firstname, lastname); | 2056 | IUserManagement userManager = World.RequestModuleInterface<IUserManagement>(); |
1936 | if (null == account) | 2057 | if (userManager == null) |
1937 | { | 2058 | { |
1938 | return UUID.Zero.ToString(); | 2059 | OSSLShoutError("osAvatarName2Key: UserManagement module not available"); |
2060 | return string.Empty; | ||
2061 | } | ||
2062 | |||
2063 | // Check if the user is already cached | ||
2064 | |||
2065 | UUID userID = userManager.GetUserIdByName(firstname, lastname); | ||
2066 | if (userID != UUID.Zero) | ||
2067 | return userID.ToString(); | ||
2068 | |||
2069 | // Query for the user | ||
2070 | |||
2071 | String realFirstName; String realLastName; String serverURI; | ||
2072 | if (Util.ParseForeignAvatarName(firstname, lastname, out realFirstName, out realLastName, out serverURI)) | ||
2073 | { | ||
2074 | try | ||
2075 | { | ||
2076 | UserAgentServiceConnector userConnection = new UserAgentServiceConnector(serverURI, true); | ||
2077 | |||
2078 | if (userConnection != null) | ||
2079 | { | ||
2080 | userID = userConnection.GetUUID(realFirstName, realLastName); | ||
2081 | if (userID != UUID.Zero) | ||
2082 | { | ||
2083 | userManager.AddUser(userID, realFirstName, realLastName, serverURI); | ||
2084 | return userID.ToString(); | ||
2085 | } | ||
2086 | } | ||
2087 | } | ||
2088 | catch (Exception /*e*/) | ||
2089 | { | ||
2090 | // m_log.Warn("[osAvatarName2Key] UserAgentServiceConnector - Unable to connect to destination grid ", e); | ||
2091 | } | ||
1939 | } | 2092 | } |
1940 | else | 2093 | else |
1941 | { | 2094 | { |
1942 | return account.PrincipalID.ToString(); | 2095 | UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, firstname, lastname); |
2096 | if (account != null) | ||
2097 | return account.PrincipalID.ToString(); | ||
1943 | } | 2098 | } |
2099 | |||
2100 | return UUID.Zero.ToString(); | ||
1944 | } | 2101 | } |
1945 | 2102 | ||
1946 | public string osKey2Name(string id) | 2103 | public string osKey2Name(string id) |
@@ -1953,19 +2110,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1953 | if (UUID.TryParse(id, out key)) | 2110 | if (UUID.TryParse(id, out key)) |
1954 | { | 2111 | { |
1955 | UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key); | 2112 | UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, key); |
1956 | if (null == account) | 2113 | if (account != null) |
1957 | { | ||
1958 | return ""; | ||
1959 | } | ||
1960 | else | ||
1961 | { | ||
1962 | return account.Name; | 2114 | return account.Name; |
2115 | |||
2116 | if (m_ScriptEngine.World.GridUserService != null) | ||
2117 | { | ||
2118 | GridUserInfo uInfo = m_ScriptEngine.World.GridUserService.GetGridUserInfo(key.ToString()); | ||
2119 | |||
2120 | if (uInfo != null) | ||
2121 | { | ||
2122 | UUID userUUID; String gridURL; String firstName; String lastName; String tmp; | ||
2123 | |||
2124 | if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out userUUID, out gridURL, out firstName, out lastName, out tmp)) | ||
2125 | { | ||
2126 | string grid = new Uri(gridURL).Authority; | ||
2127 | return firstName + "." + lastName + " @" + grid; | ||
2128 | } | ||
2129 | } | ||
1963 | } | 2130 | } |
1964 | } | 2131 | } |
1965 | else | 2132 | |
1966 | { | 2133 | return ""; |
1967 | return ""; | ||
1968 | } | ||
1969 | } | 2134 | } |
1970 | 2135 | ||
1971 | private enum InfoType | 2136 | private enum InfoType |
@@ -2101,9 +2266,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2101 | CheckThreatLevel(ThreatLevel.Moderate, "osGetGridHomeURI"); | 2266 | CheckThreatLevel(ThreatLevel.Moderate, "osGetGridHomeURI"); |
2102 | m_host.AddScriptLPS(1); | 2267 | m_host.AddScriptLPS(1); |
2103 | 2268 | ||
2104 | string HomeURI = String.Empty; | ||
2105 | IConfigSource config = m_ScriptEngine.ConfigSource; | 2269 | IConfigSource config = m_ScriptEngine.ConfigSource; |
2270 | string HomeURI = Util.GetConfigVarFromSections<string>(config, "HomeURI", | ||
2271 | new string[] { "Startup", "Hypergrid" }, String.Empty); | ||
2106 | 2272 | ||
2273 | if (!string.IsNullOrEmpty(HomeURI)) | ||
2274 | return HomeURI; | ||
2275 | |||
2276 | // Legacy. Remove soon! | ||
2107 | if (config.Configs["LoginService"] != null) | 2277 | if (config.Configs["LoginService"] != null) |
2108 | HomeURI = config.Configs["LoginService"].GetString("SRV_HomeURI", HomeURI); | 2278 | HomeURI = config.Configs["LoginService"].GetString("SRV_HomeURI", HomeURI); |
2109 | 2279 | ||
@@ -2118,9 +2288,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2118 | CheckThreatLevel(ThreatLevel.Moderate, "osGetGridGatekeeperURI"); | 2288 | CheckThreatLevel(ThreatLevel.Moderate, "osGetGridGatekeeperURI"); |
2119 | m_host.AddScriptLPS(1); | 2289 | m_host.AddScriptLPS(1); |
2120 | 2290 | ||
2121 | string gatekeeperURI = String.Empty; | ||
2122 | IConfigSource config = m_ScriptEngine.ConfigSource; | 2291 | IConfigSource config = m_ScriptEngine.ConfigSource; |
2292 | string gatekeeperURI = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI", | ||
2293 | new string[] { "Startup", "Hypergrid" }, String.Empty); | ||
2294 | |||
2295 | if (!string.IsNullOrEmpty(gatekeeperURI)) | ||
2296 | return gatekeeperURI; | ||
2123 | 2297 | ||
2298 | // Legacy. Remove soon! | ||
2124 | if (config.Configs["GridService"] != null) | 2299 | if (config.Configs["GridService"] != null) |
2125 | gatekeeperURI = config.Configs["GridService"].GetString("Gatekeeper", gatekeeperURI); | 2300 | gatekeeperURI = config.Configs["GridService"].GetString("Gatekeeper", gatekeeperURI); |
2126 | 2301 | ||
@@ -2144,6 +2319,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2144 | return retval; | 2319 | return retval; |
2145 | } | 2320 | } |
2146 | 2321 | ||
2322 | public string osGetAvatarHomeURI(string uuid) | ||
2323 | { | ||
2324 | CheckThreatLevel(ThreatLevel.Low, "osGetAvatarHomeURI"); | ||
2325 | m_host.AddScriptLPS(1); | ||
2326 | |||
2327 | IUserManagement userManager = m_ScriptEngine.World.RequestModuleInterface<IUserManagement>(); | ||
2328 | string returnValue = ""; | ||
2329 | |||
2330 | if (userManager != null) | ||
2331 | { | ||
2332 | returnValue = userManager.GetUserServerURL(new UUID(uuid), "HomeURI"); | ||
2333 | } | ||
2334 | |||
2335 | if (returnValue == "") | ||
2336 | { | ||
2337 | IConfigSource config = m_ScriptEngine.ConfigSource; | ||
2338 | returnValue = Util.GetConfigVarFromSections<string>(config, "HomeURI", | ||
2339 | new string[] { "Startup", "Hypergrid" }, String.Empty); | ||
2340 | |||
2341 | if (!string.IsNullOrEmpty(returnValue)) | ||
2342 | return returnValue; | ||
2343 | |||
2344 | // Legacy. Remove soon! | ||
2345 | if (config.Configs["LoginService"] != null) | ||
2346 | returnValue = config.Configs["LoginService"].GetString("SRV_HomeURI", returnValue); | ||
2347 | |||
2348 | if (String.IsNullOrEmpty(returnValue)) | ||
2349 | returnValue = GridUserInfo(InfoType.Home); | ||
2350 | } | ||
2351 | |||
2352 | return returnValue; | ||
2353 | } | ||
2354 | |||
2147 | public LSL_String osFormatString(string str, LSL_List strings) | 2355 | public LSL_String osFormatString(string str, LSL_List strings) |
2148 | { | 2356 | { |
2149 | CheckThreatLevel(ThreatLevel.VeryLow, "osFormatString"); | 2357 | CheckThreatLevel(ThreatLevel.VeryLow, "osFormatString"); |
@@ -2265,14 +2473,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2265 | // on the ILSL_Api interface. | 2473 | // on the ILSL_Api interface. |
2266 | LSL_Api LSL_Api = (LSL_Api)m_LSL_Api; | 2474 | LSL_Api LSL_Api = (LSL_Api)m_LSL_Api; |
2267 | LSL_List retVal = new LSL_List(); | 2475 | LSL_List retVal = new LSL_List(); |
2268 | LSL_List remaining = null; | 2476 | LSL_List remaining = new LSL_List(); |
2269 | List<SceneObjectPart> parts = LSL_Api.GetLinkParts(linknumber); | 2477 | List<SceneObjectPart> parts = LSL_Api.GetLinkParts(linknumber); |
2270 | foreach (SceneObjectPart part in parts) | 2478 | foreach (SceneObjectPart part in parts) |
2271 | { | 2479 | { |
2272 | remaining = LSL_Api.GetPrimParams(part, rules, ref retVal); | 2480 | remaining = LSL_Api.GetPrimParams(part, rules, ref retVal); |
2273 | } | 2481 | } |
2274 | 2482 | ||
2275 | while (remaining != null && remaining.Length > 2) | 2483 | while (remaining.Length > 2) |
2276 | { | 2484 | { |
2277 | linknumber = remaining.GetLSLIntegerItem(0); | 2485 | linknumber = remaining.GetLSLIntegerItem(0); |
2278 | rules = remaining.GetSublist(1, -1); | 2486 | rules = remaining.GetSublist(1, -1); |
@@ -2284,6 +2492,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2284 | return retVal; | 2492 | return retVal; |
2285 | } | 2493 | } |
2286 | 2494 | ||
2495 | public void osForceCreateLink(string target, int parent) | ||
2496 | { | ||
2497 | CheckThreatLevel(ThreatLevel.VeryLow, "osForceCreateLink"); | ||
2498 | |||
2499 | m_host.AddScriptLPS(1); | ||
2500 | |||
2501 | InitLSL(); | ||
2502 | ((LSL_Api)m_LSL_Api).CreateLink(target, parent); | ||
2503 | } | ||
2504 | |||
2505 | public void osForceBreakLink(int linknum) | ||
2506 | { | ||
2507 | CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakLink"); | ||
2508 | |||
2509 | m_host.AddScriptLPS(1); | ||
2510 | |||
2511 | InitLSL(); | ||
2512 | ((LSL_Api)m_LSL_Api).BreakLink(linknum); | ||
2513 | } | ||
2514 | |||
2515 | public void osForceBreakAllLinks() | ||
2516 | { | ||
2517 | CheckThreatLevel(ThreatLevel.VeryLow, "osForceBreakAllLinks"); | ||
2518 | |||
2519 | m_host.AddScriptLPS(1); | ||
2520 | |||
2521 | InitLSL(); | ||
2522 | ((LSL_Api)m_LSL_Api).BreakAllLinks(); | ||
2523 | } | ||
2524 | |||
2287 | public LSL_Integer osIsNpc(LSL_Key npc) | 2525 | public LSL_Integer osIsNpc(LSL_Key npc) |
2288 | { | 2526 | { |
2289 | CheckThreatLevel(ThreatLevel.None, "osIsNpc"); | 2527 | CheckThreatLevel(ThreatLevel.None, "osIsNpc"); |
@@ -2469,13 +2707,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2469 | ScenePresence sp = World.GetScenePresence(npcId); | 2707 | ScenePresence sp = World.GetScenePresence(npcId); |
2470 | 2708 | ||
2471 | if (sp != null) | 2709 | if (sp != null) |
2472 | { | 2710 | return new LSL_Vector(sp.AbsolutePosition); |
2473 | Vector3 pos = sp.AbsolutePosition; | ||
2474 | return new LSL_Vector(pos.X, pos.Y, pos.Z); | ||
2475 | } | ||
2476 | } | 2711 | } |
2477 | 2712 | ||
2478 | return new LSL_Vector(0, 0, 0); | 2713 | return Vector3.Zero; |
2479 | } | 2714 | } |
2480 | 2715 | ||
2481 | public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos) | 2716 | public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos) |
@@ -2532,21 +2767,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2532 | { | 2767 | { |
2533 | UUID npcId; | 2768 | UUID npcId; |
2534 | if (!UUID.TryParse(npc.m_string, out npcId)) | 2769 | if (!UUID.TryParse(npc.m_string, out npcId)) |
2535 | return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); | 2770 | return new LSL_Rotation(Quaternion.Identity); |
2536 | 2771 | ||
2537 | if (!npcModule.CheckPermissions(npcId, m_host.OwnerID)) | 2772 | if (!npcModule.CheckPermissions(npcId, m_host.OwnerID)) |
2538 | return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); | 2773 | return new LSL_Rotation(Quaternion.Identity); |
2539 | 2774 | ||
2540 | ScenePresence sp = World.GetScenePresence(npcId); | 2775 | ScenePresence sp = World.GetScenePresence(npcId); |
2541 | 2776 | ||
2542 | if (sp != null) | 2777 | if (sp != null) |
2543 | { | 2778 | return new LSL_Rotation(sp.GetWorldRotation()); |
2544 | Quaternion rot = sp.Rotation; | ||
2545 | return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W); | ||
2546 | } | ||
2547 | } | 2779 | } |
2548 | 2780 | ||
2549 | return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); | 2781 | return Quaternion.Identity; |
2550 | } | 2782 | } |
2551 | 2783 | ||
2552 | public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation) | 2784 | public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation) |
@@ -2824,6 +3056,51 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2824 | 3056 | ||
2825 | return SaveAppearanceToNotecard(avatarId, notecard); | 3057 | return SaveAppearanceToNotecard(avatarId, notecard); |
2826 | } | 3058 | } |
3059 | |||
3060 | /// <summary> | ||
3061 | /// Get the gender as specified in avatar appearance for a given avatar key | ||
3062 | /// </summary> | ||
3063 | /// <param name="rawAvatarId"></param> | ||
3064 | /// <returns>"male" or "female" or "unknown"</returns> | ||
3065 | public LSL_String osGetGender(LSL_Key rawAvatarId) | ||
3066 | { | ||
3067 | CheckThreatLevel(ThreatLevel.None, "osGetGender"); | ||
3068 | m_host.AddScriptLPS(1); | ||
3069 | |||
3070 | UUID avatarId; | ||
3071 | if (!UUID.TryParse(rawAvatarId, out avatarId)) | ||
3072 | return new LSL_String("unknown"); | ||
3073 | |||
3074 | ScenePresence sp = World.GetScenePresence(avatarId); | ||
3075 | |||
3076 | if (sp == null || sp.IsChildAgent || sp.Appearance == null || sp.Appearance.VisualParams == null) | ||
3077 | return new LSL_String("unknown"); | ||
3078 | |||
3079 | // find the index of "shape" parameter "male" | ||
3080 | int vpShapeMaleIndex = 0; | ||
3081 | bool indexFound = false; | ||
3082 | VisualParam param = new VisualParam(); | ||
3083 | foreach(var vpEntry in VisualParams.Params) | ||
3084 | { | ||
3085 | param = vpEntry.Value; | ||
3086 | if (param.Name == "male" && param.Wearable == "shape") | ||
3087 | { | ||
3088 | indexFound = true; | ||
3089 | break; | ||
3090 | } | ||
3091 | |||
3092 | if (param.Group == 0) | ||
3093 | vpShapeMaleIndex++; | ||
3094 | } | ||
3095 | |||
3096 | if (!indexFound) | ||
3097 | return new LSL_String("unknown"); | ||
3098 | |||
3099 | float vpShapeMale = Utils.ByteToFloat(sp.Appearance.VisualParams[vpShapeMaleIndex], param.MinValue, param.MaxValue); | ||
3100 | |||
3101 | bool isMale = vpShapeMale > 0.5f; | ||
3102 | return new LSL_String(isMale ? "male" : "female"); | ||
3103 | } | ||
2827 | 3104 | ||
2828 | /// <summary> | 3105 | /// <summary> |
2829 | /// Get current region's map texture UUID | 3106 | /// Get current region's map texture UUID |
@@ -2887,6 +3164,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2887 | return ret; | 3164 | return ret; |
2888 | } | 3165 | } |
2889 | 3166 | ||
3167 | public LSL_Vector osGetRegionSize() | ||
3168 | { | ||
3169 | CheckThreatLevel(ThreatLevel.None, "osGetRegionSize"); | ||
3170 | m_host.AddScriptLPS(1); | ||
3171 | |||
3172 | bool isMegaregion; | ||
3173 | IRegionCombinerModule rcMod = World.RequestModuleInterface<IRegionCombinerModule>(); | ||
3174 | if (rcMod != null) | ||
3175 | isMegaregion = rcMod.IsRootForMegaregion(World.RegionInfo.RegionID); | ||
3176 | else | ||
3177 | isMegaregion = false; | ||
3178 | |||
3179 | if (isMegaregion) | ||
3180 | { | ||
3181 | Vector2 size = rcMod.GetSizeOfMegaregion(World.RegionInfo.RegionID); | ||
3182 | return new LSL_Vector(size.X, size.Y, Constants.RegionHeight); | ||
3183 | } | ||
3184 | else | ||
3185 | { | ||
3186 | Scene scene = m_ScriptEngine.World; | ||
3187 | GridRegion region = scene.GridService.GetRegionByUUID(UUID.Zero, World.RegionInfo.RegionID); | ||
3188 | return new LSL_Vector((float)region.RegionSizeX, (float)region.RegionSizeX, Constants.RegionHeight); | ||
3189 | } | ||
3190 | } | ||
3191 | |||
2890 | public int osGetSimulatorMemory() | 3192 | public int osGetSimulatorMemory() |
2891 | { | 3193 | { |
2892 | CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory"); | 3194 | CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory"); |
@@ -2925,7 +3227,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2925 | sp.ControllingClient.Kick(alert); | 3227 | sp.ControllingClient.Kick(alert); |
2926 | 3228 | ||
2927 | // ...and close on our side | 3229 | // ...and close on our side |
2928 | sp.Scene.IncomingCloseAgent(sp.UUID, false); | 3230 | sp.Scene.CloseAgent(sp.UUID, false); |
2929 | } | 3231 | } |
2930 | }); | 3232 | }); |
2931 | } | 3233 | } |
@@ -2976,20 +3278,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2976 | 3278 | ||
2977 | UUID avatarId = new UUID(avatar); | 3279 | UUID avatarId = new UUID(avatar); |
2978 | ScenePresence presence = World.GetScenePresence(avatarId); | 3280 | ScenePresence presence = World.GetScenePresence(avatarId); |
2979 | Vector3 pos = m_host.GetWorldPosition(); | 3281 | |
2980 | bool result = World.ScriptDanger(m_host.LocalId, new Vector3((float)pos.X, (float)pos.Y, (float)pos.Z)); | 3282 | if (presence != null && World.ScriptDanger(m_host.LocalId, m_host.GetWorldPosition())) |
2981 | if (result) | ||
2982 | { | 3283 | { |
2983 | if (presence != null) | 3284 | float health = presence.Health; |
2984 | { | 3285 | health += (float)healing; |
2985 | float health = presence.Health; | 3286 | |
2986 | health += (float)healing; | 3287 | if (health >= 100) |
2987 | if (health >= 100) | 3288 | health = 100; |
2988 | { | 3289 | |
2989 | health = 100; | 3290 | presence.setHealthWithUpdate(health); |
2990 | } | ||
2991 | presence.setHealthWithUpdate(health); | ||
2992 | } | ||
2993 | } | 3291 | } |
2994 | } | 3292 | } |
2995 | 3293 | ||
@@ -3066,8 +3364,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3066 | if (avatar != null && avatar.UUID != m_host.OwnerID) | 3364 | if (avatar != null && avatar.UUID != m_host.OwnerID) |
3067 | { | 3365 | { |
3068 | result.Add(new LSL_String(avatar.UUID.ToString())); | 3366 | result.Add(new LSL_String(avatar.UUID.ToString())); |
3069 | OpenMetaverse.Vector3 ap = avatar.AbsolutePosition; | 3367 | result.Add(new LSL_Vector(avatar.AbsolutePosition)); |
3070 | result.Add(new LSL_Vector(ap.X, ap.Y, ap.Z)); | ||
3071 | result.Add(new LSL_String(avatar.Name)); | 3368 | result.Add(new LSL_String(avatar.Name)); |
3072 | } | 3369 | } |
3073 | }); | 3370 | }); |
@@ -3263,7 +3560,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3263 | 3560 | ||
3264 | public void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint) | 3561 | public void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint) |
3265 | { | 3562 | { |
3266 | CheckThreatLevel(ThreatLevel.Severe, "osForceAttachToOtherAvatarFromInventory"); | 3563 | CheckThreatLevel(ThreatLevel.VeryHigh, "osForceAttachToOtherAvatarFromInventory"); |
3267 | 3564 | ||
3268 | m_host.AddScriptLPS(1); | 3565 | m_host.AddScriptLPS(1); |
3269 | 3566 | ||
@@ -3307,14 +3604,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3307 | if (sp == null) | 3604 | if (sp == null) |
3308 | return; | 3605 | return; |
3309 | 3606 | ||
3310 | InventoryItemBase newItem = World.MoveTaskInventoryItem(sp.UUID, UUID.Zero, m_host, item.ItemID); | 3607 | string message; |
3608 | InventoryItemBase newItem = World.MoveTaskInventoryItem(sp.UUID, UUID.Zero, m_host, item.ItemID, out message); | ||
3311 | 3609 | ||
3312 | if (newItem == null) | 3610 | if (newItem == null) |
3313 | { | 3611 | { |
3314 | m_log.ErrorFormat( | 3612 | m_log.ErrorFormat( |
3315 | "[OSSL API]: Could not create user inventory item {0} for {1}, attach point {2} in {3}", | 3613 | "[OSSL API]: Could not create user inventory item {0} for {1}, attach point {2} in {3}: {4}", |
3316 | itemName, m_host.Name, attachmentPoint, World.Name); | 3614 | itemName, m_host.Name, attachmentPoint, World.Name, message); |
3317 | 3615 | ((LSL_Api)m_LSL_Api).llSay(0, message); | |
3318 | return; | 3616 | return; |
3319 | } | 3617 | } |
3320 | 3618 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index dd45406..64dc2e2 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs | |||
@@ -353,7 +353,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
353 | // Position of a sensor in a child prim attached to an avatar | 353 | // Position of a sensor in a child prim attached to an avatar |
354 | // will be still wrong. | 354 | // will be still wrong. |
355 | ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); | 355 | ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); |
356 | q = avatar.Rotation * q; | 356 | |
357 | // Don't proceed if the avatar for this attachment has since been removed from the scene. | ||
358 | if (avatar == null) | ||
359 | return sensedEntities; | ||
360 | |||
361 | q = avatar.GetWorldRotation() * q; | ||
357 | } | 362 | } |
358 | 363 | ||
359 | LSL_Types.Quaternion r = new LSL_Types.Quaternion(q); | 364 | LSL_Types.Quaternion r = new LSL_Types.Quaternion(q); |
@@ -362,7 +367,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
362 | 367 | ||
363 | Vector3 ZeroVector = new Vector3(0, 0, 0); | 368 | Vector3 ZeroVector = new Vector3(0, 0, 0); |
364 | 369 | ||
365 | bool nameSearch = (ts.name != null && ts.name != ""); | 370 | bool nameSearch = !string.IsNullOrEmpty(ts.name); |
366 | 371 | ||
367 | foreach (EntityBase ent in Entities) | 372 | foreach (EntityBase ent in Entities) |
368 | { | 373 | { |
@@ -480,7 +485,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
480 | // Position of a sensor in a child prim attached to an avatar | 485 | // Position of a sensor in a child prim attached to an avatar |
481 | // will be still wrong. | 486 | // will be still wrong. |
482 | ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); | 487 | ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); |
483 | q = avatar.Rotation * q; | 488 | |
489 | // Don't proceed if the avatar for this attachment has since been removed from the scene. | ||
490 | if (avatar == null) | ||
491 | return sensedEntities; | ||
492 | |||
493 | q = avatar.GetWorldRotation() * q; | ||
484 | } | 494 | } |
485 | 495 | ||
486 | LSL_Types.Quaternion r = new LSL_Types.Quaternion(q); | 496 | LSL_Types.Quaternion r = new LSL_Types.Quaternion(q); |
@@ -595,7 +605,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
595 | return sensedEntities; | 605 | return sensedEntities; |
596 | senseEntity(sp); | 606 | senseEntity(sp); |
597 | } | 607 | } |
598 | else if (ts.name != null && ts.name != "") | 608 | else if (!string.IsNullOrEmpty(ts.name)) |
599 | { | 609 | { |
600 | ScenePresence sp; | 610 | ScenePresence sp; |
601 | // Try lookup by name will return if/when found | 611 | // Try lookup by name will return if/when found |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Properties/AssemblyInfo.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Properties/AssemblyInfo.cs index d173db0..215c087 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Properties/AssemblyInfo.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Properties/AssemblyInfo.cs | |||
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices; | |||
29 | // Build Number | 29 | // Build Number |
30 | // Revision | 30 | // Revision |
31 | // | 31 | // |
32 | [assembly: AssemblyVersion("0.7.5.*")] | 32 | [assembly: AssemblyVersion("0.8.3.*")] |
33 | [assembly: AssemblyFileVersion("1.0.0.0")] | 33 | |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs index 98f8be7..3d58573 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs | |||
@@ -124,6 +124,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
124 | LSL_String llGetCreator(); | 124 | LSL_String llGetCreator(); |
125 | LSL_String llGetDate(); | 125 | LSL_String llGetDate(); |
126 | LSL_Float llGetEnergy(); | 126 | LSL_Float llGetEnergy(); |
127 | LSL_String llGetEnv(LSL_String name); | ||
127 | LSL_Vector llGetForce(); | 128 | LSL_Vector llGetForce(); |
128 | LSL_Integer llGetFreeMemory(); | 129 | LSL_Integer llGetFreeMemory(); |
129 | LSL_Integer llGetFreeURLs(); | 130 | LSL_Integer llGetFreeURLs(); |
@@ -149,6 +150,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
149 | LSL_Vector llGetLocalPos(); | 150 | LSL_Vector llGetLocalPos(); |
150 | LSL_Rotation llGetLocalRot(); | 151 | LSL_Rotation llGetLocalRot(); |
151 | LSL_Float llGetMass(); | 152 | LSL_Float llGetMass(); |
153 | LSL_Float llGetMassMKS(); | ||
152 | LSL_Integer llGetMemoryLimit(); | 154 | LSL_Integer llGetMemoryLimit(); |
153 | void llGetNextEmail(string address, string subject); | 155 | void llGetNextEmail(string address, string subject); |
154 | LSL_String llGetNotecardLine(string name, int line); | 156 | LSL_String llGetNotecardLine(string name, int line); |
@@ -207,7 +209,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
207 | LSL_Float llGetWallclock(); | 209 | LSL_Float llGetWallclock(); |
208 | void llGiveInventory(string destination, string inventory); | 210 | void llGiveInventory(string destination, string inventory); |
209 | void llGiveInventoryList(string destination, string category, LSL_List inventory); | 211 | void llGiveInventoryList(string destination, string category, LSL_List inventory); |
210 | LSL_Integer llGiveMoney(string destination, int amount); | 212 | void llGiveMoney(string destination, int amount); |
213 | LSL_String llTransferLindenDollars(string destination, int amount); | ||
211 | void llGodLikeRezObject(string inventory, LSL_Vector pos); | 214 | void llGodLikeRezObject(string inventory, LSL_Vector pos); |
212 | LSL_Float llGround(LSL_Vector offset); | 215 | LSL_Float llGround(LSL_Vector offset); |
213 | LSL_Vector llGroundContour(LSL_Vector offset); | 216 | LSL_Vector llGroundContour(LSL_Vector offset); |
@@ -337,9 +340,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
337 | void llSetCameraParams(LSL_List rules); | 340 | void llSetCameraParams(LSL_List rules); |
338 | void llSetClickAction(int action); | 341 | void llSetClickAction(int action); |
339 | void llSetColor(LSL_Vector color, int face); | 342 | void llSetColor(LSL_Vector color, int face); |
343 | void llSetContentType(LSL_Key id, LSL_Integer type); | ||
340 | void llSetDamage(double damage); | 344 | void llSetDamage(double damage); |
341 | void llSetForce(LSL_Vector force, int local); | 345 | void llSetForce(LSL_Vector force, int local); |
342 | void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local); | 346 | void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local); |
347 | void llSetVelocity(LSL_Vector velocity, int local); | ||
348 | void llSetAngularVelocity(LSL_Vector angularVelocity, int local); | ||
343 | void llSetHoverHeight(double height, int water, double tau); | 349 | void llSetHoverHeight(double height, int water, double tau); |
344 | void llSetInventoryPermMask(string item, int mask, int value); | 350 | void llSetInventoryPermMask(string item, int mask, int value); |
345 | void llSetLinkAlpha(int linknumber, double alpha, int face); | 351 | void llSetLinkAlpha(int linknumber, double alpha, int face); |
@@ -426,6 +432,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
426 | void print(string str); | 432 | void print(string str); |
427 | 433 | ||
428 | void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc); | 434 | void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc); |
435 | void llSetKeyframedMotion(LSL_List frames, LSL_List options); | ||
429 | LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules); | 436 | LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules); |
430 | } | 437 | } |
431 | } | 438 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index cdd9ea8..6259b76 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | |||
@@ -259,6 +259,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
259 | 259 | ||
260 | string osGetScriptEngineName(); | 260 | string osGetScriptEngineName(); |
261 | string osGetSimulatorVersion(); | 261 | string osGetSimulatorVersion(); |
262 | LSL_Integer osCheckODE(); | ||
263 | string osGetPhysicsEngineType(); | ||
262 | Object osParseJSONNew(string JSON); | 264 | Object osParseJSONNew(string JSON); |
263 | Hashtable osParseJSON(string JSON); | 265 | Hashtable osParseJSON(string JSON); |
264 | 266 | ||
@@ -281,6 +283,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
281 | string osGetGridGatekeeperURI(); | 283 | string osGetGridGatekeeperURI(); |
282 | string osGetGridCustom(string key); | 284 | string osGetGridCustom(string key); |
283 | 285 | ||
286 | string osGetAvatarHomeURI(string uuid); | ||
287 | |||
284 | LSL_String osFormatString(string str, LSL_List strings); | 288 | LSL_String osFormatString(string str, LSL_List strings); |
285 | LSL_List osMatchString(string src, string pattern, int start); | 289 | LSL_List osMatchString(string src, string pattern, int start); |
286 | LSL_String osReplaceString(string src, string pattern, string replace, int count, int start); | 290 | LSL_String osReplaceString(string src, string pattern, string replace, int count, int start); |
@@ -293,6 +297,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
293 | LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules); | 297 | LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules); |
294 | 298 | ||
295 | /// <summary> | 299 | /// <summary> |
300 | /// Identical to llCreateLink() but does not require permission from the owner. | ||
301 | /// </summary> | ||
302 | /// <param name='target'></param> | ||
303 | /// <param name='parent'></param> | ||
304 | void osForceCreateLink(string target, int parent); | ||
305 | |||
306 | /// <summary> | ||
307 | /// Identical to llBreakLink() but does not require permission from the owner. | ||
308 | /// </summary> | ||
309 | /// <param name='linknum'></param> | ||
310 | void osForceBreakLink(int linknum); | ||
311 | |||
312 | /// <summary> | ||
313 | /// Identical to llBreakAllLinks() but does not require permission from the owner. | ||
314 | /// </summary> | ||
315 | void osForceBreakAllLinks(); | ||
316 | |||
317 | /// <summary> | ||
296 | /// Check if the given key is an npc | 318 | /// Check if the given key is an npc |
297 | /// </summary> | 319 | /// </summary> |
298 | /// <param name="npc"></param> | 320 | /// <param name="npc"></param> |
@@ -333,9 +355,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
333 | LSL_Key osOwnerSaveAppearance(string notecard); | 355 | LSL_Key osOwnerSaveAppearance(string notecard); |
334 | LSL_Key osAgentSaveAppearance(key agentId, string notecard); | 356 | LSL_Key osAgentSaveAppearance(key agentId, string notecard); |
335 | 357 | ||
358 | key osGetGender(LSL_Key rawAvatarId); | ||
336 | key osGetMapTexture(); | 359 | key osGetMapTexture(); |
337 | key osGetRegionMapTexture(string regionName); | 360 | key osGetRegionMapTexture(string regionName); |
338 | LSL_List osGetRegionStats(); | 361 | LSL_List osGetRegionStats(); |
362 | vector osGetRegionSize(); | ||
339 | 363 | ||
340 | int osGetSimulatorMemory(); | 364 | int osGetSimulatorMemory(); |
341 | void osKickAvatar(string FirstName,string SurName,string alert); | 365 | void osKickAvatar(string FirstName,string SurName,string alert); |
@@ -343,6 +367,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
343 | LSL_Float osGetHealth(string avatar); | 367 | LSL_Float osGetHealth(string avatar); |
344 | void osCauseHealing(string avatar, double healing); | 368 | void osCauseHealing(string avatar, double healing); |
345 | void osCauseDamage(string avatar, double damage); | 369 | void osCauseDamage(string avatar, double damage); |
370 | void osForceOtherSit(string avatar); | ||
371 | void osForceOtherSit(string avatar, string target); | ||
346 | LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules); | 372 | LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules); |
347 | void osSetPrimitiveParams(LSL_Key prim, LSL_List rules); | 373 | void osSetPrimitiveParams(LSL_Key prim, LSL_List rules); |
348 | void osSetProjectionParams(bool projection, LSL_Key texture, double fov, double focus, double amb); | 374 | void osSetProjectionParams(bool projection, LSL_Key texture, double fov, double focus, double amb); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs index 9615315..ce17ed0 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs | |||
@@ -77,6 +77,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
77 | touch = 8, | 77 | touch = 8, |
78 | touch_end = 536870912, | 78 | touch_end = 536870912, |
79 | touch_start = 2097152, | 79 | touch_start = 2097152, |
80 | transaction_result = 33554432, | ||
80 | object_rez = 4194304 | 81 | object_rez = 4194304 |
81 | } | 82 | } |
82 | 83 | ||
@@ -235,6 +236,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
235 | m_eventFlagsMap.Add("touch", scriptEvents.touch); | 236 | m_eventFlagsMap.Add("touch", scriptEvents.touch); |
236 | m_eventFlagsMap.Add("touch_end", scriptEvents.touch_end); | 237 | m_eventFlagsMap.Add("touch_end", scriptEvents.touch_end); |
237 | m_eventFlagsMap.Add("touch_start", scriptEvents.touch_start); | 238 | m_eventFlagsMap.Add("touch_start", scriptEvents.touch_start); |
239 | m_eventFlagsMap.Add("transaction_result", scriptEvents.transaction_result); | ||
238 | m_eventFlagsMap.Add("object_rez", scriptEvents.object_rez); | 240 | m_eventFlagsMap.Add("object_rez", scriptEvents.object_rez); |
239 | } | 241 | } |
240 | } | 242 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index 9bf1a64..9aecea2 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs | |||
@@ -48,6 +48,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
48 | public const int STATUS_DIE_AT_EDGE = 128; | 48 | public const int STATUS_DIE_AT_EDGE = 128; |
49 | public const int STATUS_RETURN_AT_EDGE = 256; | 49 | public const int STATUS_RETURN_AT_EDGE = 256; |
50 | public const int STATUS_CAST_SHADOWS = 512; | 50 | public const int STATUS_CAST_SHADOWS = 512; |
51 | public const int STATUS_BLOCK_GRAB_OBJECT = 1024; | ||
51 | 52 | ||
52 | public const int AGENT = 1; | 53 | public const int AGENT = 1; |
53 | public const int AGENT_BY_LEGACY_NAME = 1; | 54 | public const int AGENT_BY_LEGACY_NAME = 1; |
@@ -106,6 +107,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
106 | public const int PSYS_PART_TARGET_POS_MASK = 64; | 107 | public const int PSYS_PART_TARGET_POS_MASK = 64; |
107 | public const int PSYS_PART_TARGET_LINEAR_MASK = 128; | 108 | public const int PSYS_PART_TARGET_LINEAR_MASK = 128; |
108 | public const int PSYS_PART_EMISSIVE_MASK = 256; | 109 | public const int PSYS_PART_EMISSIVE_MASK = 256; |
110 | public const int PSYS_PART_RIBBON_MASK = 1024; | ||
109 | public const int PSYS_PART_FLAGS = 0; | 111 | public const int PSYS_PART_FLAGS = 0; |
110 | public const int PSYS_PART_START_COLOR = 1; | 112 | public const int PSYS_PART_START_COLOR = 1; |
111 | public const int PSYS_PART_START_ALPHA = 2; | 113 | public const int PSYS_PART_START_ALPHA = 2; |
@@ -129,6 +131,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
129 | public const int PSYS_SRC_OMEGA = 21; | 131 | public const int PSYS_SRC_OMEGA = 21; |
130 | public const int PSYS_SRC_ANGLE_BEGIN = 22; | 132 | public const int PSYS_SRC_ANGLE_BEGIN = 22; |
131 | public const int PSYS_SRC_ANGLE_END = 23; | 133 | public const int PSYS_SRC_ANGLE_END = 23; |
134 | public const int PSYS_PART_BLEND_FUNC_SOURCE = 24; | ||
135 | public const int PSYS_PART_BLEND_FUNC_DEST = 25; | ||
136 | public const int PSYS_PART_START_GLOW = 26; | ||
137 | public const int PSYS_PART_END_GLOW = 27; | ||
138 | public const int PSYS_PART_BF_ONE = 0; | ||
139 | public const int PSYS_PART_BF_ZERO = 1; | ||
140 | public const int PSYS_PART_BF_DEST_COLOR = 2; | ||
141 | public const int PSYS_PART_BF_SOURCE_COLOR = 3; | ||
142 | public const int PSYS_PART_BF_ONE_MINUS_DEST_COLOR = 4; | ||
143 | public const int PSYS_PART_BF_ONE_MINUS_SOURCE_COLOR = 5; | ||
144 | public const int PSYS_PART_BF_SOURCE_ALPHA = 7; | ||
145 | public const int PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA = 9; | ||
132 | public const int PSYS_SRC_PATTERN_DROP = 1; | 146 | public const int PSYS_SRC_PATTERN_DROP = 1; |
133 | public const int PSYS_SRC_PATTERN_EXPLODE = 2; | 147 | public const int PSYS_SRC_PATTERN_EXPLODE = 2; |
134 | public const int PSYS_SRC_PATTERN_ANGLE = 4; | 148 | public const int PSYS_SRC_PATTERN_ANGLE = 4; |
@@ -236,6 +250,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
236 | public const int ATTACH_HUD_BOTTOM_LEFT = 36; | 250 | public const int ATTACH_HUD_BOTTOM_LEFT = 36; |
237 | public const int ATTACH_HUD_BOTTOM = 37; | 251 | public const int ATTACH_HUD_BOTTOM = 37; |
238 | public const int ATTACH_HUD_BOTTOM_RIGHT = 38; | 252 | public const int ATTACH_HUD_BOTTOM_RIGHT = 38; |
253 | public const int ATTACH_NECK = 39; | ||
254 | public const int ATTACH_AVATAR_CENTER = 40; | ||
239 | 255 | ||
240 | #region osMessageAttachments constants | 256 | #region osMessageAttachments constants |
241 | 257 | ||
@@ -355,6 +371,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
355 | public const int HTTP_MIMETYPE = 1; | 371 | public const int HTTP_MIMETYPE = 1; |
356 | public const int HTTP_BODY_MAXLENGTH = 2; | 372 | public const int HTTP_BODY_MAXLENGTH = 2; |
357 | public const int HTTP_VERIFY_CERT = 3; | 373 | public const int HTTP_VERIFY_CERT = 3; |
374 | public const int HTTP_VERBOSE_THROTTLE = 4; | ||
375 | public const int HTTP_CUSTOM_HEADER = 5; | ||
376 | public const int HTTP_PRAGMA_NO_CACHE = 6; | ||
377 | |||
378 | // llSetContentType | ||
379 | public const int CONTENT_TYPE_TEXT = 0; //text/plain | ||
380 | public const int CONTENT_TYPE_HTML = 1; //text/html | ||
381 | public const int CONTENT_TYPE_XML = 2; //application/xml | ||
382 | public const int CONTENT_TYPE_XHTML = 3; //application/xhtml+xml | ||
383 | public const int CONTENT_TYPE_ATOM = 4; //application/atom+xml | ||
384 | public const int CONTENT_TYPE_JSON = 5; //application/json | ||
385 | public const int CONTENT_TYPE_LLSD = 6; //application/llsd+xml | ||
386 | public const int CONTENT_TYPE_FORM = 7; //application/x-www-form-urlencoded | ||
387 | public const int CONTENT_TYPE_RSS = 8; //application/rss+xml | ||
358 | 388 | ||
359 | public const int PRIM_MATERIAL = 2; | 389 | public const int PRIM_MATERIAL = 2; |
360 | public const int PRIM_PHYSICS = 3; | 390 | public const int PRIM_PHYSICS = 3; |
@@ -381,6 +411,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
381 | public const int PRIM_POS_LOCAL = 33; | 411 | public const int PRIM_POS_LOCAL = 33; |
382 | public const int PRIM_LINK_TARGET = 34; | 412 | public const int PRIM_LINK_TARGET = 34; |
383 | public const int PRIM_SLICE = 35; | 413 | public const int PRIM_SLICE = 35; |
414 | public const int PRIM_SPECULAR = 36; | ||
415 | public const int PRIM_NORMAL = 37; | ||
416 | public const int PRIM_ALPHA_MODE = 38; | ||
384 | public const int PRIM_TEXGEN_DEFAULT = 0; | 417 | public const int PRIM_TEXGEN_DEFAULT = 0; |
385 | public const int PRIM_TEXGEN_PLANAR = 1; | 418 | public const int PRIM_TEXGEN_PLANAR = 1; |
386 | 419 | ||
@@ -563,6 +596,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
563 | public const int OBJECT_PHYSICS = 21; | 596 | public const int OBJECT_PHYSICS = 21; |
564 | public const int OBJECT_PHANTOM = 22; | 597 | public const int OBJECT_PHANTOM = 22; |
565 | public const int OBJECT_TEMP_ON_REZ = 23; | 598 | public const int OBJECT_TEMP_ON_REZ = 23; |
599 | public const int OBJECT_RENDER_WEIGHT = 24; | ||
600 | public const int OBJECT_HOVER_HEIGHT = 25; | ||
601 | public const int OBJECT_BODY_SHAPE_TYPE = 26; | ||
602 | public const int OBJECT_LAST_OWNER_ID = 27; | ||
566 | 603 | ||
567 | // Pathfinding types | 604 | // Pathfinding types |
568 | public const int OPT_OTHER = -1; | 605 | public const int OPT_OTHER = -1; |
@@ -635,7 +672,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
635 | public const int TOUCH_INVALID_FACE = -1; | 672 | public const int TOUCH_INVALID_FACE = -1; |
636 | public static readonly vector TOUCH_INVALID_TEXCOORD = new vector(-1.0, -1.0, 0.0); | 673 | public static readonly vector TOUCH_INVALID_TEXCOORD = new vector(-1.0, -1.0, 0.0); |
637 | public static readonly vector TOUCH_INVALID_VECTOR = ZERO_VECTOR; | 674 | public static readonly vector TOUCH_INVALID_VECTOR = ZERO_VECTOR; |
638 | 675 | ||
639 | // constants for llGetPrimMediaParams/llSetPrimMediaParams | 676 | // constants for llGetPrimMediaParams/llSetPrimMediaParams |
640 | public const int PRIM_MEDIA_ALT_IMAGE_ENABLE = 0; | 677 | public const int PRIM_MEDIA_ALT_IMAGE_ENABLE = 0; |
641 | public const int PRIM_MEDIA_CONTROLS = 1; | 678 | public const int PRIM_MEDIA_CONTROLS = 1; |
@@ -652,15 +689,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
652 | public const int PRIM_MEDIA_WHITELIST = 12; | 689 | public const int PRIM_MEDIA_WHITELIST = 12; |
653 | public const int PRIM_MEDIA_PERMS_INTERACT = 13; | 690 | public const int PRIM_MEDIA_PERMS_INTERACT = 13; |
654 | public const int PRIM_MEDIA_PERMS_CONTROL = 14; | 691 | public const int PRIM_MEDIA_PERMS_CONTROL = 14; |
655 | 692 | ||
656 | public const int PRIM_MEDIA_CONTROLS_STANDARD = 0; | 693 | public const int PRIM_MEDIA_CONTROLS_STANDARD = 0; |
657 | public const int PRIM_MEDIA_CONTROLS_MINI = 1; | 694 | public const int PRIM_MEDIA_CONTROLS_MINI = 1; |
658 | 695 | ||
659 | public const int PRIM_MEDIA_PERM_NONE = 0; | 696 | public const int PRIM_MEDIA_PERM_NONE = 0; |
660 | public const int PRIM_MEDIA_PERM_OWNER = 1; | 697 | public const int PRIM_MEDIA_PERM_OWNER = 1; |
661 | public const int PRIM_MEDIA_PERM_GROUP = 2; | 698 | public const int PRIM_MEDIA_PERM_GROUP = 2; |
662 | public const int PRIM_MEDIA_PERM_ANYONE = 4; | 699 | public const int PRIM_MEDIA_PERM_ANYONE = 4; |
663 | 700 | ||
701 | public const int PRIM_PHYSICS_SHAPE_TYPE = 30; | ||
702 | public const int PRIM_PHYSICS_SHAPE_PRIM = 0; | ||
703 | public const int PRIM_PHYSICS_SHAPE_CONVEX = 2; | ||
704 | public const int PRIM_PHYSICS_SHAPE_NONE = 1; | ||
705 | |||
706 | public const int PRIM_PHYSICS_MATERIAL = 31; | ||
707 | public const int DENSITY = 1; | ||
708 | public const int FRICTION = 2; | ||
709 | public const int RESTITUTION = 4; | ||
710 | public const int GRAVITY_MULTIPLIER = 8; | ||
711 | |||
664 | // extra constants for llSetPrimMediaParams | 712 | // extra constants for llSetPrimMediaParams |
665 | public static readonly LSLInteger LSL_STATUS_OK = new LSLInteger(0); | 713 | public static readonly LSLInteger LSL_STATUS_OK = new LSLInteger(0); |
666 | public static readonly LSLInteger LSL_STATUS_MALFORMED_PARAMS = new LSLInteger(1000); | 714 | public static readonly LSLInteger LSL_STATUS_MALFORMED_PARAMS = new LSLInteger(1000); |
@@ -677,7 +725,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
677 | public const string TEXTURE_PLYWOOD = "89556747-24cb-43ed-920b-47caed15465f"; | 725 | public const string TEXTURE_PLYWOOD = "89556747-24cb-43ed-920b-47caed15465f"; |
678 | public const string TEXTURE_TRANSPARENT = "8dcd4a48-2d37-4909-9f78-f7a9eb4ef903"; | 726 | public const string TEXTURE_TRANSPARENT = "8dcd4a48-2d37-4909-9f78-f7a9eb4ef903"; |
679 | public const string TEXTURE_MEDIA = "8b5fec65-8d8d-9dc5-cda8-8fdf2716e361"; | 727 | public const string TEXTURE_MEDIA = "8b5fec65-8d8d-9dc5-cda8-8fdf2716e361"; |
680 | 728 | ||
681 | // Constants for osGetRegionStats | 729 | // Constants for osGetRegionStats |
682 | public const int STATS_TIME_DILATION = 0; | 730 | public const int STATS_TIME_DILATION = 0; |
683 | public const int STATS_SIM_FPS = 1; | 731 | public const int STATS_SIM_FPS = 1; |
@@ -730,9 +778,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
730 | public static readonly LSLInteger RC_GET_ROOT_KEY = 2; | 778 | public static readonly LSLInteger RC_GET_ROOT_KEY = 2; |
731 | public static readonly LSLInteger RC_GET_LINK_NUM = 4; | 779 | public static readonly LSLInteger RC_GET_LINK_NUM = 4; |
732 | 780 | ||
733 | public static readonly LSLInteger RCERR_UNKNOWN = -1; | 781 | public static readonly LSLInteger RCERR_UNKNOWN = -1; |
734 | public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2; | 782 | public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2; |
735 | public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3; | 783 | public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = -3; |
784 | |||
785 | public const int KFM_MODE = 1; | ||
786 | public const int KFM_LOOP = 1; | ||
787 | public const int KFM_REVERSE = 3; | ||
788 | public const int KFM_FORWARD = 0; | ||
789 | public const int KFM_PING_PONG = 2; | ||
790 | public const int KFM_DATA = 2; | ||
791 | public const int KFM_TRANSLATION = 2; | ||
792 | public const int KFM_ROTATION = 1; | ||
793 | public const int KFM_COMMAND = 0; | ||
794 | public const int KFM_CMD_PLAY = 0; | ||
795 | public const int KFM_CMD_STOP = 1; | ||
796 | public const int KFM_CMD_PAUSE = 2; | ||
736 | 797 | ||
737 | /// <summary> | 798 | /// <summary> |
738 | /// process name parameter as regex | 799 | /// process name parameter as regex |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs index 36803a4..35aaf01 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs | |||
@@ -464,6 +464,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
464 | return m_LSL_Functions.llGetEnergy(); | 464 | return m_LSL_Functions.llGetEnergy(); |
465 | } | 465 | } |
466 | 466 | ||
467 | public LSL_String llGetEnv(LSL_String name) | ||
468 | { | ||
469 | return m_LSL_Functions.llGetEnv(name); | ||
470 | } | ||
471 | |||
467 | public LSL_Vector llGetForce() | 472 | public LSL_Vector llGetForce() |
468 | { | 473 | { |
469 | return m_LSL_Functions.llGetForce(); | 474 | return m_LSL_Functions.llGetForce(); |
@@ -554,6 +559,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
554 | return m_LSL_Functions.llGetLinkNumberOfSides(link); | 559 | return m_LSL_Functions.llGetLinkNumberOfSides(link); |
555 | } | 560 | } |
556 | 561 | ||
562 | public void llSetKeyframedMotion(LSL_List frames, LSL_List options) | ||
563 | { | ||
564 | m_LSL_Functions.llSetKeyframedMotion(frames, options); | ||
565 | } | ||
566 | |||
557 | public LSL_Integer llGetListEntryType(LSL_List src, int index) | 567 | public LSL_Integer llGetListEntryType(LSL_List src, int index) |
558 | { | 568 | { |
559 | return m_LSL_Functions.llGetListEntryType(src, index); | 569 | return m_LSL_Functions.llGetListEntryType(src, index); |
@@ -579,6 +589,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
579 | return m_LSL_Functions.llGetMass(); | 589 | return m_LSL_Functions.llGetMass(); |
580 | } | 590 | } |
581 | 591 | ||
592 | public LSL_Float llGetMassMKS() | ||
593 | { | ||
594 | return m_LSL_Functions.llGetMassMKS(); | ||
595 | } | ||
596 | |||
582 | public LSL_Integer llGetMemoryLimit() | 597 | public LSL_Integer llGetMemoryLimit() |
583 | { | 598 | { |
584 | return m_LSL_Functions.llGetMemoryLimit(); | 599 | return m_LSL_Functions.llGetMemoryLimit(); |
@@ -869,9 +884,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
869 | m_LSL_Functions.llGiveInventoryList(destination, category, inventory); | 884 | m_LSL_Functions.llGiveInventoryList(destination, category, inventory); |
870 | } | 885 | } |
871 | 886 | ||
872 | public LSL_Integer llGiveMoney(string destination, int amount) | 887 | public void llGiveMoney(string destination, int amount) |
873 | { | 888 | { |
874 | return m_LSL_Functions.llGiveMoney(destination, amount); | 889 | m_LSL_Functions.llGiveMoney(destination, amount); |
890 | } | ||
891 | |||
892 | public LSL_String llTransferLindenDollars(string destination, int amount) | ||
893 | { | ||
894 | return m_LSL_Functions.llTransferLindenDollars(destination, amount); | ||
875 | } | 895 | } |
876 | 896 | ||
877 | public void llGodLikeRezObject(string inventory, LSL_Vector pos) | 897 | public void llGodLikeRezObject(string inventory, LSL_Vector pos) |
@@ -1518,6 +1538,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
1518 | m_LSL_Functions.llSetColor(color, face); | 1538 | m_LSL_Functions.llSetColor(color, face); |
1519 | } | 1539 | } |
1520 | 1540 | ||
1541 | public void llSetContentType(LSL_Key id, LSL_Integer type) | ||
1542 | { | ||
1543 | m_LSL_Functions.llSetContentType(id, type); | ||
1544 | } | ||
1545 | |||
1521 | public void llSetDamage(double damage) | 1546 | public void llSetDamage(double damage) |
1522 | { | 1547 | { |
1523 | m_LSL_Functions.llSetDamage(damage); | 1548 | m_LSL_Functions.llSetDamage(damage); |
@@ -1533,6 +1558,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
1533 | m_LSL_Functions.llSetForceAndTorque(force, torque, local); | 1558 | m_LSL_Functions.llSetForceAndTorque(force, torque, local); |
1534 | } | 1559 | } |
1535 | 1560 | ||
1561 | public void llSetVelocity(LSL_Vector force, int local) | ||
1562 | { | ||
1563 | m_LSL_Functions.llSetVelocity(force, local); | ||
1564 | } | ||
1565 | |||
1566 | public void llSetAngularVelocity(LSL_Vector force, int local) | ||
1567 | { | ||
1568 | m_LSL_Functions.llSetAngularVelocity(force, local); | ||
1569 | } | ||
1570 | |||
1536 | public void llSetHoverHeight(double height, int water, double tau) | 1571 | public void llSetHoverHeight(double height, int water, double tau) |
1537 | { | 1572 | { |
1538 | m_LSL_Functions.llSetHoverHeight(height, water, tau); | 1573 | m_LSL_Functions.llSetHoverHeight(height, water, tau); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index afa9ae0..a60f381 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | |||
@@ -420,6 +420,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
420 | return m_OSSL_Functions.osGetScriptEngineName(); | 420 | return m_OSSL_Functions.osGetScriptEngineName(); |
421 | } | 421 | } |
422 | 422 | ||
423 | public LSL_Integer osCheckODE() | ||
424 | { | ||
425 | return m_OSSL_Functions.osCheckODE(); | ||
426 | } | ||
427 | |||
428 | public string osGetPhysicsEngineType() | ||
429 | { | ||
430 | return m_OSSL_Functions.osGetPhysicsEngineType(); | ||
431 | } | ||
432 | |||
423 | public string osGetSimulatorVersion() | 433 | public string osGetSimulatorVersion() |
424 | { | 434 | { |
425 | return m_OSSL_Functions.osGetSimulatorVersion(); | 435 | return m_OSSL_Functions.osGetSimulatorVersion(); |
@@ -500,6 +510,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
500 | return m_OSSL_Functions.osGetGridCustom(key); | 510 | return m_OSSL_Functions.osGetGridCustom(key); |
501 | } | 511 | } |
502 | 512 | ||
513 | public string osGetAvatarHomeURI(string uuid) | ||
514 | { | ||
515 | return m_OSSL_Functions.osGetAvatarHomeURI(uuid); | ||
516 | } | ||
517 | |||
503 | public LSL_String osFormatString(string str, LSL_List strings) | 518 | public LSL_String osFormatString(string str, LSL_List strings) |
504 | { | 519 | { |
505 | return m_OSSL_Functions.osFormatString(str, strings); | 520 | return m_OSSL_Functions.osFormatString(str, strings); |
@@ -537,6 +552,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
537 | return m_OSSL_Functions.osGetLinkPrimitiveParams(linknumber, rules); | 552 | return m_OSSL_Functions.osGetLinkPrimitiveParams(linknumber, rules); |
538 | } | 553 | } |
539 | 554 | ||
555 | public void osForceCreateLink(string target, int parent) | ||
556 | { | ||
557 | m_OSSL_Functions.osForceCreateLink(target, parent); | ||
558 | } | ||
559 | |||
560 | public void osForceBreakLink(int linknum) | ||
561 | { | ||
562 | m_OSSL_Functions.osForceBreakLink(linknum); | ||
563 | } | ||
564 | |||
565 | public void osForceBreakAllLinks() | ||
566 | { | ||
567 | m_OSSL_Functions.osForceBreakAllLinks(); | ||
568 | } | ||
569 | |||
540 | public LSL_Integer osIsNpc(LSL_Key npc) | 570 | public LSL_Integer osIsNpc(LSL_Key npc) |
541 | { | 571 | { |
542 | return m_OSSL_Functions.osIsNpc(npc); | 572 | return m_OSSL_Functions.osIsNpc(npc); |
@@ -708,16 +738,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
708 | } | 738 | } |
709 | private void Save() | 739 | private void Save() |
710 | { | 740 | { |
741 | /* Remove temporarily until we have a handle to the region size | ||
711 | if (Position.x > ((int)Constants.RegionSize - 1)) | 742 | if (Position.x > ((int)Constants.RegionSize - 1)) |
712 | Position.x = ((int)Constants.RegionSize - 1); | 743 | Position.x = ((int)Constants.RegionSize - 1); |
713 | if (Position.x < 0) | ||
714 | Position.x = 0; | ||
715 | if (Position.y > ((int)Constants.RegionSize - 1)) | 744 | if (Position.y > ((int)Constants.RegionSize - 1)) |
716 | Position.y = ((int)Constants.RegionSize - 1); | 745 | Position.y = ((int)Constants.RegionSize - 1); |
746 | */ | ||
747 | if (Position.z > Constants.RegionHeight) | ||
748 | Position.z = Constants.RegionHeight; | ||
749 | if (Position.x < 0) | ||
750 | Position.x = 0; | ||
717 | if (Position.y < 0) | 751 | if (Position.y < 0) |
718 | Position.y = 0; | 752 | Position.y = 0; |
719 | if (Position.z > 768) | ||
720 | Position.z = 768; | ||
721 | if (Position.z < 0) | 753 | if (Position.z < 0) |
722 | Position.z = 0; | 754 | Position.z = 0; |
723 | prim.OSSL.llSetPos(Position); | 755 | prim.OSSL.llSetPos(Position); |
@@ -843,6 +875,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
843 | } | 875 | } |
844 | } | 876 | } |
845 | 877 | ||
878 | public string osGetGender(LSL_Key rawAvatarId) | ||
879 | { | ||
880 | return m_OSSL_Functions.osGetGender(rawAvatarId); | ||
881 | } | ||
882 | |||
846 | public key osGetMapTexture() | 883 | public key osGetMapTexture() |
847 | { | 884 | { |
848 | return m_OSSL_Functions.osGetMapTexture(); | 885 | return m_OSSL_Functions.osGetMapTexture(); |
@@ -858,6 +895,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
858 | return m_OSSL_Functions.osGetRegionStats(); | 895 | return m_OSSL_Functions.osGetRegionStats(); |
859 | } | 896 | } |
860 | 897 | ||
898 | public vector osGetRegionSize() | ||
899 | { | ||
900 | return m_OSSL_Functions.osGetRegionSize(); | ||
901 | } | ||
902 | |||
861 | /// <summary> | 903 | /// <summary> |
862 | /// Returns the amount of memory in use by the Simulator Daemon. | 904 | /// Returns the amount of memory in use by the Simulator Daemon. |
863 | /// Amount in bytes - if >= 4GB, returns 4GB. (LSL is not 64-bit aware) | 905 | /// Amount in bytes - if >= 4GB, returns 4GB. (LSL is not 64-bit aware) |
@@ -892,6 +934,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
892 | { | 934 | { |
893 | m_OSSL_Functions.osCauseHealing(avatar, healing); | 935 | m_OSSL_Functions.osCauseHealing(avatar, healing); |
894 | } | 936 | } |
937 | |||
938 | public void osForceOtherSit(string avatar) | ||
939 | { | ||
940 | m_OSSL_Functions.osForceOtherSit(avatar); | ||
941 | } | ||
942 | |||
943 | public void osForceOtherSit(string avatar, string target) | ||
944 | { | ||
945 | m_OSSL_Functions.osForceOtherSit(avatar, target); | ||
946 | } | ||
895 | 947 | ||
896 | public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules) | 948 | public LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules) |
897 | { | 949 | { |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Properties/AssemblyInfo.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Properties/AssemblyInfo.cs index 573a803..b1825ac 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Properties/AssemblyInfo.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Properties/AssemblyInfo.cs | |||
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices; | |||
29 | // Build Number | 29 | // Build Number |
30 | // Revision | 30 | // Revision |
31 | // | 31 | // |
32 | [assembly: AssemblyVersion("0.7.5.*")] | 32 | [assembly: AssemblyVersion("0.7.6.*")] |
33 | [assembly: AssemblyFileVersion("1.0.0.0")] | 33 | [assembly: AssemblyFileVersion("1.0.0.0")] |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Atom.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Atom.cs deleted file mode 100644 index 27ab04e..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Atom.cs +++ /dev/null | |||
@@ -1,218 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections.Generic; | ||
33 | using System.Text; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
36 | { | ||
37 | public class Atom : IUnifiable | ||
38 | { | ||
39 | private static Dictionary<string, Atom> _atomStore = new Dictionary<string, Atom>(); | ||
40 | public readonly string _name; | ||
41 | public readonly Atom _module; | ||
42 | |||
43 | /// <summary> | ||
44 | /// You should not call this constructor, but use Atom.a instead. | ||
45 | /// </summary> | ||
46 | /// <param name="name"></param> | ||
47 | /// <param name="module"></param> | ||
48 | private Atom(string name, Atom module) | ||
49 | { | ||
50 | _name = name; | ||
51 | _module = module; | ||
52 | } | ||
53 | |||
54 | /// <summary> | ||
55 | /// Return the unique Atom object for name where module is null. You should use this to create | ||
56 | /// an Atom instead of calling the Atom constructor. | ||
57 | /// </summary> | ||
58 | /// <param name="name"></param> | ||
59 | /// <returns></returns> | ||
60 | public static Atom a(string name) | ||
61 | { | ||
62 | Atom atom; | ||
63 | if (!_atomStore.TryGetValue(name, out atom)) | ||
64 | { | ||
65 | atom = new Atom(name, null); | ||
66 | _atomStore[name] = atom; | ||
67 | } | ||
68 | return atom; | ||
69 | } | ||
70 | |||
71 | /// <summary> | ||
72 | /// Return an Atom object with the name and module. If module is null or Atom.NIL, | ||
73 | /// this behaves like Atom.a(name) and returns the unique object where the module is null. | ||
74 | /// If module is not null or Atom.NIL, this may or may not be the same object as another Atom | ||
75 | /// with the same name and module. | ||
76 | /// </summary> | ||
77 | /// <param name="name"></param> | ||
78 | /// <param name="module"></param> | ||
79 | /// <returns></returns> | ||
80 | public static Atom a(string name, Atom module) | ||
81 | { | ||
82 | if (module == null || module == Atom.NIL) | ||
83 | return a(name); | ||
84 | return new Atom(name, module); | ||
85 | } | ||
86 | |||
87 | /// <summary> | ||
88 | /// If Obj is an Atom unify its _module with Module. If the Atom's _module is null, use Atom.NIL. | ||
89 | /// </summary> | ||
90 | /// <param name="Atom"></param> | ||
91 | /// <param name="Module"></param> | ||
92 | /// <returns></returns> | ||
93 | public static IEnumerable<bool> module(object Obj, object Module) | ||
94 | { | ||
95 | Obj = YP.getValue(Obj); | ||
96 | if (Obj is Atom) | ||
97 | { | ||
98 | if (((Atom)Obj)._module == null) | ||
99 | return YP.unify(Module, Atom.NIL); | ||
100 | else | ||
101 | return YP.unify(Module, ((Atom)Obj)._module); | ||
102 | } | ||
103 | return YP.fail(); | ||
104 | } | ||
105 | |||
106 | public static readonly Atom NIL = Atom.a("[]"); | ||
107 | public static readonly Atom DOT = Atom.a("."); | ||
108 | public static readonly Atom F = Atom.a("f"); | ||
109 | public static readonly Atom SLASH = Atom.a("/"); | ||
110 | public static readonly Atom HAT = Atom.a("^"); | ||
111 | public static readonly Atom RULE = Atom.a(":-"); | ||
112 | |||
113 | public IEnumerable<bool> unify(object arg) | ||
114 | { | ||
115 | arg = YP.getValue(arg); | ||
116 | if (arg is Atom) | ||
117 | return Equals(arg) ? YP.succeed() : YP.fail(); | ||
118 | else if (arg is Variable) | ||
119 | return ((Variable)arg).unify(this); | ||
120 | else | ||
121 | return YP.fail(); | ||
122 | } | ||
123 | |||
124 | public void addUniqueVariables(List<Variable> variableSet) | ||
125 | { | ||
126 | // Atom does not contain variables. | ||
127 | } | ||
128 | |||
129 | public object makeCopy(Variable.CopyStore copyStore) | ||
130 | { | ||
131 | // Atom does not contain variables that need to be copied. | ||
132 | return this; | ||
133 | } | ||
134 | |||
135 | public bool termEqual(object term) | ||
136 | { | ||
137 | return Equals(YP.getValue(term)); | ||
138 | } | ||
139 | |||
140 | public bool ground() | ||
141 | { | ||
142 | // Atom is always ground. | ||
143 | return true; | ||
144 | } | ||
145 | |||
146 | public override bool Equals(object obj) | ||
147 | { | ||
148 | if (obj is Atom) | ||
149 | { | ||
150 | if (_module == null && ((Atom)obj)._module == null) | ||
151 | // When _declaringClass is null, we always use an identical object from _atomStore. | ||
152 | return this == obj; | ||
153 | // Otherwise, ignore _declaringClass and do a normal string compare on the _name. | ||
154 | return _name == ((Atom)obj)._name; | ||
155 | } | ||
156 | return false; | ||
157 | } | ||
158 | |||
159 | public override string ToString() | ||
160 | { | ||
161 | return _name; | ||
162 | } | ||
163 | |||
164 | public override int GetHashCode() | ||
165 | { | ||
166 | // Debug: need to check _declaringClass. | ||
167 | return _name.GetHashCode(); | ||
168 | } | ||
169 | |||
170 | public string toQuotedString() | ||
171 | { | ||
172 | if (_name.Length == 0) | ||
173 | return "''"; | ||
174 | else if (this == Atom.NIL) | ||
175 | return "[]"; | ||
176 | |||
177 | StringBuilder result = new StringBuilder(_name.Length); | ||
178 | bool useQuotes = false; | ||
179 | foreach (char c in _name) | ||
180 | { | ||
181 | int cInt = (int)c; | ||
182 | if (c == '\'') | ||
183 | { | ||
184 | result.Append("''"); | ||
185 | useQuotes = true; | ||
186 | } | ||
187 | else if (c == '_' || cInt >= (int)'a' && cInt <= (int)'z' || | ||
188 | cInt >= (int)'A' && cInt <= (int)'Z' || cInt >= (int)'0' && cInt <= (int)'9') | ||
189 | result.Append(c); | ||
190 | else | ||
191 | { | ||
192 | // Debug: Need to handle non-printable chars. | ||
193 | result.Append(c); | ||
194 | useQuotes = true; | ||
195 | } | ||
196 | } | ||
197 | |||
198 | if (!useQuotes && (int)_name[0] >= (int)'a' && (int)_name[0] <= (int)'z') | ||
199 | return result.ToString(); | ||
200 | else | ||
201 | { | ||
202 | // Surround in single quotes. | ||
203 | result.Append('\''); | ||
204 | return "'" + result; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | /// <summary> | ||
209 | /// Return true if _name is lexicographically less than atom._name. | ||
210 | /// </summary> | ||
211 | /// <param name="atom"></param> | ||
212 | /// <returns></returns> | ||
213 | public bool lessThan(Atom atom) | ||
214 | { | ||
215 | return _name.CompareTo(atom._name) < 0; | ||
216 | } | ||
217 | } | ||
218 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/BagofAnswers.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/BagofAnswers.cs deleted file mode 100644 index bbf1a5b..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/BagofAnswers.cs +++ /dev/null | |||
@@ -1,239 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// A BagofAnswers holds answers for bagof and setof. | ||
39 | /// </summary> | ||
40 | public class BagofAnswers | ||
41 | { | ||
42 | private object _template; | ||
43 | private Variable[] _freeVariables; | ||
44 | private Dictionary<object[], List<object>> _bagForFreeVariables; | ||
45 | private List<object> _findallBagArray; | ||
46 | private static TermArrayEqualityComparer _termArrayEqualityComparer = | ||
47 | new TermArrayEqualityComparer(); | ||
48 | |||
49 | /// <summary> | ||
50 | /// To get the free variables, split off any existential qualifiers from Goal such as the X in | ||
51 | /// "X ^ f(Y)", get the set of unbound variables in Goal that are not qualifiers, then remove | ||
52 | /// the unbound variables that are qualifiers as well as the unbound variables in Template. | ||
53 | /// </summary> | ||
54 | /// <param name="Template"></param> | ||
55 | /// <param name="Goal"></param> | ||
56 | public BagofAnswers(object Template, object Goal) | ||
57 | { | ||
58 | _template = Template; | ||
59 | |||
60 | // First get the set of variables that are not free variables. | ||
61 | List<Variable> variableSet = new List<Variable>(); | ||
62 | YP.addUniqueVariables(Template, variableSet); | ||
63 | object UnqualifiedGoal = YP.getValue(Goal); | ||
64 | while (UnqualifiedGoal is Functor2 && ((Functor2)UnqualifiedGoal)._name == Atom.HAT) | ||
65 | { | ||
66 | YP.addUniqueVariables(((Functor2)UnqualifiedGoal)._arg1, variableSet); | ||
67 | UnqualifiedGoal = YP.getValue(((Functor2)UnqualifiedGoal)._arg2); | ||
68 | } | ||
69 | |||
70 | // Remember how many non-free variables there are so we can find the unique free variables | ||
71 | // that are added. | ||
72 | int nNonFreeVariables = variableSet.Count; | ||
73 | YP.addUniqueVariables(UnqualifiedGoal, variableSet); | ||
74 | int nFreeVariables = variableSet.Count - nNonFreeVariables; | ||
75 | if (nFreeVariables == 0) | ||
76 | { | ||
77 | // There were no free variables added, so we won't waste time with _bagForFreeVariables. | ||
78 | _freeVariables = null; | ||
79 | _findallBagArray = new List<object>(); | ||
80 | } | ||
81 | else | ||
82 | { | ||
83 | // Copy the free variables. | ||
84 | _freeVariables = new Variable[nFreeVariables]; | ||
85 | for (int i = 0; i < nFreeVariables; ++i) | ||
86 | _freeVariables[i] = variableSet[i + nNonFreeVariables]; | ||
87 | |||
88 | _bagForFreeVariables = new Dictionary<object[], List<object>>(_termArrayEqualityComparer); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | public void add() | ||
93 | { | ||
94 | if (_freeVariables == null) | ||
95 | // The goal has bound the values in _template but we don't bother with _freeVariables. | ||
96 | _findallBagArray.Add(YP.makeCopy(_template, new Variable.CopyStore())); | ||
97 | else | ||
98 | { | ||
99 | // The goal has bound the values in _template and _freeVariables. | ||
100 | // Find the entry for this set of _freeVariables values. | ||
101 | object[] freeVariableValues = new object[_freeVariables.Length]; | ||
102 | for (int i = 0; i < _freeVariables.Length; ++i) | ||
103 | freeVariableValues[i] = YP.getValue(_freeVariables[i]); | ||
104 | List<object> bagArray; | ||
105 | if (!_bagForFreeVariables.TryGetValue(freeVariableValues, out bagArray)) | ||
106 | { | ||
107 | bagArray = new List<object>(); | ||
108 | _bagForFreeVariables[freeVariableValues] = bagArray; | ||
109 | } | ||
110 | |||
111 | // Now copy the template and add to the bag for the freeVariables values. | ||
112 | bagArray.Add(YP.makeCopy(_template, new Variable.CopyStore())); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | // disable warning on l1, don't see how we can | ||
117 | // code this differently | ||
118 | #pragma warning disable 0168, 0219 | ||
119 | |||
120 | /// <summary> | ||
121 | /// For each result, unify the _freeVariables and unify bagArrayVariable with the associated bag. | ||
122 | /// </summary> | ||
123 | /// <param name="bagArrayVariable">this is unified with the List<object> of matches for template that | ||
124 | /// corresponds to the bindings for freeVariables. Be very careful: this does not unify with a Prolog | ||
125 | /// list.</param> | ||
126 | /// <returns></returns> | ||
127 | public IEnumerable<bool> resultArray(Variable bagArrayVariable) | ||
128 | { | ||
129 | if (_freeVariables == null) | ||
130 | { | ||
131 | // No unbound free variables, so we only filled one bag. If empty, bagof fails. | ||
132 | if (_findallBagArray.Count > 0) | ||
133 | { | ||
134 | foreach (bool l1 in bagArrayVariable.unify(_findallBagArray)) | ||
135 | yield return false; | ||
136 | } | ||
137 | } | ||
138 | else | ||
139 | { | ||
140 | foreach (KeyValuePair<object[], List<object>> valuesAndBag in _bagForFreeVariables) | ||
141 | { | ||
142 | foreach (bool l1 in YP.unifyArrays(_freeVariables, valuesAndBag.Key)) | ||
143 | { | ||
144 | foreach (bool l2 in bagArrayVariable.unify(valuesAndBag.Value)) | ||
145 | yield return false; | ||
146 | } | ||
147 | // Debug: Should we free memory of the answers already returned? | ||
148 | } | ||
149 | } | ||
150 | } | ||
151 | |||
152 | /// <summary> | ||
153 | /// For each result, unify the _freeVariables and unify Bag with the associated bag. | ||
154 | /// </summary> | ||
155 | /// <param name="Bag"></param> | ||
156 | /// <returns></returns> | ||
157 | public IEnumerable<bool> result(object Bag) | ||
158 | { | ||
159 | Variable bagArrayVariable = new Variable(); | ||
160 | foreach (bool l1 in resultArray(bagArrayVariable)) | ||
161 | { | ||
162 | foreach (bool l2 in YP.unify(Bag, ListPair.make((List<object>)bagArrayVariable.getValue()))) | ||
163 | yield return false; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | /// <summary> | ||
168 | /// For each result, unify the _freeVariables and unify Bag with the associated bag which is sorted | ||
169 | /// with duplicates removed, as in setof. | ||
170 | /// </summary> | ||
171 | /// <param name="Bag"></param> | ||
172 | /// <returns></returns> | ||
173 | public IEnumerable<bool> resultSet(object Bag) | ||
174 | { | ||
175 | Variable bagArrayVariable = new Variable(); | ||
176 | foreach (bool l1 in resultArray(bagArrayVariable)) | ||
177 | { | ||
178 | List<object> bagArray = (List<object>)bagArrayVariable.getValue(); | ||
179 | YP.sortArray(bagArray); | ||
180 | foreach (bool l2 in YP.unify(Bag, ListPair.makeWithoutRepeatedTerms(bagArray))) | ||
181 | yield return false; | ||
182 | } | ||
183 | } | ||
184 | |||
185 | public static IEnumerable<bool> bagofArray | ||
186 | (object Template, object Goal, IEnumerable<bool> goalIterator, Variable bagArrayVariable) | ||
187 | { | ||
188 | BagofAnswers bagOfAnswers = new BagofAnswers(Template, Goal); | ||
189 | foreach (bool l1 in goalIterator) | ||
190 | bagOfAnswers.add(); | ||
191 | return bagOfAnswers.resultArray(bagArrayVariable); | ||
192 | } | ||
193 | |||
194 | public static IEnumerable<bool> bagof | ||
195 | (object Template, object Goal, IEnumerable<bool> goalIterator, object Bag) | ||
196 | { | ||
197 | BagofAnswers bagOfAnswers = new BagofAnswers(Template, Goal); | ||
198 | foreach (bool l1 in goalIterator) | ||
199 | bagOfAnswers.add(); | ||
200 | return bagOfAnswers.result(Bag); | ||
201 | } | ||
202 | |||
203 | public static IEnumerable<bool> setof | ||
204 | (object Template, object Goal, IEnumerable<bool> goalIterator, object Bag) | ||
205 | { | ||
206 | BagofAnswers bagOfAnswers = new BagofAnswers(Template, Goal); | ||
207 | foreach (bool l1 in goalIterator) | ||
208 | bagOfAnswers.add(); | ||
209 | return bagOfAnswers.resultSet(Bag); | ||
210 | } | ||
211 | #pragma warning restore 0168, 0219 | ||
212 | |||
213 | /// <summary> | ||
214 | /// A TermArrayEqualityComparer implements IEqualityComparer to compare two object arrays using YP.termEqual. | ||
215 | /// </summary> | ||
216 | private class TermArrayEqualityComparer : IEqualityComparer<object[]> | ||
217 | { | ||
218 | public bool Equals(object[] array1, object[] array2) | ||
219 | { | ||
220 | if (array1.Length != array2.Length) | ||
221 | return false; | ||
222 | for (int i = 0; i < array1.Length; ++i) | ||
223 | { | ||
224 | if (!YP.termEqual(array1[i], array2[i])) | ||
225 | return false; | ||
226 | } | ||
227 | return true; | ||
228 | } | ||
229 | |||
230 | public int GetHashCode(object[] array) | ||
231 | { | ||
232 | int hashCode = 0; | ||
233 | for (int i = 0; i < array.Length; ++i) | ||
234 | hashCode ^= array[i].GetHashCode(); | ||
235 | return hashCode; | ||
236 | } | ||
237 | } | ||
238 | } | ||
239 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/FindallAnswers.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/FindallAnswers.cs deleted file mode 100644 index fb9569e..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/FindallAnswers.cs +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// A FindallAnswers holds answers for findall. | ||
39 | /// </summary> | ||
40 | public class FindallAnswers | ||
41 | { | ||
42 | private object _template; | ||
43 | private List<object> _bagArray; | ||
44 | |||
45 | public FindallAnswers(object Template) | ||
46 | { | ||
47 | _template = Template; | ||
48 | _bagArray = new List<object>(); | ||
49 | } | ||
50 | |||
51 | public void add() | ||
52 | { | ||
53 | _bagArray.Add(YP.makeCopy(_template, new Variable.CopyStore())); | ||
54 | } | ||
55 | |||
56 | public List<object> resultArray() | ||
57 | { | ||
58 | return _bagArray; | ||
59 | } | ||
60 | |||
61 | /// <summary> | ||
62 | /// Unify Bag with the result. This frees the internal answers, so you can only call this once. | ||
63 | /// </summary> | ||
64 | /// <param name="Bag"></param> | ||
65 | /// <returns></returns> | ||
66 | public IEnumerable<bool> result(object Bag) | ||
67 | { | ||
68 | object result = ListPair.make(_bagArray); | ||
69 | // Try to free the memory. | ||
70 | _bagArray = null; | ||
71 | return YP.unify(Bag, result); | ||
72 | } | ||
73 | |||
74 | // disable warning on l1, don't see how we can | ||
75 | // code this differently | ||
76 | #pragma warning disable 0168, 0219 | ||
77 | |||
78 | /// <summary> | ||
79 | /// This is a simplified findall when the goal is a single call. | ||
80 | /// </summary> | ||
81 | /// <param name="Template"></param> | ||
82 | /// <param name="goal"></param> | ||
83 | /// <param name="Bag"></param> | ||
84 | /// <returns></returns> | ||
85 | public static IEnumerable<bool> findall(object Template, IEnumerable<bool> goal, object Bag) | ||
86 | { | ||
87 | FindallAnswers findallAnswers = new FindallAnswers(Template); | ||
88 | foreach (bool l1 in goal) | ||
89 | findallAnswers.add(); | ||
90 | return findallAnswers.result(Bag); | ||
91 | } | ||
92 | |||
93 | /// <summary> | ||
94 | /// Like findall, except return an array of the results. | ||
95 | /// </summary> | ||
96 | /// <param name="template"></param> | ||
97 | /// <param name="goal"></param> | ||
98 | /// <returns></returns> | ||
99 | public static List<object> findallArray(object Template, IEnumerable<bool> goal) | ||
100 | { | ||
101 | FindallAnswers findallAnswers = new FindallAnswers(Template); | ||
102 | foreach (bool l1 in goal) | ||
103 | findallAnswers.add(); | ||
104 | return findallAnswers.resultArray(); | ||
105 | } | ||
106 | #pragma warning restore 0168, 0219 | ||
107 | } | ||
108 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor.cs deleted file mode 100644 index 4d65f5b..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor.cs +++ /dev/null | |||
@@ -1,196 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections.Generic; | ||
33 | |||
34 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
35 | { | ||
36 | public class Functor : IUnifiable | ||
37 | { | ||
38 | public readonly Atom _name; | ||
39 | public readonly object[] _args; | ||
40 | |||
41 | public Functor(Atom name, object[] args) | ||
42 | { | ||
43 | if (args.Length <= 3) | ||
44 | { | ||
45 | if (args.Length == 0) | ||
46 | throw new Exception("For arity 0 functor, just use name as an Atom"); | ||
47 | else if (args.Length == 1) | ||
48 | throw new Exception("For arity 1 functor, use Functor1"); | ||
49 | else if (args.Length == 2) | ||
50 | throw new Exception("For arity 2 functor, use Functor2"); | ||
51 | else if (args.Length == 3) | ||
52 | throw new Exception("For arity 3 functor, use Functor3"); | ||
53 | else | ||
54 | // (This shouldn't happen, but include it for completeness. | ||
55 | throw new Exception("Cannot create a Functor of arity " + args.Length); | ||
56 | } | ||
57 | |||
58 | _name = name; | ||
59 | _args = args; | ||
60 | } | ||
61 | |||
62 | public Functor(string name, object[] args) | ||
63 | : this(Atom.a(name), args) | ||
64 | { | ||
65 | } | ||
66 | |||
67 | /// <summary> | ||
68 | /// Return an Atom, Functor1, Functor2, Functor3 or Functor depending on the | ||
69 | /// length of args. | ||
70 | /// Note that this is different than the Functor constructor which requires | ||
71 | /// the length of args to be greater than 3. | ||
72 | /// </summary> | ||
73 | /// <param name="name"></param> | ||
74 | /// <param name="args"></param> | ||
75 | /// <returns></returns> | ||
76 | public static object make(Atom name, object[] args) | ||
77 | { | ||
78 | if (args.Length <= 0) | ||
79 | return name; | ||
80 | else if (args.Length == 1) | ||
81 | return new Functor1(name, args[0]); | ||
82 | else if (args.Length == 2) | ||
83 | return new Functor2(name, args[0], args[1]); | ||
84 | else if (args.Length == 3) | ||
85 | return new Functor3(name, args[0], args[1], args[2]); | ||
86 | else | ||
87 | return new Functor(name, args); | ||
88 | } | ||
89 | |||
90 | /// <summary> | ||
91 | /// Call the main make, first converting name to an Atom. | ||
92 | /// </summary> | ||
93 | /// <param name="name"></param> | ||
94 | /// <param name="args"></param> | ||
95 | /// <returns></returns> | ||
96 | public static object make(string name, object[] args) | ||
97 | { | ||
98 | return make(Atom.a(name), args); | ||
99 | } | ||
100 | |||
101 | /// <summary> | ||
102 | /// If arg is another Functor, then succeed (yield once) if this and arg have the | ||
103 | /// same name and all functor args unify, otherwise fail (don't yield). | ||
104 | /// If arg is a Variable, then call its unify to unify with this. | ||
105 | /// Otherwise fail (don't yield). | ||
106 | /// </summary> | ||
107 | /// <param name="arg"></param> | ||
108 | /// <returns></returns> | ||
109 | public IEnumerable<bool> unify(object arg) | ||
110 | { | ||
111 | arg = YP.getValue(arg); | ||
112 | if (arg is Functor) | ||
113 | { | ||
114 | Functor argFunctor = (Functor)arg; | ||
115 | if (_name.Equals(argFunctor._name)) | ||
116 | return YP.unifyArrays(_args, argFunctor._args); | ||
117 | else | ||
118 | return YP.fail(); | ||
119 | } | ||
120 | else if (arg is Variable) | ||
121 | return ((Variable)arg).unify(this); | ||
122 | else | ||
123 | return YP.fail(); | ||
124 | } | ||
125 | |||
126 | public override string ToString() | ||
127 | { | ||
128 | string result = _name + "(" + YP.getValue(_args[0]); | ||
129 | for (int i = 1; i < _args.Length; ++i) | ||
130 | result += ", " + YP.getValue(_args[i]); | ||
131 | result += ")"; | ||
132 | return result; | ||
133 | } | ||
134 | |||
135 | public bool termEqual(object term) | ||
136 | { | ||
137 | term = YP.getValue(term); | ||
138 | if (term is Functor) | ||
139 | { | ||
140 | Functor termFunctor = (Functor)term; | ||
141 | if (_name.Equals(termFunctor._name) && _args.Length == termFunctor._args.Length) | ||
142 | { | ||
143 | for (int i = 0; i < _args.Length; ++i) | ||
144 | { | ||
145 | if (!YP.termEqual(_args[i], termFunctor._args[i])) | ||
146 | return false; | ||
147 | } | ||
148 | return true; | ||
149 | } | ||
150 | } | ||
151 | return false; | ||
152 | } | ||
153 | |||
154 | public bool lessThan(Functor functor) | ||
155 | { | ||
156 | // Do the equal check first since it is faster. | ||
157 | if (!_name.Equals(functor._name)) | ||
158 | return _name.lessThan(functor._name); | ||
159 | |||
160 | if (_args.Length != functor._args.Length) | ||
161 | return _args.Length < functor._args.Length; | ||
162 | |||
163 | for (int i = 0; i < _args.Length; ++i) | ||
164 | { | ||
165 | if (!YP.termEqual(_args[i], functor._args[i])) | ||
166 | return YP.termLessThan(_args[i], functor._args[i]); | ||
167 | } | ||
168 | |||
169 | return false; | ||
170 | } | ||
171 | |||
172 | public bool ground() | ||
173 | { | ||
174 | for (int i = 0; i < _args.Length; ++i) | ||
175 | { | ||
176 | if (!YP.ground(_args[i])) | ||
177 | return false; | ||
178 | } | ||
179 | return true; | ||
180 | } | ||
181 | |||
182 | public void addUniqueVariables(List<Variable> variableSet) | ||
183 | { | ||
184 | for (int i = 0; i < _args.Length; ++i) | ||
185 | YP.addUniqueVariables(_args[i], variableSet); | ||
186 | } | ||
187 | |||
188 | public object makeCopy(Variable.CopyStore copyStore) | ||
189 | { | ||
190 | object[] argsCopy = new object[_args.Length]; | ||
191 | for (int i = 0; i < _args.Length; ++i) | ||
192 | argsCopy[i] = YP.makeCopy(_args[i], copyStore); | ||
193 | return new Functor(_name, argsCopy); | ||
194 | } | ||
195 | } | ||
196 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor1.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor1.cs deleted file mode 100644 index 80d98b1..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor1.cs +++ /dev/null | |||
@@ -1,124 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections.Generic; | ||
33 | |||
34 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
35 | { | ||
36 | public class Functor1 : IUnifiable | ||
37 | { | ||
38 | public readonly Atom _name; | ||
39 | public readonly object _arg1; | ||
40 | |||
41 | public Functor1(Atom name, object arg1) | ||
42 | { | ||
43 | _name = name; | ||
44 | _arg1 = arg1; | ||
45 | } | ||
46 | |||
47 | public Functor1(string name, object arg1) | ||
48 | : this(Atom.a(name), arg1) | ||
49 | { | ||
50 | } | ||
51 | |||
52 | // disable warning on l1, don't see how we can | ||
53 | // code this differently | ||
54 | #pragma warning disable 0168, 0219 | ||
55 | /// <summary> | ||
56 | /// If arg is another Functor1, then succeed (yield once) if this and arg have the | ||
57 | /// same name and the functor args unify, otherwise fail (don't yield). | ||
58 | /// If arg is a Variable, then call its unify to unify with this. | ||
59 | /// Otherwise fail (don't yield). | ||
60 | /// </summary> | ||
61 | /// <param name="arg"></param> | ||
62 | /// <returns></returns> | ||
63 | public IEnumerable<bool> unify(object arg) | ||
64 | { | ||
65 | arg = YP.getValue(arg); | ||
66 | if (arg is Functor1) | ||
67 | { | ||
68 | Functor1 argFunctor = (Functor1)arg; | ||
69 | if (_name.Equals(argFunctor._name)) | ||
70 | { | ||
71 | foreach (bool l1 in YP.unify(_arg1, argFunctor._arg1)) | ||
72 | yield return false; | ||
73 | } | ||
74 | } | ||
75 | else if (arg is Variable) | ||
76 | { | ||
77 | foreach (bool l1 in ((Variable)arg).unify(this)) | ||
78 | yield return false; | ||
79 | } | ||
80 | } | ||
81 | #pragma warning restore 0168, 0219 | ||
82 | |||
83 | |||
84 | public override string ToString() | ||
85 | { | ||
86 | return _name + "(" + YP.getValue(_arg1) + ")"; | ||
87 | } | ||
88 | |||
89 | public bool termEqual(object term) | ||
90 | { | ||
91 | term = YP.getValue(term); | ||
92 | if (term is Functor1) | ||
93 | { | ||
94 | Functor1 termFunctor = (Functor1)term; | ||
95 | return _name.Equals(termFunctor._name) && YP.termEqual(_arg1, termFunctor._arg1); | ||
96 | } | ||
97 | return false; | ||
98 | } | ||
99 | |||
100 | public bool lessThan(Functor1 functor) | ||
101 | { | ||
102 | // Do the equal check first since it is faster. | ||
103 | if (!_name.Equals(functor._name)) | ||
104 | return _name.lessThan(functor._name); | ||
105 | |||
106 | return YP.termLessThan(_arg1, functor._arg1); | ||
107 | } | ||
108 | |||
109 | public bool ground() | ||
110 | { | ||
111 | return YP.ground(_arg1); | ||
112 | } | ||
113 | |||
114 | public void addUniqueVariables(List<Variable> variableSet) | ||
115 | { | ||
116 | YP.addUniqueVariables(_arg1, variableSet); | ||
117 | } | ||
118 | |||
119 | public object makeCopy(Variable.CopyStore copyStore) | ||
120 | { | ||
121 | return new Functor1(_name, YP.makeCopy(_arg1, copyStore)); | ||
122 | } | ||
123 | } | ||
124 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor2.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor2.cs deleted file mode 100644 index 4c501d6..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor2.cs +++ /dev/null | |||
@@ -1,163 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections.Generic; | ||
33 | |||
34 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
35 | { | ||
36 | public class Functor2 : IUnifiable | ||
37 | { | ||
38 | public readonly Atom _name; | ||
39 | public readonly object _arg1; | ||
40 | public readonly object _arg2; | ||
41 | |||
42 | public Functor2(Atom name, object arg1, object arg2) | ||
43 | { | ||
44 | _name = name; | ||
45 | _arg1 = arg1; | ||
46 | _arg2 = arg2; | ||
47 | } | ||
48 | |||
49 | public Functor2(string name, object arg1, object arg2) | ||
50 | : this(Atom.a(name), arg1, arg2) | ||
51 | { | ||
52 | } | ||
53 | |||
54 | // disable warning on l1, don't see how we can | ||
55 | // code this differently | ||
56 | #pragma warning disable 0168, 0219 | ||
57 | /// If arg is another Functor2, then succeed (yield once) if this and arg have the | ||
58 | /// same name and all functor args unify, otherwise fail (don't yield). | ||
59 | /// If arg is a Variable, then call its unify to unify with this. | ||
60 | /// Otherwise fail (don't yield). | ||
61 | public IEnumerable<bool> unify(object arg) | ||
62 | { | ||
63 | arg = YP.getValue(arg); | ||
64 | if (arg is Functor2) | ||
65 | { | ||
66 | Functor2 argFunctor = (Functor2)arg; | ||
67 | if (_name.Equals(argFunctor._name)) | ||
68 | { | ||
69 | foreach (bool l1 in YP.unify(_arg1, argFunctor._arg1)) | ||
70 | { | ||
71 | foreach (bool l2 in YP.unify(_arg2, argFunctor._arg2)) | ||
72 | yield return false; | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | else if (arg is Variable) | ||
77 | { | ||
78 | foreach (bool l1 in ((Variable)arg).unify(this)) | ||
79 | yield return false; | ||
80 | } | ||
81 | } | ||
82 | #pragma warning restore 0168, 0219 | ||
83 | |||
84 | |||
85 | public override string ToString() | ||
86 | { | ||
87 | if (_name == Atom.DOT) | ||
88 | return listPairToString(this); | ||
89 | else | ||
90 | return _name + "(" + YP.getValue(_arg1) + ", " + YP.getValue(_arg2) + ")"; | ||
91 | } | ||
92 | |||
93 | public bool termEqual(object term) | ||
94 | { | ||
95 | term = YP.getValue(term); | ||
96 | if (term is Functor2) | ||
97 | { | ||
98 | Functor2 termFunctor = (Functor2)term; | ||
99 | return _name.Equals(termFunctor._name) && YP.termEqual(_arg1, termFunctor._arg1) | ||
100 | && YP.termEqual(_arg2, termFunctor._arg2); | ||
101 | } | ||
102 | return false; | ||
103 | } | ||
104 | |||
105 | public bool lessThan(Functor2 functor) | ||
106 | { | ||
107 | // Do the equal check first since it is faster. | ||
108 | if (!_name.Equals(functor._name)) | ||
109 | return _name.lessThan(functor._name); | ||
110 | |||
111 | if (!YP.termEqual(_arg1, functor._arg1)) | ||
112 | return YP.termLessThan(_arg1, functor._arg1); | ||
113 | |||
114 | return YP.termLessThan(_arg2, functor._arg2); | ||
115 | } | ||
116 | |||
117 | public bool ground() | ||
118 | { | ||
119 | return YP.ground(_arg1) && YP.ground(_arg2); | ||
120 | } | ||
121 | |||
122 | public void addUniqueVariables(List<Variable> variableSet) | ||
123 | { | ||
124 | YP.addUniqueVariables(_arg1, variableSet); | ||
125 | YP.addUniqueVariables(_arg2, variableSet); | ||
126 | } | ||
127 | |||
128 | public object makeCopy(Variable.CopyStore copyStore) | ||
129 | { | ||
130 | return new Functor2(_name, YP.makeCopy(_arg1, copyStore), | ||
131 | YP.makeCopy(_arg2, copyStore)); | ||
132 | } | ||
133 | |||
134 | private static string listPairToString(Functor2 listPair) | ||
135 | { | ||
136 | string result = "["; | ||
137 | while (true) | ||
138 | { | ||
139 | object head = YP.getValue(listPair._arg1); | ||
140 | object tail = YP.getValue(listPair._arg2); | ||
141 | if (tail == (object)Atom.NIL) | ||
142 | { | ||
143 | result += head; | ||
144 | break; | ||
145 | } | ||
146 | else if (tail is Functor2 && ((Functor2)tail)._name == Atom.DOT) | ||
147 | { | ||
148 | result += head + ", "; | ||
149 | listPair = (Functor2)tail; | ||
150 | // Loop again. | ||
151 | } | ||
152 | else | ||
153 | { | ||
154 | // The list is not terminated with NIL. | ||
155 | result += head + "|" + tail; | ||
156 | break; | ||
157 | } | ||
158 | } | ||
159 | result += "]"; | ||
160 | return result; | ||
161 | } | ||
162 | } | ||
163 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor3.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor3.cs deleted file mode 100644 index 94e39c4..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Functor3.cs +++ /dev/null | |||
@@ -1,141 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections.Generic; | ||
33 | |||
34 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
35 | { | ||
36 | public class Functor3 : IUnifiable | ||
37 | { | ||
38 | public readonly Atom _name; | ||
39 | public readonly object _arg1; | ||
40 | public readonly object _arg2; | ||
41 | public readonly object _arg3; | ||
42 | |||
43 | public Functor3(Atom name, object arg1, object arg2, object arg3) | ||
44 | { | ||
45 | _name = name; | ||
46 | _arg1 = arg1; | ||
47 | _arg2 = arg2; | ||
48 | _arg3 = arg3; | ||
49 | } | ||
50 | |||
51 | public Functor3(string name, object arg1, object arg2, object arg3) | ||
52 | : this(Atom.a(name), arg1, arg2, arg3) | ||
53 | { | ||
54 | } | ||
55 | |||
56 | // disable warning on l1, don't see how we can | ||
57 | // code this differently | ||
58 | #pragma warning disable 0168, 0219 | ||
59 | /// If arg is another Functor3, then succeed (yield once) if this and arg have the | ||
60 | /// same name and all functor args unify, otherwise fail (don't yield). | ||
61 | /// If arg is a Variable, then call its unify to unify with this. | ||
62 | /// Otherwise fail (don't yield). | ||
63 | public IEnumerable<bool> unify(object arg) | ||
64 | { | ||
65 | arg = YP.getValue(arg); | ||
66 | if (arg is Functor3) | ||
67 | { | ||
68 | Functor3 argFunctor = (Functor3)arg; | ||
69 | if (_name.Equals(argFunctor._name)) | ||
70 | { | ||
71 | foreach (bool l1 in YP.unify(_arg1, argFunctor._arg1)) | ||
72 | { | ||
73 | foreach (bool l2 in YP.unify(_arg2, argFunctor._arg2)) | ||
74 | { | ||
75 | foreach (bool l3 in YP.unify(_arg3, argFunctor._arg3)) | ||
76 | yield return false; | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | } | ||
81 | else if (arg is Variable) | ||
82 | { | ||
83 | foreach (bool l1 in ((Variable)arg).unify(this)) | ||
84 | yield return false; | ||
85 | } | ||
86 | } | ||
87 | #pragma warning restore 0168, 0219 | ||
88 | |||
89 | public override string ToString() | ||
90 | { | ||
91 | return _name + "(" + YP.getValue(_arg1) + ", " + YP.getValue(_arg2) + ", " + | ||
92 | YP.getValue(_arg3) + ")"; | ||
93 | } | ||
94 | |||
95 | public bool termEqual(object term) | ||
96 | { | ||
97 | term = YP.getValue(term); | ||
98 | if (term is Functor3) | ||
99 | { | ||
100 | Functor3 termFunctor = (Functor3)term; | ||
101 | return _name.Equals(termFunctor._name) && YP.termEqual(_arg1, termFunctor._arg1) | ||
102 | && YP.termEqual(_arg2, termFunctor._arg2) | ||
103 | && YP.termEqual(_arg3, termFunctor._arg3); | ||
104 | } | ||
105 | return false; | ||
106 | } | ||
107 | |||
108 | public bool lessThan(Functor3 functor) | ||
109 | { | ||
110 | // Do the equal check first since it is faster. | ||
111 | if (!_name.Equals(functor._name)) | ||
112 | return _name.lessThan(functor._name); | ||
113 | |||
114 | if (!YP.termEqual(_arg1, functor._arg1)) | ||
115 | return YP.termLessThan(_arg1, functor._arg1); | ||
116 | |||
117 | if (!YP.termEqual(_arg2, functor._arg2)) | ||
118 | return YP.termLessThan(_arg2, functor._arg2); | ||
119 | |||
120 | return YP.termLessThan(_arg3, functor._arg3); | ||
121 | } | ||
122 | |||
123 | public bool ground() | ||
124 | { | ||
125 | return YP.ground(_arg1) && YP.ground(_arg2) && YP.ground(_arg3); | ||
126 | } | ||
127 | |||
128 | public void addUniqueVariables(List<Variable> variableSet) | ||
129 | { | ||
130 | YP.addUniqueVariables(_arg1, variableSet); | ||
131 | YP.addUniqueVariables(_arg2, variableSet); | ||
132 | YP.addUniqueVariables(_arg3, variableSet); | ||
133 | } | ||
134 | |||
135 | public object makeCopy(Variable.CopyStore copyStore) | ||
136 | { | ||
137 | return new Functor3(_name, YP.makeCopy(_arg1, copyStore), | ||
138 | YP.makeCopy(_arg2, copyStore), YP.makeCopy(_arg3, copyStore)); | ||
139 | } | ||
140 | } | ||
141 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/IndexedAnswers.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/IndexedAnswers.cs deleted file mode 100644 index 09a9a08..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/IndexedAnswers.cs +++ /dev/null | |||
@@ -1,385 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// An IndexedAnswers holds answers to a query based on the values of index arguments. | ||
39 | /// </summary> | ||
40 | public class IndexedAnswers : YP.IClause | ||
41 | { | ||
42 | private int _arity; | ||
43 | // addAnswer adds the answer here and indexes it later. | ||
44 | private List<object[]> _allAnswers = new List<object[]>(); | ||
45 | // The key has the arity of answers with non-null values for each indexed arg. The value | ||
46 | // is a list of the matching answers. The signature is implicit in the pattern on non-null index args. | ||
47 | private Dictionary<HashedList, List<object[]>> _indexedAnswers = | ||
48 | new Dictionary<HashedList, List<object[]>>(); | ||
49 | // Keeps track of whether we have started adding entries to _indexedAnswers for the signature. | ||
50 | private Dictionary<int, object> _gotAnswersForSignature = new Dictionary<int, object>(); | ||
51 | private const int MAX_INDEX_ARGS = 31; | ||
52 | |||
53 | public IndexedAnswers(int arity) | ||
54 | { | ||
55 | _arity = arity; | ||
56 | } | ||
57 | |||
58 | /// <summary> | ||
59 | /// Append the answer to the list and update the indexes, if any. | ||
60 | /// Elements of answer must be ground, since arguments with unbound variables make this | ||
61 | /// into a dynamic rule which we don't index. | ||
62 | /// </summary> | ||
63 | /// <param name="answer"></param> | ||
64 | public void addAnswer(object[] answer) | ||
65 | { | ||
66 | addOrPrependAnswer(answer, false); | ||
67 | } | ||
68 | |||
69 | /// <summary> | ||
70 | /// Prepend the answer to the list and clear the indexes so that they must be re-computed | ||
71 | /// on the next call to match. (Only addAnswer will maintain the indexes while adding answers.) | ||
72 | /// Elements of answer must be ground, since arguments with unbound variables make this | ||
73 | /// into a dynamic rule which we don't index. | ||
74 | /// </summary> | ||
75 | /// <param name="answer"></param> | ||
76 | public void prependAnswer(object[] answer) | ||
77 | { | ||
78 | addOrPrependAnswer(answer, true); | ||
79 | } | ||
80 | |||
81 | /// <summary> | ||
82 | /// Do the work of addAnswer or prependAnswer. | ||
83 | /// </summary> | ||
84 | /// <param name="answer"></param> | ||
85 | private void addOrPrependAnswer(object[] answer, bool prepend) | ||
86 | { | ||
87 | if (answer.Length != _arity) | ||
88 | return; | ||
89 | |||
90 | // Store a copy of the answer array. | ||
91 | object[] answerCopy = new object[answer.Length]; | ||
92 | Variable.CopyStore copyStore = new Variable.CopyStore(); | ||
93 | for (int i = 0; i < answer.Length; ++i) | ||
94 | answerCopy[i] = YP.makeCopy(answer[i], copyStore); | ||
95 | if (copyStore.getNUniqueVariables() > 0) | ||
96 | throw new InvalidOperationException | ||
97 | ("Elements of answer must be ground, but found " + copyStore.getNUniqueVariables() + | ||
98 | " unbound variables"); | ||
99 | |||
100 | if (prepend) | ||
101 | { | ||
102 | _allAnswers.Insert(0, answerCopy); | ||
103 | clearIndexes(); | ||
104 | } | ||
105 | else | ||
106 | { | ||
107 | _allAnswers.Add(answerCopy); | ||
108 | // If match has already indexed answers for a signature, we need to add | ||
109 | // this to the existing indexed answers. | ||
110 | foreach (int signature in _gotAnswersForSignature.Keys) | ||
111 | indexAnswerForSignature(answerCopy, signature); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | private void indexAnswerForSignature(object[] answer, int signature) | ||
116 | { | ||
117 | // First find out which of the answer values can be used as an index. | ||
118 | object[] indexValues = new object[answer.Length]; | ||
119 | for (int i = 0; i < answer.Length; ++i) | ||
120 | { | ||
121 | // We limit the number of indexed args in a 32-bit signature. | ||
122 | if (i >= MAX_INDEX_ARGS) | ||
123 | indexValues[i] = null; | ||
124 | else | ||
125 | indexValues[i] = getIndexValue(YP.getValue(answer[i])); | ||
126 | } | ||
127 | |||
128 | // We need an entry in indexArgs from indexValues for each 1 bit in signature. | ||
129 | HashedList indexArgs = new HashedList(indexValues.Length); | ||
130 | for (int i = 0; i < indexValues.Length; ++i) | ||
131 | { | ||
132 | if ((signature & (1 << i)) == 0) | ||
133 | indexArgs.Add(null); | ||
134 | else | ||
135 | { | ||
136 | if (indexValues[i] == null) | ||
137 | // The signature wants an index value here, but we don't have one so | ||
138 | // we can't add it as an answer for this signature. | ||
139 | return; | ||
140 | else | ||
141 | indexArgs.Add(indexValues[i]); | ||
142 | } | ||
143 | } | ||
144 | |||
145 | // Add the answer to the answers list for indexArgs, creating the entry if needed. | ||
146 | List<object[]> answers; | ||
147 | if (!_indexedAnswers.TryGetValue(indexArgs, out answers)) | ||
148 | { | ||
149 | answers = new List<object[]>(); | ||
150 | _indexedAnswers[indexArgs] = answers; | ||
151 | } | ||
152 | answers.Add(answer); | ||
153 | } | ||
154 | |||
155 | public IEnumerable<bool> match(object[] arguments) | ||
156 | { | ||
157 | if (arguments.Length != _arity) | ||
158 | yield break; | ||
159 | |||
160 | // Set up indexArgs, up to arg position MAX_INDEX_ARGS. The signature has a 1 bit for | ||
161 | // each non-null index arg. | ||
162 | HashedList indexArgs = new HashedList(arguments.Length); | ||
163 | bool gotAllIndexArgs = true; | ||
164 | int signature = 0; | ||
165 | for (int i = 0; i < arguments.Length; ++i) | ||
166 | { | ||
167 | object indexValue = null; | ||
168 | if (i < MAX_INDEX_ARGS) | ||
169 | { | ||
170 | // We limit the number of args in a 32-bit signature. | ||
171 | indexValue = getIndexValue(YP.getValue(arguments[i])); | ||
172 | if (indexValue != null) | ||
173 | signature += (1 << i); | ||
174 | } | ||
175 | if (indexValue == null) | ||
176 | gotAllIndexArgs = false; | ||
177 | indexArgs.Add(indexValue); | ||
178 | } | ||
179 | |||
180 | List<object[]> answers; | ||
181 | if (signature == 0) | ||
182 | // No index args, so we have to match from _allAnswers. | ||
183 | answers = _allAnswers; | ||
184 | else | ||
185 | { | ||
186 | if (!_gotAnswersForSignature.ContainsKey(signature)) | ||
187 | { | ||
188 | // We need to create the entry in _indexedAnswers. | ||
189 | foreach (object[] answer in _allAnswers) | ||
190 | indexAnswerForSignature(answer, signature); | ||
191 | // Mark that we did this signature. | ||
192 | _gotAnswersForSignature[signature] = null; | ||
193 | } | ||
194 | if (!_indexedAnswers.TryGetValue(indexArgs, out answers)) | ||
195 | yield break; | ||
196 | } | ||
197 | |||
198 | if (gotAllIndexArgs) | ||
199 | { | ||
200 | // All the arguments were already bound, so we don't need to do bindings. | ||
201 | yield return false; | ||
202 | yield break; | ||
203 | } | ||
204 | |||
205 | // Find matches in answers. | ||
206 | IEnumerator<bool>[] iterators = new IEnumerator<bool>[arguments.Length]; | ||
207 | // Debug: If the caller asserts another answer into this same predicate during yield, the iterator | ||
208 | // over clauses will be corrupted. Should we take the time to copy answers? | ||
209 | foreach (object[] answer in answers) | ||
210 | { | ||
211 | bool gotMatch = true; | ||
212 | int nIterators = 0; | ||
213 | // Try to bind all the arguments. | ||
214 | for (int i = 0; i < arguments.Length; ++i) | ||
215 | { | ||
216 | if (indexArgs[i] != null) | ||
217 | // We already matched this argument by looking up _indexedAnswers. | ||
218 | continue; | ||
219 | |||
220 | IEnumerator<bool> iterator = YP.unify(arguments[i], answer[i]).GetEnumerator(); | ||
221 | iterators[nIterators++] = iterator; | ||
222 | // MoveNext() is true if YP.unify succeeds. | ||
223 | if (!iterator.MoveNext()) | ||
224 | { | ||
225 | gotMatch = false; | ||
226 | break; | ||
227 | } | ||
228 | } | ||
229 | int z = 0; | ||
230 | try | ||
231 | { | ||
232 | if (gotMatch) | ||
233 | yield return false; | ||
234 | } | ||
235 | finally | ||
236 | { | ||
237 | // Manually finalize all the iterators. | ||
238 | for (z = 0; z < nIterators; ++z) | ||
239 | iterators[z].Dispose(); | ||
240 | } | ||
241 | } | ||
242 | } | ||
243 | |||
244 | public IEnumerable<bool> clause(object Head, object Body) | ||
245 | { | ||
246 | Head = YP.getValue(Head); | ||
247 | if (Head is Variable) | ||
248 | throw new PrologException("instantiation_error", "Head is an unbound variable"); | ||
249 | object[] arguments = YP.getFunctorArgs(Head); | ||
250 | |||
251 | // We always match Head from _allAnswers, and the Body is Atom.a("true"). | ||
252 | #pragma warning disable 0168, 0219 | ||
253 | foreach (bool l1 in YP.unify(Body, Atom.a("true"))) | ||
254 | { | ||
255 | // The caller can assert another answer into this same predicate during yield, so we have to | ||
256 | // make a copy of the answers. | ||
257 | foreach (object[] answer in _allAnswers.ToArray()) | ||
258 | { | ||
259 | foreach (bool l2 in YP.unifyArrays(arguments, answer)) | ||
260 | yield return false; | ||
261 | } | ||
262 | } | ||
263 | #pragma warning restore 0168, 0219 | ||
264 | } | ||
265 | |||
266 | public IEnumerable<bool> retract(object Head, object Body) | ||
267 | { | ||
268 | Head = YP.getValue(Head); | ||
269 | if (Head is Variable) | ||
270 | throw new PrologException("instantiation_error", "Head is an unbound variable"); | ||
271 | object[] arguments = YP.getFunctorArgs(Head); | ||
272 | |||
273 | // We always match Head from _allAnswers, and the Body is Atom.a("true"). | ||
274 | #pragma warning disable 0168, 0219 | ||
275 | foreach (bool l1 in YP.unify(Body, Atom.a("true"))) | ||
276 | { | ||
277 | // The caller can assert another answer into this same predicate during yield, so we have to | ||
278 | // make a copy of the answers. | ||
279 | foreach (object[] answer in _allAnswers.ToArray()) | ||
280 | { | ||
281 | foreach (bool l2 in YP.unifyArrays(arguments, answer)) | ||
282 | { | ||
283 | _allAnswers.Remove(answer); | ||
284 | clearIndexes(); | ||
285 | yield return false; | ||
286 | } | ||
287 | } | ||
288 | } | ||
289 | #pragma warning restore 0168, 0219 | ||
290 | } | ||
291 | |||
292 | /// <summary> | ||
293 | /// After retracting or prepending an answer in _allAnswers, the indexes are invalid, so clear them. | ||
294 | /// </summary> | ||
295 | private void clearIndexes() | ||
296 | { | ||
297 | _indexedAnswers.Clear(); | ||
298 | _gotAnswersForSignature.Clear(); | ||
299 | } | ||
300 | |||
301 | /// <summary> | ||
302 | /// A HashedList extends an ArrayList with methods to get a hash and to check equality | ||
303 | /// based on the elements of the list. | ||
304 | /// </summary> | ||
305 | public class HashedList : ArrayList | ||
306 | { | ||
307 | private bool _gotHashCode = false; | ||
308 | private int _hashCode; | ||
309 | |||
310 | public HashedList() | ||
311 | : base() | ||
312 | { | ||
313 | } | ||
314 | |||
315 | public HashedList(int capacity) | ||
316 | : base(capacity) | ||
317 | { | ||
318 | } | ||
319 | |||
320 | public HashedList(ICollection c) | ||
321 | : base(c) | ||
322 | { | ||
323 | } | ||
324 | |||
325 | // Debug: Should override all the other methods that change this. | ||
326 | public override int Add(object value) | ||
327 | { | ||
328 | _gotHashCode = false; | ||
329 | return base.Add(value); | ||
330 | } | ||
331 | |||
332 | public override int GetHashCode() | ||
333 | { | ||
334 | if (!_gotHashCode) | ||
335 | { | ||
336 | int hashCode = 1; | ||
337 | foreach (object obj in this) | ||
338 | hashCode = 31 * hashCode + (obj == null ? 0 : obj.GetHashCode()); | ||
339 | _hashCode = hashCode; | ||
340 | _gotHashCode = true; | ||
341 | } | ||
342 | return _hashCode; | ||
343 | } | ||
344 | |||
345 | public override bool Equals(object obj) | ||
346 | { | ||
347 | if (!(obj is ArrayList)) | ||
348 | return false; | ||
349 | |||
350 | ArrayList objList = (ArrayList)obj; | ||
351 | if (objList.Count != Count) | ||
352 | return false; | ||
353 | |||
354 | for (int i = 0; i < Count; ++i) | ||
355 | { | ||
356 | object value = objList[i]; | ||
357 | if (value == null) | ||
358 | { | ||
359 | if (this[i] != null) | ||
360 | return false; | ||
361 | } | ||
362 | else | ||
363 | { | ||
364 | if (!value.Equals(this[i])) | ||
365 | return false; | ||
366 | } | ||
367 | } | ||
368 | return true; | ||
369 | } | ||
370 | } | ||
371 | |||
372 | /// <summary> | ||
373 | /// If we keep an index on value, return the value, or null if we don't index it. | ||
374 | /// </summary> | ||
375 | /// <param name="value">the term to examine. Assume you already called YP.getValue(value)</param> | ||
376 | /// <returns></returns> | ||
377 | public static object getIndexValue(object value) | ||
378 | { | ||
379 | if (value is Atom || value is string || value is Int32 || value is DateTime) | ||
380 | return value; | ||
381 | else | ||
382 | return null; | ||
383 | } | ||
384 | } | ||
385 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/ListPair.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/ListPair.cs deleted file mode 100644 index daac0ba..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/ListPair.cs +++ /dev/null | |||
@@ -1,166 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections.Generic; | ||
33 | |||
34 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
35 | { | ||
36 | public class ListPair : Functor2 | ||
37 | { | ||
38 | public ListPair(object head, object tail) : base(Atom.DOT, head, tail) | ||
39 | { | ||
40 | } | ||
41 | |||
42 | public static object make(List<object> list) | ||
43 | { | ||
44 | if (list.Count <= 0) | ||
45 | return Atom.NIL; | ||
46 | |||
47 | object result = Atom.NIL; | ||
48 | // Start from the end. | ||
49 | for (int i = list.Count - 1; i >= 0; --i) | ||
50 | result = new ListPair(list[i], result); | ||
51 | return result; | ||
52 | } | ||
53 | |||
54 | public static object make(object[] array) | ||
55 | { | ||
56 | if (array.Length <= 0) | ||
57 | return Atom.NIL; | ||
58 | |||
59 | object result = Atom.NIL; | ||
60 | // Start from the end. | ||
61 | for (int i = array.Length - 1; i >= 0; --i) | ||
62 | result = new ListPair(array[i], result); | ||
63 | return result; | ||
64 | } | ||
65 | |||
66 | /// <summary> | ||
67 | /// Return a ListPair version of array, where repeated elements | ||
68 | /// (according to YP.termEqual) are removed. | ||
69 | /// </summary> | ||
70 | /// <param name="array"></param> | ||
71 | /// <returns></returns> | ||
72 | public static object makeWithoutRepeatedTerms(object[] array) | ||
73 | { | ||
74 | if (array.Length <= 0) | ||
75 | return Atom.NIL; | ||
76 | |||
77 | // Start from the end. | ||
78 | object previousTerm = array[array.Length - 1]; | ||
79 | object result = new ListPair(previousTerm, Atom.NIL); | ||
80 | for (int i = array.Length - 2; i >= 0; --i) | ||
81 | { | ||
82 | object term = array[i]; | ||
83 | if (YP.termEqual(term, previousTerm)) | ||
84 | continue; | ||
85 | result = new ListPair(term, result); | ||
86 | previousTerm = term; | ||
87 | } | ||
88 | return result; | ||
89 | } | ||
90 | |||
91 | /// <summary> | ||
92 | /// Return a ListPair version of array, where repeated elements | ||
93 | /// (according to YP.termEqual) are removed. | ||
94 | /// </summary> | ||
95 | /// <param name="array"></param> | ||
96 | /// <returns></returns> | ||
97 | public static object makeWithoutRepeatedTerms(List<object> array) | ||
98 | { | ||
99 | if (array.Count <= 0) | ||
100 | return Atom.NIL; | ||
101 | |||
102 | // Start from the end. | ||
103 | object previousTerm = array[array.Count - 1]; | ||
104 | object result = new ListPair(previousTerm, Atom.NIL); | ||
105 | for (int i = array.Count - 2; i >= 0; --i) | ||
106 | { | ||
107 | object term = array[i]; | ||
108 | if (YP.termEqual(term, previousTerm)) | ||
109 | continue; | ||
110 | result = new ListPair(term, result); | ||
111 | previousTerm = term; | ||
112 | } | ||
113 | return result; | ||
114 | } | ||
115 | |||
116 | public static object make(object element1) | ||
117 | { | ||
118 | return new ListPair(element1, Atom.NIL); | ||
119 | } | ||
120 | |||
121 | public static object make(object element1, object element2) | ||
122 | { | ||
123 | return new ListPair(element1, new ListPair(element2, Atom.NIL)); | ||
124 | } | ||
125 | |||
126 | public static object make(object element1, object element2, object element3) | ||
127 | { | ||
128 | return new ListPair(element1, | ||
129 | new ListPair(element2, new ListPair(element3, Atom.NIL))); | ||
130 | } | ||
131 | |||
132 | /// <summary> | ||
133 | /// Return an array of the elements in list or null if it is not | ||
134 | /// a proper list. If list is Atom.NIL, return an array of zero elements. | ||
135 | /// If the list or one of the tails of the list is Variable, raise an instantiation_error. | ||
136 | /// This does not call YP.getValue on each element. | ||
137 | /// </summary> | ||
138 | /// <param name="list"></param> | ||
139 | /// <returns></returns> | ||
140 | public static object[] toArray(object list) | ||
141 | { | ||
142 | list = YP.getValue(list); | ||
143 | if (list.Equals(Atom.NIL)) | ||
144 | return new object[0]; | ||
145 | |||
146 | List<object> result = new List<object>(); | ||
147 | object element = list; | ||
148 | while (true) { | ||
149 | if (element == Atom.NIL) | ||
150 | break; | ||
151 | if (element is Variable) | ||
152 | throw new PrologException(Atom.a("instantiation_error"), | ||
153 | "List tail is an unbound variable"); | ||
154 | if (!(element is Functor2 && ((Functor2)element)._name == Atom.DOT)) | ||
155 | // Not a proper list. | ||
156 | return null; | ||
157 | result.Add(((Functor2)element)._arg1); | ||
158 | element = YP.getValue(((Functor2)element)._arg2); | ||
159 | } | ||
160 | |||
161 | if (result.Count <= 0) | ||
162 | return null; | ||
163 | return result.ToArray(); | ||
164 | } | ||
165 | } | ||
166 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Parser.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Parser.cs deleted file mode 100644 index 34010e7..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Parser.cs +++ /dev/null | |||
@@ -1,4575 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections.Generic; | ||
33 | |||
34 | // disable warning on l1, don't see how we can | ||
35 | // code this differently | ||
36 | #pragma warning disable 0168, 0219, 0162 | ||
37 | |||
38 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
39 | { | ||
40 | public class Parser | ||
41 | { | ||
42 | public static IEnumerable<bool> read_term2(object Term, object Options) | ||
43 | { | ||
44 | Variable Answer = new Variable(); | ||
45 | Variable Variables = new Variable(); | ||
46 | foreach (bool l1 in read_termOptions(Options, Variables)) | ||
47 | { | ||
48 | foreach (bool l2 in portable_read3(Answer, Variables, new Variable())) | ||
49 | { | ||
50 | foreach (bool l3 in remove_pos(Answer, Term)) | ||
51 | yield return false; | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | |||
56 | public static IEnumerable<bool> read_term3(object Input, object Term, object Options) | ||
57 | { | ||
58 | Variable SaveInput = new Variable(); | ||
59 | Variable Answer = new Variable(); | ||
60 | Variable Variables = new Variable(); | ||
61 | foreach (bool l1 in read_termOptions(Options, Variables)) | ||
62 | { | ||
63 | foreach (bool l2 in YP.current_input(SaveInput)) | ||
64 | { | ||
65 | try | ||
66 | { | ||
67 | YP.see(Input); | ||
68 | foreach (bool l3 in portable_read3(Answer, Variables, new Variable())) | ||
69 | { | ||
70 | foreach (bool l4 in remove_pos(Answer, Term)) | ||
71 | yield return false; | ||
72 | } | ||
73 | } | ||
74 | finally | ||
75 | { | ||
76 | YP.see(SaveInput); | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | } | ||
81 | |||
82 | /// <summary> | ||
83 | /// For read_term, check if Options has variable_names(Variables). | ||
84 | /// Otherwise, ignore Options. | ||
85 | /// </summary> | ||
86 | /// <param name="Options"></param> | ||
87 | /// <param name="Variables"></param> | ||
88 | /// <returns></returns> | ||
89 | private static IEnumerable<bool> read_termOptions(object Options, object Variables) | ||
90 | { | ||
91 | Options = YP.getValue(Options); | ||
92 | if (Options is Variable) | ||
93 | throw new PrologException(Atom.a("instantiation_error"), "Options is an unbound variable"); | ||
94 | // First try to match Options = [variable_names(Variables)] | ||
95 | foreach (bool l1 in YP.unify(Options, ListPair.make(new Functor1("variable_names", Variables)))) | ||
96 | { | ||
97 | yield return false; | ||
98 | yield break; | ||
99 | } | ||
100 | // Default: Ignore Options. | ||
101 | yield return false; | ||
102 | } | ||
103 | |||
104 | public static IEnumerable<bool> read1(object Term) | ||
105 | { | ||
106 | return read_term2(Term, Atom.NIL); | ||
107 | } | ||
108 | |||
109 | public static IEnumerable<bool> read2(object Input, object Term) | ||
110 | { | ||
111 | return read_term3(Input, Term, Atom.NIL); | ||
112 | } | ||
113 | |||
114 | public static IEnumerable<bool> formatError(object Output, object Format, object Arguments) | ||
115 | { | ||
116 | // Debug: Simple implementation for now. | ||
117 | YP.write(Format); | ||
118 | YP.write(Arguments); | ||
119 | YP.nl(); | ||
120 | yield return false; | ||
121 | } | ||
122 | |||
123 | |||
124 | // Debug: Hand-modify this central predicate to do tail recursion. | ||
125 | public static IEnumerable<bool> read_tokens(object arg1, object arg2, object arg3) | ||
126 | { | ||
127 | bool repeat = true; | ||
128 | while (repeat) | ||
129 | { | ||
130 | repeat = false; | ||
131 | { | ||
132 | object C1 = arg1; | ||
133 | object Dict = arg2; | ||
134 | object Tokens = arg3; | ||
135 | Variable C2 = new Variable(); | ||
136 | if (YP.lessThanOrEqual(C1, new ListPair(32, Atom.NIL))) | ||
137 | { | ||
138 | if (YP.greaterThanOrEqual(C1, 0)) | ||
139 | { | ||
140 | foreach (bool l4 in YP.get_code(C2)) | ||
141 | { | ||
142 | #if false | ||
143 | foreach (bool l5 in read_tokens(C2, Dict, Tokens)) | ||
144 | { | ||
145 | yield return false; | ||
146 | } | ||
147 | #endif | ||
148 | arg1 = YP.getValue(C2); | ||
149 | arg2 = YP.getValue(Dict); | ||
150 | arg3 = YP.getValue(Tokens); | ||
151 | repeat = true; | ||
152 | } | ||
153 | } | ||
154 | goto cutIf1; | ||
155 | } | ||
156 | if (YP.greaterThanOrEqual(C1, new ListPair(97, Atom.NIL))) | ||
157 | { | ||
158 | if (YP.lessThanOrEqual(C1, new ListPair(122, Atom.NIL))) | ||
159 | { | ||
160 | foreach (bool l4 in read_identifier(C1, Dict, Tokens)) | ||
161 | { | ||
162 | yield return false; | ||
163 | } | ||
164 | goto cutIf2; | ||
165 | } | ||
166 | } | ||
167 | if (YP.greaterThanOrEqual(C1, new ListPair(65, Atom.NIL))) | ||
168 | { | ||
169 | if (YP.lessThanOrEqual(C1, new ListPair(90, Atom.NIL))) | ||
170 | { | ||
171 | foreach (bool l4 in read_variable(C1, Dict, Tokens)) | ||
172 | { | ||
173 | yield return false; | ||
174 | } | ||
175 | goto cutIf3; | ||
176 | } | ||
177 | } | ||
178 | if (YP.greaterThanOrEqual(C1, new ListPair(48, Atom.NIL))) | ||
179 | { | ||
180 | if (YP.lessThanOrEqual(C1, new ListPair(57, Atom.NIL))) | ||
181 | { | ||
182 | foreach (bool l4 in read_number(C1, Dict, Tokens)) | ||
183 | { | ||
184 | yield return false; | ||
185 | } | ||
186 | goto cutIf4; | ||
187 | } | ||
188 | } | ||
189 | if (YP.lessThan(C1, 127)) | ||
190 | { | ||
191 | foreach (bool l3 in read_special(C1, Dict, Tokens)) | ||
192 | { | ||
193 | yield return false; | ||
194 | } | ||
195 | goto cutIf5; | ||
196 | } | ||
197 | if (YP.lessThanOrEqual(C1, 160)) | ||
198 | { | ||
199 | foreach (bool l3 in YP.get_code(C2)) | ||
200 | { | ||
201 | #if false | ||
202 | foreach (bool l4 in read_tokens(C2, Dict, Tokens)) | ||
203 | { | ||
204 | yield return false; | ||
205 | } | ||
206 | #endif | ||
207 | arg1 = YP.getValue(C2); | ||
208 | arg2 = YP.getValue(Dict); | ||
209 | arg3 = YP.getValue(Tokens); | ||
210 | repeat = true; | ||
211 | } | ||
212 | goto cutIf6; | ||
213 | } | ||
214 | if (YP.greaterThanOrEqual(C1, 223)) | ||
215 | { | ||
216 | if (YP.notEqual(C1, 247)) | ||
217 | { | ||
218 | foreach (bool l4 in read_identifier(C1, Dict, Tokens)) | ||
219 | { | ||
220 | yield return false; | ||
221 | } | ||
222 | goto cutIf7; | ||
223 | } | ||
224 | } | ||
225 | if (YP.greaterThanOrEqual(C1, 192)) | ||
226 | { | ||
227 | if (YP.notEqual(C1, 215)) | ||
228 | { | ||
229 | foreach (bool l4 in read_variable(C1, Dict, Tokens)) | ||
230 | { | ||
231 | yield return false; | ||
232 | } | ||
233 | goto cutIf8; | ||
234 | } | ||
235 | } | ||
236 | if (YP.notEqual(C1, 170)) | ||
237 | { | ||
238 | if (YP.notEqual(C1, 186)) | ||
239 | { | ||
240 | foreach (bool l4 in read_symbol(C1, Dict, Tokens)) | ||
241 | { | ||
242 | yield return false; | ||
243 | } | ||
244 | goto cutIf9; | ||
245 | } | ||
246 | } | ||
247 | foreach (bool l2 in read_identifier(C1, Dict, Tokens)) | ||
248 | { | ||
249 | yield return false; | ||
250 | } | ||
251 | cutIf9: | ||
252 | cutIf8: | ||
253 | cutIf7: | ||
254 | cutIf6: | ||
255 | cutIf5: | ||
256 | cutIf4: | ||
257 | cutIf3: | ||
258 | cutIf2: | ||
259 | cutIf1: | ||
260 | { } | ||
261 | } | ||
262 | } | ||
263 | } | ||
264 | |||
265 | // Compiler output follows. | ||
266 | |||
267 | class YPInnerClass { } | ||
268 | // static Type getDeclaringClass() { return typeof(YPInnerClass).DeclaringType; } | ||
269 | |||
270 | public static IEnumerable<bool> parseInput(object TermList) | ||
271 | { | ||
272 | { | ||
273 | Variable TermAndVariables = new Variable(); | ||
274 | FindallAnswers findallAnswers1 = new FindallAnswers(TermAndVariables); | ||
275 | foreach (bool l2 in parseInputHelper(TermAndVariables)) | ||
276 | { | ||
277 | findallAnswers1.add(); | ||
278 | } | ||
279 | foreach (bool l2 in findallAnswers1.result(TermList)) | ||
280 | { | ||
281 | yield return false; | ||
282 | } | ||
283 | } | ||
284 | } | ||
285 | |||
286 | public static IEnumerable<bool> parseInputHelper(object arg1) | ||
287 | { | ||
288 | { | ||
289 | Variable Term = new Variable(); | ||
290 | Variable Variables = new Variable(); | ||
291 | Variable Answer = new Variable(); | ||
292 | Variable x4 = new Variable(); | ||
293 | foreach (bool l2 in YP.unify(arg1, new Functor2("f", Term, Variables))) | ||
294 | { | ||
295 | foreach (bool l3 in YP.repeat()) | ||
296 | { | ||
297 | foreach (bool l4 in portable_read3(Answer, Variables, x4)) | ||
298 | { | ||
299 | foreach (bool l5 in remove_pos(Answer, Term)) | ||
300 | { | ||
301 | if (YP.termEqual(Term, Atom.a("end_of_file"))) | ||
302 | { | ||
303 | yield break; | ||
304 | goto cutIf1; | ||
305 | } | ||
306 | yield return false; | ||
307 | cutIf1: | ||
308 | { } | ||
309 | } | ||
310 | } | ||
311 | } | ||
312 | } | ||
313 | } | ||
314 | } | ||
315 | |||
316 | public static IEnumerable<bool> clear_errors() | ||
317 | { | ||
318 | { | ||
319 | yield return false; | ||
320 | } | ||
321 | } | ||
322 | |||
323 | public static IEnumerable<bool> remove_pos(object arg1, object arg2) | ||
324 | { | ||
325 | { | ||
326 | Variable X = new Variable(); | ||
327 | foreach (bool l2 in YP.unify(arg1, X)) | ||
328 | { | ||
329 | foreach (bool l3 in YP.unify(arg2, X)) | ||
330 | { | ||
331 | if (YP.var(X)) | ||
332 | { | ||
333 | yield return true; | ||
334 | yield break; | ||
335 | } | ||
336 | } | ||
337 | } | ||
338 | } | ||
339 | { | ||
340 | object X = arg2; | ||
341 | Variable _Pos = new Variable(); | ||
342 | Variable _Name = new Variable(); | ||
343 | foreach (bool l2 in YP.unify(arg1, new Functor3("$VAR", _Pos, _Name, X))) | ||
344 | { | ||
345 | if (YP.var(X)) | ||
346 | { | ||
347 | yield return true; | ||
348 | yield break; | ||
349 | } | ||
350 | } | ||
351 | } | ||
352 | { | ||
353 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
354 | { | ||
355 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
356 | { | ||
357 | yield return true; | ||
358 | yield break; | ||
359 | } | ||
360 | } | ||
361 | } | ||
362 | { | ||
363 | Variable H = new Variable(); | ||
364 | Variable T = new Variable(); | ||
365 | Variable NH = new Variable(); | ||
366 | Variable NT = new Variable(); | ||
367 | foreach (bool l2 in YP.unify(arg1, new ListPair(H, T))) | ||
368 | { | ||
369 | foreach (bool l3 in YP.unify(arg2, new ListPair(NH, NT))) | ||
370 | { | ||
371 | foreach (bool l4 in remove_pos(H, NH)) | ||
372 | { | ||
373 | foreach (bool l5 in remove_pos(T, NT)) | ||
374 | { | ||
375 | yield return false; | ||
376 | } | ||
377 | } | ||
378 | yield break; | ||
379 | } | ||
380 | } | ||
381 | } | ||
382 | { | ||
383 | Variable A = new Variable(); | ||
384 | Variable B = new Variable(); | ||
385 | Variable NA = new Variable(); | ||
386 | Variable NB = new Variable(); | ||
387 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", A, B))) | ||
388 | { | ||
389 | foreach (bool l3 in YP.unify(arg2, new Functor2(",", NA, NB))) | ||
390 | { | ||
391 | foreach (bool l4 in remove_pos(A, NA)) | ||
392 | { | ||
393 | foreach (bool l5 in remove_pos(B, NB)) | ||
394 | { | ||
395 | yield return false; | ||
396 | } | ||
397 | } | ||
398 | yield break; | ||
399 | } | ||
400 | } | ||
401 | } | ||
402 | { | ||
403 | Variable Atom_1 = new Variable(); | ||
404 | Variable _F = new Variable(); | ||
405 | foreach (bool l2 in YP.unify(arg1, Atom_1)) | ||
406 | { | ||
407 | foreach (bool l3 in YP.unify(arg2, Atom_1)) | ||
408 | { | ||
409 | foreach (bool l4 in YP.functor(Atom_1, _F, 0)) | ||
410 | { | ||
411 | yield return false; | ||
412 | } | ||
413 | } | ||
414 | } | ||
415 | } | ||
416 | { | ||
417 | object Term = arg1; | ||
418 | object NewTerm = arg2; | ||
419 | Variable Func = new Variable(); | ||
420 | Variable _Pos = new Variable(); | ||
421 | Variable Args = new Variable(); | ||
422 | Variable NArgs = new Variable(); | ||
423 | if (YP.nonvar(Term)) | ||
424 | { | ||
425 | foreach (bool l3 in YP.univ(Term, new ListPair(Func, new ListPair(_Pos, Args)))) | ||
426 | { | ||
427 | foreach (bool l4 in remove_pos(Args, NArgs)) | ||
428 | { | ||
429 | foreach (bool l5 in YP.univ(NewTerm, new ListPair(Func, NArgs))) | ||
430 | { | ||
431 | yield return false; | ||
432 | } | ||
433 | } | ||
434 | } | ||
435 | } | ||
436 | } | ||
437 | } | ||
438 | |||
439 | public static IEnumerable<bool> portable_read_position(object Term, object PosTerm, object Syntax) | ||
440 | { | ||
441 | { | ||
442 | foreach (bool l2 in portable_read(PosTerm, Syntax)) | ||
443 | { | ||
444 | foreach (bool l3 in remove_pos(PosTerm, Term)) | ||
445 | { | ||
446 | yield return false; | ||
447 | } | ||
448 | } | ||
449 | } | ||
450 | } | ||
451 | |||
452 | public static IEnumerable<bool> portable_read(object Answer, object Syntax) | ||
453 | { | ||
454 | { | ||
455 | Variable Tokens = new Variable(); | ||
456 | Variable ParseTokens = new Variable(); | ||
457 | foreach (bool l2 in read_tokens1(Tokens)) | ||
458 | { | ||
459 | foreach (bool l3 in remove_comments(Tokens, ParseTokens, Syntax)) | ||
460 | { | ||
461 | foreach (bool l4 in parse2(ParseTokens, Answer)) | ||
462 | { | ||
463 | yield return false; | ||
464 | } | ||
465 | } | ||
466 | } | ||
467 | } | ||
468 | } | ||
469 | |||
470 | public static IEnumerable<bool> portable_read3(object Answer, object Variables, object Syntax) | ||
471 | { | ||
472 | { | ||
473 | Variable Tokens = new Variable(); | ||
474 | Variable ParseTokens = new Variable(); | ||
475 | foreach (bool l2 in read_tokens2(Tokens, Variables)) | ||
476 | { | ||
477 | foreach (bool l3 in remove_comments(Tokens, ParseTokens, Syntax)) | ||
478 | { | ||
479 | foreach (bool l4 in parse2(ParseTokens, Answer)) | ||
480 | { | ||
481 | yield return false; | ||
482 | } | ||
483 | } | ||
484 | } | ||
485 | } | ||
486 | } | ||
487 | |||
488 | public static IEnumerable<bool> remove_comments(object arg1, object arg2, object arg3) | ||
489 | { | ||
490 | { | ||
491 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
492 | { | ||
493 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
494 | { | ||
495 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
496 | { | ||
497 | yield return false; | ||
498 | } | ||
499 | } | ||
500 | } | ||
501 | } | ||
502 | { | ||
503 | object Ys = arg2; | ||
504 | Variable S = new Variable(); | ||
505 | Variable E = new Variable(); | ||
506 | Variable Xs = new Variable(); | ||
507 | Variable Zs = new Variable(); | ||
508 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("comment", S, E), Xs))) | ||
509 | { | ||
510 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("comment", S, E), Zs))) | ||
511 | { | ||
512 | foreach (bool l4 in remove_comments(Xs, Ys, Zs)) | ||
513 | { | ||
514 | yield return false; | ||
515 | } | ||
516 | yield break; | ||
517 | } | ||
518 | } | ||
519 | } | ||
520 | { | ||
521 | Variable Pos = new Variable(); | ||
522 | Variable Xs = new Variable(); | ||
523 | Variable Ys = new Variable(); | ||
524 | Variable Pos2 = new Variable(); | ||
525 | Variable Zs = new Variable(); | ||
526 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("/", Atom.a("["), Pos), Xs))) | ||
527 | { | ||
528 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a("["), Ys))) | ||
529 | { | ||
530 | foreach (bool l4 in YP.unify(arg3, new ListPair(new Functor2("list", Pos, Pos2), Zs))) | ||
531 | { | ||
532 | foreach (bool l5 in YP.unify(Pos2, YP.add(Pos, 1))) | ||
533 | { | ||
534 | foreach (bool l6 in remove_comments(Xs, Ys, Zs)) | ||
535 | { | ||
536 | yield return false; | ||
537 | } | ||
538 | } | ||
539 | yield break; | ||
540 | } | ||
541 | } | ||
542 | } | ||
543 | } | ||
544 | { | ||
545 | Variable Pos = new Variable(); | ||
546 | Variable Xs = new Variable(); | ||
547 | Variable Ys = new Variable(); | ||
548 | Variable Pos2 = new Variable(); | ||
549 | Variable Zs = new Variable(); | ||
550 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("/", Atom.a("]"), Pos), Xs))) | ||
551 | { | ||
552 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a("]"), Ys))) | ||
553 | { | ||
554 | foreach (bool l4 in YP.unify(arg3, new ListPair(new Functor2("list", Pos, Pos2), Zs))) | ||
555 | { | ||
556 | foreach (bool l5 in YP.unify(Pos2, YP.add(Pos, 1))) | ||
557 | { | ||
558 | foreach (bool l6 in remove_comments(Xs, Ys, Zs)) | ||
559 | { | ||
560 | yield return false; | ||
561 | } | ||
562 | } | ||
563 | yield break; | ||
564 | } | ||
565 | } | ||
566 | } | ||
567 | } | ||
568 | { | ||
569 | object Zs = arg3; | ||
570 | Variable Token = new Variable(); | ||
571 | Variable Xs = new Variable(); | ||
572 | Variable Ys = new Variable(); | ||
573 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, Xs))) | ||
574 | { | ||
575 | foreach (bool l3 in YP.unify(arg2, new ListPair(Token, Ys))) | ||
576 | { | ||
577 | foreach (bool l4 in remove_comments(Xs, Ys, Zs)) | ||
578 | { | ||
579 | yield return false; | ||
580 | } | ||
581 | } | ||
582 | } | ||
583 | } | ||
584 | } | ||
585 | |||
586 | public static IEnumerable<bool> expect(object Token, object arg2, object arg3) | ||
587 | { | ||
588 | { | ||
589 | object Rest = arg3; | ||
590 | foreach (bool l2 in YP.unify(arg2, new ListPair(Token, Rest))) | ||
591 | { | ||
592 | yield return true; | ||
593 | yield break; | ||
594 | } | ||
595 | } | ||
596 | { | ||
597 | object S0 = arg2; | ||
598 | object x3 = arg3; | ||
599 | foreach (bool l2 in syntax_error(ListPair.make(new object[] { Token, Atom.a("or"), Atom.a("operator"), Atom.a("expected") }), S0)) | ||
600 | { | ||
601 | yield return false; | ||
602 | } | ||
603 | } | ||
604 | } | ||
605 | |||
606 | public static IEnumerable<bool> parse2(object Tokens, object Answer) | ||
607 | { | ||
608 | { | ||
609 | Variable Term = new Variable(); | ||
610 | Variable LeftOver = new Variable(); | ||
611 | foreach (bool l2 in clear_errors()) | ||
612 | { | ||
613 | foreach (bool l3 in parse(Tokens, 1200, Term, LeftOver)) | ||
614 | { | ||
615 | foreach (bool l4 in all_read(LeftOver)) | ||
616 | { | ||
617 | foreach (bool l5 in YP.unify(Answer, Term)) | ||
618 | { | ||
619 | yield return false; | ||
620 | } | ||
621 | yield break; | ||
622 | } | ||
623 | } | ||
624 | foreach (bool l3 in syntax_error(Tokens)) | ||
625 | { | ||
626 | yield return false; | ||
627 | } | ||
628 | } | ||
629 | } | ||
630 | } | ||
631 | |||
632 | public static IEnumerable<bool> all_read(object arg1) | ||
633 | { | ||
634 | { | ||
635 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
636 | { | ||
637 | yield return false; | ||
638 | } | ||
639 | } | ||
640 | { | ||
641 | Variable Token = new Variable(); | ||
642 | Variable S = new Variable(); | ||
643 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, S))) | ||
644 | { | ||
645 | foreach (bool l3 in syntax_error(ListPair.make(new object[] { Atom.a("operator"), Atom.a("expected"), Atom.a("after"), Atom.a("expression") }), new ListPair(Token, S))) | ||
646 | { | ||
647 | yield return false; | ||
648 | } | ||
649 | } | ||
650 | } | ||
651 | } | ||
652 | |||
653 | public static IEnumerable<bool> parse(object arg1, object arg2, object arg3, object arg4) | ||
654 | { | ||
655 | { | ||
656 | object x1 = arg2; | ||
657 | object x2 = arg3; | ||
658 | object x3 = arg4; | ||
659 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
660 | { | ||
661 | foreach (bool l3 in syntax_error(new ListPair(Atom.a("expression"), new ListPair(Atom.a("expected"), Atom.NIL)), Atom.NIL)) | ||
662 | { | ||
663 | yield return false; | ||
664 | } | ||
665 | } | ||
666 | } | ||
667 | { | ||
668 | object Precedence = arg2; | ||
669 | object Term = arg3; | ||
670 | object LeftOver = arg4; | ||
671 | Variable Token = new Variable(); | ||
672 | Variable RestTokens = new Variable(); | ||
673 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, RestTokens))) | ||
674 | { | ||
675 | foreach (bool l3 in parse5(Token, RestTokens, Precedence, Term, LeftOver)) | ||
676 | { | ||
677 | yield return false; | ||
678 | } | ||
679 | } | ||
680 | } | ||
681 | } | ||
682 | |||
683 | public static IEnumerable<bool> parse5(object arg1, object arg2, object arg3, object arg4, object arg5) | ||
684 | { | ||
685 | { | ||
686 | object S0 = arg2; | ||
687 | object x2 = arg3; | ||
688 | object x3 = arg4; | ||
689 | object x4 = arg5; | ||
690 | foreach (bool l2 in YP.unify(arg1, Atom.a("}"))) | ||
691 | { | ||
692 | foreach (bool l3 in cannot_start(Atom.a("}"), S0)) | ||
693 | { | ||
694 | yield return false; | ||
695 | } | ||
696 | } | ||
697 | } | ||
698 | { | ||
699 | object S0 = arg2; | ||
700 | object x2 = arg3; | ||
701 | object x3 = arg4; | ||
702 | object x4 = arg5; | ||
703 | foreach (bool l2 in YP.unify(arg1, Atom.a("]"))) | ||
704 | { | ||
705 | foreach (bool l3 in cannot_start(Atom.a("]"), S0)) | ||
706 | { | ||
707 | yield return false; | ||
708 | } | ||
709 | } | ||
710 | } | ||
711 | { | ||
712 | object S0 = arg2; | ||
713 | object x2 = arg3; | ||
714 | object x3 = arg4; | ||
715 | object x4 = arg5; | ||
716 | foreach (bool l2 in YP.unify(arg1, Atom.a(")"))) | ||
717 | { | ||
718 | foreach (bool l3 in cannot_start(Atom.a(")"), S0)) | ||
719 | { | ||
720 | yield return false; | ||
721 | } | ||
722 | } | ||
723 | } | ||
724 | { | ||
725 | object S0 = arg2; | ||
726 | object x2 = arg3; | ||
727 | object x3 = arg4; | ||
728 | object x4 = arg5; | ||
729 | foreach (bool l2 in YP.unify(arg1, Atom.a(","))) | ||
730 | { | ||
731 | foreach (bool l3 in cannot_start(Atom.a(","), S0)) | ||
732 | { | ||
733 | yield return false; | ||
734 | } | ||
735 | } | ||
736 | } | ||
737 | { | ||
738 | object S0 = arg2; | ||
739 | object x2 = arg3; | ||
740 | object x3 = arg4; | ||
741 | object x4 = arg5; | ||
742 | foreach (bool l2 in YP.unify(arg1, Atom.a("|"))) | ||
743 | { | ||
744 | foreach (bool l3 in cannot_start(Atom.a("|"), S0)) | ||
745 | { | ||
746 | yield return false; | ||
747 | } | ||
748 | } | ||
749 | } | ||
750 | { | ||
751 | object S0 = arg2; | ||
752 | object Precedence = arg3; | ||
753 | object Answer = arg4; | ||
754 | object S = arg5; | ||
755 | Variable Codes = new Variable(); | ||
756 | Variable Term = new Variable(); | ||
757 | Variable A = new Variable(); | ||
758 | foreach (bool l2 in YP.unify(arg1, new Functor1("string", Codes))) | ||
759 | { | ||
760 | foreach (bool l3 in YP.current_prolog_flag(Atom.a("double_quotes"), Atom.a("atom"))) | ||
761 | { | ||
762 | foreach (bool l4 in YP.atom_codes(Term, Codes)) | ||
763 | { | ||
764 | foreach (bool l5 in exprtl0(S0, Term, Precedence, Answer, S)) | ||
765 | { | ||
766 | yield return false; | ||
767 | } | ||
768 | } | ||
769 | goto cutIf1; | ||
770 | } | ||
771 | foreach (bool l3 in YP.current_prolog_flag(Atom.a("double_quotes"), Atom.a("chars"))) | ||
772 | { | ||
773 | foreach (bool l4 in YP.atom_codes(A, Codes)) | ||
774 | { | ||
775 | foreach (bool l5 in YP.atom_chars(A, Term)) | ||
776 | { | ||
777 | foreach (bool l6 in exprtl0(S0, Term, Precedence, Answer, S)) | ||
778 | { | ||
779 | yield return false; | ||
780 | } | ||
781 | } | ||
782 | } | ||
783 | goto cutIf2; | ||
784 | } | ||
785 | foreach (bool l3 in YP.unify(Term, Codes)) | ||
786 | { | ||
787 | foreach (bool l4 in exprtl0(S0, Term, Precedence, Answer, S)) | ||
788 | { | ||
789 | yield return false; | ||
790 | } | ||
791 | } | ||
792 | cutIf2: | ||
793 | cutIf1: | ||
794 | { } | ||
795 | } | ||
796 | } | ||
797 | { | ||
798 | object S0 = arg2; | ||
799 | object Precedence = arg3; | ||
800 | object Answer = arg4; | ||
801 | object S = arg5; | ||
802 | Variable Number = new Variable(); | ||
803 | foreach (bool l2 in YP.unify(arg1, new Functor1("number", Number))) | ||
804 | { | ||
805 | foreach (bool l3 in exprtl0(S0, Number, Precedence, Answer, S)) | ||
806 | { | ||
807 | yield return false; | ||
808 | } | ||
809 | } | ||
810 | } | ||
811 | { | ||
812 | object Precedence = arg3; | ||
813 | object Answer = arg4; | ||
814 | object S = arg5; | ||
815 | Variable S1 = new Variable(); | ||
816 | foreach (bool l2 in YP.unify(arg1, Atom.a("["))) | ||
817 | { | ||
818 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a("]"), S1))) | ||
819 | { | ||
820 | foreach (bool l4 in read_atom(new Functor2("/", Atom.NIL, 0), S1, Precedence, Answer, S)) | ||
821 | { | ||
822 | yield return false; | ||
823 | } | ||
824 | yield break; | ||
825 | } | ||
826 | } | ||
827 | } | ||
828 | { | ||
829 | object S1 = arg2; | ||
830 | object Precedence = arg3; | ||
831 | object Answer = arg4; | ||
832 | object S = arg5; | ||
833 | Variable Arg1 = new Variable(); | ||
834 | Variable S2 = new Variable(); | ||
835 | Variable RestArgs = new Variable(); | ||
836 | Variable S3 = new Variable(); | ||
837 | foreach (bool l2 in YP.unify(arg1, Atom.a("["))) | ||
838 | { | ||
839 | foreach (bool l3 in parse(S1, 999, Arg1, S2)) | ||
840 | { | ||
841 | foreach (bool l4 in read_list(S2, RestArgs, S3)) | ||
842 | { | ||
843 | foreach (bool l5 in exprtl0(S3, new ListPair(Arg1, RestArgs), Precedence, Answer, S)) | ||
844 | { | ||
845 | yield return false; | ||
846 | } | ||
847 | yield break; | ||
848 | } | ||
849 | } | ||
850 | } | ||
851 | } | ||
852 | { | ||
853 | object S1 = arg2; | ||
854 | object Precedence = arg3; | ||
855 | object Answer = arg4; | ||
856 | object S = arg5; | ||
857 | Variable Term = new Variable(); | ||
858 | Variable S2 = new Variable(); | ||
859 | Variable S3 = new Variable(); | ||
860 | foreach (bool l2 in YP.unify(arg1, Atom.a("("))) | ||
861 | { | ||
862 | foreach (bool l3 in parse(S1, 1200, Term, S2)) | ||
863 | { | ||
864 | foreach (bool l4 in expect(Atom.a(")"), S2, S3)) | ||
865 | { | ||
866 | foreach (bool l5 in exprtl0(S3, Term, Precedence, Answer, S)) | ||
867 | { | ||
868 | yield return false; | ||
869 | } | ||
870 | yield break; | ||
871 | } | ||
872 | } | ||
873 | } | ||
874 | } | ||
875 | { | ||
876 | object S1 = arg2; | ||
877 | object Precedence = arg3; | ||
878 | object Answer = arg4; | ||
879 | object S = arg5; | ||
880 | Variable Term = new Variable(); | ||
881 | Variable S2 = new Variable(); | ||
882 | Variable S3 = new Variable(); | ||
883 | foreach (bool l2 in YP.unify(arg1, Atom.a(" ("))) | ||
884 | { | ||
885 | foreach (bool l3 in parse(S1, 1200, Term, S2)) | ||
886 | { | ||
887 | foreach (bool l4 in expect(Atom.a(")"), S2, S3)) | ||
888 | { | ||
889 | foreach (bool l5 in exprtl0(S3, Term, Precedence, Answer, S)) | ||
890 | { | ||
891 | yield return false; | ||
892 | } | ||
893 | yield break; | ||
894 | } | ||
895 | } | ||
896 | } | ||
897 | } | ||
898 | { | ||
899 | object Precedence = arg3; | ||
900 | object Answer = arg4; | ||
901 | object S = arg5; | ||
902 | Variable _Pos = new Variable(); | ||
903 | Variable S1 = new Variable(); | ||
904 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", Atom.a("{"), _Pos))) | ||
905 | { | ||
906 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a("}"), S1))) | ||
907 | { | ||
908 | foreach (bool l4 in read_atom(Atom.a("{}"), S1, Precedence, Answer, S)) | ||
909 | { | ||
910 | yield return false; | ||
911 | } | ||
912 | yield break; | ||
913 | } | ||
914 | } | ||
915 | } | ||
916 | { | ||
917 | object S1 = arg2; | ||
918 | object Precedence = arg3; | ||
919 | object Answer = arg4; | ||
920 | object S = arg5; | ||
921 | Variable Pos = new Variable(); | ||
922 | Variable Term = new Variable(); | ||
923 | Variable S2 = new Variable(); | ||
924 | Variable S3 = new Variable(); | ||
925 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", Atom.a("{"), Pos))) | ||
926 | { | ||
927 | foreach (bool l3 in parse(S1, 1200, Term, S2)) | ||
928 | { | ||
929 | foreach (bool l4 in expect(Atom.a("}"), S2, S3)) | ||
930 | { | ||
931 | foreach (bool l5 in exprtl0(S3, new Functor2("{}", Pos, Term), Precedence, Answer, S)) | ||
932 | { | ||
933 | yield return false; | ||
934 | } | ||
935 | yield break; | ||
936 | } | ||
937 | } | ||
938 | } | ||
939 | } | ||
940 | { | ||
941 | object Precedence = arg3; | ||
942 | object Answer = arg4; | ||
943 | object S = arg5; | ||
944 | Variable Variable_1 = new Variable(); | ||
945 | Variable Name = new Variable(); | ||
946 | Variable Pos = new Variable(); | ||
947 | Variable S1 = new Variable(); | ||
948 | Variable Arg1 = new Variable(); | ||
949 | Variable S2 = new Variable(); | ||
950 | Variable RestArgs = new Variable(); | ||
951 | Variable S3 = new Variable(); | ||
952 | Variable Term = new Variable(); | ||
953 | foreach (bool l2 in YP.unify(arg1, new Functor3("var", Variable_1, Name, Pos))) | ||
954 | { | ||
955 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a("("), S1))) | ||
956 | { | ||
957 | foreach (bool l4 in parse(S1, 999, Arg1, S2)) | ||
958 | { | ||
959 | foreach (bool l5 in read_args(S2, RestArgs, S3)) | ||
960 | { | ||
961 | foreach (bool l6 in YP.univ(Term, new ListPair(Atom.a("call"), new ListPair(new Functor3("$VAR", Pos, Name, Variable_1), new ListPair(Arg1, RestArgs))))) | ||
962 | { | ||
963 | foreach (bool l7 in exprtl0(S3, Term, Precedence, Answer, S)) | ||
964 | { | ||
965 | yield return false; | ||
966 | } | ||
967 | } | ||
968 | yield break; | ||
969 | } | ||
970 | } | ||
971 | yield break; | ||
972 | } | ||
973 | } | ||
974 | } | ||
975 | { | ||
976 | object S0 = arg2; | ||
977 | object Precedence = arg3; | ||
978 | object Answer = arg4; | ||
979 | object S = arg5; | ||
980 | Variable Variable_1 = new Variable(); | ||
981 | Variable Name = new Variable(); | ||
982 | Variable Pos = new Variable(); | ||
983 | foreach (bool l2 in YP.unify(arg1, new Functor3("var", Variable_1, Name, Pos))) | ||
984 | { | ||
985 | foreach (bool l3 in exprtl0(S0, new Functor3("$VAR", Pos, Name, Variable_1), Precedence, Answer, S)) | ||
986 | { | ||
987 | yield return false; | ||
988 | } | ||
989 | } | ||
990 | } | ||
991 | { | ||
992 | object S0 = arg2; | ||
993 | object Precedence = arg3; | ||
994 | object Answer = arg4; | ||
995 | object S = arg5; | ||
996 | Variable Atom_1 = new Variable(); | ||
997 | Variable P = new Variable(); | ||
998 | foreach (bool l2 in YP.unify(arg1, new Functor2("atom", Atom_1, P))) | ||
999 | { | ||
1000 | foreach (bool l3 in read_atom(new Functor2("/", Atom_1, P), S0, Precedence, Answer, S)) | ||
1001 | { | ||
1002 | yield return false; | ||
1003 | } | ||
1004 | } | ||
1005 | } | ||
1006 | } | ||
1007 | |||
1008 | public static IEnumerable<bool> read_atom(object arg1, object arg2, object Precedence, object Answer, object S) | ||
1009 | { | ||
1010 | { | ||
1011 | Variable _Pos = new Variable(); | ||
1012 | Variable Number = new Variable(); | ||
1013 | Variable S1 = new Variable(); | ||
1014 | Variable Negative = new Variable(); | ||
1015 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", Atom.a("-"), _Pos))) | ||
1016 | { | ||
1017 | foreach (bool l3 in YP.unify(arg2, new ListPair(new Functor1("number", Number), S1))) | ||
1018 | { | ||
1019 | foreach (bool l4 in YP.unify(Negative, YP.negate(Number))) | ||
1020 | { | ||
1021 | foreach (bool l5 in exprtl0(S1, Negative, Precedence, Answer, S)) | ||
1022 | { | ||
1023 | yield return false; | ||
1024 | } | ||
1025 | } | ||
1026 | yield break; | ||
1027 | } | ||
1028 | } | ||
1029 | } | ||
1030 | { | ||
1031 | Variable Functor_1 = new Variable(); | ||
1032 | Variable Pos = new Variable(); | ||
1033 | Variable S1 = new Variable(); | ||
1034 | Variable Arg1 = new Variable(); | ||
1035 | Variable S2 = new Variable(); | ||
1036 | Variable RestArgs = new Variable(); | ||
1037 | Variable S3 = new Variable(); | ||
1038 | Variable Term = new Variable(); | ||
1039 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", Functor_1, Pos))) | ||
1040 | { | ||
1041 | foreach (bool l3 in YP.unify(arg2, new ListPair(Atom.a("("), S1))) | ||
1042 | { | ||
1043 | foreach (bool l4 in parse(S1, 999, Arg1, S2)) | ||
1044 | { | ||
1045 | foreach (bool l5 in read_args(S2, RestArgs, S3)) | ||
1046 | { | ||
1047 | foreach (bool l6 in YP.univ(Term, new ListPair(Functor_1, new ListPair(Pos, new ListPair(Arg1, RestArgs))))) | ||
1048 | { | ||
1049 | foreach (bool l7 in exprtl0(S3, Term, Precedence, Answer, S)) | ||
1050 | { | ||
1051 | yield return false; | ||
1052 | } | ||
1053 | } | ||
1054 | yield break; | ||
1055 | } | ||
1056 | } | ||
1057 | yield break; | ||
1058 | } | ||
1059 | } | ||
1060 | } | ||
1061 | { | ||
1062 | object S0 = arg2; | ||
1063 | Variable Op = new Variable(); | ||
1064 | Variable Pos = new Variable(); | ||
1065 | Variable Oprec = new Variable(); | ||
1066 | Variable Aprec = new Variable(); | ||
1067 | Variable Flag = new Variable(); | ||
1068 | Variable Term = new Variable(); | ||
1069 | Variable Arg = new Variable(); | ||
1070 | Variable S1 = new Variable(); | ||
1071 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", Op, Pos))) | ||
1072 | { | ||
1073 | foreach (bool l3 in prefixop(Op, Oprec, Aprec)) | ||
1074 | { | ||
1075 | foreach (bool l4 in possible_right_operand(S0, Flag)) | ||
1076 | { | ||
1077 | if (YP.lessThan(Flag, 0)) | ||
1078 | { | ||
1079 | foreach (bool l6 in YP.univ(Term, new ListPair(Op, new ListPair(Pos, Atom.NIL)))) | ||
1080 | { | ||
1081 | foreach (bool l7 in exprtl0(S0, Term, Precedence, Answer, S)) | ||
1082 | { | ||
1083 | yield return false; | ||
1084 | } | ||
1085 | } | ||
1086 | goto cutIf1; | ||
1087 | } | ||
1088 | if (YP.greaterThan(Oprec, Precedence)) | ||
1089 | { | ||
1090 | foreach (bool l6 in syntax_error(ListPair.make(new object[] { Atom.a("prefix"), Atom.a("operator"), Op, Atom.a("in"), Atom.a("context"), Atom.a("with"), Atom.a("precedence"), Precedence }), S0)) | ||
1091 | { | ||
1092 | yield return false; | ||
1093 | } | ||
1094 | goto cutIf2; | ||
1095 | } | ||
1096 | if (YP.greaterThan(Flag, 0)) | ||
1097 | { | ||
1098 | foreach (bool l6 in parse(S0, Aprec, Arg, S1)) | ||
1099 | { | ||
1100 | foreach (bool l7 in YP.univ(Term, ListPair.make(new object[] { Op, Pos, Arg }))) | ||
1101 | { | ||
1102 | foreach (bool l8 in exprtl(S1, Oprec, Term, Precedence, Answer, S)) | ||
1103 | { | ||
1104 | yield return false; | ||
1105 | } | ||
1106 | } | ||
1107 | yield break; | ||
1108 | } | ||
1109 | goto cutIf3; | ||
1110 | } | ||
1111 | foreach (bool l5 in peepop(S0, S1)) | ||
1112 | { | ||
1113 | foreach (bool l6 in prefix_is_atom(S1, Oprec)) | ||
1114 | { | ||
1115 | foreach (bool l7 in exprtl(S1, Oprec, new Functor2("/", Op, Pos), Precedence, Answer, S)) | ||
1116 | { | ||
1117 | yield return false; | ||
1118 | } | ||
1119 | } | ||
1120 | } | ||
1121 | foreach (bool l5 in parse(S0, Aprec, Arg, S1)) | ||
1122 | { | ||
1123 | foreach (bool l6 in YP.univ(Term, ListPair.make(new object[] { Op, Pos, Arg }))) | ||
1124 | { | ||
1125 | foreach (bool l7 in exprtl(S1, Oprec, Term, Precedence, Answer, S)) | ||
1126 | { | ||
1127 | yield return false; | ||
1128 | } | ||
1129 | } | ||
1130 | yield break; | ||
1131 | } | ||
1132 | cutIf3: | ||
1133 | cutIf2: | ||
1134 | cutIf1: | ||
1135 | { } | ||
1136 | } | ||
1137 | yield break; | ||
1138 | } | ||
1139 | } | ||
1140 | } | ||
1141 | { | ||
1142 | object S0 = arg2; | ||
1143 | Variable Atom_1 = new Variable(); | ||
1144 | Variable Pos = new Variable(); | ||
1145 | Variable Term = new Variable(); | ||
1146 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", Atom_1, Pos))) | ||
1147 | { | ||
1148 | foreach (bool l3 in YP.univ(Term, new ListPair(Atom_1, new ListPair(Pos, Atom.NIL)))) | ||
1149 | { | ||
1150 | foreach (bool l4 in exprtl0(S0, Term, Precedence, Answer, S)) | ||
1151 | { | ||
1152 | yield return false; | ||
1153 | } | ||
1154 | } | ||
1155 | } | ||
1156 | } | ||
1157 | } | ||
1158 | |||
1159 | public static IEnumerable<bool> cannot_start(object Token, object S0) | ||
1160 | { | ||
1161 | { | ||
1162 | foreach (bool l2 in syntax_error(ListPair.make(new object[] { Token, Atom.a("cannot"), Atom.a("start"), Atom.a("an"), Atom.a("expression") }), S0)) | ||
1163 | { | ||
1164 | yield return false; | ||
1165 | } | ||
1166 | } | ||
1167 | } | ||
1168 | |||
1169 | public static IEnumerable<bool> read_args(object arg1, object arg2, object arg3) | ||
1170 | { | ||
1171 | { | ||
1172 | object S = arg3; | ||
1173 | Variable S1 = new Variable(); | ||
1174 | Variable Term = new Variable(); | ||
1175 | Variable Rest = new Variable(); | ||
1176 | Variable S2 = new Variable(); | ||
1177 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(","), S1))) | ||
1178 | { | ||
1179 | foreach (bool l3 in YP.unify(arg2, new ListPair(Term, Rest))) | ||
1180 | { | ||
1181 | foreach (bool l4 in parse(S1, 999, Term, S2)) | ||
1182 | { | ||
1183 | foreach (bool l5 in read_args(S2, Rest, S)) | ||
1184 | { | ||
1185 | yield return false; | ||
1186 | } | ||
1187 | yield break; | ||
1188 | } | ||
1189 | yield break; | ||
1190 | } | ||
1191 | } | ||
1192 | } | ||
1193 | { | ||
1194 | object S = arg3; | ||
1195 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a(")"), S))) | ||
1196 | { | ||
1197 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
1198 | { | ||
1199 | yield return true; | ||
1200 | yield break; | ||
1201 | } | ||
1202 | } | ||
1203 | } | ||
1204 | { | ||
1205 | object S = arg1; | ||
1206 | object x2 = arg2; | ||
1207 | object x3 = arg3; | ||
1208 | foreach (bool l2 in syntax_error(ListPair.make(new object[] { Atom.a(", or )"), Atom.a("expected"), Atom.a("in"), Atom.a("arguments") }), S)) | ||
1209 | { | ||
1210 | yield return false; | ||
1211 | } | ||
1212 | } | ||
1213 | } | ||
1214 | |||
1215 | public static IEnumerable<bool> read_list(object arg1, object arg2, object arg3) | ||
1216 | { | ||
1217 | { | ||
1218 | object x1 = arg2; | ||
1219 | object x2 = arg3; | ||
1220 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1221 | { | ||
1222 | foreach (bool l3 in syntax_error(ListPair.make(new object[] { Atom.a(", | or ]"), Atom.a("expected"), Atom.a("in"), Atom.a("list") }), Atom.NIL)) | ||
1223 | { | ||
1224 | yield return false; | ||
1225 | } | ||
1226 | } | ||
1227 | } | ||
1228 | { | ||
1229 | object Rest = arg2; | ||
1230 | object S = arg3; | ||
1231 | Variable Token = new Variable(); | ||
1232 | Variable S1 = new Variable(); | ||
1233 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, S1))) | ||
1234 | { | ||
1235 | foreach (bool l3 in read_list4(Token, S1, Rest, S)) | ||
1236 | { | ||
1237 | yield return false; | ||
1238 | } | ||
1239 | } | ||
1240 | } | ||
1241 | } | ||
1242 | |||
1243 | public static IEnumerable<bool> read_list4(object arg1, object arg2, object arg3, object arg4) | ||
1244 | { | ||
1245 | { | ||
1246 | object S1 = arg2; | ||
1247 | object S = arg4; | ||
1248 | Variable Term = new Variable(); | ||
1249 | Variable Rest = new Variable(); | ||
1250 | Variable S2 = new Variable(); | ||
1251 | foreach (bool l2 in YP.unify(arg1, Atom.a(","))) | ||
1252 | { | ||
1253 | foreach (bool l3 in YP.unify(arg3, new ListPair(Term, Rest))) | ||
1254 | { | ||
1255 | foreach (bool l4 in parse(S1, 999, Term, S2)) | ||
1256 | { | ||
1257 | foreach (bool l5 in read_list(S2, Rest, S)) | ||
1258 | { | ||
1259 | yield return false; | ||
1260 | } | ||
1261 | yield break; | ||
1262 | } | ||
1263 | yield break; | ||
1264 | } | ||
1265 | } | ||
1266 | } | ||
1267 | { | ||
1268 | object S1 = arg2; | ||
1269 | object Rest = arg3; | ||
1270 | object S = arg4; | ||
1271 | Variable S2 = new Variable(); | ||
1272 | foreach (bool l2 in YP.unify(arg1, Atom.a("|"))) | ||
1273 | { | ||
1274 | foreach (bool l3 in parse(S1, 999, Rest, S2)) | ||
1275 | { | ||
1276 | foreach (bool l4 in expect(Atom.a("]"), S2, S)) | ||
1277 | { | ||
1278 | yield return false; | ||
1279 | } | ||
1280 | yield break; | ||
1281 | } | ||
1282 | yield break; | ||
1283 | } | ||
1284 | } | ||
1285 | { | ||
1286 | Variable S1 = new Variable(); | ||
1287 | foreach (bool l2 in YP.unify(arg1, Atom.a("]"))) | ||
1288 | { | ||
1289 | foreach (bool l3 in YP.unify(arg2, S1)) | ||
1290 | { | ||
1291 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
1292 | { | ||
1293 | foreach (bool l5 in YP.unify(arg4, S1)) | ||
1294 | { | ||
1295 | yield return true; | ||
1296 | yield break; | ||
1297 | } | ||
1298 | } | ||
1299 | } | ||
1300 | } | ||
1301 | } | ||
1302 | { | ||
1303 | object Token = arg1; | ||
1304 | object S1 = arg2; | ||
1305 | object x3 = arg3; | ||
1306 | object x4 = arg4; | ||
1307 | foreach (bool l2 in syntax_error(ListPair.make(new object[] { Atom.a(", | or ]"), Atom.a("expected"), Atom.a("in"), Atom.a("list") }), new ListPair(Token, S1))) | ||
1308 | { | ||
1309 | yield return false; | ||
1310 | } | ||
1311 | } | ||
1312 | } | ||
1313 | |||
1314 | public static IEnumerable<bool> possible_right_operand(object arg1, object arg2) | ||
1315 | { | ||
1316 | { | ||
1317 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1318 | { | ||
1319 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1320 | { | ||
1321 | yield return false; | ||
1322 | } | ||
1323 | } | ||
1324 | } | ||
1325 | { | ||
1326 | object Flag = arg2; | ||
1327 | Variable H = new Variable(); | ||
1328 | Variable T = new Variable(); | ||
1329 | foreach (bool l2 in YP.unify(arg1, new ListPair(H, T))) | ||
1330 | { | ||
1331 | foreach (bool l3 in possible_right_operand3(H, Flag, T)) | ||
1332 | { | ||
1333 | yield return false; | ||
1334 | } | ||
1335 | } | ||
1336 | } | ||
1337 | } | ||
1338 | |||
1339 | public static IEnumerable<bool> possible_right_operand3(object arg1, object arg2, object arg3) | ||
1340 | { | ||
1341 | { | ||
1342 | object x4 = arg3; | ||
1343 | Variable x1 = new Variable(); | ||
1344 | Variable x2 = new Variable(); | ||
1345 | Variable x3 = new Variable(); | ||
1346 | foreach (bool l2 in YP.unify(arg1, new Functor3("var", x1, x2, x3))) | ||
1347 | { | ||
1348 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1349 | { | ||
1350 | yield return false; | ||
1351 | } | ||
1352 | } | ||
1353 | } | ||
1354 | { | ||
1355 | object x2 = arg3; | ||
1356 | Variable x1 = new Variable(); | ||
1357 | foreach (bool l2 in YP.unify(arg1, new Functor1("number", x1))) | ||
1358 | { | ||
1359 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1360 | { | ||
1361 | yield return false; | ||
1362 | } | ||
1363 | } | ||
1364 | } | ||
1365 | { | ||
1366 | object x2 = arg3; | ||
1367 | Variable x1 = new Variable(); | ||
1368 | foreach (bool l2 in YP.unify(arg1, new Functor1("string", x1))) | ||
1369 | { | ||
1370 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1371 | { | ||
1372 | yield return false; | ||
1373 | } | ||
1374 | } | ||
1375 | } | ||
1376 | { | ||
1377 | object x1 = arg3; | ||
1378 | foreach (bool l2 in YP.unify(arg1, Atom.a(" ("))) | ||
1379 | { | ||
1380 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1381 | { | ||
1382 | yield return false; | ||
1383 | } | ||
1384 | } | ||
1385 | } | ||
1386 | { | ||
1387 | object x1 = arg3; | ||
1388 | foreach (bool l2 in YP.unify(arg1, Atom.a("("))) | ||
1389 | { | ||
1390 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
1391 | { | ||
1392 | yield return false; | ||
1393 | } | ||
1394 | } | ||
1395 | } | ||
1396 | { | ||
1397 | object x1 = arg3; | ||
1398 | foreach (bool l2 in YP.unify(arg1, Atom.a(")"))) | ||
1399 | { | ||
1400 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1401 | { | ||
1402 | yield return false; | ||
1403 | } | ||
1404 | } | ||
1405 | } | ||
1406 | { | ||
1407 | Variable x1 = new Variable(); | ||
1408 | foreach (bool l2 in YP.unify(arg1, Atom.a("["))) | ||
1409 | { | ||
1410 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
1411 | { | ||
1412 | foreach (bool l4 in YP.unify(arg3, new ListPair(Atom.a("]"), x1))) | ||
1413 | { | ||
1414 | yield return true; | ||
1415 | yield break; | ||
1416 | } | ||
1417 | } | ||
1418 | } | ||
1419 | } | ||
1420 | { | ||
1421 | object x1 = arg3; | ||
1422 | foreach (bool l2 in YP.unify(arg1, Atom.a("["))) | ||
1423 | { | ||
1424 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1425 | { | ||
1426 | yield return false; | ||
1427 | } | ||
1428 | } | ||
1429 | } | ||
1430 | { | ||
1431 | object x1 = arg3; | ||
1432 | foreach (bool l2 in YP.unify(arg1, Atom.a("]"))) | ||
1433 | { | ||
1434 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1435 | { | ||
1436 | yield return false; | ||
1437 | } | ||
1438 | } | ||
1439 | } | ||
1440 | { | ||
1441 | Variable x1 = new Variable(); | ||
1442 | foreach (bool l2 in YP.unify(arg1, Atom.a("{"))) | ||
1443 | { | ||
1444 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
1445 | { | ||
1446 | foreach (bool l4 in YP.unify(arg3, new ListPair(Atom.a("}"), x1))) | ||
1447 | { | ||
1448 | yield return true; | ||
1449 | yield break; | ||
1450 | } | ||
1451 | } | ||
1452 | } | ||
1453 | } | ||
1454 | { | ||
1455 | object x1 = arg3; | ||
1456 | foreach (bool l2 in YP.unify(arg1, Atom.a("{"))) | ||
1457 | { | ||
1458 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
1459 | { | ||
1460 | yield return false; | ||
1461 | } | ||
1462 | } | ||
1463 | } | ||
1464 | { | ||
1465 | object x1 = arg3; | ||
1466 | foreach (bool l2 in YP.unify(arg1, Atom.a("}"))) | ||
1467 | { | ||
1468 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1469 | { | ||
1470 | yield return false; | ||
1471 | } | ||
1472 | } | ||
1473 | } | ||
1474 | { | ||
1475 | object x1 = arg3; | ||
1476 | foreach (bool l2 in YP.unify(arg1, Atom.a(","))) | ||
1477 | { | ||
1478 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1479 | { | ||
1480 | yield return false; | ||
1481 | } | ||
1482 | } | ||
1483 | } | ||
1484 | { | ||
1485 | object x1 = arg3; | ||
1486 | foreach (bool l2 in YP.unify(arg1, Atom.a("|"))) | ||
1487 | { | ||
1488 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
1489 | { | ||
1490 | yield return false; | ||
1491 | } | ||
1492 | } | ||
1493 | } | ||
1494 | { | ||
1495 | object x3 = arg3; | ||
1496 | Variable x1 = new Variable(); | ||
1497 | Variable x2 = new Variable(); | ||
1498 | foreach (bool l2 in YP.unify(arg1, new Functor2("atom", x1, x2))) | ||
1499 | { | ||
1500 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
1501 | { | ||
1502 | yield return false; | ||
1503 | } | ||
1504 | } | ||
1505 | } | ||
1506 | } | ||
1507 | |||
1508 | public static IEnumerable<bool> peepop(object arg1, object arg2) | ||
1509 | { | ||
1510 | { | ||
1511 | Variable F = new Variable(); | ||
1512 | Variable Pos = new Variable(); | ||
1513 | Variable S1 = new Variable(); | ||
1514 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("atom", F, Pos), new ListPair(Atom.a("("), S1)))) | ||
1515 | { | ||
1516 | foreach (bool l3 in YP.unify(arg2, new ListPair(new Functor2("atom", F, Pos), new ListPair(Atom.a("("), S1)))) | ||
1517 | { | ||
1518 | yield return true; | ||
1519 | yield break; | ||
1520 | } | ||
1521 | } | ||
1522 | } | ||
1523 | { | ||
1524 | Variable F = new Variable(); | ||
1525 | Variable Pos = new Variable(); | ||
1526 | Variable S1 = new Variable(); | ||
1527 | Variable L = new Variable(); | ||
1528 | Variable P = new Variable(); | ||
1529 | Variable R = new Variable(); | ||
1530 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("atom", F, Pos), S1))) | ||
1531 | { | ||
1532 | foreach (bool l3 in YP.unify(arg2, new ListPair(new Functor(Atom.a("infixop", Atom.a("")), new object[] { new Functor2("/", F, Pos), L, P, R }), S1))) | ||
1533 | { | ||
1534 | foreach (bool l4 in infixop(F, L, P, R)) | ||
1535 | { | ||
1536 | yield return false; | ||
1537 | } | ||
1538 | } | ||
1539 | } | ||
1540 | } | ||
1541 | { | ||
1542 | Variable F = new Variable(); | ||
1543 | Variable Pos = new Variable(); | ||
1544 | Variable S1 = new Variable(); | ||
1545 | Variable L = new Variable(); | ||
1546 | Variable P = new Variable(); | ||
1547 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("atom", F, Pos), S1))) | ||
1548 | { | ||
1549 | foreach (bool l3 in YP.unify(arg2, new ListPair(new Functor3(Atom.a("postfixop", Atom.a("")), new Functor2("/", F, Pos), L, P), S1))) | ||
1550 | { | ||
1551 | foreach (bool l4 in postfixop(F, L, P)) | ||
1552 | { | ||
1553 | yield return false; | ||
1554 | } | ||
1555 | } | ||
1556 | } | ||
1557 | } | ||
1558 | { | ||
1559 | Variable S0 = new Variable(); | ||
1560 | foreach (bool l2 in YP.unify(arg1, S0)) | ||
1561 | { | ||
1562 | foreach (bool l3 in YP.unify(arg2, S0)) | ||
1563 | { | ||
1564 | yield return false; | ||
1565 | } | ||
1566 | } | ||
1567 | } | ||
1568 | } | ||
1569 | |||
1570 | public static IEnumerable<bool> prefix_is_atom(object arg1, object arg2) | ||
1571 | { | ||
1572 | { | ||
1573 | object Precedence = arg2; | ||
1574 | Variable Token = new Variable(); | ||
1575 | Variable x2 = new Variable(); | ||
1576 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, x2))) | ||
1577 | { | ||
1578 | foreach (bool l3 in prefix_is_atom(Token, Precedence)) | ||
1579 | { | ||
1580 | yield return false; | ||
1581 | } | ||
1582 | } | ||
1583 | } | ||
1584 | { | ||
1585 | object P = arg2; | ||
1586 | Variable x1 = new Variable(); | ||
1587 | Variable L = new Variable(); | ||
1588 | Variable x3 = new Variable(); | ||
1589 | Variable x4 = new Variable(); | ||
1590 | foreach (bool l2 in YP.unify(arg1, new Functor(Atom.a("infixop", Atom.a("")), new object[] { x1, L, x3, x4 }))) | ||
1591 | { | ||
1592 | if (YP.greaterThanOrEqual(L, P)) | ||
1593 | { | ||
1594 | yield return false; | ||
1595 | } | ||
1596 | } | ||
1597 | } | ||
1598 | { | ||
1599 | object P = arg2; | ||
1600 | Variable x1 = new Variable(); | ||
1601 | Variable L = new Variable(); | ||
1602 | Variable x3 = new Variable(); | ||
1603 | foreach (bool l2 in YP.unify(arg1, new Functor3(Atom.a("postfixop", Atom.a("")), x1, L, x3))) | ||
1604 | { | ||
1605 | if (YP.greaterThanOrEqual(L, P)) | ||
1606 | { | ||
1607 | yield return false; | ||
1608 | } | ||
1609 | } | ||
1610 | } | ||
1611 | { | ||
1612 | object x1 = arg2; | ||
1613 | foreach (bool l2 in YP.unify(arg1, Atom.a(")"))) | ||
1614 | { | ||
1615 | yield return false; | ||
1616 | } | ||
1617 | } | ||
1618 | { | ||
1619 | object x1 = arg2; | ||
1620 | foreach (bool l2 in YP.unify(arg1, Atom.a("]"))) | ||
1621 | { | ||
1622 | yield return false; | ||
1623 | } | ||
1624 | } | ||
1625 | { | ||
1626 | object x1 = arg2; | ||
1627 | foreach (bool l2 in YP.unify(arg1, Atom.a("}"))) | ||
1628 | { | ||
1629 | yield return false; | ||
1630 | } | ||
1631 | } | ||
1632 | { | ||
1633 | object P = arg2; | ||
1634 | foreach (bool l2 in YP.unify(arg1, Atom.a("|"))) | ||
1635 | { | ||
1636 | if (YP.greaterThanOrEqual(1100, P)) | ||
1637 | { | ||
1638 | yield return false; | ||
1639 | } | ||
1640 | } | ||
1641 | } | ||
1642 | { | ||
1643 | object P = arg2; | ||
1644 | foreach (bool l2 in YP.unify(arg1, Atom.a(","))) | ||
1645 | { | ||
1646 | if (YP.greaterThanOrEqual(1000, P)) | ||
1647 | { | ||
1648 | yield return false; | ||
1649 | } | ||
1650 | } | ||
1651 | } | ||
1652 | { | ||
1653 | object x1 = arg2; | ||
1654 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1655 | { | ||
1656 | yield return false; | ||
1657 | } | ||
1658 | } | ||
1659 | } | ||
1660 | |||
1661 | public static IEnumerable<bool> exprtl0(object arg1, object arg2, object arg3, object arg4, object arg5) | ||
1662 | { | ||
1663 | { | ||
1664 | object x2 = arg3; | ||
1665 | Variable Term = new Variable(); | ||
1666 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1667 | { | ||
1668 | foreach (bool l3 in YP.unify(arg2, Term)) | ||
1669 | { | ||
1670 | foreach (bool l4 in YP.unify(arg4, Term)) | ||
1671 | { | ||
1672 | foreach (bool l5 in YP.unify(arg5, Atom.NIL)) | ||
1673 | { | ||
1674 | yield return false; | ||
1675 | } | ||
1676 | } | ||
1677 | } | ||
1678 | } | ||
1679 | } | ||
1680 | { | ||
1681 | object Term = arg2; | ||
1682 | object Precedence = arg3; | ||
1683 | object Answer = arg4; | ||
1684 | object S = arg5; | ||
1685 | Variable Token = new Variable(); | ||
1686 | Variable S1 = new Variable(); | ||
1687 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, S1))) | ||
1688 | { | ||
1689 | foreach (bool l3 in exprtl0_6(Token, Term, Precedence, Answer, S, S1)) | ||
1690 | { | ||
1691 | yield return false; | ||
1692 | } | ||
1693 | } | ||
1694 | } | ||
1695 | } | ||
1696 | |||
1697 | public static IEnumerable<bool> exprtl0_6(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6) | ||
1698 | { | ||
1699 | { | ||
1700 | object x2 = arg3; | ||
1701 | object S1 = arg6; | ||
1702 | Variable Term = new Variable(); | ||
1703 | foreach (bool l2 in YP.unify(arg1, Atom.a("}"))) | ||
1704 | { | ||
1705 | foreach (bool l3 in YP.unify(arg2, Term)) | ||
1706 | { | ||
1707 | foreach (bool l4 in YP.unify(arg4, Term)) | ||
1708 | { | ||
1709 | foreach (bool l5 in YP.unify(arg5, new ListPair(Atom.a("}"), S1))) | ||
1710 | { | ||
1711 | yield return false; | ||
1712 | } | ||
1713 | } | ||
1714 | } | ||
1715 | } | ||
1716 | } | ||
1717 | { | ||
1718 | object x2 = arg3; | ||
1719 | object S1 = arg6; | ||
1720 | Variable Term = new Variable(); | ||
1721 | foreach (bool l2 in YP.unify(arg1, Atom.a("]"))) | ||
1722 | { | ||
1723 | foreach (bool l3 in YP.unify(arg2, Term)) | ||
1724 | { | ||
1725 | foreach (bool l4 in YP.unify(arg4, Term)) | ||
1726 | { | ||
1727 | foreach (bool l5 in YP.unify(arg5, new ListPair(Atom.a("]"), S1))) | ||
1728 | { | ||
1729 | yield return false; | ||
1730 | } | ||
1731 | } | ||
1732 | } | ||
1733 | } | ||
1734 | } | ||
1735 | { | ||
1736 | object x2 = arg3; | ||
1737 | object S1 = arg6; | ||
1738 | Variable Term = new Variable(); | ||
1739 | foreach (bool l2 in YP.unify(arg1, Atom.a(")"))) | ||
1740 | { | ||
1741 | foreach (bool l3 in YP.unify(arg2, Term)) | ||
1742 | { | ||
1743 | foreach (bool l4 in YP.unify(arg4, Term)) | ||
1744 | { | ||
1745 | foreach (bool l5 in YP.unify(arg5, new ListPair(Atom.a(")"), S1))) | ||
1746 | { | ||
1747 | yield return false; | ||
1748 | } | ||
1749 | } | ||
1750 | } | ||
1751 | } | ||
1752 | } | ||
1753 | { | ||
1754 | object Term = arg2; | ||
1755 | object Precedence = arg3; | ||
1756 | object Answer = arg4; | ||
1757 | object S = arg5; | ||
1758 | object S1 = arg6; | ||
1759 | Variable Next = new Variable(); | ||
1760 | Variable S2 = new Variable(); | ||
1761 | foreach (bool l2 in YP.unify(arg1, Atom.a(","))) | ||
1762 | { | ||
1763 | if (YP.greaterThanOrEqual(Precedence, 1000)) | ||
1764 | { | ||
1765 | foreach (bool l4 in parse(S1, 1000, Next, S2)) | ||
1766 | { | ||
1767 | foreach (bool l5 in exprtl(S2, 1000, new Functor2(",", Term, Next), Precedence, Answer, S)) | ||
1768 | { | ||
1769 | yield return false; | ||
1770 | } | ||
1771 | yield break; | ||
1772 | } | ||
1773 | goto cutIf1; | ||
1774 | } | ||
1775 | foreach (bool l3 in YP.unify(Answer, Term)) | ||
1776 | { | ||
1777 | foreach (bool l4 in YP.unify(S, new ListPair(Atom.a(","), S1))) | ||
1778 | { | ||
1779 | yield return false; | ||
1780 | } | ||
1781 | } | ||
1782 | cutIf1: | ||
1783 | { } | ||
1784 | } | ||
1785 | } | ||
1786 | { | ||
1787 | object Term = arg2; | ||
1788 | object Precedence = arg3; | ||
1789 | object Answer = arg4; | ||
1790 | object S = arg5; | ||
1791 | object S1 = arg6; | ||
1792 | Variable Next = new Variable(); | ||
1793 | Variable S2 = new Variable(); | ||
1794 | foreach (bool l2 in YP.unify(arg1, Atom.a("|"))) | ||
1795 | { | ||
1796 | if (YP.greaterThanOrEqual(Precedence, 1100)) | ||
1797 | { | ||
1798 | foreach (bool l4 in parse(S1, 1100, Next, S2)) | ||
1799 | { | ||
1800 | foreach (bool l5 in exprtl(S2, 1100, new Functor2(";", Term, Next), Precedence, Answer, S)) | ||
1801 | { | ||
1802 | yield return false; | ||
1803 | } | ||
1804 | yield break; | ||
1805 | } | ||
1806 | goto cutIf2; | ||
1807 | } | ||
1808 | foreach (bool l3 in YP.unify(Answer, Term)) | ||
1809 | { | ||
1810 | foreach (bool l4 in YP.unify(S, new ListPair(Atom.a("|"), S1))) | ||
1811 | { | ||
1812 | yield return false; | ||
1813 | } | ||
1814 | } | ||
1815 | cutIf2: | ||
1816 | { } | ||
1817 | } | ||
1818 | } | ||
1819 | { | ||
1820 | object x2 = arg2; | ||
1821 | object x3 = arg3; | ||
1822 | object x4 = arg4; | ||
1823 | object x5 = arg5; | ||
1824 | object S1 = arg6; | ||
1825 | Variable S = new Variable(); | ||
1826 | foreach (bool l2 in YP.unify(arg1, new Functor1("string", S))) | ||
1827 | { | ||
1828 | foreach (bool l3 in cannot_follow(Atom.a("chars"), new Functor1("string", S), S1)) | ||
1829 | { | ||
1830 | yield return false; | ||
1831 | } | ||
1832 | } | ||
1833 | } | ||
1834 | { | ||
1835 | object x2 = arg2; | ||
1836 | object x3 = arg3; | ||
1837 | object x4 = arg4; | ||
1838 | object x5 = arg5; | ||
1839 | object S1 = arg6; | ||
1840 | Variable N = new Variable(); | ||
1841 | foreach (bool l2 in YP.unify(arg1, new Functor1("number", N))) | ||
1842 | { | ||
1843 | foreach (bool l3 in cannot_follow(Atom.a("number"), new Functor1("number", N), S1)) | ||
1844 | { | ||
1845 | yield return false; | ||
1846 | } | ||
1847 | } | ||
1848 | } | ||
1849 | { | ||
1850 | object Term = arg2; | ||
1851 | object Precedence = arg3; | ||
1852 | object Answer = arg4; | ||
1853 | object S = arg5; | ||
1854 | Variable S1 = new Variable(); | ||
1855 | foreach (bool l2 in YP.unify(arg1, Atom.a("{"))) | ||
1856 | { | ||
1857 | foreach (bool l3 in YP.unify(arg6, new ListPair(Atom.a("}"), S1))) | ||
1858 | { | ||
1859 | foreach (bool l4 in exprtl0_atom(Atom.a("{}"), Term, Precedence, Answer, S, S1)) | ||
1860 | { | ||
1861 | yield return false; | ||
1862 | } | ||
1863 | yield break; | ||
1864 | } | ||
1865 | } | ||
1866 | } | ||
1867 | { | ||
1868 | object x1 = arg2; | ||
1869 | object x2 = arg3; | ||
1870 | object x3 = arg4; | ||
1871 | object x4 = arg5; | ||
1872 | object S1 = arg6; | ||
1873 | foreach (bool l2 in YP.unify(arg1, Atom.a("{"))) | ||
1874 | { | ||
1875 | foreach (bool l3 in cannot_follow(Atom.a("brace"), Atom.a("{"), S1)) | ||
1876 | { | ||
1877 | yield return false; | ||
1878 | } | ||
1879 | } | ||
1880 | } | ||
1881 | { | ||
1882 | object Term = arg2; | ||
1883 | object Precedence = arg3; | ||
1884 | object Answer = arg4; | ||
1885 | object S = arg5; | ||
1886 | Variable S1 = new Variable(); | ||
1887 | foreach (bool l2 in YP.unify(arg1, Atom.a("["))) | ||
1888 | { | ||
1889 | foreach (bool l3 in YP.unify(arg6, new ListPair(Atom.a("]"), S1))) | ||
1890 | { | ||
1891 | foreach (bool l4 in exprtl0_atom(Atom.NIL, Term, Precedence, Answer, S, S1)) | ||
1892 | { | ||
1893 | yield return false; | ||
1894 | } | ||
1895 | yield break; | ||
1896 | } | ||
1897 | } | ||
1898 | } | ||
1899 | { | ||
1900 | object x1 = arg2; | ||
1901 | object x2 = arg3; | ||
1902 | object x3 = arg4; | ||
1903 | object x4 = arg5; | ||
1904 | object S1 = arg6; | ||
1905 | foreach (bool l2 in YP.unify(arg1, Atom.a("["))) | ||
1906 | { | ||
1907 | foreach (bool l3 in cannot_follow(Atom.a("bracket"), Atom.a("["), S1)) | ||
1908 | { | ||
1909 | yield return false; | ||
1910 | } | ||
1911 | } | ||
1912 | } | ||
1913 | { | ||
1914 | object x1 = arg2; | ||
1915 | object x2 = arg3; | ||
1916 | object x3 = arg4; | ||
1917 | object x4 = arg5; | ||
1918 | object S1 = arg6; | ||
1919 | foreach (bool l2 in YP.unify(arg1, Atom.a("("))) | ||
1920 | { | ||
1921 | foreach (bool l3 in cannot_follow(Atom.a("parenthesis"), Atom.a("("), S1)) | ||
1922 | { | ||
1923 | yield return false; | ||
1924 | } | ||
1925 | } | ||
1926 | } | ||
1927 | { | ||
1928 | object x1 = arg2; | ||
1929 | object x2 = arg3; | ||
1930 | object x3 = arg4; | ||
1931 | object x4 = arg5; | ||
1932 | object S1 = arg6; | ||
1933 | foreach (bool l2 in YP.unify(arg1, Atom.a(" ("))) | ||
1934 | { | ||
1935 | foreach (bool l3 in cannot_follow(Atom.a("parenthesis"), Atom.a("("), S1)) | ||
1936 | { | ||
1937 | yield return false; | ||
1938 | } | ||
1939 | } | ||
1940 | } | ||
1941 | { | ||
1942 | object x4 = arg2; | ||
1943 | object x5 = arg3; | ||
1944 | object x6 = arg4; | ||
1945 | object x7 = arg5; | ||
1946 | object S1 = arg6; | ||
1947 | Variable A = new Variable(); | ||
1948 | Variable B = new Variable(); | ||
1949 | Variable P = new Variable(); | ||
1950 | foreach (bool l2 in YP.unify(arg1, new Functor3("var", A, B, P))) | ||
1951 | { | ||
1952 | foreach (bool l3 in cannot_follow(Atom.a("variable"), new Functor3("var", A, B, P), S1)) | ||
1953 | { | ||
1954 | yield return false; | ||
1955 | } | ||
1956 | } | ||
1957 | } | ||
1958 | { | ||
1959 | object Term = arg2; | ||
1960 | object Precedence = arg3; | ||
1961 | object Answer = arg4; | ||
1962 | object S = arg5; | ||
1963 | object S1 = arg6; | ||
1964 | Variable F = new Variable(); | ||
1965 | Variable P = new Variable(); | ||
1966 | foreach (bool l2 in YP.unify(arg1, new Functor2("atom", F, P))) | ||
1967 | { | ||
1968 | foreach (bool l3 in exprtl0_atom(new Functor2("/", F, P), Term, Precedence, Answer, S, S1)) | ||
1969 | { | ||
1970 | yield return false; | ||
1971 | } | ||
1972 | } | ||
1973 | } | ||
1974 | } | ||
1975 | |||
1976 | public static IEnumerable<bool> exprtl0_atom(object arg1, object arg2, object arg3, object arg4, object arg5, object S1) | ||
1977 | { | ||
1978 | { | ||
1979 | object Term = arg2; | ||
1980 | object Precedence = arg3; | ||
1981 | object Answer = arg4; | ||
1982 | object S = arg5; | ||
1983 | Variable F = new Variable(); | ||
1984 | Variable Pos = new Variable(); | ||
1985 | Variable L1 = new Variable(); | ||
1986 | Variable O1 = new Variable(); | ||
1987 | Variable R1 = new Variable(); | ||
1988 | Variable L2 = new Variable(); | ||
1989 | Variable O2 = new Variable(); | ||
1990 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", F, Pos))) | ||
1991 | { | ||
1992 | foreach (bool l3 in ambigop(F, Precedence, L1, O1, R1, L2, O2)) | ||
1993 | { | ||
1994 | foreach (bool l4 in prefix_is_atom(S1, Precedence)) | ||
1995 | { | ||
1996 | foreach (bool l5 in exprtl(new ListPair(new Functor3(Atom.a("postfixop", Atom.a("")), new Functor2("/", F, Pos), L2, O2), S1), 0, Term, Precedence, Answer, S)) | ||
1997 | { | ||
1998 | yield return false; | ||
1999 | } | ||
2000 | yield break; | ||
2001 | } | ||
2002 | foreach (bool l4 in exprtl(new ListPair(new Functor(Atom.a("infixop", Atom.a("")), new object[] { new Functor2("/", F, Pos), L1, O1, R1 }), S1), 0, Term, Precedence, Answer, S)) | ||
2003 | { | ||
2004 | yield return false; | ||
2005 | } | ||
2006 | foreach (bool l4 in exprtl(new ListPair(new Functor3(Atom.a("postfixop", Atom.a("")), new Functor2("/", F, Pos), L2, O2), S1), 0, Term, Precedence, Answer, S)) | ||
2007 | { | ||
2008 | yield return false; | ||
2009 | } | ||
2010 | yield break; | ||
2011 | } | ||
2012 | } | ||
2013 | } | ||
2014 | { | ||
2015 | object Term = arg2; | ||
2016 | object Precedence = arg3; | ||
2017 | object Answer = arg4; | ||
2018 | object S = arg5; | ||
2019 | Variable F = new Variable(); | ||
2020 | Variable Pos = new Variable(); | ||
2021 | Variable L1 = new Variable(); | ||
2022 | Variable O1 = new Variable(); | ||
2023 | Variable R1 = new Variable(); | ||
2024 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", F, Pos))) | ||
2025 | { | ||
2026 | foreach (bool l3 in infixop(F, L1, O1, R1)) | ||
2027 | { | ||
2028 | foreach (bool l4 in exprtl(new ListPair(new Functor(Atom.a("infixop", Atom.a("")), new object[] { new Functor2("/", F, Pos), L1, O1, R1 }), S1), 0, Term, Precedence, Answer, S)) | ||
2029 | { | ||
2030 | yield return false; | ||
2031 | } | ||
2032 | yield break; | ||
2033 | } | ||
2034 | } | ||
2035 | } | ||
2036 | { | ||
2037 | object Term = arg2; | ||
2038 | object Precedence = arg3; | ||
2039 | object Answer = arg4; | ||
2040 | object S = arg5; | ||
2041 | Variable F = new Variable(); | ||
2042 | Variable Pos = new Variable(); | ||
2043 | Variable L2 = new Variable(); | ||
2044 | Variable O2 = new Variable(); | ||
2045 | foreach (bool l2 in YP.unify(arg1, new Functor2("/", F, Pos))) | ||
2046 | { | ||
2047 | foreach (bool l3 in postfixop(F, L2, O2)) | ||
2048 | { | ||
2049 | foreach (bool l4 in exprtl(new ListPair(new Functor3(Atom.a("postfixop", Atom.a("")), new Functor2("/", F, Pos), L2, O2), S1), 0, Term, Precedence, Answer, S)) | ||
2050 | { | ||
2051 | yield return false; | ||
2052 | } | ||
2053 | yield break; | ||
2054 | } | ||
2055 | } | ||
2056 | } | ||
2057 | { | ||
2058 | object X = arg1; | ||
2059 | object x2 = arg2; | ||
2060 | object x3 = arg3; | ||
2061 | object x4 = arg4; | ||
2062 | object x5 = arg5; | ||
2063 | Variable x7 = new Variable(); | ||
2064 | foreach (bool l2 in syntax_error(ListPair.make(new object[] { new Functor2("-", Atom.a("non"), Atom.a("operator")), X, Atom.a("follows"), Atom.a("expression") }), new ListPair(new Functor2("atom", X, x7), S1))) | ||
2065 | { | ||
2066 | yield return false; | ||
2067 | } | ||
2068 | yield break; | ||
2069 | } | ||
2070 | } | ||
2071 | |||
2072 | public static IEnumerable<bool> cannot_follow(object Type, object Token, object Tokens) | ||
2073 | { | ||
2074 | { | ||
2075 | foreach (bool l2 in syntax_error(ListPair.make(new object[] { Type, Atom.a("follows"), Atom.a("expression") }), new ListPair(Token, Tokens))) | ||
2076 | { | ||
2077 | yield return false; | ||
2078 | } | ||
2079 | } | ||
2080 | } | ||
2081 | |||
2082 | public static IEnumerable<bool> exprtl(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6) | ||
2083 | { | ||
2084 | { | ||
2085 | object x1 = arg2; | ||
2086 | object x3 = arg4; | ||
2087 | Variable Term = new Variable(); | ||
2088 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
2089 | { | ||
2090 | foreach (bool l3 in YP.unify(arg3, Term)) | ||
2091 | { | ||
2092 | foreach (bool l4 in YP.unify(arg5, Term)) | ||
2093 | { | ||
2094 | foreach (bool l5 in YP.unify(arg6, Atom.NIL)) | ||
2095 | { | ||
2096 | yield return false; | ||
2097 | } | ||
2098 | } | ||
2099 | } | ||
2100 | } | ||
2101 | } | ||
2102 | { | ||
2103 | object C = arg2; | ||
2104 | object Term = arg3; | ||
2105 | object Precedence = arg4; | ||
2106 | object Answer = arg5; | ||
2107 | object S = arg6; | ||
2108 | Variable Token = new Variable(); | ||
2109 | Variable Tokens = new Variable(); | ||
2110 | foreach (bool l2 in YP.unify(arg1, new ListPair(Token, Tokens))) | ||
2111 | { | ||
2112 | foreach (bool l3 in exprtl_7(Token, C, Term, Precedence, Answer, S, Tokens)) | ||
2113 | { | ||
2114 | yield return false; | ||
2115 | } | ||
2116 | } | ||
2117 | } | ||
2118 | } | ||
2119 | |||
2120 | public static IEnumerable<bool> exprtl_7(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7) | ||
2121 | { | ||
2122 | { | ||
2123 | object C = arg2; | ||
2124 | object Term = arg3; | ||
2125 | object Precedence = arg4; | ||
2126 | object Answer = arg5; | ||
2127 | object S = arg6; | ||
2128 | object S1 = arg7; | ||
2129 | Variable F = new Variable(); | ||
2130 | Variable Pos = new Variable(); | ||
2131 | Variable L = new Variable(); | ||
2132 | Variable O = new Variable(); | ||
2133 | Variable R = new Variable(); | ||
2134 | Variable Other = new Variable(); | ||
2135 | Variable S2 = new Variable(); | ||
2136 | Variable Expr = new Variable(); | ||
2137 | foreach (bool l2 in YP.unify(arg1, new Functor(Atom.a("infixop", Atom.a("")), new object[] { new Functor2("/", F, Pos), L, O, R }))) | ||
2138 | { | ||
2139 | if (YP.greaterThanOrEqual(Precedence, O)) | ||
2140 | { | ||
2141 | if (YP.lessThanOrEqual(C, L)) | ||
2142 | { | ||
2143 | foreach (bool l5 in parse(S1, R, Other, S2)) | ||
2144 | { | ||
2145 | foreach (bool l6 in YP.univ(Expr, ListPair.make(new object[] { F, Pos, Term, Other }))) | ||
2146 | { | ||
2147 | foreach (bool l7 in exprtl(S2, O, Expr, Precedence, Answer, S)) | ||
2148 | { | ||
2149 | yield return false; | ||
2150 | } | ||
2151 | } | ||
2152 | } | ||
2153 | yield break; | ||
2154 | } | ||
2155 | } | ||
2156 | } | ||
2157 | } | ||
2158 | { | ||
2159 | object C = arg2; | ||
2160 | object Term = arg3; | ||
2161 | object Precedence = arg4; | ||
2162 | object Answer = arg5; | ||
2163 | object S = arg6; | ||
2164 | object S1 = arg7; | ||
2165 | Variable F = new Variable(); | ||
2166 | Variable Pos = new Variable(); | ||
2167 | Variable L = new Variable(); | ||
2168 | Variable O = new Variable(); | ||
2169 | Variable Expr = new Variable(); | ||
2170 | Variable S2 = new Variable(); | ||
2171 | foreach (bool l2 in YP.unify(arg1, new Functor3(Atom.a("postfixop", Atom.a("")), new Functor2("/", F, Pos), L, O))) | ||
2172 | { | ||
2173 | if (YP.greaterThanOrEqual(Precedence, O)) | ||
2174 | { | ||
2175 | if (YP.lessThanOrEqual(C, L)) | ||
2176 | { | ||
2177 | foreach (bool l5 in YP.univ(Expr, ListPair.make(new object[] { F, Pos, Term }))) | ||
2178 | { | ||
2179 | foreach (bool l6 in peepop(S1, S2)) | ||
2180 | { | ||
2181 | foreach (bool l7 in exprtl(S2, O, Expr, Precedence, Answer, S)) | ||
2182 | { | ||
2183 | yield return false; | ||
2184 | } | ||
2185 | } | ||
2186 | } | ||
2187 | yield break; | ||
2188 | } | ||
2189 | } | ||
2190 | } | ||
2191 | } | ||
2192 | { | ||
2193 | object C = arg2; | ||
2194 | object Term = arg3; | ||
2195 | object Precedence = arg4; | ||
2196 | object Answer = arg5; | ||
2197 | object S = arg6; | ||
2198 | object S1 = arg7; | ||
2199 | Variable Next = new Variable(); | ||
2200 | Variable S2 = new Variable(); | ||
2201 | foreach (bool l2 in YP.unify(arg1, Atom.a(","))) | ||
2202 | { | ||
2203 | if (YP.greaterThanOrEqual(Precedence, 1000)) | ||
2204 | { | ||
2205 | if (YP.lessThan(C, 1000)) | ||
2206 | { | ||
2207 | foreach (bool l5 in parse(S1, 1000, Next, S2)) | ||
2208 | { | ||
2209 | foreach (bool l6 in exprtl(S2, 1000, new Functor2(",", Term, Next), Precedence, Answer, S)) | ||
2210 | { | ||
2211 | yield return false; | ||
2212 | } | ||
2213 | } | ||
2214 | yield break; | ||
2215 | } | ||
2216 | } | ||
2217 | } | ||
2218 | } | ||
2219 | { | ||
2220 | object C = arg2; | ||
2221 | object Term = arg3; | ||
2222 | object Precedence = arg4; | ||
2223 | object Answer = arg5; | ||
2224 | object S = arg6; | ||
2225 | object S1 = arg7; | ||
2226 | Variable Next = new Variable(); | ||
2227 | Variable S2 = new Variable(); | ||
2228 | foreach (bool l2 in YP.unify(arg1, Atom.a("|"))) | ||
2229 | { | ||
2230 | if (YP.greaterThanOrEqual(Precedence, 1100)) | ||
2231 | { | ||
2232 | if (YP.lessThan(C, 1100)) | ||
2233 | { | ||
2234 | foreach (bool l5 in parse(S1, 1100, Next, S2)) | ||
2235 | { | ||
2236 | foreach (bool l6 in exprtl(S2, 1100, new Functor2(";", Term, Next), Precedence, Answer, S)) | ||
2237 | { | ||
2238 | yield return false; | ||
2239 | } | ||
2240 | } | ||
2241 | yield break; | ||
2242 | } | ||
2243 | } | ||
2244 | } | ||
2245 | } | ||
2246 | { | ||
2247 | object Token = arg1; | ||
2248 | object x2 = arg2; | ||
2249 | object x4 = arg4; | ||
2250 | object Tokens = arg7; | ||
2251 | Variable Term = new Variable(); | ||
2252 | foreach (bool l2 in YP.unify(arg3, Term)) | ||
2253 | { | ||
2254 | foreach (bool l3 in YP.unify(arg5, Term)) | ||
2255 | { | ||
2256 | foreach (bool l4 in YP.unify(arg6, new ListPair(Token, Tokens))) | ||
2257 | { | ||
2258 | yield return false; | ||
2259 | } | ||
2260 | } | ||
2261 | } | ||
2262 | } | ||
2263 | } | ||
2264 | |||
2265 | public static IEnumerable<bool> syntax_error(object _Message, object _List) | ||
2266 | { | ||
2267 | { | ||
2268 | yield break; | ||
2269 | } | ||
2270 | foreach (bool l1 in YP.fail()) | ||
2271 | { | ||
2272 | yield return false; | ||
2273 | } | ||
2274 | } | ||
2275 | |||
2276 | public static IEnumerable<bool> syntax_error(object _List) | ||
2277 | { | ||
2278 | { | ||
2279 | yield break; | ||
2280 | } | ||
2281 | foreach (bool l1 in YP.fail()) | ||
2282 | { | ||
2283 | yield return false; | ||
2284 | } | ||
2285 | } | ||
2286 | |||
2287 | public static IEnumerable<bool> prefixop(object F, object O, object Q) | ||
2288 | { | ||
2289 | { | ||
2290 | foreach (bool l2 in YP.current_op(O, Atom.a("fx"), F)) | ||
2291 | { | ||
2292 | foreach (bool l3 in YP.unify(Q, YP.subtract(O, 1))) | ||
2293 | { | ||
2294 | yield return false; | ||
2295 | } | ||
2296 | goto cutIf1; | ||
2297 | } | ||
2298 | foreach (bool l2 in YP.current_op(O, Atom.a("fy"), F)) | ||
2299 | { | ||
2300 | foreach (bool l3 in YP.unify(Q, O)) | ||
2301 | { | ||
2302 | yield return false; | ||
2303 | } | ||
2304 | goto cutIf2; | ||
2305 | } | ||
2306 | cutIf2: | ||
2307 | cutIf1: | ||
2308 | { } | ||
2309 | } | ||
2310 | } | ||
2311 | |||
2312 | public static IEnumerable<bool> postfixop(object F, object P, object O) | ||
2313 | { | ||
2314 | { | ||
2315 | foreach (bool l2 in YP.current_op(O, Atom.a("xf"), F)) | ||
2316 | { | ||
2317 | foreach (bool l3 in YP.unify(P, YP.subtract(O, 1))) | ||
2318 | { | ||
2319 | yield return false; | ||
2320 | } | ||
2321 | goto cutIf1; | ||
2322 | } | ||
2323 | foreach (bool l2 in YP.current_op(O, Atom.a("yf"), F)) | ||
2324 | { | ||
2325 | foreach (bool l3 in YP.unify(P, O)) | ||
2326 | { | ||
2327 | yield return false; | ||
2328 | } | ||
2329 | goto cutIf2; | ||
2330 | } | ||
2331 | cutIf2: | ||
2332 | cutIf1: | ||
2333 | { } | ||
2334 | } | ||
2335 | } | ||
2336 | |||
2337 | public static IEnumerable<bool> infixop(object F, object P, object O, object Q) | ||
2338 | { | ||
2339 | { | ||
2340 | foreach (bool l2 in YP.current_op(O, Atom.a("xfy"), F)) | ||
2341 | { | ||
2342 | foreach (bool l3 in YP.unify(P, YP.subtract(O, 1))) | ||
2343 | { | ||
2344 | foreach (bool l4 in YP.unify(Q, O)) | ||
2345 | { | ||
2346 | yield return false; | ||
2347 | } | ||
2348 | } | ||
2349 | goto cutIf1; | ||
2350 | } | ||
2351 | foreach (bool l2 in YP.current_op(O, Atom.a("xfx"), F)) | ||
2352 | { | ||
2353 | foreach (bool l3 in YP.unify(P, YP.subtract(O, 1))) | ||
2354 | { | ||
2355 | foreach (bool l4 in YP.unify(Q, P)) | ||
2356 | { | ||
2357 | yield return false; | ||
2358 | } | ||
2359 | } | ||
2360 | goto cutIf2; | ||
2361 | } | ||
2362 | foreach (bool l2 in YP.current_op(O, Atom.a("yfx"), F)) | ||
2363 | { | ||
2364 | foreach (bool l3 in YP.unify(Q, YP.subtract(O, 1))) | ||
2365 | { | ||
2366 | foreach (bool l4 in YP.unify(P, O)) | ||
2367 | { | ||
2368 | yield return false; | ||
2369 | } | ||
2370 | } | ||
2371 | goto cutIf3; | ||
2372 | } | ||
2373 | cutIf3: | ||
2374 | cutIf2: | ||
2375 | cutIf1: | ||
2376 | { } | ||
2377 | } | ||
2378 | } | ||
2379 | |||
2380 | public static IEnumerable<bool> ambigop(object F, object Precedence, object L1, object O1, object R1, object L2, object O2) | ||
2381 | { | ||
2382 | { | ||
2383 | foreach (bool l2 in postfixop(F, L2, O2)) | ||
2384 | { | ||
2385 | if (YP.lessThanOrEqual(O2, Precedence)) | ||
2386 | { | ||
2387 | foreach (bool l4 in infixop(F, L1, O1, R1)) | ||
2388 | { | ||
2389 | if (YP.lessThanOrEqual(O1, Precedence)) | ||
2390 | { | ||
2391 | yield return false; | ||
2392 | } | ||
2393 | } | ||
2394 | } | ||
2395 | } | ||
2396 | } | ||
2397 | } | ||
2398 | |||
2399 | public static IEnumerable<bool> read_tokens1(object arg1) | ||
2400 | { | ||
2401 | { | ||
2402 | object TokenList = arg1; | ||
2403 | Variable C1 = new Variable(); | ||
2404 | Variable _X = new Variable(); | ||
2405 | Variable ListOfTokens = new Variable(); | ||
2406 | foreach (bool l2 in YP.get_code(C1)) | ||
2407 | { | ||
2408 | foreach (bool l3 in read_tokens(C1, _X, ListOfTokens)) | ||
2409 | { | ||
2410 | foreach (bool l4 in YP.unify(TokenList, ListOfTokens)) | ||
2411 | { | ||
2412 | yield return false; | ||
2413 | } | ||
2414 | yield break; | ||
2415 | } | ||
2416 | } | ||
2417 | } | ||
2418 | { | ||
2419 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("atom", Atom.a("end_of_file"), 0), Atom.NIL))) | ||
2420 | { | ||
2421 | yield return false; | ||
2422 | } | ||
2423 | } | ||
2424 | } | ||
2425 | |||
2426 | public static IEnumerable<bool> read_tokens2(object arg1, object arg2) | ||
2427 | { | ||
2428 | { | ||
2429 | object TokenList = arg1; | ||
2430 | object Dictionary = arg2; | ||
2431 | Variable C1 = new Variable(); | ||
2432 | Variable Dict = new Variable(); | ||
2433 | Variable ListOfTokens = new Variable(); | ||
2434 | foreach (bool l2 in YP.get_code(C1)) | ||
2435 | { | ||
2436 | foreach (bool l3 in read_tokens(C1, Dict, ListOfTokens)) | ||
2437 | { | ||
2438 | foreach (bool l4 in terminate_list(Dict)) | ||
2439 | { | ||
2440 | foreach (bool l5 in YP.unify(Dictionary, Dict)) | ||
2441 | { | ||
2442 | foreach (bool l6 in YP.unify(TokenList, ListOfTokens)) | ||
2443 | { | ||
2444 | yield return false; | ||
2445 | } | ||
2446 | } | ||
2447 | yield break; | ||
2448 | } | ||
2449 | } | ||
2450 | } | ||
2451 | } | ||
2452 | { | ||
2453 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("atom", Atom.a("end_of_file"), 0), Atom.NIL))) | ||
2454 | { | ||
2455 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
2456 | { | ||
2457 | yield return false; | ||
2458 | } | ||
2459 | } | ||
2460 | } | ||
2461 | } | ||
2462 | |||
2463 | public static IEnumerable<bool> terminate_list(object arg1) | ||
2464 | { | ||
2465 | { | ||
2466 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
2467 | { | ||
2468 | yield return false; | ||
2469 | } | ||
2470 | } | ||
2471 | { | ||
2472 | Variable x1 = new Variable(); | ||
2473 | Variable Tail = new Variable(); | ||
2474 | foreach (bool l2 in YP.unify(arg1, new ListPair(x1, Tail))) | ||
2475 | { | ||
2476 | foreach (bool l3 in terminate_list(Tail)) | ||
2477 | { | ||
2478 | yield return false; | ||
2479 | } | ||
2480 | } | ||
2481 | } | ||
2482 | } | ||
2483 | |||
2484 | public static IEnumerable<bool> read_special(object arg1, object Dict, object arg3) | ||
2485 | { | ||
2486 | { | ||
2487 | object Tokens = arg3; | ||
2488 | foreach (bool l2 in YP.unify(arg1, 95)) | ||
2489 | { | ||
2490 | foreach (bool l3 in read_variable(95, Dict, Tokens)) | ||
2491 | { | ||
2492 | yield return false; | ||
2493 | } | ||
2494 | } | ||
2495 | } | ||
2496 | { | ||
2497 | object Tokens = arg3; | ||
2498 | foreach (bool l2 in YP.unify(arg1, 247)) | ||
2499 | { | ||
2500 | foreach (bool l3 in read_symbol(247, Dict, Tokens)) | ||
2501 | { | ||
2502 | yield return false; | ||
2503 | } | ||
2504 | } | ||
2505 | } | ||
2506 | { | ||
2507 | object Tokens = arg3; | ||
2508 | foreach (bool l2 in YP.unify(arg1, 215)) | ||
2509 | { | ||
2510 | foreach (bool l3 in read_symbol(215, Dict, Tokens)) | ||
2511 | { | ||
2512 | yield return false; | ||
2513 | } | ||
2514 | } | ||
2515 | } | ||
2516 | { | ||
2517 | Variable StartPos = new Variable(); | ||
2518 | Variable EndPos = new Variable(); | ||
2519 | Variable Tokens = new Variable(); | ||
2520 | Variable Ch = new Variable(); | ||
2521 | Variable NextCh = new Variable(); | ||
2522 | foreach (bool l2 in YP.unify(arg1, 37)) | ||
2523 | { | ||
2524 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("comment", StartPos, EndPos), Tokens))) | ||
2525 | { | ||
2526 | foreach (bool l4 in get_current_position(StartPos)) | ||
2527 | { | ||
2528 | foreach (bool l5 in YP.repeat()) | ||
2529 | { | ||
2530 | foreach (bool l6 in YP.get_code(Ch)) | ||
2531 | { | ||
2532 | if (YP.lessThan(Ch, new ListPair(32, Atom.NIL))) | ||
2533 | { | ||
2534 | if (YP.notEqual(Ch, 9)) | ||
2535 | { | ||
2536 | if (YP.termNotEqual(Ch, -1)) | ||
2537 | { | ||
2538 | foreach (bool l10 in get_current_position(EndPos)) | ||
2539 | { | ||
2540 | foreach (bool l11 in YP.get_code(NextCh)) | ||
2541 | { | ||
2542 | foreach (bool l12 in read_tokens(NextCh, Dict, Tokens)) | ||
2543 | { | ||
2544 | yield return false; | ||
2545 | } | ||
2546 | } | ||
2547 | } | ||
2548 | } | ||
2549 | yield break; | ||
2550 | } | ||
2551 | } | ||
2552 | } | ||
2553 | } | ||
2554 | } | ||
2555 | } | ||
2556 | } | ||
2557 | } | ||
2558 | { | ||
2559 | object T = arg3; | ||
2560 | Variable C2 = new Variable(); | ||
2561 | Variable StartPos = new Variable(); | ||
2562 | Variable EndPos = new Variable(); | ||
2563 | Variable Tokens = new Variable(); | ||
2564 | Variable StartPos1 = new Variable(); | ||
2565 | Variable NextCh = new Variable(); | ||
2566 | Variable Chars = new Variable(); | ||
2567 | foreach (bool l2 in YP.unify(arg1, 47)) | ||
2568 | { | ||
2569 | foreach (bool l3 in YP.get_code(C2)) | ||
2570 | { | ||
2571 | if (YP.equal(C2, new ListPair(42, Atom.NIL))) | ||
2572 | { | ||
2573 | foreach (bool l5 in YP.unify(T, new ListPair(new Functor2("comment", StartPos, EndPos), Tokens))) | ||
2574 | { | ||
2575 | foreach (bool l6 in get_current_position(StartPos1)) | ||
2576 | { | ||
2577 | foreach (bool l7 in YP.unify(StartPos, YP.subtract(StartPos1, 1))) | ||
2578 | { | ||
2579 | foreach (bool l8 in read_solidus(32, NextCh)) | ||
2580 | { | ||
2581 | foreach (bool l9 in get_current_position(EndPos)) | ||
2582 | { | ||
2583 | foreach (bool l10 in read_tokens(NextCh, Dict, Tokens)) | ||
2584 | { | ||
2585 | yield return false; | ||
2586 | } | ||
2587 | } | ||
2588 | } | ||
2589 | } | ||
2590 | } | ||
2591 | } | ||
2592 | goto cutIf1; | ||
2593 | } | ||
2594 | foreach (bool l4 in YP.unify(T, Tokens)) | ||
2595 | { | ||
2596 | foreach (bool l5 in rest_symbol(C2, Chars, NextCh)) | ||
2597 | { | ||
2598 | foreach (bool l6 in read_after_atom4(NextCh, Dict, Tokens, new ListPair(47, Chars))) | ||
2599 | { | ||
2600 | yield return false; | ||
2601 | } | ||
2602 | } | ||
2603 | } | ||
2604 | cutIf1: | ||
2605 | { } | ||
2606 | } | ||
2607 | } | ||
2608 | } | ||
2609 | { | ||
2610 | Variable Pos = new Variable(); | ||
2611 | Variable Tokens = new Variable(); | ||
2612 | Variable NextCh = new Variable(); | ||
2613 | foreach (bool l2 in YP.unify(arg1, 33)) | ||
2614 | { | ||
2615 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("atom", Atom.a("!"), Pos), Tokens))) | ||
2616 | { | ||
2617 | foreach (bool l4 in get_current_position(Pos)) | ||
2618 | { | ||
2619 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2620 | { | ||
2621 | foreach (bool l6 in read_after_atom(NextCh, Dict, Tokens)) | ||
2622 | { | ||
2623 | yield return false; | ||
2624 | } | ||
2625 | } | ||
2626 | } | ||
2627 | } | ||
2628 | } | ||
2629 | } | ||
2630 | { | ||
2631 | Variable Tokens = new Variable(); | ||
2632 | Variable NextCh = new Variable(); | ||
2633 | foreach (bool l2 in YP.unify(arg1, 40)) | ||
2634 | { | ||
2635 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(" ("), Tokens))) | ||
2636 | { | ||
2637 | foreach (bool l4 in YP.get_code(NextCh)) | ||
2638 | { | ||
2639 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
2640 | { | ||
2641 | yield return false; | ||
2642 | } | ||
2643 | } | ||
2644 | } | ||
2645 | } | ||
2646 | } | ||
2647 | { | ||
2648 | Variable Tokens = new Variable(); | ||
2649 | Variable NextCh = new Variable(); | ||
2650 | foreach (bool l2 in YP.unify(arg1, 41)) | ||
2651 | { | ||
2652 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(")"), Tokens))) | ||
2653 | { | ||
2654 | foreach (bool l4 in YP.get_code(NextCh)) | ||
2655 | { | ||
2656 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
2657 | { | ||
2658 | yield return false; | ||
2659 | } | ||
2660 | } | ||
2661 | } | ||
2662 | } | ||
2663 | } | ||
2664 | { | ||
2665 | Variable Tokens = new Variable(); | ||
2666 | Variable NextCh = new Variable(); | ||
2667 | foreach (bool l2 in YP.unify(arg1, 44)) | ||
2668 | { | ||
2669 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(","), Tokens))) | ||
2670 | { | ||
2671 | foreach (bool l4 in YP.get_code(NextCh)) | ||
2672 | { | ||
2673 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
2674 | { | ||
2675 | yield return false; | ||
2676 | } | ||
2677 | } | ||
2678 | } | ||
2679 | } | ||
2680 | } | ||
2681 | { | ||
2682 | Variable Pos = new Variable(); | ||
2683 | Variable Tokens = new Variable(); | ||
2684 | Variable NextCh = new Variable(); | ||
2685 | foreach (bool l2 in YP.unify(arg1, 59)) | ||
2686 | { | ||
2687 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("atom", Atom.a(";"), Pos), Tokens))) | ||
2688 | { | ||
2689 | foreach (bool l4 in get_current_position(Pos)) | ||
2690 | { | ||
2691 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2692 | { | ||
2693 | foreach (bool l6 in read_after_atom(NextCh, Dict, Tokens)) | ||
2694 | { | ||
2695 | yield return false; | ||
2696 | } | ||
2697 | } | ||
2698 | } | ||
2699 | } | ||
2700 | } | ||
2701 | } | ||
2702 | { | ||
2703 | Variable Pos = new Variable(); | ||
2704 | Variable Tokens = new Variable(); | ||
2705 | Variable NextCh = new Variable(); | ||
2706 | foreach (bool l2 in YP.unify(arg1, 91)) | ||
2707 | { | ||
2708 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("/", Atom.a("["), Pos), Tokens))) | ||
2709 | { | ||
2710 | foreach (bool l4 in get_current_position(Pos)) | ||
2711 | { | ||
2712 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2713 | { | ||
2714 | foreach (bool l6 in read_tokens(NextCh, Dict, Tokens)) | ||
2715 | { | ||
2716 | yield return false; | ||
2717 | } | ||
2718 | } | ||
2719 | } | ||
2720 | } | ||
2721 | } | ||
2722 | } | ||
2723 | { | ||
2724 | Variable Pos = new Variable(); | ||
2725 | Variable Tokens = new Variable(); | ||
2726 | Variable NextCh = new Variable(); | ||
2727 | foreach (bool l2 in YP.unify(arg1, 93)) | ||
2728 | { | ||
2729 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("/", Atom.a("]"), Pos), Tokens))) | ||
2730 | { | ||
2731 | foreach (bool l4 in get_current_position(Pos)) | ||
2732 | { | ||
2733 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2734 | { | ||
2735 | foreach (bool l6 in read_after_atom(NextCh, Dict, Tokens)) | ||
2736 | { | ||
2737 | yield return false; | ||
2738 | } | ||
2739 | } | ||
2740 | } | ||
2741 | } | ||
2742 | } | ||
2743 | } | ||
2744 | { | ||
2745 | Variable Pos = new Variable(); | ||
2746 | Variable Tokens = new Variable(); | ||
2747 | Variable NextCh = new Variable(); | ||
2748 | foreach (bool l2 in YP.unify(arg1, 123)) | ||
2749 | { | ||
2750 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("/", Atom.a("{"), Pos), Tokens))) | ||
2751 | { | ||
2752 | foreach (bool l4 in get_current_position(Pos)) | ||
2753 | { | ||
2754 | foreach (bool l5 in YP.get_code(NextCh)) | ||
2755 | { | ||
2756 | foreach (bool l6 in read_tokens(NextCh, Dict, Tokens)) | ||
2757 | { | ||
2758 | yield return false; | ||
2759 | } | ||
2760 | } | ||
2761 | } | ||
2762 | } | ||
2763 | } | ||
2764 | } | ||
2765 | { | ||
2766 | Variable Tokens = new Variable(); | ||
2767 | Variable NextCh = new Variable(); | ||
2768 | foreach (bool l2 in YP.unify(arg1, 124)) | ||
2769 | { | ||
2770 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("|"), Tokens))) | ||
2771 | { | ||
2772 | foreach (bool l4 in YP.get_code(NextCh)) | ||
2773 | { | ||
2774 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
2775 | { | ||
2776 | yield return false; | ||
2777 | } | ||
2778 | } | ||
2779 | } | ||
2780 | } | ||
2781 | } | ||
2782 | { | ||
2783 | Variable Tokens = new Variable(); | ||
2784 | Variable NextCh = new Variable(); | ||
2785 | foreach (bool l2 in YP.unify(arg1, 125)) | ||
2786 | { | ||
2787 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("}"), Tokens))) | ||
2788 | { | ||
2789 | foreach (bool l4 in YP.get_code(NextCh)) | ||
2790 | { | ||
2791 | foreach (bool l5 in read_after_atom(NextCh, Dict, Tokens)) | ||
2792 | { | ||
2793 | yield return false; | ||
2794 | } | ||
2795 | } | ||
2796 | } | ||
2797 | } | ||
2798 | } | ||
2799 | { | ||
2800 | object Tokens = arg3; | ||
2801 | Variable NextCh = new Variable(); | ||
2802 | foreach (bool l2 in YP.unify(arg1, 46)) | ||
2803 | { | ||
2804 | foreach (bool l3 in YP.get_code(NextCh)) | ||
2805 | { | ||
2806 | foreach (bool l4 in read_fullstop(NextCh, Dict, Tokens)) | ||
2807 | { | ||
2808 | yield return false; | ||
2809 | } | ||
2810 | } | ||
2811 | } | ||
2812 | } | ||
2813 | { | ||
2814 | Variable Chars = new Variable(); | ||
2815 | Variable Tokens = new Variable(); | ||
2816 | Variable NextCh = new Variable(); | ||
2817 | foreach (bool l2 in YP.unify(arg1, 34)) | ||
2818 | { | ||
2819 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor1("string", Chars), Tokens))) | ||
2820 | { | ||
2821 | foreach (bool l4 in read_string(Chars, 34, NextCh)) | ||
2822 | { | ||
2823 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
2824 | { | ||
2825 | yield return false; | ||
2826 | } | ||
2827 | } | ||
2828 | } | ||
2829 | } | ||
2830 | } | ||
2831 | { | ||
2832 | object Tokens = arg3; | ||
2833 | Variable Chars = new Variable(); | ||
2834 | Variable NextCh = new Variable(); | ||
2835 | foreach (bool l2 in YP.unify(arg1, 39)) | ||
2836 | { | ||
2837 | foreach (bool l3 in read_string(Chars, 39, NextCh)) | ||
2838 | { | ||
2839 | foreach (bool l4 in read_after_atom4(NextCh, Dict, Tokens, Chars)) | ||
2840 | { | ||
2841 | yield return false; | ||
2842 | } | ||
2843 | } | ||
2844 | } | ||
2845 | } | ||
2846 | { | ||
2847 | object Tokens = arg3; | ||
2848 | foreach (bool l2 in YP.unify(arg1, 35)) | ||
2849 | { | ||
2850 | foreach (bool l3 in read_symbol(35, Dict, Tokens)) | ||
2851 | { | ||
2852 | yield return false; | ||
2853 | } | ||
2854 | } | ||
2855 | } | ||
2856 | { | ||
2857 | object Tokens = arg3; | ||
2858 | foreach (bool l2 in YP.unify(arg1, 36)) | ||
2859 | { | ||
2860 | foreach (bool l3 in read_symbol(36, Dict, Tokens)) | ||
2861 | { | ||
2862 | yield return false; | ||
2863 | } | ||
2864 | } | ||
2865 | } | ||
2866 | { | ||
2867 | object Tokens = arg3; | ||
2868 | foreach (bool l2 in YP.unify(arg1, 38)) | ||
2869 | { | ||
2870 | foreach (bool l3 in read_symbol(38, Dict, Tokens)) | ||
2871 | { | ||
2872 | yield return false; | ||
2873 | } | ||
2874 | } | ||
2875 | } | ||
2876 | { | ||
2877 | object Tokens = arg3; | ||
2878 | foreach (bool l2 in YP.unify(arg1, 42)) | ||
2879 | { | ||
2880 | foreach (bool l3 in read_symbol(42, Dict, Tokens)) | ||
2881 | { | ||
2882 | yield return false; | ||
2883 | } | ||
2884 | } | ||
2885 | } | ||
2886 | { | ||
2887 | object Tokens = arg3; | ||
2888 | foreach (bool l2 in YP.unify(arg1, 43)) | ||
2889 | { | ||
2890 | foreach (bool l3 in read_symbol(43, Dict, Tokens)) | ||
2891 | { | ||
2892 | yield return false; | ||
2893 | } | ||
2894 | } | ||
2895 | } | ||
2896 | { | ||
2897 | object Tokens = arg3; | ||
2898 | foreach (bool l2 in YP.unify(arg1, 45)) | ||
2899 | { | ||
2900 | foreach (bool l3 in read_symbol(45, Dict, Tokens)) | ||
2901 | { | ||
2902 | yield return false; | ||
2903 | } | ||
2904 | } | ||
2905 | } | ||
2906 | { | ||
2907 | object Tokens = arg3; | ||
2908 | foreach (bool l2 in YP.unify(arg1, 58)) | ||
2909 | { | ||
2910 | foreach (bool l3 in read_symbol(58, Dict, Tokens)) | ||
2911 | { | ||
2912 | yield return false; | ||
2913 | } | ||
2914 | } | ||
2915 | } | ||
2916 | { | ||
2917 | object Tokens = arg3; | ||
2918 | foreach (bool l2 in YP.unify(arg1, 60)) | ||
2919 | { | ||
2920 | foreach (bool l3 in read_symbol(60, Dict, Tokens)) | ||
2921 | { | ||
2922 | yield return false; | ||
2923 | } | ||
2924 | } | ||
2925 | } | ||
2926 | { | ||
2927 | object Tokens = arg3; | ||
2928 | foreach (bool l2 in YP.unify(arg1, 61)) | ||
2929 | { | ||
2930 | foreach (bool l3 in read_symbol(61, Dict, Tokens)) | ||
2931 | { | ||
2932 | yield return false; | ||
2933 | } | ||
2934 | } | ||
2935 | } | ||
2936 | { | ||
2937 | object Tokens = arg3; | ||
2938 | foreach (bool l2 in YP.unify(arg1, 62)) | ||
2939 | { | ||
2940 | foreach (bool l3 in read_symbol(62, Dict, Tokens)) | ||
2941 | { | ||
2942 | yield return false; | ||
2943 | } | ||
2944 | } | ||
2945 | } | ||
2946 | { | ||
2947 | object Tokens = arg3; | ||
2948 | foreach (bool l2 in YP.unify(arg1, 63)) | ||
2949 | { | ||
2950 | foreach (bool l3 in read_symbol(63, Dict, Tokens)) | ||
2951 | { | ||
2952 | yield return false; | ||
2953 | } | ||
2954 | } | ||
2955 | } | ||
2956 | { | ||
2957 | object Tokens = arg3; | ||
2958 | foreach (bool l2 in YP.unify(arg1, 64)) | ||
2959 | { | ||
2960 | foreach (bool l3 in read_symbol(64, Dict, Tokens)) | ||
2961 | { | ||
2962 | yield return false; | ||
2963 | } | ||
2964 | } | ||
2965 | } | ||
2966 | { | ||
2967 | object Tokens = arg3; | ||
2968 | foreach (bool l2 in YP.unify(arg1, 92)) | ||
2969 | { | ||
2970 | foreach (bool l3 in read_symbol(92, Dict, Tokens)) | ||
2971 | { | ||
2972 | yield return false; | ||
2973 | } | ||
2974 | } | ||
2975 | } | ||
2976 | { | ||
2977 | object Tokens = arg3; | ||
2978 | foreach (bool l2 in YP.unify(arg1, 94)) | ||
2979 | { | ||
2980 | foreach (bool l3 in read_symbol(94, Dict, Tokens)) | ||
2981 | { | ||
2982 | yield return false; | ||
2983 | } | ||
2984 | } | ||
2985 | } | ||
2986 | { | ||
2987 | object Tokens = arg3; | ||
2988 | foreach (bool l2 in YP.unify(arg1, 96)) | ||
2989 | { | ||
2990 | foreach (bool l3 in read_symbol(96, Dict, Tokens)) | ||
2991 | { | ||
2992 | yield return false; | ||
2993 | } | ||
2994 | } | ||
2995 | } | ||
2996 | { | ||
2997 | object Tokens = arg3; | ||
2998 | foreach (bool l2 in YP.unify(arg1, 126)) | ||
2999 | { | ||
3000 | foreach (bool l3 in read_symbol(126, Dict, Tokens)) | ||
3001 | { | ||
3002 | yield return false; | ||
3003 | } | ||
3004 | } | ||
3005 | } | ||
3006 | } | ||
3007 | |||
3008 | public static IEnumerable<bool> read_symbol(object C1, object Dict, object Tokens) | ||
3009 | { | ||
3010 | { | ||
3011 | Variable C2 = new Variable(); | ||
3012 | Variable Chars = new Variable(); | ||
3013 | Variable NextCh = new Variable(); | ||
3014 | foreach (bool l2 in YP.get_code(C2)) | ||
3015 | { | ||
3016 | foreach (bool l3 in rest_symbol(C2, Chars, NextCh)) | ||
3017 | { | ||
3018 | foreach (bool l4 in read_after_atom4(NextCh, Dict, Tokens, new ListPair(C1, Chars))) | ||
3019 | { | ||
3020 | yield return false; | ||
3021 | } | ||
3022 | } | ||
3023 | } | ||
3024 | } | ||
3025 | } | ||
3026 | |||
3027 | public static IEnumerable<bool> rest_symbol(object arg1, object arg2, object arg3) | ||
3028 | { | ||
3029 | { | ||
3030 | object C2 = arg1; | ||
3031 | object LastCh = arg3; | ||
3032 | Variable Chars = new Variable(); | ||
3033 | Variable NextCh = new Variable(); | ||
3034 | foreach (bool l2 in YP.unify(arg2, new ListPair(C2, Chars))) | ||
3035 | { | ||
3036 | if (YP.greaterThan(C2, 160)) | ||
3037 | { | ||
3038 | if (YP.lessThan(C2, 192)) | ||
3039 | { | ||
3040 | if (YP.notEqual(C2, 186)) | ||
3041 | { | ||
3042 | if (YP.notEqual(C2, 170)) | ||
3043 | { | ||
3044 | foreach (bool l7 in YP.get_code(NextCh)) | ||
3045 | { | ||
3046 | foreach (bool l8 in rest_symbol(NextCh, Chars, LastCh)) | ||
3047 | { | ||
3048 | yield return false; | ||
3049 | } | ||
3050 | } | ||
3051 | yield break; | ||
3052 | } | ||
3053 | } | ||
3054 | } | ||
3055 | goto cutIf1; | ||
3056 | } | ||
3057 | foreach (bool l3 in symbol_char(C2)) | ||
3058 | { | ||
3059 | foreach (bool l4 in YP.get_code(NextCh)) | ||
3060 | { | ||
3061 | foreach (bool l5 in rest_symbol(NextCh, Chars, LastCh)) | ||
3062 | { | ||
3063 | yield return false; | ||
3064 | } | ||
3065 | } | ||
3066 | yield break; | ||
3067 | } | ||
3068 | cutIf1: | ||
3069 | { } | ||
3070 | } | ||
3071 | } | ||
3072 | { | ||
3073 | Variable C2 = new Variable(); | ||
3074 | foreach (bool l2 in YP.unify(arg1, C2)) | ||
3075 | { | ||
3076 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
3077 | { | ||
3078 | foreach (bool l4 in YP.unify(arg3, C2)) | ||
3079 | { | ||
3080 | yield return false; | ||
3081 | } | ||
3082 | } | ||
3083 | } | ||
3084 | } | ||
3085 | } | ||
3086 | |||
3087 | public static IEnumerable<bool> symbol_char(object arg1) | ||
3088 | { | ||
3089 | { | ||
3090 | foreach (bool l2 in YP.unify(arg1, 35)) | ||
3091 | { | ||
3092 | yield return false; | ||
3093 | } | ||
3094 | } | ||
3095 | { | ||
3096 | foreach (bool l2 in YP.unify(arg1, 36)) | ||
3097 | { | ||
3098 | yield return false; | ||
3099 | } | ||
3100 | } | ||
3101 | { | ||
3102 | foreach (bool l2 in YP.unify(arg1, 38)) | ||
3103 | { | ||
3104 | yield return false; | ||
3105 | } | ||
3106 | } | ||
3107 | { | ||
3108 | foreach (bool l2 in YP.unify(arg1, 42)) | ||
3109 | { | ||
3110 | yield return false; | ||
3111 | } | ||
3112 | } | ||
3113 | { | ||
3114 | foreach (bool l2 in YP.unify(arg1, 43)) | ||
3115 | { | ||
3116 | yield return false; | ||
3117 | } | ||
3118 | } | ||
3119 | { | ||
3120 | foreach (bool l2 in YP.unify(arg1, 45)) | ||
3121 | { | ||
3122 | yield return false; | ||
3123 | } | ||
3124 | } | ||
3125 | { | ||
3126 | foreach (bool l2 in YP.unify(arg1, 46)) | ||
3127 | { | ||
3128 | yield return false; | ||
3129 | } | ||
3130 | } | ||
3131 | { | ||
3132 | foreach (bool l2 in YP.unify(arg1, 47)) | ||
3133 | { | ||
3134 | yield return false; | ||
3135 | } | ||
3136 | } | ||
3137 | { | ||
3138 | foreach (bool l2 in YP.unify(arg1, 58)) | ||
3139 | { | ||
3140 | yield return false; | ||
3141 | } | ||
3142 | } | ||
3143 | { | ||
3144 | foreach (bool l2 in YP.unify(arg1, 60)) | ||
3145 | { | ||
3146 | yield return false; | ||
3147 | } | ||
3148 | } | ||
3149 | { | ||
3150 | foreach (bool l2 in YP.unify(arg1, 61)) | ||
3151 | { | ||
3152 | yield return false; | ||
3153 | } | ||
3154 | } | ||
3155 | { | ||
3156 | foreach (bool l2 in YP.unify(arg1, 62)) | ||
3157 | { | ||
3158 | yield return false; | ||
3159 | } | ||
3160 | } | ||
3161 | { | ||
3162 | foreach (bool l2 in YP.unify(arg1, 63)) | ||
3163 | { | ||
3164 | yield return false; | ||
3165 | } | ||
3166 | } | ||
3167 | { | ||
3168 | foreach (bool l2 in YP.unify(arg1, 64)) | ||
3169 | { | ||
3170 | yield return false; | ||
3171 | } | ||
3172 | } | ||
3173 | { | ||
3174 | foreach (bool l2 in YP.unify(arg1, 92)) | ||
3175 | { | ||
3176 | yield return false; | ||
3177 | } | ||
3178 | } | ||
3179 | { | ||
3180 | foreach (bool l2 in YP.unify(arg1, 94)) | ||
3181 | { | ||
3182 | yield return false; | ||
3183 | } | ||
3184 | } | ||
3185 | { | ||
3186 | foreach (bool l2 in YP.unify(arg1, 96)) | ||
3187 | { | ||
3188 | yield return false; | ||
3189 | } | ||
3190 | } | ||
3191 | { | ||
3192 | foreach (bool l2 in YP.unify(arg1, 126)) | ||
3193 | { | ||
3194 | yield return false; | ||
3195 | } | ||
3196 | } | ||
3197 | } | ||
3198 | |||
3199 | public static IEnumerable<bool> get_current_position(object Pos) | ||
3200 | { | ||
3201 | { | ||
3202 | foreach (bool l2 in YP.unify(Pos, 0)) | ||
3203 | { | ||
3204 | yield return false; | ||
3205 | } | ||
3206 | } | ||
3207 | } | ||
3208 | |||
3209 | public static IEnumerable<bool> read_after_atom4(object Ch, object Dict, object arg3, object Chars) | ||
3210 | { | ||
3211 | { | ||
3212 | Variable Atom_1 = new Variable(); | ||
3213 | Variable Pos = new Variable(); | ||
3214 | Variable Tokens = new Variable(); | ||
3215 | foreach (bool l2 in YP.unify(arg3, new ListPair(new Functor2("atom", Atom_1, Pos), Tokens))) | ||
3216 | { | ||
3217 | foreach (bool l3 in YP.unify(Pos, 0)) | ||
3218 | { | ||
3219 | foreach (bool l4 in YP.atom_codes(Atom_1, Chars)) | ||
3220 | { | ||
3221 | foreach (bool l5 in read_after_atom(Ch, Dict, Tokens)) | ||
3222 | { | ||
3223 | yield return false; | ||
3224 | } | ||
3225 | } | ||
3226 | } | ||
3227 | } | ||
3228 | } | ||
3229 | } | ||
3230 | |||
3231 | public static IEnumerable<bool> read_after_atom(object arg1, object Dict, object arg3) | ||
3232 | { | ||
3233 | { | ||
3234 | Variable Tokens = new Variable(); | ||
3235 | Variable NextCh = new Variable(); | ||
3236 | foreach (bool l2 in YP.unify(arg1, 40)) | ||
3237 | { | ||
3238 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("("), Tokens))) | ||
3239 | { | ||
3240 | foreach (bool l4 in YP.get_code(NextCh)) | ||
3241 | { | ||
3242 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
3243 | { | ||
3244 | yield return false; | ||
3245 | } | ||
3246 | } | ||
3247 | yield break; | ||
3248 | } | ||
3249 | } | ||
3250 | } | ||
3251 | { | ||
3252 | object Ch = arg1; | ||
3253 | object Tokens = arg3; | ||
3254 | foreach (bool l2 in read_tokens(Ch, Dict, Tokens)) | ||
3255 | { | ||
3256 | yield return false; | ||
3257 | } | ||
3258 | } | ||
3259 | } | ||
3260 | |||
3261 | public static IEnumerable<bool> read_string(object Chars, object Quote, object NextCh) | ||
3262 | { | ||
3263 | { | ||
3264 | Variable Ch = new Variable(); | ||
3265 | Variable Char = new Variable(); | ||
3266 | Variable Next = new Variable(); | ||
3267 | foreach (bool l2 in YP.get_code(Ch)) | ||
3268 | { | ||
3269 | foreach (bool l3 in read_char(Ch, Quote, Char, Next)) | ||
3270 | { | ||
3271 | foreach (bool l4 in rest_string5(Char, Next, Chars, Quote, NextCh)) | ||
3272 | { | ||
3273 | yield return false; | ||
3274 | } | ||
3275 | } | ||
3276 | } | ||
3277 | } | ||
3278 | } | ||
3279 | |||
3280 | public static IEnumerable<bool> rest_string5(object arg1, object arg2, object arg3, object arg4, object arg5) | ||
3281 | { | ||
3282 | { | ||
3283 | object _X = arg4; | ||
3284 | Variable NextCh = new Variable(); | ||
3285 | foreach (bool l2 in YP.unify(arg1, -1)) | ||
3286 | { | ||
3287 | foreach (bool l3 in YP.unify(arg2, NextCh)) | ||
3288 | { | ||
3289 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
3290 | { | ||
3291 | foreach (bool l5 in YP.unify(arg5, NextCh)) | ||
3292 | { | ||
3293 | yield return true; | ||
3294 | yield break; | ||
3295 | } | ||
3296 | } | ||
3297 | } | ||
3298 | } | ||
3299 | } | ||
3300 | { | ||
3301 | object Char = arg1; | ||
3302 | object Next = arg2; | ||
3303 | object Quote = arg4; | ||
3304 | object NextCh = arg5; | ||
3305 | Variable Chars = new Variable(); | ||
3306 | Variable Char2 = new Variable(); | ||
3307 | Variable Next2 = new Variable(); | ||
3308 | foreach (bool l2 in YP.unify(arg3, new ListPair(Char, Chars))) | ||
3309 | { | ||
3310 | foreach (bool l3 in read_char(Next, Quote, Char2, Next2)) | ||
3311 | { | ||
3312 | foreach (bool l4 in rest_string5(Char2, Next2, Chars, Quote, NextCh)) | ||
3313 | { | ||
3314 | yield return false; | ||
3315 | } | ||
3316 | } | ||
3317 | } | ||
3318 | } | ||
3319 | } | ||
3320 | |||
3321 | public static IEnumerable<bool> escape_char(object arg1, object arg2) | ||
3322 | { | ||
3323 | { | ||
3324 | foreach (bool l2 in YP.unify(arg1, 110)) | ||
3325 | { | ||
3326 | foreach (bool l3 in YP.unify(arg2, 10)) | ||
3327 | { | ||
3328 | yield return false; | ||
3329 | } | ||
3330 | } | ||
3331 | } | ||
3332 | { | ||
3333 | foreach (bool l2 in YP.unify(arg1, 78)) | ||
3334 | { | ||
3335 | foreach (bool l3 in YP.unify(arg2, 10)) | ||
3336 | { | ||
3337 | yield return false; | ||
3338 | } | ||
3339 | } | ||
3340 | } | ||
3341 | { | ||
3342 | foreach (bool l2 in YP.unify(arg1, 116)) | ||
3343 | { | ||
3344 | foreach (bool l3 in YP.unify(arg2, 9)) | ||
3345 | { | ||
3346 | yield return false; | ||
3347 | } | ||
3348 | } | ||
3349 | } | ||
3350 | { | ||
3351 | foreach (bool l2 in YP.unify(arg1, 84)) | ||
3352 | { | ||
3353 | foreach (bool l3 in YP.unify(arg2, 9)) | ||
3354 | { | ||
3355 | yield return false; | ||
3356 | } | ||
3357 | } | ||
3358 | } | ||
3359 | { | ||
3360 | foreach (bool l2 in YP.unify(arg1, 114)) | ||
3361 | { | ||
3362 | foreach (bool l3 in YP.unify(arg2, 13)) | ||
3363 | { | ||
3364 | yield return false; | ||
3365 | } | ||
3366 | } | ||
3367 | } | ||
3368 | { | ||
3369 | foreach (bool l2 in YP.unify(arg1, 82)) | ||
3370 | { | ||
3371 | foreach (bool l3 in YP.unify(arg2, 13)) | ||
3372 | { | ||
3373 | yield return false; | ||
3374 | } | ||
3375 | } | ||
3376 | } | ||
3377 | { | ||
3378 | foreach (bool l2 in YP.unify(arg1, 118)) | ||
3379 | { | ||
3380 | foreach (bool l3 in YP.unify(arg2, 11)) | ||
3381 | { | ||
3382 | yield return false; | ||
3383 | } | ||
3384 | } | ||
3385 | } | ||
3386 | { | ||
3387 | foreach (bool l2 in YP.unify(arg1, 86)) | ||
3388 | { | ||
3389 | foreach (bool l3 in YP.unify(arg2, 11)) | ||
3390 | { | ||
3391 | yield return false; | ||
3392 | } | ||
3393 | } | ||
3394 | } | ||
3395 | { | ||
3396 | foreach (bool l2 in YP.unify(arg1, 98)) | ||
3397 | { | ||
3398 | foreach (bool l3 in YP.unify(arg2, 8)) | ||
3399 | { | ||
3400 | yield return false; | ||
3401 | } | ||
3402 | } | ||
3403 | } | ||
3404 | { | ||
3405 | foreach (bool l2 in YP.unify(arg1, 66)) | ||
3406 | { | ||
3407 | foreach (bool l3 in YP.unify(arg2, 8)) | ||
3408 | { | ||
3409 | yield return false; | ||
3410 | } | ||
3411 | } | ||
3412 | } | ||
3413 | { | ||
3414 | foreach (bool l2 in YP.unify(arg1, 102)) | ||
3415 | { | ||
3416 | foreach (bool l3 in YP.unify(arg2, 12)) | ||
3417 | { | ||
3418 | yield return false; | ||
3419 | } | ||
3420 | } | ||
3421 | } | ||
3422 | { | ||
3423 | foreach (bool l2 in YP.unify(arg1, 70)) | ||
3424 | { | ||
3425 | foreach (bool l3 in YP.unify(arg2, 12)) | ||
3426 | { | ||
3427 | yield return false; | ||
3428 | } | ||
3429 | } | ||
3430 | } | ||
3431 | { | ||
3432 | foreach (bool l2 in YP.unify(arg1, 101)) | ||
3433 | { | ||
3434 | foreach (bool l3 in YP.unify(arg2, 27)) | ||
3435 | { | ||
3436 | yield return false; | ||
3437 | } | ||
3438 | } | ||
3439 | } | ||
3440 | { | ||
3441 | foreach (bool l2 in YP.unify(arg1, 69)) | ||
3442 | { | ||
3443 | foreach (bool l3 in YP.unify(arg2, 27)) | ||
3444 | { | ||
3445 | yield return false; | ||
3446 | } | ||
3447 | } | ||
3448 | } | ||
3449 | { | ||
3450 | foreach (bool l2 in YP.unify(arg1, 100)) | ||
3451 | { | ||
3452 | foreach (bool l3 in YP.unify(arg2, 127)) | ||
3453 | { | ||
3454 | yield return false; | ||
3455 | } | ||
3456 | } | ||
3457 | } | ||
3458 | { | ||
3459 | foreach (bool l2 in YP.unify(arg1, 68)) | ||
3460 | { | ||
3461 | foreach (bool l3 in YP.unify(arg2, 127)) | ||
3462 | { | ||
3463 | yield return false; | ||
3464 | } | ||
3465 | } | ||
3466 | } | ||
3467 | { | ||
3468 | foreach (bool l2 in YP.unify(arg1, 115)) | ||
3469 | { | ||
3470 | foreach (bool l3 in YP.unify(arg2, 32)) | ||
3471 | { | ||
3472 | yield return false; | ||
3473 | } | ||
3474 | } | ||
3475 | } | ||
3476 | { | ||
3477 | foreach (bool l2 in YP.unify(arg1, 83)) | ||
3478 | { | ||
3479 | foreach (bool l3 in YP.unify(arg2, 32)) | ||
3480 | { | ||
3481 | yield return false; | ||
3482 | } | ||
3483 | } | ||
3484 | } | ||
3485 | { | ||
3486 | foreach (bool l2 in YP.unify(arg1, 122)) | ||
3487 | { | ||
3488 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
3489 | { | ||
3490 | yield return false; | ||
3491 | } | ||
3492 | } | ||
3493 | } | ||
3494 | { | ||
3495 | foreach (bool l2 in YP.unify(arg1, 90)) | ||
3496 | { | ||
3497 | foreach (bool l3 in YP.unify(arg2, -1)) | ||
3498 | { | ||
3499 | yield return false; | ||
3500 | } | ||
3501 | } | ||
3502 | } | ||
3503 | } | ||
3504 | |||
3505 | public static IEnumerable<bool> read_variable(object C1, object Dict, object arg3) | ||
3506 | { | ||
3507 | { | ||
3508 | Variable Var = new Variable(); | ||
3509 | Variable Name = new Variable(); | ||
3510 | Variable StartPos = new Variable(); | ||
3511 | Variable Tokens = new Variable(); | ||
3512 | Variable Chars = new Variable(); | ||
3513 | Variable NextCh = new Variable(); | ||
3514 | foreach (bool l2 in YP.unify(arg3, new ListPair(new Functor3("var", Var, Name, StartPos), Tokens))) | ||
3515 | { | ||
3516 | foreach (bool l3 in get_current_position(StartPos)) | ||
3517 | { | ||
3518 | foreach (bool l4 in read_name(C1, Chars, NextCh)) | ||
3519 | { | ||
3520 | foreach (bool l5 in YP.atom_codes(Name, Chars)) | ||
3521 | { | ||
3522 | if (YP.termEqual(Name, Atom.a("_"))) | ||
3523 | { | ||
3524 | foreach (bool l7 in read_after_atom(NextCh, Dict, Tokens)) | ||
3525 | { | ||
3526 | yield return false; | ||
3527 | } | ||
3528 | goto cutIf1; | ||
3529 | } | ||
3530 | foreach (bool l6 in read_lookup(Dict, Name, Var)) | ||
3531 | { | ||
3532 | foreach (bool l7 in read_after_atom(NextCh, Dict, Tokens)) | ||
3533 | { | ||
3534 | yield return false; | ||
3535 | } | ||
3536 | } | ||
3537 | cutIf1: | ||
3538 | { } | ||
3539 | } | ||
3540 | } | ||
3541 | } | ||
3542 | } | ||
3543 | } | ||
3544 | } | ||
3545 | |||
3546 | public static IEnumerable<bool> read_lookup(object arg1, object Name, object Var) | ||
3547 | { | ||
3548 | { | ||
3549 | Variable N = new Variable(); | ||
3550 | Variable V = new Variable(); | ||
3551 | Variable L = new Variable(); | ||
3552 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("=", N, V), L))) | ||
3553 | { | ||
3554 | foreach (bool l3 in YP.unify(N, Name)) | ||
3555 | { | ||
3556 | foreach (bool l4 in YP.unify(V, Var)) | ||
3557 | { | ||
3558 | yield return false; | ||
3559 | } | ||
3560 | goto cutIf1; | ||
3561 | } | ||
3562 | foreach (bool l3 in read_lookup(L, Name, Var)) | ||
3563 | { | ||
3564 | yield return false; | ||
3565 | } | ||
3566 | cutIf1: | ||
3567 | { } | ||
3568 | } | ||
3569 | } | ||
3570 | } | ||
3571 | |||
3572 | public static IEnumerable<bool> read_solidus(object Ch, object LastCh) | ||
3573 | { | ||
3574 | { | ||
3575 | Variable NextCh = new Variable(); | ||
3576 | if (YP.equal(Ch, 42)) | ||
3577 | { | ||
3578 | foreach (bool l3 in YP.get_code(NextCh)) | ||
3579 | { | ||
3580 | if (YP.equal(NextCh, 47)) | ||
3581 | { | ||
3582 | foreach (bool l5 in YP.get_code(LastCh)) | ||
3583 | { | ||
3584 | yield return false; | ||
3585 | } | ||
3586 | goto cutIf2; | ||
3587 | } | ||
3588 | foreach (bool l4 in read_solidus(NextCh, LastCh)) | ||
3589 | { | ||
3590 | yield return false; | ||
3591 | } | ||
3592 | cutIf2: | ||
3593 | { } | ||
3594 | } | ||
3595 | goto cutIf1; | ||
3596 | } | ||
3597 | if (YP.notEqual(Ch, -1)) | ||
3598 | { | ||
3599 | foreach (bool l3 in YP.get_code(NextCh)) | ||
3600 | { | ||
3601 | foreach (bool l4 in read_solidus(NextCh, LastCh)) | ||
3602 | { | ||
3603 | yield return false; | ||
3604 | } | ||
3605 | } | ||
3606 | goto cutIf3; | ||
3607 | } | ||
3608 | foreach (bool l2 in YP.unify(LastCh, Ch)) | ||
3609 | { | ||
3610 | foreach (bool l3 in formatError(Atom.a("user_error"), Atom.a("~N** end of file in /*comment~n"), Atom.NIL)) | ||
3611 | { | ||
3612 | yield return false; | ||
3613 | } | ||
3614 | } | ||
3615 | cutIf3: | ||
3616 | cutIf1: | ||
3617 | { } | ||
3618 | } | ||
3619 | } | ||
3620 | |||
3621 | public static IEnumerable<bool> read_identifier(object C1, object Dict, object Tokens) | ||
3622 | { | ||
3623 | { | ||
3624 | Variable Chars = new Variable(); | ||
3625 | Variable NextCh = new Variable(); | ||
3626 | foreach (bool l2 in read_name(C1, Chars, NextCh)) | ||
3627 | { | ||
3628 | foreach (bool l3 in read_after_atom4(NextCh, Dict, Tokens, Chars)) | ||
3629 | { | ||
3630 | yield return false; | ||
3631 | } | ||
3632 | } | ||
3633 | } | ||
3634 | } | ||
3635 | |||
3636 | public static IEnumerable<bool> read_name(object C1, object arg2, object LastCh) | ||
3637 | { | ||
3638 | { | ||
3639 | Variable Chars = new Variable(); | ||
3640 | Variable C2 = new Variable(); | ||
3641 | foreach (bool l2 in YP.unify(arg2, new ListPair(C1, Chars))) | ||
3642 | { | ||
3643 | foreach (bool l3 in YP.get_code(C2)) | ||
3644 | { | ||
3645 | if (YP.greaterThanOrEqual(C2, new ListPair(97, Atom.NIL))) | ||
3646 | { | ||
3647 | if (YP.lessThanOrEqual(C2, new ListPair(122, Atom.NIL))) | ||
3648 | { | ||
3649 | foreach (bool l6 in read_name(C2, Chars, LastCh)) | ||
3650 | { | ||
3651 | yield return false; | ||
3652 | } | ||
3653 | goto cutIf2; | ||
3654 | } | ||
3655 | if (YP.lessThan(C2, 192)) | ||
3656 | { | ||
3657 | if (YP.notEqual(YP.bitwiseOr(C2, 16), 186)) | ||
3658 | { | ||
3659 | foreach (bool l7 in YP.unify(Chars, Atom.NIL)) | ||
3660 | { | ||
3661 | foreach (bool l8 in YP.unify(LastCh, C2)) | ||
3662 | { | ||
3663 | yield return false; | ||
3664 | } | ||
3665 | } | ||
3666 | goto cutIf3; | ||
3667 | } | ||
3668 | } | ||
3669 | if (YP.equal(YP.bitwiseOr(C2, 32), 247)) | ||
3670 | { | ||
3671 | foreach (bool l6 in YP.unify(Chars, Atom.NIL)) | ||
3672 | { | ||
3673 | foreach (bool l7 in YP.unify(LastCh, C2)) | ||
3674 | { | ||
3675 | yield return false; | ||
3676 | } | ||
3677 | } | ||
3678 | goto cutIf4; | ||
3679 | } | ||
3680 | foreach (bool l5 in read_name(C2, Chars, LastCh)) | ||
3681 | { | ||
3682 | yield return false; | ||
3683 | } | ||
3684 | cutIf4: | ||
3685 | cutIf3: | ||
3686 | cutIf2: | ||
3687 | goto cutIf1; | ||
3688 | } | ||
3689 | if (YP.greaterThanOrEqual(C2, new ListPair(65, Atom.NIL))) | ||
3690 | { | ||
3691 | if (YP.greaterThan(C2, new ListPair(90, Atom.NIL))) | ||
3692 | { | ||
3693 | if (YP.notEqual(C2, new ListPair(95, Atom.NIL))) | ||
3694 | { | ||
3695 | foreach (bool l7 in YP.unify(Chars, Atom.NIL)) | ||
3696 | { | ||
3697 | foreach (bool l8 in YP.unify(LastCh, C2)) | ||
3698 | { | ||
3699 | yield return false; | ||
3700 | } | ||
3701 | } | ||
3702 | goto cutIf6; | ||
3703 | } | ||
3704 | } | ||
3705 | foreach (bool l5 in read_name(C2, Chars, LastCh)) | ||
3706 | { | ||
3707 | yield return false; | ||
3708 | } | ||
3709 | cutIf6: | ||
3710 | goto cutIf5; | ||
3711 | } | ||
3712 | if (YP.greaterThanOrEqual(C2, new ListPair(48, Atom.NIL))) | ||
3713 | { | ||
3714 | if (YP.lessThanOrEqual(C2, new ListPair(57, Atom.NIL))) | ||
3715 | { | ||
3716 | foreach (bool l6 in read_name(C2, Chars, LastCh)) | ||
3717 | { | ||
3718 | yield return false; | ||
3719 | } | ||
3720 | goto cutIf7; | ||
3721 | } | ||
3722 | } | ||
3723 | foreach (bool l4 in YP.unify(Chars, Atom.NIL)) | ||
3724 | { | ||
3725 | foreach (bool l5 in YP.unify(LastCh, C2)) | ||
3726 | { | ||
3727 | yield return false; | ||
3728 | } | ||
3729 | } | ||
3730 | cutIf7: | ||
3731 | cutIf5: | ||
3732 | cutIf1: | ||
3733 | { } | ||
3734 | } | ||
3735 | } | ||
3736 | } | ||
3737 | } | ||
3738 | |||
3739 | public static IEnumerable<bool> read_fullstop(object Ch, object Dict, object Tokens) | ||
3740 | { | ||
3741 | { | ||
3742 | Variable Number = new Variable(); | ||
3743 | Variable Tokens1 = new Variable(); | ||
3744 | Variable Chars = new Variable(); | ||
3745 | Variable NextCh = new Variable(); | ||
3746 | if (YP.lessThanOrEqual(Ch, new ListPair(57, Atom.NIL))) | ||
3747 | { | ||
3748 | if (YP.greaterThanOrEqual(Ch, new ListPair(48, Atom.NIL))) | ||
3749 | { | ||
3750 | foreach (bool l4 in YP.unify(Tokens, new ListPair(new Functor1("number", Number), Tokens1))) | ||
3751 | { | ||
3752 | foreach (bool l5 in read_float(Number, Dict, Tokens1, new ListPair(48, Atom.NIL), Ch)) | ||
3753 | { | ||
3754 | yield return false; | ||
3755 | } | ||
3756 | } | ||
3757 | goto cutIf1; | ||
3758 | } | ||
3759 | } | ||
3760 | if (YP.greaterThan(Ch, new ListPair(32, Atom.NIL))) | ||
3761 | { | ||
3762 | foreach (bool l3 in rest_symbol(Ch, Chars, NextCh)) | ||
3763 | { | ||
3764 | foreach (bool l4 in read_after_atom4(NextCh, Dict, Tokens, new ListPair(46, Chars))) | ||
3765 | { | ||
3766 | yield return false; | ||
3767 | } | ||
3768 | } | ||
3769 | goto cutIf2; | ||
3770 | } | ||
3771 | if (YP.greaterThanOrEqual(Ch, 0)) | ||
3772 | { | ||
3773 | foreach (bool l3 in YP.unify(Tokens, Atom.NIL)) | ||
3774 | { | ||
3775 | yield return false; | ||
3776 | } | ||
3777 | goto cutIf3; | ||
3778 | } | ||
3779 | foreach (bool l2 in formatError(Atom.a("user_error"), Atom.a("~N** end of file just after full stop~n"), Atom.NIL)) | ||
3780 | { | ||
3781 | } | ||
3782 | cutIf3: | ||
3783 | cutIf2: | ||
3784 | cutIf1: | ||
3785 | { } | ||
3786 | } | ||
3787 | } | ||
3788 | |||
3789 | public static IEnumerable<bool> read_float(object Number, object Dict, object Tokens, object Digits, object Digit) | ||
3790 | { | ||
3791 | { | ||
3792 | Variable Chars = new Variable(); | ||
3793 | Variable Rest = new Variable(); | ||
3794 | Variable NextCh = new Variable(); | ||
3795 | foreach (bool l2 in prepend(Digits, Chars, Rest)) | ||
3796 | { | ||
3797 | foreach (bool l3 in read_float4(Digit, Rest, NextCh, Chars)) | ||
3798 | { | ||
3799 | foreach (bool l4 in YP.number_codes(Number, Chars)) | ||
3800 | { | ||
3801 | foreach (bool l5 in read_tokens(NextCh, Dict, Tokens)) | ||
3802 | { | ||
3803 | yield return false; | ||
3804 | } | ||
3805 | } | ||
3806 | } | ||
3807 | } | ||
3808 | } | ||
3809 | } | ||
3810 | |||
3811 | public static IEnumerable<bool> prepend(object arg1, object arg2, object arg3) | ||
3812 | { | ||
3813 | { | ||
3814 | object X = arg3; | ||
3815 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
3816 | { | ||
3817 | foreach (bool l3 in YP.unify(arg2, new ListPair(46, X))) | ||
3818 | { | ||
3819 | yield return false; | ||
3820 | } | ||
3821 | } | ||
3822 | } | ||
3823 | { | ||
3824 | object Y = arg3; | ||
3825 | Variable C = new Variable(); | ||
3826 | Variable Cs = new Variable(); | ||
3827 | Variable X = new Variable(); | ||
3828 | foreach (bool l2 in YP.unify(arg1, new ListPair(C, Cs))) | ||
3829 | { | ||
3830 | foreach (bool l3 in YP.unify(arg2, new ListPair(C, X))) | ||
3831 | { | ||
3832 | foreach (bool l4 in prepend(Cs, X, Y)) | ||
3833 | { | ||
3834 | yield return false; | ||
3835 | } | ||
3836 | } | ||
3837 | } | ||
3838 | } | ||
3839 | } | ||
3840 | |||
3841 | public static IEnumerable<bool> read_float4(object C1, object arg2, object NextCh, object Total) | ||
3842 | { | ||
3843 | { | ||
3844 | Variable Chars = new Variable(); | ||
3845 | Variable C2 = new Variable(); | ||
3846 | Variable C3 = new Variable(); | ||
3847 | Variable C4 = new Variable(); | ||
3848 | Variable More = new Variable(); | ||
3849 | foreach (bool l2 in YP.unify(arg2, new ListPair(C1, Chars))) | ||
3850 | { | ||
3851 | foreach (bool l3 in YP.get_code(C2)) | ||
3852 | { | ||
3853 | if (YP.greaterThanOrEqual(C2, new ListPair(48, Atom.NIL))) | ||
3854 | { | ||
3855 | if (YP.lessThanOrEqual(C2, new ListPair(57, Atom.NIL))) | ||
3856 | { | ||
3857 | foreach (bool l6 in read_float4(C2, Chars, NextCh, Total)) | ||
3858 | { | ||
3859 | yield return false; | ||
3860 | } | ||
3861 | goto cutIf1; | ||
3862 | } | ||
3863 | } | ||
3864 | if (YP.equal(YP.bitwiseOr(C2, 32), new ListPair(101, Atom.NIL))) | ||
3865 | { | ||
3866 | foreach (bool l5 in YP.get_code(C3)) | ||
3867 | { | ||
3868 | if (YP.equal(C3, new ListPair(45, Atom.NIL))) | ||
3869 | { | ||
3870 | foreach (bool l7 in YP.get_code(C4)) | ||
3871 | { | ||
3872 | foreach (bool l8 in YP.unify(Chars, new ListPair(C2, new ListPair(45, More)))) | ||
3873 | { | ||
3874 | if (YP.greaterThanOrEqual(C4, new ListPair(48, Atom.NIL))) | ||
3875 | { | ||
3876 | if (YP.lessThanOrEqual(C4, new ListPair(57, Atom.NIL))) | ||
3877 | { | ||
3878 | foreach (bool l11 in read_exponent(C4, More, NextCh)) | ||
3879 | { | ||
3880 | yield return false; | ||
3881 | } | ||
3882 | goto cutIf4; | ||
3883 | } | ||
3884 | } | ||
3885 | foreach (bool l9 in YP.unify(More, Atom.NIL)) | ||
3886 | { | ||
3887 | foreach (bool l10 in formatError(Atom.a("user_error"), Atom.a("~N** Missing exponent in ~s~n"), new ListPair(Total, Atom.NIL))) | ||
3888 | { | ||
3889 | } | ||
3890 | } | ||
3891 | foreach (bool l9 in YP.unify(More, new ListPair(48, Atom.NIL))) | ||
3892 | { | ||
3893 | foreach (bool l10 in YP.unify(NextCh, C4)) | ||
3894 | { | ||
3895 | yield return false; | ||
3896 | } | ||
3897 | } | ||
3898 | cutIf4: | ||
3899 | { } | ||
3900 | } | ||
3901 | } | ||
3902 | goto cutIf3; | ||
3903 | } | ||
3904 | if (YP.equal(C3, new ListPair(43, Atom.NIL))) | ||
3905 | { | ||
3906 | foreach (bool l7 in YP.get_code(C4)) | ||
3907 | { | ||
3908 | foreach (bool l8 in YP.unify(Chars, new ListPair(C2, More))) | ||
3909 | { | ||
3910 | if (YP.greaterThanOrEqual(C4, new ListPair(48, Atom.NIL))) | ||
3911 | { | ||
3912 | if (YP.lessThanOrEqual(C4, new ListPair(57, Atom.NIL))) | ||
3913 | { | ||
3914 | foreach (bool l11 in read_exponent(C4, More, NextCh)) | ||
3915 | { | ||
3916 | yield return false; | ||
3917 | } | ||
3918 | goto cutIf6; | ||
3919 | } | ||
3920 | } | ||
3921 | foreach (bool l9 in YP.unify(More, Atom.NIL)) | ||
3922 | { | ||
3923 | foreach (bool l10 in formatError(Atom.a("user_error"), Atom.a("~N** Missing exponent in ~s~n"), new ListPair(Total, Atom.NIL))) | ||
3924 | { | ||
3925 | } | ||
3926 | } | ||
3927 | foreach (bool l9 in YP.unify(More, new ListPair(48, Atom.NIL))) | ||
3928 | { | ||
3929 | foreach (bool l10 in YP.unify(NextCh, C4)) | ||
3930 | { | ||
3931 | yield return false; | ||
3932 | } | ||
3933 | } | ||
3934 | cutIf6: | ||
3935 | { } | ||
3936 | } | ||
3937 | } | ||
3938 | goto cutIf5; | ||
3939 | } | ||
3940 | foreach (bool l6 in YP.unify(C4, C3)) | ||
3941 | { | ||
3942 | foreach (bool l7 in YP.unify(Chars, new ListPair(C2, More))) | ||
3943 | { | ||
3944 | if (YP.greaterThanOrEqual(C4, new ListPair(48, Atom.NIL))) | ||
3945 | { | ||
3946 | if (YP.lessThanOrEqual(C4, new ListPair(57, Atom.NIL))) | ||
3947 | { | ||
3948 | foreach (bool l10 in read_exponent(C4, More, NextCh)) | ||
3949 | { | ||
3950 | yield return false; | ||
3951 | } | ||
3952 | goto cutIf7; | ||
3953 | } | ||
3954 | } | ||
3955 | foreach (bool l8 in YP.unify(More, Atom.NIL)) | ||
3956 | { | ||
3957 | foreach (bool l9 in formatError(Atom.a("user_error"), Atom.a("~N** Missing exponent in ~s~n"), new ListPair(Total, Atom.NIL))) | ||
3958 | { | ||
3959 | } | ||
3960 | } | ||
3961 | foreach (bool l8 in YP.unify(More, new ListPair(48, Atom.NIL))) | ||
3962 | { | ||
3963 | foreach (bool l9 in YP.unify(NextCh, C4)) | ||
3964 | { | ||
3965 | yield return false; | ||
3966 | } | ||
3967 | } | ||
3968 | cutIf7: | ||
3969 | { } | ||
3970 | } | ||
3971 | } | ||
3972 | cutIf5: | ||
3973 | cutIf3: | ||
3974 | { } | ||
3975 | } | ||
3976 | goto cutIf2; | ||
3977 | } | ||
3978 | foreach (bool l4 in YP.unify(Chars, Atom.NIL)) | ||
3979 | { | ||
3980 | foreach (bool l5 in YP.unify(NextCh, C2)) | ||
3981 | { | ||
3982 | yield return false; | ||
3983 | } | ||
3984 | } | ||
3985 | cutIf2: | ||
3986 | cutIf1: | ||
3987 | { } | ||
3988 | } | ||
3989 | } | ||
3990 | } | ||
3991 | } | ||
3992 | |||
3993 | public static IEnumerable<bool> read_exponent(object C1, object arg2, object NextCh) | ||
3994 | { | ||
3995 | { | ||
3996 | Variable Chars = new Variable(); | ||
3997 | Variable C2 = new Variable(); | ||
3998 | foreach (bool l2 in YP.unify(arg2, new ListPair(C1, Chars))) | ||
3999 | { | ||
4000 | foreach (bool l3 in YP.get_code(C2)) | ||
4001 | { | ||
4002 | if (YP.greaterThanOrEqual(C2, new ListPair(48, Atom.NIL))) | ||
4003 | { | ||
4004 | if (YP.lessThanOrEqual(C2, new ListPair(57, Atom.NIL))) | ||
4005 | { | ||
4006 | foreach (bool l6 in read_exponent(C2, Chars, NextCh)) | ||
4007 | { | ||
4008 | yield return false; | ||
4009 | } | ||
4010 | goto cutIf1; | ||
4011 | } | ||
4012 | } | ||
4013 | foreach (bool l4 in YP.unify(Chars, Atom.NIL)) | ||
4014 | { | ||
4015 | foreach (bool l5 in YP.unify(NextCh, C2)) | ||
4016 | { | ||
4017 | yield return false; | ||
4018 | } | ||
4019 | } | ||
4020 | cutIf1: | ||
4021 | { } | ||
4022 | } | ||
4023 | } | ||
4024 | } | ||
4025 | } | ||
4026 | |||
4027 | public static IEnumerable<bool> read_number(object C1, object Dict, object arg3) | ||
4028 | { | ||
4029 | { | ||
4030 | Variable Number = new Variable(); | ||
4031 | Variable Tokens = new Variable(); | ||
4032 | Variable C2 = new Variable(); | ||
4033 | Variable N = new Variable(); | ||
4034 | Variable C = new Variable(); | ||
4035 | Variable C3 = new Variable(); | ||
4036 | Variable Digits = new Variable(); | ||
4037 | foreach (bool l2 in YP.unify(arg3, new ListPair(new Functor1("number", Number), Tokens))) | ||
4038 | { | ||
4039 | foreach (bool l3 in read_number4(C1, C2, 0, N)) | ||
4040 | { | ||
4041 | if (YP.equal(C2, 39)) | ||
4042 | { | ||
4043 | if (YP.greaterThanOrEqual(N, 2)) | ||
4044 | { | ||
4045 | if (YP.lessThanOrEqual(N, 36)) | ||
4046 | { | ||
4047 | foreach (bool l7 in read_based(N, 0, Number, C)) | ||
4048 | { | ||
4049 | foreach (bool l8 in read_tokens(C, Dict, Tokens)) | ||
4050 | { | ||
4051 | yield return false; | ||
4052 | } | ||
4053 | } | ||
4054 | goto cutIf2; | ||
4055 | } | ||
4056 | } | ||
4057 | if (YP.equal(N, 0)) | ||
4058 | { | ||
4059 | foreach (bool l6 in YP.get_code(C3)) | ||
4060 | { | ||
4061 | foreach (bool l7 in read_char(C3, -1, Number, C)) | ||
4062 | { | ||
4063 | foreach (bool l8 in read_tokens(C, Dict, Tokens)) | ||
4064 | { | ||
4065 | yield return false; | ||
4066 | } | ||
4067 | } | ||
4068 | } | ||
4069 | goto cutIf3; | ||
4070 | } | ||
4071 | foreach (bool l5 in formatError(Atom.a("user_error"), Atom.a("~N** ~d' read as ~d '~n"), new ListPair(N, new ListPair(N, Atom.NIL)))) | ||
4072 | { | ||
4073 | foreach (bool l6 in YP.unify(Number, N)) | ||
4074 | { | ||
4075 | foreach (bool l7 in YP.unify(C, C2)) | ||
4076 | { | ||
4077 | foreach (bool l8 in read_tokens(C, Dict, Tokens)) | ||
4078 | { | ||
4079 | yield return false; | ||
4080 | } | ||
4081 | } | ||
4082 | } | ||
4083 | } | ||
4084 | cutIf3: | ||
4085 | cutIf2: | ||
4086 | goto cutIf1; | ||
4087 | } | ||
4088 | if (YP.equal(C2, 46)) | ||
4089 | { | ||
4090 | foreach (bool l5 in YP.get_code(C3)) | ||
4091 | { | ||
4092 | if (YP.greaterThanOrEqual(C3, new ListPair(48, Atom.NIL))) | ||
4093 | { | ||
4094 | if (YP.lessThanOrEqual(C3, new ListPair(57, Atom.NIL))) | ||
4095 | { | ||
4096 | foreach (bool l8 in YP.number_codes(N, Digits)) | ||
4097 | { | ||
4098 | foreach (bool l9 in read_float(Number, Dict, Tokens, Digits, C3)) | ||
4099 | { | ||
4100 | yield return false; | ||
4101 | } | ||
4102 | } | ||
4103 | goto cutIf5; | ||
4104 | } | ||
4105 | } | ||
4106 | foreach (bool l6 in YP.unify(Number, N)) | ||
4107 | { | ||
4108 | foreach (bool l7 in read_fullstop(C3, Dict, Tokens)) | ||
4109 | { | ||
4110 | yield return false; | ||
4111 | } | ||
4112 | } | ||
4113 | cutIf5: | ||
4114 | { } | ||
4115 | } | ||
4116 | goto cutIf4; | ||
4117 | } | ||
4118 | foreach (bool l4 in YP.unify(Number, N)) | ||
4119 | { | ||
4120 | foreach (bool l5 in read_tokens(C2, Dict, Tokens)) | ||
4121 | { | ||
4122 | yield return false; | ||
4123 | } | ||
4124 | } | ||
4125 | cutIf4: | ||
4126 | cutIf1: | ||
4127 | { } | ||
4128 | } | ||
4129 | } | ||
4130 | } | ||
4131 | } | ||
4132 | |||
4133 | public static IEnumerable<bool> read_number4(object C0, object C, object N0, object N) | ||
4134 | { | ||
4135 | { | ||
4136 | Variable N1 = new Variable(); | ||
4137 | Variable C1 = new Variable(); | ||
4138 | if (YP.greaterThanOrEqual(C0, new ListPair(48, Atom.NIL))) | ||
4139 | { | ||
4140 | if (YP.lessThanOrEqual(C0, new ListPair(57, Atom.NIL))) | ||
4141 | { | ||
4142 | foreach (bool l4 in YP.unify(N1, YP.add(YP.subtract(YP.multiply(N0, 10), new ListPair(48, Atom.NIL)), C0))) | ||
4143 | { | ||
4144 | foreach (bool l5 in YP.get_code(C1)) | ||
4145 | { | ||
4146 | foreach (bool l6 in read_number4(C1, C, N1, N)) | ||
4147 | { | ||
4148 | yield return false; | ||
4149 | } | ||
4150 | } | ||
4151 | } | ||
4152 | goto cutIf1; | ||
4153 | } | ||
4154 | } | ||
4155 | if (YP.equal(C0, 95)) | ||
4156 | { | ||
4157 | foreach (bool l3 in YP.get_code(C1)) | ||
4158 | { | ||
4159 | foreach (bool l4 in read_number4(C1, C, N0, N)) | ||
4160 | { | ||
4161 | yield return false; | ||
4162 | } | ||
4163 | } | ||
4164 | goto cutIf2; | ||
4165 | } | ||
4166 | foreach (bool l2 in YP.unify(C, C0)) | ||
4167 | { | ||
4168 | foreach (bool l3 in YP.unify(N, N0)) | ||
4169 | { | ||
4170 | yield return false; | ||
4171 | } | ||
4172 | } | ||
4173 | cutIf2: | ||
4174 | cutIf1: | ||
4175 | { } | ||
4176 | } | ||
4177 | } | ||
4178 | |||
4179 | public static IEnumerable<bool> read_based(object Base, object N0, object N, object C) | ||
4180 | { | ||
4181 | { | ||
4182 | Variable C1 = new Variable(); | ||
4183 | Variable Digit = new Variable(); | ||
4184 | Variable N1 = new Variable(); | ||
4185 | foreach (bool l2 in YP.get_code(C1)) | ||
4186 | { | ||
4187 | if (YP.greaterThanOrEqual(C1, new ListPair(48, Atom.NIL))) | ||
4188 | { | ||
4189 | if (YP.lessThanOrEqual(C1, new ListPair(57, Atom.NIL))) | ||
4190 | { | ||
4191 | foreach (bool l5 in YP.unify(Digit, YP.subtract(C1, new ListPair(48, Atom.NIL)))) | ||
4192 | { | ||
4193 | if (YP.lessThan(Digit, Base)) | ||
4194 | { | ||
4195 | foreach (bool l7 in YP.unify(N1, YP.add(YP.multiply(N0, Base), Digit))) | ||
4196 | { | ||
4197 | foreach (bool l8 in read_based(Base, N1, N, C)) | ||
4198 | { | ||
4199 | yield return false; | ||
4200 | } | ||
4201 | } | ||
4202 | goto cutIf2; | ||
4203 | } | ||
4204 | if (YP.equal(C1, new ListPair(95, Atom.NIL))) | ||
4205 | { | ||
4206 | foreach (bool l7 in read_based(Base, N0, N, C)) | ||
4207 | { | ||
4208 | yield return false; | ||
4209 | } | ||
4210 | goto cutIf3; | ||
4211 | } | ||
4212 | foreach (bool l6 in YP.unify(N, N0)) | ||
4213 | { | ||
4214 | foreach (bool l7 in YP.unify(C, C1)) | ||
4215 | { | ||
4216 | yield return false; | ||
4217 | } | ||
4218 | } | ||
4219 | cutIf3: | ||
4220 | cutIf2: | ||
4221 | { } | ||
4222 | } | ||
4223 | goto cutIf1; | ||
4224 | } | ||
4225 | } | ||
4226 | if (YP.greaterThanOrEqual(C1, new ListPair(65, Atom.NIL))) | ||
4227 | { | ||
4228 | if (YP.lessThanOrEqual(C1, new ListPair(90, Atom.NIL))) | ||
4229 | { | ||
4230 | foreach (bool l5 in YP.unify(Digit, YP.subtract(C1, YP.subtract(new ListPair(65, Atom.NIL), 10)))) | ||
4231 | { | ||
4232 | if (YP.lessThan(Digit, Base)) | ||
4233 | { | ||
4234 | foreach (bool l7 in YP.unify(N1, YP.add(YP.multiply(N0, Base), Digit))) | ||
4235 | { | ||
4236 | foreach (bool l8 in read_based(Base, N1, N, C)) | ||
4237 | { | ||
4238 | yield return false; | ||
4239 | } | ||
4240 | } | ||
4241 | goto cutIf5; | ||
4242 | } | ||
4243 | if (YP.equal(C1, new ListPair(95, Atom.NIL))) | ||
4244 | { | ||
4245 | foreach (bool l7 in read_based(Base, N0, N, C)) | ||
4246 | { | ||
4247 | yield return false; | ||
4248 | } | ||
4249 | goto cutIf6; | ||
4250 | } | ||
4251 | foreach (bool l6 in YP.unify(N, N0)) | ||
4252 | { | ||
4253 | foreach (bool l7 in YP.unify(C, C1)) | ||
4254 | { | ||
4255 | yield return false; | ||
4256 | } | ||
4257 | } | ||
4258 | cutIf6: | ||
4259 | cutIf5: | ||
4260 | { } | ||
4261 | } | ||
4262 | goto cutIf4; | ||
4263 | } | ||
4264 | } | ||
4265 | if (YP.greaterThanOrEqual(C1, new ListPair(97, Atom.NIL))) | ||
4266 | { | ||
4267 | if (YP.lessThanOrEqual(C1, new ListPair(122, Atom.NIL))) | ||
4268 | { | ||
4269 | foreach (bool l5 in YP.unify(Digit, YP.subtract(C1, YP.subtract(new ListPair(97, Atom.NIL), 10)))) | ||
4270 | { | ||
4271 | if (YP.lessThan(Digit, Base)) | ||
4272 | { | ||
4273 | foreach (bool l7 in YP.unify(N1, YP.add(YP.multiply(N0, Base), Digit))) | ||
4274 | { | ||
4275 | foreach (bool l8 in read_based(Base, N1, N, C)) | ||
4276 | { | ||
4277 | yield return false; | ||
4278 | } | ||
4279 | } | ||
4280 | goto cutIf8; | ||
4281 | } | ||
4282 | if (YP.equal(C1, new ListPair(95, Atom.NIL))) | ||
4283 | { | ||
4284 | foreach (bool l7 in read_based(Base, N0, N, C)) | ||
4285 | { | ||
4286 | yield return false; | ||
4287 | } | ||
4288 | goto cutIf9; | ||
4289 | } | ||
4290 | foreach (bool l6 in YP.unify(N, N0)) | ||
4291 | { | ||
4292 | foreach (bool l7 in YP.unify(C, C1)) | ||
4293 | { | ||
4294 | yield return false; | ||
4295 | } | ||
4296 | } | ||
4297 | cutIf9: | ||
4298 | cutIf8: | ||
4299 | { } | ||
4300 | } | ||
4301 | goto cutIf7; | ||
4302 | } | ||
4303 | } | ||
4304 | foreach (bool l3 in YP.unify(Digit, 99)) | ||
4305 | { | ||
4306 | if (YP.lessThan(Digit, Base)) | ||
4307 | { | ||
4308 | foreach (bool l5 in YP.unify(N1, YP.add(YP.multiply(N0, Base), Digit))) | ||
4309 | { | ||
4310 | foreach (bool l6 in read_based(Base, N1, N, C)) | ||
4311 | { | ||
4312 | yield return false; | ||
4313 | } | ||
4314 | } | ||
4315 | goto cutIf10; | ||
4316 | } | ||
4317 | if (YP.equal(C1, new ListPair(95, Atom.NIL))) | ||
4318 | { | ||
4319 | foreach (bool l5 in read_based(Base, N0, N, C)) | ||
4320 | { | ||
4321 | yield return false; | ||
4322 | } | ||
4323 | goto cutIf11; | ||
4324 | } | ||
4325 | foreach (bool l4 in YP.unify(N, N0)) | ||
4326 | { | ||
4327 | foreach (bool l5 in YP.unify(C, C1)) | ||
4328 | { | ||
4329 | yield return false; | ||
4330 | } | ||
4331 | } | ||
4332 | cutIf11: | ||
4333 | cutIf10: | ||
4334 | { } | ||
4335 | } | ||
4336 | cutIf7: | ||
4337 | cutIf4: | ||
4338 | cutIf1: | ||
4339 | { } | ||
4340 | } | ||
4341 | } | ||
4342 | } | ||
4343 | |||
4344 | public static IEnumerable<bool> read_char(object Char, object Quote, object Result, object Next) | ||
4345 | { | ||
4346 | { | ||
4347 | Variable C1 = new Variable(); | ||
4348 | Variable C2 = new Variable(); | ||
4349 | Variable C3 = new Variable(); | ||
4350 | Variable Ch = new Variable(); | ||
4351 | if (YP.equal(Char, 92)) | ||
4352 | { | ||
4353 | foreach (bool l3 in YP.get_code(C1)) | ||
4354 | { | ||
4355 | if (YP.lessThan(C1, 0)) | ||
4356 | { | ||
4357 | foreach (bool l5 in formatError(Atom.a("user_error"), Atom.a("~N** end of file in ~cquoted~c~n"), new ListPair(Quote, new ListPair(Quote, Atom.NIL)))) | ||
4358 | { | ||
4359 | foreach (bool l6 in YP.unify(Result, -1)) | ||
4360 | { | ||
4361 | foreach (bool l7 in YP.unify(Next, C1)) | ||
4362 | { | ||
4363 | yield return false; | ||
4364 | } | ||
4365 | } | ||
4366 | } | ||
4367 | goto cutIf2; | ||
4368 | } | ||
4369 | if (YP.lessThanOrEqual(C1, new ListPair(32, Atom.NIL))) | ||
4370 | { | ||
4371 | foreach (bool l5 in YP.get_code(C2)) | ||
4372 | { | ||
4373 | foreach (bool l6 in read_char(C2, Quote, Result, Next)) | ||
4374 | { | ||
4375 | yield return false; | ||
4376 | } | ||
4377 | } | ||
4378 | goto cutIf3; | ||
4379 | } | ||
4380 | if (YP.equal(YP.bitwiseOr(C1, 32), new ListPair(99, Atom.NIL))) | ||
4381 | { | ||
4382 | foreach (bool l5 in YP.get_code(C2)) | ||
4383 | { | ||
4384 | foreach (bool l6 in read_char(C2, Quote, Result, Next)) | ||
4385 | { | ||
4386 | yield return false; | ||
4387 | } | ||
4388 | } | ||
4389 | goto cutIf4; | ||
4390 | } | ||
4391 | if (YP.lessThanOrEqual(C1, new ListPair(55, Atom.NIL))) | ||
4392 | { | ||
4393 | if (YP.greaterThanOrEqual(C1, new ListPair(48, Atom.NIL))) | ||
4394 | { | ||
4395 | foreach (bool l6 in YP.get_code(C2)) | ||
4396 | { | ||
4397 | if (YP.lessThanOrEqual(C2, new ListPair(55, Atom.NIL))) | ||
4398 | { | ||
4399 | if (YP.greaterThanOrEqual(C2, new ListPair(48, Atom.NIL))) | ||
4400 | { | ||
4401 | foreach (bool l9 in YP.get_code(C3)) | ||
4402 | { | ||
4403 | if (YP.lessThanOrEqual(C3, new ListPair(55, Atom.NIL))) | ||
4404 | { | ||
4405 | if (YP.greaterThanOrEqual(C3, new ListPair(48, Atom.NIL))) | ||
4406 | { | ||
4407 | foreach (bool l12 in YP.get_code(Next)) | ||
4408 | { | ||
4409 | foreach (bool l13 in YP.unify(Result, YP.subtract(YP.add(YP.multiply(YP.add(YP.multiply(C1, 8), C2), 8), C3), YP.multiply(73, new ListPair(48, Atom.NIL))))) | ||
4410 | { | ||
4411 | yield return false; | ||
4412 | } | ||
4413 | } | ||
4414 | goto cutIf7; | ||
4415 | } | ||
4416 | } | ||
4417 | foreach (bool l10 in YP.unify(Next, C3)) | ||
4418 | { | ||
4419 | foreach (bool l11 in YP.unify(Result, YP.subtract(YP.add(YP.multiply(C1, 8), C2), YP.multiply(9, new ListPair(48, Atom.NIL))))) | ||
4420 | { | ||
4421 | yield return false; | ||
4422 | } | ||
4423 | } | ||
4424 | cutIf7: | ||
4425 | { } | ||
4426 | } | ||
4427 | goto cutIf6; | ||
4428 | } | ||
4429 | } | ||
4430 | foreach (bool l7 in YP.unify(Next, C2)) | ||
4431 | { | ||
4432 | foreach (bool l8 in YP.unify(Result, YP.subtract(C1, new ListPair(48, Atom.NIL)))) | ||
4433 | { | ||
4434 | yield return false; | ||
4435 | } | ||
4436 | } | ||
4437 | cutIf6: | ||
4438 | { } | ||
4439 | } | ||
4440 | goto cutIf5; | ||
4441 | } | ||
4442 | } | ||
4443 | if (YP.equal(C1, new ListPair(94, Atom.NIL))) | ||
4444 | { | ||
4445 | foreach (bool l5 in YP.get_code(C2)) | ||
4446 | { | ||
4447 | if (YP.lessThan(C2, 0)) | ||
4448 | { | ||
4449 | foreach (bool l7 in formatError(Atom.a("user_error"), Atom.a("~N** end of file in ~c..~c^..~c~n"), ListPair.make(new object[] { Quote, 92, Quote }))) | ||
4450 | { | ||
4451 | foreach (bool l8 in YP.unify(Result, -1)) | ||
4452 | { | ||
4453 | foreach (bool l9 in YP.unify(Next, C2)) | ||
4454 | { | ||
4455 | yield return false; | ||
4456 | } | ||
4457 | } | ||
4458 | } | ||
4459 | goto cutIf9; | ||
4460 | } | ||
4461 | if (YP.equal(C2, new ListPair(63, Atom.NIL))) | ||
4462 | { | ||
4463 | foreach (bool l7 in YP.unify(Result, 127)) | ||
4464 | { | ||
4465 | foreach (bool l8 in YP.get_code(Next)) | ||
4466 | { | ||
4467 | yield return false; | ||
4468 | } | ||
4469 | } | ||
4470 | goto cutIf10; | ||
4471 | } | ||
4472 | foreach (bool l6 in YP.unify(Result, YP.bitwiseAnd(C2, 31))) | ||
4473 | { | ||
4474 | foreach (bool l7 in YP.get_code(Next)) | ||
4475 | { | ||
4476 | yield return false; | ||
4477 | } | ||
4478 | } | ||
4479 | cutIf10: | ||
4480 | cutIf9: | ||
4481 | { } | ||
4482 | } | ||
4483 | goto cutIf8; | ||
4484 | } | ||
4485 | foreach (bool l4 in escape_char(C1, Result)) | ||
4486 | { | ||
4487 | foreach (bool l5 in YP.get_code(Next)) | ||
4488 | { | ||
4489 | yield return false; | ||
4490 | } | ||
4491 | goto cutIf11; | ||
4492 | } | ||
4493 | foreach (bool l4 in YP.unify(Result, C1)) | ||
4494 | { | ||
4495 | foreach (bool l5 in YP.get_code(Next)) | ||
4496 | { | ||
4497 | yield return false; | ||
4498 | } | ||
4499 | } | ||
4500 | cutIf11: | ||
4501 | cutIf8: | ||
4502 | cutIf5: | ||
4503 | cutIf4: | ||
4504 | cutIf3: | ||
4505 | cutIf2: | ||
4506 | { } | ||
4507 | } | ||
4508 | goto cutIf1; | ||
4509 | } | ||
4510 | if (YP.equal(Char, Quote)) | ||
4511 | { | ||
4512 | foreach (bool l3 in YP.get_code(Ch)) | ||
4513 | { | ||
4514 | if (YP.equal(Ch, Quote)) | ||
4515 | { | ||
4516 | foreach (bool l5 in YP.unify(Result, Quote)) | ||
4517 | { | ||
4518 | foreach (bool l6 in YP.get_code(Next)) | ||
4519 | { | ||
4520 | yield return false; | ||
4521 | } | ||
4522 | } | ||
4523 | goto cutIf13; | ||
4524 | } | ||
4525 | foreach (bool l4 in YP.unify(Result, -1)) | ||
4526 | { | ||
4527 | foreach (bool l5 in YP.unify(Next, Ch)) | ||
4528 | { | ||
4529 | yield return false; | ||
4530 | } | ||
4531 | } | ||
4532 | cutIf13: | ||
4533 | { } | ||
4534 | } | ||
4535 | goto cutIf12; | ||
4536 | } | ||
4537 | if (YP.lessThan(Char, new ListPair(32, Atom.NIL))) | ||
4538 | { | ||
4539 | if (YP.notEqual(Char, 9)) | ||
4540 | { | ||
4541 | if (YP.notEqual(Char, 10)) | ||
4542 | { | ||
4543 | if (YP.notEqual(Char, 13)) | ||
4544 | { | ||
4545 | foreach (bool l6 in YP.unify(Result, -1)) | ||
4546 | { | ||
4547 | foreach (bool l7 in YP.unify(Next, Char)) | ||
4548 | { | ||
4549 | foreach (bool l8 in formatError(Atom.a("user_error"), Atom.a("~N** Strange character ~d ends ~ctoken~c~n"), ListPair.make(new object[] { Char, Quote, Quote }))) | ||
4550 | { | ||
4551 | yield return false; | ||
4552 | } | ||
4553 | } | ||
4554 | } | ||
4555 | goto cutIf14; | ||
4556 | } | ||
4557 | } | ||
4558 | } | ||
4559 | } | ||
4560 | foreach (bool l2 in YP.unify(Result, Char)) | ||
4561 | { | ||
4562 | foreach (bool l3 in YP.get_code(Next)) | ||
4563 | { | ||
4564 | yield return false; | ||
4565 | } | ||
4566 | } | ||
4567 | cutIf14: | ||
4568 | cutIf12: | ||
4569 | cutIf1: | ||
4570 | { } | ||
4571 | } | ||
4572 | } | ||
4573 | #pragma warning restore 0168, 0219, 0162 | ||
4574 | } | ||
4575 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/PrologException.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/PrologException.cs deleted file mode 100644 index 9f5ae3d..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/PrologException.cs +++ /dev/null | |||
@@ -1,159 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// A PrologException is used as the exception thrown by YP.throw(Term). | ||
37 | /// </summary> | ||
38 | public class PrologException : Exception | ||
39 | { | ||
40 | public readonly object _term; | ||
41 | |||
42 | /// <summary> | ||
43 | /// Create a PrologException with the given Term. The printable exception message is the full Term. | ||
44 | /// </summary> | ||
45 | /// <param name="Term">the term of the exception</param> | ||
46 | public PrologException(object Term) | ||
47 | : base(YP.getValue(Term).ToString()) | ||
48 | { | ||
49 | _term = YP.makeCopy(Term, new Variable.CopyStore()); | ||
50 | } | ||
51 | |||
52 | /// <summary> | ||
53 | /// Create a PrologException where the Term is error(ErrorTerm, Message). | ||
54 | /// This uses YP.makeCopy to copy the ErrorTerm and Message so that they are valid after unbinding. | ||
55 | /// </summary> | ||
56 | /// <param name="ErrorTerm">the error term of the error</param> | ||
57 | /// <param name="Messsage">the message term of the error. If this is a string, it is converted to an | ||
58 | /// Atom so it can be used by Prolog code. | ||
59 | /// Message, converted to a string, is use as the printable exception message. | ||
60 | /// </param> | ||
61 | public PrologException(object ErrorTerm, object Message) | ||
62 | : base(YP.getValue(Message).ToString()) | ||
63 | { | ||
64 | if (Message is string) | ||
65 | Message = Atom.a((string)Message); | ||
66 | _term = YP.makeCopy(new Functor2(Atom.a("error"), ErrorTerm, Message), new Variable.CopyStore()); | ||
67 | } | ||
68 | |||
69 | public class TypeErrorInfo | ||
70 | { | ||
71 | public readonly Atom _Type; | ||
72 | public readonly object _Culprit; | ||
73 | public readonly object _Message; | ||
74 | |||
75 | public TypeErrorInfo(Atom Type, object Culprit, object Message) | ||
76 | { | ||
77 | _Type = Type; | ||
78 | _Culprit = Culprit; | ||
79 | _Message = Message; | ||
80 | } | ||
81 | } | ||
82 | /// <summary> | ||
83 | /// Return the TypeErrorInfo for this exception, or null if _term does not match | ||
84 | /// error(type_error(Type, Culprit), Message). | ||
85 | /// </summary> | ||
86 | /// <returns></returns> | ||
87 | public TypeErrorInfo getTypeErrorInfo() | ||
88 | { | ||
89 | if (!(_term is Functor2 && ((Functor2)_term)._name._name == "error")) | ||
90 | return null; | ||
91 | object errorTerm = ((Functor2)_term)._arg1; | ||
92 | if (!(errorTerm is Functor2 && ((Functor2)errorTerm)._name._name == "type_error")) | ||
93 | return null; | ||
94 | if (!(((Functor2)errorTerm)._arg1 is Atom)) | ||
95 | return null; | ||
96 | return new TypeErrorInfo | ||
97 | ((Atom)((Functor2)errorTerm)._arg1, ((Functor2)errorTerm)._arg2, ((Functor2)_term)._arg2); | ||
98 | } | ||
99 | |||
100 | public class ExistenceErrorInfo | ||
101 | { | ||
102 | public readonly Atom _Type; | ||
103 | public readonly object _Culprit; | ||
104 | public readonly object _Message; | ||
105 | |||
106 | public ExistenceErrorInfo(Atom Type, object Culprit, object Message) | ||
107 | { | ||
108 | _Type = Type; | ||
109 | _Culprit = Culprit; | ||
110 | _Message = Message; | ||
111 | } | ||
112 | |||
113 | /// <summary> | ||
114 | /// If _Type is procedure and _Culprit is name/artity, return the name. Otherwise return null. | ||
115 | /// </summary> | ||
116 | /// <returns></returns> | ||
117 | public object getProcedureName() | ||
118 | { | ||
119 | if (!(_Type._name == "procedure" && | ||
120 | _Culprit is Functor2 && ((Functor2)_Culprit)._name == Atom.SLASH)) | ||
121 | return null; | ||
122 | return ((Functor2)_Culprit)._arg1; | ||
123 | } | ||
124 | |||
125 | /// <summary> | ||
126 | /// If _Type is procedure and _Culprit is name/arity and arity is an integer, return the arity. | ||
127 | /// Otherwise return -1. | ||
128 | /// </summary> | ||
129 | /// <returns></returns> | ||
130 | public int getProcedureArity() | ||
131 | { | ||
132 | if (!(_Type._name == "procedure" && | ||
133 | _Culprit is Functor2 && ((Functor2)_Culprit)._name == Atom.SLASH)) | ||
134 | return -1; | ||
135 | if (!(((Functor2)_Culprit)._arg2 is int)) | ||
136 | return -1; | ||
137 | return (int)((Functor2)_Culprit)._arg2; | ||
138 | } | ||
139 | } | ||
140 | /// <summary> | ||
141 | /// Return the ExistenceErrorInfo for this exception, or null if _term does not match | ||
142 | /// error(existence_error(Type, Culprit), Message). If the returned ExistenceErrorInfo _Culprit is | ||
143 | /// procedure, you can use its getProcedureName and getProcedureArity. | ||
144 | /// </summary> | ||
145 | /// <returns></returns> | ||
146 | public ExistenceErrorInfo getExistenceErrorInfo() | ||
147 | { | ||
148 | if (!(_term is Functor2 && ((Functor2)_term)._name._name == "error")) | ||
149 | return null; | ||
150 | object errorTerm = ((Functor2)_term)._arg1; | ||
151 | if (!(errorTerm is Functor2 && ((Functor2)errorTerm)._name._name == "existence_error")) | ||
152 | return null; | ||
153 | if (!(((Functor2)errorTerm)._arg1 is Atom)) | ||
154 | return null; | ||
155 | return new ExistenceErrorInfo | ||
156 | ((Atom)((Functor2)errorTerm)._arg1, ((Functor2)errorTerm)._arg2, ((Functor2)_term)._arg2); | ||
157 | } | ||
158 | } | ||
159 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Properties/AssemblyInfo.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Properties/AssemblyInfo.cs deleted file mode 100644 index f6d5d41..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Properties/AssemblyInfo.cs +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.Region.ScriptEngine.Shared.YieldProlog")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
12 | [assembly: AssemblyProduct("OpenSim")] | ||
13 | [assembly: AssemblyCopyright("OpenSimulator developers")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("8df98e6b-0425-44d6-8d91-2b3b4c56acdf")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | [assembly: AssemblyVersion("0.7.5.*")] | ||
33 | [assembly: AssemblyFileVersion("1.0.0.0")] | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/UndefinedPredicateException.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/UndefinedPredicateException.cs deleted file mode 100644 index 4b6112f..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/UndefinedPredicateException.cs +++ /dev/null | |||
@@ -1,62 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// An UndefinedPredicateException extends PrologException to create an existence_error exception. | ||
37 | /// </summary> | ||
38 | public class UndefinedPredicateException : PrologException | ||
39 | { | ||
40 | private Atom _predicateName; | ||
41 | private int _arity; | ||
42 | |||
43 | public UndefinedPredicateException(object message, Atom predicateName, int arity) | ||
44 | : base(new Functor2 | ||
45 | (Atom.a("existence_error"), Atom.a("procedure"), new Functor2(Atom.a("/"), predicateName, arity)), | ||
46 | message) | ||
47 | { | ||
48 | _predicateName = predicateName; | ||
49 | _arity = arity; | ||
50 | } | ||
51 | |||
52 | public Atom PredicateName | ||
53 | { | ||
54 | get { return _predicateName; } | ||
55 | } | ||
56 | |||
57 | public int Arity | ||
58 | { | ||
59 | get { return _arity; } | ||
60 | } | ||
61 | } | ||
62 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Variable.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Variable.cs deleted file mode 100644 index ea5b7a6..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/Variable.cs +++ /dev/null | |||
@@ -1,222 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
36 | { | ||
37 | public interface IUnifiable | ||
38 | { | ||
39 | IEnumerable<bool> unify(object arg); | ||
40 | void addUniqueVariables(List<Variable> variableSet); | ||
41 | object makeCopy(Variable.CopyStore copyStore); | ||
42 | bool termEqual(object term); | ||
43 | bool ground(); | ||
44 | } | ||
45 | |||
46 | /// <summary> | ||
47 | /// A Variable is passed to a function so that it can be unified with | ||
48 | /// value or another Variable. See getValue and unify for details. | ||
49 | /// </summary> | ||
50 | public class Variable : IUnifiable | ||
51 | { | ||
52 | // Use _isBound separate from _value so that it can be bound to any value, | ||
53 | // including null. | ||
54 | private bool _isBound = false; | ||
55 | private object _value; | ||
56 | |||
57 | /// <summary> | ||
58 | /// If this Variable is unbound, then just return this Variable. | ||
59 | /// Otherwise, if this has been bound to a value with unify, return the value. | ||
60 | /// If the bound value is another Variable, this follows the "variable chain" | ||
61 | /// to the end and returns the final value, or the final Variable if it is unbound. | ||
62 | /// For more details, see http://yieldprolog.sourceforge.net/tutorial1.html | ||
63 | /// </summary> | ||
64 | /// <returns></returns> | ||
65 | public object getValue() | ||
66 | { | ||
67 | if (!_isBound) | ||
68 | return this; | ||
69 | |||
70 | object result = _value; | ||
71 | while (result is Variable) | ||
72 | { | ||
73 | if (!((Variable)result)._isBound) | ||
74 | return result; | ||
75 | |||
76 | // Keep following the Variable chain. | ||
77 | result = ((Variable)result)._value; | ||
78 | } | ||
79 | |||
80 | return result; | ||
81 | } | ||
82 | |||
83 | /// <summary> | ||
84 | /// If this Variable is bound, then just call YP.unify to unify this with arg. | ||
85 | /// (Note that if arg is an unbound Variable, then YP.unify will bind it to | ||
86 | /// this Variable's value.) | ||
87 | /// Otherwise, bind this Variable to YP.getValue(arg) and yield once. After the | ||
88 | /// yield, return this Variable to the unbound state. | ||
89 | /// For more details, see http://yieldprolog.sourceforge.net/tutorial1.html | ||
90 | /// </summary> | ||
91 | /// <param name="arg"></param> | ||
92 | /// <returns></returns> | ||
93 | public IEnumerable<bool> unify(object arg) | ||
94 | { | ||
95 | if (!_isBound) | ||
96 | { | ||
97 | _value = YP.getValue(arg); | ||
98 | if (_value == this) | ||
99 | // We are unifying this unbound variable with itself, so leave it unbound. | ||
100 | yield return false; | ||
101 | else | ||
102 | { | ||
103 | _isBound = true; | ||
104 | try | ||
105 | { | ||
106 | yield return false; | ||
107 | } | ||
108 | finally | ||
109 | { | ||
110 | // Remove the binding. | ||
111 | _isBound = false; | ||
112 | } | ||
113 | } | ||
114 | } | ||
115 | else | ||
116 | { | ||
117 | // disable warning on l1, don't see how we can | ||
118 | // code this differently | ||
119 | #pragma warning disable 0168, 0219 | ||
120 | foreach (bool l1 in YP.unify(this, arg)) | ||
121 | yield return false; | ||
122 | #pragma warning restore 0168, 0219 | ||
123 | } | ||
124 | } | ||
125 | |||
126 | public override string ToString() | ||
127 | { | ||
128 | object value = getValue(); | ||
129 | if (value == this) | ||
130 | return "_Variable"; | ||
131 | else | ||
132 | return getValue().ToString(); | ||
133 | } | ||
134 | |||
135 | /// <summary> | ||
136 | /// If bound, call YP.addUniqueVariables on the value. Otherwise, if this unbound | ||
137 | /// variable is not already in variableSet, add it. | ||
138 | /// </summary> | ||
139 | /// <param name="variableSet"></param> | ||
140 | public void addUniqueVariables(List<Variable> variableSet) | ||
141 | { | ||
142 | if (_isBound) | ||
143 | YP.addUniqueVariables(getValue(), variableSet); | ||
144 | else | ||
145 | { | ||
146 | if (variableSet.IndexOf(this) < 0) | ||
147 | variableSet.Add(this); | ||
148 | } | ||
149 | } | ||
150 | |||
151 | /// <summary> | ||
152 | /// If bound, return YP.makeCopy for the value, else return copyStore.getCopy(this). | ||
153 | /// However, if copyStore is null, just return this. | ||
154 | /// </summary> | ||
155 | /// <param name="copyStore"></param> | ||
156 | /// <returns></returns> | ||
157 | public object makeCopy(Variable.CopyStore copyStore) | ||
158 | { | ||
159 | if (_isBound) | ||
160 | return YP.makeCopy(getValue(), copyStore); | ||
161 | else | ||
162 | return copyStore == null ? this : copyStore.getCopy(this); | ||
163 | } | ||
164 | |||
165 | public bool termEqual(object term) | ||
166 | { | ||
167 | if (_isBound) | ||
168 | return YP.termEqual(getValue(), term); | ||
169 | else | ||
170 | return this == YP.getValue(term); | ||
171 | } | ||
172 | |||
173 | public bool ground() | ||
174 | { | ||
175 | if (_isBound) | ||
176 | // This is usually called by YP.ground which already did getValue, so this | ||
177 | // should never be reached, but check anyway. | ||
178 | return YP.ground(getValue()); | ||
179 | else | ||
180 | return false; | ||
181 | } | ||
182 | |||
183 | /// <summary> | ||
184 | /// A CopyStore is used by makeCopy to track which Variable objects have | ||
185 | /// been copied. | ||
186 | /// </summary> | ||
187 | public class CopyStore | ||
188 | { | ||
189 | private List<Variable> _inVariableSet = new List<Variable>(); | ||
190 | private List<Variable> _outVariableSet = new List<Variable>(); | ||
191 | |||
192 | /// <summary> | ||
193 | /// If inVariable has already been copied, return its copy. Otherwise, | ||
194 | /// return a fresh Variable associated with inVariable. | ||
195 | /// </summary> | ||
196 | /// <param name="inVariable"></param> | ||
197 | /// <returns></returns> | ||
198 | public Variable getCopy(Variable inVariable) | ||
199 | { | ||
200 | int index = _inVariableSet.IndexOf(inVariable); | ||
201 | if (index >= 0) | ||
202 | return _outVariableSet[index]; | ||
203 | else | ||
204 | { | ||
205 | Variable outVariable = new Variable(); | ||
206 | _inVariableSet.Add(inVariable); | ||
207 | _outVariableSet.Add(outVariable); | ||
208 | return outVariable; | ||
209 | } | ||
210 | } | ||
211 | |||
212 | /// <summary> | ||
213 | /// Return the number of unique variables that have been copied. | ||
214 | /// </summary> | ||
215 | /// <returns></returns> | ||
216 | public int getNUniqueVariables() | ||
217 | { | ||
218 | return _inVariableSet.Count; | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YP.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YP.cs deleted file mode 100644 index f2171dd..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YP.cs +++ /dev/null | |||
@@ -1,2701 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.Collections; | ||
33 | using System.Collections.Generic; | ||
34 | using System.IO; | ||
35 | using System.Reflection; | ||
36 | using System.Net.Sockets; | ||
37 | using System.Text; | ||
38 | using System.Text.RegularExpressions; | ||
39 | using log4net; | ||
40 | |||
41 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
42 | { | ||
43 | /// <summary> | ||
44 | /// YP has static methods for general functions in Yield Prolog such as <see cref="getValue"/> | ||
45 | /// and <see cref="unify"/>. | ||
46 | /// </summary> | ||
47 | public class YP | ||
48 | { | ||
49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | private static Fail _fail = new Fail(); | ||
51 | private static Repeat _repeat = new Repeat(); | ||
52 | private static Dictionary<NameArity, List<IClause>> _predicatesStore = | ||
53 | new Dictionary<NameArity, List<IClause>>(); | ||
54 | private static TextWriter _outputStream = System.Console.Out; | ||
55 | private static TextReader _inputStream = System.Console.In; | ||
56 | private static IndexedAnswers _operatorTable = null; | ||
57 | private static Dictionary<string, object> _prologFlags = new Dictionary<string, object>(); | ||
58 | public const int MAX_ARITY = 255; | ||
59 | |||
60 | /// <summary> | ||
61 | /// An IClause is used so that dynamic predicates can call match. | ||
62 | /// </summary> | ||
63 | public interface IClause | ||
64 | { | ||
65 | IEnumerable<bool> match(object[] args); | ||
66 | IEnumerable<bool> clause(object Head, object Body); | ||
67 | } | ||
68 | |||
69 | /// <summary> | ||
70 | /// If value is a Variable, then return its getValue. Otherwise, just | ||
71 | /// return value. You should call YP.getValue on any object that | ||
72 | /// may be a Variable to get the value to pass to other functions in | ||
73 | /// your system that are not part of Yield Prolog, such as math functions | ||
74 | /// or file I/O. | ||
75 | /// For more details, see http://yieldprolog.sourceforge.net/tutorial1.html | ||
76 | /// </summary> | ||
77 | /// <param name="value"></param> | ||
78 | /// <returns></returns> | ||
79 | public static object getValue(object value) | ||
80 | { | ||
81 | if (value is Variable) | ||
82 | return ((Variable)value).getValue(); | ||
83 | else | ||
84 | return value; | ||
85 | } | ||
86 | |||
87 | /// <summary> | ||
88 | /// If arg1 or arg2 is an object with a unify method (such as Variable or | ||
89 | /// Functor) then just call its unify with the other argument. The object's | ||
90 | /// unify method will bind the values or check for equals as needed. | ||
91 | /// Otherwise, both arguments are "normal" (atomic) values so if they | ||
92 | /// are equal then succeed (yield once), else fail (don't yield). | ||
93 | /// For more details, see http://yieldprolog.sourceforge.net/tutorial1.html | ||
94 | /// </summary> | ||
95 | /// <param name="arg1"></param> | ||
96 | /// <param name="arg2"></param> | ||
97 | /// <returns></returns> | ||
98 | public static IEnumerable<bool> unify(object arg1, object arg2) | ||
99 | { | ||
100 | arg1 = getValue(arg1); | ||
101 | arg2 = getValue(arg2); | ||
102 | if (arg1 is IUnifiable) | ||
103 | return ((IUnifiable)arg1).unify(arg2); | ||
104 | else if (arg2 is IUnifiable) | ||
105 | return ((IUnifiable)arg2).unify(arg1); | ||
106 | else | ||
107 | { | ||
108 | // Arguments are "normal" types. | ||
109 | if (arg1.Equals(arg2)) | ||
110 | return new Succeed(); | ||
111 | else | ||
112 | return _fail; | ||
113 | } | ||
114 | } | ||
115 | |||
116 | /// <summary> | ||
117 | /// This is used for the lookup key in _factStore. | ||
118 | /// </summary> | ||
119 | public struct NameArity | ||
120 | { | ||
121 | public readonly Atom _name; | ||
122 | public readonly int _arity; | ||
123 | |||
124 | public NameArity(Atom name, int arity) | ||
125 | { | ||
126 | _name = name; | ||
127 | _arity = arity; | ||
128 | } | ||
129 | |||
130 | public override bool Equals(object obj) | ||
131 | { | ||
132 | if (obj is NameArity) | ||
133 | { | ||
134 | NameArity nameArity = (NameArity)obj; | ||
135 | return nameArity._name.Equals(_name) && nameArity._arity.Equals(_arity); | ||
136 | } | ||
137 | else | ||
138 | { | ||
139 | return false; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | public override int GetHashCode() | ||
144 | { | ||
145 | return _name.GetHashCode() ^ _arity.GetHashCode(); | ||
146 | } | ||
147 | } | ||
148 | |||
149 | /// <summary> | ||
150 | /// Convert term to an int. | ||
151 | /// If term is a single-element List, use its first element | ||
152 | /// (to handle the char types like "a"). | ||
153 | /// If can't convert, throw a PrologException for type_error evaluable (because this is only | ||
154 | /// called from arithmetic functions). | ||
155 | /// </summary> | ||
156 | /// <param name="term"></param> | ||
157 | /// <returns></returns> | ||
158 | public static int convertInt(object term) | ||
159 | { | ||
160 | term = YP.getValue(term); | ||
161 | if (term is Functor2 && ((Functor2)term)._name == Atom.DOT && | ||
162 | YP.getValue(((Functor2)term)._arg2) == Atom.NIL) | ||
163 | // Assume it is a char type like "a". | ||
164 | term = YP.getValue(((Functor2)term)._arg1); | ||
165 | if (term is Variable) | ||
166 | throw new PrologException(Atom.a("instantiation_error"), | ||
167 | "Expected a number but the argument is an unbound variable"); | ||
168 | |||
169 | try | ||
170 | { | ||
171 | return (int)term; | ||
172 | } | ||
173 | catch (InvalidCastException) | ||
174 | { | ||
175 | throw new PrologException | ||
176 | (new Functor2 | ||
177 | ("type_error", Atom.a("evaluable"), | ||
178 | new Functor2(Atom.SLASH, getFunctorName(term), getFunctorArgs(term).Length)), | ||
179 | "Term must be an integer"); | ||
180 | } | ||
181 | } | ||
182 | |||
183 | /// <summary> | ||
184 | /// Convert term to a double. This may convert an int to a double, etc. | ||
185 | /// If term is a single-element List, use its first element | ||
186 | /// (to handle the char types like "a"). | ||
187 | /// If can't convert, throw a PrologException for type_error evaluable (because this is only | ||
188 | /// called from arithmetic functions). | ||
189 | /// </summary> | ||
190 | /// <param name="term"></param> | ||
191 | /// <returns></returns> | ||
192 | public static double convertDouble(object term) | ||
193 | { | ||
194 | term = YP.getValue(term); | ||
195 | if (term is Functor2 && ((Functor2)term)._name == Atom.DOT && | ||
196 | YP.getValue(((Functor2)term)._arg2) == Atom.NIL) | ||
197 | // Assume it is a char type like "a". | ||
198 | term = YP.getValue(((Functor2)term)._arg1); | ||
199 | if (term is Variable) | ||
200 | throw new PrologException(Atom.a("instantiation_error"), | ||
201 | "Expected a number but the argument is an unbound variable"); | ||
202 | |||
203 | try | ||
204 | { | ||
205 | return Convert.ToDouble(term); | ||
206 | } | ||
207 | catch (InvalidCastException) | ||
208 | { | ||
209 | throw new PrologException | ||
210 | (new Functor2 | ||
211 | ("type_error", Atom.a("evaluable"), | ||
212 | new Functor2(Atom.SLASH, getFunctorName(term), getFunctorArgs(term).Length)), | ||
213 | "Term must be an integer"); | ||
214 | } | ||
215 | } | ||
216 | |||
217 | /// <summary> | ||
218 | /// If term is an integer, set intTerm. | ||
219 | /// If term is a single-element List, use its first element | ||
220 | /// (to handle the char types like "a"). Return true for success, false if can't convert. | ||
221 | /// We use a success return value because throwing an exception is inefficient. | ||
222 | /// </summary> | ||
223 | /// <param name="term"></param> | ||
224 | /// <returns></returns> | ||
225 | public static bool getInt(object term, out int intTerm) | ||
226 | { | ||
227 | term = YP.getValue(term); | ||
228 | if (term is Functor2 && ((Functor2)term)._name == Atom.DOT && | ||
229 | YP.getValue(((Functor2)term)._arg2) == Atom.NIL) | ||
230 | // Assume it is a char type like "a". | ||
231 | term = YP.getValue(((Functor2)term)._arg1); | ||
232 | |||
233 | if (term is int) | ||
234 | { | ||
235 | intTerm = (int)term; | ||
236 | return true; | ||
237 | } | ||
238 | |||
239 | intTerm = 0; | ||
240 | return false; | ||
241 | } | ||
242 | |||
243 | public static bool equal(object x, object y) | ||
244 | { | ||
245 | x = YP.getValue(x); | ||
246 | if (x is DateTime) | ||
247 | return (DateTime)x == (DateTime)YP.getValue(y); | ||
248 | // Assume convertDouble converts an int to a double perfectly. | ||
249 | return YP.convertDouble(x) == YP.convertDouble(y); | ||
250 | } | ||
251 | |||
252 | public static bool notEqual(object x, object y) | ||
253 | { | ||
254 | x = YP.getValue(x); | ||
255 | if (x is DateTime) | ||
256 | return (DateTime)x != (DateTime)YP.getValue(y); | ||
257 | // Assume convertDouble converts an int to a double perfectly. | ||
258 | return YP.convertDouble(x) != YP.convertDouble(y); | ||
259 | } | ||
260 | |||
261 | public static bool greaterThan(object x, object y) | ||
262 | { | ||
263 | x = YP.getValue(x); | ||
264 | if (x is DateTime) | ||
265 | return (DateTime)x > (DateTime)YP.getValue(y); | ||
266 | // Assume convertDouble converts an int to a double perfectly. | ||
267 | return YP.convertDouble(x) > YP.convertDouble(y); | ||
268 | } | ||
269 | |||
270 | public static bool lessThan(object x, object y) | ||
271 | { | ||
272 | x = YP.getValue(x); | ||
273 | if (x is DateTime) | ||
274 | return (DateTime)x < (DateTime)YP.getValue(y); | ||
275 | // Assume convertDouble converts an int to a double perfectly. | ||
276 | return YP.convertDouble(x) < YP.convertDouble(y); | ||
277 | } | ||
278 | |||
279 | public static bool greaterThanOrEqual(object x, object y) | ||
280 | { | ||
281 | x = YP.getValue(x); | ||
282 | if (x is DateTime) | ||
283 | return (DateTime)x >= (DateTime)YP.getValue(y); | ||
284 | // Assume convertDouble converts an int to a double perfectly. | ||
285 | return YP.convertDouble(x) >= YP.convertDouble(y); | ||
286 | } | ||
287 | |||
288 | public static bool lessThanOrEqual(object x, object y) | ||
289 | { | ||
290 | x = YP.getValue(x); | ||
291 | if (x is DateTime) | ||
292 | return (DateTime)x <= (DateTime)YP.getValue(y); | ||
293 | // Assume convertDouble converts an int to a double perfectly. | ||
294 | return YP.convertDouble(x) <= YP.convertDouble(y); | ||
295 | } | ||
296 | |||
297 | public static object negate(object x) | ||
298 | { | ||
299 | int intX; | ||
300 | if (getInt(x, out intX)) | ||
301 | return -intX; | ||
302 | return -convertDouble(x); | ||
303 | } | ||
304 | |||
305 | public static object abs(object x) | ||
306 | { | ||
307 | int intX; | ||
308 | if (getInt(x, out intX)) | ||
309 | return Math.Abs(intX); | ||
310 | return Math.Abs(convertDouble(x)); | ||
311 | } | ||
312 | |||
313 | public static object sign(object x) | ||
314 | { | ||
315 | int intX; | ||
316 | if (getInt(x, out intX)) | ||
317 | return Math.Sign(intX); | ||
318 | return Math.Sign(convertDouble(x)); | ||
319 | } | ||
320 | |||
321 | // Use toFloat instead of float because it is a reserved keyword. | ||
322 | public static object toFloat(object x) | ||
323 | { | ||
324 | return convertDouble(x); | ||
325 | } | ||
326 | |||
327 | /// <summary> | ||
328 | /// The ISO standard returns an int. | ||
329 | /// </summary> | ||
330 | /// <param name="x"></param> | ||
331 | /// <returns></returns> | ||
332 | public static object floor(object x) | ||
333 | { | ||
334 | return (int)Math.Floor(convertDouble(x)); | ||
335 | } | ||
336 | |||
337 | /// <summary> | ||
338 | /// The ISO standard returns an int. | ||
339 | /// </summary> | ||
340 | /// <param name="x"></param> | ||
341 | /// <returns></returns> | ||
342 | public static object truncate(object x) | ||
343 | { | ||
344 | return (int)Math.Truncate(convertDouble(x)); | ||
345 | } | ||
346 | |||
347 | /// <summary> | ||
348 | /// The ISO standard returns an int. | ||
349 | /// </summary> | ||
350 | /// <param name="x"></param> | ||
351 | /// <returns></returns> | ||
352 | public static object round(object x) | ||
353 | { | ||
354 | return (int)Math.Round(convertDouble(x)); | ||
355 | } | ||
356 | |||
357 | /// <summary> | ||
358 | /// The ISO standard returns an int. | ||
359 | /// </summary> | ||
360 | /// <param name="x"></param> | ||
361 | /// <returns></returns> | ||
362 | public static object ceiling(object x) | ||
363 | { | ||
364 | return (int)Math.Ceiling(convertDouble(x)); | ||
365 | } | ||
366 | |||
367 | public static object sin(object x) | ||
368 | { | ||
369 | return Math.Sin(YP.convertDouble(x)); | ||
370 | } | ||
371 | |||
372 | public static object cos(object x) | ||
373 | { | ||
374 | return Math.Cos(YP.convertDouble(x)); | ||
375 | } | ||
376 | |||
377 | public static object atan(object x) | ||
378 | { | ||
379 | return Math.Atan(YP.convertDouble(x)); | ||
380 | } | ||
381 | |||
382 | public static object exp(object x) | ||
383 | { | ||
384 | return Math.Exp(YP.convertDouble(x)); | ||
385 | } | ||
386 | |||
387 | public static object log(object x) | ||
388 | { | ||
389 | return Math.Log(YP.convertDouble(x)); | ||
390 | } | ||
391 | |||
392 | public static object sqrt(object x) | ||
393 | { | ||
394 | return Math.Sqrt(convertDouble(x)); | ||
395 | } | ||
396 | |||
397 | public static object bitwiseComplement(object x) | ||
398 | { | ||
399 | return ~YP.convertInt(x); | ||
400 | } | ||
401 | |||
402 | public static object add(object x, object y) | ||
403 | { | ||
404 | int intX, intY; | ||
405 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
406 | return intX + intY; | ||
407 | return convertDouble(x) + convertDouble(y); | ||
408 | } | ||
409 | |||
410 | public static object subtract(object x, object y) | ||
411 | { | ||
412 | int intX, intY; | ||
413 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
414 | return intX - intY; | ||
415 | return convertDouble(x) - convertDouble(y); | ||
416 | } | ||
417 | |||
418 | public static object multiply(object x, object y) | ||
419 | { | ||
420 | int intX, intY; | ||
421 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
422 | return intX * intY; | ||
423 | return convertDouble(x) * convertDouble(y); | ||
424 | } | ||
425 | |||
426 | /// <summary> | ||
427 | /// Return floating point, even if both arguments are integer. | ||
428 | /// </summary> | ||
429 | /// <param name="x"></param> | ||
430 | /// <param name="y"></param> | ||
431 | /// <returns></returns> | ||
432 | public static object divide(object x, object y) | ||
433 | { | ||
434 | return convertDouble(x) / convertDouble(y); | ||
435 | } | ||
436 | |||
437 | public static object intDivide(object x, object y) | ||
438 | { | ||
439 | int intX, intY; | ||
440 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
441 | return intX / intY; | ||
442 | // Still allow passing a double, but treat as an int. | ||
443 | return (int)convertDouble(x) / (int)convertDouble(y); | ||
444 | } | ||
445 | |||
446 | public static object mod(object x, object y) | ||
447 | { | ||
448 | int intX, intY; | ||
449 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
450 | return intX % intY; | ||
451 | // Still allow passing a double, but treat as an int. | ||
452 | return (int)convertDouble(x) % (int)convertDouble(y); | ||
453 | } | ||
454 | |||
455 | public static object pow(object x, object y) | ||
456 | { | ||
457 | return Math.Pow(YP.convertDouble(x), YP.convertDouble(y)); | ||
458 | } | ||
459 | |||
460 | public static object bitwiseShiftRight(object x, object y) | ||
461 | { | ||
462 | return YP.convertInt(x) >> YP.convertInt(y); | ||
463 | } | ||
464 | |||
465 | public static object bitwiseShiftLeft(object x, object y) | ||
466 | { | ||
467 | return YP.convertInt(x) << YP.convertInt(y); | ||
468 | } | ||
469 | |||
470 | public static object bitwiseAnd(object x, object y) | ||
471 | { | ||
472 | return YP.convertInt(x) & YP.convertInt(y); | ||
473 | } | ||
474 | |||
475 | public static object bitwiseOr(object x, object y) | ||
476 | { | ||
477 | return YP.convertInt(x) | YP.convertInt(y); | ||
478 | } | ||
479 | |||
480 | public static object min(object x, object y) | ||
481 | { | ||
482 | int intX, intY; | ||
483 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
484 | return Math.Min(intX, intY); | ||
485 | return Math.Min(convertDouble(x), convertDouble(y)); | ||
486 | } | ||
487 | |||
488 | public static object max(object x, object y) | ||
489 | { | ||
490 | int intX, intY; | ||
491 | if (getInt(x, out intX) && getInt(y, out intY)) | ||
492 | return Math.Max(intX, intY); | ||
493 | return Math.Max(convertDouble(x), convertDouble(y)); | ||
494 | } | ||
495 | |||
496 | public static IEnumerable<bool> copy_term(object inTerm, object outTerm) | ||
497 | { | ||
498 | return YP.unify(outTerm, YP.makeCopy(inTerm, new Variable.CopyStore())); | ||
499 | } | ||
500 | |||
501 | public static void addUniqueVariables(object term, List<Variable> variableSet) | ||
502 | { | ||
503 | term = YP.getValue(term); | ||
504 | if (term is IUnifiable) | ||
505 | ((IUnifiable)term).addUniqueVariables(variableSet); | ||
506 | } | ||
507 | |||
508 | public static object makeCopy(object term, Variable.CopyStore copyStore) | ||
509 | { | ||
510 | term = YP.getValue(term); | ||
511 | if (term is IUnifiable) | ||
512 | return ((IUnifiable)term).makeCopy(copyStore); | ||
513 | else | ||
514 | // term is a "normal" type. Assume it is ground. | ||
515 | return term; | ||
516 | } | ||
517 | |||
518 | /// <summary> | ||
519 | /// Sort the array in place according to termLessThan. This does not remove duplicates | ||
520 | /// </summary> | ||
521 | /// <param name="array"></param> | ||
522 | public static void sortArray(object[] array) | ||
523 | { | ||
524 | Array.Sort(array, YP.compareTerms); | ||
525 | } | ||
526 | |||
527 | /// <summary> | ||
528 | /// Sort the array in place according to termLessThan. This does not remove duplicates | ||
529 | /// </summary> | ||
530 | /// <param name="array"></param> | ||
531 | public static void sortArray(List<object> array) | ||
532 | { | ||
533 | array.Sort(YP.compareTerms); | ||
534 | } | ||
535 | |||
536 | /// <summary> | ||
537 | /// Sort List according to termLessThan, remove duplicates and unify with Sorted. | ||
538 | /// </summary> | ||
539 | /// <param name="List"></param> | ||
540 | /// <param name="Sorted"></param> | ||
541 | /// <returns></returns> | ||
542 | public static IEnumerable<bool> sort(object List, object Sorted) | ||
543 | { | ||
544 | object[] array = ListPair.toArray(List); | ||
545 | if (array == null) | ||
546 | return YP.fail(); | ||
547 | if (array.Length > 1) | ||
548 | sortArray(array); | ||
549 | return YP.unify(Sorted, ListPair.makeWithoutRepeatedTerms(array)); | ||
550 | } | ||
551 | |||
552 | /// <summary> | ||
553 | /// Use YP.unify to unify each of the elements of the two arrays, and yield | ||
554 | /// once if they all unify. | ||
555 | /// </summary> | ||
556 | /// <param name="array1"></param> | ||
557 | /// <param name="array2"></param> | ||
558 | /// <returns></returns> | ||
559 | public static IEnumerable<bool> unifyArrays(object[] array1, object[] array2) | ||
560 | { | ||
561 | if (array1.Length != array2.Length) | ||
562 | yield break; | ||
563 | |||
564 | IEnumerator<bool>[] iterators = new IEnumerator<bool>[array1.Length]; | ||
565 | bool gotMatch = true; | ||
566 | int nIterators = 0; | ||
567 | // Try to bind all the arguments. | ||
568 | for (int i = 0; i < array1.Length; ++i) | ||
569 | { | ||
570 | IEnumerator<bool> iterator = YP.unify(array1[i], array2[i]).GetEnumerator(); | ||
571 | iterators[nIterators++] = iterator; | ||
572 | // MoveNext() is true if YP.unify succeeds. | ||
573 | if (!iterator.MoveNext()) | ||
574 | { | ||
575 | gotMatch = false; | ||
576 | break; | ||
577 | } | ||
578 | } | ||
579 | int z = 0; | ||
580 | try | ||
581 | { | ||
582 | if (gotMatch) | ||
583 | yield return false; | ||
584 | } | ||
585 | finally | ||
586 | { | ||
587 | // Manually finalize all the iterators. | ||
588 | for (z = 0; z < nIterators; ++z) | ||
589 | iterators[z].Dispose(); | ||
590 | } | ||
591 | } | ||
592 | |||
593 | /// <summary> | ||
594 | /// Return an iterator (which you can use in a for-in loop) which does | ||
595 | /// zero iterations. This returns a pre-existing iterator which is | ||
596 | /// more efficient than letting the compiler generate a new one. | ||
597 | /// </summary> | ||
598 | /// <returns></returns> | ||
599 | public static IEnumerable<bool> fail() | ||
600 | { | ||
601 | return _fail; | ||
602 | } | ||
603 | |||
604 | /// <summary> | ||
605 | /// Return an iterator (which you can use in a for-in loop) which does | ||
606 | /// one iteration. This returns a pre-existing iterator which is | ||
607 | /// more efficient than letting the compiler generate a new one. | ||
608 | /// </summary> | ||
609 | /// <returns></returns> | ||
610 | public static IEnumerable<bool> succeed() | ||
611 | { | ||
612 | return new Succeed(); | ||
613 | } | ||
614 | |||
615 | /// <summary> | ||
616 | /// Return an iterator (which you can use in a for-in loop) which repeats | ||
617 | /// indefinitely. This returns a pre-existing iterator which is | ||
618 | /// more efficient than letting the compiler generate a new one. | ||
619 | /// </summary> | ||
620 | /// <returns></returns> | ||
621 | public static IEnumerable<bool> repeat() | ||
622 | { | ||
623 | return _repeat; | ||
624 | } | ||
625 | |||
626 | // disable warning on l1, don't see how we can | ||
627 | // code this differently | ||
628 | #pragma warning disable 0168, 0219 | ||
629 | public static IEnumerable<bool> univ(object Term, object List) | ||
630 | { | ||
631 | Term = YP.getValue(Term); | ||
632 | List = YP.getValue(List); | ||
633 | |||
634 | if (nonvar(Term)) | ||
635 | return YP.unify(new ListPair | ||
636 | (getFunctorName(Term), ListPair.make(getFunctorArgs(Term))), List); | ||
637 | |||
638 | Variable Name = new Variable(); | ||
639 | Variable ArgList = new Variable(); | ||
640 | foreach (bool l1 in new ListPair(Name, ArgList).unify(List)) | ||
641 | { | ||
642 | object[] args = ListPair.toArray(ArgList); | ||
643 | if (args == null) | ||
644 | throw new PrologException | ||
645 | (new Functor2("type_error", Atom.a("list"), ArgList), | ||
646 | "Expected a list. Got: " + ArgList.getValue()); | ||
647 | if (args.Length == 0) | ||
648 | // Return the Name, even if it is not an Atom. | ||
649 | return YP.unify(Term, Name); | ||
650 | if (args.Length > MAX_ARITY) | ||
651 | throw new PrologException | ||
652 | (new Functor1("representation_error", Atom.a("max_arity")), | ||
653 | "Functor arity " + args.Length + " may not be greater than " + MAX_ARITY); | ||
654 | if (!atom(Name)) | ||
655 | throw new PrologException | ||
656 | (new Functor2("type_error", Atom.a("atom"), Name), | ||
657 | "Expected an atom. Got: " + Name.getValue()); | ||
658 | |||
659 | return YP.unify(Term, Functor.make((Atom)YP.getValue(Name), args)); | ||
660 | } | ||
661 | |||
662 | return YP.fail(); | ||
663 | } | ||
664 | |||
665 | public static IEnumerable<bool> functor(object Term, object FunctorName, object Arity) | ||
666 | { | ||
667 | Term = YP.getValue(Term); | ||
668 | FunctorName = YP.getValue(FunctorName); | ||
669 | Arity = YP.getValue(Arity); | ||
670 | |||
671 | if (Term is Variable) | ||
672 | { | ||
673 | if (FunctorName is Variable) | ||
674 | throw new PrologException(Atom.a("instantiation_error"), | ||
675 | "Arg 2 FunctorName is an unbound variable"); | ||
676 | if (Arity is Variable) | ||
677 | throw new PrologException(Atom.a("instantiation_error"), | ||
678 | "Arg 3 Arity is an unbound variable"); | ||
679 | if (!(Arity is int)) | ||
680 | throw new PrologException | ||
681 | (new Functor2("type_error", Atom.a("integer"), Arity), "Arity is not an integer"); | ||
682 | if (!YP.atomic(FunctorName)) | ||
683 | throw new PrologException | ||
684 | (new Functor2("type_error", Atom.a("atomic"), FunctorName), "FunctorName is not atomic"); | ||
685 | |||
686 | if ((int)Arity < 0) | ||
687 | throw new PrologException | ||
688 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), Arity), | ||
689 | "Arity may not be less than zero"); | ||
690 | else if ((int)Arity == 0) | ||
691 | { | ||
692 | // Just unify Term with the atomic FunctorName. | ||
693 | foreach (bool l1 in YP.unify(Term, FunctorName)) | ||
694 | yield return false; | ||
695 | } | ||
696 | else | ||
697 | { | ||
698 | if ((int)Arity > MAX_ARITY) | ||
699 | throw new PrologException | ||
700 | (new Functor1("representation_error", Atom.a("max_arity")), | ||
701 | "Functor arity " + Arity + " may not be greater than " + MAX_ARITY); | ||
702 | if (!(FunctorName is Atom)) | ||
703 | throw new PrologException | ||
704 | (new Functor2("type_error", Atom.a("atom"), FunctorName), "FunctorName is not an atom"); | ||
705 | // Construct a functor with unbound variables. | ||
706 | object[] args = new object[(int)Arity]; | ||
707 | for (int i = 0; i < args.Length; ++i) | ||
708 | args[i] = new Variable(); | ||
709 | foreach (bool l1 in YP.unify(Term, Functor.make((Atom)FunctorName, args))) | ||
710 | yield return false; | ||
711 | } | ||
712 | } | ||
713 | else | ||
714 | { | ||
715 | foreach (bool l1 in YP.unify(FunctorName, getFunctorName(Term))) | ||
716 | { | ||
717 | foreach (bool l2 in YP.unify(Arity, getFunctorArgs(Term).Length)) | ||
718 | yield return false; | ||
719 | } | ||
720 | } | ||
721 | } | ||
722 | |||
723 | public static IEnumerable<bool> arg(object ArgNumber, object Term, object Value) | ||
724 | { | ||
725 | if (var(ArgNumber)) | ||
726 | throw new PrologException(Atom.a("instantiation_error"), "Arg 1 ArgNumber is an unbound variable"); | ||
727 | int argNumberInt; | ||
728 | if (!getInt(ArgNumber, out argNumberInt)) | ||
729 | throw new PrologException | ||
730 | (new Functor2("type_error", Atom.a("integer"), ArgNumber), "Arg 1 ArgNumber must be integer"); | ||
731 | if (argNumberInt < 0) | ||
732 | throw new PrologException | ||
733 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), argNumberInt), | ||
734 | "ArgNumber may not be less than zero"); | ||
735 | |||
736 | if (YP.var(Term)) | ||
737 | throw new PrologException(Atom.a("instantiation_error"), | ||
738 | "Arg 2 Term is an unbound variable"); | ||
739 | if (!YP.compound(Term)) | ||
740 | throw new PrologException | ||
741 | (new Functor2("type_error", Atom.a("compound"), Term), "Arg 2 Term must be compound"); | ||
742 | |||
743 | object[] termArgs = YP.getFunctorArgs(Term); | ||
744 | // Silently fail if argNumberInt is out of range. | ||
745 | if (argNumberInt >= 1 && argNumberInt <= termArgs.Length) | ||
746 | { | ||
747 | // The first ArgNumber is at 1, not 0. | ||
748 | foreach (bool l1 in YP.unify(Value, termArgs[argNumberInt - 1])) | ||
749 | yield return false; | ||
750 | } | ||
751 | } | ||
752 | |||
753 | public static bool termEqual(object Term1, object Term2) | ||
754 | { | ||
755 | Term1 = YP.getValue(Term1); | ||
756 | if (Term1 is IUnifiable) | ||
757 | return ((IUnifiable)Term1).termEqual(Term2); | ||
758 | return Term1.Equals(YP.getValue(Term2)); | ||
759 | } | ||
760 | |||
761 | public static bool termNotEqual(object Term1, object Term2) | ||
762 | { | ||
763 | return !termEqual(Term1, Term2); | ||
764 | } | ||
765 | |||
766 | public static bool termLessThan(object Term1, object Term2) | ||
767 | { | ||
768 | Term1 = YP.getValue(Term1); | ||
769 | Term2 = YP.getValue(Term2); | ||
770 | int term1TypeCode = getTypeCode(Term1); | ||
771 | int term2TypeCode = getTypeCode(Term2); | ||
772 | if (term1TypeCode != term2TypeCode) | ||
773 | return term1TypeCode < term2TypeCode; | ||
774 | |||
775 | // The terms are the same type code. | ||
776 | if (term1TypeCode == -2) | ||
777 | { | ||
778 | // Variable. | ||
779 | // We always check for equality first because we want to be sure | ||
780 | // that less than returns false if the terms are equal, in | ||
781 | // case that the less than check really behaves like less than or equal. | ||
782 | if ((Variable)Term1 != (Variable)Term2) | ||
783 | // The hash code should be unique to a Variable object. | ||
784 | return Term1.GetHashCode() < Term2.GetHashCode(); | ||
785 | return false; | ||
786 | } | ||
787 | if (term1TypeCode == 0) | ||
788 | return ((Atom)Term1)._name.CompareTo(((Atom)Term2)._name) < 0; | ||
789 | if (term1TypeCode == 1) | ||
790 | return ((Functor1)Term1).lessThan((Functor1)Term2); | ||
791 | if (term1TypeCode == 2) | ||
792 | return ((Functor2)Term1).lessThan((Functor2)Term2); | ||
793 | if (term1TypeCode == 3) | ||
794 | return ((Functor3)Term1).lessThan((Functor3)Term2); | ||
795 | if (term1TypeCode == 4) | ||
796 | return ((Functor)Term1).lessThan((Functor)Term2); | ||
797 | |||
798 | // Type code is -1 for general objects. First compare their type names. | ||
799 | // Note that this puts Double before Int32 as required by ISO Prolog. | ||
800 | string term1TypeName = Term1.GetType().ToString(); | ||
801 | string term2TypeName = Term2.GetType().ToString(); | ||
802 | if (term1TypeName != term2TypeName) | ||
803 | return term1TypeName.CompareTo(term2TypeName) < 0; | ||
804 | |||
805 | // The terms are the same type name. | ||
806 | if (Term1 is int) | ||
807 | return (int)Term1 < (int)Term2; | ||
808 | else if (Term1 is double) | ||
809 | return (double)Term1 < (double)Term2; | ||
810 | else if (Term1 is DateTime) | ||
811 | return (DateTime)Term1 < (DateTime)Term2; | ||
812 | else if (Term1 is String) | ||
813 | return ((String)Term1).CompareTo((String)Term2) < 0; | ||
814 | // Debug: Should we try arrays, etc.? | ||
815 | |||
816 | if (!Term1.Equals(Term2)) | ||
817 | // Could be equal or greater than. | ||
818 | return Term1.GetHashCode() < Term2.GetHashCode(); | ||
819 | return false; | ||
820 | } | ||
821 | |||
822 | /// <summary> | ||
823 | /// Type code is -2 if term is a Variable, 0 if it is an Atom, | ||
824 | /// 1 if it is a Functor1, 2 if it is a Functor2, 3 if it is a Functor3, | ||
825 | /// 4 if it is Functor. | ||
826 | /// Otherwise, type code is -1. | ||
827 | /// This does not call YP.getValue(term). | ||
828 | /// </summary> | ||
829 | /// <param name="term"></param> | ||
830 | /// <returns></returns> | ||
831 | private static int getTypeCode(object term) | ||
832 | { | ||
833 | if (term is Variable) | ||
834 | return -2; | ||
835 | else if (term is Atom) | ||
836 | return 0; | ||
837 | else if (term is Functor1) | ||
838 | return 1; | ||
839 | else if (term is Functor2) | ||
840 | return 2; | ||
841 | else if (term is Functor3) | ||
842 | return 3; | ||
843 | else if (term is Functor) | ||
844 | return 4; | ||
845 | else | ||
846 | return -1; | ||
847 | } | ||
848 | |||
849 | public static bool termLessThanOrEqual(object Term1, object Term2) | ||
850 | { | ||
851 | if (YP.termEqual(Term1, Term2)) | ||
852 | return true; | ||
853 | return YP.termLessThan(Term1, Term2); | ||
854 | } | ||
855 | |||
856 | public static bool termGreaterThan(object Term1, object Term2) | ||
857 | { | ||
858 | return !YP.termLessThanOrEqual(Term1, Term2); | ||
859 | } | ||
860 | |||
861 | public static bool termGreaterThanOrEqual(object Term1, object Term2) | ||
862 | { | ||
863 | // termLessThan should ensure that it returns false if terms are equal, | ||
864 | // so that this would return true. | ||
865 | return !YP.termLessThan(Term1, Term2); | ||
866 | } | ||
867 | |||
868 | public static int compareTerms(object Term1, object Term2) | ||
869 | { | ||
870 | if (YP.termEqual(Term1, Term2)) | ||
871 | return 0; | ||
872 | else if (YP.termLessThan(Term1, Term2)) | ||
873 | return -1; | ||
874 | else | ||
875 | return 1; | ||
876 | } | ||
877 | |||
878 | public static bool ground(object Term) | ||
879 | { | ||
880 | Term = YP.getValue(Term); | ||
881 | if (Term is IUnifiable) | ||
882 | return ((IUnifiable)Term).ground(); | ||
883 | return true; | ||
884 | } | ||
885 | |||
886 | public static IEnumerable<bool> current_op | ||
887 | (object Priority, object Specifier, object Operator) | ||
888 | { | ||
889 | if (_operatorTable == null) | ||
890 | { | ||
891 | // Initialize. | ||
892 | _operatorTable = new IndexedAnswers(3); | ||
893 | _operatorTable.addAnswer(new object[] { 1200, Atom.a("xfx"), Atom.a(":-") }); | ||
894 | _operatorTable.addAnswer(new object[] { 1200, Atom.a("xfx"), Atom.a("-->") }); | ||
895 | _operatorTable.addAnswer(new object[] { 1200, Atom.a("fx"), Atom.a(":-") }); | ||
896 | _operatorTable.addAnswer(new object[] { 1200, Atom.a("fx"), Atom.a("?-") }); | ||
897 | _operatorTable.addAnswer(new object[] { 1100, Atom.a("xfy"), Atom.a(";") }); | ||
898 | _operatorTable.addAnswer(new object[] { 1050, Atom.a("xfy"), Atom.a("->") }); | ||
899 | _operatorTable.addAnswer(new object[] { 1000, Atom.a("xfy"), Atom.a(",") }); | ||
900 | _operatorTable.addAnswer(new object[] { 900, Atom.a("fy"), Atom.a("\\+") }); | ||
901 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("=") }); | ||
902 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("\\=") }); | ||
903 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("==") }); | ||
904 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("\\==") }); | ||
905 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("@<") }); | ||
906 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("@=<") }); | ||
907 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("@>") }); | ||
908 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("@>=") }); | ||
909 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("=..") }); | ||
910 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("is") }); | ||
911 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("=:=") }); | ||
912 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("=\\=") }); | ||
913 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("<") }); | ||
914 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a("=<") }); | ||
915 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a(">") }); | ||
916 | _operatorTable.addAnswer(new object[] { 700, Atom.a("xfx"), Atom.a(">=") }); | ||
917 | _operatorTable.addAnswer(new object[] { 600, Atom.a("xfy"), Atom.a(":") }); | ||
918 | _operatorTable.addAnswer(new object[] { 500, Atom.a("yfx"), Atom.a("+") }); | ||
919 | _operatorTable.addAnswer(new object[] { 500, Atom.a("yfx"), Atom.a("-") }); | ||
920 | _operatorTable.addAnswer(new object[] { 500, Atom.a("yfx"), Atom.a("/\\") }); | ||
921 | _operatorTable.addAnswer(new object[] { 500, Atom.a("yfx"), Atom.a("\\/") }); | ||
922 | _operatorTable.addAnswer(new object[] { 400, Atom.a("yfx"), Atom.a("*") }); | ||
923 | _operatorTable.addAnswer(new object[] { 400, Atom.a("yfx"), Atom.a("/") }); | ||
924 | _operatorTable.addAnswer(new object[] { 400, Atom.a("yfx"), Atom.a("//") }); | ||
925 | _operatorTable.addAnswer(new object[] { 400, Atom.a("yfx"), Atom.a("rem") }); | ||
926 | _operatorTable.addAnswer(new object[] { 400, Atom.a("yfx"), Atom.a("mod") }); | ||
927 | _operatorTable.addAnswer(new object[] { 400, Atom.a("yfx"), Atom.a("<<") }); | ||
928 | _operatorTable.addAnswer(new object[] { 400, Atom.a("yfx"), Atom.a(">>") }); | ||
929 | _operatorTable.addAnswer(new object[] { 200, Atom.a("xfx"), Atom.a("**") }); | ||
930 | _operatorTable.addAnswer(new object[] { 200, Atom.a("xfy"), Atom.a("^") }); | ||
931 | _operatorTable.addAnswer(new object[] { 200, Atom.a("fy"), Atom.a("-") }); | ||
932 | _operatorTable.addAnswer(new object[] { 200, Atom.a("fy"), Atom.a("\\") }); | ||
933 | // Debug: This is hacked in to run the Prolog test suite until we implement op/3. | ||
934 | _operatorTable.addAnswer(new object[] { 20, Atom.a("xfx"), Atom.a("<--") }); | ||
935 | } | ||
936 | |||
937 | return _operatorTable.match(new object[] { Priority, Specifier, Operator }); | ||
938 | } | ||
939 | |||
940 | public static IEnumerable<bool> atom_length(object atom, object Length) | ||
941 | { | ||
942 | atom = YP.getValue(atom); | ||
943 | Length = YP.getValue(Length); | ||
944 | if (atom is Variable) | ||
945 | throw new PrologException(Atom.a("instantiation_error"), | ||
946 | "Expected atom(Arg1) but it is an unbound variable"); | ||
947 | if (!(atom is Atom)) | ||
948 | throw new PrologException | ||
949 | (new Functor2("type_error", Atom.a("atom"), atom), "Arg 1 Atom is not an atom"); | ||
950 | if (!(Length is Variable)) | ||
951 | { | ||
952 | if (!(Length is int)) | ||
953 | throw new PrologException | ||
954 | (new Functor2("type_error", Atom.a("integer"), Length), "Length must be var or integer"); | ||
955 | if ((int)Length < 0) | ||
956 | throw new PrologException | ||
957 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), Length), | ||
958 | "Length must not be less than zero"); | ||
959 | } | ||
960 | return YP.unify(Length, ((Atom)atom)._name.Length); | ||
961 | } | ||
962 | |||
963 | public static IEnumerable<bool> atom_concat(object Start, object End, object Whole) | ||
964 | { | ||
965 | // Debug: Should we try to preserve the _declaringClass? | ||
966 | Start = YP.getValue(Start); | ||
967 | End = YP.getValue(End); | ||
968 | Whole = YP.getValue(Whole); | ||
969 | if (Whole is Variable) | ||
970 | { | ||
971 | if (Start is Variable) | ||
972 | throw new PrologException(Atom.a("instantiation_error"), | ||
973 | "Arg 1 Start and arg 3 Whole are both var"); | ||
974 | if (End is Variable) | ||
975 | throw new PrologException(Atom.a("instantiation_error"), | ||
976 | "Arg 2 End and arg 3 Whole are both var"); | ||
977 | if (!(Start is Atom)) | ||
978 | throw new PrologException | ||
979 | (new Functor2("type_error", Atom.a("atom"), Start), "Arg 1 Start is not an atom"); | ||
980 | if (!(End is Atom)) | ||
981 | throw new PrologException | ||
982 | (new Functor2("type_error", Atom.a("atom"), End), "Arg 2 End is not an atom"); | ||
983 | |||
984 | foreach (bool l1 in YP.unify(Whole, Atom.a(((Atom)Start)._name + ((Atom)End)._name))) | ||
985 | yield return false; | ||
986 | } | ||
987 | else | ||
988 | { | ||
989 | if (!(Whole is Atom)) | ||
990 | throw new PrologException | ||
991 | (new Functor2("type_error", Atom.a("atom"), Whole), "Arg 3 Whole is not an atom"); | ||
992 | bool gotStartLength = false; | ||
993 | int startLength = 0; | ||
994 | if (!(Start is Variable)) | ||
995 | { | ||
996 | if (!(Start is Atom)) | ||
997 | throw new PrologException | ||
998 | (new Functor2("type_error", Atom.a("atom"), Start), "Arg 1 Start is not var or atom"); | ||
999 | startLength = ((Atom)Start)._name.Length; | ||
1000 | gotStartLength = true; | ||
1001 | } | ||
1002 | |||
1003 | bool gotEndLength = false; | ||
1004 | int endLength = 0; | ||
1005 | if (!(End is Variable)) | ||
1006 | { | ||
1007 | if (!(End is Atom)) | ||
1008 | throw new PrologException | ||
1009 | (new Functor2("type_error", Atom.a("atom"), End), "Arg 2 End is not var or atom"); | ||
1010 | endLength = ((Atom)End)._name.Length; | ||
1011 | gotEndLength = true; | ||
1012 | } | ||
1013 | |||
1014 | // We are doing a search through all possible Start and End which concatenate to Whole. | ||
1015 | string wholeString = ((Atom)Whole)._name; | ||
1016 | for (int i = 0; i <= wholeString.Length; ++i) | ||
1017 | { | ||
1018 | // If we got either startLength or endLength, we know the lengths have to match so check | ||
1019 | // the lengths instead of constructing an Atom to do it. | ||
1020 | if (gotStartLength && startLength != i) | ||
1021 | continue; | ||
1022 | if (gotEndLength && endLength != wholeString.Length - i) | ||
1023 | continue; | ||
1024 | foreach (bool l1 in YP.unify(Start, Atom.a(wholeString.Substring(0, i)))) | ||
1025 | { | ||
1026 | foreach (bool l2 in YP.unify(End, Atom.a(wholeString.Substring(i, wholeString.Length - i)))) | ||
1027 | yield return false; | ||
1028 | } | ||
1029 | } | ||
1030 | } | ||
1031 | } | ||
1032 | |||
1033 | public static IEnumerable<bool> sub_atom | ||
1034 | (object atom, object Before, object Length, object After, object Sub_atom) | ||
1035 | { | ||
1036 | // Debug: Should we try to preserve the _declaringClass? | ||
1037 | atom = YP.getValue(atom); | ||
1038 | Before = YP.getValue(Before); | ||
1039 | Length = YP.getValue(Length); | ||
1040 | After = YP.getValue(After); | ||
1041 | Sub_atom = YP.getValue(Sub_atom); | ||
1042 | if (atom is Variable) | ||
1043 | throw new PrologException(Atom.a("instantiation_error"), | ||
1044 | "Expected atom(Arg1) but it is an unbound variable"); | ||
1045 | if (!(atom is Atom)) | ||
1046 | throw new PrologException | ||
1047 | (new Functor2("type_error", Atom.a("atom"), atom), "Arg 1 Atom is not an atom"); | ||
1048 | if (!(Sub_atom is Variable)) | ||
1049 | { | ||
1050 | if (!(Sub_atom is Atom)) | ||
1051 | throw new PrologException | ||
1052 | (new Functor2("type_error", Atom.a("atom"), Sub_atom), "Sub_atom is not var or atom"); | ||
1053 | } | ||
1054 | |||
1055 | bool beforeIsInt = false; | ||
1056 | bool lengthIsInt = false; | ||
1057 | bool afterIsInt = false; | ||
1058 | if (!(Before is Variable)) | ||
1059 | { | ||
1060 | if (!(Before is int)) | ||
1061 | throw new PrologException | ||
1062 | (new Functor2("type_error", Atom.a("integer"), Before), "Before must be var or integer"); | ||
1063 | beforeIsInt = true; | ||
1064 | if ((int)Before < 0) | ||
1065 | throw new PrologException | ||
1066 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), Before), | ||
1067 | "Before must not be less than zero"); | ||
1068 | } | ||
1069 | if (!(Length is Variable)) | ||
1070 | { | ||
1071 | if (!(Length is int)) | ||
1072 | throw new PrologException | ||
1073 | (new Functor2("type_error", Atom.a("integer"), Length), "Length must be var or integer"); | ||
1074 | lengthIsInt = true; | ||
1075 | if ((int)Length < 0) | ||
1076 | throw new PrologException | ||
1077 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), Length), | ||
1078 | "Length must not be less than zero"); | ||
1079 | } | ||
1080 | if (!(After is Variable)) | ||
1081 | { | ||
1082 | if (!(After is int)) | ||
1083 | throw new PrologException | ||
1084 | (new Functor2("type_error", Atom.a("integer"), After), "After must be var or integer"); | ||
1085 | afterIsInt = true; | ||
1086 | if ((int)After < 0) | ||
1087 | throw new PrologException | ||
1088 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), After), | ||
1089 | "After must not be less than zero"); | ||
1090 | } | ||
1091 | |||
1092 | Atom atomAtom = (Atom)atom; | ||
1093 | int atomLength = atomAtom._name.Length; | ||
1094 | if (beforeIsInt && lengthIsInt) | ||
1095 | { | ||
1096 | // Special case: the caller is just trying to extract a substring, so do it quickly. | ||
1097 | int xAfter = atomLength - (int)Before - (int)Length; | ||
1098 | if (xAfter >= 0) | ||
1099 | { | ||
1100 | foreach (bool l1 in YP.unify(After, xAfter)) | ||
1101 | { | ||
1102 | foreach (bool l2 in YP.unify | ||
1103 | (Sub_atom, Atom.a(atomAtom._name.Substring((int)Before, (int)Length)))) | ||
1104 | yield return false; | ||
1105 | } | ||
1106 | } | ||
1107 | } | ||
1108 | else if (afterIsInt && lengthIsInt) | ||
1109 | { | ||
1110 | // Special case: the caller is just trying to extract a substring, so do it quickly. | ||
1111 | int xBefore = atomLength - (int)After - (int)Length; | ||
1112 | if (xBefore >= 0) | ||
1113 | { | ||
1114 | foreach (bool l1 in YP.unify(Before, xBefore)) | ||
1115 | { | ||
1116 | foreach (bool l2 in YP.unify | ||
1117 | (Sub_atom, Atom.a(atomAtom._name.Substring(xBefore, (int)Length)))) | ||
1118 | yield return false; | ||
1119 | } | ||
1120 | } | ||
1121 | } | ||
1122 | else | ||
1123 | { | ||
1124 | // We are underconstrained and doing a search, so go through all possibilities. | ||
1125 | for (int xBefore = 0; xBefore <= atomLength; ++xBefore) | ||
1126 | { | ||
1127 | foreach (bool l1 in YP.unify(Before, xBefore)) | ||
1128 | { | ||
1129 | for (int xLength = 0; xLength <= (atomLength - xBefore); ++xLength) | ||
1130 | { | ||
1131 | foreach (bool l2 in YP.unify(Length, xLength)) | ||
1132 | { | ||
1133 | foreach (bool l3 in YP.unify(After, atomLength - (xBefore + xLength))) | ||
1134 | { | ||
1135 | foreach (bool l4 in YP.unify | ||
1136 | (Sub_atom, Atom.a(atomAtom._name.Substring(xBefore, xLength)))) | ||
1137 | yield return false; | ||
1138 | } | ||
1139 | } | ||
1140 | } | ||
1141 | } | ||
1142 | } | ||
1143 | } | ||
1144 | } | ||
1145 | |||
1146 | public static IEnumerable<bool> atom_chars(object atom, object List) | ||
1147 | { | ||
1148 | atom = YP.getValue(atom); | ||
1149 | List = YP.getValue(List); | ||
1150 | |||
1151 | if (atom is Variable) | ||
1152 | { | ||
1153 | if (List is Variable) | ||
1154 | throw new PrologException(Atom.a("instantiation_error"), | ||
1155 | "Arg 1 Atom and arg 2 List are both unbound variables"); | ||
1156 | object[] codeArray = ListPair.toArray(List); | ||
1157 | if (codeArray == null) | ||
1158 | throw new PrologException | ||
1159 | (new Functor2("type_error", Atom.a("list"), List), "Arg 2 List is not a list"); | ||
1160 | |||
1161 | char[] charArray = new char[codeArray.Length]; | ||
1162 | for (int i = 0; i < codeArray.Length; ++i) | ||
1163 | { | ||
1164 | object listAtom = YP.getValue(codeArray[i]); | ||
1165 | if (listAtom is Variable) | ||
1166 | throw new PrologException(Atom.a("instantiation_error"), | ||
1167 | "Arg 2 List has an element which is an unbound variable"); | ||
1168 | if (!(listAtom is Atom && ((Atom)listAtom)._name.Length == 1)) | ||
1169 | throw new PrologException | ||
1170 | (new Functor2("type_error", Atom.a("character"), listAtom), | ||
1171 | "Arg 2 List has an element which is not a one character atom"); | ||
1172 | charArray[i] = ((Atom)listAtom)._name[0]; | ||
1173 | } | ||
1174 | return YP.unify(atom, Atom.a(new String(charArray))); | ||
1175 | } | ||
1176 | else | ||
1177 | { | ||
1178 | if (!(atom is Atom)) | ||
1179 | throw new PrologException | ||
1180 | (new Functor2("type_error", Atom.a("atom"), atom), "Arg 1 Atom is not var or atom"); | ||
1181 | |||
1182 | string atomString = ((Atom)atom)._name; | ||
1183 | object charList = Atom.NIL; | ||
1184 | // Start from the back to make the list. | ||
1185 | for (int i = atomString.Length - 1; i >= 0; --i) | ||
1186 | charList = new ListPair(Atom.a(atomString.Substring(i, 1)), charList); | ||
1187 | return YP.unify(List, charList); | ||
1188 | } | ||
1189 | } | ||
1190 | |||
1191 | public static IEnumerable<bool> atom_codes(object atom, object List) | ||
1192 | { | ||
1193 | atom = YP.getValue(atom); | ||
1194 | List = YP.getValue(List); | ||
1195 | |||
1196 | if (atom is Variable) | ||
1197 | { | ||
1198 | if (List is Variable) | ||
1199 | throw new PrologException(Atom.a("instantiation_error"), | ||
1200 | "Arg 1 Atom and arg 2 List are both unbound variables"); | ||
1201 | object[] codeArray = ListPair.toArray(List); | ||
1202 | if (codeArray == null) | ||
1203 | throw new PrologException | ||
1204 | (new Functor2("type_error", Atom.a("list"), List), "Arg 2 List is not a list"); | ||
1205 | |||
1206 | char[] charArray = new char[codeArray.Length]; | ||
1207 | for (int i = 0; i < codeArray.Length; ++i) | ||
1208 | { | ||
1209 | int codeInt; | ||
1210 | if (!getInt(codeArray[i], out codeInt) || codeInt < 0) | ||
1211 | throw new PrologException | ||
1212 | (new Functor1("representation_error", Atom.a("character_code")), | ||
1213 | "Element of Arg 2 List is not a character code"); | ||
1214 | charArray[i] = (char)codeInt; | ||
1215 | } | ||
1216 | return YP.unify(atom, Atom.a(new String(charArray))); | ||
1217 | } | ||
1218 | else | ||
1219 | { | ||
1220 | if (!(atom is Atom)) | ||
1221 | throw new PrologException | ||
1222 | (new Functor2("type_error", Atom.a("atom"), atom), "Arg 1 Atom is not var or atom"); | ||
1223 | |||
1224 | string atomString = ((Atom)atom)._name; | ||
1225 | object codeList = Atom.NIL; | ||
1226 | // Start from the back to make the list. | ||
1227 | for (int i = atomString.Length - 1; i >= 0; --i) | ||
1228 | codeList = new ListPair((int)atomString[i], codeList); | ||
1229 | return YP.unify(List, codeList); | ||
1230 | } | ||
1231 | } | ||
1232 | |||
1233 | public static IEnumerable<bool> number_chars(object Number, object List) | ||
1234 | { | ||
1235 | Number = YP.getValue(Number); | ||
1236 | List = YP.getValue(List); | ||
1237 | |||
1238 | if (Number is Variable) | ||
1239 | { | ||
1240 | if (List is Variable) | ||
1241 | throw new PrologException(Atom.a("instantiation_error"), | ||
1242 | "Arg 1 Number and arg 2 List are both unbound variables"); | ||
1243 | object[] codeArray = ListPair.toArray(List); | ||
1244 | if (codeArray == null) | ||
1245 | throw new PrologException | ||
1246 | (new Functor2("type_error", Atom.a("list"), List), "Arg 2 List is not a list"); | ||
1247 | |||
1248 | char[] charArray = new char[codeArray.Length]; | ||
1249 | for (int i = 0; i < codeArray.Length; ++i) | ||
1250 | { | ||
1251 | object listAtom = YP.getValue(codeArray[i]); | ||
1252 | if (listAtom is Variable) | ||
1253 | throw new PrologException(Atom.a("instantiation_error"), | ||
1254 | "Arg 2 List has an element which is an unbound variable"); | ||
1255 | if (!(listAtom is Atom && ((Atom)listAtom)._name.Length == 1)) | ||
1256 | throw new PrologException | ||
1257 | (new Functor2("type_error", Atom.a("character"), listAtom), | ||
1258 | "Arg 2 List has an element which is not a one character atom"); | ||
1259 | charArray[i] = ((Atom)listAtom)._name[0]; | ||
1260 | } | ||
1261 | return YP.unify(Number, parseNumberString(charArray)); | ||
1262 | } | ||
1263 | else | ||
1264 | { | ||
1265 | string numberString = null; | ||
1266 | // Try converting to an int first. | ||
1267 | int intNumber; | ||
1268 | if (YP.getInt(Number, out intNumber)) | ||
1269 | numberString = intNumber.ToString(); | ||
1270 | else | ||
1271 | { | ||
1272 | if (!YP.number(Number)) | ||
1273 | throw new PrologException | ||
1274 | (new Functor2("type_error", Atom.a("number"), Number), | ||
1275 | "Arg 1 Number is not var or number"); | ||
1276 | // We just checked, so convertDouble shouldn't throw an exception. | ||
1277 | numberString = YP.doubleToString(YP.convertDouble(Number)); | ||
1278 | } | ||
1279 | |||
1280 | object charList = Atom.NIL; | ||
1281 | // Start from the back to make the list. | ||
1282 | for (int i = numberString.Length - 1; i >= 0; --i) | ||
1283 | charList = new ListPair(Atom.a(numberString.Substring(i, 1)), charList); | ||
1284 | return YP.unify(List, charList); | ||
1285 | } | ||
1286 | } | ||
1287 | |||
1288 | public static IEnumerable<bool> number_codes(object Number, object List) | ||
1289 | { | ||
1290 | Number = YP.getValue(Number); | ||
1291 | List = YP.getValue(List); | ||
1292 | |||
1293 | if (Number is Variable) | ||
1294 | { | ||
1295 | if (List is Variable) | ||
1296 | throw new PrologException(Atom.a("instantiation_error"), | ||
1297 | "Arg 1 Number and arg 2 List are both unbound variables"); | ||
1298 | object[] codeArray = ListPair.toArray(List); | ||
1299 | if (codeArray == null) | ||
1300 | throw new PrologException | ||
1301 | (new Functor2("type_error", Atom.a("list"), List), "Arg 2 List is not a list"); | ||
1302 | |||
1303 | char[] charArray = new char[codeArray.Length]; | ||
1304 | for (int i = 0; i < codeArray.Length; ++i) | ||
1305 | { | ||
1306 | int codeInt; | ||
1307 | if (!getInt(codeArray[i], out codeInt) || codeInt < 0) | ||
1308 | throw new PrologException | ||
1309 | (new Functor1("representation_error", Atom.a("character_code")), | ||
1310 | "Element of Arg 2 List is not a character code"); | ||
1311 | charArray[i] = (char)codeInt; | ||
1312 | } | ||
1313 | return YP.unify(Number, parseNumberString(charArray)); | ||
1314 | } | ||
1315 | else | ||
1316 | { | ||
1317 | string numberString = null; | ||
1318 | // Try converting to an int first. | ||
1319 | int intNumber; | ||
1320 | if (YP.getInt(Number, out intNumber)) | ||
1321 | numberString = intNumber.ToString(); | ||
1322 | else | ||
1323 | { | ||
1324 | if (!YP.number(Number)) | ||
1325 | throw new PrologException | ||
1326 | (new Functor2("type_error", Atom.a("number"), Number), | ||
1327 | "Arg 1 Number is not var or number"); | ||
1328 | // We just checked, so convertDouble shouldn't throw an exception. | ||
1329 | numberString = YP.doubleToString(YP.convertDouble(Number)); | ||
1330 | } | ||
1331 | |||
1332 | object codeList = Atom.NIL; | ||
1333 | // Start from the back to make the list. | ||
1334 | for (int i = numberString.Length - 1; i >= 0; --i) | ||
1335 | codeList = new ListPair((int)numberString[i], codeList); | ||
1336 | return YP.unify(List, codeList); | ||
1337 | } | ||
1338 | } | ||
1339 | |||
1340 | /// <summary> | ||
1341 | /// Used by number_chars and number_codes. Return the number in charArray or | ||
1342 | /// throw an exception if can't parse. | ||
1343 | /// </summary> | ||
1344 | /// <param name="numberString"></param> | ||
1345 | /// <returns></returns> | ||
1346 | private static object parseNumberString(char[] charArray) | ||
1347 | { | ||
1348 | string numberString = new String(charArray); | ||
1349 | if (charArray.Length == 3 && numberString.StartsWith("0'")) | ||
1350 | // This is a char code. | ||
1351 | return (int)charArray[2]; | ||
1352 | if (numberString.StartsWith("0x")) | ||
1353 | { | ||
1354 | try | ||
1355 | { | ||
1356 | return Int32.Parse | ||
1357 | (numberString.Substring(2), System.Globalization.NumberStyles.AllowHexSpecifier); | ||
1358 | } | ||
1359 | catch (FormatException) | ||
1360 | { | ||
1361 | throw new PrologException | ||
1362 | (new Functor1("syntax_error", Atom.a("number_format: " + numberString)), | ||
1363 | "Arg 2 List is not a list for a hexadecimal number"); | ||
1364 | } | ||
1365 | } | ||
1366 | // Debug: Is there a way in C# to ask if a string parses as int without throwing an exception? | ||
1367 | try | ||
1368 | { | ||
1369 | // Try an int first. | ||
1370 | return Convert.ToInt32(numberString); | ||
1371 | } | ||
1372 | catch (FormatException) { } | ||
1373 | try | ||
1374 | { | ||
1375 | return Convert.ToDouble(numberString); | ||
1376 | } | ||
1377 | catch (FormatException) | ||
1378 | { | ||
1379 | throw new PrologException | ||
1380 | (new Functor1("syntax_error", Atom.a("number_format: " + numberString)), | ||
1381 | "Arg 2 List is not a list for a number"); | ||
1382 | } | ||
1383 | } | ||
1384 | |||
1385 | public static IEnumerable<bool> char_code(object Char, object Code) | ||
1386 | { | ||
1387 | Char = YP.getValue(Char); | ||
1388 | Code = YP.getValue(Code); | ||
1389 | |||
1390 | int codeInt = 0; | ||
1391 | if (!(Code is Variable)) | ||
1392 | { | ||
1393 | // Get codeInt now so we type check it whether or not Char is Variable. | ||
1394 | if (!getInt(Code, out codeInt)) | ||
1395 | throw new PrologException | ||
1396 | (new Functor2("type_error", Atom.a("integer"), Code), | ||
1397 | "Arg 2 Code is not var or a character code"); | ||
1398 | if (codeInt < 0) | ||
1399 | throw new PrologException | ||
1400 | (new Functor1("representation_error", Atom.a("character_code")), | ||
1401 | "Arg 2 Code is not a character code"); | ||
1402 | } | ||
1403 | |||
1404 | if (Char is Variable) | ||
1405 | { | ||
1406 | if (Code is Variable) | ||
1407 | throw new PrologException(Atom.a("instantiation_error"), | ||
1408 | "Arg 1 Char and arg 2 Code are both unbound variables"); | ||
1409 | |||
1410 | return YP.unify(Char, Atom.a(new String(new char[] {(char)codeInt}))); | ||
1411 | } | ||
1412 | else | ||
1413 | { | ||
1414 | if (!(Char is Atom) || ((Atom)Char)._name.Length != 1) | ||
1415 | throw new PrologException | ||
1416 | (new Functor2("type_error", Atom.a("character"), Char), | ||
1417 | "Arg 1 Char is not var or one-character atom"); | ||
1418 | |||
1419 | if (Code is Variable) | ||
1420 | return YP.unify(Code, (int)((Atom)Char)._name[0]); | ||
1421 | else | ||
1422 | // Use codeInt to handle whether Code is supplied as, e.g., 97 or 0'a . | ||
1423 | return YP.unify(codeInt, (int)((Atom)Char)._name[0]); | ||
1424 | } | ||
1425 | } | ||
1426 | |||
1427 | /// <summary> | ||
1428 | /// If term is an Atom or functor type, return its name. | ||
1429 | /// Otherwise, return term. | ||
1430 | /// </summary> | ||
1431 | /// <param name="term"></param> | ||
1432 | /// <returns></returns> | ||
1433 | public static object getFunctorName(object term) | ||
1434 | { | ||
1435 | term = YP.getValue(term); | ||
1436 | if (term is Functor1) | ||
1437 | return ((Functor1)term)._name; | ||
1438 | else if (term is Functor2) | ||
1439 | return ((Functor2)term)._name; | ||
1440 | else if (term is Functor3) | ||
1441 | return ((Functor3)term)._name; | ||
1442 | else if (term is Functor) | ||
1443 | return ((Functor)term)._name; | ||
1444 | else | ||
1445 | return term; | ||
1446 | } | ||
1447 | |||
1448 | /// <summary> | ||
1449 | /// If term is an Atom or functor type, return an array of its args. | ||
1450 | /// Otherwise, return an empty array. | ||
1451 | /// </summary> | ||
1452 | /// <param name="term"></param> | ||
1453 | /// <returns></returns> | ||
1454 | public static object[] getFunctorArgs(object term) | ||
1455 | { | ||
1456 | term = YP.getValue(term); | ||
1457 | if (term is Functor1) | ||
1458 | { | ||
1459 | Functor1 functor = (Functor1)term; | ||
1460 | return new object[] { functor._arg1 }; | ||
1461 | } | ||
1462 | else if (term is Functor2) | ||
1463 | { | ||
1464 | Functor2 functor = (Functor2)term; | ||
1465 | return new object[] { functor._arg1, functor._arg2 }; | ||
1466 | } | ||
1467 | else if (term is Functor3) | ||
1468 | { | ||
1469 | Functor3 functor = (Functor3)term; | ||
1470 | return new object[] { functor._arg1, functor._arg2, functor._arg3 }; | ||
1471 | } | ||
1472 | else if (term is Functor) { | ||
1473 | Functor functor = (Functor)term; | ||
1474 | return functor._args; | ||
1475 | } | ||
1476 | else | ||
1477 | return new object[0]; | ||
1478 | } | ||
1479 | |||
1480 | public static bool var(object Term) | ||
1481 | { | ||
1482 | return YP.getValue(Term) is Variable; | ||
1483 | } | ||
1484 | |||
1485 | public static bool nonvar(object Term) | ||
1486 | { | ||
1487 | return !YP.var(Term); | ||
1488 | } | ||
1489 | |||
1490 | public static bool atom(object Term) | ||
1491 | { | ||
1492 | return YP.getValue(Term) is Atom; | ||
1493 | } | ||
1494 | |||
1495 | public static bool integer(object Term) | ||
1496 | { | ||
1497 | // Debug: Should exhaustively check for all integer types. | ||
1498 | return getValue(Term) is int; | ||
1499 | } | ||
1500 | |||
1501 | // Use isFloat instead of float because it is a reserved keyword. | ||
1502 | public static bool isFloat(object Term) | ||
1503 | { | ||
1504 | // Debug: Should exhaustively check for all float types. | ||
1505 | return getValue(Term) is double; | ||
1506 | } | ||
1507 | |||
1508 | public static bool number(object Term) | ||
1509 | { | ||
1510 | return YP.integer(Term) || YP.isFloat(Term); | ||
1511 | } | ||
1512 | |||
1513 | public static bool atomic(object Term) | ||
1514 | { | ||
1515 | return YP.atom(Term) || YP.number(Term); | ||
1516 | } | ||
1517 | |||
1518 | public static bool compound(object Term) | ||
1519 | { | ||
1520 | Term = getValue(Term); | ||
1521 | return Term is Functor1 || Term is Functor2 || Term is Functor3 || Term is Functor; | ||
1522 | } | ||
1523 | |||
1524 | /// <summary> | ||
1525 | /// If input is a TextReader, use it. If input is an Atom or String, create a StreamReader with the | ||
1526 | /// input as the filename. If input is a Prolog list, then read character codes from it. | ||
1527 | /// </summary> | ||
1528 | /// <param name="input"></param> | ||
1529 | public static void see(object input) | ||
1530 | { | ||
1531 | input = YP.getValue(input); | ||
1532 | if (input is Variable) | ||
1533 | throw new PrologException(Atom.a("instantiation_error"), "Arg is an unbound variable"); | ||
1534 | |||
1535 | if (input == null) | ||
1536 | { | ||
1537 | _inputStream = null; | ||
1538 | return; | ||
1539 | } | ||
1540 | if (input is TextReader) | ||
1541 | { | ||
1542 | _inputStream = (TextReader)input; | ||
1543 | return; | ||
1544 | } | ||
1545 | else if (input is Atom) | ||
1546 | { | ||
1547 | _inputStream = new StreamReader(((Atom)input)._name); | ||
1548 | return; | ||
1549 | } | ||
1550 | else if (input is String) | ||
1551 | { | ||
1552 | _inputStream = new StreamReader((String)input); | ||
1553 | return; | ||
1554 | } | ||
1555 | else if (input is Functor2 && ((Functor2)input)._name == Atom.DOT) | ||
1556 | { | ||
1557 | _inputStream = new CodeListReader(input); | ||
1558 | return; | ||
1559 | } | ||
1560 | else | ||
1561 | throw new PrologException | ||
1562 | (new Functor2("domain_error", Atom.a("stream_or_alias"), input), | ||
1563 | "Input stream specifier not recognized"); | ||
1564 | } | ||
1565 | |||
1566 | public static void seen() | ||
1567 | { | ||
1568 | if (_inputStream == null) | ||
1569 | return; | ||
1570 | if (_inputStream == Console.In) | ||
1571 | return; | ||
1572 | _inputStream.Close(); | ||
1573 | _inputStream = Console.In; | ||
1574 | } | ||
1575 | |||
1576 | public static IEnumerable<bool> current_input(object Stream) | ||
1577 | { | ||
1578 | return YP.unify(Stream, _inputStream); | ||
1579 | } | ||
1580 | |||
1581 | /// <summary> | ||
1582 | /// If output is a TextWriter, use it. If output is an Atom or a String, create a StreamWriter | ||
1583 | /// with the input as the filename. | ||
1584 | /// </summary> | ||
1585 | /// <param name="output"></param> | ||
1586 | public static void tell(object output) | ||
1587 | { | ||
1588 | output = YP.getValue(output); | ||
1589 | if (output is Variable) | ||
1590 | throw new PrologException(Atom.a("instantiation_error"), "Arg is an unbound variable"); | ||
1591 | |||
1592 | if (output == null) | ||
1593 | { | ||
1594 | _outputStream = null; | ||
1595 | return; | ||
1596 | } | ||
1597 | if (output is TextWriter) | ||
1598 | { | ||
1599 | _outputStream = (TextWriter)output; | ||
1600 | return; | ||
1601 | } | ||
1602 | else if (output is Atom) | ||
1603 | { | ||
1604 | _outputStream = new StreamWriter(((Atom)output)._name); | ||
1605 | return; | ||
1606 | } | ||
1607 | else if (output is String) | ||
1608 | { | ||
1609 | _outputStream = new StreamWriter((String)output); | ||
1610 | return; | ||
1611 | } | ||
1612 | else | ||
1613 | throw new PrologException | ||
1614 | (new Functor2("domain_error", Atom.a("stream_or_alias"), output), | ||
1615 | "Can't open stream for " + output); | ||
1616 | } | ||
1617 | |||
1618 | public static void told() | ||
1619 | { | ||
1620 | if (_outputStream == null) | ||
1621 | return; | ||
1622 | if (_outputStream == Console.Out) | ||
1623 | return; | ||
1624 | _outputStream.Close(); | ||
1625 | _outputStream = Console.Out; | ||
1626 | } | ||
1627 | |||
1628 | public static IEnumerable<bool> current_output(object Stream) | ||
1629 | { | ||
1630 | return YP.unify(Stream, _outputStream); | ||
1631 | } | ||
1632 | |||
1633 | public static void write(object x) | ||
1634 | { | ||
1635 | if (_outputStream == null) | ||
1636 | return; | ||
1637 | x = YP.getValue(x); | ||
1638 | if (x is double) | ||
1639 | _outputStream.Write(doubleToString((double)x)); | ||
1640 | else | ||
1641 | _outputStream.Write(x.ToString()); | ||
1642 | } | ||
1643 | |||
1644 | /// <summary> | ||
1645 | /// Format x as a string, making sure that it won't parse as an int later. I.e., for 1.0, don't just | ||
1646 | /// use "1" which will parse as an int. | ||
1647 | /// </summary> | ||
1648 | /// <param name="x"></param> | ||
1649 | /// <returns></returns> | ||
1650 | private static string doubleToString(double x) | ||
1651 | { | ||
1652 | string xString = x.ToString(); | ||
1653 | // Debug: Is there a way in C# to ask if a string parses as int without throwing an exception? | ||
1654 | try | ||
1655 | { | ||
1656 | Convert.ToInt32(xString); | ||
1657 | // The string will parse as an int, not a double, so re-format so that it does. | ||
1658 | // Use float if possible, else exponential if it would be too big. | ||
1659 | return x.ToString(x >= 100000.0 ? "E1" : "f1"); | ||
1660 | } | ||
1661 | catch (FormatException) | ||
1662 | { | ||
1663 | // Assume it will parse as a double. | ||
1664 | } | ||
1665 | return xString; | ||
1666 | } | ||
1667 | |||
1668 | public static void put_code(object x) | ||
1669 | { | ||
1670 | if (_outputStream == null) | ||
1671 | return; | ||
1672 | if (var(x)) | ||
1673 | throw new PrologException(Atom.a("instantiation_error"), "Arg 1 is an unbound variable"); | ||
1674 | int xInt; | ||
1675 | if (!getInt(x, out xInt)) | ||
1676 | throw new PrologException | ||
1677 | (new Functor2("type_error", Atom.a("integer"), x), "Arg 1 must be integer"); | ||
1678 | _outputStream.Write((char)xInt); | ||
1679 | } | ||
1680 | |||
1681 | public static void nl() | ||
1682 | { | ||
1683 | if (_outputStream == null) | ||
1684 | return; | ||
1685 | _outputStream.WriteLine(); | ||
1686 | } | ||
1687 | |||
1688 | public static IEnumerable<bool> get_code(object code) | ||
1689 | { | ||
1690 | if (_inputStream == null) | ||
1691 | return YP.unify(code, -1); | ||
1692 | else | ||
1693 | return YP.unify(code, _inputStream.Read()); | ||
1694 | } | ||
1695 | |||
1696 | public static void asserta(object Term, Type declaringClass) | ||
1697 | { | ||
1698 | assertDynamic(Term, declaringClass, true); | ||
1699 | } | ||
1700 | |||
1701 | public static void assertz(object Term, Type declaringClass) | ||
1702 | { | ||
1703 | assertDynamic(Term, declaringClass, false); | ||
1704 | } | ||
1705 | |||
1706 | public static void assertDynamic(object Term, Type declaringClass, bool prepend) | ||
1707 | { | ||
1708 | Term = getValue(Term); | ||
1709 | if (Term is Variable) | ||
1710 | throw new PrologException("instantiation_error", "Term to assert is an unbound variable"); | ||
1711 | |||
1712 | Variable.CopyStore copyStore = new Variable.CopyStore(); | ||
1713 | object TermCopy = makeCopy(Term, copyStore); | ||
1714 | object Head, Body; | ||
1715 | if (TermCopy is Functor2 && ((Functor2)TermCopy)._name == Atom.RULE) | ||
1716 | { | ||
1717 | Head = YP.getValue(((Functor2)TermCopy)._arg1); | ||
1718 | Body = YP.getValue(((Functor2)TermCopy)._arg2); | ||
1719 | if (Head is Variable) | ||
1720 | throw new PrologException("instantiation_error", "Head to assert is an unbound variable"); | ||
1721 | if (Body is Variable) | ||
1722 | throw new PrologException("instantiation_error", "Body to assert is an unbound variable"); | ||
1723 | } | ||
1724 | else | ||
1725 | { | ||
1726 | Head = TermCopy; | ||
1727 | Body = Atom.a("true"); | ||
1728 | } | ||
1729 | |||
1730 | Atom name = getFunctorName(Head) as Atom; | ||
1731 | if (name == null) | ||
1732 | // name is a non-Atom, such as a number. | ||
1733 | throw new PrologException | ||
1734 | (new Functor2("type_error", Atom.a("callable"), Head), "Term to assert is not callable"); | ||
1735 | object[] args = getFunctorArgs(Head); | ||
1736 | if (isSystemPredicate(name, args.Length)) | ||
1737 | throw new PrologException | ||
1738 | (new Functor3("permission_error", Atom.a("modify"), Atom.a("static_procedure"), | ||
1739 | new Functor2(Atom.SLASH, name, args.Length)), | ||
1740 | "Assert cannot modify static predicate " + name + "/" + args.Length); | ||
1741 | |||
1742 | if (copyStore.getNUniqueVariables() == 0 && Body == Atom.a("true")) | ||
1743 | { | ||
1744 | // This is a fact with no unbound variables | ||
1745 | // assertFact and prependFact use IndexedAnswers, so don't we don't need to compile. | ||
1746 | if (prepend) | ||
1747 | prependFact(name, args); | ||
1748 | else | ||
1749 | assertFact(name, args); | ||
1750 | |||
1751 | return; | ||
1752 | } | ||
1753 | |||
1754 | IClause clause = YPCompiler.compileAnonymousClause(Head, Body, declaringClass); | ||
1755 | // We expect clause to be a ClauseHeadAndBody (from Compiler.compileAnonymousFunction) | ||
1756 | // so we can set the Head and Body. | ||
1757 | if (clause is ClauseHeadAndBody) | ||
1758 | ((ClauseHeadAndBody)clause).setHeadAndBody(Head, Body); | ||
1759 | |||
1760 | // Add the clause to the entry in _predicatesStore. | ||
1761 | NameArity nameArity = new NameArity(name, args.Length); | ||
1762 | List<IClause> clauses; | ||
1763 | if (!_predicatesStore.TryGetValue(nameArity, out clauses)) | ||
1764 | // Create an entry for the nameArity. | ||
1765 | _predicatesStore[nameArity] = (clauses = new List<IClause>()); | ||
1766 | |||
1767 | if (prepend) | ||
1768 | clauses.Insert(0, clause); | ||
1769 | else | ||
1770 | clauses.Add(clause); | ||
1771 | } | ||
1772 | |||
1773 | private static bool isSystemPredicate(Atom name, int arity) | ||
1774 | { | ||
1775 | if (arity == 2 && (name == Atom.a(",") || name == Atom.a(";") || name == Atom.DOT)) | ||
1776 | return true; | ||
1777 | // Use the same mapping to static predicates in YP as the compiler. | ||
1778 | foreach (bool l1 in YPCompiler.functorCallYPFunctionName(name, arity, new Variable())) | ||
1779 | return true; | ||
1780 | // Debug: Do we need to check if name._module is null? | ||
1781 | return false; | ||
1782 | } | ||
1783 | |||
1784 | /// <summary> | ||
1785 | /// Assert values at the end of the set of facts for the predicate with the | ||
1786 | /// name and with arity values.Length. | ||
1787 | /// </summary> | ||
1788 | /// <param name="name">must be an Atom</param> | ||
1789 | /// <param name="values">the array of arguments to the fact predicate. | ||
1790 | /// It is an error if an value has an unbound variable.</param> | ||
1791 | public static void assertFact(Atom name, object[] values) | ||
1792 | { | ||
1793 | NameArity nameArity = new NameArity(name, values.Length); | ||
1794 | List<IClause> clauses; | ||
1795 | IndexedAnswers indexedAnswers; | ||
1796 | if (!_predicatesStore.TryGetValue(nameArity, out clauses)) | ||
1797 | { | ||
1798 | // Create an IndexedAnswers as the only clause of the predicate. | ||
1799 | _predicatesStore[nameArity] = (clauses = new List<IClause>()); | ||
1800 | clauses.Add(indexedAnswers = new IndexedAnswers(values.Length)); | ||
1801 | } | ||
1802 | else | ||
1803 | { | ||
1804 | indexedAnswers = null; | ||
1805 | if (clauses.Count >= 1) | ||
1806 | indexedAnswers = clauses[clauses.Count - 1] as IndexedAnswers; | ||
1807 | if (indexedAnswers == null) | ||
1808 | // The latest clause is not an IndexedAnswers, so add one. | ||
1809 | clauses.Add(indexedAnswers = new IndexedAnswers(values.Length)); | ||
1810 | } | ||
1811 | |||
1812 | indexedAnswers.addAnswer(values); | ||
1813 | } | ||
1814 | |||
1815 | /// <summary> | ||
1816 | /// Assert values, prepending to the front of the set of facts for the predicate with the | ||
1817 | /// name and with arity values.Length. | ||
1818 | /// </summary> | ||
1819 | /// <param name="name">must be an Atom</param> | ||
1820 | /// <param name="values">the array of arguments to the fact predicate. | ||
1821 | /// It is an error if an value has an unbound variable.</param> | ||
1822 | public static void prependFact(Atom name, object[] values) | ||
1823 | { | ||
1824 | NameArity nameArity = new NameArity(name, values.Length); | ||
1825 | List<IClause> clauses; | ||
1826 | IndexedAnswers indexedAnswers; | ||
1827 | if (!_predicatesStore.TryGetValue(nameArity, out clauses)) | ||
1828 | { | ||
1829 | // Create an IndexedAnswers as the only clause of the predicate. | ||
1830 | _predicatesStore[nameArity] = (clauses = new List<IClause>()); | ||
1831 | clauses.Add(indexedAnswers = new IndexedAnswers(values.Length)); | ||
1832 | } | ||
1833 | else | ||
1834 | { | ||
1835 | indexedAnswers = null; | ||
1836 | if (clauses.Count >= 1) | ||
1837 | indexedAnswers = clauses[0] as IndexedAnswers; | ||
1838 | if (indexedAnswers == null) | ||
1839 | // The first clause is not an IndexedAnswers, so prepend one. | ||
1840 | clauses.Insert(0, indexedAnswers = new IndexedAnswers(values.Length)); | ||
1841 | } | ||
1842 | |||
1843 | indexedAnswers.prependAnswer(values); | ||
1844 | } | ||
1845 | |||
1846 | /// <summary> | ||
1847 | /// Match all clauses of the dynamic predicate with the name and with arity | ||
1848 | /// arguments.Length. | ||
1849 | /// If the predicate is not defined, return the result of YP.unknownPredicate. | ||
1850 | /// </summary> | ||
1851 | /// <param name="name">must be an Atom</param> | ||
1852 | /// <param name="arguments">an array of arity number of arguments</param> | ||
1853 | /// <returns>an iterator which you can use in foreach</returns> | ||
1854 | public static IEnumerable<bool> matchDynamic(Atom name, object[] arguments) | ||
1855 | { | ||
1856 | List<IClause> clauses; | ||
1857 | if (!_predicatesStore.TryGetValue(new NameArity(name, arguments.Length), out clauses)) | ||
1858 | return unknownPredicate(name, arguments.Length, | ||
1859 | "Undefined dynamic predicate: " + name + "/" + arguments.Length); | ||
1860 | |||
1861 | if (clauses.Count == 1) | ||
1862 | // Usually there is only one clause, so return it without needing to wrap it in an iterator. | ||
1863 | return clauses[0].match(arguments); | ||
1864 | else | ||
1865 | return matchAllClauses(clauses, arguments); | ||
1866 | } | ||
1867 | |||
1868 | /// <summary> | ||
1869 | /// Call match(arguments) for each IClause in clauses. We make this a separate | ||
1870 | /// function so that matchDynamic itself does not need to be an iterator object. | ||
1871 | /// </summary> | ||
1872 | /// <param name="clauses"></param> | ||
1873 | /// <param name="arguments"></param> | ||
1874 | /// <returns></returns> | ||
1875 | private static IEnumerable<bool> matchAllClauses(List<IClause> clauses, object[] arguments) | ||
1876 | { | ||
1877 | // Debug: If the caller asserts another clause into this same predicate during yield, the iterator | ||
1878 | // over clauses will be corrupted. Should we take the time to copy clauses? | ||
1879 | foreach (IClause clause in clauses) | ||
1880 | { | ||
1881 | foreach (bool lastCall in clause.match(arguments)) | ||
1882 | { | ||
1883 | yield return false; | ||
1884 | if (lastCall) | ||
1885 | // This happens after a cut in a clause. | ||
1886 | yield break; | ||
1887 | } | ||
1888 | } | ||
1889 | } | ||
1890 | |||
1891 | /// <summary> | ||
1892 | /// If _prologFlags["unknown"] is fail then return fail(), else if | ||
1893 | /// _prologFlags["unknown"] is warning then write the message to YP.write and | ||
1894 | /// return fail(), else throw a PrologException for existence_error. . | ||
1895 | /// </summary> | ||
1896 | /// <param name="name"></param> | ||
1897 | /// <param name="arity"></param> | ||
1898 | /// <param name="message"></param> | ||
1899 | /// <returns></returns> | ||
1900 | public static IEnumerable<bool> unknownPredicate(Atom name, int arity, string message) | ||
1901 | { | ||
1902 | establishPrologFlags(); | ||
1903 | |||
1904 | if (_prologFlags["unknown"] == Atom.a("fail")) | ||
1905 | return fail(); | ||
1906 | else if (_prologFlags["unknown"] == Atom.a("warning")) | ||
1907 | { | ||
1908 | write(message); | ||
1909 | nl(); | ||
1910 | return fail(); | ||
1911 | } | ||
1912 | else | ||
1913 | throw new PrologException | ||
1914 | (new Functor2 | ||
1915 | (Atom.a("existence_error"), Atom.a("procedure"), | ||
1916 | new Functor2(Atom.SLASH, name, arity)), message); | ||
1917 | } | ||
1918 | |||
1919 | /// <summary> | ||
1920 | /// This is deprecated and just calls matchDynamic. This matches all clauses, | ||
1921 | /// not just the ones defined with assertFact. | ||
1922 | /// </summary> | ||
1923 | /// <param name="name"></param> | ||
1924 | /// <param name="arguments"></param> | ||
1925 | /// <returns></returns> | ||
1926 | public static IEnumerable<bool> matchFact(Atom name, object[] arguments) | ||
1927 | { | ||
1928 | return matchDynamic(name, arguments); | ||
1929 | } | ||
1930 | |||
1931 | public static IEnumerable<bool> clause(object Head, object Body) | ||
1932 | { | ||
1933 | Head = getValue(Head); | ||
1934 | Body = getValue(Body); | ||
1935 | if (Head is Variable) | ||
1936 | throw new PrologException("instantiation_error", "Head is an unbound variable"); | ||
1937 | |||
1938 | Atom name = getFunctorName(Head) as Atom; | ||
1939 | if (name == null) | ||
1940 | // name is a non-Atom, such as a number. | ||
1941 | throw new PrologException | ||
1942 | (new Functor2("type_error", Atom.a("callable"), Head), "Head is not callable"); | ||
1943 | object[] args = getFunctorArgs(Head); | ||
1944 | if (isSystemPredicate(name, args.Length)) | ||
1945 | throw new PrologException | ||
1946 | (new Functor3("permission_error", Atom.a("access"), Atom.a("private_procedure"), | ||
1947 | new Functor2(Atom.SLASH, name, args.Length)), | ||
1948 | "clause cannot access private predicate " + name + "/" + args.Length); | ||
1949 | if (!(Body is Variable) && !(YP.getFunctorName(Body) is Atom)) | ||
1950 | throw new PrologException | ||
1951 | (new Functor2("type_error", Atom.a("callable"), Body), "Body is not callable"); | ||
1952 | |||
1953 | List<IClause> clauses; | ||
1954 | if (!_predicatesStore.TryGetValue(new NameArity(name, args.Length), out clauses)) | ||
1955 | yield break; | ||
1956 | // The caller can assert another clause into this same predicate during yield, so we have to | ||
1957 | // make a copy of the clauses. | ||
1958 | foreach (IClause predicateClause in clauses.ToArray()) | ||
1959 | { | ||
1960 | foreach (bool l1 in predicateClause.clause(Head, Body)) | ||
1961 | yield return false; | ||
1962 | } | ||
1963 | } | ||
1964 | |||
1965 | public static IEnumerable<bool> retract(object Term) | ||
1966 | { | ||
1967 | Term = getValue(Term); | ||
1968 | if (Term is Variable) | ||
1969 | throw new PrologException("instantiation_error", "Term to retract is an unbound variable"); | ||
1970 | |||
1971 | object Head, Body; | ||
1972 | if (Term is Functor2 && ((Functor2)Term)._name == Atom.RULE) | ||
1973 | { | ||
1974 | Head = YP.getValue(((Functor2)Term)._arg1); | ||
1975 | Body = YP.getValue(((Functor2)Term)._arg2); | ||
1976 | } | ||
1977 | else | ||
1978 | { | ||
1979 | Head = Term; | ||
1980 | Body = Atom.a("true"); | ||
1981 | } | ||
1982 | if (Head is Variable) | ||
1983 | throw new PrologException("instantiation_error", "Head is an unbound variable"); | ||
1984 | |||
1985 | Atom name = getFunctorName(Head) as Atom; | ||
1986 | if (name == null) | ||
1987 | // name is a non-Atom, such as a number. | ||
1988 | throw new PrologException | ||
1989 | (new Functor2("type_error", Atom.a("callable"), Head), "Head is not callable"); | ||
1990 | object[] args = getFunctorArgs(Head); | ||
1991 | if (isSystemPredicate(name, args.Length)) | ||
1992 | throw new PrologException | ||
1993 | (new Functor3("permission_error", Atom.a("modify"), Atom.a("static_procedure"), | ||
1994 | new Functor2(Atom.SLASH, name, args.Length)), | ||
1995 | "clause cannot access private predicate " + name + "/" + args.Length); | ||
1996 | if (!(Body is Variable) && !(YP.getFunctorName(Body) is Atom)) | ||
1997 | throw new PrologException | ||
1998 | (new Functor2("type_error", Atom.a("callable"), Body), "Body is not callable"); | ||
1999 | |||
2000 | List<IClause> clauses; | ||
2001 | if (!_predicatesStore.TryGetValue(new NameArity(name, args.Length), out clauses)) | ||
2002 | yield break; | ||
2003 | // The caller can assert another clause into this same predicate during yield, so we have to | ||
2004 | // make a copy of the clauses. | ||
2005 | foreach (IClause predicateClause in clauses.ToArray()) | ||
2006 | { | ||
2007 | if (predicateClause is IndexedAnswers) | ||
2008 | { | ||
2009 | // IndexedAnswers handles its own retract. Even if it removes all of its | ||
2010 | // answers, it is OK to leave it empty as one of the elements in clauses. | ||
2011 | foreach (bool l1 in ((IndexedAnswers)predicateClause).retract(Head, Body)) | ||
2012 | yield return false; | ||
2013 | } | ||
2014 | else | ||
2015 | { | ||
2016 | foreach (bool l1 in predicateClause.clause(Head, Body)) | ||
2017 | { | ||
2018 | clauses.Remove(predicateClause); | ||
2019 | yield return false; | ||
2020 | } | ||
2021 | } | ||
2022 | } | ||
2023 | } | ||
2024 | |||
2025 | /// <summary> | ||
2026 | /// This is deprecated for backward compatibility. You should use retractall. | ||
2027 | /// </summary> | ||
2028 | /// <param name="name">must be an Atom</param> | ||
2029 | /// <param name="arguments">an array of arity number of arguments</param> | ||
2030 | public static void retractFact(Atom name, object[] arguments) | ||
2031 | { | ||
2032 | retractall(Functor.make(name, arguments)); | ||
2033 | } | ||
2034 | |||
2035 | /// <summary> | ||
2036 | /// Retract all dynamic clauses which unify with Head. If this matches all clauses in a predicate, | ||
2037 | /// the predicate is still defined. To completely remove the predicate, see abolish. | ||
2038 | /// </summary> | ||
2039 | /// <param name="Head"></param> | ||
2040 | public static void retractall(object Head) | ||
2041 | { | ||
2042 | object name = YP.getFunctorName(Head); | ||
2043 | object[] arguments = getFunctorArgs(Head); | ||
2044 | if (!(name is Atom)) | ||
2045 | return; | ||
2046 | NameArity nameArity = new NameArity((Atom)name, arguments.Length); | ||
2047 | List<IClause> clauses; | ||
2048 | if (!_predicatesStore.TryGetValue(nameArity, out clauses)) | ||
2049 | // Can't find, so ignore. | ||
2050 | return; | ||
2051 | |||
2052 | foreach (object arg in arguments) | ||
2053 | { | ||
2054 | if (!YP.var(arg)) | ||
2055 | throw new InvalidOperationException | ||
2056 | ("Until matching retractall is supported, all arguments must be unbound to retract all clauses"); | ||
2057 | } | ||
2058 | // Clear all clauses. | ||
2059 | _predicatesStore[nameArity] = new List<IClause>(); | ||
2060 | } | ||
2061 | |||
2062 | /// <summary> | ||
2063 | /// If NameSlashArity is var, match with all the dynamic predicates using the | ||
2064 | /// Name/Artity form. | ||
2065 | /// If NameSlashArity is not var, check if the Name/Arity exists as a static or | ||
2066 | /// dynamic predicate. | ||
2067 | /// </summary> | ||
2068 | /// <param name="NameSlashArity"></param> | ||
2069 | /// <param name="declaringClass">if not null, used to resolve references to the default | ||
2070 | /// module Atom.a("")</param> | ||
2071 | /// <returns></returns> | ||
2072 | public static IEnumerable<bool> current_predicate(object NameSlashArity, Type declaringClass) | ||
2073 | { | ||
2074 | NameSlashArity = YP.getValue(NameSlashArity); | ||
2075 | // First check if Name and Arity are nonvar so we can do a direct lookup. | ||
2076 | if (YP.ground(NameSlashArity)) | ||
2077 | { | ||
2078 | Functor2 NameArityFunctor = NameSlashArity as Functor2; | ||
2079 | if (!(NameArityFunctor != null && NameArityFunctor._name == Atom.SLASH)) | ||
2080 | throw new PrologException | ||
2081 | (new Functor2("type_error", Atom.a("predicate_indicator"), NameSlashArity), | ||
2082 | "Must be a name/arity predicate indicator"); | ||
2083 | object name = YP.getValue(NameArityFunctor._arg1); | ||
2084 | object arity = YP.getValue(NameArityFunctor._arg2); | ||
2085 | if (name is Variable || arity is Variable) | ||
2086 | throw new PrologException | ||
2087 | ("instantiation_error", "Predicate indicator name or arity is an unbound variable"); | ||
2088 | if (!(name is Atom && arity is int)) | ||
2089 | throw new PrologException | ||
2090 | (new Functor2("type_error", Atom.a("predicate_indicator"), NameSlashArity), | ||
2091 | "Must be a name/arity predicate indicator"); | ||
2092 | if ((int)arity < 0) | ||
2093 | throw new PrologException | ||
2094 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), arity), | ||
2095 | "Arity may not be less than zero"); | ||
2096 | |||
2097 | if (YPCompiler.isCurrentPredicate((Atom)name, (int)arity, declaringClass)) | ||
2098 | // The predicate is defined. | ||
2099 | yield return false; | ||
2100 | } | ||
2101 | else | ||
2102 | { | ||
2103 | foreach (NameArity key in _predicatesStore.Keys) | ||
2104 | { | ||
2105 | foreach (bool l1 in YP.unify | ||
2106 | (new Functor2(Atom.SLASH, key._name, key._arity), NameSlashArity)) | ||
2107 | yield return false; | ||
2108 | } | ||
2109 | } | ||
2110 | } | ||
2111 | |||
2112 | /// <summary> | ||
2113 | /// Return true if the dynamic predicate store has an entry for the predicate | ||
2114 | /// with name and arity. | ||
2115 | /// </summary> | ||
2116 | /// <param name="name"></param> | ||
2117 | /// <param name="arity"></param> | ||
2118 | /// <returns></returns> | ||
2119 | public static bool isDynamicCurrentPredicate(Atom name, int arity) | ||
2120 | { | ||
2121 | return _predicatesStore.ContainsKey(new NameArity(name, arity)); | ||
2122 | } | ||
2123 | |||
2124 | public static void abolish(object NameSlashArity) | ||
2125 | { | ||
2126 | NameSlashArity = YP.getValue(NameSlashArity); | ||
2127 | if (NameSlashArity is Variable) | ||
2128 | throw new PrologException | ||
2129 | ("instantiation_error", "Predicate indicator is an unbound variable"); | ||
2130 | Functor2 NameArityFunctor = NameSlashArity as Functor2; | ||
2131 | if (!(NameArityFunctor != null && NameArityFunctor._name == Atom.SLASH)) | ||
2132 | throw new PrologException | ||
2133 | (new Functor2("type_error", Atom.a("predicate_indicator"), NameSlashArity), | ||
2134 | "Must be a name/arity predicate indicator"); | ||
2135 | object name = YP.getValue(NameArityFunctor._arg1); | ||
2136 | object arity = YP.getValue(NameArityFunctor._arg2); | ||
2137 | if (name is Variable || arity is Variable) | ||
2138 | throw new PrologException | ||
2139 | ("instantiation_error", "Predicate indicator name or arity is an unbound variable"); | ||
2140 | if (!(name is Atom)) | ||
2141 | throw new PrologException | ||
2142 | (new Functor2("type_error", Atom.a("atom"), name), | ||
2143 | "Predicate indicator name must be an atom"); | ||
2144 | if (!(arity is int)) | ||
2145 | throw new PrologException | ||
2146 | (new Functor2("type_error", Atom.a("integer"), arity), | ||
2147 | "Predicate indicator arity must be an integer"); | ||
2148 | if ((int)arity < 0) | ||
2149 | throw new PrologException | ||
2150 | (new Functor2("domain_error", Atom.a("not_less_than_zero"), arity), | ||
2151 | "Arity may not be less than zero"); | ||
2152 | if ((int)arity > MAX_ARITY) | ||
2153 | throw new PrologException | ||
2154 | (new Functor1("representation_error", Atom.a("max_arity")), | ||
2155 | "Arity may not be greater than " + MAX_ARITY); | ||
2156 | |||
2157 | if (isSystemPredicate((Atom)name, (int)arity)) | ||
2158 | throw new PrologException | ||
2159 | (new Functor3("permission_error", Atom.a("modify"), Atom.a("static_procedure"), | ||
2160 | new Functor2(Atom.SLASH, name, arity)), | ||
2161 | "Abolish cannot modify static predicate " + name + "/" + arity); | ||
2162 | _predicatesStore.Remove(new NameArity((Atom)name, (int)arity)); | ||
2163 | } | ||
2164 | |||
2165 | /// <summary> | ||
2166 | /// If Goal is a simple predicate, call YP.getFunctorName(Goal) using arguments from | ||
2167 | /// YP.getFunctorArgs(Goal). If not found, this throws a PrologException for existence_error. | ||
2168 | /// Otherwise, compile the goal as a single clause predicate and invoke it. | ||
2169 | /// </summary> | ||
2170 | /// <param name="Goal"></param> | ||
2171 | /// <param name="declaringClass">if not null, used to resolve references to the default | ||
2172 | /// module Atom.a("")</param> | ||
2173 | /// <returns></returns> | ||
2174 | public static IEnumerable<bool> getIterator(object Goal, Type declaringClass) | ||
2175 | { | ||
2176 | Atom name; | ||
2177 | object[] args; | ||
2178 | while (true) | ||
2179 | { | ||
2180 | Goal = YP.getValue(Goal); | ||
2181 | if (Goal is Variable) | ||
2182 | throw new PrologException("instantiation_error", "Goal to call is an unbound variable"); | ||
2183 | name = YP.getFunctorName(Goal) as Atom; | ||
2184 | if (name == null) | ||
2185 | throw new PrologException | ||
2186 | (new Functor2("type_error", Atom.a("callable"), Goal), "Goal to call is not callable"); | ||
2187 | args = YP.getFunctorArgs(Goal); | ||
2188 | if (name == Atom.HAT && args.Length == 2) | ||
2189 | // Assume this is called from a bagof operation. Skip the leading qualifiers. | ||
2190 | Goal = YP.getValue(((Functor2)Goal)._arg2); | ||
2191 | else | ||
2192 | break; | ||
2193 | } | ||
2194 | |||
2195 | IEnumerable<bool> simpleIterator = YPCompiler.getSimpleIterator(name, args, declaringClass); | ||
2196 | if (simpleIterator != null) | ||
2197 | // We don't need to compile since the goal is a simple predicate which we call directly. | ||
2198 | return simpleIterator; | ||
2199 | |||
2200 | // Compile the goal as a clause. | ||
2201 | List<Variable> variableSetList = new List<Variable>(); | ||
2202 | addUniqueVariables(Goal, variableSetList); | ||
2203 | Variable[] variableSet = variableSetList.ToArray(); | ||
2204 | |||
2205 | // Use Atom.F since it is ignored. | ||
2206 | return YPCompiler.compileAnonymousClause | ||
2207 | (Functor.make(Atom.F, variableSet), Goal, declaringClass).match(variableSet); | ||
2208 | } | ||
2209 | |||
2210 | public static void throwException(object Term) | ||
2211 | { | ||
2212 | throw new PrologException(Term); | ||
2213 | } | ||
2214 | /// <summary> | ||
2215 | /// This must be called by any function that uses YP._prologFlags to make sure | ||
2216 | /// the initial defaults are loaded. | ||
2217 | /// </summary> | ||
2218 | private static void establishPrologFlags() | ||
2219 | { | ||
2220 | if (_prologFlags.Count > 0) | ||
2221 | // Already established. | ||
2222 | return; | ||
2223 | |||
2224 | // List these in the order they appear in the ISO standard. | ||
2225 | _prologFlags["bounded"] = Atom.a("true"); | ||
2226 | _prologFlags["max_integer"] = Int32.MaxValue; | ||
2227 | _prologFlags["min_integer"] = Int32.MinValue; | ||
2228 | _prologFlags["integer_rounding_function"] = Atom.a("toward_zero"); | ||
2229 | _prologFlags["char_conversion"] = Atom.a("off"); | ||
2230 | _prologFlags["debug"] = Atom.a("off"); | ||
2231 | _prologFlags["max_arity"] = MAX_ARITY; | ||
2232 | _prologFlags["unknown"] = Atom.a("error"); | ||
2233 | _prologFlags["double_quotes"] = Atom.a("codes"); | ||
2234 | } | ||
2235 | |||
2236 | public static IEnumerable<bool> current_prolog_flag(object Key, object Value) | ||
2237 | { | ||
2238 | establishPrologFlags(); | ||
2239 | |||
2240 | Key = YP.getValue(Key); | ||
2241 | Value = YP.getValue(Value); | ||
2242 | |||
2243 | if (Key is Variable) | ||
2244 | { | ||
2245 | // Bind all key values. | ||
2246 | foreach (string key in _prologFlags.Keys) | ||
2247 | { | ||
2248 | foreach (bool l1 in YP.unify(Key, Atom.a(key))) | ||
2249 | { | ||
2250 | foreach (bool l2 in YP.unify(Value, _prologFlags[key])) | ||
2251 | yield return false; | ||
2252 | } | ||
2253 | } | ||
2254 | } | ||
2255 | else | ||
2256 | { | ||
2257 | if (!(Key is Atom)) | ||
2258 | throw new PrologException | ||
2259 | (new Functor2("type_error", Atom.a("atom"), Key), "Arg 1 Key is not an atom"); | ||
2260 | if (!_prologFlags.ContainsKey(((Atom)Key)._name)) | ||
2261 | throw new PrologException | ||
2262 | (new Functor2("domain_error", Atom.a("prolog_flag"), Key), | ||
2263 | "Arg 1 Key is not a recognized flag"); | ||
2264 | |||
2265 | foreach (bool l1 in YP.unify(Value, _prologFlags[((Atom)Key)._name])) | ||
2266 | yield return false; | ||
2267 | } | ||
2268 | } | ||
2269 | |||
2270 | public static void set_prolog_flag(object Key, object Value) | ||
2271 | { | ||
2272 | establishPrologFlags(); | ||
2273 | |||
2274 | Key = YP.getValue(Key); | ||
2275 | Value = YP.getValue(Value); | ||
2276 | |||
2277 | if (Key is Variable) | ||
2278 | throw new PrologException(Atom.a("instantiation_error"), | ||
2279 | "Arg 1 Key is an unbound variable"); | ||
2280 | if (Value is Variable) | ||
2281 | throw new PrologException(Atom.a("instantiation_error"), | ||
2282 | "Arg 1 Key is an unbound variable"); | ||
2283 | if (!(Key is Atom)) | ||
2284 | throw new PrologException | ||
2285 | (new Functor2("type_error", Atom.a("atom"), Key), "Arg 1 Key is not an atom"); | ||
2286 | |||
2287 | string keyName = ((Atom)Key)._name; | ||
2288 | if (!_prologFlags.ContainsKey(keyName)) | ||
2289 | throw new PrologException | ||
2290 | (new Functor2("domain_error", Atom.a("prolog_flag"), Key), | ||
2291 | "Arg 1 Key " + Key + " is not a recognized flag"); | ||
2292 | |||
2293 | bool valueIsOK = false; | ||
2294 | if (keyName == "char_conversion") | ||
2295 | valueIsOK = (Value == _prologFlags[keyName]); | ||
2296 | else if (keyName == "debug") | ||
2297 | valueIsOK = (Value == _prologFlags[keyName]); | ||
2298 | else if (keyName == "unknown") | ||
2299 | valueIsOK = (Value == Atom.a("fail") || Value == Atom.a("warning") || | ||
2300 | Value == Atom.a("error")); | ||
2301 | else if (keyName == "double_quotes") | ||
2302 | valueIsOK = (Value == Atom.a("codes") || Value == Atom.a("chars") || | ||
2303 | Value == Atom.a("atom")); | ||
2304 | else | ||
2305 | throw new PrologException | ||
2306 | (new Functor3("permission_error", Atom.a("modify"), Atom.a("flag"), Key), | ||
2307 | "May not modify Prolog flag " + Key); | ||
2308 | |||
2309 | if (!valueIsOK) | ||
2310 | throw new PrologException | ||
2311 | (new Functor2("domain_error", Atom.a("flag_value"), new Functor2("+", Key, Value)), | ||
2312 | "May not set arg 1 Key " + Key + " to arg 2 Value " + Value); | ||
2313 | |||
2314 | _prologFlags[keyName] = Value; | ||
2315 | } | ||
2316 | /// <summary> | ||
2317 | /// script_event calls hosting script with events as a callback method. | ||
2318 | /// </summary> | ||
2319 | /// <param name="script_event"></param> | ||
2320 | /// <param name="script_params"></param> | ||
2321 | /// <returns></returns> | ||
2322 | public static IEnumerable<bool> script_event(object script_event, object script_params) | ||
2323 | { | ||
2324 | // string function = ((Atom)YP.getValue(script_event))._name; | ||
2325 | object[] array = ListPair.toArray(script_params); | ||
2326 | if (array == null) | ||
2327 | yield return false; // return; // YP.fail(); | ||
2328 | if (array.Length > 1) | ||
2329 | { | ||
2330 | //m_CmdManager.m_ScriptEngine.m_EventQueManager.AddToScriptQueue | ||
2331 | //(localID, itemID, function, array); | ||
2332 | // sortArray(array); | ||
2333 | } | ||
2334 | //return YP.unify(Sorted, ListPair.makeWithoutRepeatedTerms(array)); | ||
2335 | yield return false; | ||
2336 | } | ||
2337 | |||
2338 | /* Non-prolog-ish functions for inline coding */ | ||
2339 | public static string regexString(string inData, string inPattern, string presep,string postsep) | ||
2340 | { | ||
2341 | //string str=cycMessage; | ||
2342 | //string strMatch = @"\. \#\$(.*)\)"; | ||
2343 | string results = ""; | ||
2344 | for (Match m = Regex.Match(inData,inPattern); m.Success; m=m.NextMatch()) | ||
2345 | { | ||
2346 | //m_log.Debug(m); | ||
2347 | results += presep+ m + postsep; | ||
2348 | } | ||
2349 | return results; | ||
2350 | } | ||
2351 | |||
2352 | public static string cycComm(object msgobj) | ||
2353 | { | ||
2354 | string cycInputString = msgobj.ToString(); | ||
2355 | string cycOutputString=""; | ||
2356 | TcpClient socketForServer; | ||
2357 | |||
2358 | try | ||
2359 | { | ||
2360 | socketForServer = new TcpClient("localHost", 3601); | ||
2361 | } | ||
2362 | catch | ||
2363 | { | ||
2364 | m_log.Error("Failed to connect to server at localhost:999"); | ||
2365 | return ""; | ||
2366 | } | ||
2367 | |||
2368 | NetworkStream networkStream = socketForServer.GetStream(); | ||
2369 | |||
2370 | System.IO.StreamReader streamReader = new System.IO.StreamReader(networkStream); | ||
2371 | |||
2372 | System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(networkStream); | ||
2373 | |||
2374 | try | ||
2375 | { | ||
2376 | // read the data from the host and display it | ||
2377 | |||
2378 | { | ||
2379 | |||
2380 | streamWriter.WriteLine(cycInputString); | ||
2381 | streamWriter.Flush(); | ||
2382 | |||
2383 | cycOutputString = streamReader.ReadLine(); | ||
2384 | m_log.Debug("Cycoutput:" + cycOutputString); | ||
2385 | //streamWriter.WriteLine("Client Message"); | ||
2386 | //m_log.Debug("Client Message"); | ||
2387 | streamWriter.Flush(); | ||
2388 | } | ||
2389 | |||
2390 | } | ||
2391 | catch | ||
2392 | { | ||
2393 | m_log.Error("Exception reading from Server"); | ||
2394 | return ""; | ||
2395 | } | ||
2396 | // tidy up | ||
2397 | networkStream.Close(); | ||
2398 | return cycOutputString; | ||
2399 | |||
2400 | } | ||
2401 | //public static void throwException(object Term) | ||
2402 | //{ | ||
2403 | // throw new PrologException(Term); | ||
2404 | //} | ||
2405 | /// <summary> | ||
2406 | /// An enumerator that does zero loops. | ||
2407 | /// </summary> | ||
2408 | private class Fail : IEnumerator<bool>, IEnumerable<bool> | ||
2409 | { | ||
2410 | public bool MoveNext() | ||
2411 | { | ||
2412 | return false; | ||
2413 | } | ||
2414 | |||
2415 | public IEnumerator<bool> GetEnumerator() | ||
2416 | { | ||
2417 | return (IEnumerator<bool>)this; | ||
2418 | } | ||
2419 | |||
2420 | IEnumerator IEnumerable.GetEnumerator() | ||
2421 | { | ||
2422 | return GetEnumerator(); | ||
2423 | } | ||
2424 | |||
2425 | public bool Current | ||
2426 | { | ||
2427 | get { return true; } | ||
2428 | } | ||
2429 | |||
2430 | object IEnumerator.Current | ||
2431 | { | ||
2432 | get { return true; } | ||
2433 | } | ||
2434 | |||
2435 | public void Dispose() | ||
2436 | { | ||
2437 | } | ||
2438 | |||
2439 | public void Reset() | ||
2440 | { | ||
2441 | throw new NotImplementedException(); | ||
2442 | } | ||
2443 | } | ||
2444 | |||
2445 | /// <summary> | ||
2446 | /// An enumerator that does one iteration. | ||
2447 | /// </summary> | ||
2448 | private class Succeed : IEnumerator<bool>, IEnumerable<bool> | ||
2449 | { | ||
2450 | private bool _didIteration = false; | ||
2451 | |||
2452 | public bool MoveNext() | ||
2453 | { | ||
2454 | if (!_didIteration) | ||
2455 | { | ||
2456 | _didIteration = true; | ||
2457 | return true; | ||
2458 | } | ||
2459 | else | ||
2460 | return false; | ||
2461 | } | ||
2462 | |||
2463 | public IEnumerator<bool> GetEnumerator() | ||
2464 | { | ||
2465 | return (IEnumerator<bool>)this; | ||
2466 | } | ||
2467 | |||
2468 | IEnumerator IEnumerable.GetEnumerator() | ||
2469 | { | ||
2470 | return GetEnumerator(); | ||
2471 | } | ||
2472 | |||
2473 | public bool Current | ||
2474 | { | ||
2475 | get { return false; } | ||
2476 | } | ||
2477 | |||
2478 | object IEnumerator.Current | ||
2479 | { | ||
2480 | get { return false; } | ||
2481 | } | ||
2482 | |||
2483 | public void Dispose() | ||
2484 | { | ||
2485 | } | ||
2486 | |||
2487 | public void Reset() | ||
2488 | { | ||
2489 | throw new NotImplementedException(); | ||
2490 | } | ||
2491 | } | ||
2492 | |||
2493 | /// <summary> | ||
2494 | /// An enumerator that repeats forever. | ||
2495 | /// </summary> | ||
2496 | private class Repeat : IEnumerator<bool>, IEnumerable<bool> | ||
2497 | { | ||
2498 | public bool MoveNext() | ||
2499 | { | ||
2500 | return true; | ||
2501 | } | ||
2502 | |||
2503 | public IEnumerator<bool> GetEnumerator() | ||
2504 | { | ||
2505 | return (IEnumerator<bool>)this; | ||
2506 | } | ||
2507 | |||
2508 | IEnumerator IEnumerable.GetEnumerator() | ||
2509 | { | ||
2510 | return GetEnumerator(); | ||
2511 | } | ||
2512 | |||
2513 | public bool Current | ||
2514 | { | ||
2515 | get { return false; } | ||
2516 | } | ||
2517 | |||
2518 | object IEnumerator.Current | ||
2519 | { | ||
2520 | get { return false; } | ||
2521 | } | ||
2522 | |||
2523 | public void Dispose() | ||
2524 | { | ||
2525 | } | ||
2526 | |||
2527 | public void Reset() | ||
2528 | { | ||
2529 | throw new NotImplementedException(); | ||
2530 | } | ||
2531 | } | ||
2532 | |||
2533 | /// <summary> | ||
2534 | /// An enumerator that wraps another enumerator in order to catch a PrologException. | ||
2535 | /// </summary> | ||
2536 | public class Catch : IEnumerator<bool>, IEnumerable<bool> | ||
2537 | { | ||
2538 | private IEnumerator<bool> _enumerator; | ||
2539 | private PrologException _exception = null; | ||
2540 | |||
2541 | /// <summary> | ||
2542 | /// Call YP.getIterator(Goal, declaringClass) and save the returned iterator. | ||
2543 | /// If getIterator throws an exception, save it the same as MoveNext(). | ||
2544 | /// </summary> | ||
2545 | /// <param name="Goal"></param> | ||
2546 | /// <param name="declaringClass"></param> | ||
2547 | public Catch(object Goal, Type declaringClass) | ||
2548 | { | ||
2549 | try | ||
2550 | { | ||
2551 | _enumerator = getIterator(Goal, declaringClass).GetEnumerator(); | ||
2552 | } | ||
2553 | catch (PrologException exception) | ||
2554 | { | ||
2555 | // MoveNext() will check this. | ||
2556 | _exception = exception; | ||
2557 | } | ||
2558 | } | ||
2559 | |||
2560 | /// <summary> | ||
2561 | /// Call _enumerator.MoveNext(). If it throws a PrologException, set _exception | ||
2562 | /// and return false. After this returns false, call unifyExceptionOrThrow. | ||
2563 | /// </summary> | ||
2564 | /// <returns></returns> | ||
2565 | public bool MoveNext() | ||
2566 | { | ||
2567 | if (_exception != null) | ||
2568 | return false; | ||
2569 | |||
2570 | try | ||
2571 | { | ||
2572 | return _enumerator.MoveNext(); | ||
2573 | } | ||
2574 | catch (PrologException exception) | ||
2575 | { | ||
2576 | _exception = exception; | ||
2577 | return false; | ||
2578 | } | ||
2579 | } | ||
2580 | |||
2581 | /// <summary> | ||
2582 | /// Call this after MoveNext() returns false to check for an exception. If | ||
2583 | /// MoveNext did not get a PrologException, don't yield. | ||
2584 | /// Otherwise, unify the exception with Catcher and yield so the caller can | ||
2585 | /// do the handler code. However, if can't unify with Catcher then throw the exception. | ||
2586 | /// </summary> | ||
2587 | /// <param name="Catcher"></param> | ||
2588 | /// <returns></returns> | ||
2589 | public IEnumerable<bool> unifyExceptionOrThrow(object Catcher) | ||
2590 | { | ||
2591 | if (_exception != null) | ||
2592 | { | ||
2593 | bool didUnify = false; | ||
2594 | foreach (bool l1 in YP.unify(_exception._term, Catcher)) | ||
2595 | { | ||
2596 | didUnify = true; | ||
2597 | yield return false; | ||
2598 | } | ||
2599 | if (!didUnify) | ||
2600 | throw _exception; | ||
2601 | } | ||
2602 | } | ||
2603 | |||
2604 | public IEnumerator<bool> GetEnumerator() | ||
2605 | { | ||
2606 | return (IEnumerator<bool>)this; | ||
2607 | } | ||
2608 | |||
2609 | IEnumerator IEnumerable.GetEnumerator() | ||
2610 | { | ||
2611 | return GetEnumerator(); | ||
2612 | } | ||
2613 | |||
2614 | public bool Current | ||
2615 | { | ||
2616 | get { return _enumerator.Current; } | ||
2617 | } | ||
2618 | |||
2619 | object IEnumerator.Current | ||
2620 | { | ||
2621 | get { return _enumerator.Current; } | ||
2622 | } | ||
2623 | |||
2624 | public void Dispose() | ||
2625 | { | ||
2626 | if (_enumerator != null) | ||
2627 | _enumerator.Dispose(); | ||
2628 | } | ||
2629 | |||
2630 | public void Reset() | ||
2631 | { | ||
2632 | throw new NotImplementedException(); | ||
2633 | } | ||
2634 | } | ||
2635 | #pragma warning restore 0168, 0219 | ||
2636 | /// <summary> | ||
2637 | /// A ClauseHeadAndBody is used in Compiler.compileAnonymousFunction as a base class | ||
2638 | /// in order to implement YP.IClause. After creating the object, you must call setHeadAndBody. | ||
2639 | /// </summary> | ||
2640 | public class ClauseHeadAndBody | ||
2641 | { | ||
2642 | private object _Head; | ||
2643 | private object _Body; | ||
2644 | |||
2645 | public void setHeadAndBody(object Head, object Body) | ||
2646 | { | ||
2647 | _Head = Head; | ||
2648 | _Body = Body; | ||
2649 | } | ||
2650 | |||
2651 | public IEnumerable<bool> clause(object Head, object Body) | ||
2652 | { | ||
2653 | if (_Head == null || _Body == null) | ||
2654 | yield break; | ||
2655 | |||
2656 | #pragma warning disable 0168, 0219 | ||
2657 | foreach (bool l1 in YP.unify(Head, _Head)) | ||
2658 | { | ||
2659 | foreach (bool l2 in YP.unify(Body, _Body)) | ||
2660 | yield return false; | ||
2661 | } | ||
2662 | #pragma warning restore 0168, 0219 | ||
2663 | } | ||
2664 | } | ||
2665 | |||
2666 | /// <summary> | ||
2667 | /// CodeListReader extends TextReader and overrides Read to read the next code from | ||
2668 | /// the CodeList which is a Prolog list of integer character codes. | ||
2669 | /// </summary> | ||
2670 | public class CodeListReader : TextReader | ||
2671 | { | ||
2672 | private object _CodeList; | ||
2673 | |||
2674 | public CodeListReader(object CodeList) | ||
2675 | { | ||
2676 | _CodeList = YP.getValue(CodeList); | ||
2677 | } | ||
2678 | |||
2679 | /// <summary> | ||
2680 | /// If the head of _CodeList is an integer, return it and advance the list. Otherwise, | ||
2681 | /// return -1 for end of file. | ||
2682 | /// </summary> | ||
2683 | /// <returns></returns> | ||
2684 | public override int Read() | ||
2685 | { | ||
2686 | Functor2 CodeListPair = _CodeList as Functor2; | ||
2687 | int code; | ||
2688 | if (!(CodeListPair != null && CodeListPair._name == Atom.DOT && | ||
2689 | getInt(CodeListPair._arg1, out code))) | ||
2690 | { | ||
2691 | _CodeList = Atom.NIL; | ||
2692 | return -1; | ||
2693 | } | ||
2694 | |||
2695 | // Advance. | ||
2696 | _CodeList = YP.getValue(CodeListPair._arg2); | ||
2697 | return code; | ||
2698 | } | ||
2699 | } | ||
2700 | } | ||
2701 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YPCompiler.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YPCompiler.cs deleted file mode 100644 index c6a6748..0000000 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YPCompiler.cs +++ /dev/null | |||
@@ -1,6382 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008, Jeff Thompson | ||
3 | * | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the copyright holder nor the names of its contributors | ||
15 | * may be used to endorse or promote products derived from this software | ||
16 | * without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | using System; | ||
32 | using System.IO; | ||
33 | using System.Collections; | ||
34 | using System.Collections.Generic; | ||
35 | using System.Text; | ||
36 | using System.CodeDom.Compiler; | ||
37 | using System.Reflection; | ||
38 | |||
39 | namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | ||
40 | { | ||
41 | public class YPCompiler | ||
42 | { | ||
43 | private class CompilerState | ||
44 | { | ||
45 | public IndexedAnswers _pred = new IndexedAnswers(4); | ||
46 | public Dictionary<YP.NameArity, Atom> _moduleForNameArity = new Dictionary<YP.NameArity, Atom>(); | ||
47 | public int _gensymCounter; | ||
48 | public bool _useFinalCutCode; | ||
49 | public Variable _finalCutCode; | ||
50 | public bool _codeUsesYield; | ||
51 | public Atom _determinism; | ||
52 | // a list of '='(Name, Variable) | ||
53 | public List<object> _variableNames; | ||
54 | |||
55 | // Make these static functions that explicitly take the State so Prolog can call it. | ||
56 | |||
57 | /// <summary> | ||
58 | /// Make a new CompilerState and bind it to State. | ||
59 | /// </summary> | ||
60 | /// <param name="State"></param> | ||
61 | /// <returns></returns> | ||
62 | public static IEnumerable<bool> make(object State) | ||
63 | { | ||
64 | return YP.unify(State, new CompilerState()); | ||
65 | } | ||
66 | |||
67 | public static void assertPred(object State, object Pred, object Determinism) | ||
68 | { | ||
69 | State = YP.getValue(State); | ||
70 | object functorName = YP.getFunctorName(Pred); | ||
71 | object[] functorArgs = YP.getFunctorArgs(Pred); | ||
72 | // Debug: Should check if it's already asserted and is the same. | ||
73 | ((CompilerState)State)._pred.addAnswer | ||
74 | (new object[] { functorName, functorArgs.Length, Pred, YP.getValue(Determinism) }); | ||
75 | } | ||
76 | |||
77 | public static void assertModuleForNameArity(object State, object Name, object Arity, object Module) | ||
78 | { | ||
79 | State = YP.getValue(State); | ||
80 | Name = YP.getValue(Name); | ||
81 | Arity = YP.getValue(Arity); | ||
82 | Module = YP.getValue(Module); | ||
83 | // If the Module Atom comes from the parser, it always has null _declaringClass. | ||
84 | if (Module is Atom && ((Atom)Module)._module == null && Name is Atom && Arity is int) | ||
85 | // Replace a previous entry if it exists. | ||
86 | ((CompilerState)State)._moduleForNameArity[new YP.NameArity((Atom)Name, (int)Arity)] = | ||
87 | (Atom)Module; | ||
88 | } | ||
89 | |||
90 | public static void startFunction(object State, object Head) | ||
91 | { | ||
92 | State = YP.getValue(State); | ||
93 | ((CompilerState)State)._gensymCounter = 0; | ||
94 | ((CompilerState)State)._useFinalCutCode = false; | ||
95 | ((CompilerState)State)._finalCutCode = new Variable(); | ||
96 | ((CompilerState)State)._codeUsesYield = false; | ||
97 | if (CompilerState.isDetNoneOut(State, Head)) | ||
98 | ((CompilerState)State)._determinism = Atom.a("detNoneOut"); | ||
99 | else if (CompilerState.isSemidetNoneOut(State, Head)) | ||
100 | ((CompilerState)State)._determinism = Atom.a("semidetNoneOut"); | ||
101 | else | ||
102 | ((CompilerState)State)._determinism = Atom.a("nondet"); | ||
103 | } | ||
104 | |||
105 | public static void setCodeUsesYield(object State) | ||
106 | { | ||
107 | State = YP.getValue(State); | ||
108 | ((CompilerState)State)._codeUsesYield = true; | ||
109 | } | ||
110 | |||
111 | public static bool codeUsesYield(object State) | ||
112 | { | ||
113 | State = YP.getValue(State); | ||
114 | return ((CompilerState)State)._codeUsesYield; | ||
115 | } | ||
116 | |||
117 | public static bool determinismEquals(object State, object Term) | ||
118 | { | ||
119 | State = YP.getValue(State); | ||
120 | return YP.termEqual(((CompilerState)State)._determinism, Term); | ||
121 | } | ||
122 | |||
123 | /// <summary> | ||
124 | /// Set _variableNames to a new list of (Name = Variable) for each unique variable in rule. | ||
125 | /// If the variable is in variableNameSuggestions, use it, otherwise use x1, x2, etc. | ||
126 | /// </summary> | ||
127 | /// <param name="State"></param> | ||
128 | /// <param name="rule"></param> | ||
129 | /// <param name="variableNameSuggestions"></param> | ||
130 | public static void newVariableNames(object State, object Rule, object VariableNameSuggestions) | ||
131 | { | ||
132 | State = YP.getValue(State); | ||
133 | List<Variable> variablesSet = new List<Variable>(); | ||
134 | YP.addUniqueVariables(Rule, variablesSet); | ||
135 | |||
136 | ((CompilerState)State)._variableNames = new List<object>(); | ||
137 | int xCounter = 0; | ||
138 | foreach (Variable variable in variablesSet) | ||
139 | ((CompilerState)State)._variableNames.Add | ||
140 | (new Functor2(Atom.a("="), makeVariableName(variable, VariableNameSuggestions, ++xCounter), | ||
141 | variable)); | ||
142 | } | ||
143 | |||
144 | private static object makeVariableName(object variable, object variableNameSuggestions, int xCounter) | ||
145 | { | ||
146 | // Debug: should require named variables to start with _ or capital. Should | ||
147 | // check for duplicates and clashes with keywords. | ||
148 | for (object element = YP.getValue(variableNameSuggestions); | ||
149 | element is Functor2 && ((Functor2)element)._name == Atom.DOT; | ||
150 | element = YP.getValue(((Functor2)element)._arg2)) | ||
151 | { | ||
152 | object suggestionPair = YP.getValue(((Functor2)element)._arg1); | ||
153 | if (sameVariable(variable, ((Functor2)suggestionPair)._arg2)) | ||
154 | { | ||
155 | Atom suggestion = (Atom)YP.getValue(((Functor2)suggestionPair)._arg1); | ||
156 | if (suggestion.Equals(Atom.a("Atom"))) | ||
157 | suggestion = Atom.a("Atom_1"); | ||
158 | if (suggestion.Equals(Atom.a("Variable"))) | ||
159 | suggestion = Atom.a("Variable_1"); | ||
160 | if (suggestion.Equals(Atom.a("Functor"))) | ||
161 | suggestion = Atom.a("Functor_1"); | ||
162 | return suggestion; | ||
163 | } | ||
164 | } | ||
165 | |||
166 | return Atom.a("x" + xCounter); | ||
167 | } | ||
168 | |||
169 | /// <summary> | ||
170 | /// Unify Result with the name assigned by CompilerState.newVariableNames in State._variableNames | ||
171 | /// for variable. | ||
172 | /// </summary> | ||
173 | /// <param name="variable">a Variable</param> | ||
174 | /// <param name="State"></param> | ||
175 | /// <param name="Result">the assigned Name</param> | ||
176 | public static IEnumerable<bool> getVariableName(object State, object variable, object Result) | ||
177 | { | ||
178 | State = YP.getValue(State); | ||
179 | foreach (object variableInfo in ((CompilerState)State)._variableNames) | ||
180 | { | ||
181 | if (variableInfo is Functor2 && ((Functor2)variableInfo)._name.Equals(Atom.a("="))) | ||
182 | { | ||
183 | if (sameVariable(variable, ((Functor2)variableInfo)._arg2)) | ||
184 | return YP.unify(Result, ((Functor2)variableInfo)._arg1); | ||
185 | } | ||
186 | } | ||
187 | |||
188 | // We set up names for all unique variables, so this should never happen. | ||
189 | throw new PrologException(Atom.a("Can't find entry in _variableNames")); | ||
190 | } | ||
191 | |||
192 | public static IEnumerable<bool> variableNamesList(object State, object VariableNamesList) | ||
193 | { | ||
194 | State = YP.getValue(State); | ||
195 | return YP.unify(VariableNamesList, ListPair.make(((CompilerState)State)._variableNames)); | ||
196 | } | ||
197 | |||
198 | public static IEnumerable<bool> gensym(object State, object Base, object Symbol) | ||
199 | { | ||
200 | State = YP.getValue(State); | ||
201 | return YP.unify(Symbol, Atom.a(Base.ToString() + ++((CompilerState)State)._gensymCounter)); | ||
202 | } | ||
203 | |||
204 | // disable warning on l1, don't see how we can | ||
205 | // code this differently | ||
206 | #pragma warning disable 0168, 0164, 0162, 0219 | ||
207 | public static bool isDetNoneOut(object State, object Term) | ||
208 | { | ||
209 | State = YP.getValue(State); | ||
210 | object functorName = YP.getFunctorName(Term); | ||
211 | object[] functorArgs = YP.getFunctorArgs(Term); | ||
212 | |||
213 | Variable pred = new Variable(); | ||
214 | foreach (bool l1 in ((CompilerState)State)._pred.match | ||
215 | (new object[] { functorName, functorArgs.Length, pred, Atom.a("det") })) | ||
216 | { | ||
217 | if (CompilerState.isNoneOut(YP.getFunctorArgs(pred.getValue()))) | ||
218 | { | ||
219 | return true; | ||
220 | } | ||
221 | } | ||
222 | |||
223 | return false; | ||
224 | } | ||
225 | |||
226 | public static bool isSemidetNoneOut(object State, object Term) | ||
227 | { | ||
228 | State = YP.getValue(State); | ||
229 | object functorName = YP.getFunctorName(Term); | ||
230 | object[] functorArgs = YP.getFunctorArgs(Term); | ||
231 | |||
232 | Variable pred = new Variable(); | ||
233 | foreach (bool l1 in ((CompilerState)State)._pred.match | ||
234 | (new object[] { functorName, functorArgs.Length, pred, Atom.a("semidet") })) | ||
235 | { | ||
236 | if (CompilerState.isNoneOut(YP.getFunctorArgs(pred.getValue()))) | ||
237 | { | ||
238 | return true; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | return false; | ||
243 | } | ||
244 | #pragma warning restore 0168, 0164, 0162, 0219 | ||
245 | |||
246 | /// <summary> | ||
247 | /// Return false if any of args is out, otherwise true. | ||
248 | /// args is an array of ::(Type,Mode) where Mode is in or out. | ||
249 | /// </summary> | ||
250 | /// <param name="args"></param> | ||
251 | /// <returns></returns> | ||
252 | private static bool isNoneOut(object[] args) | ||
253 | { | ||
254 | foreach (object arg in args) | ||
255 | { | ||
256 | if (arg is Functor2 && ((Functor2)arg)._name == Atom.a("::") && | ||
257 | ((Functor2)arg)._arg2 == Atom.a("out")) | ||
258 | return false; | ||
259 | } | ||
260 | return true; | ||
261 | } | ||
262 | |||
263 | public static bool nameArityHasModule(object State, object Name, object Arity, object Module) | ||
264 | { | ||
265 | State = YP.getValue(State); | ||
266 | Name = YP.getValue(Name); | ||
267 | Arity = YP.getValue(Arity); | ||
268 | Module = YP.getValue(Module); | ||
269 | if (Name is Atom && Arity is int) | ||
270 | { | ||
271 | Atom FoundModule; | ||
272 | if (!((CompilerState)State)._moduleForNameArity.TryGetValue | ||
273 | (new YP.NameArity((Atom)Name, (int)Arity), out FoundModule)) | ||
274 | return false; | ||
275 | return FoundModule == Module; | ||
276 | } | ||
277 | return false; | ||
278 | } | ||
279 | } | ||
280 | |||
281 | // disable warning on l1, don't see how we can | ||
282 | // code this differently | ||
283 | #pragma warning disable 0168, 0219,0164,0162 | ||
284 | |||
285 | /// <summary> | ||
286 | /// Use makeFunctionPseudoCode, convertFunctionCSharp and compileAnonymousFunction | ||
287 | /// to return an anonymous YP.IClause for the Head and Body of a rule clause. | ||
288 | /// </summary> | ||
289 | /// <param name="Head">a prolog term such as new Functor2("test1", X, Y). | ||
290 | /// Note that the name of the head is ignored. | ||
291 | /// </param> | ||
292 | /// <param name="Body">a prolog term such as | ||
293 | /// new Functor2(",", new Functor1(Atom.a("test2", Atom.a("")), X), | ||
294 | /// new Functor2("=", Y, X)). | ||
295 | /// This may not be null. (For a head-only clause, set the Body to Atom.a("true"). | ||
296 | /// </param> | ||
297 | /// <param name="declaringClass">if not null, the code is compiled as a subclass of this class | ||
298 | /// to resolve references to the default module Atom.a("")</param> | ||
299 | /// <returns>a new YP.IClause object on which you can call match(object[] args) where | ||
300 | /// args length is the arity of the Head</returns> | ||
301 | public static YP.IClause compileAnonymousClause(object Head, object Body, Type declaringClass) | ||
302 | { | ||
303 | object[] args = YP.getFunctorArgs(Head); | ||
304 | // compileAnonymousFunction wants "function". | ||
305 | object Rule = new Functor2(Atom.RULE, Functor.make("function", args), Body); | ||
306 | object RuleList = ListPair.make(new Functor2(Atom.F, Rule, Atom.NIL)); | ||
307 | |||
308 | StringWriter functionCode = new StringWriter(); | ||
309 | Variable SaveOutputStream = new Variable(); | ||
310 | foreach (bool l1 in YP.current_output(SaveOutputStream)) | ||
311 | { | ||
312 | try | ||
313 | { | ||
314 | YP.tell(functionCode); | ||
315 | Variable PseudoCode = new Variable(); | ||
316 | foreach (bool l2 in makeFunctionPseudoCode(RuleList, PseudoCode)) | ||
317 | { | ||
318 | if (YP.termEqual(PseudoCode, Atom.a("getDeclaringClass"))) | ||
319 | // Ignore getDeclaringClass since we have access to the one passed in. | ||
320 | continue; | ||
321 | |||
322 | convertFunctionCSharp(PseudoCode); | ||
323 | } | ||
324 | YP.told(); | ||
325 | } | ||
326 | finally | ||
327 | { | ||
328 | // Restore after calling tell. | ||
329 | YP.tell(SaveOutputStream.getValue()); | ||
330 | } | ||
331 | } | ||
332 | return YPCompiler.compileAnonymousFunction | ||
333 | (functionCode.ToString(), args.Length, declaringClass); | ||
334 | } | ||
335 | |||
336 | /// <summary> | ||
337 | /// Use CodeDomProvider to compile the functionCode and return a YP.ClauseHeadAndBody | ||
338 | /// which implements YP.IClause. | ||
339 | /// The function name must be "function" and have nArgs arguments. | ||
340 | /// </summary> | ||
341 | /// <param name="functionCode">the code for the iterator, such as | ||
342 | /// "public static IEnumerable<bool> function() { yield return false; }" | ||
343 | /// </param> | ||
344 | /// <param name="nArgs">the number of args in the function</param> | ||
345 | /// <param name="declaringClass">if not null, then use the functionCode inside a class which | ||
346 | /// inherits from contextClass, so that references in functionCode to methods in declaringClass don't | ||
347 | /// have to be qualified</param> | ||
348 | /// <returns>a new YP.IClause object on which you can call match(object[] args) where | ||
349 | /// args length is nArgs</returns> | ||
350 | public static YP.IClause compileAnonymousFunction(string functionCode, int nArgs, Type declaringClass) | ||
351 | { | ||
352 | CompilerParameters parameters = new CompilerParameters(); | ||
353 | // This gets the location of the System assembly. | ||
354 | parameters.ReferencedAssemblies.Add(typeof(System.Int32).Assembly.Location); | ||
355 | // This gets the location of this assembly which also has YieldProlog.YP, etc. | ||
356 | parameters.ReferencedAssemblies.Add(typeof(YPCompiler).Assembly.Location); | ||
357 | if (declaringClass != null) | ||
358 | parameters.ReferencedAssemblies.Add(declaringClass.Assembly.Location); | ||
359 | parameters.GenerateInMemory = true; | ||
360 | |||
361 | StringBuilder sourceCode = new StringBuilder(); | ||
362 | sourceCode.Append(@" | ||
363 | using System; | ||
364 | using System.Collections.Generic; | ||
365 | using OpenSim.Region.ScriptEngine.Shared.YieldProlog; | ||
366 | |||
367 | namespace Temporary { | ||
368 | public class Temporary : YP.ClauseHeadAndBody, YP.IClause {"); | ||
369 | if (declaringClass == null) | ||
370 | // We don't extend a class with getDeclaringClass, so define it. | ||
371 | sourceCode.Append(@" | ||
372 | public class Inner { | ||
373 | public static System.Type getDeclaringClass() { return null; } | ||
374 | "); | ||
375 | else | ||
376 | sourceCode.Append(@" | ||
377 | public class Inner : " + declaringClass.FullName + @" { | ||
378 | "); | ||
379 | sourceCode.Append(functionCode); | ||
380 | // Basically, match applies the args to function. | ||
381 | sourceCode.Append(@" | ||
382 | } | ||
383 | public IEnumerable<bool> match(object[] args) { | ||
384 | return Inner.function("); | ||
385 | if (nArgs >= 1) | ||
386 | sourceCode.Append("args[0]"); | ||
387 | for (int i = 1; i < nArgs; ++i) | ||
388 | sourceCode.Append(", args[" + i + "]"); | ||
389 | sourceCode.Append(@"); | ||
390 | } | ||
391 | } | ||
392 | } | ||
393 | "); | ||
394 | |||
395 | CompilerResults results = CodeDomProvider.CreateProvider | ||
396 | ("CSharp").CompileAssemblyFromSource(parameters, sourceCode.ToString()); | ||
397 | if (results.Errors.Count > 0) | ||
398 | throw new Exception("Error evaluating code: " + results.Errors[0]); | ||
399 | |||
400 | // Return a new Temporary.Temporary object. | ||
401 | return (YP.IClause)results.CompiledAssembly.GetType | ||
402 | ("Temporary.Temporary").GetConstructor(Type.EmptyTypes).Invoke(null); | ||
403 | } | ||
404 | |||
405 | /// <summary> | ||
406 | /// If the functor with name and args can be called directly as determined by | ||
407 | /// functorCallFunctionName, then call it and return its iterator. If the predicate is | ||
408 | /// dynamic and undefined, or if static and the method cannot be found, return | ||
409 | /// the result of YP.unknownPredicate. | ||
410 | /// This returns null if the functor has a special form than needs to be compiled | ||
411 | /// (including ,/2 and ;/2). | ||
412 | /// </summary> | ||
413 | /// <param name="name"></param> | ||
414 | /// <param name="args"></param> | ||
415 | /// <param name="declaringClass">used to resolve references to the default | ||
416 | /// module Atom.a(""). If a declaringClass is needed to resolve the reference but it is | ||
417 | /// null, this throws a PrologException for existence_error</param> | ||
418 | /// <returns></returns> | ||
419 | public static IEnumerable<bool> getSimpleIterator(Atom name, object[] args, Type declaringClass) | ||
420 | { | ||
421 | CompilerState state = new CompilerState(); | ||
422 | Variable FunctionName = new Variable(); | ||
423 | foreach (bool l1 in functorCallFunctionName(state, name, args.Length, FunctionName)) | ||
424 | { | ||
425 | Atom functionNameAtom = ((Atom)FunctionName.getValue()); | ||
426 | if (functionNameAtom == Atom.NIL) | ||
427 | // name is for a dynamic predicate. | ||
428 | return YP.matchDynamic(name, args); | ||
429 | |||
430 | string methodName = functionNameAtom._name; | ||
431 | // Set the default for the method to call. | ||
432 | Type methodClass = declaringClass; | ||
433 | |||
434 | bool checkMode = false; | ||
435 | if (methodName.StartsWith("YP.")) | ||
436 | { | ||
437 | // Assume we only check mode in calls to standard Prolog predicates in YP. | ||
438 | checkMode = true; | ||
439 | |||
440 | // Use the method in class YP. | ||
441 | methodName = methodName.Substring(3); | ||
442 | methodClass = typeof(YP); | ||
443 | } | ||
444 | if (methodName.Contains(".")) | ||
445 | // We don't support calling inner classes, etc. | ||
446 | return null; | ||
447 | |||
448 | if (methodClass == null) | ||
449 | return YP.unknownPredicate | ||
450 | (name, args.Length, | ||
451 | "Cannot find predicate function for: " + name + "/" + args.Length + | ||
452 | " because declaringClass is null. Set declaringClass to the class containing " + | ||
453 | methodName); | ||
454 | try | ||
455 | { | ||
456 | if (checkMode) | ||
457 | { | ||
458 | assertYPPred(state); | ||
459 | object functor = Functor.make(name, args); | ||
460 | if (CompilerState.isDetNoneOut(state, functor)) | ||
461 | { | ||
462 | methodClass.InvokeMember | ||
463 | (methodName, BindingFlags.InvokeMethod, null, null, args); | ||
464 | return YP.succeed(); | ||
465 | } | ||
466 | if (CompilerState.isSemidetNoneOut(state, functor)) | ||
467 | { | ||
468 | if ((bool)methodClass.InvokeMember | ||
469 | (methodName, BindingFlags.InvokeMethod, null, null, args)) | ||
470 | return YP.succeed(); | ||
471 | else | ||
472 | return YP.fail(); | ||
473 | } | ||
474 | |||
475 | } | ||
476 | return (IEnumerable<bool>)methodClass.InvokeMember | ||
477 | (methodName, BindingFlags.InvokeMethod, null, null, args); | ||
478 | } | ||
479 | catch (TargetInvocationException exception) | ||
480 | { | ||
481 | throw exception.InnerException; | ||
482 | } | ||
483 | catch (MissingMethodException) | ||
484 | { | ||
485 | return YP.unknownPredicate | ||
486 | (name, args.Length, | ||
487 | "Cannot find predicate function " + methodName + " for " + name + "/" + args.Length + | ||
488 | " in " + methodClass.FullName); | ||
489 | } | ||
490 | } | ||
491 | |||
492 | return null; | ||
493 | } | ||
494 | |||
495 | /// <summary> | ||
496 | /// Return true if there is a dynamic or static predicate with name and arity. | ||
497 | /// This returns false for built-in predicates. | ||
498 | /// </summary> | ||
499 | /// <param name="name"></param> | ||
500 | /// <param name="arity"></param> | ||
501 | /// <param name="declaringClass">used to resolve references to the default | ||
502 | /// module Atom.a(""). If a declaringClass is needed to resolve the reference but it is | ||
503 | /// null, return false</param> | ||
504 | /// <returns></returns> | ||
505 | public static bool isCurrentPredicate(Atom name, int arity, Type declaringClass) | ||
506 | { | ||
507 | CompilerState state = new CompilerState(); | ||
508 | Variable FunctionName = new Variable(); | ||
509 | foreach (bool l1 in functorCallFunctionName(state, name, arity, FunctionName)) | ||
510 | { | ||
511 | Atom functionNameAtom = ((Atom)FunctionName.getValue()); | ||
512 | if (functionNameAtom == Atom.NIL) | ||
513 | // name is for a dynamic predicate. | ||
514 | return YP.isDynamicCurrentPredicate(name, arity); | ||
515 | |||
516 | string methodName = functionNameAtom._name; | ||
517 | |||
518 | if (methodName.StartsWith("YP.")) | ||
519 | // current_predicate/1 should fail for built-ins. | ||
520 | return false; | ||
521 | if (methodName.Contains(".")) | ||
522 | // We don't support calling inner classes, etc. | ||
523 | return false; | ||
524 | if (declaringClass == null) | ||
525 | return false; | ||
526 | |||
527 | foreach (MemberInfo member in declaringClass.GetMember(methodName)) | ||
528 | { | ||
529 | MethodInfo method = member as MethodInfo; | ||
530 | if (method == null) | ||
531 | continue; | ||
532 | if ((method.Attributes | MethodAttributes.Static) == 0) | ||
533 | // Not a static method. | ||
534 | continue; | ||
535 | if (method.GetParameters().Length == arity) | ||
536 | return true; | ||
537 | } | ||
538 | } | ||
539 | |||
540 | return false; | ||
541 | } | ||
542 | |||
543 | // Compiler output follows. | ||
544 | |||
545 | public class YPInnerClass { } | ||
546 | public static System.Type getDeclaringClass() { return typeof(YPInnerClass).DeclaringType; } | ||
547 | |||
548 | public static void repeatWrite(object arg1, object N) | ||
549 | { | ||
550 | { | ||
551 | object _Value = arg1; | ||
552 | if (YP.termEqual(N, 0)) | ||
553 | { | ||
554 | return; | ||
555 | } | ||
556 | } | ||
557 | { | ||
558 | object Value = arg1; | ||
559 | Variable NextN = new Variable(); | ||
560 | YP.write(Value); | ||
561 | foreach (bool l2 in YP.unify(NextN, YP.subtract(N, 1))) | ||
562 | { | ||
563 | repeatWrite(Value, NextN); | ||
564 | return; | ||
565 | } | ||
566 | } | ||
567 | } | ||
568 | |||
569 | public static bool sameVariable(object Variable1, object Variable2) | ||
570 | { | ||
571 | { | ||
572 | if (YP.var(Variable1)) | ||
573 | { | ||
574 | if (YP.var(Variable2)) | ||
575 | { | ||
576 | if (YP.termEqual(Variable1, Variable2)) | ||
577 | { | ||
578 | return true; | ||
579 | } | ||
580 | } | ||
581 | } | ||
582 | } | ||
583 | return false; | ||
584 | } | ||
585 | |||
586 | public static IEnumerable<bool> makeFunctionPseudoCode(object RuleList, object FunctionCode) | ||
587 | { | ||
588 | { | ||
589 | Variable State = new Variable(); | ||
590 | foreach (bool l2 in CompilerState.make(State)) | ||
591 | { | ||
592 | assertYPPred(State); | ||
593 | processCompilerDirectives(RuleList, State); | ||
594 | foreach (bool l3 in YP.unify(FunctionCode, Atom.a("getDeclaringClass"))) | ||
595 | { | ||
596 | yield return false; | ||
597 | } | ||
598 | foreach (bool l3 in makeFunctionPseudoCode3(RuleList, State, FunctionCode)) | ||
599 | { | ||
600 | yield return false; | ||
601 | } | ||
602 | } | ||
603 | } | ||
604 | } | ||
605 | |||
606 | public static void assertYPPred(object State) | ||
607 | { | ||
608 | { | ||
609 | CompilerState.assertPred(State, Atom.a("nl"), Atom.a("det")); | ||
610 | CompilerState.assertPred(State, new Functor1("write", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
611 | CompilerState.assertPred(State, new Functor1("put_code", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
612 | CompilerState.assertPred(State, new Functor1("see", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
613 | CompilerState.assertPred(State, Atom.a("seen"), Atom.a("det")); | ||
614 | CompilerState.assertPred(State, new Functor1("tell", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
615 | CompilerState.assertPred(State, Atom.a("told"), Atom.a("det")); | ||
616 | CompilerState.assertPred(State, new Functor1("throw", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
617 | CompilerState.assertPred(State, new Functor1("abolish", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
618 | CompilerState.assertPred(State, new Functor1("retractall", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
619 | CompilerState.assertPred(State, new Functor2("set_prolog_flag", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
620 | CompilerState.assertPred(State, new Functor1("var", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
621 | CompilerState.assertPred(State, new Functor1("nonvar", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
622 | CompilerState.assertPred(State, new Functor1("atom", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
623 | CompilerState.assertPred(State, new Functor1("integer", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
624 | CompilerState.assertPred(State, new Functor1("float", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
625 | CompilerState.assertPred(State, new Functor1("number", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
626 | CompilerState.assertPred(State, new Functor1("atomic", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
627 | CompilerState.assertPred(State, new Functor1("compound", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
628 | CompilerState.assertPred(State, new Functor2("==", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
629 | CompilerState.assertPred(State, new Functor2("\\==", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
630 | CompilerState.assertPred(State, new Functor2("@<", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
631 | CompilerState.assertPred(State, new Functor2("@=<", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
632 | CompilerState.assertPred(State, new Functor2("@>", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
633 | CompilerState.assertPred(State, new Functor2("@>=", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | ||
634 | return; | ||
635 | } | ||
636 | } | ||
637 | |||
638 | public static void processCompilerDirectives(object arg1, object arg2) | ||
639 | { | ||
640 | { | ||
641 | object _State = arg2; | ||
642 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
643 | { | ||
644 | return; | ||
645 | } | ||
646 | } | ||
647 | { | ||
648 | object State = arg2; | ||
649 | Variable Pred = new Variable(); | ||
650 | Variable Determinism = new Variable(); | ||
651 | Variable x3 = new Variable(); | ||
652 | Variable RestRules = new Variable(); | ||
653 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("f", new Functor1(":-", new Functor1("pred", new Functor2("is", Pred, Determinism))), x3), RestRules))) | ||
654 | { | ||
655 | CompilerState.assertPred(State, Pred, Determinism); | ||
656 | processCompilerDirectives(RestRules, State); | ||
657 | return; | ||
658 | } | ||
659 | } | ||
660 | { | ||
661 | object State = arg2; | ||
662 | Variable Module = new Variable(); | ||
663 | Variable PredicateList = new Variable(); | ||
664 | Variable x3 = new Variable(); | ||
665 | Variable RestRules = new Variable(); | ||
666 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("f", new Functor1(":-", new Functor2("import", Module, PredicateList)), x3), RestRules))) | ||
667 | { | ||
668 | foreach (bool l3 in importPredicateList(State, Module, PredicateList)) | ||
669 | { | ||
670 | processCompilerDirectives(RestRules, State); | ||
671 | return; | ||
672 | } | ||
673 | } | ||
674 | } | ||
675 | { | ||
676 | object State = arg2; | ||
677 | Variable x1 = new Variable(); | ||
678 | Variable x2 = new Variable(); | ||
679 | Variable RestRules = new Variable(); | ||
680 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("f", new Functor1(":-", x1), x2), RestRules))) | ||
681 | { | ||
682 | processCompilerDirectives(RestRules, State); | ||
683 | return; | ||
684 | } | ||
685 | } | ||
686 | { | ||
687 | object State = arg2; | ||
688 | Variable Head = new Variable(); | ||
689 | Variable _Body = new Variable(); | ||
690 | Variable x3 = new Variable(); | ||
691 | Variable RestRules = new Variable(); | ||
692 | Variable Name = new Variable(); | ||
693 | Variable Arity = new Variable(); | ||
694 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("f", new Functor2(":-", Head, _Body), x3), RestRules))) | ||
695 | { | ||
696 | foreach (bool l3 in YP.functor(Head, Name, Arity)) | ||
697 | { | ||
698 | CompilerState.assertModuleForNameArity(State, Name, Arity, Atom.a("")); | ||
699 | processCompilerDirectives(RestRules, State); | ||
700 | return; | ||
701 | } | ||
702 | } | ||
703 | } | ||
704 | { | ||
705 | object State = arg2; | ||
706 | Variable Fact = new Variable(); | ||
707 | Variable x2 = new Variable(); | ||
708 | Variable RestRules = new Variable(); | ||
709 | Variable Name = new Variable(); | ||
710 | Variable Arity = new Variable(); | ||
711 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("f", Fact, x2), RestRules))) | ||
712 | { | ||
713 | foreach (bool l3 in YP.functor(Fact, Name, Arity)) | ||
714 | { | ||
715 | CompilerState.assertModuleForNameArity(State, Name, Arity, Atom.a("")); | ||
716 | processCompilerDirectives(RestRules, State); | ||
717 | return; | ||
718 | } | ||
719 | } | ||
720 | } | ||
721 | { | ||
722 | object State = arg2; | ||
723 | Variable x1 = new Variable(); | ||
724 | Variable RestRules = new Variable(); | ||
725 | foreach (bool l2 in YP.unify(arg1, new ListPair(x1, RestRules))) | ||
726 | { | ||
727 | processCompilerDirectives(RestRules, State); | ||
728 | return; | ||
729 | } | ||
730 | } | ||
731 | } | ||
732 | |||
733 | public static IEnumerable<bool> importPredicateList(object arg1, object arg2, object arg3) | ||
734 | { | ||
735 | { | ||
736 | object _State = arg1; | ||
737 | object _Module = arg2; | ||
738 | foreach (bool l2 in YP.unify(arg3, Atom.NIL)) | ||
739 | { | ||
740 | yield return true; | ||
741 | yield break; | ||
742 | } | ||
743 | } | ||
744 | { | ||
745 | object State = arg1; | ||
746 | object Module = arg2; | ||
747 | Variable Name = new Variable(); | ||
748 | Variable Arity = new Variable(); | ||
749 | Variable Rest = new Variable(); | ||
750 | foreach (bool l2 in YP.unify(arg3, new ListPair(new Functor2("/", Name, Arity), Rest))) | ||
751 | { | ||
752 | CompilerState.assertModuleForNameArity(State, Name, Arity, Module); | ||
753 | foreach (bool l3 in importPredicateList(State, Module, Rest)) | ||
754 | { | ||
755 | yield return true; | ||
756 | yield break; | ||
757 | } | ||
758 | } | ||
759 | } | ||
760 | { | ||
761 | object State = arg1; | ||
762 | object Module = arg2; | ||
763 | Variable x3 = new Variable(); | ||
764 | Variable Rest = new Variable(); | ||
765 | foreach (bool l2 in YP.unify(arg3, new ListPair(x3, Rest))) | ||
766 | { | ||
767 | foreach (bool l3 in importPredicateList(State, Module, Rest)) | ||
768 | { | ||
769 | yield return true; | ||
770 | yield break; | ||
771 | } | ||
772 | } | ||
773 | } | ||
774 | } | ||
775 | |||
776 | public static IEnumerable<bool> makeFunctionPseudoCode3(object RuleList, object State, object FunctionCode) | ||
777 | { | ||
778 | { | ||
779 | Variable SamePredicateRuleList = new Variable(); | ||
780 | Variable RestRules = new Variable(); | ||
781 | foreach (bool l2 in samePredicateRuleList(RuleList, SamePredicateRuleList, RestRules)) | ||
782 | { | ||
783 | if (YP.termNotEqual(SamePredicateRuleList, Atom.NIL)) | ||
784 | { | ||
785 | foreach (bool l4 in compileSamePredicateFunction(SamePredicateRuleList, State, FunctionCode)) | ||
786 | { | ||
787 | yield return false; | ||
788 | } | ||
789 | foreach (bool l4 in makeFunctionPseudoCode3(RestRules, State, FunctionCode)) | ||
790 | { | ||
791 | yield return false; | ||
792 | } | ||
793 | } | ||
794 | } | ||
795 | } | ||
796 | } | ||
797 | |||
798 | public static IEnumerable<bool> compileSamePredicateFunction(object SamePredicateRuleList, object State, object FunctionCode) | ||
799 | { | ||
800 | { | ||
801 | Variable FirstRule = new Variable(); | ||
802 | Variable x5 = new Variable(); | ||
803 | Variable x6 = new Variable(); | ||
804 | Variable x7 = new Variable(); | ||
805 | Variable Head = new Variable(); | ||
806 | Variable x9 = new Variable(); | ||
807 | Variable ArgAssignments = new Variable(); | ||
808 | Variable Calls = new Variable(); | ||
809 | Variable Rule = new Variable(); | ||
810 | Variable VariableNameSuggestions = new Variable(); | ||
811 | Variable ClauseBag = new Variable(); | ||
812 | Variable Name = new Variable(); | ||
813 | Variable ArgsList = new Variable(); | ||
814 | Variable FunctionArgNames = new Variable(); | ||
815 | Variable MergedArgName = new Variable(); | ||
816 | Variable ArgName = new Variable(); | ||
817 | Variable MergedArgNames = new Variable(); | ||
818 | Variable FunctionArgs = new Variable(); | ||
819 | Variable BodyCode = new Variable(); | ||
820 | Variable ReturnType = new Variable(); | ||
821 | Variable BodyWithReturn = new Variable(); | ||
822 | foreach (bool l2 in YP.unify(new ListPair(new Functor2("f", FirstRule, x5), x6), SamePredicateRuleList)) | ||
823 | { | ||
824 | foreach (bool l3 in YP.unify(FirstRule, new Functor1(":-", x7))) | ||
825 | { | ||
826 | goto cutIf1; | ||
827 | } | ||
828 | foreach (bool l3 in YP.unify(new Functor2(":-", Head, x9), FirstRule)) | ||
829 | { | ||
830 | CompilerState.startFunction(State, Head); | ||
831 | FindallAnswers findallAnswers3 = new FindallAnswers(new Functor2("f", ArgAssignments, Calls)); | ||
832 | foreach (bool l4 in member(new Functor2("f", Rule, VariableNameSuggestions), SamePredicateRuleList)) | ||
833 | { | ||
834 | foreach (bool l5 in compileBodyWithHeadBindings(Rule, VariableNameSuggestions, State, ArgAssignments, Calls)) | ||
835 | { | ||
836 | findallAnswers3.add(); | ||
837 | } | ||
838 | } | ||
839 | foreach (bool l4 in findallAnswers3.result(ClauseBag)) | ||
840 | { | ||
841 | foreach (bool l5 in YP.univ(Head, new ListPair(Name, ArgsList))) | ||
842 | { | ||
843 | foreach (bool l6 in getFunctionArgNames(ArgsList, 1, FunctionArgNames)) | ||
844 | { | ||
845 | FindallAnswers findallAnswers4 = new FindallAnswers(MergedArgName); | ||
846 | foreach (bool l7 in member(ArgName, FunctionArgNames)) | ||
847 | { | ||
848 | foreach (bool l8 in argAssignedAll(ArgName, ClauseBag, MergedArgName)) | ||
849 | { | ||
850 | findallAnswers4.add(); | ||
851 | goto cutIf5; | ||
852 | } | ||
853 | foreach (bool l8 in YP.unify(MergedArgName, ArgName)) | ||
854 | { | ||
855 | findallAnswers4.add(); | ||
856 | } | ||
857 | cutIf5: | ||
858 | { } | ||
859 | } | ||
860 | foreach (bool l7 in findallAnswers4.result(MergedArgNames)) | ||
861 | { | ||
862 | foreach (bool l8 in maplist_arg(MergedArgNames, FunctionArgs)) | ||
863 | { | ||
864 | foreach (bool l9 in maplist_compileClause(ClauseBag, MergedArgNames, BodyCode)) | ||
865 | { | ||
866 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
867 | { | ||
868 | foreach (bool l11 in YP.unify(ReturnType, Atom.a("void"))) | ||
869 | { | ||
870 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
871 | { | ||
872 | foreach (bool l13 in append(BodyCode, new ListPair(Atom.a("returnfalse"), Atom.NIL), BodyWithReturn)) | ||
873 | { | ||
874 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
875 | { | ||
876 | yield return false; | ||
877 | } | ||
878 | } | ||
879 | goto cutIf7; | ||
880 | } | ||
881 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
882 | { | ||
883 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
884 | { | ||
885 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
886 | { | ||
887 | yield return false; | ||
888 | } | ||
889 | } | ||
890 | goto cutIf8; | ||
891 | } | ||
892 | if (CompilerState.codeUsesYield(State)) | ||
893 | { | ||
894 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
895 | { | ||
896 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
897 | { | ||
898 | yield return false; | ||
899 | } | ||
900 | } | ||
901 | goto cutIf9; | ||
902 | } | ||
903 | foreach (bool l12 in append(BodyCode, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.fail"), Atom.NIL), new ListPair(Atom.a("yieldfalse"), Atom.NIL)), Atom.NIL), BodyWithReturn)) | ||
904 | { | ||
905 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
906 | { | ||
907 | yield return false; | ||
908 | } | ||
909 | } | ||
910 | cutIf9: | ||
911 | cutIf8: | ||
912 | cutIf7: | ||
913 | { } | ||
914 | } | ||
915 | goto cutIf6; | ||
916 | } | ||
917 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
918 | { | ||
919 | foreach (bool l11 in YP.unify(ReturnType, Atom.a("bool"))) | ||
920 | { | ||
921 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
922 | { | ||
923 | foreach (bool l13 in append(BodyCode, new ListPair(Atom.a("returnfalse"), Atom.NIL), BodyWithReturn)) | ||
924 | { | ||
925 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
926 | { | ||
927 | yield return false; | ||
928 | } | ||
929 | } | ||
930 | goto cutIf11; | ||
931 | } | ||
932 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
933 | { | ||
934 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
935 | { | ||
936 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
937 | { | ||
938 | yield return false; | ||
939 | } | ||
940 | } | ||
941 | goto cutIf12; | ||
942 | } | ||
943 | if (CompilerState.codeUsesYield(State)) | ||
944 | { | ||
945 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
946 | { | ||
947 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
948 | { | ||
949 | yield return false; | ||
950 | } | ||
951 | } | ||
952 | goto cutIf13; | ||
953 | } | ||
954 | foreach (bool l12 in append(BodyCode, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.fail"), Atom.NIL), new ListPair(Atom.a("yieldfalse"), Atom.NIL)), Atom.NIL), BodyWithReturn)) | ||
955 | { | ||
956 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
957 | { | ||
958 | yield return false; | ||
959 | } | ||
960 | } | ||
961 | cutIf13: | ||
962 | cutIf12: | ||
963 | cutIf11: | ||
964 | { } | ||
965 | } | ||
966 | goto cutIf10; | ||
967 | } | ||
968 | foreach (bool l10 in YP.unify(ReturnType, Atom.a("IEnumerable<bool>"))) | ||
969 | { | ||
970 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
971 | { | ||
972 | foreach (bool l12 in append(BodyCode, new ListPair(Atom.a("returnfalse"), Atom.NIL), BodyWithReturn)) | ||
973 | { | ||
974 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
975 | { | ||
976 | yield return false; | ||
977 | } | ||
978 | } | ||
979 | goto cutIf14; | ||
980 | } | ||
981 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
982 | { | ||
983 | foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) | ||
984 | { | ||
985 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
986 | { | ||
987 | yield return false; | ||
988 | } | ||
989 | } | ||
990 | goto cutIf15; | ||
991 | } | ||
992 | if (CompilerState.codeUsesYield(State)) | ||
993 | { | ||
994 | foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) | ||
995 | { | ||
996 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
997 | { | ||
998 | yield return false; | ||
999 | } | ||
1000 | } | ||
1001 | goto cutIf16; | ||
1002 | } | ||
1003 | foreach (bool l11 in append(BodyCode, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.fail"), Atom.NIL), new ListPair(Atom.a("yieldfalse"), Atom.NIL)), Atom.NIL), BodyWithReturn)) | ||
1004 | { | ||
1005 | foreach (bool l12 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1006 | { | ||
1007 | yield return false; | ||
1008 | } | ||
1009 | } | ||
1010 | cutIf16: | ||
1011 | cutIf15: | ||
1012 | cutIf14: | ||
1013 | { } | ||
1014 | } | ||
1015 | cutIf10: | ||
1016 | cutIf6: | ||
1017 | { } | ||
1018 | } | ||
1019 | } | ||
1020 | } | ||
1021 | } | ||
1022 | } | ||
1023 | } | ||
1024 | goto cutIf2; | ||
1025 | } | ||
1026 | foreach (bool l3 in YP.unify(Head, FirstRule)) | ||
1027 | { | ||
1028 | CompilerState.startFunction(State, Head); | ||
1029 | FindallAnswers findallAnswers17 = new FindallAnswers(new Functor2("f", ArgAssignments, Calls)); | ||
1030 | foreach (bool l4 in member(new Functor2("f", Rule, VariableNameSuggestions), SamePredicateRuleList)) | ||
1031 | { | ||
1032 | foreach (bool l5 in compileBodyWithHeadBindings(Rule, VariableNameSuggestions, State, ArgAssignments, Calls)) | ||
1033 | { | ||
1034 | findallAnswers17.add(); | ||
1035 | } | ||
1036 | } | ||
1037 | foreach (bool l4 in findallAnswers17.result(ClauseBag)) | ||
1038 | { | ||
1039 | foreach (bool l5 in YP.univ(Head, new ListPair(Name, ArgsList))) | ||
1040 | { | ||
1041 | foreach (bool l6 in getFunctionArgNames(ArgsList, 1, FunctionArgNames)) | ||
1042 | { | ||
1043 | FindallAnswers findallAnswers18 = new FindallAnswers(MergedArgName); | ||
1044 | foreach (bool l7 in member(ArgName, FunctionArgNames)) | ||
1045 | { | ||
1046 | foreach (bool l8 in argAssignedAll(ArgName, ClauseBag, MergedArgName)) | ||
1047 | { | ||
1048 | findallAnswers18.add(); | ||
1049 | goto cutIf19; | ||
1050 | } | ||
1051 | foreach (bool l8 in YP.unify(MergedArgName, ArgName)) | ||
1052 | { | ||
1053 | findallAnswers18.add(); | ||
1054 | } | ||
1055 | cutIf19: | ||
1056 | { } | ||
1057 | } | ||
1058 | foreach (bool l7 in findallAnswers18.result(MergedArgNames)) | ||
1059 | { | ||
1060 | foreach (bool l8 in maplist_arg(MergedArgNames, FunctionArgs)) | ||
1061 | { | ||
1062 | foreach (bool l9 in maplist_compileClause(ClauseBag, MergedArgNames, BodyCode)) | ||
1063 | { | ||
1064 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
1065 | { | ||
1066 | foreach (bool l11 in YP.unify(ReturnType, Atom.a("void"))) | ||
1067 | { | ||
1068 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
1069 | { | ||
1070 | foreach (bool l13 in append(BodyCode, new ListPair(Atom.a("returnfalse"), Atom.NIL), BodyWithReturn)) | ||
1071 | { | ||
1072 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1073 | { | ||
1074 | yield return false; | ||
1075 | } | ||
1076 | } | ||
1077 | goto cutIf21; | ||
1078 | } | ||
1079 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
1080 | { | ||
1081 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
1082 | { | ||
1083 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1084 | { | ||
1085 | yield return false; | ||
1086 | } | ||
1087 | } | ||
1088 | goto cutIf22; | ||
1089 | } | ||
1090 | if (CompilerState.codeUsesYield(State)) | ||
1091 | { | ||
1092 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
1093 | { | ||
1094 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1095 | { | ||
1096 | yield return false; | ||
1097 | } | ||
1098 | } | ||
1099 | goto cutIf23; | ||
1100 | } | ||
1101 | foreach (bool l12 in append(BodyCode, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.fail"), Atom.NIL), new ListPair(Atom.a("yieldfalse"), Atom.NIL)), Atom.NIL), BodyWithReturn)) | ||
1102 | { | ||
1103 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1104 | { | ||
1105 | yield return false; | ||
1106 | } | ||
1107 | } | ||
1108 | cutIf23: | ||
1109 | cutIf22: | ||
1110 | cutIf21: | ||
1111 | { } | ||
1112 | } | ||
1113 | goto cutIf20; | ||
1114 | } | ||
1115 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
1116 | { | ||
1117 | foreach (bool l11 in YP.unify(ReturnType, Atom.a("bool"))) | ||
1118 | { | ||
1119 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
1120 | { | ||
1121 | foreach (bool l13 in append(BodyCode, new ListPair(Atom.a("returnfalse"), Atom.NIL), BodyWithReturn)) | ||
1122 | { | ||
1123 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1124 | { | ||
1125 | yield return false; | ||
1126 | } | ||
1127 | } | ||
1128 | goto cutIf25; | ||
1129 | } | ||
1130 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
1131 | { | ||
1132 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
1133 | { | ||
1134 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1135 | { | ||
1136 | yield return false; | ||
1137 | } | ||
1138 | } | ||
1139 | goto cutIf26; | ||
1140 | } | ||
1141 | if (CompilerState.codeUsesYield(State)) | ||
1142 | { | ||
1143 | foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) | ||
1144 | { | ||
1145 | foreach (bool l14 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1146 | { | ||
1147 | yield return false; | ||
1148 | } | ||
1149 | } | ||
1150 | goto cutIf27; | ||
1151 | } | ||
1152 | foreach (bool l12 in append(BodyCode, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.fail"), Atom.NIL), new ListPair(Atom.a("yieldfalse"), Atom.NIL)), Atom.NIL), BodyWithReturn)) | ||
1153 | { | ||
1154 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1155 | { | ||
1156 | yield return false; | ||
1157 | } | ||
1158 | } | ||
1159 | cutIf27: | ||
1160 | cutIf26: | ||
1161 | cutIf25: | ||
1162 | { } | ||
1163 | } | ||
1164 | goto cutIf24; | ||
1165 | } | ||
1166 | foreach (bool l10 in YP.unify(ReturnType, Atom.a("IEnumerable<bool>"))) | ||
1167 | { | ||
1168 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
1169 | { | ||
1170 | foreach (bool l12 in append(BodyCode, new ListPair(Atom.a("returnfalse"), Atom.NIL), BodyWithReturn)) | ||
1171 | { | ||
1172 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1173 | { | ||
1174 | yield return false; | ||
1175 | } | ||
1176 | } | ||
1177 | goto cutIf28; | ||
1178 | } | ||
1179 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
1180 | { | ||
1181 | foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) | ||
1182 | { | ||
1183 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1184 | { | ||
1185 | yield return false; | ||
1186 | } | ||
1187 | } | ||
1188 | goto cutIf29; | ||
1189 | } | ||
1190 | if (CompilerState.codeUsesYield(State)) | ||
1191 | { | ||
1192 | foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) | ||
1193 | { | ||
1194 | foreach (bool l13 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1195 | { | ||
1196 | yield return false; | ||
1197 | } | ||
1198 | } | ||
1199 | goto cutIf30; | ||
1200 | } | ||
1201 | foreach (bool l11 in append(BodyCode, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.fail"), Atom.NIL), new ListPair(Atom.a("yieldfalse"), Atom.NIL)), Atom.NIL), BodyWithReturn)) | ||
1202 | { | ||
1203 | foreach (bool l12 in YP.unify(FunctionCode, new Functor("function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) | ||
1204 | { | ||
1205 | yield return false; | ||
1206 | } | ||
1207 | } | ||
1208 | cutIf30: | ||
1209 | cutIf29: | ||
1210 | cutIf28: | ||
1211 | { } | ||
1212 | } | ||
1213 | cutIf24: | ||
1214 | cutIf20: | ||
1215 | { } | ||
1216 | } | ||
1217 | } | ||
1218 | } | ||
1219 | } | ||
1220 | } | ||
1221 | } | ||
1222 | } | ||
1223 | cutIf2: | ||
1224 | cutIf1: | ||
1225 | { } | ||
1226 | } | ||
1227 | } | ||
1228 | } | ||
1229 | |||
1230 | public static IEnumerable<bool> samePredicateRuleList(object arg1, object arg2, object arg3) | ||
1231 | { | ||
1232 | { | ||
1233 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1234 | { | ||
1235 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
1236 | { | ||
1237 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
1238 | { | ||
1239 | yield return true; | ||
1240 | yield break; | ||
1241 | } | ||
1242 | } | ||
1243 | } | ||
1244 | } | ||
1245 | { | ||
1246 | Variable First = new Variable(); | ||
1247 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Atom.NIL))) | ||
1248 | { | ||
1249 | foreach (bool l3 in YP.unify(arg2, new ListPair(First, Atom.NIL))) | ||
1250 | { | ||
1251 | foreach (bool l4 in YP.unify(arg3, Atom.NIL)) | ||
1252 | { | ||
1253 | yield return true; | ||
1254 | yield break; | ||
1255 | } | ||
1256 | } | ||
1257 | } | ||
1258 | } | ||
1259 | { | ||
1260 | object SamePredicateRuleList = arg2; | ||
1261 | object RestRules = arg3; | ||
1262 | Variable First = new Variable(); | ||
1263 | Variable Rest = new Variable(); | ||
1264 | Variable FirstRule = new Variable(); | ||
1265 | Variable x6 = new Variable(); | ||
1266 | Variable SecondRule = new Variable(); | ||
1267 | Variable x8 = new Variable(); | ||
1268 | Variable x9 = new Variable(); | ||
1269 | Variable FirstHead = new Variable(); | ||
1270 | Variable x11 = new Variable(); | ||
1271 | Variable SecondHead = new Variable(); | ||
1272 | Variable x13 = new Variable(); | ||
1273 | Variable Name = new Variable(); | ||
1274 | Variable Arity = new Variable(); | ||
1275 | Variable RestSamePredicates = new Variable(); | ||
1276 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
1277 | { | ||
1278 | foreach (bool l3 in YP.unify(new Functor2("f", FirstRule, x6), First)) | ||
1279 | { | ||
1280 | foreach (bool l4 in YP.unify(new ListPair(new Functor2("f", SecondRule, x8), x9), Rest)) | ||
1281 | { | ||
1282 | foreach (bool l5 in YP.unify(new Functor2(":-", FirstHead, x11), FirstRule)) | ||
1283 | { | ||
1284 | foreach (bool l6 in YP.unify(new Functor2(":-", SecondHead, x13), SecondRule)) | ||
1285 | { | ||
1286 | foreach (bool l7 in YP.functor(FirstHead, Name, Arity)) | ||
1287 | { | ||
1288 | foreach (bool l8 in YP.functor(SecondHead, Name, Arity)) | ||
1289 | { | ||
1290 | foreach (bool l9 in samePredicateRuleList(Rest, RestSamePredicates, RestRules)) | ||
1291 | { | ||
1292 | foreach (bool l10 in YP.unify(SamePredicateRuleList, new ListPair(First, RestSamePredicates))) | ||
1293 | { | ||
1294 | yield return true; | ||
1295 | yield break; | ||
1296 | } | ||
1297 | } | ||
1298 | goto cutIf3; | ||
1299 | } | ||
1300 | foreach (bool l8 in YP.unify(SamePredicateRuleList, new ListPair(First, Atom.NIL))) | ||
1301 | { | ||
1302 | foreach (bool l9 in YP.unify(RestRules, Rest)) | ||
1303 | { | ||
1304 | yield return true; | ||
1305 | yield break; | ||
1306 | } | ||
1307 | } | ||
1308 | cutIf3: | ||
1309 | { } | ||
1310 | } | ||
1311 | goto cutIf2; | ||
1312 | } | ||
1313 | foreach (bool l6 in YP.unify(SecondHead, SecondRule)) | ||
1314 | { | ||
1315 | foreach (bool l7 in YP.functor(FirstHead, Name, Arity)) | ||
1316 | { | ||
1317 | foreach (bool l8 in YP.functor(SecondHead, Name, Arity)) | ||
1318 | { | ||
1319 | foreach (bool l9 in samePredicateRuleList(Rest, RestSamePredicates, RestRules)) | ||
1320 | { | ||
1321 | foreach (bool l10 in YP.unify(SamePredicateRuleList, new ListPair(First, RestSamePredicates))) | ||
1322 | { | ||
1323 | yield return true; | ||
1324 | yield break; | ||
1325 | } | ||
1326 | } | ||
1327 | goto cutIf4; | ||
1328 | } | ||
1329 | foreach (bool l8 in YP.unify(SamePredicateRuleList, new ListPair(First, Atom.NIL))) | ||
1330 | { | ||
1331 | foreach (bool l9 in YP.unify(RestRules, Rest)) | ||
1332 | { | ||
1333 | yield return true; | ||
1334 | yield break; | ||
1335 | } | ||
1336 | } | ||
1337 | cutIf4: | ||
1338 | { } | ||
1339 | } | ||
1340 | } | ||
1341 | cutIf2: | ||
1342 | goto cutIf1; | ||
1343 | } | ||
1344 | foreach (bool l5 in YP.unify(FirstHead, FirstRule)) | ||
1345 | { | ||
1346 | foreach (bool l6 in YP.unify(new Functor2(":-", SecondHead, x13), SecondRule)) | ||
1347 | { | ||
1348 | foreach (bool l7 in YP.functor(FirstHead, Name, Arity)) | ||
1349 | { | ||
1350 | foreach (bool l8 in YP.functor(SecondHead, Name, Arity)) | ||
1351 | { | ||
1352 | foreach (bool l9 in samePredicateRuleList(Rest, RestSamePredicates, RestRules)) | ||
1353 | { | ||
1354 | foreach (bool l10 in YP.unify(SamePredicateRuleList, new ListPair(First, RestSamePredicates))) | ||
1355 | { | ||
1356 | yield return true; | ||
1357 | yield break; | ||
1358 | } | ||
1359 | } | ||
1360 | goto cutIf6; | ||
1361 | } | ||
1362 | foreach (bool l8 in YP.unify(SamePredicateRuleList, new ListPair(First, Atom.NIL))) | ||
1363 | { | ||
1364 | foreach (bool l9 in YP.unify(RestRules, Rest)) | ||
1365 | { | ||
1366 | yield return true; | ||
1367 | yield break; | ||
1368 | } | ||
1369 | } | ||
1370 | cutIf6: | ||
1371 | { } | ||
1372 | } | ||
1373 | goto cutIf5; | ||
1374 | } | ||
1375 | foreach (bool l6 in YP.unify(SecondHead, SecondRule)) | ||
1376 | { | ||
1377 | foreach (bool l7 in YP.functor(FirstHead, Name, Arity)) | ||
1378 | { | ||
1379 | foreach (bool l8 in YP.functor(SecondHead, Name, Arity)) | ||
1380 | { | ||
1381 | foreach (bool l9 in samePredicateRuleList(Rest, RestSamePredicates, RestRules)) | ||
1382 | { | ||
1383 | foreach (bool l10 in YP.unify(SamePredicateRuleList, new ListPair(First, RestSamePredicates))) | ||
1384 | { | ||
1385 | yield return true; | ||
1386 | yield break; | ||
1387 | } | ||
1388 | } | ||
1389 | goto cutIf7; | ||
1390 | } | ||
1391 | foreach (bool l8 in YP.unify(SamePredicateRuleList, new ListPair(First, Atom.NIL))) | ||
1392 | { | ||
1393 | foreach (bool l9 in YP.unify(RestRules, Rest)) | ||
1394 | { | ||
1395 | yield return true; | ||
1396 | yield break; | ||
1397 | } | ||
1398 | } | ||
1399 | cutIf7: | ||
1400 | { } | ||
1401 | } | ||
1402 | } | ||
1403 | cutIf5: | ||
1404 | { } | ||
1405 | } | ||
1406 | cutIf1: | ||
1407 | { } | ||
1408 | } | ||
1409 | } | ||
1410 | } | ||
1411 | } | ||
1412 | } | ||
1413 | |||
1414 | public static IEnumerable<bool> maplist_compileClause(object arg1, object arg2, object arg3) | ||
1415 | { | ||
1416 | { | ||
1417 | object _MergedArgNames = arg2; | ||
1418 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1419 | { | ||
1420 | foreach (bool l3 in YP.unify(arg3, Atom.NIL)) | ||
1421 | { | ||
1422 | yield return true; | ||
1423 | yield break; | ||
1424 | } | ||
1425 | } | ||
1426 | } | ||
1427 | { | ||
1428 | object MergedArgNames = arg2; | ||
1429 | Variable ArgAssignments = new Variable(); | ||
1430 | Variable Calls = new Variable(); | ||
1431 | Variable Rest = new Variable(); | ||
1432 | Variable ClauseCode = new Variable(); | ||
1433 | Variable RestResults = new Variable(); | ||
1434 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("f", ArgAssignments, Calls), Rest))) | ||
1435 | { | ||
1436 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor1("blockScope", ClauseCode), RestResults))) | ||
1437 | { | ||
1438 | foreach (bool l4 in prependArgAssignments(ArgAssignments, Calls, MergedArgNames, ClauseCode)) | ||
1439 | { | ||
1440 | foreach (bool l5 in maplist_compileClause(Rest, MergedArgNames, RestResults)) | ||
1441 | { | ||
1442 | yield return true; | ||
1443 | yield break; | ||
1444 | } | ||
1445 | } | ||
1446 | } | ||
1447 | } | ||
1448 | } | ||
1449 | } | ||
1450 | |||
1451 | public static IEnumerable<bool> prependArgAssignments(object arg1, object arg2, object arg3, object arg4) | ||
1452 | { | ||
1453 | { | ||
1454 | object _MergedArgNames = arg3; | ||
1455 | Variable In = new Variable(); | ||
1456 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1457 | { | ||
1458 | foreach (bool l3 in YP.unify(arg2, In)) | ||
1459 | { | ||
1460 | foreach (bool l4 in YP.unify(arg4, In)) | ||
1461 | { | ||
1462 | yield return true; | ||
1463 | yield break; | ||
1464 | } | ||
1465 | } | ||
1466 | } | ||
1467 | } | ||
1468 | { | ||
1469 | object In = arg2; | ||
1470 | object MergedArgNames = arg3; | ||
1471 | object ClauseCode = arg4; | ||
1472 | Variable VariableName = new Variable(); | ||
1473 | Variable ArgName = new Variable(); | ||
1474 | Variable RestArgAssignments = new Variable(); | ||
1475 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("f", VariableName, ArgName), RestArgAssignments))) | ||
1476 | { | ||
1477 | foreach (bool l3 in member(VariableName, MergedArgNames)) | ||
1478 | { | ||
1479 | foreach (bool l4 in prependArgAssignments(RestArgAssignments, In, MergedArgNames, ClauseCode)) | ||
1480 | { | ||
1481 | yield return true; | ||
1482 | yield break; | ||
1483 | } | ||
1484 | goto cutIf1; | ||
1485 | } | ||
1486 | foreach (bool l3 in prependArgAssignments(RestArgAssignments, new ListPair(new Functor3("declare", Atom.a("object"), VariableName, new Functor1("var", ArgName)), In), MergedArgNames, ClauseCode)) | ||
1487 | { | ||
1488 | yield return true; | ||
1489 | yield break; | ||
1490 | } | ||
1491 | cutIf1: | ||
1492 | { } | ||
1493 | } | ||
1494 | } | ||
1495 | } | ||
1496 | |||
1497 | public static IEnumerable<bool> argAssignedAll(object arg1, object arg2, object VariableName) | ||
1498 | { | ||
1499 | { | ||
1500 | object _ArgName = arg1; | ||
1501 | foreach (bool l2 in YP.unify(arg2, Atom.NIL)) | ||
1502 | { | ||
1503 | if (YP.nonvar(VariableName)) | ||
1504 | { | ||
1505 | yield return true; | ||
1506 | yield break; | ||
1507 | } | ||
1508 | } | ||
1509 | } | ||
1510 | { | ||
1511 | object ArgName = arg1; | ||
1512 | Variable ArgAssignments = new Variable(); | ||
1513 | Variable _Calls = new Variable(); | ||
1514 | Variable RestClauseBag = new Variable(); | ||
1515 | foreach (bool l2 in YP.unify(arg2, new ListPair(new Functor2("f", ArgAssignments, _Calls), RestClauseBag))) | ||
1516 | { | ||
1517 | foreach (bool l3 in member(new Functor2("f", VariableName, ArgName), ArgAssignments)) | ||
1518 | { | ||
1519 | foreach (bool l4 in argAssignedAll(ArgName, RestClauseBag, VariableName)) | ||
1520 | { | ||
1521 | yield return false; | ||
1522 | } | ||
1523 | } | ||
1524 | } | ||
1525 | } | ||
1526 | } | ||
1527 | |||
1528 | public static IEnumerable<bool> maplist_arg(object arg1, object arg2) | ||
1529 | { | ||
1530 | { | ||
1531 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1532 | { | ||
1533 | foreach (bool l3 in YP.unify(arg2, Atom.NIL)) | ||
1534 | { | ||
1535 | yield return true; | ||
1536 | yield break; | ||
1537 | } | ||
1538 | } | ||
1539 | } | ||
1540 | { | ||
1541 | Variable First = new Variable(); | ||
1542 | Variable Rest = new Variable(); | ||
1543 | Variable RestResults = new Variable(); | ||
1544 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
1545 | { | ||
1546 | foreach (bool l3 in YP.unify(arg2, new ListPair(new Functor1("arg", First), RestResults))) | ||
1547 | { | ||
1548 | foreach (bool l4 in maplist_arg(Rest, RestResults)) | ||
1549 | { | ||
1550 | yield return true; | ||
1551 | yield break; | ||
1552 | } | ||
1553 | } | ||
1554 | } | ||
1555 | } | ||
1556 | } | ||
1557 | |||
1558 | public static IEnumerable<bool> getFunctionArgNames(object arg1, object arg2, object arg3) | ||
1559 | { | ||
1560 | { | ||
1561 | object _StartArgNumber = arg2; | ||
1562 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1563 | { | ||
1564 | foreach (bool l3 in YP.unify(arg3, Atom.NIL)) | ||
1565 | { | ||
1566 | yield return true; | ||
1567 | yield break; | ||
1568 | } | ||
1569 | } | ||
1570 | } | ||
1571 | { | ||
1572 | object StartArgNumber = arg2; | ||
1573 | Variable x1 = new Variable(); | ||
1574 | Variable Rest = new Variable(); | ||
1575 | Variable ArgName = new Variable(); | ||
1576 | Variable RestFunctionArgs = new Variable(); | ||
1577 | Variable NumberCodes = new Variable(); | ||
1578 | Variable NumberAtom = new Variable(); | ||
1579 | Variable NextArgNumber = new Variable(); | ||
1580 | foreach (bool l2 in YP.unify(arg1, new ListPair(x1, Rest))) | ||
1581 | { | ||
1582 | foreach (bool l3 in YP.unify(arg3, new ListPair(ArgName, RestFunctionArgs))) | ||
1583 | { | ||
1584 | foreach (bool l4 in YP.number_codes(StartArgNumber, NumberCodes)) | ||
1585 | { | ||
1586 | foreach (bool l5 in YP.atom_codes(NumberAtom, NumberCodes)) | ||
1587 | { | ||
1588 | foreach (bool l6 in YP.atom_concat(Atom.a("arg"), NumberAtom, ArgName)) | ||
1589 | { | ||
1590 | foreach (bool l7 in YP.unify(NextArgNumber, YP.add(StartArgNumber, 1))) | ||
1591 | { | ||
1592 | foreach (bool l8 in getFunctionArgNames(Rest, NextArgNumber, RestFunctionArgs)) | ||
1593 | { | ||
1594 | yield return true; | ||
1595 | yield break; | ||
1596 | } | ||
1597 | } | ||
1598 | } | ||
1599 | } | ||
1600 | } | ||
1601 | } | ||
1602 | } | ||
1603 | } | ||
1604 | } | ||
1605 | |||
1606 | public static IEnumerable<bool> compileBodyWithHeadBindings(object Rule, object VariableNameSuggestions, object State, object ArgAssignments, object Calls) | ||
1607 | { | ||
1608 | { | ||
1609 | Variable Head = new Variable(); | ||
1610 | Variable Body = new Variable(); | ||
1611 | Variable x8 = new Variable(); | ||
1612 | Variable HeadArgs = new Variable(); | ||
1613 | Variable CompiledHeadArgs = new Variable(); | ||
1614 | Variable BodyCode = new Variable(); | ||
1615 | Variable VariableNamesList = new Variable(); | ||
1616 | Variable ArgUnifications = new Variable(); | ||
1617 | foreach (bool l2 in YP.unify(new Functor2(":-", Head, Body), Rule)) | ||
1618 | { | ||
1619 | CompilerState.newVariableNames(State, Rule, VariableNameSuggestions); | ||
1620 | foreach (bool l3 in YP.univ(Head, new ListPair(x8, HeadArgs))) | ||
1621 | { | ||
1622 | foreach (bool l4 in maplist_compileTerm(HeadArgs, State, CompiledHeadArgs)) | ||
1623 | { | ||
1624 | foreach (bool l5 in compileRuleBody(Body, State, BodyCode)) | ||
1625 | { | ||
1626 | foreach (bool l6 in CompilerState.variableNamesList(State, VariableNamesList)) | ||
1627 | { | ||
1628 | foreach (bool l7 in compileArgUnifications(HeadArgs, CompiledHeadArgs, 1, HeadArgs, BodyCode, ArgUnifications)) | ||
1629 | { | ||
1630 | foreach (bool l8 in compileDeclarations(VariableNamesList, HeadArgs, Atom.NIL, ArgAssignments, ArgUnifications, Calls)) | ||
1631 | { | ||
1632 | yield return true; | ||
1633 | yield break; | ||
1634 | } | ||
1635 | } | ||
1636 | } | ||
1637 | } | ||
1638 | } | ||
1639 | } | ||
1640 | } | ||
1641 | } | ||
1642 | { | ||
1643 | foreach (bool l2 in compileBodyWithHeadBindings(new Functor2(":-", Rule, Atom.a("true")), VariableNameSuggestions, State, ArgAssignments, Calls)) | ||
1644 | { | ||
1645 | yield return true; | ||
1646 | yield break; | ||
1647 | } | ||
1648 | } | ||
1649 | } | ||
1650 | |||
1651 | public static IEnumerable<bool> compileArgUnifications(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6) | ||
1652 | { | ||
1653 | { | ||
1654 | object x1 = arg2; | ||
1655 | object x2 = arg3; | ||
1656 | object x3 = arg4; | ||
1657 | Variable BodyCode = new Variable(); | ||
1658 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1659 | { | ||
1660 | foreach (bool l3 in YP.unify(arg5, BodyCode)) | ||
1661 | { | ||
1662 | foreach (bool l4 in YP.unify(arg6, BodyCode)) | ||
1663 | { | ||
1664 | yield return true; | ||
1665 | yield break; | ||
1666 | } | ||
1667 | } | ||
1668 | } | ||
1669 | } | ||
1670 | { | ||
1671 | object Index = arg3; | ||
1672 | object AllHeadArgs = arg4; | ||
1673 | object BodyCode = arg5; | ||
1674 | object ArgUnifications = arg6; | ||
1675 | Variable HeadArg = new Variable(); | ||
1676 | Variable RestHeadArgs = new Variable(); | ||
1677 | Variable x3 = new Variable(); | ||
1678 | Variable RestCompiledHeadArgs = new Variable(); | ||
1679 | Variable _ArgIndex1 = new Variable(); | ||
1680 | Variable NextIndex = new Variable(); | ||
1681 | foreach (bool l2 in YP.unify(arg1, new ListPair(HeadArg, RestHeadArgs))) | ||
1682 | { | ||
1683 | foreach (bool l3 in YP.unify(arg2, new ListPair(x3, RestCompiledHeadArgs))) | ||
1684 | { | ||
1685 | foreach (bool l4 in getVariableArgIndex1(HeadArg, AllHeadArgs, _ArgIndex1)) | ||
1686 | { | ||
1687 | foreach (bool l5 in YP.unify(NextIndex, YP.add(Index, 1))) | ||
1688 | { | ||
1689 | foreach (bool l6 in compileArgUnifications(RestHeadArgs, RestCompiledHeadArgs, NextIndex, AllHeadArgs, BodyCode, ArgUnifications)) | ||
1690 | { | ||
1691 | yield return true; | ||
1692 | yield break; | ||
1693 | } | ||
1694 | } | ||
1695 | } | ||
1696 | } | ||
1697 | } | ||
1698 | } | ||
1699 | { | ||
1700 | object Index = arg3; | ||
1701 | object AllHeadArgs = arg4; | ||
1702 | object BodyCode = arg5; | ||
1703 | Variable _HeadArg = new Variable(); | ||
1704 | Variable RestHeadArgs = new Variable(); | ||
1705 | Variable CompiledHeadArg = new Variable(); | ||
1706 | Variable RestCompiledHeadArgs = new Variable(); | ||
1707 | Variable ArgName = new Variable(); | ||
1708 | Variable RestArgUnifications = new Variable(); | ||
1709 | Variable NumberCodes = new Variable(); | ||
1710 | Variable NumberAtom = new Variable(); | ||
1711 | Variable NextIndex = new Variable(); | ||
1712 | foreach (bool l2 in YP.unify(arg1, new ListPair(_HeadArg, RestHeadArgs))) | ||
1713 | { | ||
1714 | foreach (bool l3 in YP.unify(arg2, new ListPair(CompiledHeadArg, RestCompiledHeadArgs))) | ||
1715 | { | ||
1716 | foreach (bool l4 in YP.unify(arg6, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.unify"), new ListPair(new Functor1("var", ArgName), new ListPair(CompiledHeadArg, Atom.NIL))), RestArgUnifications), Atom.NIL))) | ||
1717 | { | ||
1718 | foreach (bool l5 in YP.number_codes(Index, NumberCodes)) | ||
1719 | { | ||
1720 | foreach (bool l6 in YP.atom_codes(NumberAtom, NumberCodes)) | ||
1721 | { | ||
1722 | foreach (bool l7 in YP.atom_concat(Atom.a("arg"), NumberAtom, ArgName)) | ||
1723 | { | ||
1724 | foreach (bool l8 in YP.unify(NextIndex, YP.add(Index, 1))) | ||
1725 | { | ||
1726 | foreach (bool l9 in compileArgUnifications(RestHeadArgs, RestCompiledHeadArgs, NextIndex, AllHeadArgs, BodyCode, RestArgUnifications)) | ||
1727 | { | ||
1728 | yield return true; | ||
1729 | yield break; | ||
1730 | } | ||
1731 | } | ||
1732 | } | ||
1733 | } | ||
1734 | } | ||
1735 | } | ||
1736 | } | ||
1737 | } | ||
1738 | } | ||
1739 | } | ||
1740 | |||
1741 | public static IEnumerable<bool> compileDeclarations(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6) | ||
1742 | { | ||
1743 | { | ||
1744 | object _HeadArgs = arg2; | ||
1745 | Variable ArgAssignmentsIn = new Variable(); | ||
1746 | Variable DeclarationsIn = new Variable(); | ||
1747 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
1748 | { | ||
1749 | foreach (bool l3 in YP.unify(arg3, ArgAssignmentsIn)) | ||
1750 | { | ||
1751 | foreach (bool l4 in YP.unify(arg4, ArgAssignmentsIn)) | ||
1752 | { | ||
1753 | foreach (bool l5 in YP.unify(arg5, DeclarationsIn)) | ||
1754 | { | ||
1755 | foreach (bool l6 in YP.unify(arg6, DeclarationsIn)) | ||
1756 | { | ||
1757 | yield return true; | ||
1758 | yield break; | ||
1759 | } | ||
1760 | } | ||
1761 | } | ||
1762 | } | ||
1763 | } | ||
1764 | } | ||
1765 | { | ||
1766 | object HeadArgs = arg2; | ||
1767 | object ArgAssignmentsIn = arg3; | ||
1768 | object ArgAssignmentsOut = arg4; | ||
1769 | object DeclarationsIn = arg5; | ||
1770 | object DeclarationsOut = arg6; | ||
1771 | Variable VariableName = new Variable(); | ||
1772 | Variable Var = new Variable(); | ||
1773 | Variable RestVariableNames = new Variable(); | ||
1774 | Variable ArgIndex1 = new Variable(); | ||
1775 | Variable NumberCodes = new Variable(); | ||
1776 | Variable NumberAtom = new Variable(); | ||
1777 | Variable ArgName = new Variable(); | ||
1778 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("=", VariableName, Var), RestVariableNames))) | ||
1779 | { | ||
1780 | foreach (bool l3 in getVariableArgIndex1(Var, HeadArgs, ArgIndex1)) | ||
1781 | { | ||
1782 | foreach (bool l4 in YP.number_codes(ArgIndex1, NumberCodes)) | ||
1783 | { | ||
1784 | foreach (bool l5 in YP.atom_codes(NumberAtom, NumberCodes)) | ||
1785 | { | ||
1786 | foreach (bool l6 in YP.atom_concat(Atom.a("arg"), NumberAtom, ArgName)) | ||
1787 | { | ||
1788 | foreach (bool l7 in compileDeclarations(RestVariableNames, HeadArgs, new ListPair(new Functor2("f", VariableName, ArgName), ArgAssignmentsIn), ArgAssignmentsOut, DeclarationsIn, DeclarationsOut)) | ||
1789 | { | ||
1790 | yield return true; | ||
1791 | yield break; | ||
1792 | } | ||
1793 | } | ||
1794 | } | ||
1795 | } | ||
1796 | } | ||
1797 | } | ||
1798 | } | ||
1799 | { | ||
1800 | object HeadArgs = arg2; | ||
1801 | object ArgAssignmentsIn = arg3; | ||
1802 | object ArgAssignmentsOut = arg4; | ||
1803 | object DeclarationsIn = arg5; | ||
1804 | Variable VariableName = new Variable(); | ||
1805 | Variable _Var = new Variable(); | ||
1806 | Variable RestVariableNames = new Variable(); | ||
1807 | Variable DeclarationsOut = new Variable(); | ||
1808 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("=", VariableName, _Var), RestVariableNames))) | ||
1809 | { | ||
1810 | foreach (bool l3 in YP.unify(arg6, new ListPair(new Functor3("declare", Atom.a("Variable"), VariableName, new Functor2("new", Atom.a("Variable"), Atom.NIL)), DeclarationsOut))) | ||
1811 | { | ||
1812 | foreach (bool l4 in compileDeclarations(RestVariableNames, HeadArgs, ArgAssignmentsIn, ArgAssignmentsOut, DeclarationsIn, DeclarationsOut)) | ||
1813 | { | ||
1814 | yield return true; | ||
1815 | yield break; | ||
1816 | } | ||
1817 | } | ||
1818 | } | ||
1819 | } | ||
1820 | } | ||
1821 | |||
1822 | public static IEnumerable<bool> getVariableArgIndex1(object Var, object arg2, object arg3) | ||
1823 | { | ||
1824 | { | ||
1825 | Variable FirstHeadArgs = new Variable(); | ||
1826 | Variable RestHeadArgs = new Variable(); | ||
1827 | Variable x4 = new Variable(); | ||
1828 | foreach (bool l2 in YP.unify(arg2, new ListPair(FirstHeadArgs, RestHeadArgs))) | ||
1829 | { | ||
1830 | foreach (bool l3 in YP.unify(arg3, 1)) | ||
1831 | { | ||
1832 | if (sameVariable(Var, FirstHeadArgs)) | ||
1833 | { | ||
1834 | foreach (bool l5 in getVariableArgIndex1(Var, RestHeadArgs, x4)) | ||
1835 | { | ||
1836 | goto cutIf1; | ||
1837 | } | ||
1838 | yield return false; | ||
1839 | cutIf1: | ||
1840 | yield break; | ||
1841 | } | ||
1842 | } | ||
1843 | } | ||
1844 | } | ||
1845 | { | ||
1846 | object Index = arg3; | ||
1847 | Variable x2 = new Variable(); | ||
1848 | Variable RestHeadArgs = new Variable(); | ||
1849 | Variable RestIndex = new Variable(); | ||
1850 | foreach (bool l2 in YP.unify(arg2, new ListPair(x2, RestHeadArgs))) | ||
1851 | { | ||
1852 | foreach (bool l3 in getVariableArgIndex1(Var, RestHeadArgs, RestIndex)) | ||
1853 | { | ||
1854 | foreach (bool l4 in YP.unify(Index, YP.add(1, RestIndex))) | ||
1855 | { | ||
1856 | yield return true; | ||
1857 | yield break; | ||
1858 | } | ||
1859 | } | ||
1860 | } | ||
1861 | } | ||
1862 | } | ||
1863 | |||
1864 | public static IEnumerable<bool> compileRuleBody(object arg1, object arg2, object arg3) | ||
1865 | { | ||
1866 | { | ||
1867 | object A = arg1; | ||
1868 | object State = arg2; | ||
1869 | object PseudoCode = arg3; | ||
1870 | if (YP.var(A)) | ||
1871 | { | ||
1872 | foreach (bool l3 in compileRuleBody(new Functor2(",", new Functor1("call", A), Atom.a("true")), State, PseudoCode)) | ||
1873 | { | ||
1874 | yield return true; | ||
1875 | yield break; | ||
1876 | } | ||
1877 | } | ||
1878 | } | ||
1879 | { | ||
1880 | object State = arg2; | ||
1881 | object PseudoCode = arg3; | ||
1882 | Variable A = new Variable(); | ||
1883 | Variable B = new Variable(); | ||
1884 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", A, B))) | ||
1885 | { | ||
1886 | if (YP.var(A)) | ||
1887 | { | ||
1888 | foreach (bool l4 in compileRuleBody(new Functor2(",", new Functor1("call", A), B), State, PseudoCode)) | ||
1889 | { | ||
1890 | yield return true; | ||
1891 | yield break; | ||
1892 | } | ||
1893 | } | ||
1894 | } | ||
1895 | } | ||
1896 | { | ||
1897 | object State = arg2; | ||
1898 | object PseudoCode = arg3; | ||
1899 | Variable A = new Variable(); | ||
1900 | Variable B = new Variable(); | ||
1901 | Variable ACode = new Variable(); | ||
1902 | Variable BCode = new Variable(); | ||
1903 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", A, B))) | ||
1904 | { | ||
1905 | foreach (bool l3 in compileFunctorCall(A, State, ACode)) | ||
1906 | { | ||
1907 | if (CompilerState.isDetNoneOut(State, A)) | ||
1908 | { | ||
1909 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
1910 | { | ||
1911 | foreach (bool l6 in YP.unify(PseudoCode, new ListPair(ACode, BCode))) | ||
1912 | { | ||
1913 | yield return true; | ||
1914 | yield break; | ||
1915 | } | ||
1916 | } | ||
1917 | } | ||
1918 | if (CompilerState.isSemidetNoneOut(State, A)) | ||
1919 | { | ||
1920 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
1921 | { | ||
1922 | foreach (bool l6 in YP.unify(PseudoCode, new ListPair(new Functor2("if", ACode, BCode), Atom.NIL))) | ||
1923 | { | ||
1924 | yield return true; | ||
1925 | yield break; | ||
1926 | } | ||
1927 | } | ||
1928 | } | ||
1929 | foreach (bool l4 in compileRuleBody(B, State, BCode)) | ||
1930 | { | ||
1931 | foreach (bool l5 in YP.unify(PseudoCode, new ListPair(new Functor2("foreach", ACode, BCode), Atom.NIL))) | ||
1932 | { | ||
1933 | yield return true; | ||
1934 | yield break; | ||
1935 | } | ||
1936 | } | ||
1937 | } | ||
1938 | } | ||
1939 | } | ||
1940 | { | ||
1941 | object State = arg2; | ||
1942 | object PseudoCode = arg3; | ||
1943 | Variable A = new Variable(); | ||
1944 | Variable T = new Variable(); | ||
1945 | Variable B = new Variable(); | ||
1946 | Variable C = new Variable(); | ||
1947 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor2(";", new Functor2("->", A, T), B), C))) | ||
1948 | { | ||
1949 | foreach (bool l3 in compileRuleBody(new Functor2(";", new Functor2("->", A, new Functor2(",", T, C)), new Functor2(",", B, C)), State, PseudoCode)) | ||
1950 | { | ||
1951 | yield return true; | ||
1952 | yield break; | ||
1953 | } | ||
1954 | } | ||
1955 | } | ||
1956 | { | ||
1957 | object State = arg2; | ||
1958 | object PseudoCode = arg3; | ||
1959 | Variable A = new Variable(); | ||
1960 | Variable B = new Variable(); | ||
1961 | Variable C = new Variable(); | ||
1962 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor2(";", A, B), C))) | ||
1963 | { | ||
1964 | foreach (bool l3 in compileRuleBody(new Functor2(";", new Functor2(",", A, C), new Functor2(",", B, C)), State, PseudoCode)) | ||
1965 | { | ||
1966 | yield return true; | ||
1967 | yield break; | ||
1968 | } | ||
1969 | } | ||
1970 | } | ||
1971 | { | ||
1972 | object State = arg2; | ||
1973 | Variable A = new Variable(); | ||
1974 | Variable B = new Variable(); | ||
1975 | Variable ACode = new Variable(); | ||
1976 | Variable BCode = new Variable(); | ||
1977 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("\\+", A), B))) | ||
1978 | { | ||
1979 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("if", new Functor1("not", ACode), BCode), Atom.NIL))) | ||
1980 | { | ||
1981 | if (CompilerState.isSemidetNoneOut(State, A)) | ||
1982 | { | ||
1983 | foreach (bool l5 in compileFunctorCall(A, State, ACode)) | ||
1984 | { | ||
1985 | foreach (bool l6 in compileRuleBody(B, State, BCode)) | ||
1986 | { | ||
1987 | yield return true; | ||
1988 | yield break; | ||
1989 | } | ||
1990 | } | ||
1991 | } | ||
1992 | } | ||
1993 | } | ||
1994 | } | ||
1995 | { | ||
1996 | object State = arg2; | ||
1997 | object PseudoCode = arg3; | ||
1998 | Variable A = new Variable(); | ||
1999 | Variable B = new Variable(); | ||
2000 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("\\+", A), B))) | ||
2001 | { | ||
2002 | foreach (bool l3 in compileRuleBody(new Functor2(",", new Functor2(";", new Functor2("->", A, Atom.a("fail")), Atom.a("true")), B), State, PseudoCode)) | ||
2003 | { | ||
2004 | yield return true; | ||
2005 | yield break; | ||
2006 | } | ||
2007 | } | ||
2008 | } | ||
2009 | { | ||
2010 | object State = arg2; | ||
2011 | object PseudoCode = arg3; | ||
2012 | Variable A = new Variable(); | ||
2013 | Variable B = new Variable(); | ||
2014 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("once", A), B))) | ||
2015 | { | ||
2016 | foreach (bool l3 in compileRuleBody(new Functor2(",", new Functor2(";", new Functor2("->", A, Atom.a("true")), Atom.a("fail")), B), State, PseudoCode)) | ||
2017 | { | ||
2018 | yield return true; | ||
2019 | yield break; | ||
2020 | } | ||
2021 | } | ||
2022 | } | ||
2023 | { | ||
2024 | object State = arg2; | ||
2025 | object PseudoCode = arg3; | ||
2026 | Variable A = new Variable(); | ||
2027 | Variable T = new Variable(); | ||
2028 | Variable B = new Variable(); | ||
2029 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor2("->", A, T), B))) | ||
2030 | { | ||
2031 | foreach (bool l3 in compileRuleBody(new Functor2(",", new Functor2(";", new Functor2("->", A, T), Atom.a("fail")), B), State, PseudoCode)) | ||
2032 | { | ||
2033 | yield return true; | ||
2034 | yield break; | ||
2035 | } | ||
2036 | } | ||
2037 | } | ||
2038 | { | ||
2039 | object State = arg2; | ||
2040 | object PseudoCode = arg3; | ||
2041 | Variable A = new Variable(); | ||
2042 | Variable B = new Variable(); | ||
2043 | Variable C = new Variable(); | ||
2044 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor2("\\=", A, B), C))) | ||
2045 | { | ||
2046 | foreach (bool l3 in compileRuleBody(new Functor2(",", new Functor1("\\+", new Functor2("=", A, B)), C), State, PseudoCode)) | ||
2047 | { | ||
2048 | yield return true; | ||
2049 | yield break; | ||
2050 | } | ||
2051 | } | ||
2052 | } | ||
2053 | { | ||
2054 | object State = arg2; | ||
2055 | object PseudoCode = arg3; | ||
2056 | Variable A = new Variable(); | ||
2057 | Variable ACode = new Variable(); | ||
2058 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", Atom.a("!"), A))) | ||
2059 | { | ||
2060 | foreach (bool l3 in compileRuleBody(A, State, ACode)) | ||
2061 | { | ||
2062 | foreach (bool l4 in append(ACode, new ListPair(Atom.a("yieldbreak"), Atom.NIL), PseudoCode)) | ||
2063 | { | ||
2064 | yield return true; | ||
2065 | yield break; | ||
2066 | } | ||
2067 | } | ||
2068 | } | ||
2069 | } | ||
2070 | { | ||
2071 | object State = arg2; | ||
2072 | object PseudoCode = arg3; | ||
2073 | Variable Name = new Variable(); | ||
2074 | Variable A = new Variable(); | ||
2075 | Variable ACode = new Variable(); | ||
2076 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("$CUTIF", Name), A))) | ||
2077 | { | ||
2078 | foreach (bool l3 in compileRuleBody(A, State, ACode)) | ||
2079 | { | ||
2080 | foreach (bool l4 in append(ACode, new ListPair(new Functor1("breakBlock", Name), Atom.NIL), PseudoCode)) | ||
2081 | { | ||
2082 | yield return true; | ||
2083 | yield break; | ||
2084 | } | ||
2085 | } | ||
2086 | } | ||
2087 | } | ||
2088 | { | ||
2089 | object _State = arg2; | ||
2090 | Variable x1 = new Variable(); | ||
2091 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", Atom.a("fail"), x1))) | ||
2092 | { | ||
2093 | foreach (bool l3 in YP.unify(arg3, Atom.NIL)) | ||
2094 | { | ||
2095 | yield return true; | ||
2096 | yield break; | ||
2097 | } | ||
2098 | } | ||
2099 | } | ||
2100 | { | ||
2101 | object State = arg2; | ||
2102 | object PseudoCode = arg3; | ||
2103 | Variable A = new Variable(); | ||
2104 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", Atom.a("true"), A))) | ||
2105 | { | ||
2106 | foreach (bool l3 in compileRuleBody(A, State, PseudoCode)) | ||
2107 | { | ||
2108 | yield return true; | ||
2109 | yield break; | ||
2110 | } | ||
2111 | } | ||
2112 | } | ||
2113 | { | ||
2114 | object State = arg2; | ||
2115 | Variable A = new Variable(); | ||
2116 | Variable Term = new Variable(); | ||
2117 | Variable B = new Variable(); | ||
2118 | Variable ACode = new Variable(); | ||
2119 | Variable TermCode = new Variable(); | ||
2120 | Variable BCode = new Variable(); | ||
2121 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor2("is", A, Term), B))) | ||
2122 | { | ||
2123 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.unify"), new ListPair(ACode, new ListPair(TermCode, Atom.NIL))), BCode), Atom.NIL))) | ||
2124 | { | ||
2125 | foreach (bool l4 in compileTerm(A, State, ACode)) | ||
2126 | { | ||
2127 | foreach (bool l5 in compileExpression(Term, State, TermCode)) | ||
2128 | { | ||
2129 | foreach (bool l6 in compileRuleBody(B, State, BCode)) | ||
2130 | { | ||
2131 | yield return true; | ||
2132 | yield break; | ||
2133 | } | ||
2134 | } | ||
2135 | } | ||
2136 | } | ||
2137 | } | ||
2138 | } | ||
2139 | { | ||
2140 | object State = arg2; | ||
2141 | Variable ACode = new Variable(); | ||
2142 | Variable B = new Variable(); | ||
2143 | Variable BCode = new Variable(); | ||
2144 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("$DET_NONE_OUT", ACode), B))) | ||
2145 | { | ||
2146 | foreach (bool l3 in YP.unify(arg3, new ListPair(ACode, BCode))) | ||
2147 | { | ||
2148 | foreach (bool l4 in compileRuleBody(B, State, BCode)) | ||
2149 | { | ||
2150 | yield return true; | ||
2151 | yield break; | ||
2152 | } | ||
2153 | } | ||
2154 | } | ||
2155 | } | ||
2156 | { | ||
2157 | object State = arg2; | ||
2158 | Variable A = new Variable(); | ||
2159 | Variable B = new Variable(); | ||
2160 | Variable FunctionName = new Variable(); | ||
2161 | Variable X1Code = new Variable(); | ||
2162 | Variable X2Code = new Variable(); | ||
2163 | Variable BCode = new Variable(); | ||
2164 | Variable Name = new Variable(); | ||
2165 | Variable X1 = new Variable(); | ||
2166 | Variable X2 = new Variable(); | ||
2167 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", A, B))) | ||
2168 | { | ||
2169 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("if", new Functor2("call", FunctionName, new ListPair(X1Code, new ListPair(X2Code, Atom.NIL))), BCode), Atom.NIL))) | ||
2170 | { | ||
2171 | foreach (bool l4 in YP.univ(A, ListPair.make(new object[] { Name, X1, X2 }))) | ||
2172 | { | ||
2173 | foreach (bool l5 in binaryExpressionConditional(Name, FunctionName)) | ||
2174 | { | ||
2175 | foreach (bool l6 in compileExpression(X1, State, X1Code)) | ||
2176 | { | ||
2177 | foreach (bool l7 in compileExpression(X2, State, X2Code)) | ||
2178 | { | ||
2179 | foreach (bool l8 in compileRuleBody(B, State, BCode)) | ||
2180 | { | ||
2181 | yield return true; | ||
2182 | yield break; | ||
2183 | } | ||
2184 | } | ||
2185 | } | ||
2186 | } | ||
2187 | } | ||
2188 | } | ||
2189 | } | ||
2190 | } | ||
2191 | { | ||
2192 | object State = arg2; | ||
2193 | object PseudoCode = arg3; | ||
2194 | Variable Template = new Variable(); | ||
2195 | Variable Goal = new Variable(); | ||
2196 | Variable Bag = new Variable(); | ||
2197 | Variable B = new Variable(); | ||
2198 | Variable TemplateCode = new Variable(); | ||
2199 | Variable FindallAnswers = new Variable(); | ||
2200 | Variable GoalAndAddCode = new Variable(); | ||
2201 | Variable BagCode = new Variable(); | ||
2202 | Variable BCode = new Variable(); | ||
2203 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor3("findall", Template, Goal, Bag), B))) | ||
2204 | { | ||
2205 | foreach (bool l3 in compileTerm(Template, State, TemplateCode)) | ||
2206 | { | ||
2207 | foreach (bool l4 in CompilerState.gensym(State, Atom.a("findallAnswers"), FindallAnswers)) | ||
2208 | { | ||
2209 | foreach (bool l5 in compileRuleBody(new Functor2(",", Goal, new Functor2(",", new Functor1("$DET_NONE_OUT", new Functor3("callMember", new Functor1("var", FindallAnswers), Atom.a("add"), Atom.NIL)), Atom.a("fail"))), State, GoalAndAddCode)) | ||
2210 | { | ||
2211 | foreach (bool l6 in compileTerm(Bag, State, BagCode)) | ||
2212 | { | ||
2213 | foreach (bool l7 in compileRuleBody(B, State, BCode)) | ||
2214 | { | ||
2215 | foreach (bool l8 in append(new ListPair(new Functor3("declare", Atom.a("FindallAnswers"), FindallAnswers, new Functor2("new", Atom.a("FindallAnswers"), new ListPair(TemplateCode, Atom.NIL))), GoalAndAddCode), new ListPair(new Functor2("foreach", new Functor3("callMember", new Functor1("var", FindallAnswers), Atom.a("result"), new ListPair(BagCode, Atom.NIL)), BCode), Atom.NIL), PseudoCode)) | ||
2216 | { | ||
2217 | yield return true; | ||
2218 | yield break; | ||
2219 | } | ||
2220 | } | ||
2221 | } | ||
2222 | } | ||
2223 | } | ||
2224 | } | ||
2225 | } | ||
2226 | } | ||
2227 | { | ||
2228 | object State = arg2; | ||
2229 | object PseudoCode = arg3; | ||
2230 | Variable Template = new Variable(); | ||
2231 | Variable Goal = new Variable(); | ||
2232 | Variable Bag = new Variable(); | ||
2233 | Variable B = new Variable(); | ||
2234 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor3("bagof", Template, Goal, Bag), B))) | ||
2235 | { | ||
2236 | foreach (bool l3 in compileBagof(Atom.a("result"), Template, Goal, Bag, B, State, PseudoCode)) | ||
2237 | { | ||
2238 | yield return true; | ||
2239 | yield break; | ||
2240 | } | ||
2241 | } | ||
2242 | } | ||
2243 | { | ||
2244 | object State = arg2; | ||
2245 | object PseudoCode = arg3; | ||
2246 | Variable Template = new Variable(); | ||
2247 | Variable Goal = new Variable(); | ||
2248 | Variable Bag = new Variable(); | ||
2249 | Variable B = new Variable(); | ||
2250 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor3("setof", Template, Goal, Bag), B))) | ||
2251 | { | ||
2252 | foreach (bool l3 in compileBagof(Atom.a("resultSet"), Template, Goal, Bag, B, State, PseudoCode)) | ||
2253 | { | ||
2254 | yield return true; | ||
2255 | yield break; | ||
2256 | } | ||
2257 | } | ||
2258 | } | ||
2259 | { | ||
2260 | object State = arg2; | ||
2261 | Variable A = new Variable(); | ||
2262 | Variable B = new Variable(); | ||
2263 | Variable ATermCode = new Variable(); | ||
2264 | Variable BCode = new Variable(); | ||
2265 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("call", A), B))) | ||
2266 | { | ||
2267 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.getIterator"), new ListPair(ATermCode, new ListPair(new Functor2("call", Atom.a("getDeclaringClass"), Atom.NIL), Atom.NIL))), BCode), Atom.NIL))) | ||
2268 | { | ||
2269 | foreach (bool l4 in compileTerm(A, State, ATermCode)) | ||
2270 | { | ||
2271 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
2272 | { | ||
2273 | yield return true; | ||
2274 | yield break; | ||
2275 | } | ||
2276 | } | ||
2277 | } | ||
2278 | } | ||
2279 | } | ||
2280 | { | ||
2281 | object State = arg2; | ||
2282 | Variable A = new Variable(); | ||
2283 | Variable B = new Variable(); | ||
2284 | Variable ATermCode = new Variable(); | ||
2285 | Variable BCode = new Variable(); | ||
2286 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("current_predicate", A), B))) | ||
2287 | { | ||
2288 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.current_predicate"), new ListPair(ATermCode, new ListPair(new Functor2("call", Atom.a("getDeclaringClass"), Atom.NIL), Atom.NIL))), BCode), Atom.NIL))) | ||
2289 | { | ||
2290 | foreach (bool l4 in compileTerm(A, State, ATermCode)) | ||
2291 | { | ||
2292 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
2293 | { | ||
2294 | yield return true; | ||
2295 | yield break; | ||
2296 | } | ||
2297 | } | ||
2298 | } | ||
2299 | } | ||
2300 | } | ||
2301 | { | ||
2302 | object State = arg2; | ||
2303 | Variable A = new Variable(); | ||
2304 | Variable B = new Variable(); | ||
2305 | Variable ATermCode = new Variable(); | ||
2306 | Variable BCode = new Variable(); | ||
2307 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("asserta", A), B))) | ||
2308 | { | ||
2309 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("call", Atom.a("YP.asserta"), new ListPair(ATermCode, new ListPair(new Functor2("call", Atom.a("getDeclaringClass"), Atom.NIL), Atom.NIL))), BCode))) | ||
2310 | { | ||
2311 | foreach (bool l4 in compileTerm(A, State, ATermCode)) | ||
2312 | { | ||
2313 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
2314 | { | ||
2315 | yield return true; | ||
2316 | yield break; | ||
2317 | } | ||
2318 | } | ||
2319 | } | ||
2320 | } | ||
2321 | } | ||
2322 | { | ||
2323 | object State = arg2; | ||
2324 | Variable A = new Variable(); | ||
2325 | Variable B = new Variable(); | ||
2326 | Variable ATermCode = new Variable(); | ||
2327 | Variable BCode = new Variable(); | ||
2328 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("assertz", A), B))) | ||
2329 | { | ||
2330 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("call", Atom.a("YP.assertz"), new ListPair(ATermCode, new ListPair(new Functor2("call", Atom.a("getDeclaringClass"), Atom.NIL), Atom.NIL))), BCode))) | ||
2331 | { | ||
2332 | foreach (bool l4 in compileTerm(A, State, ATermCode)) | ||
2333 | { | ||
2334 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
2335 | { | ||
2336 | yield return true; | ||
2337 | yield break; | ||
2338 | } | ||
2339 | } | ||
2340 | } | ||
2341 | } | ||
2342 | } | ||
2343 | { | ||
2344 | object State = arg2; | ||
2345 | object PseudoCode = arg3; | ||
2346 | Variable A = new Variable(); | ||
2347 | Variable B = new Variable(); | ||
2348 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("assert", A), B))) | ||
2349 | { | ||
2350 | foreach (bool l3 in compileRuleBody(new Functor2(",", new Functor1("assertz", A), B), State, PseudoCode)) | ||
2351 | { | ||
2352 | yield return true; | ||
2353 | yield break; | ||
2354 | } | ||
2355 | } | ||
2356 | } | ||
2357 | { | ||
2358 | object State = arg2; | ||
2359 | Variable Goal = new Variable(); | ||
2360 | Variable Catcher = new Variable(); | ||
2361 | Variable Handler = new Variable(); | ||
2362 | Variable B = new Variable(); | ||
2363 | Variable CatchGoal = new Variable(); | ||
2364 | Variable GoalTermCode = new Variable(); | ||
2365 | Variable BCode = new Variable(); | ||
2366 | Variable CatcherTermCode = new Variable(); | ||
2367 | Variable HandlerAndBCode = new Variable(); | ||
2368 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor3("catch", Goal, Catcher, Handler), B))) | ||
2369 | { | ||
2370 | foreach (bool l3 in YP.unify(arg3, ListPair.make(new object[] { new Functor3("declare", Atom.a("YP.Catch"), CatchGoal, new Functor2("new", Atom.a("YP.Catch"), new ListPair(GoalTermCode, new ListPair(new Functor2("call", Atom.a("getDeclaringClass"), Atom.NIL), Atom.NIL)))), new Functor2("foreach", new Functor1("var", CatchGoal), BCode), new Functor2("foreach", new Functor3("callMember", new Functor1("var", CatchGoal), Atom.a("unifyExceptionOrThrow"), new ListPair(CatcherTermCode, Atom.NIL)), HandlerAndBCode) }))) | ||
2371 | { | ||
2372 | foreach (bool l4 in CompilerState.gensym(State, Atom.a("catchGoal"), CatchGoal)) | ||
2373 | { | ||
2374 | foreach (bool l5 in compileTerm(Goal, State, GoalTermCode)) | ||
2375 | { | ||
2376 | foreach (bool l6 in compileTerm(Catcher, State, CatcherTermCode)) | ||
2377 | { | ||
2378 | foreach (bool l7 in compileRuleBody(B, State, BCode)) | ||
2379 | { | ||
2380 | foreach (bool l8 in compileRuleBody(new Functor2(",", Handler, B), State, HandlerAndBCode)) | ||
2381 | { | ||
2382 | yield return true; | ||
2383 | yield break; | ||
2384 | } | ||
2385 | } | ||
2386 | } | ||
2387 | } | ||
2388 | } | ||
2389 | } | ||
2390 | } | ||
2391 | } | ||
2392 | { | ||
2393 | object State = arg2; | ||
2394 | object PseudoCode = arg3; | ||
2395 | Variable A = new Variable(); | ||
2396 | Variable B = new Variable(); | ||
2397 | Variable C = new Variable(); | ||
2398 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor2(",", A, B), C))) | ||
2399 | { | ||
2400 | foreach (bool l3 in compileRuleBody(new Functor2(",", A, new Functor2(",", B, C)), State, PseudoCode)) | ||
2401 | { | ||
2402 | yield return true; | ||
2403 | yield break; | ||
2404 | } | ||
2405 | } | ||
2406 | } | ||
2407 | { | ||
2408 | object State = arg2; | ||
2409 | object PseudoCode = arg3; | ||
2410 | Variable A = new Variable(); | ||
2411 | Variable B = new Variable(); | ||
2412 | foreach (bool l2 in YP.unify(arg1, new Functor2(";", A, B))) | ||
2413 | { | ||
2414 | if (YP.var(A)) | ||
2415 | { | ||
2416 | foreach (bool l4 in compileRuleBody(new Functor2(";", new Functor1("call", A), B), State, PseudoCode)) | ||
2417 | { | ||
2418 | yield return true; | ||
2419 | yield break; | ||
2420 | } | ||
2421 | } | ||
2422 | } | ||
2423 | } | ||
2424 | { | ||
2425 | object State = arg2; | ||
2426 | Variable A = new Variable(); | ||
2427 | Variable T = new Variable(); | ||
2428 | Variable B = new Variable(); | ||
2429 | Variable CutIfLabel = new Variable(); | ||
2430 | Variable Code = new Variable(); | ||
2431 | foreach (bool l2 in YP.unify(arg1, new Functor2(";", new Functor2("->", A, T), B))) | ||
2432 | { | ||
2433 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("breakableBlock", CutIfLabel, Code), Atom.NIL))) | ||
2434 | { | ||
2435 | foreach (bool l4 in CompilerState.gensym(State, Atom.a("cutIf"), CutIfLabel)) | ||
2436 | { | ||
2437 | foreach (bool l5 in compileRuleBody(new Functor2(";", new Functor2(",", A, new Functor2(",", new Functor1("$CUTIF", CutIfLabel), T)), B), State, Code)) | ||
2438 | { | ||
2439 | yield return true; | ||
2440 | yield break; | ||
2441 | } | ||
2442 | } | ||
2443 | } | ||
2444 | } | ||
2445 | } | ||
2446 | { | ||
2447 | object State = arg2; | ||
2448 | object PseudoCode = arg3; | ||
2449 | Variable _B = new Variable(); | ||
2450 | foreach (bool l2 in YP.unify(arg1, new Functor2(";", Atom.a("!"), _B))) | ||
2451 | { | ||
2452 | foreach (bool l3 in compileRuleBody(Atom.a("!"), State, PseudoCode)) | ||
2453 | { | ||
2454 | yield return true; | ||
2455 | yield break; | ||
2456 | } | ||
2457 | } | ||
2458 | } | ||
2459 | { | ||
2460 | object State = arg2; | ||
2461 | object PseudoCode = arg3; | ||
2462 | Variable A = new Variable(); | ||
2463 | Variable B = new Variable(); | ||
2464 | Variable ACode = new Variable(); | ||
2465 | Variable BCode = new Variable(); | ||
2466 | foreach (bool l2 in YP.unify(arg1, new Functor2(";", A, B))) | ||
2467 | { | ||
2468 | foreach (bool l3 in compileRuleBody(A, State, ACode)) | ||
2469 | { | ||
2470 | foreach (bool l4 in compileRuleBody(B, State, BCode)) | ||
2471 | { | ||
2472 | foreach (bool l5 in append(ACode, BCode, PseudoCode)) | ||
2473 | { | ||
2474 | yield return true; | ||
2475 | yield break; | ||
2476 | } | ||
2477 | } | ||
2478 | } | ||
2479 | } | ||
2480 | } | ||
2481 | { | ||
2482 | object State = arg2; | ||
2483 | foreach (bool l2 in YP.unify(arg1, Atom.a("!"))) | ||
2484 | { | ||
2485 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("return"), Atom.NIL))) | ||
2486 | { | ||
2487 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
2488 | { | ||
2489 | yield return true; | ||
2490 | yield break; | ||
2491 | } | ||
2492 | } | ||
2493 | } | ||
2494 | } | ||
2495 | { | ||
2496 | object State = arg2; | ||
2497 | foreach (bool l2 in YP.unify(arg1, Atom.a("!"))) | ||
2498 | { | ||
2499 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("returntrue"), Atom.NIL))) | ||
2500 | { | ||
2501 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
2502 | { | ||
2503 | yield return true; | ||
2504 | yield break; | ||
2505 | } | ||
2506 | } | ||
2507 | } | ||
2508 | } | ||
2509 | { | ||
2510 | object State = arg2; | ||
2511 | foreach (bool l2 in YP.unify(arg1, Atom.a("!"))) | ||
2512 | { | ||
2513 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("yieldtrue"), new ListPair(Atom.a("yieldbreak"), Atom.NIL)))) | ||
2514 | { | ||
2515 | CompilerState.setCodeUsesYield(State); | ||
2516 | yield return true; | ||
2517 | yield break; | ||
2518 | } | ||
2519 | } | ||
2520 | } | ||
2521 | { | ||
2522 | object _State = arg2; | ||
2523 | Variable Name = new Variable(); | ||
2524 | foreach (bool l2 in YP.unify(arg1, new Functor1("$CUTIF", Name))) | ||
2525 | { | ||
2526 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor1("breakBlock", Name), Atom.NIL))) | ||
2527 | { | ||
2528 | yield return true; | ||
2529 | yield break; | ||
2530 | } | ||
2531 | } | ||
2532 | } | ||
2533 | { | ||
2534 | object State = arg2; | ||
2535 | foreach (bool l2 in YP.unify(arg1, Atom.a("true"))) | ||
2536 | { | ||
2537 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("return"), Atom.NIL))) | ||
2538 | { | ||
2539 | if (CompilerState.determinismEquals(State, Atom.a("detNoneOut"))) | ||
2540 | { | ||
2541 | yield return true; | ||
2542 | yield break; | ||
2543 | } | ||
2544 | } | ||
2545 | } | ||
2546 | } | ||
2547 | { | ||
2548 | object State = arg2; | ||
2549 | foreach (bool l2 in YP.unify(arg1, Atom.a("true"))) | ||
2550 | { | ||
2551 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("returntrue"), Atom.NIL))) | ||
2552 | { | ||
2553 | if (CompilerState.determinismEquals(State, Atom.a("semidetNoneOut"))) | ||
2554 | { | ||
2555 | yield return true; | ||
2556 | yield break; | ||
2557 | } | ||
2558 | } | ||
2559 | } | ||
2560 | } | ||
2561 | { | ||
2562 | object State = arg2; | ||
2563 | foreach (bool l2 in YP.unify(arg1, Atom.a("true"))) | ||
2564 | { | ||
2565 | foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a("yieldfalse"), Atom.NIL))) | ||
2566 | { | ||
2567 | CompilerState.setCodeUsesYield(State); | ||
2568 | yield return true; | ||
2569 | yield break; | ||
2570 | } | ||
2571 | } | ||
2572 | } | ||
2573 | { | ||
2574 | object A = arg1; | ||
2575 | object State = arg2; | ||
2576 | object PseudoCode = arg3; | ||
2577 | foreach (bool l2 in compileRuleBody(new Functor2(",", A, Atom.a("true")), State, PseudoCode)) | ||
2578 | { | ||
2579 | yield return true; | ||
2580 | yield break; | ||
2581 | } | ||
2582 | } | ||
2583 | } | ||
2584 | |||
2585 | public static IEnumerable<bool> compileBagof(object ResultMethod, object Template, object Goal, object Bag, object B, object State, object PseudoCode) | ||
2586 | { | ||
2587 | { | ||
2588 | Variable TemplateCode = new Variable(); | ||
2589 | Variable GoalTermCode = new Variable(); | ||
2590 | Variable UnqualifiedGoal = new Variable(); | ||
2591 | Variable BagofAnswers = new Variable(); | ||
2592 | Variable GoalAndAddCode = new Variable(); | ||
2593 | Variable BagCode = new Variable(); | ||
2594 | Variable BCode = new Variable(); | ||
2595 | foreach (bool l2 in compileTerm(Template, State, TemplateCode)) | ||
2596 | { | ||
2597 | foreach (bool l3 in compileTerm(Goal, State, GoalTermCode)) | ||
2598 | { | ||
2599 | foreach (bool l4 in unqualifiedGoal(Goal, UnqualifiedGoal)) | ||
2600 | { | ||
2601 | foreach (bool l5 in CompilerState.gensym(State, Atom.a("bagofAnswers"), BagofAnswers)) | ||
2602 | { | ||
2603 | foreach (bool l6 in compileRuleBody(new Functor2(",", UnqualifiedGoal, new Functor2(",", new Functor1("$DET_NONE_OUT", new Functor3("callMember", new Functor1("var", BagofAnswers), Atom.a("add"), Atom.NIL)), Atom.a("fail"))), State, GoalAndAddCode)) | ||
2604 | { | ||
2605 | foreach (bool l7 in compileTerm(Bag, State, BagCode)) | ||
2606 | { | ||
2607 | foreach (bool l8 in compileRuleBody(B, State, BCode)) | ||
2608 | { | ||
2609 | foreach (bool l9 in append(new ListPair(new Functor3("declare", Atom.a("BagofAnswers"), BagofAnswers, new Functor2("new", Atom.a("BagofAnswers"), new ListPair(TemplateCode, new ListPair(GoalTermCode, Atom.NIL)))), GoalAndAddCode), new ListPair(new Functor2("foreach", new Functor3("callMember", new Functor1("var", BagofAnswers), ResultMethod, new ListPair(BagCode, Atom.NIL)), BCode), Atom.NIL), PseudoCode)) | ||
2610 | { | ||
2611 | yield return true; | ||
2612 | yield break; | ||
2613 | } | ||
2614 | } | ||
2615 | } | ||
2616 | } | ||
2617 | } | ||
2618 | } | ||
2619 | } | ||
2620 | } | ||
2621 | } | ||
2622 | } | ||
2623 | |||
2624 | public static IEnumerable<bool> unqualifiedGoal(object arg1, object arg2) | ||
2625 | { | ||
2626 | { | ||
2627 | object Goal = arg1; | ||
2628 | foreach (bool l2 in YP.unify(arg2, new Functor1("call", Goal))) | ||
2629 | { | ||
2630 | if (YP.var(Goal)) | ||
2631 | { | ||
2632 | yield return true; | ||
2633 | yield break; | ||
2634 | } | ||
2635 | } | ||
2636 | } | ||
2637 | { | ||
2638 | object UnqualifiedGoal = arg2; | ||
2639 | Variable x1 = new Variable(); | ||
2640 | Variable Goal = new Variable(); | ||
2641 | foreach (bool l2 in YP.unify(arg1, new Functor2("^", x1, Goal))) | ||
2642 | { | ||
2643 | foreach (bool l3 in unqualifiedGoal(Goal, UnqualifiedGoal)) | ||
2644 | { | ||
2645 | yield return true; | ||
2646 | yield break; | ||
2647 | } | ||
2648 | } | ||
2649 | } | ||
2650 | { | ||
2651 | Variable UnqualifiedGoal = new Variable(); | ||
2652 | foreach (bool l2 in YP.unify(arg1, UnqualifiedGoal)) | ||
2653 | { | ||
2654 | foreach (bool l3 in YP.unify(arg2, UnqualifiedGoal)) | ||
2655 | { | ||
2656 | yield return true; | ||
2657 | yield break; | ||
2658 | } | ||
2659 | } | ||
2660 | } | ||
2661 | } | ||
2662 | |||
2663 | public static IEnumerable<bool> binaryExpressionConditional(object arg1, object arg2) | ||
2664 | { | ||
2665 | { | ||
2666 | foreach (bool l2 in YP.unify(arg1, Atom.a("=:="))) | ||
2667 | { | ||
2668 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.equal"))) | ||
2669 | { | ||
2670 | yield return true; | ||
2671 | yield break; | ||
2672 | } | ||
2673 | } | ||
2674 | } | ||
2675 | { | ||
2676 | foreach (bool l2 in YP.unify(arg1, Atom.a("=\\="))) | ||
2677 | { | ||
2678 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.notEqual"))) | ||
2679 | { | ||
2680 | yield return true; | ||
2681 | yield break; | ||
2682 | } | ||
2683 | } | ||
2684 | } | ||
2685 | { | ||
2686 | foreach (bool l2 in YP.unify(arg1, Atom.a(">"))) | ||
2687 | { | ||
2688 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.greaterThan"))) | ||
2689 | { | ||
2690 | yield return true; | ||
2691 | yield break; | ||
2692 | } | ||
2693 | } | ||
2694 | } | ||
2695 | { | ||
2696 | foreach (bool l2 in YP.unify(arg1, Atom.a("<"))) | ||
2697 | { | ||
2698 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.lessThan"))) | ||
2699 | { | ||
2700 | yield return true; | ||
2701 | yield break; | ||
2702 | } | ||
2703 | } | ||
2704 | } | ||
2705 | { | ||
2706 | foreach (bool l2 in YP.unify(arg1, Atom.a(">="))) | ||
2707 | { | ||
2708 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.greaterThanOrEqual"))) | ||
2709 | { | ||
2710 | yield return true; | ||
2711 | yield break; | ||
2712 | } | ||
2713 | } | ||
2714 | } | ||
2715 | { | ||
2716 | foreach (bool l2 in YP.unify(arg1, Atom.a("=<"))) | ||
2717 | { | ||
2718 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.lessThanOrEqual"))) | ||
2719 | { | ||
2720 | yield return true; | ||
2721 | yield break; | ||
2722 | } | ||
2723 | } | ||
2724 | } | ||
2725 | } | ||
2726 | |||
2727 | public static IEnumerable<bool> compileFunctorCall(object Functor_1, object State, object PseudoCode) | ||
2728 | { | ||
2729 | { | ||
2730 | Variable FunctorName = new Variable(); | ||
2731 | Variable FunctorArgs = new Variable(); | ||
2732 | Variable x6 = new Variable(); | ||
2733 | Variable Arity = new Variable(); | ||
2734 | Variable FunctionName = new Variable(); | ||
2735 | Variable CompiledArgs = new Variable(); | ||
2736 | foreach (bool l2 in YP.univ(Functor_1, new ListPair(FunctorName, FunctorArgs))) | ||
2737 | { | ||
2738 | foreach (bool l3 in YP.functor(Functor_1, x6, Arity)) | ||
2739 | { | ||
2740 | foreach (bool l4 in functorCallFunctionName(State, FunctorName, Arity, FunctionName)) | ||
2741 | { | ||
2742 | foreach (bool l5 in maplist_compileTerm(FunctorArgs, State, CompiledArgs)) | ||
2743 | { | ||
2744 | if (YP.termEqual(FunctionName, Atom.NIL)) | ||
2745 | { | ||
2746 | foreach (bool l7 in YP.unify(PseudoCode, new Functor2("call", Atom.a("YP.matchDynamic"), new ListPair(new Functor2("call", Atom.a("Atom.a"), new ListPair(new Functor1("object", FunctorName), Atom.NIL)), new ListPair(new Functor1("objectArray", CompiledArgs), Atom.NIL))))) | ||
2747 | { | ||
2748 | yield return true; | ||
2749 | yield break; | ||
2750 | } | ||
2751 | goto cutIf1; | ||
2752 | } | ||
2753 | foreach (bool l6 in YP.unify(PseudoCode, new Functor3("functorCall", FunctionName, FunctorArgs, CompiledArgs))) | ||
2754 | { | ||
2755 | yield return true; | ||
2756 | yield break; | ||
2757 | } | ||
2758 | cutIf1: | ||
2759 | { } | ||
2760 | } | ||
2761 | } | ||
2762 | } | ||
2763 | } | ||
2764 | } | ||
2765 | } | ||
2766 | |||
2767 | public static IEnumerable<bool> functorCallFunctionName(object arg1, object arg2, object arg3, object arg4) | ||
2768 | { | ||
2769 | { | ||
2770 | object _State = arg1; | ||
2771 | object Name = arg2; | ||
2772 | object Arity = arg3; | ||
2773 | object x4 = arg4; | ||
2774 | if (functorCallIsSpecialForm(Name, Arity)) | ||
2775 | { | ||
2776 | yield break; | ||
2777 | } | ||
2778 | } | ||
2779 | { | ||
2780 | object x1 = arg1; | ||
2781 | object Name = arg2; | ||
2782 | object Arity = arg3; | ||
2783 | object FunctionName = arg4; | ||
2784 | foreach (bool l2 in functorCallYPFunctionName(Name, Arity, FunctionName)) | ||
2785 | { | ||
2786 | yield return true; | ||
2787 | yield break; | ||
2788 | } | ||
2789 | } | ||
2790 | { | ||
2791 | object State = arg1; | ||
2792 | object Arity = arg3; | ||
2793 | Variable Name = new Variable(); | ||
2794 | foreach (bool l2 in YP.unify(arg2, Name)) | ||
2795 | { | ||
2796 | foreach (bool l3 in YP.unify(arg4, Name)) | ||
2797 | { | ||
2798 | if (CompilerState.nameArityHasModule(State, Name, Arity, Atom.a(""))) | ||
2799 | { | ||
2800 | yield return true; | ||
2801 | yield break; | ||
2802 | } | ||
2803 | } | ||
2804 | } | ||
2805 | } | ||
2806 | { | ||
2807 | object _State = arg1; | ||
2808 | object _Arity = arg3; | ||
2809 | Variable Name = new Variable(); | ||
2810 | foreach (bool l2 in YP.unify(arg2, Name)) | ||
2811 | { | ||
2812 | foreach (bool l3 in YP.unify(arg4, Name)) | ||
2813 | { | ||
2814 | foreach (bool l4 in Atom.module(Name, Atom.a(""))) | ||
2815 | { | ||
2816 | yield return true; | ||
2817 | yield break; | ||
2818 | } | ||
2819 | } | ||
2820 | } | ||
2821 | } | ||
2822 | { | ||
2823 | object _State = arg1; | ||
2824 | object Name = arg2; | ||
2825 | object _Arity = arg3; | ||
2826 | foreach (bool l2 in YP.unify(arg4, Atom.NIL)) | ||
2827 | { | ||
2828 | foreach (bool l3 in Atom.module(Name, Atom.NIL)) | ||
2829 | { | ||
2830 | yield return true; | ||
2831 | yield break; | ||
2832 | } | ||
2833 | } | ||
2834 | } | ||
2835 | { | ||
2836 | object _State = arg1; | ||
2837 | object Name = arg2; | ||
2838 | object Arity = arg3; | ||
2839 | object x4 = arg4; | ||
2840 | Variable Module = new Variable(); | ||
2841 | Variable Message = new Variable(); | ||
2842 | foreach (bool l2 in Atom.module(Name, Module)) | ||
2843 | { | ||
2844 | foreach (bool l3 in YP.atom_concat(Atom.a("Not supporting calls to external module: "), Module, Message)) | ||
2845 | { | ||
2846 | YP.throwException(new Functor2("error", new Functor2("type_error", Atom.a("callable"), new Functor2("/", Name, Arity)), Message)); | ||
2847 | yield return true; | ||
2848 | yield break; | ||
2849 | } | ||
2850 | } | ||
2851 | } | ||
2852 | { | ||
2853 | object _State = arg1; | ||
2854 | object Name = arg2; | ||
2855 | object _Arity = arg3; | ||
2856 | object x4 = arg4; | ||
2857 | YP.throwException(new Functor2("error", new Functor2("type_error", Atom.a("callable"), Name), Atom.a("Term is not callable"))); | ||
2858 | yield return true; | ||
2859 | yield break; | ||
2860 | } | ||
2861 | } | ||
2862 | |||
2863 | public static bool functorCallIsSpecialForm(object Name, object Arity) | ||
2864 | { | ||
2865 | { | ||
2866 | Variable x3 = new Variable(); | ||
2867 | if (YP.termEqual(Arity, 0)) | ||
2868 | { | ||
2869 | if (YP.termEqual(Name, Atom.a("!"))) | ||
2870 | { | ||
2871 | return true; | ||
2872 | } | ||
2873 | if (YP.termEqual(Name, Atom.a("fail"))) | ||
2874 | { | ||
2875 | return true; | ||
2876 | } | ||
2877 | if (YP.termEqual(Name, Atom.a("true"))) | ||
2878 | { | ||
2879 | return true; | ||
2880 | } | ||
2881 | } | ||
2882 | if (YP.termEqual(Arity, 1)) | ||
2883 | { | ||
2884 | if (YP.termEqual(Name, Atom.a("\\+"))) | ||
2885 | { | ||
2886 | return true; | ||
2887 | } | ||
2888 | if (YP.termEqual(Name, Atom.a("once"))) | ||
2889 | { | ||
2890 | return true; | ||
2891 | } | ||
2892 | if (YP.termEqual(Name, Atom.a("$CUTIF"))) | ||
2893 | { | ||
2894 | return true; | ||
2895 | } | ||
2896 | if (YP.termEqual(Name, Atom.a("$DET_NONE_OUT"))) | ||
2897 | { | ||
2898 | return true; | ||
2899 | } | ||
2900 | if (YP.termEqual(Name, Atom.a("call"))) | ||
2901 | { | ||
2902 | return true; | ||
2903 | } | ||
2904 | if (YP.termEqual(Name, Atom.a("current_predicate"))) | ||
2905 | { | ||
2906 | return true; | ||
2907 | } | ||
2908 | if (YP.termEqual(Name, Atom.a("asserta"))) | ||
2909 | { | ||
2910 | return true; | ||
2911 | } | ||
2912 | if (YP.termEqual(Name, Atom.a("assertz"))) | ||
2913 | { | ||
2914 | return true; | ||
2915 | } | ||
2916 | if (YP.termEqual(Name, Atom.a("assert"))) | ||
2917 | { | ||
2918 | return true; | ||
2919 | } | ||
2920 | } | ||
2921 | if (YP.termEqual(Arity, 2)) | ||
2922 | { | ||
2923 | if (YP.termEqual(Name, Atom.a(";"))) | ||
2924 | { | ||
2925 | return true; | ||
2926 | } | ||
2927 | if (YP.termEqual(Name, Atom.a(","))) | ||
2928 | { | ||
2929 | return true; | ||
2930 | } | ||
2931 | if (YP.termEqual(Name, Atom.a("->"))) | ||
2932 | { | ||
2933 | return true; | ||
2934 | } | ||
2935 | if (YP.termEqual(Name, Atom.a("\\="))) | ||
2936 | { | ||
2937 | return true; | ||
2938 | } | ||
2939 | if (YP.termEqual(Name, Atom.a("is"))) | ||
2940 | { | ||
2941 | return true; | ||
2942 | } | ||
2943 | foreach (bool l3 in binaryExpressionConditional(Name, x3)) | ||
2944 | { | ||
2945 | return true; | ||
2946 | } | ||
2947 | } | ||
2948 | if (YP.termEqual(Arity, 3)) | ||
2949 | { | ||
2950 | if (YP.termEqual(Name, Atom.a("findall"))) | ||
2951 | { | ||
2952 | return true; | ||
2953 | } | ||
2954 | if (YP.termEqual(Name, Atom.a("bagof"))) | ||
2955 | { | ||
2956 | return true; | ||
2957 | } | ||
2958 | if (YP.termEqual(Name, Atom.a("setof"))) | ||
2959 | { | ||
2960 | return true; | ||
2961 | } | ||
2962 | if (YP.termEqual(Name, Atom.a("catch"))) | ||
2963 | { | ||
2964 | return true; | ||
2965 | } | ||
2966 | } | ||
2967 | } | ||
2968 | return false; | ||
2969 | } | ||
2970 | |||
2971 | public static IEnumerable<bool> functorCallYPFunctionName(object arg1, object arg2, object arg3) | ||
2972 | { | ||
2973 | { | ||
2974 | foreach (bool l2 in YP.unify(arg1, Atom.a("="))) | ||
2975 | { | ||
2976 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
2977 | { | ||
2978 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.unify"))) | ||
2979 | { | ||
2980 | yield return true; | ||
2981 | yield break; | ||
2982 | } | ||
2983 | } | ||
2984 | } | ||
2985 | } | ||
2986 | { | ||
2987 | foreach (bool l2 in YP.unify(arg1, Atom.a("=.."))) | ||
2988 | { | ||
2989 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
2990 | { | ||
2991 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.univ"))) | ||
2992 | { | ||
2993 | yield return true; | ||
2994 | yield break; | ||
2995 | } | ||
2996 | } | ||
2997 | } | ||
2998 | } | ||
2999 | { | ||
3000 | foreach (bool l2 in YP.unify(arg1, Atom.a("var"))) | ||
3001 | { | ||
3002 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3003 | { | ||
3004 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.var"))) | ||
3005 | { | ||
3006 | yield return true; | ||
3007 | yield break; | ||
3008 | } | ||
3009 | } | ||
3010 | } | ||
3011 | } | ||
3012 | { | ||
3013 | foreach (bool l2 in YP.unify(arg1, Atom.a("nonvar"))) | ||
3014 | { | ||
3015 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3016 | { | ||
3017 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.nonvar"))) | ||
3018 | { | ||
3019 | yield return true; | ||
3020 | yield break; | ||
3021 | } | ||
3022 | } | ||
3023 | } | ||
3024 | } | ||
3025 | { | ||
3026 | foreach (bool l2 in YP.unify(arg1, Atom.a("arg"))) | ||
3027 | { | ||
3028 | foreach (bool l3 in YP.unify(arg2, 3)) | ||
3029 | { | ||
3030 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.arg"))) | ||
3031 | { | ||
3032 | yield return true; | ||
3033 | yield break; | ||
3034 | } | ||
3035 | } | ||
3036 | } | ||
3037 | } | ||
3038 | { | ||
3039 | foreach (bool l2 in YP.unify(arg1, Atom.a("functor"))) | ||
3040 | { | ||
3041 | foreach (bool l3 in YP.unify(arg2, 3)) | ||
3042 | { | ||
3043 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.functor"))) | ||
3044 | { | ||
3045 | yield return true; | ||
3046 | yield break; | ||
3047 | } | ||
3048 | } | ||
3049 | } | ||
3050 | } | ||
3051 | { | ||
3052 | foreach (bool l2 in YP.unify(arg1, Atom.a("repeat"))) | ||
3053 | { | ||
3054 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
3055 | { | ||
3056 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.repeat"))) | ||
3057 | { | ||
3058 | yield return true; | ||
3059 | yield break; | ||
3060 | } | ||
3061 | } | ||
3062 | } | ||
3063 | } | ||
3064 | { | ||
3065 | foreach (bool l2 in YP.unify(arg1, Atom.a("get_code"))) | ||
3066 | { | ||
3067 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3068 | { | ||
3069 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.get_code"))) | ||
3070 | { | ||
3071 | yield return true; | ||
3072 | yield break; | ||
3073 | } | ||
3074 | } | ||
3075 | } | ||
3076 | } | ||
3077 | { | ||
3078 | foreach (bool l2 in YP.unify(arg1, Atom.a("current_op"))) | ||
3079 | { | ||
3080 | foreach (bool l3 in YP.unify(arg2, 3)) | ||
3081 | { | ||
3082 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.current_op"))) | ||
3083 | { | ||
3084 | yield return true; | ||
3085 | yield break; | ||
3086 | } | ||
3087 | } | ||
3088 | } | ||
3089 | } | ||
3090 | { | ||
3091 | foreach (bool l2 in YP.unify(arg1, Atom.a("atom_length"))) | ||
3092 | { | ||
3093 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3094 | { | ||
3095 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.atom_length"))) | ||
3096 | { | ||
3097 | yield return true; | ||
3098 | yield break; | ||
3099 | } | ||
3100 | } | ||
3101 | } | ||
3102 | } | ||
3103 | { | ||
3104 | foreach (bool l2 in YP.unify(arg1, Atom.a("atom_concat"))) | ||
3105 | { | ||
3106 | foreach (bool l3 in YP.unify(arg2, 3)) | ||
3107 | { | ||
3108 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.atom_concat"))) | ||
3109 | { | ||
3110 | yield return true; | ||
3111 | yield break; | ||
3112 | } | ||
3113 | } | ||
3114 | } | ||
3115 | } | ||
3116 | { | ||
3117 | foreach (bool l2 in YP.unify(arg1, Atom.a("sub_atom"))) | ||
3118 | { | ||
3119 | foreach (bool l3 in YP.unify(arg2, 5)) | ||
3120 | { | ||
3121 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.sub_atom"))) | ||
3122 | { | ||
3123 | yield return true; | ||
3124 | yield break; | ||
3125 | } | ||
3126 | } | ||
3127 | } | ||
3128 | } | ||
3129 | { | ||
3130 | foreach (bool l2 in YP.unify(arg1, Atom.a("atom_chars"))) | ||
3131 | { | ||
3132 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3133 | { | ||
3134 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.atom_chars"))) | ||
3135 | { | ||
3136 | yield return true; | ||
3137 | yield break; | ||
3138 | } | ||
3139 | } | ||
3140 | } | ||
3141 | } | ||
3142 | { | ||
3143 | foreach (bool l2 in YP.unify(arg1, Atom.a("atom_codes"))) | ||
3144 | { | ||
3145 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3146 | { | ||
3147 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.atom_codes"))) | ||
3148 | { | ||
3149 | yield return true; | ||
3150 | yield break; | ||
3151 | } | ||
3152 | } | ||
3153 | } | ||
3154 | } | ||
3155 | { | ||
3156 | foreach (bool l2 in YP.unify(arg1, Atom.a("char_code"))) | ||
3157 | { | ||
3158 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3159 | { | ||
3160 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.char_code"))) | ||
3161 | { | ||
3162 | yield return true; | ||
3163 | yield break; | ||
3164 | } | ||
3165 | } | ||
3166 | } | ||
3167 | } | ||
3168 | { | ||
3169 | foreach (bool l2 in YP.unify(arg1, Atom.a("number_chars"))) | ||
3170 | { | ||
3171 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3172 | { | ||
3173 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.number_chars"))) | ||
3174 | { | ||
3175 | yield return true; | ||
3176 | yield break; | ||
3177 | } | ||
3178 | } | ||
3179 | } | ||
3180 | } | ||
3181 | { | ||
3182 | foreach (bool l2 in YP.unify(arg1, Atom.a("number_codes"))) | ||
3183 | { | ||
3184 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3185 | { | ||
3186 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.number_codes"))) | ||
3187 | { | ||
3188 | yield return true; | ||
3189 | yield break; | ||
3190 | } | ||
3191 | } | ||
3192 | } | ||
3193 | } | ||
3194 | { | ||
3195 | foreach (bool l2 in YP.unify(arg1, Atom.a("copy_term"))) | ||
3196 | { | ||
3197 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3198 | { | ||
3199 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.copy_term"))) | ||
3200 | { | ||
3201 | yield return true; | ||
3202 | yield break; | ||
3203 | } | ||
3204 | } | ||
3205 | } | ||
3206 | } | ||
3207 | { | ||
3208 | foreach (bool l2 in YP.unify(arg1, Atom.a("sort"))) | ||
3209 | { | ||
3210 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3211 | { | ||
3212 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.sort"))) | ||
3213 | { | ||
3214 | yield return true; | ||
3215 | yield break; | ||
3216 | } | ||
3217 | } | ||
3218 | } | ||
3219 | } | ||
3220 | { | ||
3221 | // Manually included : script_event for callback to LSL/C# | ||
3222 | |||
3223 | //object x1 = arg1; | ||
3224 | foreach (bool l2 in YP.unify(arg1, Atom.a(@"script_event"))) | ||
3225 | { | ||
3226 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3227 | { | ||
3228 | foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.script_event"))) | ||
3229 | { | ||
3230 | yield return true; | ||
3231 | yield break; | ||
3232 | } | ||
3233 | } | ||
3234 | } | ||
3235 | } | ||
3236 | { | ||
3237 | foreach (bool l2 in YP.unify(arg1, Atom.a("nl"))) | ||
3238 | { | ||
3239 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
3240 | { | ||
3241 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.nl"))) | ||
3242 | { | ||
3243 | yield return true; | ||
3244 | yield break; | ||
3245 | } | ||
3246 | } | ||
3247 | } | ||
3248 | } | ||
3249 | { | ||
3250 | foreach (bool l2 in YP.unify(arg1, Atom.a("write"))) | ||
3251 | { | ||
3252 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3253 | { | ||
3254 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.write"))) | ||
3255 | { | ||
3256 | yield return true; | ||
3257 | yield break; | ||
3258 | } | ||
3259 | } | ||
3260 | } | ||
3261 | } | ||
3262 | { | ||
3263 | foreach (bool l2 in YP.unify(arg1, Atom.a("put_code"))) | ||
3264 | { | ||
3265 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3266 | { | ||
3267 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.put_code"))) | ||
3268 | { | ||
3269 | yield return true; | ||
3270 | yield break; | ||
3271 | } | ||
3272 | } | ||
3273 | } | ||
3274 | } | ||
3275 | { | ||
3276 | foreach (bool l2 in YP.unify(arg1, Atom.a("see"))) | ||
3277 | { | ||
3278 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3279 | { | ||
3280 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.see"))) | ||
3281 | { | ||
3282 | yield return true; | ||
3283 | yield break; | ||
3284 | } | ||
3285 | } | ||
3286 | } | ||
3287 | } | ||
3288 | { | ||
3289 | foreach (bool l2 in YP.unify(arg1, Atom.a("seen"))) | ||
3290 | { | ||
3291 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
3292 | { | ||
3293 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.seen"))) | ||
3294 | { | ||
3295 | yield return true; | ||
3296 | yield break; | ||
3297 | } | ||
3298 | } | ||
3299 | } | ||
3300 | } | ||
3301 | { | ||
3302 | foreach (bool l2 in YP.unify(arg1, Atom.a("tell"))) | ||
3303 | { | ||
3304 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3305 | { | ||
3306 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.tell"))) | ||
3307 | { | ||
3308 | yield return true; | ||
3309 | yield break; | ||
3310 | } | ||
3311 | } | ||
3312 | } | ||
3313 | } | ||
3314 | { | ||
3315 | foreach (bool l2 in YP.unify(arg1, Atom.a("told"))) | ||
3316 | { | ||
3317 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
3318 | { | ||
3319 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.told"))) | ||
3320 | { | ||
3321 | yield return true; | ||
3322 | yield break; | ||
3323 | } | ||
3324 | } | ||
3325 | } | ||
3326 | } | ||
3327 | { | ||
3328 | foreach (bool l2 in YP.unify(arg1, Atom.a("clause"))) | ||
3329 | { | ||
3330 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3331 | { | ||
3332 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.clause"))) | ||
3333 | { | ||
3334 | yield return true; | ||
3335 | yield break; | ||
3336 | } | ||
3337 | } | ||
3338 | } | ||
3339 | } | ||
3340 | { | ||
3341 | foreach (bool l2 in YP.unify(arg1, Atom.a("retract"))) | ||
3342 | { | ||
3343 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3344 | { | ||
3345 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.retract"))) | ||
3346 | { | ||
3347 | yield return true; | ||
3348 | yield break; | ||
3349 | } | ||
3350 | } | ||
3351 | } | ||
3352 | } | ||
3353 | { | ||
3354 | foreach (bool l2 in YP.unify(arg1, Atom.a("abolish"))) | ||
3355 | { | ||
3356 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3357 | { | ||
3358 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.abolish"))) | ||
3359 | { | ||
3360 | yield return true; | ||
3361 | yield break; | ||
3362 | } | ||
3363 | } | ||
3364 | } | ||
3365 | } | ||
3366 | { | ||
3367 | foreach (bool l2 in YP.unify(arg1, Atom.a("retractall"))) | ||
3368 | { | ||
3369 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3370 | { | ||
3371 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.retractall"))) | ||
3372 | { | ||
3373 | yield return true; | ||
3374 | yield break; | ||
3375 | } | ||
3376 | } | ||
3377 | } | ||
3378 | } | ||
3379 | { | ||
3380 | foreach (bool l2 in YP.unify(arg1, Atom.a("atom"))) | ||
3381 | { | ||
3382 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3383 | { | ||
3384 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.atom"))) | ||
3385 | { | ||
3386 | yield return true; | ||
3387 | yield break; | ||
3388 | } | ||
3389 | } | ||
3390 | } | ||
3391 | } | ||
3392 | { | ||
3393 | foreach (bool l2 in YP.unify(arg1, Atom.a("integer"))) | ||
3394 | { | ||
3395 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3396 | { | ||
3397 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.integer"))) | ||
3398 | { | ||
3399 | yield return true; | ||
3400 | yield break; | ||
3401 | } | ||
3402 | } | ||
3403 | } | ||
3404 | } | ||
3405 | { | ||
3406 | foreach (bool l2 in YP.unify(arg1, Atom.a("float"))) | ||
3407 | { | ||
3408 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3409 | { | ||
3410 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.isFloat"))) | ||
3411 | { | ||
3412 | yield return true; | ||
3413 | yield break; | ||
3414 | } | ||
3415 | } | ||
3416 | } | ||
3417 | } | ||
3418 | { | ||
3419 | foreach (bool l2 in YP.unify(arg1, Atom.a("number"))) | ||
3420 | { | ||
3421 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3422 | { | ||
3423 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.number"))) | ||
3424 | { | ||
3425 | yield return true; | ||
3426 | yield break; | ||
3427 | } | ||
3428 | } | ||
3429 | } | ||
3430 | } | ||
3431 | { | ||
3432 | foreach (bool l2 in YP.unify(arg1, Atom.a("atomic"))) | ||
3433 | { | ||
3434 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3435 | { | ||
3436 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.atomic"))) | ||
3437 | { | ||
3438 | yield return true; | ||
3439 | yield break; | ||
3440 | } | ||
3441 | } | ||
3442 | } | ||
3443 | } | ||
3444 | { | ||
3445 | foreach (bool l2 in YP.unify(arg1, Atom.a("compound"))) | ||
3446 | { | ||
3447 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3448 | { | ||
3449 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.compound"))) | ||
3450 | { | ||
3451 | yield return true; | ||
3452 | yield break; | ||
3453 | } | ||
3454 | } | ||
3455 | } | ||
3456 | } | ||
3457 | { | ||
3458 | foreach (bool l2 in YP.unify(arg1, Atom.a("=="))) | ||
3459 | { | ||
3460 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3461 | { | ||
3462 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.termEqual"))) | ||
3463 | { | ||
3464 | yield return true; | ||
3465 | yield break; | ||
3466 | } | ||
3467 | } | ||
3468 | } | ||
3469 | } | ||
3470 | { | ||
3471 | foreach (bool l2 in YP.unify(arg1, Atom.a("\\=="))) | ||
3472 | { | ||
3473 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3474 | { | ||
3475 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.termNotEqual"))) | ||
3476 | { | ||
3477 | yield return true; | ||
3478 | yield break; | ||
3479 | } | ||
3480 | } | ||
3481 | } | ||
3482 | } | ||
3483 | { | ||
3484 | foreach (bool l2 in YP.unify(arg1, Atom.a("@<"))) | ||
3485 | { | ||
3486 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3487 | { | ||
3488 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.termLessThan"))) | ||
3489 | { | ||
3490 | yield return true; | ||
3491 | yield break; | ||
3492 | } | ||
3493 | } | ||
3494 | } | ||
3495 | } | ||
3496 | { | ||
3497 | foreach (bool l2 in YP.unify(arg1, Atom.a("@=<"))) | ||
3498 | { | ||
3499 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3500 | { | ||
3501 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.termLessThanOrEqual"))) | ||
3502 | { | ||
3503 | yield return true; | ||
3504 | yield break; | ||
3505 | } | ||
3506 | } | ||
3507 | } | ||
3508 | } | ||
3509 | { | ||
3510 | foreach (bool l2 in YP.unify(arg1, Atom.a("@>"))) | ||
3511 | { | ||
3512 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3513 | { | ||
3514 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.termGreaterThan"))) | ||
3515 | { | ||
3516 | yield return true; | ||
3517 | yield break; | ||
3518 | } | ||
3519 | } | ||
3520 | } | ||
3521 | } | ||
3522 | { | ||
3523 | foreach (bool l2 in YP.unify(arg1, Atom.a("@>="))) | ||
3524 | { | ||
3525 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3526 | { | ||
3527 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.termGreaterThanOrEqual"))) | ||
3528 | { | ||
3529 | yield return true; | ||
3530 | yield break; | ||
3531 | } | ||
3532 | } | ||
3533 | } | ||
3534 | } | ||
3535 | { | ||
3536 | foreach (bool l2 in YP.unify(arg1, Atom.a("throw"))) | ||
3537 | { | ||
3538 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3539 | { | ||
3540 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.throwException"))) | ||
3541 | { | ||
3542 | yield return true; | ||
3543 | yield break; | ||
3544 | } | ||
3545 | } | ||
3546 | } | ||
3547 | } | ||
3548 | { | ||
3549 | foreach (bool l2 in YP.unify(arg1, Atom.a("current_prolog_flag"))) | ||
3550 | { | ||
3551 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3552 | { | ||
3553 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.current_prolog_flag"))) | ||
3554 | { | ||
3555 | yield return true; | ||
3556 | yield break; | ||
3557 | } | ||
3558 | } | ||
3559 | } | ||
3560 | } | ||
3561 | { | ||
3562 | foreach (bool l2 in YP.unify(arg1, Atom.a("set_prolog_flag"))) | ||
3563 | { | ||
3564 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3565 | { | ||
3566 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.set_prolog_flag"))) | ||
3567 | { | ||
3568 | yield return true; | ||
3569 | yield break; | ||
3570 | } | ||
3571 | } | ||
3572 | } | ||
3573 | } | ||
3574 | { | ||
3575 | foreach (bool l2 in YP.unify(arg1, Atom.a("current_input"))) | ||
3576 | { | ||
3577 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3578 | { | ||
3579 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.current_input"))) | ||
3580 | { | ||
3581 | yield return true; | ||
3582 | yield break; | ||
3583 | } | ||
3584 | } | ||
3585 | } | ||
3586 | } | ||
3587 | { | ||
3588 | foreach (bool l2 in YP.unify(arg1, Atom.a("current_output"))) | ||
3589 | { | ||
3590 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3591 | { | ||
3592 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.current_output"))) | ||
3593 | { | ||
3594 | yield return true; | ||
3595 | yield break; | ||
3596 | } | ||
3597 | } | ||
3598 | } | ||
3599 | } | ||
3600 | { | ||
3601 | foreach (bool l2 in YP.unify(arg1, Atom.a("read_term"))) | ||
3602 | { | ||
3603 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3604 | { | ||
3605 | foreach (bool l4 in YP.unify(arg3, Atom.a("Parser.read_term2"))) | ||
3606 | { | ||
3607 | yield return true; | ||
3608 | yield break; | ||
3609 | } | ||
3610 | } | ||
3611 | } | ||
3612 | } | ||
3613 | { | ||
3614 | foreach (bool l2 in YP.unify(arg1, Atom.a("read_term"))) | ||
3615 | { | ||
3616 | foreach (bool l3 in YP.unify(arg2, 3)) | ||
3617 | { | ||
3618 | foreach (bool l4 in YP.unify(arg3, Atom.a("Parser.read_term3"))) | ||
3619 | { | ||
3620 | yield return true; | ||
3621 | yield break; | ||
3622 | } | ||
3623 | } | ||
3624 | } | ||
3625 | } | ||
3626 | { | ||
3627 | foreach (bool l2 in YP.unify(arg1, Atom.a("read"))) | ||
3628 | { | ||
3629 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3630 | { | ||
3631 | foreach (bool l4 in YP.unify(arg3, Atom.a("Parser.read1"))) | ||
3632 | { | ||
3633 | yield return true; | ||
3634 | yield break; | ||
3635 | } | ||
3636 | } | ||
3637 | } | ||
3638 | } | ||
3639 | { | ||
3640 | foreach (bool l2 in YP.unify(arg1, Atom.a("read"))) | ||
3641 | { | ||
3642 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3643 | { | ||
3644 | foreach (bool l4 in YP.unify(arg3, Atom.a("Parser.read2"))) | ||
3645 | { | ||
3646 | yield return true; | ||
3647 | yield break; | ||
3648 | } | ||
3649 | } | ||
3650 | } | ||
3651 | } | ||
3652 | } | ||
3653 | |||
3654 | public static IEnumerable<bool> compileTerm(object arg1, object arg2, object arg3) | ||
3655 | { | ||
3656 | { | ||
3657 | object Term = arg1; | ||
3658 | object State = arg2; | ||
3659 | Variable VariableName = new Variable(); | ||
3660 | foreach (bool l2 in YP.unify(arg3, new Functor1("var", VariableName))) | ||
3661 | { | ||
3662 | if (YP.var(Term)) | ||
3663 | { | ||
3664 | foreach (bool l4 in CompilerState.getVariableName(State, Term, VariableName)) | ||
3665 | { | ||
3666 | yield return true; | ||
3667 | yield break; | ||
3668 | } | ||
3669 | } | ||
3670 | } | ||
3671 | } | ||
3672 | { | ||
3673 | object _State = arg2; | ||
3674 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
3675 | { | ||
3676 | foreach (bool l3 in YP.unify(arg3, new Functor1("var", Atom.a("Atom.NIL")))) | ||
3677 | { | ||
3678 | yield return true; | ||
3679 | yield break; | ||
3680 | } | ||
3681 | } | ||
3682 | } | ||
3683 | { | ||
3684 | object Term = arg1; | ||
3685 | object State = arg2; | ||
3686 | object Code = arg3; | ||
3687 | Variable ModuleCode = new Variable(); | ||
3688 | if (YP.atom(Term)) | ||
3689 | { | ||
3690 | foreach (bool l3 in compileAtomModule(Term, 0, State, ModuleCode)) | ||
3691 | { | ||
3692 | foreach (bool l4 in YP.unify(Code, new Functor2("call", Atom.a("Atom.a"), new ListPair(new Functor1("object", Term), new ListPair(ModuleCode, Atom.NIL))))) | ||
3693 | { | ||
3694 | yield return true; | ||
3695 | yield break; | ||
3696 | } | ||
3697 | goto cutIf1; | ||
3698 | } | ||
3699 | foreach (bool l3 in YP.unify(Code, new Functor2("call", Atom.a("Atom.a"), new ListPair(new Functor1("object", Term), Atom.NIL)))) | ||
3700 | { | ||
3701 | yield return true; | ||
3702 | yield break; | ||
3703 | } | ||
3704 | cutIf1: | ||
3705 | { } | ||
3706 | } | ||
3707 | } | ||
3708 | { | ||
3709 | object State = arg2; | ||
3710 | Variable First = new Variable(); | ||
3711 | Variable Rest = new Variable(); | ||
3712 | Variable CompiledList = new Variable(); | ||
3713 | Variable x5 = new Variable(); | ||
3714 | Variable Rest2 = new Variable(); | ||
3715 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
3716 | { | ||
3717 | foreach (bool l3 in YP.unify(arg3, new Functor2("call", Atom.a("ListPair.make"), new ListPair(new Functor1("objectArray", CompiledList), Atom.NIL)))) | ||
3718 | { | ||
3719 | if (YP.nonvar(Rest)) | ||
3720 | { | ||
3721 | foreach (bool l5 in YP.unify(Rest, new ListPair(x5, Rest2))) | ||
3722 | { | ||
3723 | if (YP.termNotEqual(Rest2, Atom.NIL)) | ||
3724 | { | ||
3725 | foreach (bool l7 in maplist_compileTerm(new ListPair(First, Rest), State, CompiledList)) | ||
3726 | { | ||
3727 | yield return true; | ||
3728 | yield break; | ||
3729 | } | ||
3730 | } | ||
3731 | } | ||
3732 | } | ||
3733 | } | ||
3734 | } | ||
3735 | } | ||
3736 | { | ||
3737 | object State = arg2; | ||
3738 | Variable First = new Variable(); | ||
3739 | Variable Rest = new Variable(); | ||
3740 | Variable Arg1 = new Variable(); | ||
3741 | Variable Arg2 = new Variable(); | ||
3742 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
3743 | { | ||
3744 | foreach (bool l3 in YP.unify(arg3, new Functor2("new", Atom.a("ListPair"), new ListPair(Arg1, new ListPair(Arg2, Atom.NIL))))) | ||
3745 | { | ||
3746 | foreach (bool l4 in compileTerm(First, State, Arg1)) | ||
3747 | { | ||
3748 | foreach (bool l5 in compileTerm(Rest, State, Arg2)) | ||
3749 | { | ||
3750 | yield return true; | ||
3751 | yield break; | ||
3752 | } | ||
3753 | } | ||
3754 | } | ||
3755 | } | ||
3756 | } | ||
3757 | { | ||
3758 | object Term = arg1; | ||
3759 | object State = arg2; | ||
3760 | object Result = arg3; | ||
3761 | Variable Name = new Variable(); | ||
3762 | Variable TermArgs = new Variable(); | ||
3763 | Variable x6 = new Variable(); | ||
3764 | Variable Arity = new Variable(); | ||
3765 | Variable ModuleCode = new Variable(); | ||
3766 | Variable NameCode = new Variable(); | ||
3767 | Variable X1 = new Variable(); | ||
3768 | Variable Arg1 = new Variable(); | ||
3769 | Variable X2 = new Variable(); | ||
3770 | Variable Arg2 = new Variable(); | ||
3771 | Variable X3 = new Variable(); | ||
3772 | Variable Arg3 = new Variable(); | ||
3773 | Variable Args = new Variable(); | ||
3774 | foreach (bool l2 in YP.univ(Term, new ListPair(Name, TermArgs))) | ||
3775 | { | ||
3776 | if (YP.termEqual(TermArgs, Atom.NIL)) | ||
3777 | { | ||
3778 | foreach (bool l4 in YP.unify(Result, new Functor1("object", Name))) | ||
3779 | { | ||
3780 | yield return true; | ||
3781 | yield break; | ||
3782 | } | ||
3783 | goto cutIf2; | ||
3784 | } | ||
3785 | foreach (bool l3 in YP.functor(Term, x6, Arity)) | ||
3786 | { | ||
3787 | foreach (bool l4 in compileAtomModule(Name, Arity, State, ModuleCode)) | ||
3788 | { | ||
3789 | foreach (bool l5 in YP.unify(NameCode, new Functor2("call", Atom.a("Atom.a"), new ListPair(new Functor1("object", Name), new ListPair(ModuleCode, Atom.NIL))))) | ||
3790 | { | ||
3791 | foreach (bool l6 in YP.unify(TermArgs, new ListPair(X1, Atom.NIL))) | ||
3792 | { | ||
3793 | foreach (bool l7 in compileTerm(X1, State, Arg1)) | ||
3794 | { | ||
3795 | foreach (bool l8 in YP.unify(Result, new Functor2("new", Atom.a("Functor1"), new ListPair(NameCode, new ListPair(Arg1, Atom.NIL))))) | ||
3796 | { | ||
3797 | yield return true; | ||
3798 | yield break; | ||
3799 | } | ||
3800 | } | ||
3801 | goto cutIf4; | ||
3802 | } | ||
3803 | foreach (bool l6 in YP.unify(TermArgs, new ListPair(X1, new ListPair(X2, Atom.NIL)))) | ||
3804 | { | ||
3805 | foreach (bool l7 in compileTerm(X1, State, Arg1)) | ||
3806 | { | ||
3807 | foreach (bool l8 in compileTerm(X2, State, Arg2)) | ||
3808 | { | ||
3809 | foreach (bool l9 in YP.unify(Result, new Functor2("new", Atom.a("Functor2"), ListPair.make(new object[] { NameCode, Arg1, Arg2 })))) | ||
3810 | { | ||
3811 | yield return true; | ||
3812 | yield break; | ||
3813 | } | ||
3814 | } | ||
3815 | } | ||
3816 | goto cutIf5; | ||
3817 | } | ||
3818 | foreach (bool l6 in YP.unify(TermArgs, ListPair.make(new object[] { X1, X2, X3 }))) | ||
3819 | { | ||
3820 | foreach (bool l7 in compileTerm(X1, State, Arg1)) | ||
3821 | { | ||
3822 | foreach (bool l8 in compileTerm(X2, State, Arg2)) | ||
3823 | { | ||
3824 | foreach (bool l9 in compileTerm(X3, State, Arg3)) | ||
3825 | { | ||
3826 | foreach (bool l10 in YP.unify(Result, new Functor2("new", Atom.a("Functor3"), ListPair.make(new object[] { NameCode, Arg1, Arg2, Arg3 })))) | ||
3827 | { | ||
3828 | yield return true; | ||
3829 | yield break; | ||
3830 | } | ||
3831 | } | ||
3832 | } | ||
3833 | } | ||
3834 | } | ||
3835 | foreach (bool l6 in maplist_compileTerm(TermArgs, State, Args)) | ||
3836 | { | ||
3837 | foreach (bool l7 in YP.unify(Result, new Functor2("new", Atom.a("Functor"), new ListPair(NameCode, new ListPair(new Functor1("objectArray", Args), Atom.NIL))))) | ||
3838 | { | ||
3839 | yield return true; | ||
3840 | yield break; | ||
3841 | } | ||
3842 | } | ||
3843 | cutIf5: | ||
3844 | cutIf4: | ||
3845 | { } | ||
3846 | } | ||
3847 | goto cutIf3; | ||
3848 | } | ||
3849 | foreach (bool l4 in YP.unify(NameCode, new Functor1("object", Name))) | ||
3850 | { | ||
3851 | foreach (bool l5 in YP.unify(TermArgs, new ListPair(X1, Atom.NIL))) | ||
3852 | { | ||
3853 | foreach (bool l6 in compileTerm(X1, State, Arg1)) | ||
3854 | { | ||
3855 | foreach (bool l7 in YP.unify(Result, new Functor2("new", Atom.a("Functor1"), new ListPair(NameCode, new ListPair(Arg1, Atom.NIL))))) | ||
3856 | { | ||
3857 | yield return true; | ||
3858 | yield break; | ||
3859 | } | ||
3860 | } | ||
3861 | goto cutIf6; | ||
3862 | } | ||
3863 | foreach (bool l5 in YP.unify(TermArgs, new ListPair(X1, new ListPair(X2, Atom.NIL)))) | ||
3864 | { | ||
3865 | foreach (bool l6 in compileTerm(X1, State, Arg1)) | ||
3866 | { | ||
3867 | foreach (bool l7 in compileTerm(X2, State, Arg2)) | ||
3868 | { | ||
3869 | foreach (bool l8 in YP.unify(Result, new Functor2("new", Atom.a("Functor2"), ListPair.make(new object[] { NameCode, Arg1, Arg2 })))) | ||
3870 | { | ||
3871 | yield return true; | ||
3872 | yield break; | ||
3873 | } | ||
3874 | } | ||
3875 | } | ||
3876 | goto cutIf7; | ||
3877 | } | ||
3878 | foreach (bool l5 in YP.unify(TermArgs, ListPair.make(new object[] { X1, X2, X3 }))) | ||
3879 | { | ||
3880 | foreach (bool l6 in compileTerm(X1, State, Arg1)) | ||
3881 | { | ||
3882 | foreach (bool l7 in compileTerm(X2, State, Arg2)) | ||
3883 | { | ||
3884 | foreach (bool l8 in compileTerm(X3, State, Arg3)) | ||
3885 | { | ||
3886 | foreach (bool l9 in YP.unify(Result, new Functor2("new", Atom.a("Functor3"), ListPair.make(new object[] { NameCode, Arg1, Arg2, Arg3 })))) | ||
3887 | { | ||
3888 | yield return true; | ||
3889 | yield break; | ||
3890 | } | ||
3891 | } | ||
3892 | } | ||
3893 | } | ||
3894 | } | ||
3895 | foreach (bool l5 in maplist_compileTerm(TermArgs, State, Args)) | ||
3896 | { | ||
3897 | foreach (bool l6 in YP.unify(Result, new Functor2("new", Atom.a("Functor"), new ListPair(NameCode, new ListPair(new Functor1("objectArray", Args), Atom.NIL))))) | ||
3898 | { | ||
3899 | yield return true; | ||
3900 | yield break; | ||
3901 | } | ||
3902 | } | ||
3903 | cutIf7: | ||
3904 | cutIf6: | ||
3905 | { } | ||
3906 | } | ||
3907 | cutIf3: | ||
3908 | { } | ||
3909 | } | ||
3910 | cutIf2: | ||
3911 | { } | ||
3912 | } | ||
3913 | } | ||
3914 | } | ||
3915 | |||
3916 | public static IEnumerable<bool> compileAtomModule(object Name, object arg2, object arg3, object ModuleCode) | ||
3917 | { | ||
3918 | { | ||
3919 | object Arity = arg2; | ||
3920 | object State = arg3; | ||
3921 | if (CompilerState.nameArityHasModule(State, Name, Arity, Atom.a(""))) | ||
3922 | { | ||
3923 | foreach (bool l3 in YP.unify(ModuleCode, new Functor2("call", Atom.a("Atom.a"), new ListPair(new Functor1("object", Atom.a("")), Atom.NIL)))) | ||
3924 | { | ||
3925 | yield return true; | ||
3926 | yield break; | ||
3927 | } | ||
3928 | } | ||
3929 | } | ||
3930 | { | ||
3931 | object _Arity = arg2; | ||
3932 | object _State = arg3; | ||
3933 | Variable Module = new Variable(); | ||
3934 | foreach (bool l2 in Atom.module(Name, Module)) | ||
3935 | { | ||
3936 | if (YP.termNotEqual(Module, Atom.NIL)) | ||
3937 | { | ||
3938 | foreach (bool l4 in YP.unify(ModuleCode, new Functor2("call", Atom.a("Atom.a"), new ListPair(new Functor1("object", Module), Atom.NIL)))) | ||
3939 | { | ||
3940 | yield return true; | ||
3941 | yield break; | ||
3942 | } | ||
3943 | } | ||
3944 | } | ||
3945 | } | ||
3946 | } | ||
3947 | |||
3948 | public static IEnumerable<bool> maplist_compileTerm(object arg1, object arg2, object arg3) | ||
3949 | { | ||
3950 | { | ||
3951 | object _State = arg2; | ||
3952 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
3953 | { | ||
3954 | foreach (bool l3 in YP.unify(arg3, Atom.NIL)) | ||
3955 | { | ||
3956 | yield return true; | ||
3957 | yield break; | ||
3958 | } | ||
3959 | } | ||
3960 | } | ||
3961 | { | ||
3962 | object State = arg2; | ||
3963 | Variable First = new Variable(); | ||
3964 | Variable Rest = new Variable(); | ||
3965 | Variable FirstResult = new Variable(); | ||
3966 | Variable RestResults = new Variable(); | ||
3967 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
3968 | { | ||
3969 | foreach (bool l3 in YP.unify(arg3, new ListPair(FirstResult, RestResults))) | ||
3970 | { | ||
3971 | if (YP.nonvar(Rest)) | ||
3972 | { | ||
3973 | foreach (bool l5 in compileTerm(First, State, FirstResult)) | ||
3974 | { | ||
3975 | foreach (bool l6 in maplist_compileTerm(Rest, State, RestResults)) | ||
3976 | { | ||
3977 | yield return true; | ||
3978 | yield break; | ||
3979 | } | ||
3980 | } | ||
3981 | } | ||
3982 | } | ||
3983 | } | ||
3984 | } | ||
3985 | } | ||
3986 | |||
3987 | public static IEnumerable<bool> compileExpression(object Term, object State, object Result) | ||
3988 | { | ||
3989 | { | ||
3990 | Variable Name = new Variable(); | ||
3991 | Variable TermArgs = new Variable(); | ||
3992 | Variable X1 = new Variable(); | ||
3993 | Variable FunctionName = new Variable(); | ||
3994 | Variable Arg1 = new Variable(); | ||
3995 | Variable x9 = new Variable(); | ||
3996 | Variable X2 = new Variable(); | ||
3997 | Variable Arg2 = new Variable(); | ||
3998 | Variable x12 = new Variable(); | ||
3999 | Variable Arity = new Variable(); | ||
4000 | if (YP.nonvar(Term)) | ||
4001 | { | ||
4002 | foreach (bool l3 in YP.univ(Term, new ListPair(Name, TermArgs))) | ||
4003 | { | ||
4004 | if (YP.atom(Name)) | ||
4005 | { | ||
4006 | foreach (bool l5 in YP.unify(TermArgs, new ListPair(X1, Atom.NIL))) | ||
4007 | { | ||
4008 | foreach (bool l6 in unaryFunction(Name, FunctionName)) | ||
4009 | { | ||
4010 | foreach (bool l7 in compileExpression(X1, State, Arg1)) | ||
4011 | { | ||
4012 | foreach (bool l8 in YP.unify(Result, new Functor2("call", FunctionName, new ListPair(Arg1, Atom.NIL)))) | ||
4013 | { | ||
4014 | yield return true; | ||
4015 | yield break; | ||
4016 | } | ||
4017 | } | ||
4018 | goto cutIf1; | ||
4019 | } | ||
4020 | } | ||
4021 | foreach (bool l5 in YP.unify(Term, new ListPair(x9, Atom.NIL))) | ||
4022 | { | ||
4023 | foreach (bool l6 in compileTerm(Term, State, Result)) | ||
4024 | { | ||
4025 | yield return true; | ||
4026 | yield break; | ||
4027 | } | ||
4028 | goto cutIf2; | ||
4029 | } | ||
4030 | foreach (bool l5 in YP.unify(TermArgs, new ListPair(X1, new ListPair(X2, Atom.NIL)))) | ||
4031 | { | ||
4032 | foreach (bool l6 in binaryFunction(Name, FunctionName)) | ||
4033 | { | ||
4034 | foreach (bool l7 in compileExpression(X1, State, Arg1)) | ||
4035 | { | ||
4036 | foreach (bool l8 in compileExpression(X2, State, Arg2)) | ||
4037 | { | ||
4038 | foreach (bool l9 in YP.unify(Result, new Functor2("call", FunctionName, new ListPair(Arg1, new ListPair(Arg2, Atom.NIL))))) | ||
4039 | { | ||
4040 | yield return true; | ||
4041 | yield break; | ||
4042 | } | ||
4043 | } | ||
4044 | } | ||
4045 | goto cutIf3; | ||
4046 | } | ||
4047 | } | ||
4048 | foreach (bool l5 in YP.functor(Term, x12, Arity)) | ||
4049 | { | ||
4050 | YP.throwException(new Functor2("error", new Functor2("type_error", Atom.a("evaluable"), new Functor2("/", Name, Arity)), Atom.a("Not an expression function"))); | ||
4051 | yield return false; | ||
4052 | } | ||
4053 | cutIf3: | ||
4054 | cutIf2: | ||
4055 | cutIf1: | ||
4056 | { } | ||
4057 | } | ||
4058 | } | ||
4059 | } | ||
4060 | } | ||
4061 | { | ||
4062 | foreach (bool l2 in compileTerm(Term, State, Result)) | ||
4063 | { | ||
4064 | yield return true; | ||
4065 | yield break; | ||
4066 | } | ||
4067 | } | ||
4068 | } | ||
4069 | |||
4070 | public static IEnumerable<bool> unaryFunction(object arg1, object arg2) | ||
4071 | { | ||
4072 | { | ||
4073 | foreach (bool l2 in YP.unify(arg1, Atom.a("-"))) | ||
4074 | { | ||
4075 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.negate"))) | ||
4076 | { | ||
4077 | yield return true; | ||
4078 | yield break; | ||
4079 | } | ||
4080 | } | ||
4081 | } | ||
4082 | { | ||
4083 | foreach (bool l2 in YP.unify(arg1, Atom.a("abs"))) | ||
4084 | { | ||
4085 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.abs"))) | ||
4086 | { | ||
4087 | yield return true; | ||
4088 | yield break; | ||
4089 | } | ||
4090 | } | ||
4091 | } | ||
4092 | { | ||
4093 | foreach (bool l2 in YP.unify(arg1, Atom.a("sign"))) | ||
4094 | { | ||
4095 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.sign"))) | ||
4096 | { | ||
4097 | yield return true; | ||
4098 | yield break; | ||
4099 | } | ||
4100 | } | ||
4101 | } | ||
4102 | { | ||
4103 | foreach (bool l2 in YP.unify(arg1, Atom.a("float"))) | ||
4104 | { | ||
4105 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.toFloat"))) | ||
4106 | { | ||
4107 | yield return true; | ||
4108 | yield break; | ||
4109 | } | ||
4110 | } | ||
4111 | } | ||
4112 | { | ||
4113 | foreach (bool l2 in YP.unify(arg1, Atom.a("floor"))) | ||
4114 | { | ||
4115 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.floor"))) | ||
4116 | { | ||
4117 | yield return true; | ||
4118 | yield break; | ||
4119 | } | ||
4120 | } | ||
4121 | } | ||
4122 | { | ||
4123 | foreach (bool l2 in YP.unify(arg1, Atom.a("truncate"))) | ||
4124 | { | ||
4125 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.truncate"))) | ||
4126 | { | ||
4127 | yield return true; | ||
4128 | yield break; | ||
4129 | } | ||
4130 | } | ||
4131 | } | ||
4132 | { | ||
4133 | foreach (bool l2 in YP.unify(arg1, Atom.a("round"))) | ||
4134 | { | ||
4135 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.round"))) | ||
4136 | { | ||
4137 | yield return true; | ||
4138 | yield break; | ||
4139 | } | ||
4140 | } | ||
4141 | } | ||
4142 | { | ||
4143 | foreach (bool l2 in YP.unify(arg1, Atom.a("ceiling"))) | ||
4144 | { | ||
4145 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.ceiling"))) | ||
4146 | { | ||
4147 | yield return true; | ||
4148 | yield break; | ||
4149 | } | ||
4150 | } | ||
4151 | } | ||
4152 | { | ||
4153 | foreach (bool l2 in YP.unify(arg1, Atom.a("sin"))) | ||
4154 | { | ||
4155 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.sin"))) | ||
4156 | { | ||
4157 | yield return true; | ||
4158 | yield break; | ||
4159 | } | ||
4160 | } | ||
4161 | } | ||
4162 | { | ||
4163 | foreach (bool l2 in YP.unify(arg1, Atom.a("cos"))) | ||
4164 | { | ||
4165 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.cos"))) | ||
4166 | { | ||
4167 | yield return true; | ||
4168 | yield break; | ||
4169 | } | ||
4170 | } | ||
4171 | } | ||
4172 | { | ||
4173 | foreach (bool l2 in YP.unify(arg1, Atom.a("atan"))) | ||
4174 | { | ||
4175 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.atan"))) | ||
4176 | { | ||
4177 | yield return true; | ||
4178 | yield break; | ||
4179 | } | ||
4180 | } | ||
4181 | } | ||
4182 | { | ||
4183 | foreach (bool l2 in YP.unify(arg1, Atom.a("exp"))) | ||
4184 | { | ||
4185 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.exp"))) | ||
4186 | { | ||
4187 | yield return true; | ||
4188 | yield break; | ||
4189 | } | ||
4190 | } | ||
4191 | } | ||
4192 | { | ||
4193 | foreach (bool l2 in YP.unify(arg1, Atom.a("log"))) | ||
4194 | { | ||
4195 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.log"))) | ||
4196 | { | ||
4197 | yield return true; | ||
4198 | yield break; | ||
4199 | } | ||
4200 | } | ||
4201 | } | ||
4202 | { | ||
4203 | foreach (bool l2 in YP.unify(arg1, Atom.a("sqrt"))) | ||
4204 | { | ||
4205 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.sqrt"))) | ||
4206 | { | ||
4207 | yield return true; | ||
4208 | yield break; | ||
4209 | } | ||
4210 | } | ||
4211 | } | ||
4212 | { | ||
4213 | foreach (bool l2 in YP.unify(arg1, Atom.a("\\"))) | ||
4214 | { | ||
4215 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.bitwiseComplement"))) | ||
4216 | { | ||
4217 | yield return true; | ||
4218 | yield break; | ||
4219 | } | ||
4220 | } | ||
4221 | } | ||
4222 | } | ||
4223 | |||
4224 | public static IEnumerable<bool> binaryFunction(object arg1, object arg2) | ||
4225 | { | ||
4226 | { | ||
4227 | foreach (bool l2 in YP.unify(arg1, Atom.a("+"))) | ||
4228 | { | ||
4229 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.add"))) | ||
4230 | { | ||
4231 | yield return true; | ||
4232 | yield break; | ||
4233 | } | ||
4234 | } | ||
4235 | } | ||
4236 | { | ||
4237 | foreach (bool l2 in YP.unify(arg1, Atom.a("-"))) | ||
4238 | { | ||
4239 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.subtract"))) | ||
4240 | { | ||
4241 | yield return true; | ||
4242 | yield break; | ||
4243 | } | ||
4244 | } | ||
4245 | } | ||
4246 | { | ||
4247 | foreach (bool l2 in YP.unify(arg1, Atom.a("*"))) | ||
4248 | { | ||
4249 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.multiply"))) | ||
4250 | { | ||
4251 | yield return true; | ||
4252 | yield break; | ||
4253 | } | ||
4254 | } | ||
4255 | } | ||
4256 | { | ||
4257 | foreach (bool l2 in YP.unify(arg1, Atom.a("/"))) | ||
4258 | { | ||
4259 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.divide"))) | ||
4260 | { | ||
4261 | yield return true; | ||
4262 | yield break; | ||
4263 | } | ||
4264 | } | ||
4265 | } | ||
4266 | { | ||
4267 | foreach (bool l2 in YP.unify(arg1, Atom.a("//"))) | ||
4268 | { | ||
4269 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.intDivide"))) | ||
4270 | { | ||
4271 | yield return true; | ||
4272 | yield break; | ||
4273 | } | ||
4274 | } | ||
4275 | } | ||
4276 | { | ||
4277 | foreach (bool l2 in YP.unify(arg1, Atom.a("mod"))) | ||
4278 | { | ||
4279 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.mod"))) | ||
4280 | { | ||
4281 | yield return true; | ||
4282 | yield break; | ||
4283 | } | ||
4284 | } | ||
4285 | } | ||
4286 | { | ||
4287 | foreach (bool l2 in YP.unify(arg1, Atom.a("**"))) | ||
4288 | { | ||
4289 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.pow"))) | ||
4290 | { | ||
4291 | yield return true; | ||
4292 | yield break; | ||
4293 | } | ||
4294 | } | ||
4295 | } | ||
4296 | { | ||
4297 | foreach (bool l2 in YP.unify(arg1, Atom.a(">>"))) | ||
4298 | { | ||
4299 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.bitwiseShiftRight"))) | ||
4300 | { | ||
4301 | yield return true; | ||
4302 | yield break; | ||
4303 | } | ||
4304 | } | ||
4305 | } | ||
4306 | { | ||
4307 | foreach (bool l2 in YP.unify(arg1, Atom.a("<<"))) | ||
4308 | { | ||
4309 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.bitwiseShiftLeft"))) | ||
4310 | { | ||
4311 | yield return true; | ||
4312 | yield break; | ||
4313 | } | ||
4314 | } | ||
4315 | } | ||
4316 | { | ||
4317 | foreach (bool l2 in YP.unify(arg1, Atom.a("/\\"))) | ||
4318 | { | ||
4319 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.bitwiseAnd"))) | ||
4320 | { | ||
4321 | yield return true; | ||
4322 | yield break; | ||
4323 | } | ||
4324 | } | ||
4325 | } | ||
4326 | { | ||
4327 | foreach (bool l2 in YP.unify(arg1, Atom.a("\\/"))) | ||
4328 | { | ||
4329 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.bitwiseOr"))) | ||
4330 | { | ||
4331 | yield return true; | ||
4332 | yield break; | ||
4333 | } | ||
4334 | } | ||
4335 | } | ||
4336 | { | ||
4337 | foreach (bool l2 in YP.unify(arg1, Atom.a("min"))) | ||
4338 | { | ||
4339 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.min"))) | ||
4340 | { | ||
4341 | yield return true; | ||
4342 | yield break; | ||
4343 | } | ||
4344 | } | ||
4345 | } | ||
4346 | { | ||
4347 | foreach (bool l2 in YP.unify(arg1, Atom.a("max"))) | ||
4348 | { | ||
4349 | foreach (bool l3 in YP.unify(arg2, Atom.a("YP.max"))) | ||
4350 | { | ||
4351 | yield return true; | ||
4352 | yield break; | ||
4353 | } | ||
4354 | } | ||
4355 | } | ||
4356 | } | ||
4357 | |||
4358 | public static void convertFunctionCSharp(object arg1) | ||
4359 | { | ||
4360 | { | ||
4361 | foreach (bool l2 in YP.unify(arg1, Atom.a("getDeclaringClass"))) | ||
4362 | { | ||
4363 | YP.write(Atom.a("public class YPInnerClass {}")); | ||
4364 | YP.nl(); | ||
4365 | YP.write(Atom.a("public static System.Type getDeclaringClass() { return typeof(YPInnerClass).DeclaringType; }")); | ||
4366 | YP.nl(); | ||
4367 | YP.nl(); | ||
4368 | return; | ||
4369 | } | ||
4370 | } | ||
4371 | { | ||
4372 | Variable ReturnType = new Variable(); | ||
4373 | Variable Name = new Variable(); | ||
4374 | Variable ArgList = new Variable(); | ||
4375 | Variable Body = new Variable(); | ||
4376 | Variable Level = new Variable(); | ||
4377 | foreach (bool l2 in YP.unify(arg1, new Functor("function", new object[] { ReturnType, Name, ArgList, Body }))) | ||
4378 | { | ||
4379 | YP.write(Atom.a("public static ")); | ||
4380 | YP.write(ReturnType); | ||
4381 | YP.write(Atom.a(" ")); | ||
4382 | YP.write(Name); | ||
4383 | YP.write(Atom.a("(")); | ||
4384 | convertArgListCSharp(ArgList); | ||
4385 | YP.write(Atom.a(") {")); | ||
4386 | YP.nl(); | ||
4387 | foreach (bool l3 in YP.unify(Level, 1)) | ||
4388 | { | ||
4389 | convertStatementListCSharp(Body, Level); | ||
4390 | YP.write(Atom.a("}")); | ||
4391 | YP.nl(); | ||
4392 | YP.nl(); | ||
4393 | return; | ||
4394 | } | ||
4395 | } | ||
4396 | } | ||
4397 | } | ||
4398 | |||
4399 | public static IEnumerable<bool> convertStatementListCSharp(object arg1, object x1, object x2) | ||
4400 | { | ||
4401 | { | ||
4402 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
4403 | { | ||
4404 | yield return true; | ||
4405 | yield break; | ||
4406 | } | ||
4407 | } | ||
4408 | } | ||
4409 | |||
4410 | public static void convertStatementListCSharp(object arg1, object Level) | ||
4411 | { | ||
4412 | { | ||
4413 | Variable Name = new Variable(); | ||
4414 | Variable Body = new Variable(); | ||
4415 | Variable RestStatements = new Variable(); | ||
4416 | Variable NewStatements = new Variable(); | ||
4417 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("breakableBlock", Name, Body), RestStatements))) | ||
4418 | { | ||
4419 | foreach (bool l3 in append(Body, new ListPair(new Functor1("label", Name), RestStatements), NewStatements)) | ||
4420 | { | ||
4421 | convertStatementListCSharp(NewStatements, Level); | ||
4422 | return; | ||
4423 | } | ||
4424 | } | ||
4425 | } | ||
4426 | { | ||
4427 | Variable Type = new Variable(); | ||
4428 | Variable Name = new Variable(); | ||
4429 | Variable Expression = new Variable(); | ||
4430 | Variable RestStatements = new Variable(); | ||
4431 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("declare", Type, Name, Expression), RestStatements))) | ||
4432 | { | ||
4433 | convertIndentationCSharp(Level); | ||
4434 | YP.write(Type); | ||
4435 | YP.write(Atom.a(" ")); | ||
4436 | YP.write(Name); | ||
4437 | YP.write(Atom.a(" = ")); | ||
4438 | convertExpressionCSharp(Expression); | ||
4439 | YP.write(Atom.a(";")); | ||
4440 | YP.nl(); | ||
4441 | convertStatementListCSharp(RestStatements, Level); | ||
4442 | return; | ||
4443 | } | ||
4444 | } | ||
4445 | { | ||
4446 | Variable Name = new Variable(); | ||
4447 | Variable Expression = new Variable(); | ||
4448 | Variable RestStatements = new Variable(); | ||
4449 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("assign", Name, Expression), RestStatements))) | ||
4450 | { | ||
4451 | convertIndentationCSharp(Level); | ||
4452 | YP.write(Name); | ||
4453 | YP.write(Atom.a(" = ")); | ||
4454 | convertExpressionCSharp(Expression); | ||
4455 | YP.write(Atom.a(";")); | ||
4456 | YP.nl(); | ||
4457 | convertStatementListCSharp(RestStatements, Level); | ||
4458 | return; | ||
4459 | } | ||
4460 | } | ||
4461 | { | ||
4462 | Variable RestStatements = new Variable(); | ||
4463 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldtrue"), RestStatements))) | ||
4464 | { | ||
4465 | convertIndentationCSharp(Level); | ||
4466 | YP.write(Atom.a("yield return true;")); | ||
4467 | YP.nl(); | ||
4468 | convertStatementListCSharp(RestStatements, Level); | ||
4469 | return; | ||
4470 | } | ||
4471 | } | ||
4472 | { | ||
4473 | Variable RestStatements = new Variable(); | ||
4474 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldfalse"), RestStatements))) | ||
4475 | { | ||
4476 | convertIndentationCSharp(Level); | ||
4477 | YP.write(Atom.a("yield return false;")); | ||
4478 | YP.nl(); | ||
4479 | convertStatementListCSharp(RestStatements, Level); | ||
4480 | return; | ||
4481 | } | ||
4482 | } | ||
4483 | { | ||
4484 | Variable RestStatements = new Variable(); | ||
4485 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldbreak"), RestStatements))) | ||
4486 | { | ||
4487 | convertIndentationCSharp(Level); | ||
4488 | YP.write(Atom.a("yield break;")); | ||
4489 | YP.nl(); | ||
4490 | convertStatementListCSharp(RestStatements, Level); | ||
4491 | return; | ||
4492 | } | ||
4493 | } | ||
4494 | { | ||
4495 | Variable RestStatements = new Variable(); | ||
4496 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("return"), RestStatements))) | ||
4497 | { | ||
4498 | convertIndentationCSharp(Level); | ||
4499 | YP.write(Atom.a("return;")); | ||
4500 | YP.nl(); | ||
4501 | convertStatementListCSharp(RestStatements, Level); | ||
4502 | return; | ||
4503 | } | ||
4504 | } | ||
4505 | { | ||
4506 | Variable RestStatements = new Variable(); | ||
4507 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("returntrue"), RestStatements))) | ||
4508 | { | ||
4509 | convertIndentationCSharp(Level); | ||
4510 | YP.write(Atom.a("return true;")); | ||
4511 | YP.nl(); | ||
4512 | convertStatementListCSharp(RestStatements, Level); | ||
4513 | return; | ||
4514 | } | ||
4515 | } | ||
4516 | { | ||
4517 | Variable RestStatements = new Variable(); | ||
4518 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("returnfalse"), RestStatements))) | ||
4519 | { | ||
4520 | convertIndentationCSharp(Level); | ||
4521 | YP.write(Atom.a("return false;")); | ||
4522 | YP.nl(); | ||
4523 | convertStatementListCSharp(RestStatements, Level); | ||
4524 | return; | ||
4525 | } | ||
4526 | } | ||
4527 | { | ||
4528 | Variable Name = new Variable(); | ||
4529 | Variable RestStatements = new Variable(); | ||
4530 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("label", Name), RestStatements))) | ||
4531 | { | ||
4532 | convertIndentationCSharp(Level); | ||
4533 | YP.write(Name); | ||
4534 | YP.write(Atom.a(":")); | ||
4535 | YP.nl(); | ||
4536 | if (YP.termEqual(RestStatements, Atom.NIL)) | ||
4537 | { | ||
4538 | convertIndentationCSharp(Level); | ||
4539 | YP.write(Atom.a("{}")); | ||
4540 | YP.nl(); | ||
4541 | convertStatementListCSharp(RestStatements, Level); | ||
4542 | return; | ||
4543 | goto cutIf1; | ||
4544 | } | ||
4545 | convertStatementListCSharp(RestStatements, Level); | ||
4546 | return; | ||
4547 | cutIf1: | ||
4548 | { } | ||
4549 | } | ||
4550 | } | ||
4551 | { | ||
4552 | Variable Name = new Variable(); | ||
4553 | Variable RestStatements = new Variable(); | ||
4554 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("breakBlock", Name), RestStatements))) | ||
4555 | { | ||
4556 | convertIndentationCSharp(Level); | ||
4557 | YP.write(Atom.a("goto ")); | ||
4558 | YP.write(Name); | ||
4559 | YP.write(Atom.a(";")); | ||
4560 | YP.nl(); | ||
4561 | convertStatementListCSharp(RestStatements, Level); | ||
4562 | return; | ||
4563 | } | ||
4564 | } | ||
4565 | { | ||
4566 | Variable Name = new Variable(); | ||
4567 | Variable ArgList = new Variable(); | ||
4568 | Variable RestStatements = new Variable(); | ||
4569 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("call", Name, ArgList), RestStatements))) | ||
4570 | { | ||
4571 | convertIndentationCSharp(Level); | ||
4572 | YP.write(Name); | ||
4573 | YP.write(Atom.a("(")); | ||
4574 | convertArgListCSharp(ArgList); | ||
4575 | YP.write(Atom.a(");")); | ||
4576 | YP.nl(); | ||
4577 | convertStatementListCSharp(RestStatements, Level); | ||
4578 | return; | ||
4579 | } | ||
4580 | } | ||
4581 | { | ||
4582 | Variable Name = new Variable(); | ||
4583 | Variable _FunctorArgs = new Variable(); | ||
4584 | Variable ArgList = new Variable(); | ||
4585 | Variable RestStatements = new Variable(); | ||
4586 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("functorCall", Name, _FunctorArgs, ArgList), RestStatements))) | ||
4587 | { | ||
4588 | convertStatementListCSharp(new ListPair(new Functor2("call", Name, ArgList), RestStatements), Level); | ||
4589 | return; | ||
4590 | } | ||
4591 | } | ||
4592 | { | ||
4593 | Variable Obj = new Variable(); | ||
4594 | Variable Name = new Variable(); | ||
4595 | Variable ArgList = new Variable(); | ||
4596 | Variable RestStatements = new Variable(); | ||
4597 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("callMember", new Functor1("var", Obj), Name, ArgList), RestStatements))) | ||
4598 | { | ||
4599 | convertIndentationCSharp(Level); | ||
4600 | YP.write(Obj); | ||
4601 | YP.write(Atom.a(".")); | ||
4602 | YP.write(Name); | ||
4603 | YP.write(Atom.a("(")); | ||
4604 | convertArgListCSharp(ArgList); | ||
4605 | YP.write(Atom.a(");")); | ||
4606 | YP.nl(); | ||
4607 | convertStatementListCSharp(RestStatements, Level); | ||
4608 | return; | ||
4609 | } | ||
4610 | } | ||
4611 | { | ||
4612 | Variable Body = new Variable(); | ||
4613 | Variable RestStatements = new Variable(); | ||
4614 | Variable NextLevel = new Variable(); | ||
4615 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("blockScope", Body), RestStatements))) | ||
4616 | { | ||
4617 | convertIndentationCSharp(Level); | ||
4618 | YP.write(Atom.a("{")); | ||
4619 | YP.nl(); | ||
4620 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4621 | { | ||
4622 | convertStatementListCSharp(Body, NextLevel); | ||
4623 | convertIndentationCSharp(Level); | ||
4624 | YP.write(Atom.a("}")); | ||
4625 | YP.nl(); | ||
4626 | convertStatementListCSharp(RestStatements, Level); | ||
4627 | return; | ||
4628 | } | ||
4629 | } | ||
4630 | } | ||
4631 | { | ||
4632 | Variable Expression = new Variable(); | ||
4633 | Variable Body = new Variable(); | ||
4634 | Variable RestStatements = new Variable(); | ||
4635 | Variable NextLevel = new Variable(); | ||
4636 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("if", Expression, Body), RestStatements))) | ||
4637 | { | ||
4638 | convertIndentationCSharp(Level); | ||
4639 | YP.write(Atom.a("if (")); | ||
4640 | convertExpressionCSharp(Expression); | ||
4641 | YP.write(Atom.a(") {")); | ||
4642 | YP.nl(); | ||
4643 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4644 | { | ||
4645 | convertStatementListCSharp(Body, NextLevel); | ||
4646 | convertIndentationCSharp(Level); | ||
4647 | YP.write(Atom.a("}")); | ||
4648 | YP.nl(); | ||
4649 | convertStatementListCSharp(RestStatements, Level); | ||
4650 | return; | ||
4651 | } | ||
4652 | } | ||
4653 | } | ||
4654 | { | ||
4655 | Variable Expression = new Variable(); | ||
4656 | Variable Body = new Variable(); | ||
4657 | Variable RestStatements = new Variable(); | ||
4658 | Variable NextLevel = new Variable(); | ||
4659 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("foreach", Expression, Body), RestStatements))) | ||
4660 | { | ||
4661 | convertIndentationCSharp(Level); | ||
4662 | YP.write(Atom.a("foreach (bool l")); | ||
4663 | YP.write(Level); | ||
4664 | YP.write(Atom.a(" in ")); | ||
4665 | convertExpressionCSharp(Expression); | ||
4666 | YP.write(Atom.a(") {")); | ||
4667 | YP.nl(); | ||
4668 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4669 | { | ||
4670 | convertStatementListCSharp(Body, NextLevel); | ||
4671 | convertIndentationCSharp(Level); | ||
4672 | YP.write(Atom.a("}")); | ||
4673 | YP.nl(); | ||
4674 | convertStatementListCSharp(RestStatements, Level); | ||
4675 | return; | ||
4676 | } | ||
4677 | } | ||
4678 | } | ||
4679 | { | ||
4680 | Variable Expression = new Variable(); | ||
4681 | Variable RestStatements = new Variable(); | ||
4682 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("throw", Expression), RestStatements))) | ||
4683 | { | ||
4684 | convertIndentationCSharp(Level); | ||
4685 | YP.write(Atom.a("throw ")); | ||
4686 | convertExpressionCSharp(Expression); | ||
4687 | YP.write(Atom.a(";")); | ||
4688 | YP.nl(); | ||
4689 | convertStatementListCSharp(RestStatements, Level); | ||
4690 | return; | ||
4691 | } | ||
4692 | } | ||
4693 | } | ||
4694 | |||
4695 | public static void convertIndentationCSharp(object Level) | ||
4696 | { | ||
4697 | { | ||
4698 | Variable N = new Variable(); | ||
4699 | foreach (bool l2 in YP.unify(N, YP.multiply(Level, 2))) | ||
4700 | { | ||
4701 | repeatWrite(Atom.a(" "), N); | ||
4702 | return; | ||
4703 | } | ||
4704 | } | ||
4705 | } | ||
4706 | |||
4707 | public static void convertArgListCSharp(object arg1) | ||
4708 | { | ||
4709 | { | ||
4710 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
4711 | { | ||
4712 | return; | ||
4713 | } | ||
4714 | } | ||
4715 | { | ||
4716 | Variable Head = new Variable(); | ||
4717 | Variable Tail = new Variable(); | ||
4718 | foreach (bool l2 in YP.unify(arg1, new ListPair(Head, Tail))) | ||
4719 | { | ||
4720 | convertExpressionCSharp(Head); | ||
4721 | if (YP.termNotEqual(Tail, Atom.NIL)) | ||
4722 | { | ||
4723 | YP.write(Atom.a(", ")); | ||
4724 | convertArgListCSharp(Tail); | ||
4725 | return; | ||
4726 | goto cutIf1; | ||
4727 | } | ||
4728 | convertArgListCSharp(Tail); | ||
4729 | return; | ||
4730 | cutIf1: | ||
4731 | { } | ||
4732 | } | ||
4733 | } | ||
4734 | } | ||
4735 | |||
4736 | public static void convertExpressionCSharp(object arg1) | ||
4737 | { | ||
4738 | { | ||
4739 | Variable X = new Variable(); | ||
4740 | foreach (bool l2 in YP.unify(arg1, new Functor1("arg", X))) | ||
4741 | { | ||
4742 | YP.write(Atom.a("object ")); | ||
4743 | YP.write(X); | ||
4744 | return; | ||
4745 | } | ||
4746 | } | ||
4747 | { | ||
4748 | Variable Name = new Variable(); | ||
4749 | Variable ArgList = new Variable(); | ||
4750 | foreach (bool l2 in YP.unify(arg1, new Functor2("call", Name, ArgList))) | ||
4751 | { | ||
4752 | YP.write(Name); | ||
4753 | YP.write(Atom.a("(")); | ||
4754 | convertArgListCSharp(ArgList); | ||
4755 | YP.write(Atom.a(")")); | ||
4756 | return; | ||
4757 | } | ||
4758 | } | ||
4759 | { | ||
4760 | Variable Name = new Variable(); | ||
4761 | Variable _FunctorArgs = new Variable(); | ||
4762 | Variable ArgList = new Variable(); | ||
4763 | foreach (bool l2 in YP.unify(arg1, new Functor3("functorCall", Name, _FunctorArgs, ArgList))) | ||
4764 | { | ||
4765 | convertExpressionCSharp(new Functor2("call", Name, ArgList)); | ||
4766 | return; | ||
4767 | } | ||
4768 | } | ||
4769 | { | ||
4770 | Variable Obj = new Variable(); | ||
4771 | Variable Name = new Variable(); | ||
4772 | Variable ArgList = new Variable(); | ||
4773 | foreach (bool l2 in YP.unify(arg1, new Functor3("callMember", new Functor1("var", Obj), Name, ArgList))) | ||
4774 | { | ||
4775 | YP.write(Obj); | ||
4776 | YP.write(Atom.a(".")); | ||
4777 | YP.write(Name); | ||
4778 | YP.write(Atom.a("(")); | ||
4779 | convertArgListCSharp(ArgList); | ||
4780 | YP.write(Atom.a(")")); | ||
4781 | return; | ||
4782 | } | ||
4783 | } | ||
4784 | { | ||
4785 | Variable Name = new Variable(); | ||
4786 | Variable ArgList = new Variable(); | ||
4787 | foreach (bool l2 in YP.unify(arg1, new Functor2("new", Name, ArgList))) | ||
4788 | { | ||
4789 | YP.write(Atom.a("new ")); | ||
4790 | YP.write(Name); | ||
4791 | YP.write(Atom.a("(")); | ||
4792 | convertArgListCSharp(ArgList); | ||
4793 | YP.write(Atom.a(")")); | ||
4794 | return; | ||
4795 | } | ||
4796 | } | ||
4797 | { | ||
4798 | Variable Name = new Variable(); | ||
4799 | foreach (bool l2 in YP.unify(arg1, new Functor1("var", Name))) | ||
4800 | { | ||
4801 | YP.write(Name); | ||
4802 | return; | ||
4803 | } | ||
4804 | } | ||
4805 | { | ||
4806 | foreach (bool l2 in YP.unify(arg1, Atom.a("null"))) | ||
4807 | { | ||
4808 | YP.write(Atom.a("null")); | ||
4809 | return; | ||
4810 | } | ||
4811 | } | ||
4812 | { | ||
4813 | Variable X = new Variable(); | ||
4814 | foreach (bool l2 in YP.unify(arg1, new Functor1("not", X))) | ||
4815 | { | ||
4816 | YP.write(Atom.a("!(")); | ||
4817 | convertExpressionCSharp(X); | ||
4818 | YP.write(Atom.a(")")); | ||
4819 | return; | ||
4820 | } | ||
4821 | } | ||
4822 | { | ||
4823 | Variable X = new Variable(); | ||
4824 | Variable Y = new Variable(); | ||
4825 | foreach (bool l2 in YP.unify(arg1, new Functor2("and", X, Y))) | ||
4826 | { | ||
4827 | YP.write(Atom.a("(")); | ||
4828 | convertExpressionCSharp(X); | ||
4829 | YP.write(Atom.a(") && (")); | ||
4830 | convertExpressionCSharp(Y); | ||
4831 | YP.write(Atom.a(")")); | ||
4832 | return; | ||
4833 | } | ||
4834 | } | ||
4835 | { | ||
4836 | Variable ArgList = new Variable(); | ||
4837 | foreach (bool l2 in YP.unify(arg1, new Functor1("objectArray", ArgList))) | ||
4838 | { | ||
4839 | YP.write(Atom.a("new object[] {")); | ||
4840 | convertArgListCSharp(ArgList); | ||
4841 | YP.write(Atom.a("}")); | ||
4842 | return; | ||
4843 | } | ||
4844 | } | ||
4845 | { | ||
4846 | Variable X = new Variable(); | ||
4847 | Variable Codes = new Variable(); | ||
4848 | foreach (bool l2 in YP.unify(arg1, new Functor1("object", X))) | ||
4849 | { | ||
4850 | if (YP.atom(X)) | ||
4851 | { | ||
4852 | YP.write(Atom.a("\"")); | ||
4853 | foreach (bool l4 in YP.atom_codes(X, Codes)) | ||
4854 | { | ||
4855 | convertStringCodesCSharp(Codes); | ||
4856 | YP.write(Atom.a("\"")); | ||
4857 | return; | ||
4858 | } | ||
4859 | } | ||
4860 | } | ||
4861 | } | ||
4862 | { | ||
4863 | Variable X = new Variable(); | ||
4864 | foreach (bool l2 in YP.unify(arg1, new Functor1("object", X))) | ||
4865 | { | ||
4866 | YP.write(X); | ||
4867 | return; | ||
4868 | } | ||
4869 | } | ||
4870 | } | ||
4871 | |||
4872 | public static void convertStringCodesCSharp(object arg1) | ||
4873 | { | ||
4874 | { | ||
4875 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
4876 | { | ||
4877 | return; | ||
4878 | } | ||
4879 | } | ||
4880 | { | ||
4881 | Variable Code = new Variable(); | ||
4882 | Variable RestCodes = new Variable(); | ||
4883 | foreach (bool l2 in YP.unify(arg1, new ListPair(Code, RestCodes))) | ||
4884 | { | ||
4885 | foreach (bool l3 in putCStringCode(Code)) | ||
4886 | { | ||
4887 | convertStringCodesCSharp(RestCodes); | ||
4888 | return; | ||
4889 | } | ||
4890 | } | ||
4891 | } | ||
4892 | } | ||
4893 | |||
4894 | public static void convertFunctionJavascript(object arg1) | ||
4895 | { | ||
4896 | { | ||
4897 | foreach (bool l2 in YP.unify(arg1, Atom.a("getDeclaringClass"))) | ||
4898 | { | ||
4899 | YP.write(Atom.a("function getDeclaringClass() { return null; }")); | ||
4900 | YP.nl(); | ||
4901 | YP.nl(); | ||
4902 | return; | ||
4903 | } | ||
4904 | } | ||
4905 | { | ||
4906 | Variable x1 = new Variable(); | ||
4907 | Variable Name = new Variable(); | ||
4908 | Variable ArgList = new Variable(); | ||
4909 | Variable Body = new Variable(); | ||
4910 | foreach (bool l2 in YP.unify(arg1, new Functor("function", new object[] { x1, Name, ArgList, Body }))) | ||
4911 | { | ||
4912 | YP.write(Atom.a("function ")); | ||
4913 | YP.write(Name); | ||
4914 | YP.write(Atom.a("(")); | ||
4915 | convertArgListJavascript(ArgList); | ||
4916 | YP.write(Atom.a(") {")); | ||
4917 | YP.nl(); | ||
4918 | convertStatementListJavascript(Body, 1); | ||
4919 | YP.write(Atom.a("}")); | ||
4920 | YP.nl(); | ||
4921 | YP.nl(); | ||
4922 | return; | ||
4923 | } | ||
4924 | } | ||
4925 | } | ||
4926 | |||
4927 | public static void convertStatementListJavascript(object arg1, object arg2) | ||
4928 | { | ||
4929 | { | ||
4930 | object x1 = arg2; | ||
4931 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
4932 | { | ||
4933 | return; | ||
4934 | } | ||
4935 | } | ||
4936 | { | ||
4937 | object Level = arg2; | ||
4938 | Variable Name = new Variable(); | ||
4939 | Variable Body = new Variable(); | ||
4940 | Variable RestStatements = new Variable(); | ||
4941 | Variable NextLevel = new Variable(); | ||
4942 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("breakableBlock", Name, Body), RestStatements))) | ||
4943 | { | ||
4944 | convertIndentationJavascript(Level); | ||
4945 | YP.write(Name); | ||
4946 | YP.write(Atom.a(":")); | ||
4947 | YP.nl(); | ||
4948 | convertIndentationJavascript(Level); | ||
4949 | YP.write(Atom.a("{")); | ||
4950 | YP.nl(); | ||
4951 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
4952 | { | ||
4953 | convertStatementListJavascript(Body, NextLevel); | ||
4954 | convertIndentationJavascript(Level); | ||
4955 | YP.write(Atom.a("}")); | ||
4956 | YP.nl(); | ||
4957 | convertStatementListJavascript(RestStatements, Level); | ||
4958 | return; | ||
4959 | } | ||
4960 | } | ||
4961 | } | ||
4962 | { | ||
4963 | object Level = arg2; | ||
4964 | Variable _Type = new Variable(); | ||
4965 | Variable Name = new Variable(); | ||
4966 | Variable Expression = new Variable(); | ||
4967 | Variable RestStatements = new Variable(); | ||
4968 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("declare", _Type, Name, Expression), RestStatements))) | ||
4969 | { | ||
4970 | convertIndentationJavascript(Level); | ||
4971 | YP.write(Atom.a("var ")); | ||
4972 | YP.write(Name); | ||
4973 | YP.write(Atom.a(" = ")); | ||
4974 | convertExpressionJavascript(Expression); | ||
4975 | YP.write(Atom.a(";")); | ||
4976 | YP.nl(); | ||
4977 | convertStatementListJavascript(RestStatements, Level); | ||
4978 | return; | ||
4979 | } | ||
4980 | } | ||
4981 | { | ||
4982 | object Level = arg2; | ||
4983 | Variable Name = new Variable(); | ||
4984 | Variable Expression = new Variable(); | ||
4985 | Variable RestStatements = new Variable(); | ||
4986 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("assign", Name, Expression), RestStatements))) | ||
4987 | { | ||
4988 | convertIndentationJavascript(Level); | ||
4989 | YP.write(Name); | ||
4990 | YP.write(Atom.a(" = ")); | ||
4991 | convertExpressionJavascript(Expression); | ||
4992 | YP.write(Atom.a(";")); | ||
4993 | YP.nl(); | ||
4994 | convertStatementListJavascript(RestStatements, Level); | ||
4995 | return; | ||
4996 | } | ||
4997 | } | ||
4998 | { | ||
4999 | object Level = arg2; | ||
5000 | Variable RestStatements = new Variable(); | ||
5001 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldtrue"), RestStatements))) | ||
5002 | { | ||
5003 | convertIndentationJavascript(Level); | ||
5004 | YP.write(Atom.a("yield true;")); | ||
5005 | YP.nl(); | ||
5006 | convertStatementListJavascript(RestStatements, Level); | ||
5007 | return; | ||
5008 | } | ||
5009 | } | ||
5010 | { | ||
5011 | object Level = arg2; | ||
5012 | Variable RestStatements = new Variable(); | ||
5013 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldfalse"), RestStatements))) | ||
5014 | { | ||
5015 | convertIndentationJavascript(Level); | ||
5016 | YP.write(Atom.a("yield false;")); | ||
5017 | YP.nl(); | ||
5018 | convertStatementListJavascript(RestStatements, Level); | ||
5019 | return; | ||
5020 | } | ||
5021 | } | ||
5022 | { | ||
5023 | object Level = arg2; | ||
5024 | Variable RestStatements = new Variable(); | ||
5025 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldbreak"), RestStatements))) | ||
5026 | { | ||
5027 | convertIndentationJavascript(Level); | ||
5028 | YP.write(Atom.a("return;")); | ||
5029 | YP.nl(); | ||
5030 | convertStatementListJavascript(RestStatements, Level); | ||
5031 | return; | ||
5032 | } | ||
5033 | } | ||
5034 | { | ||
5035 | object Level = arg2; | ||
5036 | Variable RestStatements = new Variable(); | ||
5037 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("return"), RestStatements))) | ||
5038 | { | ||
5039 | convertIndentationJavascript(Level); | ||
5040 | YP.write(Atom.a("return;")); | ||
5041 | YP.nl(); | ||
5042 | convertStatementListJavascript(RestStatements, Level); | ||
5043 | return; | ||
5044 | } | ||
5045 | } | ||
5046 | { | ||
5047 | object Level = arg2; | ||
5048 | Variable RestStatements = new Variable(); | ||
5049 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("returntrue"), RestStatements))) | ||
5050 | { | ||
5051 | convertIndentationJavascript(Level); | ||
5052 | YP.write(Atom.a("return true;")); | ||
5053 | YP.nl(); | ||
5054 | convertStatementListJavascript(RestStatements, Level); | ||
5055 | return; | ||
5056 | } | ||
5057 | } | ||
5058 | { | ||
5059 | object Level = arg2; | ||
5060 | Variable RestStatements = new Variable(); | ||
5061 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("returnfalse"), RestStatements))) | ||
5062 | { | ||
5063 | convertIndentationJavascript(Level); | ||
5064 | YP.write(Atom.a("return false;")); | ||
5065 | YP.nl(); | ||
5066 | convertStatementListJavascript(RestStatements, Level); | ||
5067 | return; | ||
5068 | } | ||
5069 | } | ||
5070 | { | ||
5071 | object Level = arg2; | ||
5072 | Variable Name = new Variable(); | ||
5073 | Variable RestStatements = new Variable(); | ||
5074 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("breakBlock", Name), RestStatements))) | ||
5075 | { | ||
5076 | convertIndentationJavascript(Level); | ||
5077 | YP.write(Atom.a("break ")); | ||
5078 | YP.write(Name); | ||
5079 | YP.write(Atom.a(";")); | ||
5080 | YP.nl(); | ||
5081 | convertStatementListJavascript(RestStatements, Level); | ||
5082 | return; | ||
5083 | } | ||
5084 | } | ||
5085 | { | ||
5086 | object Level = arg2; | ||
5087 | Variable Name = new Variable(); | ||
5088 | Variable ArgList = new Variable(); | ||
5089 | Variable RestStatements = new Variable(); | ||
5090 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("call", Name, ArgList), RestStatements))) | ||
5091 | { | ||
5092 | convertIndentationJavascript(Level); | ||
5093 | YP.write(Name); | ||
5094 | YP.write(Atom.a("(")); | ||
5095 | convertArgListJavascript(ArgList); | ||
5096 | YP.write(Atom.a(");")); | ||
5097 | YP.nl(); | ||
5098 | convertStatementListJavascript(RestStatements, Level); | ||
5099 | return; | ||
5100 | } | ||
5101 | } | ||
5102 | { | ||
5103 | object Level = arg2; | ||
5104 | Variable Name = new Variable(); | ||
5105 | Variable _FunctorArgs = new Variable(); | ||
5106 | Variable ArgList = new Variable(); | ||
5107 | Variable RestStatements = new Variable(); | ||
5108 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("functorCall", Name, _FunctorArgs, ArgList), RestStatements))) | ||
5109 | { | ||
5110 | convertStatementListJavascript(new ListPair(new Functor2("call", Name, ArgList), RestStatements), Level); | ||
5111 | return; | ||
5112 | } | ||
5113 | } | ||
5114 | { | ||
5115 | object Level = arg2; | ||
5116 | Variable Obj = new Variable(); | ||
5117 | Variable Name = new Variable(); | ||
5118 | Variable ArgList = new Variable(); | ||
5119 | Variable RestStatements = new Variable(); | ||
5120 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("callMember", new Functor1("var", Obj), Name, ArgList), RestStatements))) | ||
5121 | { | ||
5122 | convertIndentationJavascript(Level); | ||
5123 | YP.write(Obj); | ||
5124 | YP.write(Atom.a(".")); | ||
5125 | YP.write(Name); | ||
5126 | YP.write(Atom.a("(")); | ||
5127 | convertArgListJavascript(ArgList); | ||
5128 | YP.write(Atom.a(");")); | ||
5129 | YP.nl(); | ||
5130 | convertStatementListJavascript(RestStatements, Level); | ||
5131 | return; | ||
5132 | } | ||
5133 | } | ||
5134 | { | ||
5135 | object Level = arg2; | ||
5136 | Variable Body = new Variable(); | ||
5137 | Variable RestStatements = new Variable(); | ||
5138 | Variable NextLevel = new Variable(); | ||
5139 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("blockScope", Body), RestStatements))) | ||
5140 | { | ||
5141 | convertIndentationJavascript(Level); | ||
5142 | YP.write(Atom.a("{")); | ||
5143 | YP.nl(); | ||
5144 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
5145 | { | ||
5146 | convertStatementListJavascript(Body, NextLevel); | ||
5147 | convertIndentationJavascript(Level); | ||
5148 | YP.write(Atom.a("}")); | ||
5149 | YP.nl(); | ||
5150 | convertStatementListJavascript(RestStatements, Level); | ||
5151 | return; | ||
5152 | } | ||
5153 | } | ||
5154 | } | ||
5155 | { | ||
5156 | object Level = arg2; | ||
5157 | Variable Expression = new Variable(); | ||
5158 | Variable Body = new Variable(); | ||
5159 | Variable RestStatements = new Variable(); | ||
5160 | Variable NextLevel = new Variable(); | ||
5161 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("if", Expression, Body), RestStatements))) | ||
5162 | { | ||
5163 | convertIndentationJavascript(Level); | ||
5164 | YP.write(Atom.a("if (")); | ||
5165 | convertExpressionJavascript(Expression); | ||
5166 | YP.write(Atom.a(") {")); | ||
5167 | YP.nl(); | ||
5168 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
5169 | { | ||
5170 | convertStatementListJavascript(Body, NextLevel); | ||
5171 | convertIndentationJavascript(Level); | ||
5172 | YP.write(Atom.a("}")); | ||
5173 | YP.nl(); | ||
5174 | convertStatementListJavascript(RestStatements, Level); | ||
5175 | return; | ||
5176 | } | ||
5177 | } | ||
5178 | } | ||
5179 | { | ||
5180 | object Level = arg2; | ||
5181 | Variable Expression = new Variable(); | ||
5182 | Variable Body = new Variable(); | ||
5183 | Variable RestStatements = new Variable(); | ||
5184 | Variable NextLevel = new Variable(); | ||
5185 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("foreach", Expression, Body), RestStatements))) | ||
5186 | { | ||
5187 | convertIndentationJavascript(Level); | ||
5188 | YP.write(Atom.a("for each (var l")); | ||
5189 | YP.write(Level); | ||
5190 | YP.write(Atom.a(" in ")); | ||
5191 | convertExpressionJavascript(Expression); | ||
5192 | YP.write(Atom.a(") {")); | ||
5193 | YP.nl(); | ||
5194 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
5195 | { | ||
5196 | convertStatementListJavascript(Body, NextLevel); | ||
5197 | convertIndentationJavascript(Level); | ||
5198 | YP.write(Atom.a("}")); | ||
5199 | YP.nl(); | ||
5200 | convertStatementListJavascript(RestStatements, Level); | ||
5201 | return; | ||
5202 | } | ||
5203 | } | ||
5204 | } | ||
5205 | { | ||
5206 | object Level = arg2; | ||
5207 | Variable Expression = new Variable(); | ||
5208 | Variable RestStatements = new Variable(); | ||
5209 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("throw", Expression), RestStatements))) | ||
5210 | { | ||
5211 | convertIndentationJavascript(Level); | ||
5212 | YP.write(Atom.a("throw ")); | ||
5213 | convertExpressionJavascript(Expression); | ||
5214 | YP.write(Atom.a(";")); | ||
5215 | YP.nl(); | ||
5216 | convertStatementListJavascript(RestStatements, Level); | ||
5217 | return; | ||
5218 | } | ||
5219 | } | ||
5220 | } | ||
5221 | |||
5222 | public static void convertIndentationJavascript(object Level) | ||
5223 | { | ||
5224 | { | ||
5225 | Variable N = new Variable(); | ||
5226 | foreach (bool l2 in YP.unify(N, YP.multiply(Level, 2))) | ||
5227 | { | ||
5228 | repeatWrite(Atom.a(" "), N); | ||
5229 | return; | ||
5230 | } | ||
5231 | } | ||
5232 | } | ||
5233 | |||
5234 | public static void convertArgListJavascript(object arg1) | ||
5235 | { | ||
5236 | { | ||
5237 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
5238 | { | ||
5239 | return; | ||
5240 | } | ||
5241 | } | ||
5242 | { | ||
5243 | Variable Head = new Variable(); | ||
5244 | Variable Tail = new Variable(); | ||
5245 | foreach (bool l2 in YP.unify(arg1, new ListPair(Head, Tail))) | ||
5246 | { | ||
5247 | convertExpressionJavascript(Head); | ||
5248 | if (YP.termNotEqual(Tail, Atom.NIL)) | ||
5249 | { | ||
5250 | YP.write(Atom.a(", ")); | ||
5251 | convertArgListJavascript(Tail); | ||
5252 | return; | ||
5253 | goto cutIf1; | ||
5254 | } | ||
5255 | convertArgListJavascript(Tail); | ||
5256 | return; | ||
5257 | cutIf1: | ||
5258 | { } | ||
5259 | } | ||
5260 | } | ||
5261 | } | ||
5262 | |||
5263 | public static void convertExpressionJavascript(object arg1) | ||
5264 | { | ||
5265 | { | ||
5266 | Variable X = new Variable(); | ||
5267 | foreach (bool l2 in YP.unify(arg1, new Functor1("arg", X))) | ||
5268 | { | ||
5269 | YP.write(X); | ||
5270 | return; | ||
5271 | } | ||
5272 | } | ||
5273 | { | ||
5274 | Variable Name = new Variable(); | ||
5275 | Variable ArgList = new Variable(); | ||
5276 | foreach (bool l2 in YP.unify(arg1, new Functor2("call", Name, ArgList))) | ||
5277 | { | ||
5278 | YP.write(Name); | ||
5279 | YP.write(Atom.a("(")); | ||
5280 | convertArgListJavascript(ArgList); | ||
5281 | YP.write(Atom.a(")")); | ||
5282 | return; | ||
5283 | } | ||
5284 | } | ||
5285 | { | ||
5286 | Variable Name = new Variable(); | ||
5287 | Variable _FunctorArgs = new Variable(); | ||
5288 | Variable ArgList = new Variable(); | ||
5289 | foreach (bool l2 in YP.unify(arg1, new Functor3("functorCall", Name, _FunctorArgs, ArgList))) | ||
5290 | { | ||
5291 | convertExpressionJavascript(new Functor2("call", Name, ArgList)); | ||
5292 | return; | ||
5293 | } | ||
5294 | } | ||
5295 | { | ||
5296 | Variable Obj = new Variable(); | ||
5297 | Variable Name = new Variable(); | ||
5298 | Variable ArgList = new Variable(); | ||
5299 | foreach (bool l2 in YP.unify(arg1, new Functor3("callMember", new Functor1("var", Obj), Name, ArgList))) | ||
5300 | { | ||
5301 | YP.write(Obj); | ||
5302 | YP.write(Atom.a(".")); | ||
5303 | YP.write(Name); | ||
5304 | YP.write(Atom.a("(")); | ||
5305 | convertArgListJavascript(ArgList); | ||
5306 | YP.write(Atom.a(")")); | ||
5307 | return; | ||
5308 | } | ||
5309 | } | ||
5310 | { | ||
5311 | Variable Name = new Variable(); | ||
5312 | Variable ArgList = new Variable(); | ||
5313 | foreach (bool l2 in YP.unify(arg1, new Functor2("new", Name, ArgList))) | ||
5314 | { | ||
5315 | YP.write(Atom.a("new ")); | ||
5316 | YP.write(Name); | ||
5317 | YP.write(Atom.a("(")); | ||
5318 | convertArgListJavascript(ArgList); | ||
5319 | YP.write(Atom.a(")")); | ||
5320 | return; | ||
5321 | } | ||
5322 | } | ||
5323 | { | ||
5324 | Variable Name = new Variable(); | ||
5325 | foreach (bool l2 in YP.unify(arg1, new Functor1("var", Name))) | ||
5326 | { | ||
5327 | YP.write(Name); | ||
5328 | return; | ||
5329 | } | ||
5330 | } | ||
5331 | { | ||
5332 | foreach (bool l2 in YP.unify(arg1, Atom.a("null"))) | ||
5333 | { | ||
5334 | YP.write(Atom.a("null")); | ||
5335 | return; | ||
5336 | } | ||
5337 | } | ||
5338 | { | ||
5339 | Variable X = new Variable(); | ||
5340 | foreach (bool l2 in YP.unify(arg1, new Functor1("not", X))) | ||
5341 | { | ||
5342 | YP.write(Atom.a("!(")); | ||
5343 | convertExpressionJavascript(X); | ||
5344 | YP.write(Atom.a(")")); | ||
5345 | return; | ||
5346 | } | ||
5347 | } | ||
5348 | { | ||
5349 | Variable X = new Variable(); | ||
5350 | Variable Y = new Variable(); | ||
5351 | foreach (bool l2 in YP.unify(arg1, new Functor2("and", X, Y))) | ||
5352 | { | ||
5353 | YP.write(Atom.a("(")); | ||
5354 | convertExpressionJavascript(X); | ||
5355 | YP.write(Atom.a(") && (")); | ||
5356 | convertExpressionJavascript(Y); | ||
5357 | YP.write(Atom.a(")")); | ||
5358 | return; | ||
5359 | } | ||
5360 | } | ||
5361 | { | ||
5362 | Variable ArgList = new Variable(); | ||
5363 | foreach (bool l2 in YP.unify(arg1, new Functor1("objectArray", ArgList))) | ||
5364 | { | ||
5365 | YP.write(Atom.a("[")); | ||
5366 | convertArgListJavascript(ArgList); | ||
5367 | YP.write(Atom.a("]")); | ||
5368 | return; | ||
5369 | } | ||
5370 | } | ||
5371 | { | ||
5372 | Variable X = new Variable(); | ||
5373 | Variable Codes = new Variable(); | ||
5374 | foreach (bool l2 in YP.unify(arg1, new Functor1("object", X))) | ||
5375 | { | ||
5376 | if (YP.atom(X)) | ||
5377 | { | ||
5378 | YP.write(Atom.a("\"")); | ||
5379 | foreach (bool l4 in YP.atom_codes(X, Codes)) | ||
5380 | { | ||
5381 | convertStringCodesJavascript(Codes); | ||
5382 | YP.write(Atom.a("\"")); | ||
5383 | return; | ||
5384 | } | ||
5385 | } | ||
5386 | } | ||
5387 | } | ||
5388 | { | ||
5389 | Variable X = new Variable(); | ||
5390 | foreach (bool l2 in YP.unify(arg1, new Functor1("object", X))) | ||
5391 | { | ||
5392 | YP.write(X); | ||
5393 | return; | ||
5394 | } | ||
5395 | } | ||
5396 | } | ||
5397 | |||
5398 | public static void convertStringCodesJavascript(object arg1) | ||
5399 | { | ||
5400 | { | ||
5401 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
5402 | { | ||
5403 | return; | ||
5404 | } | ||
5405 | } | ||
5406 | { | ||
5407 | Variable Code = new Variable(); | ||
5408 | Variable RestCodes = new Variable(); | ||
5409 | foreach (bool l2 in YP.unify(arg1, new ListPair(Code, RestCodes))) | ||
5410 | { | ||
5411 | foreach (bool l3 in putCStringCode(Code)) | ||
5412 | { | ||
5413 | convertStringCodesJavascript(RestCodes); | ||
5414 | return; | ||
5415 | } | ||
5416 | } | ||
5417 | } | ||
5418 | } | ||
5419 | |||
5420 | public static void convertFunctionPython(object arg1) | ||
5421 | { | ||
5422 | { | ||
5423 | foreach (bool l2 in YP.unify(arg1, Atom.a("getDeclaringClass"))) | ||
5424 | { | ||
5425 | YP.write(Atom.a("def getDeclaringClass():")); | ||
5426 | YP.nl(); | ||
5427 | YP.write(Atom.a(" return None")); | ||
5428 | YP.nl(); | ||
5429 | YP.nl(); | ||
5430 | return; | ||
5431 | } | ||
5432 | } | ||
5433 | { | ||
5434 | Variable x1 = new Variable(); | ||
5435 | Variable Name = new Variable(); | ||
5436 | Variable ArgList = new Variable(); | ||
5437 | Variable Body = new Variable(); | ||
5438 | Variable Level = new Variable(); | ||
5439 | Variable HasBreakableBlock = new Variable(); | ||
5440 | foreach (bool l2 in YP.unify(arg1, new Functor("function", new object[] { x1, Name, ArgList, Body }))) | ||
5441 | { | ||
5442 | YP.write(Atom.a("def ")); | ||
5443 | YP.write(Name); | ||
5444 | YP.write(Atom.a("(")); | ||
5445 | convertArgListPython(ArgList); | ||
5446 | YP.write(Atom.a("):")); | ||
5447 | YP.nl(); | ||
5448 | foreach (bool l3 in YP.unify(Level, 1)) | ||
5449 | { | ||
5450 | if (hasBreakableBlockPython(Body)) | ||
5451 | { | ||
5452 | foreach (bool l5 in YP.unify(HasBreakableBlock, 1)) | ||
5453 | { | ||
5454 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
5455 | { | ||
5456 | convertIndentationPython(Level); | ||
5457 | YP.write(Atom.a("doBreak = False")); | ||
5458 | YP.nl(); | ||
5459 | foreach (bool l7 in convertStatementListPython(Body, Level, HasBreakableBlock)) | ||
5460 | { | ||
5461 | YP.nl(); | ||
5462 | return; | ||
5463 | } | ||
5464 | goto cutIf2; | ||
5465 | } | ||
5466 | foreach (bool l6 in convertStatementListPython(Body, Level, HasBreakableBlock)) | ||
5467 | { | ||
5468 | YP.nl(); | ||
5469 | return; | ||
5470 | } | ||
5471 | cutIf2: | ||
5472 | { } | ||
5473 | } | ||
5474 | goto cutIf1; | ||
5475 | } | ||
5476 | foreach (bool l4 in YP.unify(HasBreakableBlock, 0)) | ||
5477 | { | ||
5478 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
5479 | { | ||
5480 | convertIndentationPython(Level); | ||
5481 | YP.write(Atom.a("doBreak = False")); | ||
5482 | YP.nl(); | ||
5483 | foreach (bool l6 in convertStatementListPython(Body, Level, HasBreakableBlock)) | ||
5484 | { | ||
5485 | YP.nl(); | ||
5486 | return; | ||
5487 | } | ||
5488 | goto cutIf3; | ||
5489 | } | ||
5490 | foreach (bool l5 in convertStatementListPython(Body, Level, HasBreakableBlock)) | ||
5491 | { | ||
5492 | YP.nl(); | ||
5493 | return; | ||
5494 | } | ||
5495 | cutIf3: | ||
5496 | { } | ||
5497 | } | ||
5498 | cutIf1: | ||
5499 | { } | ||
5500 | } | ||
5501 | } | ||
5502 | } | ||
5503 | } | ||
5504 | |||
5505 | public static bool hasBreakableBlockPython(object arg1) | ||
5506 | { | ||
5507 | { | ||
5508 | Variable _Name = new Variable(); | ||
5509 | Variable _Body = new Variable(); | ||
5510 | Variable _RestStatements = new Variable(); | ||
5511 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("breakableBlock", _Name, _Body), _RestStatements))) | ||
5512 | { | ||
5513 | return true; | ||
5514 | } | ||
5515 | } | ||
5516 | { | ||
5517 | Variable Body = new Variable(); | ||
5518 | Variable _RestStatements = new Variable(); | ||
5519 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("blockScope", Body), _RestStatements))) | ||
5520 | { | ||
5521 | if (hasBreakableBlockPython(Body)) | ||
5522 | { | ||
5523 | return true; | ||
5524 | } | ||
5525 | } | ||
5526 | } | ||
5527 | { | ||
5528 | Variable _Expression = new Variable(); | ||
5529 | Variable Body = new Variable(); | ||
5530 | Variable _RestStatements = new Variable(); | ||
5531 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("if", _Expression, Body), _RestStatements))) | ||
5532 | { | ||
5533 | if (hasBreakableBlockPython(Body)) | ||
5534 | { | ||
5535 | return true; | ||
5536 | } | ||
5537 | } | ||
5538 | } | ||
5539 | { | ||
5540 | Variable _Expression = new Variable(); | ||
5541 | Variable Body = new Variable(); | ||
5542 | Variable _RestStatements = new Variable(); | ||
5543 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("foreach", _Expression, Body), _RestStatements))) | ||
5544 | { | ||
5545 | if (hasBreakableBlockPython(Body)) | ||
5546 | { | ||
5547 | return true; | ||
5548 | } | ||
5549 | } | ||
5550 | } | ||
5551 | { | ||
5552 | Variable x1 = new Variable(); | ||
5553 | Variable RestStatements = new Variable(); | ||
5554 | foreach (bool l2 in YP.unify(arg1, new ListPair(x1, RestStatements))) | ||
5555 | { | ||
5556 | if (hasBreakableBlockPython(RestStatements)) | ||
5557 | { | ||
5558 | return true; | ||
5559 | } | ||
5560 | } | ||
5561 | } | ||
5562 | return false; | ||
5563 | } | ||
5564 | |||
5565 | public static IEnumerable<bool> convertStatementListPython(object arg1, object arg2, object arg3) | ||
5566 | { | ||
5567 | { | ||
5568 | object x1 = arg2; | ||
5569 | object x2 = arg3; | ||
5570 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
5571 | { | ||
5572 | yield return true; | ||
5573 | yield break; | ||
5574 | } | ||
5575 | } | ||
5576 | { | ||
5577 | object Level = arg2; | ||
5578 | object HasBreakableBlock = arg3; | ||
5579 | Variable Name = new Variable(); | ||
5580 | Variable Body = new Variable(); | ||
5581 | Variable RestStatements = new Variable(); | ||
5582 | Variable NextLevel = new Variable(); | ||
5583 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("breakableBlock", Name, Body), RestStatements))) | ||
5584 | { | ||
5585 | convertIndentationPython(Level); | ||
5586 | YP.write(Name); | ||
5587 | YP.write(Atom.a(" = False")); | ||
5588 | YP.nl(); | ||
5589 | convertIndentationPython(Level); | ||
5590 | YP.write(Atom.a("for _ in [1]:")); | ||
5591 | YP.nl(); | ||
5592 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
5593 | { | ||
5594 | foreach (bool l4 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
5595 | { | ||
5596 | convertIndentationPython(Level); | ||
5597 | YP.write(Atom.a("if ")); | ||
5598 | YP.write(Name); | ||
5599 | YP.write(Atom.a(":")); | ||
5600 | YP.nl(); | ||
5601 | convertIndentationPython(NextLevel); | ||
5602 | YP.write(Atom.a("doBreak = False")); | ||
5603 | YP.nl(); | ||
5604 | convertIndentationPython(Level); | ||
5605 | YP.write(Atom.a("if doBreak:")); | ||
5606 | YP.nl(); | ||
5607 | convertIndentationPython(NextLevel); | ||
5608 | YP.write(Atom.a("break")); | ||
5609 | YP.nl(); | ||
5610 | foreach (bool l5 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5611 | { | ||
5612 | yield return true; | ||
5613 | yield break; | ||
5614 | } | ||
5615 | } | ||
5616 | } | ||
5617 | } | ||
5618 | } | ||
5619 | { | ||
5620 | object Level = arg2; | ||
5621 | object HasBreakableBlock = arg3; | ||
5622 | Variable _Type = new Variable(); | ||
5623 | Variable Name = new Variable(); | ||
5624 | Variable Expression = new Variable(); | ||
5625 | Variable RestStatements = new Variable(); | ||
5626 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("declare", _Type, Name, Expression), RestStatements))) | ||
5627 | { | ||
5628 | convertIndentationPython(Level); | ||
5629 | YP.write(Name); | ||
5630 | YP.write(Atom.a(" = ")); | ||
5631 | convertExpressionPython(Expression); | ||
5632 | YP.nl(); | ||
5633 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5634 | { | ||
5635 | yield return true; | ||
5636 | yield break; | ||
5637 | } | ||
5638 | } | ||
5639 | } | ||
5640 | { | ||
5641 | object Level = arg2; | ||
5642 | object HasBreakableBlock = arg3; | ||
5643 | Variable Name = new Variable(); | ||
5644 | Variable Expression = new Variable(); | ||
5645 | Variable RestStatements = new Variable(); | ||
5646 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("assign", Name, Expression), RestStatements))) | ||
5647 | { | ||
5648 | convertIndentationPython(Level); | ||
5649 | YP.write(Name); | ||
5650 | YP.write(Atom.a(" = ")); | ||
5651 | convertExpressionPython(Expression); | ||
5652 | YP.nl(); | ||
5653 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5654 | { | ||
5655 | yield return true; | ||
5656 | yield break; | ||
5657 | } | ||
5658 | } | ||
5659 | } | ||
5660 | { | ||
5661 | object Level = arg2; | ||
5662 | object HasBreakableBlock = arg3; | ||
5663 | Variable RestStatements = new Variable(); | ||
5664 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldtrue"), RestStatements))) | ||
5665 | { | ||
5666 | convertIndentationPython(Level); | ||
5667 | YP.write(Atom.a("yield True")); | ||
5668 | YP.nl(); | ||
5669 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5670 | { | ||
5671 | yield return true; | ||
5672 | yield break; | ||
5673 | } | ||
5674 | } | ||
5675 | } | ||
5676 | { | ||
5677 | object Level = arg2; | ||
5678 | object HasBreakableBlock = arg3; | ||
5679 | Variable RestStatements = new Variable(); | ||
5680 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldfalse"), RestStatements))) | ||
5681 | { | ||
5682 | convertIndentationPython(Level); | ||
5683 | YP.write(Atom.a("yield False")); | ||
5684 | YP.nl(); | ||
5685 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5686 | { | ||
5687 | yield return true; | ||
5688 | yield break; | ||
5689 | } | ||
5690 | } | ||
5691 | } | ||
5692 | { | ||
5693 | object Level = arg2; | ||
5694 | object HasBreakableBlock = arg3; | ||
5695 | Variable RestStatements = new Variable(); | ||
5696 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("yieldbreak"), RestStatements))) | ||
5697 | { | ||
5698 | convertIndentationPython(Level); | ||
5699 | YP.write(Atom.a("return")); | ||
5700 | YP.nl(); | ||
5701 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5702 | { | ||
5703 | yield return true; | ||
5704 | yield break; | ||
5705 | } | ||
5706 | } | ||
5707 | } | ||
5708 | { | ||
5709 | object Level = arg2; | ||
5710 | object HasBreakableBlock = arg3; | ||
5711 | Variable RestStatements = new Variable(); | ||
5712 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("return"), RestStatements))) | ||
5713 | { | ||
5714 | convertIndentationPython(Level); | ||
5715 | YP.write(Atom.a("return")); | ||
5716 | YP.nl(); | ||
5717 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5718 | { | ||
5719 | yield return true; | ||
5720 | yield break; | ||
5721 | } | ||
5722 | } | ||
5723 | } | ||
5724 | { | ||
5725 | object Level = arg2; | ||
5726 | object HasBreakableBlock = arg3; | ||
5727 | Variable RestStatements = new Variable(); | ||
5728 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("returntrue"), RestStatements))) | ||
5729 | { | ||
5730 | convertIndentationPython(Level); | ||
5731 | YP.write(Atom.a("return True")); | ||
5732 | YP.nl(); | ||
5733 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5734 | { | ||
5735 | yield return true; | ||
5736 | yield break; | ||
5737 | } | ||
5738 | } | ||
5739 | } | ||
5740 | { | ||
5741 | object Level = arg2; | ||
5742 | object HasBreakableBlock = arg3; | ||
5743 | Variable RestStatements = new Variable(); | ||
5744 | foreach (bool l2 in YP.unify(arg1, new ListPair(Atom.a("returnfalse"), RestStatements))) | ||
5745 | { | ||
5746 | convertIndentationPython(Level); | ||
5747 | YP.write(Atom.a("return False")); | ||
5748 | YP.nl(); | ||
5749 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5750 | { | ||
5751 | yield return true; | ||
5752 | yield break; | ||
5753 | } | ||
5754 | } | ||
5755 | } | ||
5756 | { | ||
5757 | object Level = arg2; | ||
5758 | object HasBreakableBlock = arg3; | ||
5759 | Variable Name = new Variable(); | ||
5760 | Variable RestStatements = new Variable(); | ||
5761 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("breakBlock", Name), RestStatements))) | ||
5762 | { | ||
5763 | convertIndentationPython(Level); | ||
5764 | YP.write(Name); | ||
5765 | YP.write(Atom.a(" = True")); | ||
5766 | YP.nl(); | ||
5767 | convertIndentationPython(Level); | ||
5768 | YP.write(Atom.a("doBreak = True")); | ||
5769 | YP.nl(); | ||
5770 | convertIndentationPython(Level); | ||
5771 | YP.write(Atom.a("break")); | ||
5772 | YP.nl(); | ||
5773 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5774 | { | ||
5775 | yield return true; | ||
5776 | yield break; | ||
5777 | } | ||
5778 | } | ||
5779 | } | ||
5780 | { | ||
5781 | object Level = arg2; | ||
5782 | object HasBreakableBlock = arg3; | ||
5783 | Variable Name = new Variable(); | ||
5784 | Variable ArgList = new Variable(); | ||
5785 | Variable RestStatements = new Variable(); | ||
5786 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("call", Name, ArgList), RestStatements))) | ||
5787 | { | ||
5788 | convertIndentationPython(Level); | ||
5789 | YP.write(Name); | ||
5790 | YP.write(Atom.a("(")); | ||
5791 | convertArgListPython(ArgList); | ||
5792 | YP.write(Atom.a(")")); | ||
5793 | YP.nl(); | ||
5794 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5795 | { | ||
5796 | yield return true; | ||
5797 | yield break; | ||
5798 | } | ||
5799 | } | ||
5800 | } | ||
5801 | { | ||
5802 | object Level = arg2; | ||
5803 | object HasBreakableBlock = arg3; | ||
5804 | Variable Name = new Variable(); | ||
5805 | Variable _FunctorArgs = new Variable(); | ||
5806 | Variable ArgList = new Variable(); | ||
5807 | Variable RestStatements = new Variable(); | ||
5808 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("functorCall", Name, _FunctorArgs, ArgList), RestStatements))) | ||
5809 | { | ||
5810 | foreach (bool l3 in convertStatementListPython(new ListPair(new Functor2("call", Name, ArgList), RestStatements), Level, HasBreakableBlock)) | ||
5811 | { | ||
5812 | yield return true; | ||
5813 | yield break; | ||
5814 | } | ||
5815 | } | ||
5816 | } | ||
5817 | { | ||
5818 | object Level = arg2; | ||
5819 | object HasBreakableBlock = arg3; | ||
5820 | Variable Obj = new Variable(); | ||
5821 | Variable Name = new Variable(); | ||
5822 | Variable ArgList = new Variable(); | ||
5823 | Variable RestStatements = new Variable(); | ||
5824 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor3("callMember", new Functor1("var", Obj), Name, ArgList), RestStatements))) | ||
5825 | { | ||
5826 | convertIndentationPython(Level); | ||
5827 | YP.write(Obj); | ||
5828 | YP.write(Atom.a(".")); | ||
5829 | YP.write(Name); | ||
5830 | YP.write(Atom.a("(")); | ||
5831 | convertArgListPython(ArgList); | ||
5832 | YP.write(Atom.a(")")); | ||
5833 | YP.nl(); | ||
5834 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5835 | { | ||
5836 | yield return true; | ||
5837 | yield break; | ||
5838 | } | ||
5839 | } | ||
5840 | } | ||
5841 | { | ||
5842 | object Level = arg2; | ||
5843 | object HasBreakableBlock = arg3; | ||
5844 | Variable Body = new Variable(); | ||
5845 | Variable RestStatements = new Variable(); | ||
5846 | Variable NextLevel = new Variable(); | ||
5847 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("blockScope", Body), RestStatements))) | ||
5848 | { | ||
5849 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
5850 | { | ||
5851 | convertIndentationPython(Level); | ||
5852 | YP.write(Atom.a("for _ in [1]:")); | ||
5853 | YP.nl(); | ||
5854 | foreach (bool l4 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
5855 | { | ||
5856 | foreach (bool l5 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
5857 | { | ||
5858 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
5859 | { | ||
5860 | if (YP.greaterThan(Level, 1)) | ||
5861 | { | ||
5862 | convertIndentationPython(Level); | ||
5863 | YP.write(Atom.a("if doBreak:")); | ||
5864 | YP.nl(); | ||
5865 | convertIndentationPython(NextLevel); | ||
5866 | YP.write(Atom.a("break")); | ||
5867 | YP.nl(); | ||
5868 | foreach (bool l8 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5869 | { | ||
5870 | yield return true; | ||
5871 | yield break; | ||
5872 | } | ||
5873 | goto cutIf3; | ||
5874 | } | ||
5875 | foreach (bool l7 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5876 | { | ||
5877 | yield return true; | ||
5878 | yield break; | ||
5879 | } | ||
5880 | cutIf3: | ||
5881 | goto cutIf2; | ||
5882 | } | ||
5883 | foreach (bool l6 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5884 | { | ||
5885 | yield return true; | ||
5886 | yield break; | ||
5887 | } | ||
5888 | cutIf2: | ||
5889 | { } | ||
5890 | } | ||
5891 | } | ||
5892 | goto cutIf1; | ||
5893 | } | ||
5894 | foreach (bool l3 in YP.unify(NextLevel, Level)) | ||
5895 | { | ||
5896 | foreach (bool l4 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
5897 | { | ||
5898 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
5899 | { | ||
5900 | if (YP.greaterThan(Level, 1)) | ||
5901 | { | ||
5902 | convertIndentationPython(Level); | ||
5903 | YP.write(Atom.a("if doBreak:")); | ||
5904 | YP.nl(); | ||
5905 | convertIndentationPython(NextLevel); | ||
5906 | YP.write(Atom.a("break")); | ||
5907 | YP.nl(); | ||
5908 | foreach (bool l7 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5909 | { | ||
5910 | yield return true; | ||
5911 | yield break; | ||
5912 | } | ||
5913 | goto cutIf5; | ||
5914 | } | ||
5915 | foreach (bool l6 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5916 | { | ||
5917 | yield return true; | ||
5918 | yield break; | ||
5919 | } | ||
5920 | cutIf5: | ||
5921 | goto cutIf4; | ||
5922 | } | ||
5923 | foreach (bool l5 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5924 | { | ||
5925 | yield return true; | ||
5926 | yield break; | ||
5927 | } | ||
5928 | cutIf4: | ||
5929 | { } | ||
5930 | } | ||
5931 | } | ||
5932 | cutIf1: | ||
5933 | { } | ||
5934 | } | ||
5935 | } | ||
5936 | { | ||
5937 | object Level = arg2; | ||
5938 | object HasBreakableBlock = arg3; | ||
5939 | Variable Expression = new Variable(); | ||
5940 | Variable Body = new Variable(); | ||
5941 | Variable RestStatements = new Variable(); | ||
5942 | Variable NextLevel = new Variable(); | ||
5943 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("if", Expression, Body), RestStatements))) | ||
5944 | { | ||
5945 | convertIndentationPython(Level); | ||
5946 | YP.write(Atom.a("if ")); | ||
5947 | convertExpressionPython(Expression); | ||
5948 | YP.write(Atom.a(":")); | ||
5949 | YP.nl(); | ||
5950 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
5951 | { | ||
5952 | foreach (bool l4 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
5953 | { | ||
5954 | foreach (bool l5 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5955 | { | ||
5956 | yield return true; | ||
5957 | yield break; | ||
5958 | } | ||
5959 | } | ||
5960 | } | ||
5961 | } | ||
5962 | } | ||
5963 | { | ||
5964 | object Level = arg2; | ||
5965 | object HasBreakableBlock = arg3; | ||
5966 | Variable Expression = new Variable(); | ||
5967 | Variable Body = new Variable(); | ||
5968 | Variable RestStatements = new Variable(); | ||
5969 | Variable NextLevel = new Variable(); | ||
5970 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor2("foreach", Expression, Body), RestStatements))) | ||
5971 | { | ||
5972 | convertIndentationPython(Level); | ||
5973 | YP.write(Atom.a("for l")); | ||
5974 | YP.write(Level); | ||
5975 | YP.write(Atom.a(" in ")); | ||
5976 | convertExpressionPython(Expression); | ||
5977 | YP.write(Atom.a(":")); | ||
5978 | YP.nl(); | ||
5979 | foreach (bool l3 in YP.unify(NextLevel, YP.add(Level, 1))) | ||
5980 | { | ||
5981 | foreach (bool l4 in convertStatementListPython(Body, NextLevel, HasBreakableBlock)) | ||
5982 | { | ||
5983 | if (YP.termEqual(HasBreakableBlock, 1)) | ||
5984 | { | ||
5985 | convertIndentationPython(Level); | ||
5986 | YP.write(Atom.a("if doBreak:")); | ||
5987 | YP.nl(); | ||
5988 | convertIndentationPython(NextLevel); | ||
5989 | YP.write(Atom.a("break")); | ||
5990 | YP.nl(); | ||
5991 | foreach (bool l6 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5992 | { | ||
5993 | yield return true; | ||
5994 | yield break; | ||
5995 | } | ||
5996 | goto cutIf6; | ||
5997 | } | ||
5998 | foreach (bool l5 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
5999 | { | ||
6000 | yield return true; | ||
6001 | yield break; | ||
6002 | } | ||
6003 | cutIf6: | ||
6004 | { } | ||
6005 | } | ||
6006 | } | ||
6007 | } | ||
6008 | } | ||
6009 | { | ||
6010 | object Level = arg2; | ||
6011 | object HasBreakableBlock = arg3; | ||
6012 | Variable Expression = new Variable(); | ||
6013 | Variable RestStatements = new Variable(); | ||
6014 | foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1("throw", Expression), RestStatements))) | ||
6015 | { | ||
6016 | convertIndentationPython(Level); | ||
6017 | YP.write(Atom.a("raise ")); | ||
6018 | convertExpressionPython(Expression); | ||
6019 | YP.nl(); | ||
6020 | foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) | ||
6021 | { | ||
6022 | yield return true; | ||
6023 | yield break; | ||
6024 | } | ||
6025 | } | ||
6026 | } | ||
6027 | } | ||
6028 | |||
6029 | public static void convertIndentationPython(object Level) | ||
6030 | { | ||
6031 | { | ||
6032 | Variable N = new Variable(); | ||
6033 | foreach (bool l2 in YP.unify(N, YP.multiply(Level, 2))) | ||
6034 | { | ||
6035 | repeatWrite(Atom.a(" "), N); | ||
6036 | return; | ||
6037 | } | ||
6038 | } | ||
6039 | } | ||
6040 | |||
6041 | public static void convertArgListPython(object arg1) | ||
6042 | { | ||
6043 | { | ||
6044 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
6045 | { | ||
6046 | return; | ||
6047 | } | ||
6048 | } | ||
6049 | { | ||
6050 | Variable Head = new Variable(); | ||
6051 | Variable Tail = new Variable(); | ||
6052 | foreach (bool l2 in YP.unify(arg1, new ListPair(Head, Tail))) | ||
6053 | { | ||
6054 | convertExpressionPython(Head); | ||
6055 | if (YP.termNotEqual(Tail, Atom.NIL)) | ||
6056 | { | ||
6057 | YP.write(Atom.a(", ")); | ||
6058 | convertArgListPython(Tail); | ||
6059 | return; | ||
6060 | goto cutIf1; | ||
6061 | } | ||
6062 | convertArgListPython(Tail); | ||
6063 | return; | ||
6064 | cutIf1: | ||
6065 | { } | ||
6066 | } | ||
6067 | } | ||
6068 | } | ||
6069 | |||
6070 | public static void convertExpressionPython(object arg1) | ||
6071 | { | ||
6072 | { | ||
6073 | Variable X = new Variable(); | ||
6074 | foreach (bool l2 in YP.unify(arg1, new Functor1("arg", X))) | ||
6075 | { | ||
6076 | YP.write(X); | ||
6077 | return; | ||
6078 | } | ||
6079 | } | ||
6080 | { | ||
6081 | Variable Name = new Variable(); | ||
6082 | Variable ArgList = new Variable(); | ||
6083 | foreach (bool l2 in YP.unify(arg1, new Functor2("call", Name, ArgList))) | ||
6084 | { | ||
6085 | YP.write(Name); | ||
6086 | YP.write(Atom.a("(")); | ||
6087 | convertArgListPython(ArgList); | ||
6088 | YP.write(Atom.a(")")); | ||
6089 | return; | ||
6090 | } | ||
6091 | } | ||
6092 | { | ||
6093 | Variable Name = new Variable(); | ||
6094 | Variable _FunctorArgs = new Variable(); | ||
6095 | Variable ArgList = new Variable(); | ||
6096 | foreach (bool l2 in YP.unify(arg1, new Functor3("functorCall", Name, _FunctorArgs, ArgList))) | ||
6097 | { | ||
6098 | convertExpressionPython(new Functor2("call", Name, ArgList)); | ||
6099 | return; | ||
6100 | } | ||
6101 | } | ||
6102 | { | ||
6103 | Variable Obj = new Variable(); | ||
6104 | Variable Name = new Variable(); | ||
6105 | Variable ArgList = new Variable(); | ||
6106 | foreach (bool l2 in YP.unify(arg1, new Functor3("callMember", new Functor1("var", Obj), Name, ArgList))) | ||
6107 | { | ||
6108 | YP.write(Obj); | ||
6109 | YP.write(Atom.a(".")); | ||
6110 | YP.write(Name); | ||
6111 | YP.write(Atom.a("(")); | ||
6112 | convertArgListPython(ArgList); | ||
6113 | YP.write(Atom.a(")")); | ||
6114 | return; | ||
6115 | } | ||
6116 | } | ||
6117 | { | ||
6118 | Variable Name = new Variable(); | ||
6119 | Variable ArgList = new Variable(); | ||
6120 | foreach (bool l2 in YP.unify(arg1, new Functor2("new", Name, ArgList))) | ||
6121 | { | ||
6122 | YP.write(Name); | ||
6123 | YP.write(Atom.a("(")); | ||
6124 | convertArgListPython(ArgList); | ||
6125 | YP.write(Atom.a(")")); | ||
6126 | return; | ||
6127 | } | ||
6128 | } | ||
6129 | { | ||
6130 | Variable Name = new Variable(); | ||
6131 | foreach (bool l2 in YP.unify(arg1, new Functor1("var", Name))) | ||
6132 | { | ||
6133 | YP.write(Name); | ||
6134 | return; | ||
6135 | } | ||
6136 | } | ||
6137 | { | ||
6138 | foreach (bool l2 in YP.unify(arg1, Atom.a("null"))) | ||
6139 | { | ||
6140 | YP.write(Atom.a("None")); | ||
6141 | return; | ||
6142 | } | ||
6143 | } | ||
6144 | { | ||
6145 | Variable X = new Variable(); | ||
6146 | foreach (bool l2 in YP.unify(arg1, new Functor1("not", X))) | ||
6147 | { | ||
6148 | YP.write(Atom.a("not (")); | ||
6149 | convertExpressionPython(X); | ||
6150 | YP.write(Atom.a(")")); | ||
6151 | return; | ||
6152 | } | ||
6153 | } | ||
6154 | { | ||
6155 | Variable X = new Variable(); | ||
6156 | Variable Y = new Variable(); | ||
6157 | foreach (bool l2 in YP.unify(arg1, new Functor2("and", X, Y))) | ||
6158 | { | ||
6159 | YP.write(Atom.a("(")); | ||
6160 | convertExpressionPython(X); | ||
6161 | YP.write(Atom.a(") and (")); | ||
6162 | convertExpressionPython(Y); | ||
6163 | YP.write(Atom.a(")")); | ||
6164 | return; | ||
6165 | } | ||
6166 | } | ||
6167 | { | ||
6168 | Variable ArgList = new Variable(); | ||
6169 | foreach (bool l2 in YP.unify(arg1, new Functor1("objectArray", ArgList))) | ||
6170 | { | ||
6171 | YP.write(Atom.a("[")); | ||
6172 | convertArgListPython(ArgList); | ||
6173 | YP.write(Atom.a("]")); | ||
6174 | return; | ||
6175 | } | ||
6176 | } | ||
6177 | { | ||
6178 | Variable X = new Variable(); | ||
6179 | Variable Codes = new Variable(); | ||
6180 | foreach (bool l2 in YP.unify(arg1, new Functor1("object", X))) | ||
6181 | { | ||
6182 | if (YP.atom(X)) | ||
6183 | { | ||
6184 | YP.write(Atom.a("\"")); | ||
6185 | foreach (bool l4 in YP.atom_codes(X, Codes)) | ||
6186 | { | ||
6187 | convertStringCodesPython(Codes); | ||
6188 | YP.write(Atom.a("\"")); | ||
6189 | return; | ||
6190 | } | ||
6191 | } | ||
6192 | } | ||
6193 | } | ||
6194 | { | ||
6195 | Variable X = new Variable(); | ||
6196 | foreach (bool l2 in YP.unify(arg1, new Functor1("object", X))) | ||
6197 | { | ||
6198 | YP.write(X); | ||
6199 | return; | ||
6200 | } | ||
6201 | } | ||
6202 | } | ||
6203 | |||
6204 | public static void convertStringCodesPython(object arg1) | ||
6205 | { | ||
6206 | { | ||
6207 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
6208 | { | ||
6209 | return; | ||
6210 | } | ||
6211 | } | ||
6212 | { | ||
6213 | Variable Code = new Variable(); | ||
6214 | Variable RestCodes = new Variable(); | ||
6215 | foreach (bool l2 in YP.unify(arg1, new ListPair(Code, RestCodes))) | ||
6216 | { | ||
6217 | if (YP.termEqual(Code, 34)) | ||
6218 | { | ||
6219 | YP.put_code(92); | ||
6220 | YP.put_code(Code); | ||
6221 | convertStringCodesPython(RestCodes); | ||
6222 | return; | ||
6223 | goto cutIf1; | ||
6224 | } | ||
6225 | if (YP.termEqual(Code, 92)) | ||
6226 | { | ||
6227 | YP.put_code(92); | ||
6228 | YP.put_code(Code); | ||
6229 | convertStringCodesPython(RestCodes); | ||
6230 | return; | ||
6231 | goto cutIf1; | ||
6232 | } | ||
6233 | YP.put_code(Code); | ||
6234 | convertStringCodesPython(RestCodes); | ||
6235 | return; | ||
6236 | cutIf1: | ||
6237 | { } | ||
6238 | } | ||
6239 | } | ||
6240 | } | ||
6241 | |||
6242 | public static IEnumerable<bool> putCStringCode(object Code) | ||
6243 | { | ||
6244 | { | ||
6245 | Variable HexDigit = new Variable(); | ||
6246 | Variable HexChar = new Variable(); | ||
6247 | if (YP.lessThanOrEqual(Code, 31)) | ||
6248 | { | ||
6249 | if (YP.lessThanOrEqual(Code, 15)) | ||
6250 | { | ||
6251 | YP.write(Atom.a("\\u000")); | ||
6252 | foreach (bool l4 in YP.unify(HexDigit, Code)) | ||
6253 | { | ||
6254 | if (YP.lessThanOrEqual(HexDigit, 9)) | ||
6255 | { | ||
6256 | foreach (bool l6 in YP.unify(HexChar, YP.add(HexDigit, 48))) | ||
6257 | { | ||
6258 | YP.put_code(HexChar); | ||
6259 | yield return true; | ||
6260 | yield break; | ||
6261 | } | ||
6262 | goto cutIf2; | ||
6263 | } | ||
6264 | foreach (bool l5 in YP.unify(HexChar, YP.add(HexDigit, 55))) | ||
6265 | { | ||
6266 | YP.put_code(HexChar); | ||
6267 | yield return true; | ||
6268 | yield break; | ||
6269 | } | ||
6270 | cutIf2: | ||
6271 | { } | ||
6272 | } | ||
6273 | goto cutIf1; | ||
6274 | } | ||
6275 | YP.write(Atom.a("\\u001")); | ||
6276 | foreach (bool l3 in YP.unify(HexDigit, YP.subtract(Code, 16))) | ||
6277 | { | ||
6278 | if (YP.lessThanOrEqual(HexDigit, 9)) | ||
6279 | { | ||
6280 | foreach (bool l5 in YP.unify(HexChar, YP.add(HexDigit, 48))) | ||
6281 | { | ||
6282 | YP.put_code(HexChar); | ||
6283 | yield return true; | ||
6284 | yield break; | ||
6285 | } | ||
6286 | goto cutIf3; | ||
6287 | } | ||
6288 | foreach (bool l4 in YP.unify(HexChar, YP.add(HexDigit, 55))) | ||
6289 | { | ||
6290 | YP.put_code(HexChar); | ||
6291 | yield return true; | ||
6292 | yield break; | ||
6293 | } | ||
6294 | cutIf3: | ||
6295 | { } | ||
6296 | } | ||
6297 | cutIf1: | ||
6298 | { } | ||
6299 | } | ||
6300 | } | ||
6301 | { | ||
6302 | if (YP.termEqual(Code, 34)) | ||
6303 | { | ||
6304 | YP.put_code(92); | ||
6305 | YP.put_code(34); | ||
6306 | yield return true; | ||
6307 | yield break; | ||
6308 | } | ||
6309 | } | ||
6310 | { | ||
6311 | if (YP.termEqual(Code, 92)) | ||
6312 | { | ||
6313 | YP.put_code(92); | ||
6314 | YP.put_code(92); | ||
6315 | yield return true; | ||
6316 | yield break; | ||
6317 | } | ||
6318 | } | ||
6319 | { | ||
6320 | YP.put_code(Code); | ||
6321 | yield return true; | ||
6322 | yield break; | ||
6323 | } | ||
6324 | } | ||
6325 | |||
6326 | public static IEnumerable<bool> member(object X, object arg2) | ||
6327 | { | ||
6328 | { | ||
6329 | Variable x2 = new Variable(); | ||
6330 | foreach (bool l2 in YP.unify(arg2, new ListPair(X, x2))) | ||
6331 | { | ||
6332 | yield return false; | ||
6333 | } | ||
6334 | } | ||
6335 | { | ||
6336 | Variable x2 = new Variable(); | ||
6337 | Variable Rest = new Variable(); | ||
6338 | foreach (bool l2 in YP.unify(arg2, new ListPair(x2, Rest))) | ||
6339 | { | ||
6340 | foreach (bool l3 in member(X, Rest)) | ||
6341 | { | ||
6342 | yield return false; | ||
6343 | } | ||
6344 | } | ||
6345 | } | ||
6346 | } | ||
6347 | |||
6348 | public static IEnumerable<bool> append(object arg1, object arg2, object arg3) | ||
6349 | { | ||
6350 | { | ||
6351 | Variable List = new Variable(); | ||
6352 | foreach (bool l2 in YP.unify(arg1, Atom.NIL)) | ||
6353 | { | ||
6354 | foreach (bool l3 in YP.unify(arg2, List)) | ||
6355 | { | ||
6356 | foreach (bool l4 in YP.unify(arg3, List)) | ||
6357 | { | ||
6358 | yield return false; | ||
6359 | } | ||
6360 | } | ||
6361 | } | ||
6362 | } | ||
6363 | { | ||
6364 | object List2 = arg2; | ||
6365 | Variable X = new Variable(); | ||
6366 | Variable List1 = new Variable(); | ||
6367 | Variable List12 = new Variable(); | ||
6368 | foreach (bool l2 in YP.unify(arg1, new ListPair(X, List1))) | ||
6369 | { | ||
6370 | foreach (bool l3 in YP.unify(arg3, new ListPair(X, List12))) | ||
6371 | { | ||
6372 | foreach (bool l4 in append(List1, List2, List12)) | ||
6373 | { | ||
6374 | yield return false; | ||
6375 | } | ||
6376 | } | ||
6377 | } | ||
6378 | } | ||
6379 | } | ||
6380 | #pragma warning restore 0168, 0219, 0164,0162 | ||
6381 | } | ||
6382 | } | ||