// File: AshOlogn[P]ash-language-interpreter/src/executor.cpp
// Function: executeAssignmentStatement(AssignmentStatementNode*)
void executeAssignmentStatement(AssignmentStatementNode* node) {
	
  //get stuff out of the node first
  SymbolTable* symbolTable = node->symbolTable;
  std::string variable = node->variable;
  AbstractExpressionNode* value = node->value;
  
  ParseDataType type = (symbolTable->get(variable)).type;
  ParseData d = value->evaluate();

	if(type == ARRAY_T) {

		//deep copy of array, casting as necessary
		Array* arr = (Array*) (symbolTable->get(variable)).value.allocated;
		ParseDataType subType = arr->subtype;

		Array* origArr = (Array*) d.value.allocated;
		uint32_t length = arr->length = origArr->length;
		
		ParseData* values = new ParseData[length];
		ParseData* origValues = origArr->values;

		for(uint32_t i = 0; i < length; i++) {
			values[i] = castHelper(origValues[i], subType);
		}

		arr->values = values;

	} else {
		//update variable value (innermost scope)
  	symbolTable->update(variable, castHelper(d, type));
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rsi
addq $0x18, %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x40f0
movq -0x170(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x40f0
jmp 0x2f0bc
movq -0x168(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x2c020
movq %rdx, -0x180(%rbp)
movl %eax, -0x174(%rbp)
jmp 0x2f0db
movq -0x180(%rbp), %rax
movl -0x174(%rbp), %ecx
movl %ecx, -0x50(%rbp)
movq %rax, -0x48(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x194(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x4170
movl -0x194(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movq %rdx, -0x190(%rbp)
movl %eax, -0x184(%rbp)
jmp 0x2f125
movq -0x190(%rbp), %rax
movl -0x184(%rbp), %ecx
movl %ecx, -0x90(%rbp)
movq %rax, -0x88(%rbp)
cmpl $0xc, -0x3c(%rbp)
jne 0x2f350
movq -0x10(%rbp), %rax
movq %rax, -0x1a0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x40f0
jmp 0x2f166
movq -0x1a0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2c020
movq %rdx, -0x1b0(%rbp)
movl %eax, -0x1a4(%rbp)
jmp 0x2f188
movq -0x1b0(%rbp), %rax
movl -0x1a4(%rbp), %ecx
movl %ecx, -0xa8(%rbp)
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x1c0(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x4170
movq -0x1c0(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xcc(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x98(%rbp), %rcx
movl %eax, 0x4(%rcx)
movl %eax, -0xdc(%rbp)
movl -0xdc(%rbp), %eax
movl %eax, %edi
shlq $0x4, %rdi
callq 0x4030
movq %rax, -0x1b8(%rbp)
jmp 0x2f21b
movq -0x1b8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xd8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xf0(%rbp)
movl $0x0, -0xf4(%rbp)
movl -0xf4(%rbp), %eax
cmpl -0xdc(%rbp), %eax
jae 0x2f339
movq -0xf0(%rbp), %rax
movl -0xf4(%rbp), %ecx
shlq $0x4, %rcx
movups (%rax,%rcx), %xmm0
movaps %xmm0, -0x120(%rbp)
movl -0xcc(%rbp), %edx
movl -0x120(%rbp), %edi
movq -0x118(%rbp), %rsi
callq 0x29c10
movq %rdx, -0x1d0(%rbp)
movl %eax, -0x1c4(%rbp)
jmp 0x2f29a
movq -0x1d0(%rbp), %rax
movl -0x1c4(%rbp), %ecx
movl %ecx, -0x108(%rbp)
movq %rax, -0x100(%rbp)
movq -0xe8(%rbp), %rax
movl -0xf4(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x108(%rbp), %rcx
movq %rcx, (%rax)
movq -0x100(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0xf4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4(%rbp)
jmp 0x2f245
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x2f415
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x4170
jmp 0x2f415
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x4170
jmp 0x2f415
movq -0xe8(%rbp), %rcx
movq -0x98(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x2f403
movq -0x10(%rbp), %rax
movq %rax, -0x1d8(%rbp)
leaq -0x140(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x40f0
jmp 0x2f36d
movups -0x90(%rbp), %xmm0
movaps %xmm0, -0x160(%rbp)
movl -0x3c(%rbp), %edx
movl -0x160(%rbp), %edi
movq -0x158(%rbp), %rsi
callq 0x29c10
movq %rdx, -0x1e8(%rbp)
movl %eax, -0x1dc(%rbp)
jmp 0x2f39f
movq -0x1d8(%rbp), %rdi
movq -0x1e8(%rbp), %rax
movl -0x1dc(%rbp), %ecx
movl %ecx, -0x150(%rbp)
movq %rax, -0x148(%rbp)
movl -0x150(%rbp), %edx
movq -0x148(%rbp), %rcx
leaq -0x140(%rbp), %rsi
callq 0x2bdf0
jmp 0x2f3db
leaq -0x140(%rbp), %rdi
callq 0x4170
jmp 0x2f403
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x4170
jmp 0x2f415
leaq -0x30(%rbp), %rdi
callq 0x4170
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x4170
movq -0x78(%rbp), %rdi
callq 0x4420
nopw (%rax,%rax)