aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Variable.cs
diff options
context:
space:
mode:
authorJeff Ames2008-06-01 03:01:33 +0000
committerJeff Ames2008-06-01 03:01:33 +0000
commitd22a54a19568f8d5e9b6dab1f76f9c5c58682aa5 (patch)
tree2311b4c6ad2617cc71b975460c48e723a7e027ee /OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Variable.cs
parent* Committing some stuff I'm working to make it so I can commit an upcoming pa... (diff)
downloadopensim-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/Variable.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Variable.cs392
1 files changed, 196 insertions, 196 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Variable.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Variable.cs
index d5ee21c..47b5278 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Variable.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Variable.cs
@@ -1,196 +1,196 @@
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
31using System; 31using System;
32using System.Collections; 32using System.Collections;
33using System.Collections.Generic; 33using System.Collections.Generic;
34 34
35namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog 35namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
36{ 36{
37 public interface IUnifiable 37 public interface IUnifiable
38 { 38 {
39 IEnumerable<bool> unify(object arg); 39 IEnumerable<bool> unify(object arg);
40 void addUniqueVariables(List<Variable> variableSet); 40 void addUniqueVariables(List<Variable> variableSet);
41 object makeCopy(Variable.CopyStore copyStore); 41 object makeCopy(Variable.CopyStore copyStore);
42 bool termEqual(object term); 42 bool termEqual(object term);
43 bool ground(); 43 bool ground();
44 } 44 }
45 45
46 public class Variable : IUnifiable 46 public class Variable : IUnifiable
47 { 47 {
48 // Use _isBound separate from _value so that it can be bound to any value, 48 // Use _isBound separate from _value so that it can be bound to any value,
49 // including null. 49 // including null.
50 private bool _isBound = false; 50 private bool _isBound = false;
51 private object _value; 51 private object _value;
52 52
53 public object getValue() 53 public object getValue()
54 { 54 {
55 if (!_isBound) 55 if (!_isBound)
56 return this; 56 return this;
57 57
58 object result = _value; 58 object result = _value;
59 while (result is Variable) 59 while (result is Variable)
60 { 60 {
61 if (!((Variable)result)._isBound) 61 if (!((Variable)result)._isBound)
62 return result; 62 return result;
63 63
64 // Keep following the Variable chain. 64 // Keep following the Variable chain.
65 result = ((Variable)result)._value; 65 result = ((Variable)result)._value;
66 } 66 }
67 67
68 return result; 68 return result;
69 } 69 }
70 70
71 public IEnumerable<bool> unify(object arg) 71 public IEnumerable<bool> unify(object arg)
72 { 72 {
73 if (!_isBound) 73 if (!_isBound)
74 { 74 {
75 _value = YP.getValue(arg); 75 _value = YP.getValue(arg);
76 if (_value == this) 76 if (_value == this)
77 // We are unifying this unbound variable with itself, so leave it unbound. 77 // We are unifying this unbound variable with itself, so leave it unbound.
78 yield return false; 78 yield return false;
79 else 79 else
80 { 80 {
81 _isBound = true; 81 _isBound = true;
82 try 82 try
83 { 83 {
84 yield return false; 84 yield return false;
85 } 85 }
86 finally 86 finally
87 { 87 {
88 // Remove the binding. 88 // Remove the binding.
89 _isBound = false; 89 _isBound = false;
90 } 90 }
91 } 91 }
92 } 92 }
93 else 93 else
94 { 94 {
95 foreach (bool l1 in YP.unify(this, arg)) 95 foreach (bool l1 in YP.unify(this, arg))
96 yield return false; 96 yield return false;
97 } 97 }
98 } 98 }
99 99
100 public override string ToString() 100 public override string ToString()
101 { 101 {
102 object value = getValue(); 102 object value = getValue();
103 if (value == this) 103 if (value == this)
104 return "Variable"; 104 return "Variable";
105 else 105 else
106 return getValue().ToString(); 106 return getValue().ToString();
107 } 107 }
108 108
109 /// <summary> 109 /// <summary>
110 /// If bound, call YP.addUniqueVariables on the value. Otherwise, if this unbound 110 /// If bound, call YP.addUniqueVariables on the value. Otherwise, if this unbound
111 /// variable is not already in variableSet, add it. 111 /// variable is not already in variableSet, add it.
112 /// </summary> 112 /// </summary>
113 /// <param name="variableSet"></param> 113 /// <param name="variableSet"></param>
114 public void addUniqueVariables(List<Variable> variableSet) 114 public void addUniqueVariables(List<Variable> variableSet)
115 { 115 {
116 if (_isBound) 116 if (_isBound)
117 YP.addUniqueVariables(getValue(), variableSet); 117 YP.addUniqueVariables(getValue(), variableSet);
118 else 118 else
119 { 119 {
120 if (variableSet.IndexOf(this) < 0) 120 if (variableSet.IndexOf(this) < 0)
121 variableSet.Add(this); 121 variableSet.Add(this);
122 } 122 }
123 } 123 }
124 124
125 /// <summary> 125 /// <summary>
126 /// If bound, return YP.makeCopy for the value, else return copyStore.getCopy(this). 126 /// If bound, return YP.makeCopy for the value, else return copyStore.getCopy(this).
127 /// However, if copyStore is null, just return this. 127 /// However, if copyStore is null, just return this.
128 /// </summary> 128 /// </summary>
129 /// <param name="copyStore"></param> 129 /// <param name="copyStore"></param>
130 /// <returns></returns> 130 /// <returns></returns>
131 public object makeCopy(Variable.CopyStore copyStore) 131 public object makeCopy(Variable.CopyStore copyStore)
132 { 132 {
133 if (_isBound) 133 if (_isBound)
134 return YP.makeCopy(getValue(), copyStore); 134 return YP.makeCopy(getValue(), copyStore);
135 else 135 else
136 return copyStore == null ? this : copyStore.getCopy(this); 136 return copyStore == null ? this : copyStore.getCopy(this);
137 } 137 }
138 138
139 public bool termEqual(object term) 139 public bool termEqual(object term)
140 { 140 {
141 if (_isBound) 141 if (_isBound)
142 return YP.termEqual(getValue(), term); 142 return YP.termEqual(getValue(), term);
143 else 143 else
144 return this == YP.getValue(term); 144 return this == YP.getValue(term);
145 } 145 }
146 146
147 public bool ground() 147 public bool ground()
148 { 148 {
149 if (_isBound) 149 if (_isBound)
150 // This is usually called by YP.ground which already did getValue, so this 150 // This is usually called by YP.ground which already did getValue, so this
151 // should never be reached, but check anyway. 151 // should never be reached, but check anyway.
152 return YP.ground(getValue()); 152 return YP.ground(getValue());
153 else 153 else
154 return false; 154 return false;
155 } 155 }
156 156
157 /// <summary> 157 /// <summary>
158 /// A CopyStore is used by makeCopy to track which Variable objects have 158 /// A CopyStore is used by makeCopy to track which Variable objects have
159 /// been copied. 159 /// been copied.
160 /// </summary> 160 /// </summary>
161 public class CopyStore 161 public class CopyStore
162 { 162 {
163 private List<Variable> _inVariableSet = new List<Variable>(); 163 private List<Variable> _inVariableSet = new List<Variable>();
164 private List<Variable> _outVariableSet = new List<Variable>(); 164 private List<Variable> _outVariableSet = new List<Variable>();
165 165
166 /// <summary> 166 /// <summary>
167 /// If inVariable has already been copied, return its copy. Otherwise, 167 /// If inVariable has already been copied, return its copy. Otherwise,
168 /// return a fresh Variable associated with inVariable. 168 /// return a fresh Variable associated with inVariable.
169 /// </summary> 169 /// </summary>
170 /// <param name="inVariable"></param> 170 /// <param name="inVariable"></param>
171 /// <returns></returns> 171 /// <returns></returns>
172 public Variable getCopy(Variable inVariable) 172 public Variable getCopy(Variable inVariable)
173 { 173 {
174 int index = _inVariableSet.IndexOf(inVariable); 174 int index = _inVariableSet.IndexOf(inVariable);
175 if (index >= 0) 175 if (index >= 0)
176 return _outVariableSet[index]; 176 return _outVariableSet[index];
177 else 177 else
178 { 178 {
179 Variable outVariable = new Variable(); 179 Variable outVariable = new Variable();
180 _inVariableSet.Add(inVariable); 180 _inVariableSet.Add(inVariable);
181 _outVariableSet.Add(outVariable); 181 _outVariableSet.Add(outVariable);
182 return outVariable; 182 return outVariable;
183 } 183 }
184 } 184 }
185 185
186 /// <summary> 186 /// <summary>
187 /// Return the number of unique variables that have been copied. 187 /// Return the number of unique variables that have been copied.
188 /// </summary> 188 /// </summary>
189 /// <returns></returns> 189 /// <returns></returns>
190 public int getNUniqueVariables() 190 public int getNUniqueVariables()
191 { 191 {
192 return _inVariableSet.Count; 192 return _inVariableSet.Count;
193 } 193 }
194 } 194 }
195 } 195 }
196} 196}