// File: /workspace/github_cpp_makefile_star2_O3/marxn[P]pupp/src/parser/expression.cpp
// Function: LambdaExpression::Calculate(NodeContext*)
ConstValue * LambdaExpression::Calculate(NodeContext * context)
{
        list<ClosureVarDesc*> * CopyVars = this->FuncNode->GetCopyList();
        list<Variable *> * cv = new list<Variable *>;

        if(CopyVars!=NULL)
        {
            list<ClosureVarDesc*>::iterator i;
            for(i = CopyVars->begin(); i != CopyVars->end(); i++)
            {
                string varname = (*i)->GetVarName();
                unsigned long layer  = (*i)->GetSrcLayer();
                VariableDef * srcdef = (*i)->GetSrcDef();
                
                Variable * origin = context->GetVariable(layer, srcdef->GetVarIndex());
                if(origin==NULL)
                {
                    cerr<<"pupp runtime error: cannot find variable: "<<varname<<" in the context"<<endl;
                    return NULL;
                }

                if((*i)->IsRef())
                {
                    cv->push_back(origin->CreateVarRef());
                }
                else
                {
                    if(origin->GetVarType()==Func)
                    {
                        ValueBox * vbox = origin->GetVBox();
                        if(vbox==NULL || vbox->GetVal()->GetType()==Null)
                        {
                            return NULL;
                        }
                    }

                    Variable * cl_var = new Variable(origin->GetVarName(), origin->GetVarType());
                    cl_var->SetSource(origin->GetSource());
                    cl_var->SetRef(origin->GetValue());
                    cv->push_back(cl_var);
                }
            }
        }
        FuncValue * ret = new FuncValue(this->FuncNode, cv);

        return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, 0x20(%rsp)
movq 0x18(%rdi), %rdi
callq 0xbd7a
movq %rax, %r12
movl $0x18, %edi
callq 0x6260
movq %rax, %r14
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq $0x0, 0x10(%rax)
testq %r12, %r12
je 0xb4f6
movq (%r12), %r13
cmpq %r12, %r13
je 0xb4f6
movq 0x10(%r13), %rsi
movq %rsp, %rdi
callq 0xbc82
movq 0x10(%r13), %rdi
callq 0xbcba
movq %rax, %rbx
movq 0x10(%r13), %rdi
callq 0xbcc0
movq %rax, %rdi
callq 0x189a0
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0xc7ec
movq %rax, %rbx
testq %rax, %rax
je 0xb51c
movq 0x10(%r13), %rdi
callq 0xbca4
testb %al, %al
je 0xb40c
movq %rbx, %rdi
callq 0x18798
movq %rax, %rbp
movl $0x18, %edi
callq 0x6260
jmp 0xb4bf
movq %rbx, %rdi
callq 0x18716
cmpl $0x8, %eax
jne 0xb442
movq %rbx, %rdi
callq 0x185ae
testq %rax, %rax
je 0xb587
movq %rax, %rdi
callq 0x7e76
movq %rax, %rdi
callq 0x7da6
testl %eax, %eax
je 0xb587
movl $0x38, %edi
callq 0x6260
movq %rax, %rbp
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x1857c
movq %rbx, %rdi
callq 0x18716
movq %rbp, %rdi
leaq 0x28(%rsp), %rsi
movl %eax, %edx
callq 0x184e8
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xb48f
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6270
movq %rbx, %rdi
callq 0x185a4
movq %rbp, %rdi
movq %rax, %rsi
callq 0x185a0
movq %rbx, %rdi
callq 0x1868a
movq %rbp, %rdi
movq %rax, %rsi
callq 0x185b4
movl $0x18, %edi
callq 0x6260
movq %rbp, 0x10(%rax)
movq %rax, %rdi
movq %r14, %rsi
callq 0x6070
incq 0x10(%r14)
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb4ed
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6270
movq (%r13), %r13
jmp 0xb399
movl $0x20, %edi
callq 0x6260
movq %rax, %r15
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x189b0
jmp 0xb5a5
movq 0x3bacd(%rip), %rdi     # 0x46ff0
leaq 0x29ef3(%rip), %rsi     # 0x3541d
movl $0x2a, %edx
callq 0x62f0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x3baac(%rip), %rdi     # 0x46ff0
callq 0x62f0
movq %rax, %rbx
leaq 0x29ef5(%rip), %rsi     # 0x35448
movl $0xf, %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 (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb5a2
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6270
xorl %r15d, %r15d
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x20, %esi
movq %r15, %rdi
jmp 0xb61c
jmp 0xb603
movq %rax, %rbx
jmp 0xb5ec
jmp 0xb603
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xb5ec
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6270
movl $0x38, %esi
movq %rbp, %rdi
callq 0x6270
jmp 0xb606
jmp 0xb603
jmp 0xb603
jmp 0xb603
jmp 0xb603
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb621
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6270
movq %rbx, %rdi
callq 0x6460
nop