aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YP.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YP.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YP.cs74
1 files changed, 37 insertions, 37 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YP.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YP.cs
index b69f9c4..694e733 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YP.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YP.cs
@@ -1,20 +1,20 @@
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
@@ -147,7 +147,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
147 /// <summary> 147 /// <summary>
148 /// Convert term to an int. 148 /// Convert term to an int.
149 /// If term is a single-element List, use its first element 149 /// If term is a single-element List, use its first element
150 /// (to handle the char types like "a"). 150 /// (to handle the char types like "a").
151 /// If can't convert, throw a PrologException for type_error evaluable (because this is only 151 /// If can't convert, throw a PrologException for type_error evaluable (because this is only
152 /// called from arithmetic functions). 152 /// called from arithmetic functions).
153 /// </summary> 153 /// </summary>
@@ -172,8 +172,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
172 { 172 {
173 throw new PrologException 173 throw new PrologException
174 (new Functor2 174 (new Functor2
175 ("type_error", Atom.a("evaluable"), 175 ("type_error", Atom.a("evaluable"),
176 new Functor2(Atom.SLASH, getFunctorName(term), getFunctorArgs(term).Length)), 176 new Functor2(Atom.SLASH, getFunctorName(term), getFunctorArgs(term).Length)),
177 "Term must be an integer"); 177 "Term must be an integer");
178 } 178 }
179 } 179 }
@@ -181,7 +181,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
181 /// <summary> 181 /// <summary>
182 /// Convert term to a double. This may convert an int to a double, etc. 182 /// Convert term to a double. This may convert an int to a double, etc.
183 /// If term is a single-element List, use its first element 183 /// If term is a single-element List, use its first element
184 /// (to handle the char types like "a"). 184 /// (to handle the char types like "a").
185 /// If can't convert, throw a PrologException for type_error evaluable (because this is only 185 /// If can't convert, throw a PrologException for type_error evaluable (because this is only
186 /// called from arithmetic functions). 186 /// called from arithmetic functions).
187 /// </summary> 187 /// </summary>
@@ -195,7 +195,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
195 // Assume it is a char type like "a". 195 // Assume it is a char type like "a".
196 term = YP.getValue(((Functor2)term)._arg1); 196 term = YP.getValue(((Functor2)term)._arg1);
197 if (term is Variable) 197 if (term is Variable)
198 throw new PrologException(Atom.a("instantiation_error"), 198 throw new PrologException(Atom.a("instantiation_error"),
199 "Expected a number but the argument is an unbound variable"); 199 "Expected a number but the argument is an unbound variable");
200 200
201 try 201 try
@@ -776,8 +776,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
776 if (term1TypeCode == -2) 776 if (term1TypeCode == -2)
777 { 777 {
778 // Variable. 778 // Variable.
779 // We always check for equality first because we want to be sure 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 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. 781 // case that the less than check really behaves like less than or equal.
782 if ((Variable)Term1 != (Variable)Term2) 782 if ((Variable)Term1 != (Variable)Term2)
783 // The hash code should be unique to a Variable object. 783 // The hash code should be unique to a Variable object.
@@ -820,8 +820,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
820 } 820 }
821 821
822 /// <summary> 822 /// <summary>
823 /// Type code is -2 if term is a Variable, 0 if it is an Atom, 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, 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. 825 /// 4 if it is Functor.
826 /// Otherwise, type code is -1. 826 /// Otherwise, type code is -1.
827 /// This does not call YP.getValue(term). 827 /// This does not call YP.getValue(term).
@@ -1167,7 +1167,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
1167 "Arg 2 List has an element which is an unbound variable"); 1167 "Arg 2 List has an element which is an unbound variable");
1168 if (!(listAtom is Atom && ((Atom)listAtom)._name.Length == 1)) 1168 if (!(listAtom is Atom && ((Atom)listAtom)._name.Length == 1))
1169 throw new PrologException 1169 throw new PrologException
1170 (new Functor2("type_error", Atom.a("character"), listAtom), 1170 (new Functor2("type_error", Atom.a("character"), listAtom),
1171 "Arg 2 List has an element which is not a one character atom"); 1171 "Arg 2 List has an element which is not a one character atom");
1172 charArray[i] = ((Atom)listAtom)._name[0]; 1172 charArray[i] = ((Atom)listAtom)._name[0];
1173 } 1173 }
@@ -1209,7 +1209,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
1209 int codeInt; 1209 int codeInt;
1210 if (!getInt(codeArray[i], out codeInt) || codeInt < 0) 1210 if (!getInt(codeArray[i], out codeInt) || codeInt < 0)
1211 throw new PrologException 1211 throw new PrologException
1212 (new Functor1("representation_error", Atom.a("character_code")), 1212 (new Functor1("representation_error", Atom.a("character_code")),
1213 "Element of Arg 2 List is not a character code"); 1213 "Element of Arg 2 List is not a character code");
1214 charArray[i] = (char)codeInt; 1214 charArray[i] = (char)codeInt;
1215 } 1215 }
@@ -1323,7 +1323,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
1323 { 1323 {
1324 if (!YP.number(Number)) 1324 if (!YP.number(Number))
1325 throw new PrologException 1325 throw new PrologException
1326 (new Functor2("type_error", Atom.a("number"), Number), 1326 (new Functor2("type_error", Atom.a("number"), Number),
1327 "Arg 1 Number is not var or number"); 1327 "Arg 1 Number is not var or number");
1328 // We just checked, so convertDouble shouldn't throw an exception. 1328 // We just checked, so convertDouble shouldn't throw an exception.
1329 numberString = YP.doubleToString(YP.convertDouble(Number)); 1329 numberString = YP.doubleToString(YP.convertDouble(Number));
@@ -1413,7 +1413,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
1413 { 1413 {
1414 if (!(Char is Atom) || ((Atom)Char)._name.Length != 1) 1414 if (!(Char is Atom) || ((Atom)Char)._name.Length != 1)
1415 throw new PrologException 1415 throw new PrologException
1416 (new Functor2("type_error", Atom.a("character"), Char), 1416 (new Functor2("type_error", Atom.a("character"), Char),
1417 "Arg 1 Char is not var or one-character atom"); 1417 "Arg 1 Char is not var or one-character atom");
1418 1418
1419 if (Code is Variable) 1419 if (Code is Variable)
@@ -1795,7 +1795,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
1795 IndexedAnswers indexedAnswers; 1795 IndexedAnswers indexedAnswers;
1796 if (!_predicatesStore.TryGetValue(nameArity, out clauses)) 1796 if (!_predicatesStore.TryGetValue(nameArity, out clauses))
1797 { 1797 {
1798 // Create an IndexedAnswers as the only clause of the predicate. 1798 // Create an IndexedAnswers as the only clause of the predicate.
1799 _predicatesStore[nameArity] = (clauses = new List<IClause>()); 1799 _predicatesStore[nameArity] = (clauses = new List<IClause>());
1800 clauses.Add(indexedAnswers = new IndexedAnswers(values.Length)); 1800 clauses.Add(indexedAnswers = new IndexedAnswers(values.Length));
1801 } 1801 }
@@ -1826,7 +1826,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
1826 IndexedAnswers indexedAnswers; 1826 IndexedAnswers indexedAnswers;
1827 if (!_predicatesStore.TryGetValue(nameArity, out clauses)) 1827 if (!_predicatesStore.TryGetValue(nameArity, out clauses))
1828 { 1828 {
1829 // Create an IndexedAnswers as the only clause of the predicate. 1829 // Create an IndexedAnswers as the only clause of the predicate.
1830 _predicatesStore[nameArity] = (clauses = new List<IClause>()); 1830 _predicatesStore[nameArity] = (clauses = new List<IClause>());
1831 clauses.Add(indexedAnswers = new IndexedAnswers(values.Length)); 1831 clauses.Add(indexedAnswers = new IndexedAnswers(values.Length));
1832 } 1832 }
@@ -1855,7 +1855,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
1855 { 1855 {
1856 List<IClause> clauses; 1856 List<IClause> clauses;
1857 if (!_predicatesStore.TryGetValue(new NameArity(name, arguments.Length), out clauses)) 1857 if (!_predicatesStore.TryGetValue(new NameArity(name, arguments.Length), out clauses))
1858 return unknownPredicate(name, arguments.Length, 1858 return unknownPredicate(name, arguments.Length,
1859 "Undefined dynamic predicate: " + name + "/" + arguments.Length); 1859 "Undefined dynamic predicate: " + name + "/" + arguments.Length);
1860 1860
1861 if (clauses.Count == 1) 1861 if (clauses.Count == 1)
@@ -1889,7 +1889,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
1889 } 1889 }
1890 1890
1891 /// <summary> 1891 /// <summary>
1892 /// If _prologFlags["unknown"] is fail then return fail(), else if 1892 /// If _prologFlags["unknown"] is fail then return fail(), else if
1893 /// _prologFlags["unknown"] is warning then write the message to YP.write and 1893 /// _prologFlags["unknown"] is warning then write the message to YP.write and
1894 /// return fail(), else throw a PrologException for existence_error. . 1894 /// return fail(), else throw a PrologException for existence_error. .
1895 /// </summary> 1895 /// </summary>
@@ -1917,7 +1917,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
1917 } 1917 }
1918 1918
1919 /// <summary> 1919 /// <summary>
1920 /// This is deprecated and just calls matchDynamic. This matches all clauses, 1920 /// This is deprecated and just calls matchDynamic. This matches all clauses,
1921 /// not just the ones defined with assertFact. 1921 /// not just the ones defined with assertFact.
1922 /// </summary> 1922 /// </summary>
1923 /// <param name="name"></param> 1923 /// <param name="name"></param>
@@ -2066,7 +2066,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
2066 /// dynamic predicate. 2066 /// dynamic predicate.
2067 /// </summary> 2067 /// </summary>
2068 /// <param name="NameSlashArity"></param> 2068 /// <param name="NameSlashArity"></param>
2069 /// <param name="declaringClass">if not null, used to resolve references to the default 2069 /// <param name="declaringClass">if not null, used to resolve references to the default
2070 /// module Atom.a("")</param> 2070 /// module Atom.a("")</param>
2071 /// <returns></returns> 2071 /// <returns></returns>
2072 public static IEnumerable<bool> current_predicate(object NameSlashArity, Type declaringClass) 2072 public static IEnumerable<bool> current_predicate(object NameSlashArity, Type declaringClass)
@@ -2078,7 +2078,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
2078 Functor2 NameArityFunctor = NameSlashArity as Functor2; 2078 Functor2 NameArityFunctor = NameSlashArity as Functor2;
2079 if (!(NameArityFunctor != null && NameArityFunctor._name == Atom.SLASH)) 2079 if (!(NameArityFunctor != null && NameArityFunctor._name == Atom.SLASH))
2080 throw new PrologException 2080 throw new PrologException
2081 (new Functor2("type_error", Atom.a("predicate_indicator"), NameSlashArity), 2081 (new Functor2("type_error", Atom.a("predicate_indicator"), NameSlashArity),
2082 "Must be a name/arity predicate indicator"); 2082 "Must be a name/arity predicate indicator");
2083 object name = YP.getValue(NameArityFunctor._arg1); 2083 object name = YP.getValue(NameArityFunctor._arg1);
2084 object arity = YP.getValue(NameArityFunctor._arg2); 2084 object arity = YP.getValue(NameArityFunctor._arg2);
@@ -2163,12 +2163,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
2163 } 2163 }
2164 2164
2165 /// <summary> 2165 /// <summary>
2166 /// If Goal is a simple predicate, call YP.getFunctorName(Goal) using arguments from 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. 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. 2168 /// Otherwise, compile the goal as a single clause predicate and invoke it.
2169 /// </summary> 2169 /// </summary>
2170 /// <param name="Goal"></param> 2170 /// <param name="Goal"></param>
2171 /// <param name="declaringClass">if not null, used to resolve references to the default 2171 /// <param name="declaringClass">if not null, used to resolve references to the default
2172 /// module Atom.a("")</param> 2172 /// module Atom.a("")</param>
2173 /// <returns></returns> 2173 /// <returns></returns>
2174 public static IEnumerable<bool> getIterator(object Goal, Type declaringClass) 2174 public static IEnumerable<bool> getIterator(object Goal, Type declaringClass)
@@ -2259,7 +2259,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
2259 (new Functor2("type_error", Atom.a("atom"), Key), "Arg 1 Key is not an atom"); 2259 (new Functor2("type_error", Atom.a("atom"), Key), "Arg 1 Key is not an atom");
2260 if (!_prologFlags.ContainsKey(((Atom)Key)._name)) 2260 if (!_prologFlags.ContainsKey(((Atom)Key)._name))
2261 throw new PrologException 2261 throw new PrologException
2262 (new Functor2("domain_error", Atom.a("prolog_flag"), Key), 2262 (new Functor2("domain_error", Atom.a("prolog_flag"), Key),
2263 "Arg 1 Key is not a recognized flag"); 2263 "Arg 1 Key is not a recognized flag");
2264 2264
2265 foreach (bool l1 in YP.unify(Value, _prologFlags[((Atom)Key)._name])) 2265 foreach (bool l1 in YP.unify(Value, _prologFlags[((Atom)Key)._name]))
@@ -2343,7 +2343,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
2343 string results = ""; 2343 string results = "";
2344 for (Match m = Regex.Match(inData,inPattern); m.Success; m=m.NextMatch()) 2344 for (Match m = Regex.Match(inData,inPattern); m.Success; m=m.NextMatch())
2345 { 2345 {
2346 //Console.WriteLine( m ); 2346 //Console.WriteLine( m );
2347 results += presep+ m + postsep; 2347 results += presep+ m + postsep;
2348 } 2348 }
2349 return results; 2349 return results;
@@ -2662,7 +2662,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
2662 #pragma warning restore 0168 2662 #pragma warning restore 0168
2663 } 2663 }
2664 } 2664 }
2665 2665
2666 /// <summary> 2666 /// <summary>
2667 /// CodeListReader extends TextReader and overrides Read to read the next code from 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. 2668 /// the CodeList which is a Prolog list of integer character codes.
@@ -2683,7 +2683,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
2683 /// <returns></returns> 2683 /// <returns></returns>
2684 public override int Read() 2684 public override int Read()
2685 { 2685 {
2686 Functor2 CodeListPair = _CodeList as Functor2; 2686 Functor2 CodeListPair = _CodeList as Functor2;
2687 int code; 2687 int code;
2688 if (!(CodeListPair != null && CodeListPair._name == Atom.DOT && 2688 if (!(CodeListPair != null && CodeListPair._name == Atom.DOT &&
2689 getInt(CodeListPair._arg1, out code))) 2689 getInt(CodeListPair._arg1, out code)))