From 80079e14e3f92accb309c25778fe87e3916e0143 Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Sat, 7 Jun 2008 15:43:16 +0000 Subject: Mantis#1475. Thank you kindly, Kinoc for a patch that: This patch brings the Yield Prolog in sync with the YP r669. Biggest item is support for functions asserta and assertz , providing dynamic databases. --- .../DotNetEngine/Compiler/YieldProlog/YP.cs | 270 ++++++- .../Compiler/YieldProlog/YPCompiler.cs | 782 ++++++++++++++++----- 2 files changed, 830 insertions(+), 222 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YP.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YP.cs index a03cd30..68cfd3e 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YP.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YP.cs @@ -149,6 +149,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog YP.getValue(((Functor2)term)._arg2) == Atom.NIL) // Assume it is a char type like "a". term = YP.getValue(((Functor2)term)._arg1); + if (term is Variable) + throw new PrologException(Atom.a("instantiation_error"), + "Expected a number but the argument is an unbound variable"); return Convert.ToDouble(term); } @@ -982,11 +985,22 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog return YP.getValue(Term) is Atom; } + public static bool integer(object Term) + { + // Debug: Should exhaustively check for all integer types. + return getValue(Term) is int; + } + + // Use isFloat instead of float because it is a reserved keyword. + public static bool isFloat(object Term) + { + // Debug: Should exhaustively check for all float types. + return getValue(Term) is double; + } + public static bool number(object Term) { - Term = getValue(Term); - // Debug: Should exhaustively check for all number types. - return Term is int || Term is double; + return YP.integer(Term) || YP.isFloat(Term); } public static bool atomic(object Term) @@ -1060,6 +1074,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog _outputStream = Console.Out; } + public static IEnumerable current_output(object Stream) + { + return YP.unify(Stream, _outputStream); + } + public static void write(object x) { x = YP.getValue(x); @@ -1108,6 +1127,93 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog return YP.unify(code, _inputStream.Read()); } + public static void asserta(object Term, Type declaringClass) + { + assertDynamic(Term, declaringClass, true); + } + + public static void assertz(object Term, Type declaringClass) + { + assertDynamic(Term, declaringClass, false); + } + + public static void assertDynamic(object Term, Type declaringClass, bool prepend) + { + Term = getValue(Term); + if (Term is Variable) + throw new PrologException("instantiation_error", "Term to assert is an unbound variable"); + + Variable.CopyStore copyStore = new Variable.CopyStore(); + object TermCopy = makeCopy(Term, copyStore); + object Head, Body; + if (TermCopy is Functor2 && ((Functor2)TermCopy)._name == Atom.RULE) + { + Head = YP.getValue(((Functor2)TermCopy)._arg1); + Body = YP.getValue(((Functor2)TermCopy)._arg2); + } + else + { + Head = TermCopy; + Body = Atom.a("true"); + } + + Atom name = getFunctorName(Head) as Atom; + if (name == null) + // name is a non-Atom, such as a number. + throw new PrologException + (new Functor2("type_error", Atom.a("callable"), Head), "Term to assert is not callable"); + object[] args = getFunctorArgs(Head); + if (!isDynamic(name, args.Length)) + throw new PrologException + (new Functor3("permission_error", Atom.a("modify"), Atom.a("static_procedure"), + new Functor2(Atom.SLASH, name, args.Length)), + "Assert cannot modify static predicate " + name + "/" + args.Length); + + if (copyStore.getNUniqueVariables() == 0 && Body == Atom.a("true")) + { + // Debug: Until IndexedAnswers supports prepend, compile the fact so we can prepend it below. + if (!prepend) + { + // This is a fact with no unbound variables + // assertFact uses IndexedAnswers, so don't we don't need to compile. + assertFact(name, args); + return; + } + } + + IClause clause = YPCompiler.compileAnonymousClause(Head, Body, declaringClass); + + // Add the clause to the entry in _predicatesStore. + NameArity nameArity = new NameArity(name, args.Length); + List clauses; + if (!_predicatesStore.TryGetValue(nameArity, out clauses)) + // Create an entry for the nameArity. + _predicatesStore[nameArity] = (clauses = new List()); + + if (prepend) + clauses.Insert(0, clause); + else + clauses.Add(clause); + } + + private static bool isDynamic(Atom name, int arity) + { + if (arity == 2 && (name == Atom.a(",") || name == Atom.a(";") || name == Atom.DOT)) + return false; + // Use the same mapping to static predicates in YP as the compiler. + foreach (bool l1 in YPCompiler.functorCallYPFunctionName(name, arity, new Variable())) + return false; + // Debug: Do we need to check if name._module is null? + return true; + } + + /// + /// Assert values at the end of the set of facts for the predicate with the + /// name and with arity values.Length. + /// + /// must be an Atom + /// the array of arguments to the fact predicate. + /// It is an error if an value has an unbound variable. public static void assertFact(Atom name, object[] values) { NameArity nameArity = new NameArity(name, values.Length); @@ -1130,7 +1236,15 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog indexedAnswers.addAnswer(values); } - public static IEnumerable matchFact(Atom name, object[] arguments) + /// + /// Match all clauses of the dynamic predicate with the name and with arity + /// arguments.Length. + /// It is an error if the predicate is not defined. + /// + /// must be an Atom + /// an array of arity number of arguments + /// an iterator which you can use in foreach + public static IEnumerable matchDynamic(Atom name, object[] arguments) { List clauses; if (!_predicatesStore.TryGetValue(new NameArity(name, arguments.Length), out clauses)) @@ -1147,20 +1261,46 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog /// /// Call match(arguments) for each IClause in clauses. We make this a separate - /// function so that matchFact itself does not need to be an iterator object. + /// function so that matchDynamic itself does not need to be an iterator object. /// /// /// /// private static IEnumerable matchAllClauses(List clauses, object[] arguments) { + // Debug: If the clause asserts another clause into this same predicate, the iterator + // over clauses will be corrupted. Should we take the time to copy clauses? foreach (IClause clause in clauses) { foreach (bool lastCall in clause.match(arguments)) + { yield return false; + if (lastCall) + // This happens after a cut in a clause. + yield break; + } } } + /// + /// This is deprecated and just calls matchDynamic. This matches all clauses, + /// not just the ones defined with assertFact. + /// + /// + /// + /// + public static IEnumerable matchFact(Atom name, object[] arguments) + { + return matchDynamic(name, arguments); + } + + /// + /// This actually searches all clauses, not just + /// the ones defined with assertFact, but we keep the name for + /// backwards compatibility. + /// + /// must be an Atom + /// an array of arity number of arguments public static void retractFact(Atom name, object[] arguments) { NameArity nameArity = new NameArity(name, arguments.Length); @@ -1219,40 +1359,18 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog /// public static IEnumerable getIterator(object Goal, Type declaringClass) { + Goal = YP.getValue(Goal); + if (Goal is Variable) + throw new PrologException("instantiation_error", "Goal to call is an unbound variable"); #if true List variableSetList = new List(); addUniqueVariables(Goal, variableSetList); Variable[] variableSet = variableSetList.ToArray(); - object Head = Functor.make("function", variableSet); - object Rule = new Functor2(Atom.RULE, Head, Goal); - object RuleList = ListPair.make(new Functor2(Atom.F, Rule, Atom.NIL)); - StringWriter functionCode = new StringWriter(); - TextWriter saveOutputStream = _outputStream; - try - { - tell(functionCode); - Variable FunctionCode = new Variable(); - foreach (bool l1 in YPCompiler.makeFunctionPseudoCode(RuleList, FunctionCode)) - { - if (YP.termEqual(FunctionCode, Atom.a("getDeclaringClass"))) - // Ignore getDeclaringClass since we have access to the one passed in. - continue; - - // Debug: should check if FunctionCode is a single call. - YPCompiler.convertFunctionCSharp(FunctionCode); - } - told(); - } - finally - { - // Restore after calling tell. - _outputStream = saveOutputStream; - } - return YPCompiler.compileAnonymousFunction - (functionCode.ToString(), variableSet.Length, declaringClass).match(variableSet); + // Use Atom.F since it is ignored. + return YPCompiler.compileAnonymousClause + (Functor.make(Atom.F, variableSet), Goal, declaringClass).match(variableSet); #else - Goal = YP.getValue(Goal); Atom name; object[] args; while (true) @@ -1436,5 +1554,91 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog throw new NotImplementedException(); } } + + /// + /// An enumerator that wraps another enumerator in order to catch a PrologException. + /// + public class Catch : IEnumerator, IEnumerable + { + private IEnumerator _enumerator; + private PrologException _exception = null; + + public Catch(IEnumerable iterator) + { + _enumerator = iterator.GetEnumerator(); + } + + /// + /// Call _enumerator.MoveNext(). If it throws a PrologException, set _exception + /// and return false. After this returns false, call unifyExceptionOrThrow. + /// Assume that, after this returns false, it will not be called again. + /// + /// + public bool MoveNext() + { + try + { + return _enumerator.MoveNext(); + } + catch (PrologException exception) + { + _exception = exception; + return false; + } + } + + /// + /// Call this after MoveNext() returns false to check for an exception. If + /// MoveNext did not get a PrologException, don't yield. + /// Otherwise, unify the exception with Catcher and yield so the caller can + /// do the handler code. However, if can't unify with Catcher then throw the exception. + /// + /// + /// + public IEnumerable unifyExceptionOrThrow(object Catcher) + { + if (_exception != null) + { + bool didUnify = false; + foreach (bool l1 in YP.unify(_exception._term, Catcher)) + { + didUnify = true; + yield return false; + } + if (!didUnify) + throw _exception; + } + } + + public IEnumerator GetEnumerator() + { + return (IEnumerator)this; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public bool Current + { + get { return _enumerator.Current; } + } + + object IEnumerator.Current + { + get { return _enumerator.Current; } + } + + public void Dispose() + { + _enumerator.Dispose(); + } + + public void Reset() + { + throw new NotImplementedException(); + } + } } } diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YPCompiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YPCompiler.cs index d998bac..572583b 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YPCompiler.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/YPCompiler.cs @@ -276,6 +276,58 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog } /// + /// Use makeFunctionPseudoCode, convertFunctionCSharp and compileAnonymousFunction + /// to return an anonymous YP.IClause for the Head and Body of a rule clause. + /// + /// a prolog term such as new Functor2("test1", X, Y). + /// Note that the name of the head is ignored. + /// + /// a prolog term such as + /// new Functor2(",", new Functor1(Atom.a("test2", Atom.a("")), X), + /// new Functor2("=", Y, X)). + /// This may not be null. (For a head-only clause, set the Body to Atom.a("true"). + /// + /// if not null, the code is compiled as a subclass of this class + /// to resolve references to the default module Atom.a("") + /// a new YP.IClause object on which you can call match(object[] args) where + /// args length is the arity of the Head + public static YP.IClause compileAnonymousClause(object Head, object Body, Type declaringClass) + { + object[] args = YP.getFunctorArgs(Head); + // compileAnonymousFunction wants "function". + object Rule = new Functor2(Atom.RULE, Functor.make("function", args), Body); + object RuleList = ListPair.make(new Functor2(Atom.F, Rule, Atom.NIL)); + + StringWriter functionCode = new StringWriter(); + Variable SaveOutputStream = new Variable(); + foreach (bool l1 in YP.current_output(SaveOutputStream)) + { + try + { + YP.tell(functionCode); + Variable FunctionCode = new Variable(); + foreach (bool l2 in makeFunctionPseudoCode(RuleList, FunctionCode)) + { + if (YP.termEqual(FunctionCode, Atom.a("getDeclaringClass"))) + // Ignore getDeclaringClass since we have access to the one passed in. + continue; + + // Debug: should check if FunctionCode is a single call. + convertFunctionCSharp(FunctionCode); + } + YP.told(); + } + finally + { + // Restore after calling tell. + YP.tell(SaveOutputStream.getValue()); + } + } + return YPCompiler.compileAnonymousFunction + (functionCode.ToString(), args.Length, declaringClass); + } + + /// /// Use CodeDomProvider to compile the functionCode and return a YP.IClause. /// The function name must be "function" and have nArgs arguments. /// @@ -337,8 +389,8 @@ namespace Temporary { // Compiler output follows. - class YPInnerClass { } - static Type getDeclaringClass() { return typeof(YPInnerClass).DeclaringType; } + public class YPInnerClass { } + public static System.Type getDeclaringClass() { return typeof(YPInnerClass).DeclaringType; } public static void repeatWrite(object arg1, object N) { @@ -391,7 +443,11 @@ namespace Temporary { CompilerState.assertPred(State, new Functor1(@"var", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); CompilerState.assertPred(State, new Functor1(@"nonvar", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); CompilerState.assertPred(State, new Functor1(@"atom", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); + CompilerState.assertPred(State, new Functor1(@"integer", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); + CompilerState.assertPred(State, new Functor1(@"float", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); CompilerState.assertPred(State, new Functor1(@"number", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); + CompilerState.assertPred(State, new Functor1(@"atomic", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); + CompilerState.assertPred(State, new Functor1(@"compound", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); CompilerState.assertPred(State, new Functor2(@"==", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in")), new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); CompilerState.assertPred(State, new Functor2(@"\==", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in")), new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); CompilerState.assertPred(State, new Functor2(@"@<", new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in")), new Functor2(@"::", Atom.a(@"univ"), Atom.a(@"in"))), Atom.a(@"semidet")); @@ -654,13 +710,37 @@ namespace Temporary { } goto cutIf7; } - foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) + if (CompilerState.determinismEquals(State, Atom.a(@"detNoneOut"))) + { + foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) + { + foreach (bool l14 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) + { + yield return false; + } + } + goto cutIf8; + } + if (CompilerState.codeUsesYield(State)) + { + foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) + { + foreach (bool l14 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) + { + yield return false; + } + } + goto cutIf9; + } + 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)) { foreach (bool l13 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) { yield return false; } } + cutIf9: + cutIf8: cutIf7: { } } @@ -679,19 +759,43 @@ namespace Temporary { yield return false; } } - goto cutIf9; + goto cutIf11; } - foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) + if (CompilerState.determinismEquals(State, Atom.a(@"detNoneOut"))) + { + foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) + { + foreach (bool l14 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) + { + yield return false; + } + } + goto cutIf12; + } + if (CompilerState.codeUsesYield(State)) + { + foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) + { + foreach (bool l14 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) + { + yield return false; + } + } + goto cutIf13; + } + 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)) { foreach (bool l13 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) { yield return false; } } - cutIf9: + cutIf13: + cutIf12: + cutIf11: { } } - goto cutIf8; + goto cutIf10; } foreach (bool l10 in YP.unify(ReturnType, Atom.a(@"IEnumerable"))) { @@ -704,19 +808,43 @@ namespace Temporary { yield return false; } } - goto cutIf10; + goto cutIf14; } - foreach (bool l11 in YP.unify(BodyWithReturn, BodyCode)) + if (CompilerState.determinismEquals(State, Atom.a(@"detNoneOut"))) + { + foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) + { + foreach (bool l13 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) + { + yield return false; + } + } + goto cutIf15; + } + if (CompilerState.codeUsesYield(State)) + { + foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) + { + foreach (bool l13 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) + { + yield return false; + } + } + goto cutIf16; + } + 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)) { foreach (bool l12 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) { yield return false; } } - cutIf10: + cutIf16: + cutIf15: + cutIf14: { } } - cutIf8: + cutIf10: cutIf6: { } } @@ -730,36 +858,36 @@ namespace Temporary { foreach (bool l3 in YP.unify(Head, FirstRule)) { CompilerState.startFunction(State, Head); - FindallAnswers findallAnswers11 = new FindallAnswers(new Functor2(@"f", ArgAssignments, Calls)); + FindallAnswers findallAnswers17 = new FindallAnswers(new Functor2(@"f", ArgAssignments, Calls)); foreach (bool l4 in member(new Functor2(@"f", Rule, VariableNameSuggestions), SamePredicateRuleList)) { foreach (bool l5 in compileBodyWithHeadBindings(Rule, VariableNameSuggestions, State, ArgAssignments, Calls)) { - findallAnswers11.add(); + findallAnswers17.add(); } } - foreach (bool l4 in findallAnswers11.result(ClauseBag)) + foreach (bool l4 in findallAnswers17.result(ClauseBag)) { foreach (bool l5 in YP.univ(Head, new ListPair(Name, ArgsList))) { foreach (bool l6 in getFunctionArgNames(ArgsList, 1, FunctionArgNames)) { - FindallAnswers findallAnswers12 = new FindallAnswers(MergedArgName); + FindallAnswers findallAnswers18 = new FindallAnswers(MergedArgName); foreach (bool l7 in member(ArgName, FunctionArgNames)) { foreach (bool l8 in argAssignedAll(ArgName, ClauseBag, MergedArgName)) { - findallAnswers12.add(); - goto cutIf13; + findallAnswers18.add(); + goto cutIf19; } foreach (bool l8 in YP.unify(MergedArgName, ArgName)) { - findallAnswers12.add(); + findallAnswers18.add(); } - cutIf13: + cutIf19: { } } - foreach (bool l7 in findallAnswers12.result(MergedArgNames)) + foreach (bool l7 in findallAnswers18.result(MergedArgNames)) { foreach (bool l8 in maplist_arg(MergedArgNames, FunctionArgs)) { @@ -778,19 +906,43 @@ namespace Temporary { yield return false; } } - goto cutIf15; + goto cutIf21; } - foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) + if (CompilerState.determinismEquals(State, Atom.a(@"detNoneOut"))) + { + foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) + { + foreach (bool l14 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) + { + yield return false; + } + } + goto cutIf22; + } + if (CompilerState.codeUsesYield(State)) + { + foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) + { + foreach (bool l14 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) + { + yield return false; + } + } + goto cutIf23; + } + 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)) { foreach (bool l13 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) { yield return false; } } - cutIf15: + cutIf23: + cutIf22: + cutIf21: { } } - goto cutIf14; + goto cutIf20; } if (CompilerState.determinismEquals(State, Atom.a(@"semidetNoneOut"))) { @@ -805,19 +957,43 @@ namespace Temporary { yield return false; } } - goto cutIf17; + goto cutIf25; } - foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) + if (CompilerState.determinismEquals(State, Atom.a(@"detNoneOut"))) + { + foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) + { + foreach (bool l14 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) + { + yield return false; + } + } + goto cutIf26; + } + if (CompilerState.codeUsesYield(State)) + { + foreach (bool l13 in YP.unify(BodyWithReturn, BodyCode)) + { + foreach (bool l14 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) + { + yield return false; + } + } + goto cutIf27; + } + 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)) { foreach (bool l13 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) { yield return false; } } - cutIf17: + cutIf27: + cutIf26: + cutIf25: { } } - goto cutIf16; + goto cutIf24; } foreach (bool l10 in YP.unify(ReturnType, Atom.a(@"IEnumerable"))) { @@ -830,20 +1006,44 @@ namespace Temporary { yield return false; } } - goto cutIf18; + goto cutIf28; + } + if (CompilerState.determinismEquals(State, Atom.a(@"detNoneOut"))) + { + foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) + { + foreach (bool l13 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) + { + yield return false; + } + } + goto cutIf29; } - foreach (bool l11 in YP.unify(BodyWithReturn, BodyCode)) + if (CompilerState.codeUsesYield(State)) + { + foreach (bool l12 in YP.unify(BodyWithReturn, BodyCode)) + { + foreach (bool l13 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) + { + yield return false; + } + } + goto cutIf30; + } + 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)) { foreach (bool l12 in YP.unify(FunctionCode, new Functor(@"function", new object[] { ReturnType, Name, FunctionArgs, BodyWithReturn }))) { yield return false; } } - cutIf18: + cutIf30: + cutIf29: + cutIf28: { } } - cutIf16: - cutIf14: + cutIf24: + cutIf20: { } } } @@ -1537,11 +1737,12 @@ namespace Temporary { } } { - object _State = arg2; + object State = arg2; foreach (bool l2 in YP.unify(arg1, Atom.a(@"!"))) { foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(@"yieldtrue"), new ListPair(Atom.a(@"yieldbreak"), Atom.NIL)))) { + CompilerState.setCodeUsesYield(State); yield return true; yield break; } @@ -1588,11 +1789,12 @@ namespace Temporary { } } { - object _State = arg2; + object State = arg2; foreach (bool l2 in YP.unify(arg1, Atom.a(@"true"))) { foreach (bool l3 in YP.unify(arg3, new ListPair(Atom.a(@"yieldfalse"), Atom.NIL))) { + CompilerState.setCodeUsesYield(State); yield return true; yield break; } @@ -2022,6 +2224,97 @@ namespace Temporary { object State = arg2; Variable A = new Variable(); Variable B = new Variable(); + Variable ATermCode = new Variable(); + Variable BCode = new Variable(); + foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor1(@"asserta", A), B))) + { + 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))) + { + foreach (bool l4 in compileTerm(A, State, ATermCode)) + { + foreach (bool l5 in compileRuleBody(B, State, BCode)) + { + yield return true; + yield break; + } + } + } + } + } + { + object State = arg2; + Variable A = new Variable(); + Variable B = new Variable(); + Variable ATermCode = new Variable(); + Variable BCode = new Variable(); + foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor1(@"assertz", A), B))) + { + 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))) + { + foreach (bool l4 in compileTerm(A, State, ATermCode)) + { + foreach (bool l5 in compileRuleBody(B, State, BCode)) + { + yield return true; + yield break; + } + } + } + } + } + { + object State = arg2; + object PseudoCode = arg3; + Variable A = new Variable(); + Variable B = new Variable(); + foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor1(@"assert", A), B))) + { + foreach (bool l3 in compileRuleBody(new Functor2(@",", new Functor1(@"assertz", A), B), State, PseudoCode)) + { + yield return true; + yield break; + } + } + } + { + object State = arg2; + Variable Goal = new Variable(); + Variable Catcher = new Variable(); + Variable Handler = new Variable(); + Variable B = new Variable(); + Variable CatchGoal = new Variable(); + Variable GoalTermCode = new Variable(); + Variable BCode = new Variable(); + Variable CatcherTermCode = new Variable(); + Variable HandlerAndBCode = new Variable(); + foreach (bool l2 in YP.unify(arg1, new Functor2(@",", new Functor3(@"catch", Goal, Catcher, Handler), B))) + { + foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor3(@"declare", Atom.a(@"YP.Catch"), CatchGoal, new Functor2(@"new", Atom.a(@"YP.Catch"), new ListPair(new Functor2(@"call", Atom.a(@"YP.getIterator"), new ListPair(GoalTermCode, new ListPair(new Functor2(@"call", Atom.a(@"getDeclaringClass"), Atom.NIL), Atom.NIL))), Atom.NIL))), new ListPair(new Functor2(@"foreach", new Functor1(@"var", CatchGoal), BCode), new ListPair(new Functor2(@"foreach", new Functor3(@"callMember", new Functor1(@"var", CatchGoal), Atom.a(@"unifyExceptionOrThrow"), new ListPair(CatcherTermCode, Atom.NIL)), HandlerAndBCode), Atom.NIL))))) + { + foreach (bool l4 in CompilerState.gensym(State, Atom.a(@"catchGoal"), CatchGoal)) + { + foreach (bool l5 in compileTerm(Goal, State, GoalTermCode)) + { + foreach (bool l6 in compileTerm(Catcher, State, CatcherTermCode)) + { + foreach (bool l7 in compileRuleBody(B, State, BCode)) + { + foreach (bool l8 in compileRuleBody(new Functor2(@",", Handler, B), State, HandlerAndBCode)) + { + yield return true; + yield break; + } + } + } + } + } + } + } + } + { + object State = arg2; + Variable A = new Variable(); + Variable B = new Variable(); Variable ACode = new Variable(); Variable BCode = new Variable(); foreach (bool l2 in YP.unify(arg1, new Functor2(@",", A, B))) @@ -2254,28 +2547,39 @@ namespace Temporary { } } - public static IEnumerable compileFunctorCall(object Functor_1, object State, object arg3) + public static IEnumerable compileFunctorCall(object Functor_1, object State, object PseudoCode) { { - Variable FunctionName = new Variable(); - Variable CompiledArgs = new Variable(); Variable FunctorName = new Variable(); Variable FunctorArgs = new Variable(); - Variable x7 = new Variable(); + Variable x6 = new Variable(); Variable Arity = new Variable(); - foreach (bool l2 in YP.unify(arg3, new Functor2(@"call", FunctionName, CompiledArgs))) + Variable CompiledArgs = new Variable(); + Variable FunctionName = new Variable(); + foreach (bool l2 in YP.univ(Functor_1, new ListPair(FunctorName, FunctorArgs))) { - foreach (bool l3 in YP.univ(Functor_1, new ListPair(FunctorName, FunctorArgs))) + foreach (bool l3 in YP.functor(Functor_1, x6, Arity)) { - foreach (bool l4 in YP.functor(Functor_1, x7, Arity)) + foreach (bool l4 in maplist_compileTerm(FunctorArgs, State, CompiledArgs)) { foreach (bool l5 in functorCallFunctionName(State, FunctorName, Arity, FunctionName)) { - foreach (bool l6 in maplist_compileTerm(FunctorArgs, State, CompiledArgs)) + if (YP.termEqual(FunctionName, Atom.NIL)) + { + 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))))) + { + yield return true; + yield break; + } + goto cutIf1; + } + foreach (bool l6 in YP.unify(PseudoCode, new Functor2(@"call", FunctionName, CompiledArgs))) { yield return true; yield break; } + cutIf1: + { } } } } @@ -2287,11 +2591,24 @@ namespace Temporary { { { object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"="))) + object Name = arg2; + object Arity = arg3; + object FunctionName = arg4; + foreach (bool l2 in functorCallYPFunctionName(Name, Arity, FunctionName)) { - foreach (bool l3 in YP.unify(arg3, 2)) + yield return true; + yield break; + } + } + { + object State = arg1; + object Arity = arg3; + Variable Name = new Variable(); + foreach (bool l2 in YP.unify(arg2, Name)) + { + foreach (bool l3 in YP.unify(arg4, Name)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.unify"))) + if (CompilerState.nameArityHasModule(State, Name, Arity, Atom.a(@""))) { yield return true; yield break; @@ -2300,12 +2617,14 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"=.."))) + object _State = arg1; + object _Arity = arg3; + Variable Name = new Variable(); + foreach (bool l2 in YP.unify(arg2, Name)) { - foreach (bool l3 in YP.unify(arg3, 2)) + foreach (bool l3 in YP.unify(arg4, Name)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.univ"))) + foreach (bool l4 in Atom.module(Name, Atom.a(@""))) { yield return true; yield break; @@ -2314,12 +2633,54 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"var"))) + object _State = arg1; + object Name = arg2; + object Arity = arg3; + foreach (bool l2 in YP.unify(arg4, Atom.NIL)) { - foreach (bool l3 in YP.unify(arg3, 1)) + foreach (bool l3 in Atom.module(Name, Atom.NIL)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.var"))) + yield return true; + yield break; + } + } + } + { + object _State = arg1; + object Name = arg2; + object Arity = arg3; + object x4 = arg4; + Variable Module = new Variable(); + Variable Message = new Variable(); + foreach (bool l2 in Atom.module(Name, Module)) + { + foreach (bool l3 in YP.atom_concat(Atom.a(@"Not supporting calls to external module: "), Module, Message)) + { + YP.throwException(new Functor2(@"error", new Functor2(@"type_error", Atom.a(@"callable"), new Functor2(@"/", Name, Arity)), Message)); + yield return true; + yield break; + } + } + } + { + object _State = arg1; + object Name = arg2; + object _Arity = arg3; + object x4 = arg4; + YP.throwException(new Functor2(@"error", new Functor2(@"type_error", Atom.a(@"callable"), Name), Atom.a(@"Term is not callable"))); + yield return true; + yield break; + } + } + + public static IEnumerable functorCallYPFunctionName(object arg1, object arg2, object arg3) + { + { + foreach (bool l2 in YP.unify(arg1, Atom.a(@"="))) + { + foreach (bool l3 in YP.unify(arg2, 2)) + { + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.unify"))) { yield return true; yield break; @@ -2328,12 +2689,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"nonvar"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"=.."))) { - foreach (bool l3 in YP.unify(arg3, 1)) + foreach (bool l3 in YP.unify(arg2, 2)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.nonvar"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.univ"))) { yield return true; yield break; @@ -2342,12 +2702,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"arg"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"var"))) { - foreach (bool l3 in YP.unify(arg3, 3)) + foreach (bool l3 in YP.unify(arg2, 1)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.arg"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.var"))) { yield return true; yield break; @@ -2356,12 +2715,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"functor"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"nonvar"))) { - foreach (bool l3 in YP.unify(arg3, 3)) + foreach (bool l3 in YP.unify(arg2, 1)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.functor"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.nonvar"))) { yield return true; yield break; @@ -2370,12 +2728,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"repeat"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"arg"))) { - foreach (bool l3 in YP.unify(arg3, 0)) + foreach (bool l3 in YP.unify(arg2, 3)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.repeat"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.arg"))) { yield return true; yield break; @@ -2384,12 +2741,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"get_code"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"functor"))) { - foreach (bool l3 in YP.unify(arg3, 1)) + foreach (bool l3 in YP.unify(arg2, 3)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.get_code"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.functor"))) { yield return true; yield break; @@ -2398,12 +2754,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"current_op"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"repeat"))) { - foreach (bool l3 in YP.unify(arg3, 3)) + foreach (bool l3 in YP.unify(arg2, 0)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.current_op"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.repeat"))) { yield return true; yield break; @@ -2412,12 +2767,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"atom_length"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"get_code"))) { - foreach (bool l3 in YP.unify(arg3, 2)) + foreach (bool l3 in YP.unify(arg2, 1)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.atom_length"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.get_code"))) { yield return true; yield break; @@ -2426,12 +2780,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"atom_concat"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"current_op"))) { - foreach (bool l3 in YP.unify(arg3, 3)) + foreach (bool l3 in YP.unify(arg2, 3)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.atom_concat"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.current_op"))) { yield return true; yield break; @@ -2440,12 +2793,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"sub_atom"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"atom_length"))) { - foreach (bool l3 in YP.unify(arg3, 5)) + foreach (bool l3 in YP.unify(arg2, 2)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.sub_atom"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.atom_length"))) { yield return true; yield break; @@ -2454,12 +2806,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"atom_codes"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"atom_concat"))) { - foreach (bool l3 in YP.unify(arg3, 2)) + foreach (bool l3 in YP.unify(arg2, 3)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.atom_codes"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.atom_concat"))) { yield return true; yield break; @@ -2468,12 +2819,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"number_codes"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"sub_atom"))) { - foreach (bool l3 in YP.unify(arg3, 2)) + foreach (bool l3 in YP.unify(arg2, 5)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.number_codes"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.sub_atom"))) { yield return true; yield break; @@ -2482,12 +2832,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"copy_term"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"atom_codes"))) { - foreach (bool l3 in YP.unify(arg3, 2)) + foreach (bool l3 in YP.unify(arg2, 2)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.copy_term"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.atom_codes"))) { yield return true; yield break; @@ -2496,12 +2845,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"sort"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"number_codes"))) { - foreach (bool l3 in YP.unify(arg3, 2)) + foreach (bool l3 in YP.unify(arg2, 2)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.sort"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.number_codes"))) { yield return true; yield break; @@ -2510,12 +2858,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"script_event"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"copy_term"))) { - foreach (bool l3 in YP.unify(arg3, 2)) + foreach (bool l3 in YP.unify(arg2, 2)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.script_event"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.copy_term"))) { yield return true; yield break; @@ -2524,12 +2871,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"nl"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"sort"))) { - foreach (bool l3 in YP.unify(arg3, 0)) + foreach (bool l3 in YP.unify(arg2, 2)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.nl"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.sort"))) { yield return true; yield break; @@ -2538,12 +2884,14 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"write"))) + // Manually included : script_event for callback to LSL/C# + + //object x1 = arg1; + foreach (bool l2 in YP.unify(arg1, Atom.a(@"script_event"))) { - foreach (bool l3 in YP.unify(arg3, 1)) + foreach (bool l3 in YP.unify(arg2, 2)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.write"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.script_event"))) { yield return true; yield break; @@ -2552,12 +2900,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"put_code"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"nl"))) { - foreach (bool l3 in YP.unify(arg3, 1)) + foreach (bool l3 in YP.unify(arg2, 0)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.put_code"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.nl"))) { yield return true; yield break; @@ -2566,12 +2913,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"atom"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"write"))) { - foreach (bool l3 in YP.unify(arg3, 1)) + foreach (bool l3 in YP.unify(arg2, 1)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.atom"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.write"))) { yield return true; yield break; @@ -2580,12 +2926,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"number"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"put_code"))) { - foreach (bool l3 in YP.unify(arg3, 1)) + foreach (bool l3 in YP.unify(arg2, 1)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.number"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.put_code"))) { yield return true; yield break; @@ -2594,13 +2939,25 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"=="))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"atom"))) { - foreach (bool l3 in YP.unify(arg3, 2)) + foreach (bool l3 in YP.unify(arg2, 1)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.termEqual"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.atom"))) + { + yield return true; + yield break; + } + } + } + } + { + foreach (bool l2 in YP.unify(arg1, Atom.a(@"integer"))) { + foreach (bool l3 in YP.unify(arg2, 1)) + { + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.integer"))) + { yield return true; yield break; } @@ -2608,12 +2965,24 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"\=="))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"float"))) { - foreach (bool l3 in YP.unify(arg3, 2)) + foreach (bool l3 in YP.unify(arg2, 1)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.termNotEqual"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.isFloat"))) + { + yield return true; + yield break; + } + } + } + } + { + foreach (bool l2 in YP.unify(arg1, Atom.a(@"number"))) + { + foreach (bool l3 in YP.unify(arg2, 1)) + { + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.number"))) { yield return true; yield break; @@ -2622,12 +2991,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"@<"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"atomic"))) { - foreach (bool l3 in YP.unify(arg3, 2)) + foreach (bool l3 in YP.unify(arg2, 1)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.termLessThan"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.atomic"))) { yield return true; yield break; @@ -2636,12 +3004,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"@=<"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"compound"))) { - foreach (bool l3 in YP.unify(arg3, 2)) + foreach (bool l3 in YP.unify(arg2, 1)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.termLessThanOrEqual"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.compound"))) { yield return true; yield break; @@ -2650,12 +3017,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"@>"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"=="))) { - foreach (bool l3 in YP.unify(arg3, 2)) + foreach (bool l3 in YP.unify(arg2, 2)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.termGreaterThan"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.termEqual"))) { yield return true; yield break; @@ -2664,12 +3030,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"@>="))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"\=="))) { - foreach (bool l3 in YP.unify(arg3, 2)) + foreach (bool l3 in YP.unify(arg2, 2)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.termGreaterThanOrEqual"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.termNotEqual"))) { yield return true; yield break; @@ -2678,12 +3043,11 @@ namespace Temporary { } } { - object x1 = arg1; - foreach (bool l2 in YP.unify(arg2, Atom.a(@"throw"))) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"@<"))) { - foreach (bool l3 in YP.unify(arg3, 1)) + foreach (bool l3 in YP.unify(arg2, 2)) { - foreach (bool l4 in YP.unify(arg4, Atom.a(@"YP.throwException"))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.termLessThan"))) { yield return true; yield break; @@ -2692,14 +3056,11 @@ namespace Temporary { } } { - object State = arg1; - object Arity = arg3; - Variable Name = new Variable(); - foreach (bool l2 in YP.unify(arg2, Name)) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"@=<"))) { - foreach (bool l3 in YP.unify(arg4, Name)) + foreach (bool l3 in YP.unify(arg2, 2)) { - if (CompilerState.nameArityHasModule(State, Name, Arity, Atom.a(@""))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.termLessThanOrEqual"))) { yield return true; yield break; @@ -2708,14 +3069,11 @@ namespace Temporary { } } { - object _State = arg1; - object _Arity = arg3; - Variable Name = new Variable(); - foreach (bool l2 in YP.unify(arg2, Name)) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"@>"))) { - foreach (bool l3 in YP.unify(arg4, Name)) + foreach (bool l3 in YP.unify(arg2, 2)) { - foreach (bool l4 in Atom.module(Name, Atom.a(@""))) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.termGreaterThan"))) { yield return true; yield break; @@ -2724,31 +3082,25 @@ namespace Temporary { } } { - object _State = arg1; - object Name = arg2; - object Arity = arg3; - object x4 = arg4; - foreach (bool l2 in Atom.module(Name, Atom.NIL)) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"@>="))) + { + foreach (bool l3 in YP.unify(arg2, 2)) + { + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.termGreaterThanOrEqual"))) { - YP.throwException(new Functor2(@"error", new Functor2(@"type_error", Atom.a(@"callable"), new Functor2(@"/", Name, Arity)), Atom.a(@"Calls to dynamic predicates not supported"))); yield return true; yield break; } } + } + } { - object _State = arg1; - object Name = arg2; - object Arity = arg3; - object x4 = arg4; - Variable Module = new Variable(); - Variable Message = new Variable(); - foreach (bool l2 in Atom.module(Name, Module)) + foreach (bool l2 in YP.unify(arg1, Atom.a(@"throw"))) { - foreach (bool l3 in Atom.module(Name, Atom.NIL)) + foreach (bool l3 in YP.unify(arg2, 1)) { - foreach (bool l4 in YP.atom_concat(Atom.a(@"Not supporting calls to external module: "), Module, Message)) + foreach (bool l4 in YP.unify(arg3, Atom.a(@"YP.throwException"))) { - YP.throwException(new Functor2(@"error", new Functor2(@"type_error", Atom.a(@"callable"), new Functor2(@"/", Name, Arity)), Message)); yield return true; yield break; } @@ -3052,6 +3404,8 @@ namespace Temporary { Variable x9 = new Variable(); Variable X2 = new Variable(); Variable Arg2 = new Variable(); + Variable x12 = new Variable(); + Variable Arity = new Variable(); if (YP.nonvar(Term)) { foreach (bool l3 in YP.univ(Term, new ListPair(Name, TermArgs))) @@ -3100,8 +3454,11 @@ namespace Temporary { goto cutIf3; } } - YP.throwException(new Functor2(@"error", new Functor2(@"type_error", Atom.a(@"evaluable"), Name), Atom.a(@"Not an expression function"))); + foreach (bool l5 in YP.functor(Term, x12, Arity)) + { + YP.throwException(new Functor2(@"error", new Functor2(@"type_error", Atom.a(@"evaluable"), new Functor2(@"/", Name, Arity)), Atom.a(@"Not an expression function"))); yield return false; + } cutIf3: cutIf2: cutIf1: @@ -3402,9 +3759,9 @@ namespace Temporary { { foreach (bool l2 in YP.unify(arg1, Atom.a(@"getDeclaringClass"))) { - YP.write(Atom.a(@"class YPInnerClass {}")); + YP.write(Atom.a(@"public class YPInnerClass {}")); YP.nl(); - YP.write(Atom.a(@"static System.Type getDeclaringClass() { return typeof(YPInnerClass).DeclaringType; }")); + YP.write(Atom.a(@"public static System.Type getDeclaringClass() { return typeof(YPInnerClass).DeclaringType; }")); YP.nl(); YP.nl(); return; @@ -3707,6 +4064,20 @@ namespace Temporary { } } } + { + Variable Expression = new Variable(); + Variable RestStatements = new Variable(); + foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1(@"throw", Expression), RestStatements))) + { + convertIndentationCSharp(Level); + YP.write(Atom.a(@"throw ")); + convertExpressionCSharp(Expression); + YP.write(Atom.a(@";")); + YP.nl(); + convertStatementListCSharp(RestStatements, Level); + return; + } + } } public static void convertIndentationCSharp(object Level) @@ -4204,6 +4575,21 @@ namespace Temporary { } } } + { + object Level = arg2; + Variable Expression = new Variable(); + Variable RestStatements = new Variable(); + foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1(@"throw", Expression), RestStatements))) + { + convertIndentationJavascript(Level); + YP.write(Atom.a(@"throw ")); + convertExpressionJavascript(Expression); + YP.write(Atom.a(@";")); + YP.nl(); + convertStatementListJavascript(RestStatements, Level); + return; + } + } } public static void convertIndentationJavascript(object Level) @@ -4983,6 +5369,24 @@ namespace Temporary { } } } + { + object Level = arg2; + object HasBreakableBlock = arg3; + Variable Expression = new Variable(); + Variable RestStatements = new Variable(); + foreach (bool l2 in YP.unify(arg1, new ListPair(new Functor1(@"throw", Expression), RestStatements))) + { + convertIndentationPython(Level); + YP.write(Atom.a(@"raise ")); + convertExpressionPython(Expression); + YP.nl(); + foreach (bool l3 in convertStatementListPython(RestStatements, Level, HasBreakableBlock)) + { + yield return true; + yield break; + } + } + } } public static void convertIndentationPython(object Level) -- cgit v1.1