// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq %rsi, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
movq 0x18(%rdi), %rdi
callq 0xa5dc
movq %rax, %rbx
pushq $0x18
popq %rdi
callq 0x6260
movq %rax, %r14
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
movq %rbx, 0x10(%rsp)
testq %rbx, %rbx
je 0x9b87
leaq 0x48(%rsp), %r13
movq 0x10(%rsp), %r12
movq (%r12), %r12
cmpq 0x10(%rsp), %r12
je 0x9b87
movq 0x10(%r12), %rsi
leaq 0x28(%rsp), %rdi
callq 0xa516
movq 0x10(%r12), %rdi
callq 0xa53a
movq %rax, %rbx
movq 0x10(%r12), %rdi
callq 0xa540
movq %rax, %rdi
callq 0x15116
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0xad28
movq %rax, %rbp
testq %rax, %rax
je 0x9ba8
movq 0x10(%r12), %rdi
callq 0xa524
testb %al, %al
je 0x9acf
movq %rbp, %rdi
callq 0x14f90
movq %rax, 0x8(%rsp)
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x9f90
jmp 0x9b78
movq %rbp, %rdi
callq 0x14f12
cmpl $0x8, %eax
jne 0x9b05
movq %rbp, %rdi
callq 0x14db6
testq %rax, %rax
je 0x9bdf
movq %rax, %rdi
callq 0x6d66
movq %rax, %rdi
callq 0x6cbc
testl %eax, %eax
je 0x9bdf
pushq $0x38
popq %rdi
callq 0x6260
movq %rax, %rbx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x14d96
movq %rbp, %rdi
callq 0x14f12
movq %r13, %r15
movq %rbx, %rdi
movq %r13, %rsi
movl %eax, %edx
callq 0x14d20
movq %r15, %rdi
callq 0x6130
movq %rbx, 0x8(%rsp)
movq %rbp, %rdi
callq 0x14dac
movq %rbx, %rdi
movq %rax, %rsi
callq 0x14da8
movq 0x8(%rsp), %rbx
movq %rbp, %rdi
callq 0x14e8a
movq %rbx, %rdi
movq %rax, %rsi
callq 0x14dbc
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x9f9c
leaq 0x28(%rsp), %rdi
callq 0x6130
jmp 0x9a49
pushq $0x20
popq %rdi
callq 0x6260
movq %rax, %rbx
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x15128
jmp 0x9beb
movq 0x39441(%rip), %rdi     # 0x42ff0
leaq 0x25867(%rip), %rsi     # 0x2f41d
callq 0x6240
leaq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x6210
leaq 0x25879(%rip), %rsi     # 0x2f448
movq %rax, %rdi
callq 0x6240
movq %rax, %rdi
callq 0x6140
leaq 0x28(%rsp), %rdi
callq 0x6130
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0x6270
jmp 0x9c45
jmp 0x9c38
movq %rax, %r14
jmp 0x9c23
jmp 0x9c38
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0x6130
pushq $0x38
popq %rsi
movq %rbx, %rdi
callq 0x6270
jmp 0x9c3b
jmp 0x9c38
jmp 0x9c38
jmp 0x9c38
jmp 0x9c38
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x6130
movq %r14, %rdi
callq 0x6460
nop