// File: /workspace/github_cpp_makefile_star2_O2/marxn[P]pupp/src/parser/statement.cpp
// Function: AssignStatement::Invoke(NodeContext*)
int AssignStatement::Invoke(NodeContext * context)
{
        Variable * var = context->GetVariable(this->VarLayer, this->VarDef->GetVarIndex());
        if(var==NULL)
        {
                cerr<<"pupp runtime error: cannot find variable: "<<this->VarDef->GetVarName()<<endl;
                return NODE_RET_ERROR;
        }

        if(var->GetVarType()!=Array && var->GetVarType()!=Map && this->Reference->GetExpsList()->size()>0)
        {
                cerr<<"pupp runtime error: Variable "<<this->Reference->GetVarName()<<" is neither an array nor a set."<<endl;
                return false;
        }

        ValueBox * result = var->GetVBox();
        
        if(this->Reference->GetExpsList()->size()==0 && var->GetVarType()==Array)
        {
                cerr<<"pupp runtime error: cannot assign for an array"<<var->GetVarName()<<endl;
                return NODE_RET_ERROR;
        }
        
        bool need_convert = true;
        list<list<Expression*>*> * exprslist = this->Reference->GetExpsList();
        
        for(list<list<Expression*>*>::iterator gitor = exprslist->begin(); gitor!=exprslist->end(); gitor++)
        {
                list<Expression*>* exprlist = *gitor;
                
                if(result==NULL)
                {
                        cerr<<"pupp runtime error: cannot find key for variable "<<var->GetVarName()<<endl;
                        return NODE_RET_ERROR;
                }
                else if(result->GetVal()->GetType()==Array)
                {
                        if(static_cast<ArrayValue*>(result->GetVal())->GetDimensionNum()!=exprlist->size())
                        {
                                cerr<<"pupp runtime error: wrong dimension variable: "<<var->GetVarName()<<endl;
                                return NODE_RET_ERROR;
                        }

                        vector<long> desc;
                        
                        for(list<Expression*>::iterator i = exprlist->begin(); i!=exprlist->end(); i++)
                        {
                                ConstValue * value = (*i)->Calculate(context);
                                if(value->GetType()!=Integer)
                                {
                                        ConstValue * thevalue = ConstValueCast(value, Integer);
                                        delete value;

                                        if(thevalue==NULL)
                                        {
                                                cerr<<"pupp runtime error: invalid index type for variable: "<<var->GetVarName()<<endl;
                                                return NODE_RET_ERROR;
                                        }
                                        
                                        value = thevalue;
                                        
                                }
                                
                                desc.push_back(static_cast<IntegerValue*>(value)->GetValue());
                                delete value;
                        }

                        ArrayValue * val = static_cast<ArrayValue*>(result->GetVal());
                        
                        result = val->GetElementBox(desc);
                }
                else if(result->GetVal()->GetType()==Map)
                {
                        need_convert = false;
                        
                        if(exprlist->size() > 1)
                        {
                                cerr<<"pupp runtime error: invalid key list for a collection"<<endl;
                                return NODE_RET_ERROR;
                        }
                        
                        ConstValue * key = exprlist->front()->Calculate(context);
                        if(key==NULL)
                        {
                                cerr<<"pupp runtime error: invalid key for a collection"<<endl;
                                return NODE_RET_ERROR;
                        }
                        
                        MapValue * val = static_cast<MapValue*>(result->GetVal());
                        result = val->FindByKey(key->toString());
                        
                        if(result==NULL)
                        {
                                MapValue * value = new MapValue();
                                ValueBox * vb = new ValueBox(value);
                                KVValue * kv = new KVValue(key, vb);
                                val->AddKV(kv);

                                delete kv;
                                delete vb;
                                delete value;
                                
                                result = val->FindByKey(key->toString());
                        }
                        
                        delete key;
                }
                else
                {
                        cerr<<"pupp runtime error: cannot accept a non-collection variable: "<<var->GetVarName()<<endl;
                        return NODE_RET_ERROR;
                }
        }
        
        ConstValue * value = Expr->Calculate(context);
        
        if(value==NULL)
        {
                cerr<<"pupp runtime error: cannot calculate the value for the expression"<<endl;
                return NODE_RET_ERROR;
        }

        if(result->GetVal()->GetType()!=value->GetType() && need_convert)
        {
                ConstValue * thevalue = ConstValueCast(value, var->GetVarType());
                delete value;
                value = thevalue;

                if(value==NULL)
                {
                        cerr<<"pupp runtime error: data type mismatch while assigning "<<endl;
                        return NODE_RET_ERROR;
                }
        }
        
        this->AdjustValue(result, value, this->OperType);
                
        return NODE_RET_NORMAL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r12
movq %rdi, %r14
movq 0x78(%rdi), %rdi
movq 0x80(%r14), %rbx
callq 0x15116
movq %r12, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0xad28
pushq $-0x1
popq %r13
testq %rax, %rax
je 0x1376d
movq %r14, 0x8(%rsp)
movq %rax, %rbx
movq %rax, %rdi
callq 0x14f12
cmpl $0x7, %eax
je 0x136f1
movq %rbx, %rdi
callq 0x14f12
cmpl $0x6, %eax
je 0x136f1
movq 0x8(%rsp), %rax
movq 0x68(%rax), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0x136f1
movq 0x2f955(%rip), %rdi     # 0x42ff0
leaq 0x1d5eb(%rip), %rsi     # 0x30c8d
callq 0x6240
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq 0x68(%rax), %rsi
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x6380
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6210
leaq 0x1d5d9(%rip), %rsi     # 0x30cab
movq %rax, %rdi
callq 0x6240
movq %rax, %rdi
callq 0x6140
leaq 0x28(%rsp), %rdi
callq 0x6130
jmp 0x13bcf
movq %rbx, 0x18(%rsp)
movq %rbx, %rdi
callq 0x14db6
movq %rax, %r15
movq 0x8(%rsp), %rax
movq 0x68(%rax), %rax
movq 0x20(%rax), %r14
cmpq $0x0, 0x10(%r14)
jne 0x137c6
movq %r15, %rbx
movq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x14f12
cmpl $0x7, %eax
jne 0x137b6
movq 0x2f8b7(%rip), %rdi     # 0x42ff0
leaq 0x1d58b(%rip), %rsi     # 0x30ccb
callq 0x6240
movq %rax, %rbx
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x14d96
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6210
movq %rax, %rdi
callq 0x6140
jmp 0x137a7
movq 0x2f87c(%rip), %rdi     # 0x42ff0
leaq 0x1bca2(%rip), %rsi     # 0x2f41d
callq 0x6240
movq %rax, %rbx
movq 0x78(%r14), %rsi
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x150f6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6210
movq %rax, %rdi
callq 0x6140
leaq 0x28(%rsp), %rdi
callq 0x6130
jmp 0x13bd2
movq 0x8(%rsp), %rax
movq 0x68(%rax), %rax
movq 0x20(%rax), %r14
movq %rbx, %r15
movb $0x1, %al
movl %eax, 0x20(%rsp)
leaq 0x28(%rsp), %r13
movq %r14, %rax
movq %r14, 0x70(%rsp)
movq (%rax), %rax
cmpq %r14, %rax
je 0x13a7e
testq %r15, %r15
je 0x13b17
movq %rax, 0x48(%rsp)
movq 0x10(%rax), %rbp
movq %r15, %rdi
callq 0x6d66
movq %rax, %rdi
callq 0x6cbc
movl %eax, %ebx
movq %r15, 0x10(%rsp)
movq %r15, %rdi
callq 0x6d66
movq %rax, %rdi
cmpl $0x7, %ebx
jne 0x13931
callq 0x7f96
cmpq 0x10(%rbp), %rax
jne 0x13b54
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
andq $0x0, 0x60(%rsp)
movq %rbp, %r14
movq (%r14), %r14
cmpq %rbp, %r14
je 0x138ab
movq 0x10(%r14), %rdi
movq (%rdi), %rax
movq %r12, %rsi
callq *0x10(%rax)
movq %rax, %r15
movq %rax, %rdi
callq 0x6cbc
cmpl $0x1, %eax
je 0x13886
movq %r15, %rdi
pushq $0x1
popq %rsi
callq 0x7fa3
movq %rax, %rbx
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
movq %rbx, %r15
testq %rbx, %rbx
je 0x138c9
movq %r15, %rdi
callq 0x6fe4
movq %rax, 0x28(%rsp)
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0xa146
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
jmp 0x13842
movq 0x10(%rsp), %rdi
callq 0x6d66
movq %rax, %rdi
leaq 0x50(%rsp), %rsi
callq 0x7d4e
movq %rax, 0x10(%rsp)
jmp 0x1390a
movq 0x2f720(%rip), %rdi     # 0x42ff0
leaq 0x1d455(%rip), %rsi     # 0x30d2c
callq 0x6240
movq %rax, %r15
movq %r13, %rbx
movq %r13, %rdi
movq 0x18(%rsp), %rsi
callq 0x14d96
movq %r15, %rdi
movq %rbx, %rsi
callq 0x6210
movq %rax, %rdi
callq 0x6140
movq %r13, %rdi
callq 0x6130
leaq 0x50(%rsp), %rdi
callq 0x8746
cmpq %rbp, %r14
movq 0x70(%rsp), %r14
movq 0x48(%rsp), %rax
movq 0x10(%rsp), %r15
je 0x137d9
jmp 0x13b99
callq 0x6cbc
cmpl $0x6, %eax
jne 0x13be7
cmpq $0x2, 0x10(%rbp)
jae 0x13c2b
movq (%rbp), %rax
movq 0x10(%rax), %rdi
movq (%rdi), %rax
movq %r12, %rsi
callq *0x10(%rax)
testq %rax, %rax
je 0x13c3b
movq %rax, %r15
movq 0x10(%rsp), %rdi
callq 0x6d66
movq %rax, %rbp
movq (%r15), %rax
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
movq %r15, 0x10(%rsp)
movq %r15, %rsi
callq *0x18(%rax)
movq %rbp, 0x20(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x78f0
movq %rax, %r15
movq %rbx, %rdi
callq 0x6130
movq %r15, %rbx
testq %r15, %r15
jne 0x13a5e
pushq $0x40
popq %rdi
callq 0x6260
movq %rax, %rbx
movq %rax, %rdi
callq 0x76dc
pushq $0x10
popq %rdi
callq 0x6260
movq %rax, %r15
movq %rax, %rdi
movq %rbx, 0x68(%rsp)
movq %rbx, %rsi
callq 0x6cce
pushq $0x20
popq %rdi
callq 0x6260
movq %rax, %rbx
movq %rax, %rdi
movq 0x10(%rsp), %rbp
movq %rbp, %rsi
movq %r15, %rdx
callq 0x7554
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x782c
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movq %r15, %rdi
callq 0x6cf2
movq %r15, %rdi
pushq $0x10
popq %rsi
callq 0x6270
movq 0x68(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq (%rbp), %rax
leaq 0x78(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq *0x18(%rax)
movq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x78f0
movq %rax, %rbx
movq %r15, %rdi
callq 0x6130
movq 0x10(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x0, 0x20(%rsp)
movq 0x48(%rsp), %rax
movq %rbx, %r15
jmp 0x137d9
movq %r15, %r14
movq 0x8(%rsp), %rax
movq 0x70(%rax), %rdi
movq (%rdi), %rax
movq %r12, %rsi
callq *0x10(%rax)
testq %rax, %rax
pushq $-0x1
popq %r13
je 0x13b9f
movq %rax, %rbx
movq %r14, %rdi
callq 0x6d66
movq %rax, %rdi
callq 0x6cbc
movl %eax, %ebp
movq %rbx, %rdi
callq 0x6cbc
cmpl %eax, %ebp
sete %al
movl 0x20(%rsp), %ecx
notb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x13bbc
movq 0x18(%rsp), %rdi
callq 0x14f12
movq %rbx, %rdi
movl %eax, %esi
callq 0x7fa3
movq %rax, %r15
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movq %r15, %rbx
testq %r15, %r15
movq 0x8(%rsp), %rax
jne 0x13bc1
movq 0x2f4e5(%rip), %rdi     # 0x42ff0
leaq 0x1d337(%rip), %rsi     # 0x30e49
jmp 0x13bad
movq 0x2f4d2(%rip), %rdi     # 0x42ff0
leaq 0x1d1d5(%rip), %rsi     # 0x30cfa
callq 0x6240
movq %rax, %rbx
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x14d96
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6210
movq %rax, %rdi
callq 0x6140
jmp 0x13b8f
movq 0x2f495(%rip), %rdi     # 0x42ff0
leaq 0x1b608(%rip), %rsi     # 0x2f16a
callq 0x6240
movq %rax, %rbx
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x14d96
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6210
movq %rax, %rdi
callq 0x6140
leaq 0x28(%rsp), %rdi
callq 0x6130
pushq $-0x1
popq %r13
jmp 0x13bd2
movq 0x2f44a(%rip), %rdi     # 0x42ff0
leaq 0x1d25a(%rip), %rsi     # 0x30e07
callq 0x6240
movq %rax, %rdi
callq 0x6140
jmp 0x13bd2
movq 0x8(%rsp), %rax
movl 0x60(%rax), %ecx
movq %r14, %rsi
movq %rbx, %rdx
callq 0x13cdc
xorl %r13d, %r13d
movl %r13d, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2f402(%rip), %rdi     # 0x42ff0
leaq 0x1d1d4(%rip), %rsi     # 0x30dc9
callq 0x6240
movq %rax, %rbx
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x14d96
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6210
pushq $-0x1
popq %r13
movq %rax, %rdi
callq 0x6140
jmp 0x137a7
movq 0x2f3be(%rip), %rdi     # 0x42ff0
leaq 0x1d129(%rip), %rsi     # 0x30d62
jmp 0x13c49
movq 0x2f3ae(%rip), %rdi     # 0x42ff0
leaq 0x1d14f(%rip), %rsi     # 0x30d98
callq 0x6240
movq %rax, %rdi
callq 0x6140
jmp 0x13b99
jmp 0x13c9e
movq %rax, %r14
leaq 0x78(%rsp), %rdi
jmp 0x13ca6
movq %rax, %r14
pushq $0x20
jmp 0x13c7e
movq %rax, %r14
pushq $0x10
popq %rsi
movq %r15, %rdi
jmp 0x13c82
movq %rax, %r14
pushq $0x40
popq %rsi
movq %rbx, %rdi
callq 0x6270
jmp 0x13cd3
movq %rax, %r14
leaq 0x98(%rsp), %rdi
jmp 0x13ca6
jmp 0x13c9e
jmp 0x13c9e
jmp 0x13c9e
jmp 0x13c9e
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x6130
jmp 0x13cd3
jmp 0x13cc6
jmp 0x13cc6
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x6130
jmp 0x13cc9
jmp 0x13cc6
jmp 0x13cc6
jmp 0x13cc6
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x8746
movq %r14, %rdi
callq 0x6460
nop