// File: /workspace/github_cpp_makefile_star2_O3/AshOlogn[P]ash-language-interpreter/src/parser.cpp
// Function: evalAssignment()
AbstractExpressionNode* evalAssignment() {
  
  AbstractExpressionNode* head = evalLogicOr();
  VariableNode* var = dynamic_cast<VariableNode*>(head);
	ArrayAccessNode* arrVar = dynamic_cast<ArrayAccessNode*>(head);
  
  if((var || arrVar) && isAssignmentOperatorTokenType(peek()->type)) {
  
    //if just variable, make sure it is already declared in some scope
		if(var && !symbolTable->isDeclared(var->variable)) {
      throw StaticVariableScopeError(var->startLine, var->variable, getCodeLineBlock(var->startLine-1, var->startLine-1), false);
		}
    
    //get variable's type
    ParseDataType type = head->evalType;
    
    Token* assignmentToken = consume();
    AbstractExpressionNode* next = evalAssignment();
		
		//make sure the assignment operation is even valid
		if(assignmentToken->type != EQ) {

			ParseOperatorType opType;
			switch(assignmentToken->type) {
				case ADD_EQ: opType = ADD_OP; break;
				case SUBTRACT_EQ: opType = SUBTRACT_OP; break;
				case EXPONENT_EQ: opType = EXPONENT_OP; break;
				case MULTIPLY_EQ: opType = MULTIPLY_OP; break;
				case DIVIDE_EQ: opType = DIVIDE_OP; break;
				case AND_EQ: opType = AND_OP; break;
				case XOR_EQ: opType = XOR_OP; break;
				case OR_EQ: opType = OR_OP; break;
				default: opType = INVALID_OP;
			}

			if(isArithmeticParseOperatorType(opType)) {

				if(!typecheckArithmeticExpression(opType, type, next->evalType)) {
					uint32_t startLine = head->startLine;
					throw StaticTypeError(startLine, next->endLine, getCodeLineBlock(startLine-1, next->endLine-1), 
																toStringParseOperatorType(opType), type, next->evalType); 
				}

			} else {

				if(!typecheckBitLogicalExpression(opType, type, next->evalType)) {
					uint32_t startLine = head->startLine;
					throw StaticTypeError(startLine, next->endLine, getCodeLineBlock(startLine-1, next->endLine-1), 
																toStringParseOperatorType(opType), type, next->evalType); 
				}
			}
		}
    
    switch(assignmentToken->type) {
      case EQ: break;
      case ADD_EQ: next = new ArithmeticOperatorNode(ADD_OP, head, next); break; 
      case SUBTRACT_EQ: next = new ArithmeticOperatorNode(SUBTRACT_OP, head, next); break;
      case EXPONENT_EQ: next = new ArithmeticOperatorNode(EXPONENT_OP, head, next); break;
      case MULTIPLY_EQ: next = new ArithmeticOperatorNode(MULTIPLY_OP, head, next); break;
      case DIVIDE_EQ: next = new ArithmeticOperatorNode(DIVIDE_OP, head, next); break;
      case AND_EQ: {
        if(type == BOOL_T)
          next = new BitLogicalOperatorNode(AND_OP, head, next);
        else 
          next = new BitLogicalOperatorNode(BIT_AND_OP, head, next);
        break;
      }
      
      case XOR_EQ: {
        if(type == BOOL_T)
          next = new BitLogicalOperatorNode(XOR_OP, head, next);
        else 
          next = new BitLogicalOperatorNode(BIT_XOR_OP, head, next);
        break;
      }
      
      case OR_EQ: {
        if(type == BOOL_T)
          next = new BitLogicalOperatorNode(OR_OP, head, next);
        else 
          next = new BitLogicalOperatorNode(BIT_OR_OP, head, next);
        break;
      }
    }
    
    //now make sure that implicit type cast is valid
    if(!typecheckImplicitCastExpression(next->evalType, type)) {
      throw StaticCastError(head->startLine, next->endLine, getCodeLineBlock(head->startLine-1, next->endLine-1), next->evalType, type, false);
    }
    
		if(var) {
			return new AssignmentExpressionNode(var->variable, type, next, symbolTable, var->startLine);
		} else {
			return new ArrayAssignmentExpressionNode(arrVar->array, arrVar->start, next, getCodeLineBlock(arrVar->startLine-1, next->endLine-1), symbolTable);
		}
    
  } else {
    return head;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
callq 0x1cd4e
movq %rax, %rbx
leaq 0xeca6(%rip), %r14      # 0x2bb28
leaq 0xec3f(%rip), %rdx      # 0x2bac8
movq %rax, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x4230
movq %rax, %r15
leaq 0xebf8(%rip), %rdx      # 0x2ba98
movq %rbx, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x4230
movq %rax, %r13
movq %r15, %rax
orq %r13, %rax
je 0x1d274
callq 0x1781b
movl (%rax), %edi
callq 0x6409
testb %al, %al
je 0x1d274
testq %r15, %r15
je 0x1cf24
movq 0xf3b4(%rip), %r14      # 0x2c290
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
addq %rsi, %rdx
leaq -0x58(%rbp), %r12
movq %r12, %rdi
callq 0x897a
movq %r14, %rdi
movq %r12, %rsi
callq 0x16598
movl %eax, %r14d
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x1cf1b
callq 0x41e0
testb %r14b, %r14b
je 0x1d2f6
movl 0x10(%rbx), %r14d
callq 0x177cc
movq %rax, %r12
callq 0x1ce62
movq %rax, -0x30(%rbp)
movl (%r12), %eax
addl $-0x1f, %eax
cmpl $0x9, %eax
movl %r14d, -0x34(%rbp)
ja 0x1cf99
leaq 0x6098(%rip), %rcx      # 0x22fe8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0xf, %r14d
jmp 0x1cf9f
movl $0x10, %r14d
jmp 0x1cf9f
movl $0xd, %r14d
jmp 0x1cf9f
movl $0x1c, %r14d
jmp 0x1cf9f
movl $0x1d, %r14d
jmp 0x1cf9f
movl $0xb, %r14d
jmp 0x1cf9f
movl $0xc, %r14d
jmp 0x1cf9f
movl $0x1e, %r14d
jmp 0x1cf9f
movl $0x2b, %r14d
movl %r14d, %edi
callq 0x80d6
movq -0x30(%rbp), %rcx
movl 0x10(%rcx), %edx
movl %r14d, %edi
testb %al, %al
je 0x1cff8
movl -0x34(%rbp), %esi
callq 0x160ee
testb %al, %al
jne 0x1d008
movl 0x8(%rbx), %r12d
movl $0x38, %edi
callq 0x4110
movq %rax, %rbx
movq -0x30(%rbp), %rax
movl 0xc(%rax), %r13d
leal -0x1(%r12), %edi
leal -0x1(%r13), %esi
callq 0x17891
movq %rax, %r15
movl %r14d, %edi
callq 0x81a3
jmp 0x1d39d
movl -0x34(%rbp), %esi
callq 0x161d9
testb %al, %al
je 0x1d36b
movl (%r12), %eax
addl $-0x20, %eax
cmpl $0x8, %eax
ja 0x1d1b6
leaq 0x5ff1(%rip), %rcx      # 0x23010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movl -0x34(%rbp), %r14d
jmpq *%rax
movl $0x30, %edi
callq 0x4210
movq %rax, %r12
movq %rax, %rdi
movl $0xf, %esi
movq %rbx, %rdx
movq -0x30(%rbp), %rcx
callq 0x8de0
jmp 0x1d1be
movl $0x30, %edi
callq 0x4210
movq %rax, %r12
cmpl $0x9, %r14d
jne 0x1d174
movq %r12, %rdi
movl $0x1c, %esi
movq %rbx, %rdx
movq -0x30(%rbp), %rcx
callq 0x8e3e
jmp 0x1d1be
movl $0x30, %edi
callq 0x4210
movq %rax, %r12
movq %rax, %rdi
movl $0x10, %esi
movq %rbx, %rdx
movq -0x30(%rbp), %rcx
callq 0x8de0
jmp 0x1d1be
movl $0x30, %edi
callq 0x4210
movq %rax, %r12
cmpl $0x9, %r14d
jne 0x1d18a
movq %r12, %rdi
movl $0x1d, %esi
movq %rbx, %rdx
movq -0x30(%rbp), %rcx
callq 0x8e3e
jmp 0x1d1be
movl $0x30, %edi
callq 0x4210
movq %rax, %r12
cmpl $0x9, %r14d
jne 0x1d1a0
movq %r12, %rdi
movl $0x1e, %esi
movq %rbx, %rdx
movq -0x30(%rbp), %rcx
callq 0x8e3e
jmp 0x1d1be
movl $0x30, %edi
callq 0x4210
movq %rax, %r12
movq %rax, %rdi
movl $0xb, %esi
movq %rbx, %rdx
movq -0x30(%rbp), %rcx
callq 0x8de0
jmp 0x1d1be
movl $0x30, %edi
callq 0x4210
movq %rax, %r12
movq %rax, %rdi
movl $0xc, %esi
movq %rbx, %rdx
movq -0x30(%rbp), %rcx
callq 0x8de0
jmp 0x1d1be
movl $0x30, %edi
callq 0x4210
movq %rax, %r12
movq %rax, %rdi
movl $0xd, %esi
movq %rbx, %rdx
movq -0x30(%rbp), %rcx
callq 0x8de0
jmp 0x1d1be
movq %r12, %rdi
movl $0x19, %esi
movq %rbx, %rdx
movq -0x30(%rbp), %rcx
callq 0x8e3e
jmp 0x1d1be
movq %r12, %rdi
movl $0x1a, %esi
movq %rbx, %rdx
movq -0x30(%rbp), %rcx
callq 0x8e3e
jmp 0x1d1be
movq %r12, %rdi
movl $0x1b, %esi
movq %rbx, %rdx
movq -0x30(%rbp), %rcx
callq 0x8e3e
jmp 0x1d1be
movl -0x34(%rbp), %r14d
movq -0x30(%rbp), %r12
movl 0x10(%r12), %edi
movl %r14d, %esi
callq 0x15ff7
testb %al, %al
je 0x1d286
testq %r15, %r15
je 0x1d232
movq %r12, %r13
movl $0x50, %edi
callq 0x4210
movq %rax, %rbx
leaq -0x68(%rbp), %r12
movq %r12, -0x10(%r12)
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
addq %rsi, %rdx
leaq -0x78(%rbp), %rdi
callq 0x897a
movq 0xf084(%rip), %r8       # 0x2c290
movl 0x8(%r15), %r9d
leaq -0x78(%rbp), %rsi
movq %rbx, %rdi
movl %r14d, %edx
movq %r13, %rcx
callq 0x8a18
movq -0x78(%rbp), %rdi
cmpq %r12, %rdi
je 0x1d274
callq 0x41e0
jmp 0x1d274
movl $0x40, %edi
callq 0x4210
movq %rax, %rbx
movq 0x18(%r13), %r14
movq 0x20(%r13), %r15
movl 0x8(%r13), %edi
decl %edi
movl 0xc(%r12), %esi
decl %esi
callq 0x17891
movq 0xf030(%rip), %r9       # 0x2c290
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
movq %rax, %r8
callq 0x8ade
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x30, %edi
callq 0x4110
movq %rax, %r15
movl 0x8(%rbx), %ebx
movq %r12, %r13
movl 0xc(%r12), %r14d
leal -0x1(%rbx), %edi
leal -0x1(%r14), %esi
callq 0x17891
movl 0x10(%r13), %ecx
leaq 0xe3db(%rip), %rdx      # 0x2b690
addq $0x10, %rdx
movq %rdx, (%r15)
movl %ecx, 0x8(%r15)
movl -0x34(%rbp), %ecx
movl %ecx, 0xc(%r15)
movq %rax, 0x10(%r15)
movq $0x0, 0x18(%r15)
movb $0x0, 0x20(%r15)
movl %ebx, 0x24(%r15)
movl %r14d, 0x28(%r15)
leaq 0xe3d1(%rip), %rsi      # 0x2b6b8
movq 0xecea(%rip), %rdx      # 0x2bfd8
movq %r15, %rdi
callq 0x4350
movl $0x38, %edi
callq 0x4110
movq %rax, %rbx
movl 0x8(%r15), %r14d
leaq -0x88(%rbp), %r12
movq %r12, -0x10(%r12)
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
addq %rsi, %rdx
leaq -0x98(%rbp), %rdi
callq 0x897a
movl 0x8(%r15), %edi
decl %edi
movb $0x1, %r15b
movl %edi, %esi
callq 0x17891
leaq -0x98(%rbp), %rdx
movq %rbx, %rdi
movl %r14d, %esi
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x1d60a
xorl %r15d, %r15d
leaq 0xe31c(%rip), %rsi      # 0x2b678
leaq -0x177a9(%rip), %rdx    # 0x5bba
movq %rbx, %rdi
callq 0x4350
movl 0x8(%rbx), %r12d
movl $0x38, %edi
callq 0x4110
movq %rax, %rbx
movq -0x30(%rbp), %rax
movl 0xc(%rax), %r13d
leal -0x1(%r12), %edi
leal -0x1(%r13), %esi
callq 0x17891
movq %rax, %r15
movl %r14d, %edi
callq 0x81a3
movq -0x30(%rbp), %rcx
movl 0x10(%rcx), %ecx
leaq 0xe265(%rip), %rdx      # 0x2b610
addq $0x10, %rdx
movq %rdx, (%rbx)
movw $0x1, 0x8(%rbx)
movq %r15, 0x10(%rbx)
movq %rax, 0x18(%rbx)
movq $0x0, 0x20(%rbx)
movl %r12d, 0x28(%rbx)
movl %r13d, 0x2c(%rbx)
movl -0x34(%rbp), %eax
movl %eax, 0x30(%rbx)
movl %ecx, 0x34(%rbx)
leaq 0xe258(%rip), %rsi      # 0x2b638
movq 0xebf1(%rip), %rdx      # 0x2bfd8
movq %rbx, %rdi
callq 0x4350
jmp 0x1d403
jmp 0x1d403
jmp 0x1d403
jmp 0x1d403
jmp 0x1d403
jmp 0x1d403
jmp 0x1d403
jmp 0x1d403
jmp 0x1d403
jmp 0x1d403
movq %rax, %r14
movq %r12, %rdi
jmp 0x1d46c
movq %rax, %r14
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
je 0x1d41f
callq 0x41e0
testb %r15b, %r15b
jne 0x1d42d
jmp 0x1d471
jmp 0x1d42a
jmp 0x1d42a
movq %rax, %r14
movq %rbx, %rdi
jmp 0x1d438
movq %rax, %r14
movq %r15, %rdi
callq 0x4190
jmp 0x1d471
movq %rax, %r14
movq -0x78(%rbp), %rdi
cmpq %r12, %rdi
je 0x1d469
callq 0x41e0
jmp 0x1d469
jmp 0x1d466
movq %rax, %r14
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
jne 0x1d46c
jmp 0x1d471
movq %rax, %r14
movq %rbx, %rdi
callq 0x41e0
movq %r14, %rdi
callq 0x4380