Advertisement
logicmoo

Untitled

Jun 21st, 2018
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.03 KB | None | 0 0
  1. #include "pred_append_3.h"
  2. #include "Term.h"
  3. #include "UpperPrologMachine.h"
  4. #include "../../lang/src/main/java/TauPrologG/Operation.h"
  5. #include "../../lang/src/main/java/TauPrologG/Prolog.h"
  6. #include "../../lang/src/main/java/TauPrologG/StructureTerm.h"
  7. #include "../../lang/src/main/java/TauPrologG/SymbolTerm.h"
  8. #include "../../lang/src/main/java/TauPrologG/VariableTerm.h"
  9. namespace TauPrologG {
  10.  
  11.   Predicate* pred_append_3::entry_code;
  12.   Predicate* pred_append_3::cl1 = new pred_append_3_1();
  13.   Predicate* pred_append_3::cl2 = new pred_append_3_2();
  14.   std::string pred_append_3::string0 = SymbolTerm::istr("cut");
  15.   std::string pred_append_3::string1 = SymbolTerm::istr(".");
  16.   std::string pred_append_3::string2 = SymbolTerm::istr("[]");
  17.   std::string pred_append_3::string3 = SymbolTerm::istr("append");
  18.   std::string pred_append_3::string4 = SymbolTerm::istr("call");
  19.  
  20.   int pred_append_3::arity() {
  21.     return 3;
  22.   }
  23.  
  24.   Operation pred_append_3::exec(Prolog* mach) {
  25.     std::vector<Term*> aregs = { mach->Areg[0], mach->Areg[1], mach->Areg[2], mach->Areg[3]};
  26.     mach->CreateChoicePoint(aregs);
  27.     return cl1->exec(mach);
  28.   }
  29.  
  30.   void pred_append_3::init(Prolog* mach) {
  31.     entry_code = this;
  32.   }
  33.  
  34.   Operation pred_append_3_1::exec(Prolog* mach) {
  35.     mach->FillAlternative(cl2);
  36.     std::vector<Term*> local_aregs = mach->Areg;
  37.     Term* continuation = local_aregs[3];
  38.     Term* areg2 = local_aregs[2]->dereference();
  39.     Term* areg1 = local_aregs[1]->dereference();
  40.     Term* areg0 = local_aregs[0]->dereference();
  41.     Term* var1 = Machine::Var(mach);
  42.     if ( !((areg0)->LogUnify(SymbolTerm::intern(string2))) ) {
  43.       return mach->fail();
  44.     }
  45.     if ( !((areg1)->LogUnify(var1)) ) {
  46.       return mach->fail();
  47.     }
  48.     if ( !((areg2)->LogUnify(var1->dereference())) ) {
  49.       return mach->fail();
  50.     }
  51.     local_aregs[0] = continuation;
  52.     mach->CUTB = mach->CurrentChoice;
  53.     local_aregs[3] = local_aregs[2] = local_aregs[1] = nullptr;
  54.     return UpperPrologMachine::Call1;
  55.   }
  56.  
  57.   Operation pred_append_3_2::exec(Prolog* mach) {
  58.  
  59.     mach->RemoveChoice();
  60.     std::vector<Term*> local_aregs = mach->Areg;
  61.     Term* continuation = local_aregs[3];
  62.     Term* areg2 = local_aregs[2]->dereference();
  63.     Term* areg1 = local_aregs[1]->dereference();
  64.     Term* areg0 = local_aregs[0]->dereference();
  65.     Term* var4 = Machine::Var(mach);
  66.     Term* var3 = Machine::Var(mach);
  67.     Term* var2 = Machine::Var(mach);
  68.     Term* var1 = Machine::Var(mach);
  69.     if ( !((areg0)->LogUnify(StructureTerm::makeCompound(string1,{ var1, var2}))) ) {
  70.       return mach->fail();
  71.     }
  72.     if ( !((areg1)->LogUnify(var3)) ) {
  73.       return mach->fail();
  74.     }
  75.     if ( !((areg2)->LogUnify(StructureTerm::makeCompound(string1,{ var1->dereference(), var4}))) ) {
  76.       return mach->fail();
  77.     }
  78.     local_aregs[0] = var2->dereference();
  79.     local_aregs[1] = var3->dereference();
  80.     local_aregs[2] = var4->dereference();
  81.     local_aregs[3] = continuation;
  82.     mach->CUTB = mach->CurrentChoice;
  83.     return entry_code;
  84.   }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement