Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pred_append_3.h"
- #include "Term.h"
- #include "UpperPrologMachine.h"
- #include "../../lang/src/main/java/TauPrologG/Operation.h"
- #include "../../lang/src/main/java/TauPrologG/Prolog.h"
- #include "../../lang/src/main/java/TauPrologG/StructureTerm.h"
- #include "../../lang/src/main/java/TauPrologG/SymbolTerm.h"
- #include "../../lang/src/main/java/TauPrologG/VariableTerm.h"
- namespace TauPrologG {
- Predicate* pred_append_3::entry_code;
- Predicate* pred_append_3::cl1 = new pred_append_3_1();
- Predicate* pred_append_3::cl2 = new pred_append_3_2();
- std::string pred_append_3::string0 = SymbolTerm::istr("cut");
- std::string pred_append_3::string1 = SymbolTerm::istr(".");
- std::string pred_append_3::string2 = SymbolTerm::istr("[]");
- std::string pred_append_3::string3 = SymbolTerm::istr("append");
- std::string pred_append_3::string4 = SymbolTerm::istr("call");
- int pred_append_3::arity() {
- return 3;
- }
- Operation pred_append_3::exec(Prolog* mach) {
- std::vector<Term*> aregs = { mach->Areg[0], mach->Areg[1], mach->Areg[2], mach->Areg[3]};
- mach->CreateChoicePoint(aregs);
- return cl1->exec(mach);
- }
- void pred_append_3::init(Prolog* mach) {
- entry_code = this;
- }
- Operation pred_append_3_1::exec(Prolog* mach) {
- mach->FillAlternative(cl2);
- std::vector<Term*> local_aregs = mach->Areg;
- Term* continuation = local_aregs[3];
- Term* areg2 = local_aregs[2]->dereference();
- Term* areg1 = local_aregs[1]->dereference();
- Term* areg0 = local_aregs[0]->dereference();
- Term* var1 = Machine::Var(mach);
- if ( !((areg0)->LogUnify(SymbolTerm::intern(string2))) ) {
- return mach->fail();
- }
- if ( !((areg1)->LogUnify(var1)) ) {
- return mach->fail();
- }
- if ( !((areg2)->LogUnify(var1->dereference())) ) {
- return mach->fail();
- }
- local_aregs[0] = continuation;
- mach->CUTB = mach->CurrentChoice;
- local_aregs[3] = local_aregs[2] = local_aregs[1] = nullptr;
- return UpperPrologMachine::Call1;
- }
- Operation pred_append_3_2::exec(Prolog* mach) {
- mach->RemoveChoice();
- std::vector<Term*> local_aregs = mach->Areg;
- Term* continuation = local_aregs[3];
- Term* areg2 = local_aregs[2]->dereference();
- Term* areg1 = local_aregs[1]->dereference();
- Term* areg0 = local_aregs[0]->dereference();
- Term* var4 = Machine::Var(mach);
- Term* var3 = Machine::Var(mach);
- Term* var2 = Machine::Var(mach);
- Term* var1 = Machine::Var(mach);
- if ( !((areg0)->LogUnify(StructureTerm::makeCompound(string1,{ var1, var2}))) ) {
- return mach->fail();
- }
- if ( !((areg1)->LogUnify(var3)) ) {
- return mach->fail();
- }
- if ( !((areg2)->LogUnify(StructureTerm::makeCompound(string1,{ var1->dereference(), var4}))) ) {
- return mach->fail();
- }
- local_aregs[0] = var2->dereference();
- local_aregs[1] = var3->dereference();
- local_aregs[2] = var4->dereference();
- local_aregs[3] = continuation;
- mach->CUTB = mach->CurrentChoice;
- return entry_code;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement