// File: iamlouk[P]asbi/src/parser.cc
// Function: asbi::Parser::parse_lambda(std::vector<ast::Node*, std::allocator<ast::Node*>>)
ast::Lambda* Parser::parse_lambda(std::vector<ast::Node*> argnamenodes) {
	expect(tok::Arrow);

	std::vector<asbi::StringContainer*> argnames;
	for (auto const& node: argnamenodes) {
		ast::Variable* var = dynamic_cast<ast::Variable*>(node);
		if (var == nullptr)
			throw utils::parser_error("lambda-litteral args should only be identifiers", node);

		argnames.push_back(var->sc);
		delete var;
	}

	ast::Block* body;
	auto _body = parse_expr();
	if (body = dynamic_cast<ast::Block*>(_body); body == nullptr) {
		std::vector<ast::Node*> vec = { _body };
		body = new ast::Block(vec);
	}

	return new ast::Lambda(std::move(argnames), body);
}

// Assembly:
subq $0x158, %rsp            # imm = 0x158
movq %rsi, 0x68(%rsp)
movq %rdi, 0x150(%rsp)
movq %rsi, 0x148(%rsp)
movq 0x150(%rsp), %rdi
movq %rdi, 0x60(%rsp)
movl $0xc, %esi
callq 0xdcd0
leaq 0x130(%rsp), %rdi
callq 0x127f0
movq 0x68(%rsp), %rsi
movq %rsi, 0x128(%rsp)
movq 0x128(%rsp), %rdi
callq 0x12800
movq %rax, 0x120(%rsp)
movq 0x128(%rsp), %rdi
callq 0x12830
movq %rax, 0x118(%rsp)
leaq 0x120(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x12860
testb $0x1, %al
jne 0x11545
jmp 0x1168c
leaq 0x120(%rsp), %rdi
callq 0x128a0
movq %rax, 0x110(%rsp)
movq 0x110(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x58(%rsp)
cmpq $0x0, %rax
je 0x11593
movq 0x58(%rsp), %rdi
leaq 0x39fc4(%rip), %rsi     # 0x4b540
leaq 0x3a0d5(%rip), %rdx     # 0x4b658
xorl %eax, %eax
movl %eax, %ecx
callq 0x6520
movq %rax, 0x50(%rsp)
jmp 0x1159c
xorl %eax, %eax
movq %rax, 0x50(%rsp)
jmp 0x1159c
movq 0x50(%rsp), %rax
movq %rax, 0x108(%rsp)
cmpq $0x0, 0x108(%rsp)
jne 0x1163f
movl $0x48, %edi
callq 0x6200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x48(%rsp)
movq 0x110(%rsp), %rax
movq (%rax), %rdx
leaq 0x27383(%rip), %rsi     # 0x38962
callq 0x17550
jmp 0x115e6
movq 0x48(%rsp), %rdi
leaq 0x39f36(%rip), %rsi     # 0x4b528
leaq 0x6a7(%rip), %rdx       # 0x11ca0
callq 0x6780
jmp 0x1194f
movq 0x48(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
callq 0x6320
jmp 0x11935
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x11935
movq 0x108(%rsp), %rsi
addq $0x8, %rsi
leaq 0x130(%rsp), %rdi
callq 0x128b0
jmp 0x1165a
movq 0x108(%rsp), %rax
movq %rax, 0x40(%rsp)
cmpq $0x0, %rax
je 0x11678
movq 0x40(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x1167a
leaq 0x120(%rsp), %rdi
callq 0x12920
jmp 0x11527
movq 0x60(%rsp), %rdi
callq 0xe090
movq %rax, 0x38(%rsp)
jmp 0x1169d
movq 0x38(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, %rax
je 0x116e0
movq 0x30(%rsp), %rdi
leaq 0x39e77(%rip), %rsi     # 0x4b540
leaq 0x3a4d8(%rip), %rdx     # 0x4bba8
xorl %eax, %eax
movl %eax, %ecx
callq 0x6520
movq %rax, 0x28(%rsp)
jmp 0x116e9
xorl %eax, %eax
movq %rax, 0x28(%rsp)
jmp 0x116e9
movq 0x28(%rsp), %rax
movq %rax, 0xf0(%rsp)
cmpq $0x0, 0xf0(%rsp)
jne 0x1188e
movq 0xe8(%rsp), %rax
movq %rax, 0xb8(%rsp)
leaq 0xb8(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq $0x1, 0xc8(%rsp)
leaq 0xb7(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x125f0
movq 0x20(%rsp), %rcx
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
leaq 0xd0(%rsp), %rdi
callq 0x12600
jmp 0x11767
leaq 0xb7(%rsp), %rdi
callq 0x12690
movl $0x20, %edi
callq 0x6460
movq %rax, 0x18(%rsp)
jmp 0x11785
movb $0x1, 0x97(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x11d60
jmp 0x117a4
movq 0x18(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x11e60
jmp 0x117b8
movq 0x18(%rsp), %rax
movb $0x0, 0x97(%rsp)
movq %rax, 0xf0(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x11ed0
leaq 0xd0(%rsp), %rdi
callq 0x11ed0
jmp 0x1188e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0xb7(%rsp), %rdi
callq 0x12690
jmp 0x11935
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x1187c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x1185f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x11ed0
testb $0x1, 0x97(%rsp)
jne 0x1186b
jmp 0x1187a
movq 0x18(%rsp), %rdi
movl $0x20, %esi
callq 0x6470
jmp 0x1187c
leaq 0xd0(%rsp), %rdi
callq 0x11ed0
jmp 0x11935
movl $0x28, %edi
callq 0x6460
movq %rax, 0x10(%rsp)
jmp 0x1189f
movb $0x1, 0x77(%rsp)
leaq 0x78(%rsp), %rdi
movq %rdi, 0x8(%rsp)
leaq 0x130(%rsp), %rsi
callq 0x12940
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0xf0(%rsp), %rdx
callq 0x12970
jmp 0x118d4
movb $0x0, 0x77(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x129f0
leaq 0x130(%rsp), %rdi
callq 0x129f0
movq 0x10(%rsp), %rax
addq $0x158, %rsp            # imm = 0x158
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x129f0
testb $0x1, 0x77(%rsp)
jne 0x11924
jmp 0x11933
movq 0x10(%rsp), %rdi
movl $0x28, %esi
callq 0x6470
jmp 0x11935
leaq 0x130(%rsp), %rdi
callq 0x129f0
movq 0x100(%rsp), %rdi
callq 0x67a0
nop