diff options
author | Charles Krinke | 2008-08-13 14:13:49 +0000 |
---|---|---|
committer | Charles Krinke | 2008-08-13 14:13:49 +0000 |
commit | 323ada012d3bed0c6f7a6d5d0ee14b409b7457c7 (patch) | |
tree | d5a2e30707baba7804aefb341774d6d51ca7b439 /OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YPCompiler.cs | |
parent | Thank you, tyre, for a patch that fixes a null reference in LSL (diff) | |
download | opensim-SC-323ada012d3bed0c6f7a6d5d0ee14b409b7457c7.zip opensim-SC-323ada012d3bed0c6f7a6d5d0ee14b409b7457c7.tar.gz opensim-SC-323ada012d3bed0c6f7a6d5d0ee14b409b7457c7.tar.bz2 opensim-SC-323ada012d3bed0c6f7a6d5d0ee14b409b7457c7.tar.xz |
Mantis#1931. Thank you kindly, Kinoc for a patch that:
* Yield Prolog 1.0.1 Released : it passes all but 9 of the
421 tests in the ISO Prolog test suite (97.8%) .
* support dynamic predicates and rules.
* support 'import' to use external static functions
improves connection to C# functions
* Matches Yield Prolog r831
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YPCompiler.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YPCompiler.cs | 326 |
1 files changed, 286 insertions, 40 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YPCompiler.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YPCompiler.cs index 1f1b41d..de7f168 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YPCompiler.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/YieldProlog/YPCompiler.cs | |||
@@ -203,7 +203,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | |||
203 | 203 | ||
204 | // disable warning on l1, don't see how we can | 204 | // disable warning on l1, don't see how we can |
205 | // code this differently | 205 | // code this differently |
206 | #pragma warning disable 0168, 0164, 0162 | 206 | #pragma warning disable 0168,0164,0162 |
207 | public static bool isDetNoneOut(object State, object Term) | 207 | public static bool isDetNoneOut(object State, object Term) |
208 | { | 208 | { |
209 | State = YP.getValue(State); | 209 | State = YP.getValue(State); |
@@ -241,7 +241,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | |||
241 | 241 | ||
242 | return false; | 242 | return false; |
243 | } | 243 | } |
244 | #pragma warning restore 0168, 0164, 0162 | 244 | #pragma warning restore 0168,0164,0162 |
245 | 245 | ||
246 | /// <summary> | 246 | /// <summary> |
247 | /// Return false if any of args is out, otherwise true. | 247 | /// Return false if any of args is out, otherwise true. |
@@ -280,7 +280,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.YieldProlog | |||
280 | 280 | ||
281 | // disable warning on l1, don't see how we can | 281 | // disable warning on l1, don't see how we can |
282 | // code this differently | 282 | // code this differently |
283 | #pragma warning disable 0168, 0219, 0164, 0162 | 283 | #pragma warning disable 0168, 0219,0164,0162 |
284 | 284 | ||
285 | /// <summary> | 285 | /// <summary> |
286 | /// Use makeFunctionPseudoCode, convertFunctionCSharp and compileAnonymousFunction | 286 | /// Use makeFunctionPseudoCode, convertFunctionCSharp and compileAnonymousFunction |
@@ -405,8 +405,8 @@ namespace Temporary { | |||
405 | /// <summary> | 405 | /// <summary> |
406 | /// If the functor with name and args can be called directly as determined by | 406 | /// If the functor with name and args can be called directly as determined by |
407 | /// functorCallFunctionName, then call it and return its iterator. If the predicate is | 407 | /// functorCallFunctionName, then call it and return its iterator. If the predicate is |
408 | /// dynamic and undefined, or if static and the method cannot be found, throw | 408 | /// dynamic and undefined, or if static and the method cannot be found, return |
409 | /// a PrologException for existence_error. | 409 | /// the result of YP.unknownPredicate. |
410 | /// This returns null if the functor has a special form than needs to be compiled | 410 | /// This returns null if the functor has a special form than needs to be compiled |
411 | /// (including ,/2 and ;/2). | 411 | /// (including ,/2 and ;/2). |
412 | /// </summary> | 412 | /// </summary> |
@@ -424,13 +424,11 @@ namespace Temporary { | |||
424 | { | 424 | { |
425 | Atom functionNameAtom = ((Atom)FunctionName.getValue()); | 425 | Atom functionNameAtom = ((Atom)FunctionName.getValue()); |
426 | if (functionNameAtom == Atom.NIL) | 426 | if (functionNameAtom == Atom.NIL) |
427 | { | ||
428 | // name is for a dynamic predicate. | 427 | // name is for a dynamic predicate. |
429 | return YP.matchDynamic(name, args); | 428 | return YP.matchDynamic(name, args); |
430 | } | ||
431 | 429 | ||
432 | // Set the default for the method to call. | ||
433 | string methodName = functionNameAtom._name; | 430 | string methodName = functionNameAtom._name; |
431 | // Set the default for the method to call. | ||
434 | Type methodClass = declaringClass; | 432 | Type methodClass = declaringClass; |
435 | 433 | ||
436 | bool checkMode = false; | 434 | bool checkMode = false; |
@@ -448,10 +446,8 @@ namespace Temporary { | |||
448 | return null; | 446 | return null; |
449 | 447 | ||
450 | if (methodClass == null) | 448 | if (methodClass == null) |
451 | throw new PrologException | 449 | return YP.unknownPredicate |
452 | (new Functor2 | 450 | (name, args.Length, |
453 | (Atom.a("existence_error"), Atom.a("procedure"), | ||
454 | new Functor2(Atom.a("/"), name, args.Length)), | ||
455 | "Cannot find predicate function for: " + name + "/" + args.Length + | 451 | "Cannot find predicate function for: " + name + "/" + args.Length + |
456 | " because declaringClass is null. Set declaringClass to the class containing " + | 452 | " because declaringClass is null. Set declaringClass to the class containing " + |
457 | methodName); | 453 | methodName); |
@@ -486,10 +482,8 @@ namespace Temporary { | |||
486 | } | 482 | } |
487 | catch (MissingMethodException) | 483 | catch (MissingMethodException) |
488 | { | 484 | { |
489 | throw new PrologException | 485 | return YP.unknownPredicate |
490 | (new Functor2 | 486 | (name, args.Length, |
491 | (Atom.a("existence_error"), Atom.a("procedure"), | ||
492 | new Functor2(Atom.a("/"), name, args.Length)), | ||
493 | "Cannot find predicate function " + methodName + " for " + name + "/" + args.Length + | 487 | "Cannot find predicate function " + methodName + " for " + name + "/" + args.Length + |
494 | " in " + methodClass.FullName); | 488 | " in " + methodClass.FullName); |
495 | } | 489 | } |
@@ -498,6 +492,54 @@ namespace Temporary { | |||
498 | return null; | 492 | return null; |
499 | } | 493 | } |
500 | 494 | ||
495 | /// <summary> | ||
496 | /// Return true if there is a dynamic or static predicate with name and arity. | ||
497 | /// This returns false for built-in predicates. | ||
498 | /// </summary> | ||
499 | /// <param name="name"></param> | ||
500 | /// <param name="arity"></param> | ||
501 | /// <param name="declaringClass">used to resolve references to the default | ||
502 | /// module Atom.a(""). If a declaringClass is needed to resolve the reference but it is | ||
503 | /// null, return false</param> | ||
504 | /// <returns></returns> | ||
505 | public static bool isCurrentPredicate(Atom name, int arity, Type declaringClass) | ||
506 | { | ||
507 | CompilerState state = new CompilerState(); | ||
508 | Variable FunctionName = new Variable(); | ||
509 | foreach (bool l1 in functorCallFunctionName(state, name, arity, FunctionName)) | ||
510 | { | ||
511 | Atom functionNameAtom = ((Atom)FunctionName.getValue()); | ||
512 | if (functionNameAtom == Atom.NIL) | ||
513 | // name is for a dynamic predicate. | ||
514 | return YP.isDynamicCurrentPredicate(name, arity); | ||
515 | |||
516 | string methodName = functionNameAtom._name; | ||
517 | |||
518 | if (methodName.StartsWith("YP.")) | ||
519 | // current_predicate/1 should fail for built-ins. | ||
520 | return false; | ||
521 | if (methodName.Contains(".")) | ||
522 | // We don't support calling inner classes, etc. | ||
523 | return false; | ||
524 | if (declaringClass == null) | ||
525 | return false; | ||
526 | |||
527 | foreach (MemberInfo member in declaringClass.GetMember(methodName)) | ||
528 | { | ||
529 | MethodInfo method = member as MethodInfo; | ||
530 | if (method == null) | ||
531 | continue; | ||
532 | if ((method.Attributes | MethodAttributes.Static) == 0) | ||
533 | // Not a static method. | ||
534 | continue; | ||
535 | if (method.GetParameters().Length == arity) | ||
536 | return true; | ||
537 | } | ||
538 | } | ||
539 | |||
540 | return false; | ||
541 | } | ||
542 | |||
501 | // Compiler output follows. | 543 | // Compiler output follows. |
502 | 544 | ||
503 | public class YPInnerClass { } | 545 | public class YPInnerClass { } |
@@ -567,9 +609,14 @@ namespace Temporary { | |||
567 | CompilerState.assertPred(State, Atom.a("nl"), Atom.a("det")); | 609 | CompilerState.assertPred(State, Atom.a("nl"), Atom.a("det")); |
568 | CompilerState.assertPred(State, new Functor1("write", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | 610 | CompilerState.assertPred(State, new Functor1("write", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); |
569 | CompilerState.assertPred(State, new Functor1("put_code", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | 611 | CompilerState.assertPred(State, new Functor1("put_code", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); |
612 | CompilerState.assertPred(State, new Functor1("see", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
613 | CompilerState.assertPred(State, Atom.a("seen"), Atom.a("det")); | ||
614 | CompilerState.assertPred(State, new Functor1("tell", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
615 | CompilerState.assertPred(State, Atom.a("told"), Atom.a("det")); | ||
570 | CompilerState.assertPred(State, new Functor1("throw", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | 616 | CompilerState.assertPred(State, new Functor1("throw", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); |
571 | CompilerState.assertPred(State, new Functor1("abolish", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | 617 | CompilerState.assertPred(State, new Functor1("abolish", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); |
572 | CompilerState.assertPred(State, new Functor1("retractall", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | 618 | CompilerState.assertPred(State, new Functor1("retractall", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); |
619 | CompilerState.assertPred(State, new Functor2("set_prolog_flag", new Functor2("::", Atom.a("univ"), Atom.a("in")), new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("det")); | ||
573 | CompilerState.assertPred(State, new Functor1("var", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | 620 | CompilerState.assertPred(State, new Functor1("var", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); |
574 | CompilerState.assertPred(State, new Functor1("nonvar", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | 621 | CompilerState.assertPred(State, new Functor1("nonvar", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); |
575 | CompilerState.assertPred(State, new Functor1("atom", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); | 622 | CompilerState.assertPred(State, new Functor1("atom", new Functor2("::", Atom.a("univ"), Atom.a("in"))), Atom.a("semidet")); |
@@ -2121,7 +2168,7 @@ namespace Temporary { | |||
2121 | { | 2168 | { |
2122 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("if", new Functor2("call", FunctionName, new ListPair(X1Code, new ListPair(X2Code, Atom.NIL))), BCode), Atom.NIL))) | 2169 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("if", new Functor2("call", FunctionName, new ListPair(X1Code, new ListPair(X2Code, Atom.NIL))), BCode), Atom.NIL))) |
2123 | { | 2170 | { |
2124 | foreach (bool l4 in YP.univ(A, new ListPair(Name, new ListPair(X1, new ListPair(X2, Atom.NIL))))) | 2171 | foreach (bool l4 in YP.univ(A, ListPair.make(new object[] { Name, X1, X2 }))) |
2125 | { | 2172 | { |
2126 | foreach (bool l5 in binaryExpressionConditional(Name, FunctionName)) | 2173 | foreach (bool l5 in binaryExpressionConditional(Name, FunctionName)) |
2127 | { | 2174 | { |
@@ -2236,6 +2283,27 @@ namespace Temporary { | |||
2236 | Variable B = new Variable(); | 2283 | Variable B = new Variable(); |
2237 | Variable ATermCode = new Variable(); | 2284 | Variable ATermCode = new Variable(); |
2238 | Variable BCode = new Variable(); | 2285 | Variable BCode = new Variable(); |
2286 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("current_predicate", A), B))) | ||
2287 | { | ||
2288 | foreach (bool l3 in YP.unify(arg3, new ListPair(new Functor2("foreach", new Functor2("call", Atom.a("YP.current_predicate"), new ListPair(ATermCode, new ListPair(new Functor2("call", Atom.a("getDeclaringClass"), Atom.NIL), Atom.NIL))), BCode), Atom.NIL))) | ||
2289 | { | ||
2290 | foreach (bool l4 in compileTerm(A, State, ATermCode)) | ||
2291 | { | ||
2292 | foreach (bool l5 in compileRuleBody(B, State, BCode)) | ||
2293 | { | ||
2294 | yield return true; | ||
2295 | yield break; | ||
2296 | } | ||
2297 | } | ||
2298 | } | ||
2299 | } | ||
2300 | } | ||
2301 | { | ||
2302 | object State = arg2; | ||
2303 | Variable A = new Variable(); | ||
2304 | Variable B = new Variable(); | ||
2305 | Variable ATermCode = new Variable(); | ||
2306 | Variable BCode = new Variable(); | ||
2239 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("asserta", A), B))) | 2307 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor1("asserta", A), B))) |
2240 | { | 2308 | { |
2241 | 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))) | 2309 | 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))) |
@@ -2299,7 +2367,7 @@ namespace Temporary { | |||
2299 | Variable HandlerAndBCode = new Variable(); | 2367 | Variable HandlerAndBCode = new Variable(); |
2300 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor3("catch", Goal, Catcher, Handler), B))) | 2368 | foreach (bool l2 in YP.unify(arg1, new Functor2(",", new Functor3("catch", Goal, Catcher, Handler), B))) |
2301 | { | 2369 | { |
2302 | 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))))) | 2370 | foreach (bool l3 in YP.unify(arg3, ListPair.make(new object[] { new Functor3("declare", Atom.a("YP.Catch"), CatchGoal, new Functor2("new", Atom.a("YP.Catch"), new ListPair(GoalTermCode, new ListPair(new Functor2("call", Atom.a("getDeclaringClass"), Atom.NIL), Atom.NIL)))), new Functor2("foreach", new Functor1("var", CatchGoal), BCode), new Functor2("foreach", new Functor3("callMember", new Functor1("var", CatchGoal), Atom.a("unifyExceptionOrThrow"), new ListPair(CatcherTermCode, Atom.NIL)), HandlerAndBCode) }))) |
2303 | { | 2371 | { |
2304 | foreach (bool l4 in CompilerState.gensym(State, Atom.a("catchGoal"), CatchGoal)) | 2372 | foreach (bool l4 in CompilerState.gensym(State, Atom.a("catchGoal"), CatchGoal)) |
2305 | { | 2373 | { |
@@ -2833,6 +2901,10 @@ namespace Temporary { | |||
2833 | { | 2901 | { |
2834 | return true; | 2902 | return true; |
2835 | } | 2903 | } |
2904 | if (YP.termEqual(Name, Atom.a("current_predicate"))) | ||
2905 | { | ||
2906 | return true; | ||
2907 | } | ||
2836 | if (YP.termEqual(Name, Atom.a("asserta"))) | 2908 | if (YP.termEqual(Name, Atom.a("asserta"))) |
2837 | { | 2909 | { |
2838 | return true; | 2910 | return true; |
@@ -3016,19 +3088,6 @@ namespace Temporary { | |||
3016 | } | 3088 | } |
3017 | } | 3089 | } |
3018 | { | 3090 | { |
3019 | foreach (bool l2 in YP.unify(arg1, Atom.a("current_predicate"))) | ||
3020 | { | ||
3021 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3022 | { | ||
3023 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.current_predicate"))) | ||
3024 | { | ||
3025 | yield return true; | ||
3026 | yield break; | ||
3027 | } | ||
3028 | } | ||
3029 | } | ||
3030 | } | ||
3031 | { | ||
3032 | foreach (bool l2 in YP.unify(arg1, Atom.a("atom_length"))) | 3091 | foreach (bool l2 in YP.unify(arg1, Atom.a("atom_length"))) |
3033 | { | 3092 | { |
3034 | foreach (bool l3 in YP.unify(arg2, 2)) | 3093 | foreach (bool l3 in YP.unify(arg2, 2)) |
@@ -3214,6 +3273,58 @@ namespace Temporary { | |||
3214 | } | 3273 | } |
3215 | } | 3274 | } |
3216 | { | 3275 | { |
3276 | foreach (bool l2 in YP.unify(arg1, Atom.a("see"))) | ||
3277 | { | ||
3278 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3279 | { | ||
3280 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.see"))) | ||
3281 | { | ||
3282 | yield return true; | ||
3283 | yield break; | ||
3284 | } | ||
3285 | } | ||
3286 | } | ||
3287 | } | ||
3288 | { | ||
3289 | foreach (bool l2 in YP.unify(arg1, Atom.a("seen"))) | ||
3290 | { | ||
3291 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
3292 | { | ||
3293 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.seen"))) | ||
3294 | { | ||
3295 | yield return true; | ||
3296 | yield break; | ||
3297 | } | ||
3298 | } | ||
3299 | } | ||
3300 | } | ||
3301 | { | ||
3302 | foreach (bool l2 in YP.unify(arg1, Atom.a("tell"))) | ||
3303 | { | ||
3304 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3305 | { | ||
3306 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.tell"))) | ||
3307 | { | ||
3308 | yield return true; | ||
3309 | yield break; | ||
3310 | } | ||
3311 | } | ||
3312 | } | ||
3313 | } | ||
3314 | { | ||
3315 | foreach (bool l2 in YP.unify(arg1, Atom.a("told"))) | ||
3316 | { | ||
3317 | foreach (bool l3 in YP.unify(arg2, 0)) | ||
3318 | { | ||
3319 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.told"))) | ||
3320 | { | ||
3321 | yield return true; | ||
3322 | yield break; | ||
3323 | } | ||
3324 | } | ||
3325 | } | ||
3326 | } | ||
3327 | { | ||
3217 | foreach (bool l2 in YP.unify(arg1, Atom.a("clause"))) | 3328 | foreach (bool l2 in YP.unify(arg1, Atom.a("clause"))) |
3218 | { | 3329 | { |
3219 | foreach (bool l3 in YP.unify(arg2, 2)) | 3330 | foreach (bool l3 in YP.unify(arg2, 2)) |
@@ -3434,6 +3545,110 @@ namespace Temporary { | |||
3434 | } | 3545 | } |
3435 | } | 3546 | } |
3436 | } | 3547 | } |
3548 | { | ||
3549 | foreach (bool l2 in YP.unify(arg1, Atom.a("current_prolog_flag"))) | ||
3550 | { | ||
3551 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3552 | { | ||
3553 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.current_prolog_flag"))) | ||
3554 | { | ||
3555 | yield return true; | ||
3556 | yield break; | ||
3557 | } | ||
3558 | } | ||
3559 | } | ||
3560 | } | ||
3561 | { | ||
3562 | foreach (bool l2 in YP.unify(arg1, Atom.a("set_prolog_flag"))) | ||
3563 | { | ||
3564 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3565 | { | ||
3566 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.set_prolog_flag"))) | ||
3567 | { | ||
3568 | yield return true; | ||
3569 | yield break; | ||
3570 | } | ||
3571 | } | ||
3572 | } | ||
3573 | } | ||
3574 | { | ||
3575 | foreach (bool l2 in YP.unify(arg1, Atom.a("current_input"))) | ||
3576 | { | ||
3577 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3578 | { | ||
3579 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.current_input"))) | ||
3580 | { | ||
3581 | yield return true; | ||
3582 | yield break; | ||
3583 | } | ||
3584 | } | ||
3585 | } | ||
3586 | } | ||
3587 | { | ||
3588 | foreach (bool l2 in YP.unify(arg1, Atom.a("current_output"))) | ||
3589 | { | ||
3590 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3591 | { | ||
3592 | foreach (bool l4 in YP.unify(arg3, Atom.a("YP.current_output"))) | ||
3593 | { | ||
3594 | yield return true; | ||
3595 | yield break; | ||
3596 | } | ||
3597 | } | ||
3598 | } | ||
3599 | } | ||
3600 | { | ||
3601 | foreach (bool l2 in YP.unify(arg1, Atom.a("read_term"))) | ||
3602 | { | ||
3603 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3604 | { | ||
3605 | foreach (bool l4 in YP.unify(arg3, Atom.a("Parser.read_term2"))) | ||
3606 | { | ||
3607 | yield return true; | ||
3608 | yield break; | ||
3609 | } | ||
3610 | } | ||
3611 | } | ||
3612 | } | ||
3613 | { | ||
3614 | foreach (bool l2 in YP.unify(arg1, Atom.a("read_term"))) | ||
3615 | { | ||
3616 | foreach (bool l3 in YP.unify(arg2, 3)) | ||
3617 | { | ||
3618 | foreach (bool l4 in YP.unify(arg3, Atom.a("Parser.read_term3"))) | ||
3619 | { | ||
3620 | yield return true; | ||
3621 | yield break; | ||
3622 | } | ||
3623 | } | ||
3624 | } | ||
3625 | } | ||
3626 | { | ||
3627 | foreach (bool l2 in YP.unify(arg1, Atom.a("read"))) | ||
3628 | { | ||
3629 | foreach (bool l3 in YP.unify(arg2, 1)) | ||
3630 | { | ||
3631 | foreach (bool l4 in YP.unify(arg3, Atom.a("Parser.read1"))) | ||
3632 | { | ||
3633 | yield return true; | ||
3634 | yield break; | ||
3635 | } | ||
3636 | } | ||
3637 | } | ||
3638 | } | ||
3639 | { | ||
3640 | foreach (bool l2 in YP.unify(arg1, Atom.a("read"))) | ||
3641 | { | ||
3642 | foreach (bool l3 in YP.unify(arg2, 2)) | ||
3643 | { | ||
3644 | foreach (bool l4 in YP.unify(arg3, Atom.a("Parser.read2"))) | ||
3645 | { | ||
3646 | yield return true; | ||
3647 | yield break; | ||
3648 | } | ||
3649 | } | ||
3650 | } | ||
3651 | } | ||
3437 | } | 3652 | } |
3438 | 3653 | ||
3439 | public static IEnumerable<bool> compileTerm(object arg1, object arg2, object arg3) | 3654 | public static IEnumerable<bool> compileTerm(object arg1, object arg2, object arg3) |
@@ -3494,6 +3709,34 @@ namespace Temporary { | |||
3494 | object State = arg2; | 3709 | object State = arg2; |
3495 | Variable First = new Variable(); | 3710 | Variable First = new Variable(); |
3496 | Variable Rest = new Variable(); | 3711 | Variable Rest = new Variable(); |
3712 | Variable CompiledList = new Variable(); | ||
3713 | Variable x5 = new Variable(); | ||
3714 | Variable Rest2 = new Variable(); | ||
3715 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | ||
3716 | { | ||
3717 | foreach (bool l3 in YP.unify(arg3, new Functor2("call", Atom.a("ListPair.make"), new ListPair(new Functor1("objectArray", CompiledList), Atom.NIL)))) | ||
3718 | { | ||
3719 | if (YP.nonvar(Rest)) | ||
3720 | { | ||
3721 | foreach (bool l5 in YP.unify(Rest, new ListPair(x5, Rest2))) | ||
3722 | { | ||
3723 | if (YP.termNotEqual(Rest2, Atom.NIL)) | ||
3724 | { | ||
3725 | foreach (bool l7 in maplist_compileTerm(new ListPair(First, Rest), State, CompiledList)) | ||
3726 | { | ||
3727 | yield return true; | ||
3728 | yield break; | ||
3729 | } | ||
3730 | } | ||
3731 | } | ||
3732 | } | ||
3733 | } | ||
3734 | } | ||
3735 | } | ||
3736 | { | ||
3737 | object State = arg2; | ||
3738 | Variable First = new Variable(); | ||
3739 | Variable Rest = new Variable(); | ||
3497 | Variable Arg1 = new Variable(); | 3740 | Variable Arg1 = new Variable(); |
3498 | Variable Arg2 = new Variable(); | 3741 | Variable Arg2 = new Variable(); |
3499 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) | 3742 | foreach (bool l2 in YP.unify(arg1, new ListPair(First, Rest))) |
@@ -3563,7 +3806,7 @@ namespace Temporary { | |||
3563 | { | 3806 | { |
3564 | foreach (bool l8 in compileTerm(X2, State, Arg2)) | 3807 | foreach (bool l8 in compileTerm(X2, State, Arg2)) |
3565 | { | 3808 | { |
3566 | foreach (bool l9 in YP.unify(Result, new Functor2("new", Atom.a("Functor2"), new ListPair(NameCode, new ListPair(Arg1, new ListPair(Arg2, Atom.NIL)))))) | 3809 | foreach (bool l9 in YP.unify(Result, new Functor2("new", Atom.a("Functor2"), ListPair.make(new object[] { NameCode, Arg1, Arg2 })))) |
3567 | { | 3810 | { |
3568 | yield return true; | 3811 | yield return true; |
3569 | yield break; | 3812 | yield break; |
@@ -3572,7 +3815,7 @@ namespace Temporary { | |||
3572 | } | 3815 | } |
3573 | goto cutIf5; | 3816 | goto cutIf5; |
3574 | } | 3817 | } |
3575 | foreach (bool l6 in YP.unify(TermArgs, new ListPair(X1, new ListPair(X2, new ListPair(X3, Atom.NIL))))) | 3818 | foreach (bool l6 in YP.unify(TermArgs, ListPair.make(new object[] { X1, X2, X3 }))) |
3576 | { | 3819 | { |
3577 | foreach (bool l7 in compileTerm(X1, State, Arg1)) | 3820 | foreach (bool l7 in compileTerm(X1, State, Arg1)) |
3578 | { | 3821 | { |
@@ -3580,7 +3823,7 @@ namespace Temporary { | |||
3580 | { | 3823 | { |
3581 | foreach (bool l9 in compileTerm(X3, State, Arg3)) | 3824 | foreach (bool l9 in compileTerm(X3, State, Arg3)) |
3582 | { | 3825 | { |
3583 | foreach (bool l10 in YP.unify(Result, new Functor2("new", Atom.a("Functor3"), new ListPair(NameCode, new ListPair(Arg1, new ListPair(Arg2, new ListPair(Arg3, Atom.NIL))))))) | 3826 | foreach (bool l10 in YP.unify(Result, new Functor2("new", Atom.a("Functor3"), ListPair.make(new object[] { NameCode, Arg1, Arg2, Arg3 })))) |
3584 | { | 3827 | { |
3585 | yield return true; | 3828 | yield return true; |
3586 | yield break; | 3829 | yield break; |
@@ -3623,7 +3866,7 @@ namespace Temporary { | |||
3623 | { | 3866 | { |
3624 | foreach (bool l7 in compileTerm(X2, State, Arg2)) | 3867 | foreach (bool l7 in compileTerm(X2, State, Arg2)) |
3625 | { | 3868 | { |
3626 | foreach (bool l8 in YP.unify(Result, new Functor2("new", Atom.a("Functor2"), new ListPair(NameCode, new ListPair(Arg1, new ListPair(Arg2, Atom.NIL)))))) | 3869 | foreach (bool l8 in YP.unify(Result, new Functor2("new", Atom.a("Functor2"), ListPair.make(new object[] { NameCode, Arg1, Arg2 })))) |
3627 | { | 3870 | { |
3628 | yield return true; | 3871 | yield return true; |
3629 | yield break; | 3872 | yield break; |
@@ -3632,7 +3875,7 @@ namespace Temporary { | |||
3632 | } | 3875 | } |
3633 | goto cutIf7; | 3876 | goto cutIf7; |
3634 | } | 3877 | } |
3635 | foreach (bool l5 in YP.unify(TermArgs, new ListPair(X1, new ListPair(X2, new ListPair(X3, Atom.NIL))))) | 3878 | foreach (bool l5 in YP.unify(TermArgs, ListPair.make(new object[] { X1, X2, X3 }))) |
3636 | { | 3879 | { |
3637 | foreach (bool l6 in compileTerm(X1, State, Arg1)) | 3880 | foreach (bool l6 in compileTerm(X1, State, Arg1)) |
3638 | { | 3881 | { |
@@ -3640,7 +3883,7 @@ namespace Temporary { | |||
3640 | { | 3883 | { |
3641 | foreach (bool l8 in compileTerm(X3, State, Arg3)) | 3884 | foreach (bool l8 in compileTerm(X3, State, Arg3)) |
3642 | { | 3885 | { |
3643 | foreach (bool l9 in YP.unify(Result, new Functor2("new", Atom.a("Functor3"), new ListPair(NameCode, new ListPair(Arg1, new ListPair(Arg2, new ListPair(Arg3, Atom.NIL))))))) | 3886 | foreach (bool l9 in YP.unify(Result, new Functor2("new", Atom.a("Functor3"), ListPair.make(new object[] { NameCode, Arg1, Arg2, Arg3 })))) |
3644 | { | 3887 | { |
3645 | yield return true; | 3888 | yield return true; |
3646 | yield break; | 3889 | yield break; |
@@ -3725,9 +3968,11 @@ namespace Temporary { | |||
3725 | { | 3968 | { |
3726 | foreach (bool l3 in YP.unify(arg3, new ListPair(FirstResult, RestResults))) | 3969 | foreach (bool l3 in YP.unify(arg3, new ListPair(FirstResult, RestResults))) |
3727 | { | 3970 | { |
3728 | foreach (bool l4 in compileTerm(First, State, FirstResult)) | 3971 | if (YP.nonvar(Rest)) |
3972 | { | ||
3973 | foreach (bool l5 in compileTerm(First, State, FirstResult)) | ||
3729 | { | 3974 | { |
3730 | foreach (bool l5 in maplist_compileTerm(Rest, State, RestResults)) | 3975 | foreach (bool l6 in maplist_compileTerm(Rest, State, RestResults)) |
3731 | { | 3976 | { |
3732 | yield return true; | 3977 | yield return true; |
3733 | yield break; | 3978 | yield break; |
@@ -3737,6 +3982,7 @@ namespace Temporary { | |||
3737 | } | 3982 | } |
3738 | } | 3983 | } |
3739 | } | 3984 | } |
3985 | } | ||
3740 | 3986 | ||
3741 | public static IEnumerable<bool> compileExpression(object Term, object State, object Result) | 3987 | public static IEnumerable<bool> compileExpression(object Term, object State, object Result) |
3742 | { | 3988 | { |
@@ -6131,6 +6377,6 @@ namespace Temporary { | |||
6131 | } | 6377 | } |
6132 | } | 6378 | } |
6133 | } | 6379 | } |
6134 | #pragma warning restore 0168, 0219, 0164, 0162 | 6380 | #pragma warning restore 0168, 0219, 0164,0162 |
6135 | } | 6381 | } |
6136 | } | 6382 | } |