// File: /workspace/github_cpp_makefile_star2_O2/marxn[P]pupp/src/parser/transaction.cpp
// Function: TransNode::Invoke(NodeContext*)
int TransNode::Invoke(NodeContext * context)
{
        list<TransIdentDesc>::iterator vd;
                
        for(vd = this->VarDefList.begin(); vd!= this->VarDefList.end(); vd++)
        {
                string varname = vd->SrcVardef->GetVarName();
                
                unsigned long src_layer = vd->SrcLayer;
                unsigned long src_index = vd->SrcVardef->GetVarIndex();
                unsigned long dst_index = vd->DstVarDef->GetVarIndex();
                
                Variable * var = context->GetVariable(0, dst_index);
                if(var==NULL)
                {
                        cerr<<"pupp runtime error: cannot find variable "<<varname<<" in current context."<<endl;
                        return NODE_RET_ERROR;
                }
                
                Variable * origin = context->GetVariable(src_layer, src_index);
                if(origin==NULL)
                {
                        cerr<<"pupp runtime error: cannot find variable: "<<varname<<" in outer context"<<endl;
                        return NODE_RET_ERROR;
                }

                //Copy the value of source variable to local transaction variable.
                //Note: var type must be figure out because any var type is determined in run-time.
                ConstValue * value = origin->GetValue();
                DataType type = origin->GetVarType();
                var->SetRef(value);
                var->SetVarType(type);
        }

        list<Node*>::iterator i;
        for(i = subnodelist->begin(); i != subnodelist->end(); i++)
        {
                context->AddFrame(*i);
                int cond = (*i)->Execute(context);
                context->PopFrame();

                if(cond==NODE_RET_NEEDROLLBACK)
                {
                        return NODE_RET_NORMAL;
                }
                else if(cond==NODE_RET_NEEDCOMMIT)
                {
                        list<TransIdentDesc>::iterator vd;
                        for(vd = this->VarDefList.begin(); vd!= this->VarDefList.end(); vd++)
                        {
                                string varname = vd->SrcVardef->GetVarName();
                                
                                unsigned long src_layer = vd->SrcLayer;
                                unsigned long src_index = vd->SrcVardef->GetVarIndex();
                                unsigned long dst_index = vd->DstVarDef->GetVarIndex();
                
                                Variable * var = context->GetVariable(0, dst_index);
                                
                                if(var==NULL)
                                {
                                        cerr<<"pupp runtime error: cannot find variable "<<varname<<" in current context."<<endl;
                                        return NODE_RET_ERROR;
                                }

                                Variable * origin = context->GetVariable(src_layer, src_index);
                                if(origin==NULL)
                                {
                                        cerr<<"pupp runtime error: cannot find variable: "<<varname<<" in outer context"<<endl;
                                        return NODE_RET_ERROR;
                                }

                                ConstValue * value = var->GetValue();
                                origin->SetRef(value);
                                //delete value;
                        }

                        return NODE_RET_NORMAL;
                }
                else if(cond!=NODE_RET_NORMAL)
                {
                        return cond;
                }
        }

        return NODE_RET_NORMAL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, 0x10(%rsp)
leaq 0x70(%rdi), %r15
movq %r15, 0x8(%rsp)
movq (%r15), %r15
cmpq 0x8(%rsp), %r15
je 0x14886
movq 0x10(%r15), %rsi
leaq 0x18(%rsp), %rdi
callq 0x150f6
movq 0x10(%r15), %rdi
movq 0x20(%r15), %r12
callq 0x15116
movq %rax, %rbp
movq 0x18(%r15), %rdi
callq 0x15116
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0xad28
movq %rax, %r13
testq %rax, %rax
je 0x1496e
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0xad28
movq %rax, %r12
testq %rax, %rax
je 0x14837
movq %r12, %rdi
callq 0x14e8a
movq %rax, %r14
movq %r12, %rdi
callq 0x14f12
movl %eax, %ebp
movq %r13, %rdi
movq %r14, %rsi
callq 0x14dbc
movq %r13, %rdi
movl %ebp, %esi
callq 0x14f0e
jmp 0x1486e
movq 0x2e7b2(%rip), %rdi     # 0x42ff0
leaq 0x1abd8(%rip), %rsi     # 0x2f41d
callq 0x6240
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x6210
movq %rax, %rdi
leaq 0x1c753(%rip), %rsi     # 0x30fb4
callq 0x6240
movq %rax, %rdi
callq 0x6140
leaq 0x18(%rsp), %rdi
callq 0x6130
testq %r12, %r12
jne 0x147a7
jmp 0x149af
movq 0x10(%rsp), %rax
movq 0x60(%rax), %r14
movq (%r14), %r14
xorl %r15d, %r15d
movq 0x10(%rsp), %rax
cmpq 0x60(%rax), %r14
je 0x149b5
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0xac22
movq 0x10(%r14), %rdi
movq %rbx, %rsi
callq 0xa98a
movl %eax, %ebp
movq %rbx, %rdi
callq 0xabba
testl %ebp, %ebp
je 0x1488f
cmpl $0x4, %ebp
je 0x149b5
cmpl $0x5, %ebp
jne 0x149c7
xorl %r15d, %r15d
movq 0x8(%rsp), %r14
movq (%r14), %r14
cmpq 0x8(%rsp), %r14
je 0x149b5
movq 0x10(%r14), %rsi
leaq 0x18(%rsp), %rdi
callq 0x150f6
movq 0x10(%r14), %rdi
movq 0x20(%r14), %r12
callq 0x15116
movq %rax, %r13
movq 0x18(%r14), %rdi
callq 0x15116
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0xad28
movq %rax, %rbp
testq %rax, %rax
je 0x149cc
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xad28
movq %rax, %r12
testq %rax, %rax
je 0x14a05
movq %rbp, %rdi
callq 0x14e8a
movq %r12, %rdi
movq %rax, %rsi
callq 0x14dbc
leaq 0x18(%rsp), %rdi
callq 0x6130
jmp 0x148e4
movq 0x2e67b(%rip), %rdi     # 0x42ff0
leaq 0x1c5f9(%rip), %rsi     # 0x30f75
callq 0x6240
leaq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x6210
leaq 0x1c60a(%rip), %rsi     # 0x30f9f
movq %rax, %rdi
callq 0x6240
movq %rax, %rdi
callq 0x6140
leaq 0x18(%rsp), %rdi
callq 0x6130
pushq $-0x1
popq %rax
movl %eax, %r15d
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, %r15d
jmp 0x149b5
movq 0x2e61d(%rip), %rdi     # 0x42ff0
leaq 0x1c59b(%rip), %rsi     # 0x30f75
callq 0x6240
leaq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x6210
leaq 0x1c5ac(%rip), %rsi     # 0x30f9f
movq %rax, %rdi
callq 0x6240
movq %rax, %rdi
callq 0x6140
jmp 0x149a5
movq 0x2e5e4(%rip), %rdi     # 0x42ff0
leaq 0x1aa0a(%rip), %rsi     # 0x2f41d
callq 0x6240
leaq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x6210
leaq 0x1c588(%rip), %rsi     # 0x30fb4
movq %rax, %rdi
callq 0x6240
movq %rax, %rdi
callq 0x6140
jmp 0x149a5
jmp 0x14a5b
jmp 0x14a5b
jmp 0x14a5b
jmp 0x14a5b
jmp 0x14a5b
jmp 0x14a5b
jmp 0x14a5b
jmp 0x14a5b
jmp 0x14a5b
jmp 0x14a5b
jmp 0x14a5b
jmp 0x14a5b
jmp 0x14a5b
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x6130
movq %rbx, %rdi
callq 0x6460