// File: /workspace/github_cpp_makefile_star2_O1/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), %r15
movq %r15, 0x28(%rsp)
movq (%r15), %r15
cmpq 0x28(%rsp), %r15
je 0x1826d
movq 0x10(%r15), %rsi
leaq 0x8(%rsp), %rdi
callq 0x18cc0
movq 0x10(%r15), %rdi
movq 0x20(%r15), %r13
callq 0x18cf4
movq %rax, %r14
movq 0x18(%r15), %rdi
callq 0x18cf4
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0xc886
movq %rax, %rbp
testq %rax, %rax
je 0x18486
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0xc886
movq %rax, %r13
testq %rax, %rax
je 0x181d7
movq %r13, %rdi
callq 0x189e0
movq %rax, %r12
movq %r13, %rdi
callq 0x18a6c
movl %eax, %r14d
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1890c
movq %rbp, %rdi
movl %r14d, %esi
callq 0x18a68
jmp 0x18243
movl $0x2a, %edx
movq 0x2fe0d(%rip), %rdi     # 0x47ff0
leaq 0x1e233(%rip), %rsi     # 0x3641d
callq 0x62f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x2fdf0(%rip), %rdi     # 0x47ff0
callq 0x62f0
movq %rax, %r14
movl $0x11, %edx
movq %rax, %rdi
leaq 0x1fda1(%rip), %rsi     # 0x37fb8
callq 0x62f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %r14, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1825f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6270
testq %r13, %r13
jne 0x18145
jmp 0x1850e
movq 0x30(%rsp), %rax
movq 0x60(%rax), %r12
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq (%r12), %r12
movq 0x30(%rsp), %rax
cmpq 0x60(%rax), %r12
je 0x18516
movq 0x10(%r12), %rsi
movq %rbx, %rdi
callq 0xc748
movq 0x10(%r12), %rdi
movq %rbx, %rsi
callq 0xc3c2
movl %eax, %ebp
movq %rbx, %rdi
callq 0xc6cc
testl %ebp, %ebp
je 0x18470
cmpl $0x4, %ebp
je 0x18469
cmpl $0x5, %ebp
jne 0x18474
movl %r14d, 0x4(%rsp)
movq 0x28(%rsp), %r13
movq (%r13), %r13
cmpq 0x28(%rsp), %r13
je 0x18469
movq 0x10(%r13), %rsi
leaq 0x8(%rsp), %rdi
callq 0x18cc0
movq 0x10(%r13), %rdi
movq 0x20(%r13), %rbp
callq 0x18cf4
movq %rax, %r14
movq 0x18(%r13), %rdi
callq 0x18cf4
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0xc886
movq %rax, %r15
testq %rax, %rax
je 0x18357
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0xc886
movq %rax, %r14
testq %rax, %rax
je 0x183c5
movq %r15, %rdi
callq 0x189e0
movb $0x1, %bpl
movq %r14, %rdi
movq %rax, %rsi
callq 0x1890c
jmp 0x1843b
movl $0x29, %edx
movq 0x2fc8d(%rip), %rdi     # 0x47ff0
leaq 0x1fc0f(%rip), %rsi     # 0x37f79
callq 0x62f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x2fc70(%rip), %rdi     # 0x47ff0
callq 0x62f0
movq %rax, %r14
movl $0x14, %edx
movq %rax, %rdi
leaq 0x1fc0c(%rip), %rsi     # 0x37fa3
callq 0x62f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %r14, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
jmp 0x18431
movl $0x2a, %edx
movq 0x2fc1f(%rip), %rdi     # 0x47ff0
leaq 0x1e045(%rip), %rsi     # 0x3641d
callq 0x62f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x2fc02(%rip), %rdi     # 0x47ff0
callq 0x62f0
movq %rax, %r14
movl $0x11, %edx
movq %rax, %rdi
leaq 0x1fbb3(%rip), %rsi     # 0x37fb8
callq 0x62f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %r14, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x18457
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6270
testb %bpl, %bpl
jne 0x182d7
xorl %eax, %eax
movl 0x4(%rsp), %r14d
jmp 0x18479
xorl %eax, %eax
xorl %r14d, %r14d
jmp 0x18479
movb $0x1, %al
jmp 0x18479
xorl %eax, %eax
movl %ebp, %r14d
testb %al, %al
jne 0x1827c
jmp 0x18519
movq 0x2fb63(%rip), %rdi     # 0x47ff0
leaq 0x1fae5(%rip), %rsi     # 0x37f79
movl $0x29, %edx
callq 0x62f0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x2fb41(%rip), %rdi     # 0x47ff0
callq 0x62f0
movq %rax, %rbx
leaq 0x1fae5(%rip), %rsi     # 0x37fa3
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 0x1850e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6270
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x18519
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x18541
jmp 0x18541
jmp 0x18541
jmp 0x18541
jmp 0x18541
jmp 0x18541
jmp 0x18541
jmp 0x18541
jmp 0x18541
jmp 0x18541
jmp 0x18541
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x18560
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6270
movq %rbx, %rdi
callq 0x6470