// File: /workspace/github_cpp_makefile_star2_O2/marxn[P]pupp/src/parser/statement.cpp
// Function: VarDefinitionStatement::Invoke(NodeContext*)
int VarDefinitionStatement::Invoke(NodeContext * context)
{
        string name = *(this->Ident);
        Variable * var = context->GetVariable(1, this->VarDef->GetVarIndex());

        if(var==NULL)
        {
                cerr<<"pupp runtime error: cannot find variable:"<<name<<endl;
                return NODE_RET_ERROR;
        }

        if(this->VarType->GetVarType()==Array)
        {
                list<Expression*> * dim = this->VarType->GetDimentions();
                vector<long> desc;
                long size = 1;

                list<Expression*>::iterator i;
                for(i = dim->begin(); i!= dim->end(); i++)
                {
                        ConstValue * dsize = (*i)->Calculate(context);
                        if(dsize->GetType()!=Integer || static_cast<IntegerValue*>(dsize)->GetValue()<=0)
                        {
                                cerr<<"pupp runtime error: Size of an array must be a positive integer."<<endl;
                                delete dsize;
                                return NODE_RET_ERROR;
                        }

                        delete dsize;

                        long n = static_cast<IntegerValue*>(dsize)->GetValue();
                        size *= n;
                        desc.push_back(n);
                }

                ArrayValue * val = new ArrayValue(this->VarType->GetElementType(), desc, size);
                var->SetRef(val);
                return NODE_RET_NORMAL;
        }

        if(this->InitExpr!=NULL)
        {
                ConstValue * value = this->InitExpr->Calculate(context);
                if(value==NULL)
                {
                        return NODE_RET_ERROR;
                }

                if(value->GetType()==Null)
                {
                        cerr<<"pupp runtime error: variable type cannot be determined."<<endl;
                        delete value;
                        return NODE_RET_ERROR;
                }
                var->SetVarType(value->GetType());
                var->SetRef(value);
        }

        return NODE_RET_NORMAL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, %r14
movq 0x70(%rdi), %rsi
leaq 0x28(%rsp), %rdi
callq 0x6380
movq 0x60(%r14), %rdi
callq 0x15116
pushq $0x1
popq %r12
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0xad28
testq %rax, %rax
je 0x1406f
movq %rax, (%rsp)
movq 0x78(%r14), %r13
cmpl $0x7, (%r13)
jne 0x1409f
addq $0x8, %r13
leaq 0x10(%rsp), %rax
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movq %r13, %rbp
movq (%rbp), %rbp
cmpq %r13, %rbp
je 0x14125
movq 0x10(%rbp), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
movq %rax, %rbx
movq %rax, %rdi
callq 0x6cbc
cmpl $0x1, %eax
jne 0x140fc
movq %rbx, %rdi
callq 0x6fe4
testq %rax, %rax
jle 0x140fc
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movq %rbx, %rdi
callq 0x6fe4
movq %rax, %rbx
movq %rax, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x14596
imulq %rbx, %r12
jmp 0x14002
movq 0x2ef7a(%rip), %rdi     # 0x42ff0
leaq 0x1b0c3(%rip), %rsi     # 0x2f140
callq 0x6240
leaq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x6210
movq %rax, %rdi
callq 0x6140
pushq $-0x1
popq %rbp
jmp 0x14187
movq 0x68(%r14), %rdi
xorl %ebp, %ebp
testq %rdi, %rdi
je 0x14187
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
movq (%rsp), %r15
movq %rax, %r14
pushq $-0x1
popq %rbx
testq %rax, %rax
je 0x14185
movq %r14, %rdi
callq 0x6cbc
testl %eax, %eax
je 0x14161
movq %r14, %rdi
callq 0x6cbc
movq %r15, %rdi
movl %eax, %esi
callq 0x14f0e
movq %r15, %rdi
movq %r14, %rsi
callq 0x14dbc
jmp 0x14187
movq 0x2eeed(%rip), %rdi     # 0x42ff0
leaq 0x1cd87(%rip), %rsi     # 0x30e91
callq 0x6240
movq %rax, %rdi
callq 0x6140
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
pushq $-0x1
popq %rbp
jmp 0x14155
pushq $0x38
popq %rdi
callq 0x6260
movq %rax, %r15
movq 0x78(%r14), %rax
movl 0x4(%rax), %esi
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rcx
callq 0x7bf4
movq (%rsp), %rdi
xorl %ebp, %ebp
movq %r15, %rsi
callq 0x14dbc
leaq 0x10(%rsp), %rdi
callq 0x8746
jmp 0x14187
movq 0x2ee88(%rip), %rdi     # 0x42ff0
leaq 0x1cd63(%rip), %rsi     # 0x30ed2
callq 0x6240
movq %rax, %rdi
callq 0x6140
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
movl %ebx, %ebp
leaq 0x28(%rsp), %rdi
callq 0x6130
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
pushq $0x38
popq %rsi
movq %r15, %rdi
callq 0x6270
jmp 0x141c2
jmp 0x141bf
jmp 0x141bf
jmp 0x141b8
movq %rax, %rbx
jmp 0x141cc
jmp 0x141bf
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x8746
leaq 0x28(%rsp), %rdi
callq 0x6130
movq %rbx, %rdi
callq 0x6460