// File: /workspace/github_cpp_makefile_star2_O1/iamlouk[P]asbi/src/parser.cc
// Function: asbi::Parser::parse_assign()
ast::Node* Parser::parse_assign() {
	auto left = parse_logic();
	if (tokenizer.peek().type == tok::Assign) {
		tokenizer.next();
		auto right = parse_expr();

		ast::Variable* var = dynamic_cast<ast::Variable*>(left);
		if (var != nullptr)
			return new ast::AssignVariable(var, right);

		ast::Access* acs = dynamic_cast<ast::Access*>(left);
		if (acs != nullptr)
			return new ast::AssignAccess(acs, right);

		throw utils::parser_error("one can only assign to variables or dict subscripts", left);
	}

	if (tokenizer.peek().type == tok::Declare) {
		auto tok = tokenizer.next();

		auto right = parse_expr();
		auto var = dynamic_cast<ast::Variable*>(left);
		if (var != nullptr) {
			std::vector<std::pair<ast::Variable*, ast::Node*>> decls;
			decls.push_back(std::make_pair(var, right));
			while (tokenizer.peek().type == tok::Comma) {
				tokenizer.next();
				auto node = parse_logic();
				auto var = dynamic_cast<ast::Variable*>(node);
				if (var == nullptr)
					throw utils::parser_error("expected Variable", node);

				ast::Node* val = nullptr;
				if (tokenizer.peek().type == tok::Declare) {
					tokenizer.next();
					val = parse_logic();
				}

				decls.push_back(std::make_pair(var, val));
			}

			return new ast::VariableDecl(std::move(decls));
		}

		ast::List* list = dynamic_cast<ast::List*>(left);
		if (list != nullptr) {
			auto node = new ast::DestructList(std::move(list->values), right);
			list->values.clear();
			delete list;
			return node;
		}

		ast::Map* map = dynamic_cast<ast::Map*>(left);
		if (map != nullptr) {
			/*std::vector<std::pair<ast::Variable*, ast::Node*>> vars;
			for (auto [key, val]: map->values) {
				auto var = dynamic_cast<ast::Variable*>(val);
				if (var == nullptr)
					throw utils::parser_error("only variables allowed in destructuring", left);

				vars.push_back(std::make_pair(var, key));
			}
			map->values.clear();
			delete map;
			return new ast::DestructMap(std::move(vars), right);*/

			throw utils::parser_error("unimplemented!", left);
		}

		throw utils::parser_error("one can only declare variables or destruct using ':='", tok /*left*/);
	}

	return left;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %r14
callq 0x8c30
movq %rax, %rbx
movq %r14, %rdi
callq 0x6a1a
movq %r14, %rdi
cmpl $0x6, %eax
jne 0x8551
callq 0x6a44
movq %r14, %rdi
callq 0x8330
movq %rax, %r14
testq %rbx, %rbx
je 0x8597
leaq 0x18055(%rip), %rsi     # 0x20590
leaq 0x18136(%rip), %rdx     # 0x20678
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x53f0
movq %rax, %r15
jmp 0x859a
callq 0x6a1a
cmpl $0x7, %eax
jne 0x8671
movq %r14, %rdi
callq 0x6a44
movq %rax, %r15
movq %rdx, %r12
movq %r14, %rdi
callq 0x8330
movq %rax, %r13
testq %rbx, %rbx
je 0x85de
leaq 0x1800c(%rip), %rsi     # 0x20590
leaq 0x180ed(%rip), %rdx     # 0x20678
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x53f0
jmp 0x85e0
xorl %r15d, %r15d
testq %r15, %r15
je 0x85b8
movl $0x18, %edi
callq 0x5380
movq %rax, %rbx
leaq 0x181b5(%rip), %rax     # 0x20768
jmp 0x8662
testq %rbx, %rbx
je 0x8642
leaq 0x17fc8(%rip), %rsi     # 0x20590
leaq 0x180f1(%rip), %rdx     # 0x206c0
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x53f0
movq %rax, %r15
jmp 0x8645
xorl %eax, %eax
testq %rax, %rax
je 0x8619
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq %r13, 0x20(%rsp)
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
je 0x8683
movups 0x18(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rsp)
jmp 0x8690
testq %rbx, %rbx
je 0x87c8
leaq 0x17f67(%rip), %rsi     # 0x20590
leaq 0x185b0(%rip), %rdx     # 0x20be0
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x53f0
movq %rax, %r14
jmp 0x87cb
xorl %r15d, %r15d
testq %r15, %r15
je 0x8890
movl $0x18, %edi
callq 0x5380
movq %rax, %rbx
leaq 0x1814e(%rip), %rax     # 0x207b0
addq $0x10, %rax
movq %rax, (%rbx)
movq %r15, 0x8(%rbx)
movq %r14, 0x10(%rbx)
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsp, %rdi
leaq 0x18(%rsp), %rdx
callq 0xa446
leaq 0x18(%rsp), %r15
leaq 0x17ef4(%rip), %r12     # 0x20590
leaq 0x17fd5(%rip), %r13     # 0x20678
movq %r14, %rdi
callq 0x6a1a
cmpl $0x1d, %eax
jne 0x8746
movq %r14, %rdi
callq 0x6a44
movq %r14, %rdi
callq 0x8c30
movq %rax, %rbx
testq %rax, %rax
je 0x86e1
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x53f0
movq %rax, %rbp
jmp 0x86e3
xorl %ebp, %ebp
testq %rbp, %rbp
je 0x885b
movq %r14, %rdi
callq 0x6a1a
cmpl $0x7, %eax
jne 0x870b
movq %r14, %rdi
callq 0x6a44
movq %r14, %rdi
callq 0x8c30
jmp 0x870d
xorl %eax, %eax
movq %rbp, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x8736
movups 0x18(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rsp)
jmp 0x86a3
movq %rsp, %rdi
movq %r15, %rdx
callq 0xa446
jmp 0x86a3
movl $0x20, %edi
callq 0x5380
movq %rax, %rbx
movq (%rsp), %rax
leaq 0x40(%rsp), %rsi
movq %rax, (%rsi)
movups 0x8(%rsp), %xmm0
movups %xmm0, 0x8(%rsi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
leaq 0x18269(%rip), %rax     # 0x209e8
addq $0x10, %rax
movq %rax, (%rbx)
movq %rbx, %rdi
addq $0x8, %rdi
callq 0xa116
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x87a9
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8671
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
jmp 0x8671
xorl %r14d, %r14d
testq %r14, %r14
je 0x88c5
movl $0x28, %edi
callq 0x5380
movq %rax, %rbx
movq 0x8(%r14), %rax
leaq 0x28(%rsp), %rsi
movq %rax, (%rsi)
movq 0x10(%r14), %rax
movq %rax, 0x8(%rsi)
movq 0x18(%r14), %rax
movq %rax, 0x10(%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r14)
movq $0x0, 0x18(%r14)
leaq 0x18204(%rip), %rax     # 0x20a18
addq $0x10, %rax
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
callq 0xa00e
movq %r13, 0x20(%rbx)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x883f
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq 0x8(%r14), %rax
cmpq %rax, 0x10(%r14)
je 0x884d
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
jmp 0x8671
movl $0x48, %edi
callq 0x51b0
movq %rax, %r15
leaq 0xeede(%rip), %rsi      # 0x1774d
movq %rax, %rdi
movq %rbx, %rdx
callq 0xabda
leaq 0x17cf7(%rip), %rsi     # 0x20578
leaq 0x1756(%rip), %rdx      # 0x9fde
movq %r15, %rdi
callq 0x55d0
movl $0x48, %edi
callq 0x51b0
movq %rax, %r15
leaq 0xee75(%rip), %rsi      # 0x17719
movq %rax, %rdi
movq %rbx, %rdx
callq 0xabda
leaq 0x17cc2(%rip), %rsi     # 0x20578
leaq 0x1721(%rip), %rdx      # 0x9fde
movq %r15, %rdi
callq 0x55d0
testq %rbx, %rbx
je 0x88e7
leaq 0x17cbf(%rip), %rsi     # 0x20590
leaq 0x18320(%rip), %rdx     # 0x20bf8
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x53f0
testq %rax, %rax
jne 0x891f
movl $0x48, %edi
callq 0x51b0
movq %rax, %rbx
leaq 0xee73(%rip), %rsi      # 0x1776e
movq %rax, %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0xa9f6
leaq 0x17c68(%rip), %rsi     # 0x20578
leaq 0x16c7(%rip), %rdx      # 0x9fde
movq %rbx, %rdi
callq 0x55d0
movl $0x48, %edi
callq 0x51b0
movq %rax, %r15
leaq 0xee2c(%rip), %rsi      # 0x1775f
movq %rax, %rdi
movq %rbx, %rdx
callq 0xabda
jmp 0x88af
jmp 0x8973
movq %rax, %r14
movq %rbx, %rdi
jmp 0x8979
jmp 0x89c4
movq %rax, %r14
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x8969
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movl $0x28, %esi
movq %rbx, %rdi
jmp 0x89d8
movq %rax, %r14
movq %r15, %rdi
callq 0x5280
jmp 0x89dd
movq %rax, %r14
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x899a
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movl $0x20, %esi
movq %rbx, %rdi
callq 0x5390
jmp 0x89c7
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
movq %rax, %r14
movq %r15, %rdi
callq 0x5280
jmp 0x89c7
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
jmp 0x89c4
movq %rax, %r14
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x89dd
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq %r14, %rdi
callq 0x55e0
nop