// File: kram[P]kram/./src/parser/parser.cpp
// Function: Parser::assign_with_type(Instruction*)
Instruction* Parser::assign_with_type(Instruction* prev) {
	Instruction* ins = new Instruction(Ins::ASSIGN);

	if (prev->instruction != Ins::NAME) {
		std::cout << ": expects previous instruction to be of type NAME";
		exit(0);
	}

	// Get name from previous OP
	ins->name = prev->name;

	// Read the rest of the row
	std::vector<Instruction*> row = this->read_until_eol();

	// Expect exactly one name
	if (row.size() != 1 || row[0]->instruction != Ins::NAME) {
		std::cout << ": needs to be followed by exactly one NAME (aka the type)";
		exit(0);
	}

	std::string type = row[0]->name;

	if (type == "Number") {
		ins->right.push_back(this->number_init());
	} else if (type == "String") {
		ins->right.push_back(this->string_init());
	} else if (type == "Bool") {
		ins->right.push_back(this->boolean_init());
	} else {
		std::cout << "Does not know how to init type " << type << " after :";
		exit(0);
	}

	return ins;
}

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x60(%rsp)
movl $0x80, %edi
callq 0x32e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x68(%rsp)
xorl %esi, %esi
callq 0x26dd0
jmp 0x222a2
movq 0x68(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0xd8(%rsp), %rax
cmpl $0x3, (%rax)
je 0x222f9
movq 0x17d15(%rip), %rdi     # 0x39fd8
leaq 0x9dcd(%rip), %rsi      # 0x2c097
callq 0x32d0
xorl %edi, %edi
callq 0x3330
movq 0x68(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
callq 0x32b0
jmp 0x2259b
movq 0xd8(%rsp), %rsi
addq $0x8, %rsi
movq 0xd0(%rsp), %rdi
addq $0x8, %rdi
callq 0x3040
movq 0x60(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x20c30
leaq 0xa8(%rsp), %rdi
callq 0x56b0
cmpq $0x1, %rax
jne 0x22354
leaq 0xa8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x13710
movq (%rax), %rax
cmpl $0x3, (%rax)
je 0x22389
movq 0x17c7d(%rip), %rdi     # 0x39fd8
leaq 0x9d67(%rip), %rsi      # 0x2c0c9
callq 0x32d0
jmp 0x22369
xorl %edi, %edi
callq 0x3330
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
jmp 0x2258e
xorl %eax, %eax
movl %eax, %esi
leaq 0xa8(%rsp), %rdi
callq 0x13710
movq (%rax), %rsi
addq $0x8, %rsi
leaq 0x88(%rsp), %rdi
callq 0x3140
jmp 0x223b0
leaq 0x92e8(%rip), %rsi      # 0x2b69f
leaq 0x88(%rsp), %rdi
callq 0x4070
movb %al, 0x5f(%rsp)
jmp 0x223ca
movb 0x5f(%rsp), %al
testb $0x1, %al
jne 0x223d4
jmp 0x22442
movq 0x60(%rsp), %rdi
movq 0xd0(%rsp), %rax
addq $0x50, %rax
movq %rax, 0x48(%rsp)
callq 0x23610
movq %rax, 0x50(%rsp)
jmp 0x223f6
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x80(%rsp), %rsi
callq 0x26f00
jmp 0x22417
jmp 0x2255c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x31f0
jmp 0x2258e
leaq 0x925d(%rip), %rsi      # 0x2b6a6
leaq 0x88(%rsp), %rdi
callq 0x4070
movb %al, 0x47(%rsp)
jmp 0x2245c
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x22466
jmp 0x224a8
movq 0x60(%rsp), %rdi
movq 0xd0(%rsp), %rax
addq $0x50, %rax
movq %rax, 0x30(%rsp)
callq 0x26160
movq %rax, 0x38(%rsp)
jmp 0x22488
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x78(%rsp), %rsi
callq 0x26f00
jmp 0x224a3
jmp 0x2255a
leaq 0x9c54(%rip), %rsi      # 0x2c103
leaq 0x88(%rsp), %rdi
callq 0x4070
movb %al, 0x2f(%rsp)
jmp 0x224c2
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x224cc
jmp 0x2250b
movq 0x60(%rsp), %rdi
movq 0xd0(%rsp), %rax
addq $0x50, %rax
movq %rax, 0x18(%rsp)
callq 0x26290
movq %rax, 0x20(%rsp)
jmp 0x224ee
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x70(%rsp), %rsi
callq 0x26f00
jmp 0x22509
jmp 0x22558
movq 0x17ac6(%rip), %rdi     # 0x39fd8
leaq 0x9bef(%rip), %rsi      # 0x2c108
callq 0x32d0
movq %rax, 0x10(%rsp)
jmp 0x22525
movq 0x10(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x32a0
movq %rax, 0x8(%rsp)
jmp 0x2253e
movq 0x8(%rsp), %rdi
leaq 0x9bde(%rip), %rsi      # 0x2c128
callq 0x32d0
jmp 0x22551
xorl %edi, %edi
callq 0x3330
jmp 0x2255a
jmp 0x2255c
movq 0xd0(%rsp), %rax
movq %rax, (%rsp)
leaq 0x88(%rsp), %rdi
callq 0x31f0
leaq 0xa8(%rsp), %rdi
callq 0x5560
movq (%rsp), %rax
addq $0xe8, %rsp
retq
leaq 0xa8(%rsp), %rdi
callq 0x5560
movq 0xc8(%rsp), %rdi
callq 0x3490
nopl (%rax,%rax)