aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor2.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor2.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor2.cs308
1 files changed, 154 insertions, 154 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor2.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor2.cs
index 87c5f1b..138a44c 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor2.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/Functor2.cs
@@ -1,154 +1,154 @@
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.Generic; 32using System.Collections.Generic;
33 33
34namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog 34namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
35{ 35{
36 public class Functor2 : IUnifiable 36 public class Functor2 : IUnifiable
37 { 37 {
38 public readonly Atom _name; 38 public readonly Atom _name;
39 public readonly object _arg1; 39 public readonly object _arg1;
40 public readonly object _arg2; 40 public readonly object _arg2;
41 41
42 public Functor2(Atom name, object arg1, object arg2) 42 public Functor2(Atom name, object arg1, object arg2)
43 { 43 {
44 _name = name; 44 _name = name;
45 _arg1 = arg1; 45 _arg1 = arg1;
46 _arg2 = arg2; 46 _arg2 = arg2;
47 } 47 }
48 48
49 public Functor2(string name, object arg1, object arg2) 49 public Functor2(string name, object arg1, object arg2)
50 : this(Atom.a(name), arg1, arg2) 50 : this(Atom.a(name), arg1, arg2)
51 { 51 {
52 } 52 }
53 53
54 public IEnumerable<bool> unify(object arg) 54 public IEnumerable<bool> unify(object arg)
55 { 55 {
56 arg = YP.getValue(arg); 56 arg = YP.getValue(arg);
57 if (arg is Functor2) 57 if (arg is Functor2)
58 { 58 {
59 Functor2 argFunctor = (Functor2)arg; 59 Functor2 argFunctor = (Functor2)arg;
60 if (_name.Equals(argFunctor._name)) 60 if (_name.Equals(argFunctor._name))
61 { 61 {
62 foreach (bool l1 in YP.unify(_arg1, argFunctor._arg1)) 62 foreach (bool l1 in YP.unify(_arg1, argFunctor._arg1))
63 { 63 {
64 foreach (bool l2 in YP.unify(_arg2, argFunctor._arg2)) 64 foreach (bool l2 in YP.unify(_arg2, argFunctor._arg2))
65 yield return false; 65 yield return false;
66 } 66 }
67 } 67 }
68 } 68 }
69 else if (arg is Variable) 69 else if (arg is Variable)
70 { 70 {
71 foreach (bool l1 in ((Variable)arg).unify(this)) 71 foreach (bool l1 in ((Variable)arg).unify(this))
72 yield return false; 72 yield return false;
73 } 73 }
74 } 74 }
75 75
76 public override string ToString() 76 public override string ToString()
77 { 77 {
78 if (_name == Atom.DOT) 78 if (_name == Atom.DOT)
79 return listPairToString(this); 79 return listPairToString(this);
80 else 80 else
81 return _name + "(" + YP.getValue(_arg1) + ", " + YP.getValue(_arg2) + ")"; 81 return _name + "(" + YP.getValue(_arg1) + ", " + YP.getValue(_arg2) + ")";
82 } 82 }
83 83
84 public bool termEqual(object term) 84 public bool termEqual(object term)
85 { 85 {
86 term = YP.getValue(term); 86 term = YP.getValue(term);
87 if (term is Functor2) 87 if (term is Functor2)
88 { 88 {
89 Functor2 termFunctor = (Functor2)term; 89 Functor2 termFunctor = (Functor2)term;
90 return _name.Equals(termFunctor._name) && YP.termEqual(_arg1, termFunctor._arg1) 90 return _name.Equals(termFunctor._name) && YP.termEqual(_arg1, termFunctor._arg1)
91 && YP.termEqual(_arg2, termFunctor._arg2); 91 && YP.termEqual(_arg2, termFunctor._arg2);
92 } 92 }
93 return false; 93 return false;
94 } 94 }
95 95
96 public bool lessThan(Functor2 functor) 96 public bool lessThan(Functor2 functor)
97 { 97 {
98 // Do the equal check first since it is faster. 98 // Do the equal check first since it is faster.
99 if (!_name.Equals(functor._name)) 99 if (!_name.Equals(functor._name))
100 return _name.lessThan(functor._name); 100 return _name.lessThan(functor._name);
101 101
102 if (!YP.termEqual(_arg1, functor._arg1)) 102 if (!YP.termEqual(_arg1, functor._arg1))
103 return YP.termLessThan(_arg1, functor._arg1); 103 return YP.termLessThan(_arg1, functor._arg1);
104 104
105 return YP.termLessThan(_arg2, functor._arg2); 105 return YP.termLessThan(_arg2, functor._arg2);
106 } 106 }
107 107
108 public bool ground() 108 public bool ground()
109 { 109 {
110 return YP.ground(_arg1) && YP.ground(_arg2); 110 return YP.ground(_arg1) && YP.ground(_arg2);
111 } 111 }
112 112
113 public void addUniqueVariables(List<Variable> variableSet) 113 public void addUniqueVariables(List<Variable> variableSet)
114 { 114 {
115 YP.addUniqueVariables(_arg1, variableSet); 115 YP.addUniqueVariables(_arg1, variableSet);
116 YP.addUniqueVariables(_arg2, variableSet); 116 YP.addUniqueVariables(_arg2, variableSet);
117 } 117 }
118 118
119 public object makeCopy(Variable.CopyStore copyStore) 119 public object makeCopy(Variable.CopyStore copyStore)
120 { 120 {
121 return new Functor2(_name, YP.makeCopy(_arg1, copyStore), 121 return new Functor2(_name, YP.makeCopy(_arg1, copyStore),
122 YP.makeCopy(_arg2, copyStore)); 122 YP.makeCopy(_arg2, copyStore));
123 } 123 }
124 124
125 private static string listPairToString(Functor2 listPair) 125 private static string listPairToString(Functor2 listPair)
126 { 126 {
127 string result = "["; 127 string result = "[";
128 while (true) 128 while (true)
129 { 129 {
130 object head = YP.getValue(listPair._arg1); 130 object head = YP.getValue(listPair._arg1);
131 object tail = YP.getValue(listPair._arg2); 131 object tail = YP.getValue(listPair._arg2);
132 if (tail == (object)Atom.NIL) 132 if (tail == (object)Atom.NIL)
133 { 133 {
134 result += head; 134 result += head;
135 break; 135 break;
136 } 136 }
137 else if (tail is Functor2 && ((Functor2)tail)._name == Atom.DOT) 137 else if (tail is Functor2 && ((Functor2)tail)._name == Atom.DOT)
138 { 138 {
139 result += head + ", "; 139 result += head + ", ";
140 listPair = (Functor2)tail; 140 listPair = (Functor2)tail;
141 // Loop again. 141 // Loop again.
142 } 142 }
143 else 143 else
144 { 144 {
145 // The list is not terminated with NIL. 145 // The list is not terminated with NIL.
146 result += head + "|" + tail; 146 result += head + "|" + tail;
147 break; 147 break;
148 } 148 }
149 } 149 }
150 result += "]"; 150 result += "]";
151 return result; 151 return result;
152 } 152 }
153 } 153 }
154} 154}