diff options
author | Jeff Ames | 2008-06-01 03:01:33 +0000 |
---|---|---|
committer | Jeff Ames | 2008-06-01 03:01:33 +0000 |
commit | d22a54a19568f8d5e9b6dab1f76f9c5c58682aa5 (patch) | |
tree | 2311b4c6ad2617cc71b975460c48e723a7e027ee /OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/ListPair.cs | |
parent | * Committing some stuff I'm working to make it so I can commit an upcoming pa... (diff) | |
download | opensim-SC-d22a54a19568f8d5e9b6dab1f76f9c5c58682aa5.zip opensim-SC-d22a54a19568f8d5e9b6dab1f76f9c5c58682aa5.tar.gz opensim-SC-d22a54a19568f8d5e9b6dab1f76f9c5c58682aa5.tar.bz2 opensim-SC-d22a54a19568f8d5e9b6dab1f76f9c5c58682aa5.tar.xz |
Update svn properties.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/ListPair.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/ListPair.cs | 312 |
1 files changed, 156 insertions, 156 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/ListPair.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/ListPair.cs index b16e8a4..681c445 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/ListPair.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/ListPair.cs | |||
@@ -1,156 +1,156 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2007-2008, Jeff Thompson | 2 | * Copyright (C) 2007-2008, Jeff Thompson |
3 | * | 3 | * |
4 | * All rights reserved. | 4 | * All rights reserved. |
5 | * | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions are met: | 7 | * modification, are permitted provided that the following conditions are met: |
8 | * | 8 | * |
9 | * * Redistributions of source code must retain the above copyright | 9 | * * Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * * Redistributions in binary form must reproduce the above copyright | 11 | * * Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. |
14 | * * Neither the name of the copyright holder nor the names of its contributors | 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 | 15 | * may be used to endorse or promote products derived from this software |
16 | * without specific prior written permission. | 16 | * without specific prior written permission. |
17 | * | 17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 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 | 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 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. | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | using System; | 31 | using System; |
32 | using System.Collections.Generic; | 32 | using System.Collections.Generic; |
33 | 33 | ||
34 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog | 34 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog |
35 | { | 35 | { |
36 | public class ListPair : Functor2 | 36 | public class ListPair : Functor2 |
37 | { | 37 | { |
38 | public ListPair(object head, object tail) : base(Atom.DOT, head, tail) | 38 | public ListPair(object head, object tail) : base(Atom.DOT, head, tail) |
39 | { | 39 | { |
40 | } | 40 | } |
41 | 41 | ||
42 | public static object make(List<object> list) | 42 | public static object make(List<object> list) |
43 | { | 43 | { |
44 | if (list.Count <= 0) | 44 | if (list.Count <= 0) |
45 | return Atom.NIL; | 45 | return Atom.NIL; |
46 | 46 | ||
47 | object result = Atom.NIL; | 47 | object result = Atom.NIL; |
48 | // Start from the end. | 48 | // Start from the end. |
49 | for (int i = list.Count - 1; i >= 0; --i) | 49 | for (int i = list.Count - 1; i >= 0; --i) |
50 | result = new ListPair(list[i], result); | 50 | result = new ListPair(list[i], result); |
51 | return result; | 51 | return result; |
52 | } | 52 | } |
53 | 53 | ||
54 | public static object make(object[] array) | 54 | public static object make(object[] array) |
55 | { | 55 | { |
56 | if (array.Length <= 0) | 56 | if (array.Length <= 0) |
57 | return Atom.NIL; | 57 | return Atom.NIL; |
58 | 58 | ||
59 | object result = Atom.NIL; | 59 | object result = Atom.NIL; |
60 | // Start from the end. | 60 | // Start from the end. |
61 | for (int i = array.Length - 1; i >= 0; --i) | 61 | for (int i = array.Length - 1; i >= 0; --i) |
62 | result = new ListPair(array[i], result); | 62 | result = new ListPair(array[i], result); |
63 | return result; | 63 | return result; |
64 | } | 64 | } |
65 | 65 | ||
66 | /// <summary> | 66 | /// <summary> |
67 | /// Return a ListPair version of array, where repeated elements | 67 | /// Return a ListPair version of array, where repeated elements |
68 | /// (according to YP.termEqual) are removed. | 68 | /// (according to YP.termEqual) are removed. |
69 | /// </summary> | 69 | /// </summary> |
70 | /// <param name="array"></param> | 70 | /// <param name="array"></param> |
71 | /// <returns></returns> | 71 | /// <returns></returns> |
72 | public static object makeWithoutRepeatedTerms(object[] array) | 72 | public static object makeWithoutRepeatedTerms(object[] array) |
73 | { | 73 | { |
74 | if (array.Length <= 0) | 74 | if (array.Length <= 0) |
75 | return Atom.NIL; | 75 | return Atom.NIL; |
76 | 76 | ||
77 | // Start from the end. | 77 | // Start from the end. |
78 | object previousTerm = array[array.Length - 1]; | 78 | object previousTerm = array[array.Length - 1]; |
79 | object result = new ListPair(previousTerm, Atom.NIL); | 79 | object result = new ListPair(previousTerm, Atom.NIL); |
80 | for (int i = array.Length - 2; i >= 0; --i) | 80 | for (int i = array.Length - 2; i >= 0; --i) |
81 | { | 81 | { |
82 | object term = array[i]; | 82 | object term = array[i]; |
83 | if (YP.termEqual(term, previousTerm)) | 83 | if (YP.termEqual(term, previousTerm)) |
84 | continue; | 84 | continue; |
85 | result = new ListPair(term, result); | 85 | result = new ListPair(term, result); |
86 | previousTerm = term; | 86 | previousTerm = term; |
87 | } | 87 | } |
88 | return result; | 88 | return result; |
89 | } | 89 | } |
90 | 90 | ||
91 | /// <summary> | 91 | /// <summary> |
92 | /// Return a ListPair version of array, where repeated elements | 92 | /// Return a ListPair version of array, where repeated elements |
93 | /// (according to YP.termEqual) are removed. | 93 | /// (according to YP.termEqual) are removed. |
94 | /// </summary> | 94 | /// </summary> |
95 | /// <param name="array"></param> | 95 | /// <param name="array"></param> |
96 | /// <returns></returns> | 96 | /// <returns></returns> |
97 | public static object makeWithoutRepeatedTerms(List<object> array) | 97 | public static object makeWithoutRepeatedTerms(List<object> array) |
98 | { | 98 | { |
99 | if (array.Count <= 0) | 99 | if (array.Count <= 0) |
100 | return Atom.NIL; | 100 | return Atom.NIL; |
101 | 101 | ||
102 | // Start from the end. | 102 | // Start from the end. |
103 | object previousTerm = array[array.Count - 1]; | 103 | object previousTerm = array[array.Count - 1]; |
104 | object result = new ListPair(previousTerm, Atom.NIL); | 104 | object result = new ListPair(previousTerm, Atom.NIL); |
105 | for (int i = array.Count - 2; i >= 0; --i) | 105 | for (int i = array.Count - 2; i >= 0; --i) |
106 | { | 106 | { |
107 | object term = array[i]; | 107 | object term = array[i]; |
108 | if (YP.termEqual(term, previousTerm)) | 108 | if (YP.termEqual(term, previousTerm)) |
109 | continue; | 109 | continue; |
110 | result = new ListPair(term, result); | 110 | result = new ListPair(term, result); |
111 | previousTerm = term; | 111 | previousTerm = term; |
112 | } | 112 | } |
113 | return result; | 113 | return result; |
114 | } | 114 | } |
115 | 115 | ||
116 | public static object make(object element1) | 116 | public static object make(object element1) |
117 | { | 117 | { |
118 | return new ListPair(element1, Atom.NIL); | 118 | return new ListPair(element1, Atom.NIL); |
119 | } | 119 | } |
120 | 120 | ||
121 | public static object make(object element1, object element2) | 121 | public static object make(object element1, object element2) |
122 | { | 122 | { |
123 | return new ListPair(element1, new ListPair(element2, Atom.NIL)); | 123 | return new ListPair(element1, new ListPair(element2, Atom.NIL)); |
124 | } | 124 | } |
125 | 125 | ||
126 | public static object make(object element1, object element2, object element3) | 126 | public static object make(object element1, object element2, object element3) |
127 | { | 127 | { |
128 | return new ListPair(element1, | 128 | return new ListPair(element1, |
129 | new ListPair(element2, new ListPair(element3, Atom.NIL))); | 129 | new ListPair(element2, new ListPair(element3, Atom.NIL))); |
130 | } | 130 | } |
131 | 131 | ||
132 | /// <summary> | 132 | /// <summary> |
133 | /// Return an array of the elements in list or null if it is not | 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. | 134 | /// a proper list. If list is Atom.NIL, return an array of zero elements. |
135 | /// This does not call YP.getValue on each element. | 135 | /// This does not call YP.getValue on each element. |
136 | /// </summary> | 136 | /// </summary> |
137 | /// <param name="list"></param> | 137 | /// <param name="list"></param> |
138 | /// <returns></returns> | 138 | /// <returns></returns> |
139 | public static object[] toArray(object list) | 139 | public static object[] toArray(object list) |
140 | { | 140 | { |
141 | list = YP.getValue(list); | 141 | list = YP.getValue(list); |
142 | if (list.Equals(Atom.NIL)) | 142 | if (list.Equals(Atom.NIL)) |
143 | return new object[0]; | 143 | return new object[0]; |
144 | 144 | ||
145 | List<object> result = new List<object>(); | 145 | List<object> result = new List<object>(); |
146 | for (object element = list; | 146 | for (object element = list; |
147 | element is Functor2 && ((Functor2)element)._name == Atom.DOT; | 147 | element is Functor2 && ((Functor2)element)._name == Atom.DOT; |
148 | element = YP.getValue(((Functor2)element)._arg2)) | 148 | element = YP.getValue(((Functor2)element)._arg2)) |
149 | result.Add(((Functor2)element)._arg1); | 149 | result.Add(((Functor2)element)._arg1); |
150 | 150 | ||
151 | if (result.Count <= 0) | 151 | if (result.Count <= 0) |
152 | return null; | 152 | return null; |
153 | return result.ToArray(); | 153 | return result.ToArray(); |
154 | } | 154 | } |
155 | } | 155 | } |
156 | } | 156 | } |