// File: /workspace/github_cpp_makefile_star2_O3/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, 0x30(%rsp)
leaq 0x70(%rdi), %r14
movq %r14, 0x28(%rsp)
movq (%r14), %r14
cmpq 0x28(%rsp), %r14
je 0x17f5e
movq 0x10(%r14), %rsi
leaq 0x8(%rsp), %rdi
callq 0x1896c
movq 0x10(%r14), %rdi
movq 0x20(%r14), %r13
callq 0x189a0
movq %rax, %r12
movq 0x18(%r14), %rdi
callq 0x189a0
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0xc7ec
movq %rax, %rbp
testq %rax, %rax
je 0x18148
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0xc7ec
movq %rax, %r13
testq %rax, %rax
je 0x17ec7
movq %r13, %rdi
callq 0x1868a
movq %rax, %r15
movq %r13, %rdi
callq 0x18716
movl %eax, %r12d
movq %rbp, %rdi
movq %r15, %rsi
callq 0x185b4
movq %rbp, %rdi
movl %r12d, %esi
callq 0x18712
jmp 0x17f34
movl $0x2a, %edx
movq 0x2f11d(%rip), %rdi     # 0x46ff0
leaq 0x1d543(%rip), %rsi     # 0x3541d
callq 0x62f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x2f100(%rip), %rdi     # 0x46ff0
callq 0x62f0
movq %rax, %r12
movl $0x11, %edx
movq %rax, %rdi
leaq 0x1f0ad(%rip), %rsi     # 0x36fb4
callq 0x62f0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %r12, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x17f50
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6270
testq %r13, %r13
jne 0x17e35
jmp 0x181d0
movq 0x30(%rsp), %rax
movq 0x60(%rax), %r15
movq (%r15), %r15
xorl %r14d, %r14d
movq 0x30(%rsp), %rax
cmpq 0x60(%rax), %r15
je 0x181d6
movq 0x10(%r15), %rsi
movq %rbx, %rdi
callq 0xc6ae
movq 0x10(%r15), %rdi
movq %rbx, %rsi
callq 0xc316
movl %eax, %ebp
movq %rbx, %rdi
callq 0xc626
testl %ebp, %ebp
je 0x17f67
cmpl $0x4, %ebp
je 0x181d6
cmpl $0x5, %ebp
jne 0x181e8
xorl %r14d, %r14d
movq 0x28(%rsp), %r12
movq (%r12), %r12
cmpq 0x28(%rsp), %r12
je 0x181d6
movq 0x10(%r12), %rsi
leaq 0x8(%rsp), %rdi
callq 0x1896c
movq 0x10(%r12), %rdi
movq 0x20(%r12), %r13
callq 0x189a0
movq %rax, %rbp
movq 0x18(%r12), %rdi
callq 0x189a0
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0xc7ec
movq %rax, %r15
testq %rax, %rax
je 0x18040
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0xc7ec
movq %rax, %r13
testq %rax, %rax
je 0x180af
movq %r15, %rdi
callq 0x1868a
movb $0x1, %bpl
movq %r13, %rdi
movq %rax, %rsi
callq 0x185b4
jmp 0x1811e
movl $0x29, %edx
movq 0x2efa4(%rip), %rdi     # 0x46ff0
leaq 0x1ef22(%rip), %rsi     # 0x36f75
callq 0x62f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x2ef87(%rip), %rdi     # 0x46ff0
callq 0x62f0
movq %rax, %r13
movl $0x14, %edx
movq %rax, %rdi
leaq 0x1ef1f(%rip), %rsi     # 0x36f9f
callq 0x62f0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %r13, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
jmp 0x1811c
movl $0x2a, %edx
movq 0x2ef35(%rip), %rdi     # 0x46ff0
leaq 0x1d35b(%rip), %rsi     # 0x3541d
callq 0x62f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x2ef18(%rip), %rdi     # 0x46ff0
callq 0x62f0
movq %rax, %r13
movl $0x11, %edx
movq %rax, %rdi
leaq 0x1eec5(%rip), %rsi     # 0x36fb4
callq 0x62f0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %r13, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
xorl %ebp, %ebp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1813a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6270
testb %bpl, %bpl
jne 0x17fbc
jmp 0x181d0
movq 0x2eea1(%rip), %rdi     # 0x46ff0
leaq 0x1ee1f(%rip), %rsi     # 0x36f75
movl $0x29, %edx
callq 0x62f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x2ee7f(%rip), %rdi     # 0x46ff0
callq 0x62f0
movq %rax, %rbx
leaq 0x1ee1f(%rip), %rsi     # 0x36f9f
movl $0x14, %edx
movq %rax, %rdi
callq 0x62f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x181d0
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6270
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, %r14d
jmp 0x181d6
jmp 0x18203
jmp 0x18203
jmp 0x18203
jmp 0x18203
jmp 0x18203
jmp 0x18203
jmp 0x18203
jmp 0x18203
jmp 0x18203
jmp 0x18203
jmp 0x18203
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x18222
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6270
movq %rbx, %rdi
callq 0x6460