// File: /workspace/github_cpp_makefile_star2_O1/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 0xbe36
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 0xb5b2
movq (%r12), %r13
cmpq %r12, %r13
je 0xb5b2
movq 0x10(%r13), %rsi
movq %rsp, %rdi
callq 0xbd3e
movq 0x10(%r13), %rdi
callq 0xbd76
movq %rax, %rbx
movq 0x10(%r13), %rdi
callq 0xbd7c
movq %rax, %rdi
callq 0x18cf4
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0xc886
movq %rax, %rbx
testq %rax, %rax
je 0xb5d8
movq 0x10(%r13), %rdi
callq 0xbd60
testb %al, %al
je 0xb4c8
movq %rbx, %rdi
callq 0x18aec
movq %rax, %rbp
movl $0x18, %edi
callq 0x6260
jmp 0xb57b
movq %rbx, %rdi
callq 0x18a6c
cmpl $0x8, %eax
jne 0xb4fe
movq %rbx, %rdi
callq 0x18906
testq %rax, %rax
je 0xb643
movq %rax, %rdi
callq 0x7ec4
movq %rax, %rdi
callq 0x7dee
testl %eax, %eax
je 0xb643
movl $0x38, %edi
callq 0x6260
movq %rax, %rbp
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x188d4
movq %rbx, %rdi
callq 0x18a6c
movq %rbp, %rdi
leaq 0x28(%rsp), %rsi
movl %eax, %edx
callq 0x18840
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xb54b
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6270
movq %rbx, %rdi
callq 0x188fc
movq %rbp, %rdi
movq %rax, %rsi
callq 0x188f8
movq %rbx, %rdi
callq 0x189e0
movq %rbp, %rdi
movq %rax, %rsi
callq 0x1890c
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 0xb5a9
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6270
movq (%r13), %r13
jmp 0xb455
movl $0x20, %edi
callq 0x6260
movq %rax, %r15
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x18d04
jmp 0xb661
movq 0x3ca11(%rip), %rdi     # 0x47ff0
leaq 0x2ae37(%rip), %rsi     # 0x3641d
movl $0x2a, %edx
callq 0x62f0
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x3c9f0(%rip), %rdi     # 0x47ff0
callq 0x62f0
movq %rax, %rbx
leaq 0x2ae39(%rip), %rsi     # 0x36448
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 0xb65e
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 0xb6d8
jmp 0xb6bf
movq %rax, %rbx
jmp 0xb6a8
jmp 0xb6bf
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xb6a8
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6270
movl $0x38, %esi
movq %rbp, %rdi
callq 0x6270
jmp 0xb6c2
jmp 0xb6bf
jmp 0xb6bf
jmp 0xb6bf
jmp 0xb6bf
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb6dd
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6270
movq %rbx, %rdi
callq 0x6470
nop